linuxMain.files.FileSystemLinux.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package kotlinx.io.files
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.cstr
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toKString
import platform.posix.__xpg_basename
import platform.posix.dirname
@OptIn(ExperimentalForeignApi::class)
internal actual fun dirnameImpl(path: String): String {
if (!path.contains(SystemPathSeparator)) {
return ""
}
memScoped {
return dirname(path.cstr.ptr)?.toKString() ?: ""
}
}
@OptIn(ExperimentalForeignApi::class)
internal actual fun basenameImpl(path: String): String {
memScoped {
return __xpg_basename(path.cstr.ptr)?.toKString() ?: ""
}
}
internal actual fun isAbsoluteImpl(path: String): Boolean = path.startsWith('/')