pajatopmr
11/23/2018, 4:08 PMolonho
11/24/2018, 6:45 AMimport kotlinx.cinterop.*
import platform.posix.*
val String.isDir: Boolean
get() = memScoped {
val statbuf = alloc<stat>()
if (stat(this@isDir, statbuf.ptr) != 0)
// no file
return false
return (statbuf.st_mode.toInt() and S_IFMT) == S_IFDIR
}
fun main() {
println("/tmp".isDir)
}
pajatopmr
11/24/2018, 7:53 AMolonho
11/24/2018, 7:56 AM/usr/include/sys/stat.h:#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */
olonho
11/24/2018, 7:59 AM