Skip to content

Commit

Permalink
Fix stupid stat bug wreaking havoc on macOS
Browse files Browse the repository at this point in the history
When interrogating the output struct, do
it *before* it falls out of scope. :-e
  • Loading branch information
ctrueden committed Feb 13, 2024
1 parent f6fb394 commit 828fc1f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/posixMain/kotlin/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ actual class File actual constructor(private val rawPath: String) {
actual val isDirectory: Boolean get() = isMode(S_IFDIR)
actual val isRoot: Boolean = path == SLASH

@OptIn(ExperimentalForeignApi::class)
@OptIn(ExperimentalForeignApi::class, UnsafeNumber::class)
private fun isMode(modeBits: Int): Boolean {
val statResult = memScoped {
val statMode = memScoped {
val statResult = alloc<stat>()
stat(path, statResult.ptr)
statResult
statResult.st_mode.toInt()
}
return (statResult.st_mode.toInt() and modeBits) != 0
return (statMode and modeBits) != 0
}

@OptIn(ExperimentalForeignApi::class)
Expand Down

0 comments on commit 828fc1f

Please sign in to comment.