Hi, how to I get a file modification time or times...
# io
r
Hi, how to I get a file modification time or timestamp with kotlin native on linux
f
There is no way at the moment
r
Alright, thanks for replying this
Maybe I can use Cinterop to get
f
It should be something like
Copy code
import kotlinx.cinterop.*
import platform.posix.*
import kotlin.time.*

@OptIn(ExperimentalTime::class, ExperimentalForeignApi::class, UnsafeNumber::class)
public fun getMTime(path: Path): Instant {
    memScoped {
        val stat = alloc<stat>()
        if (lstat(path.toString(), stat.ptr) != 0) {
            throw IllegalStateException("Failed to get mtime for $path")
        }
        return Instant.fromEpochSeconds(stat.st_mtim.tv_sec.toLong(), stat.st_mtim.tv_nsec)
    }
}
🙌 1
r
wow, thanks, I will try it now ❤️