https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
w

willflier

03/14/2023, 11:20 AM
Hello. How to find current executable's path (not working path) on MacOS? I can't find
_NSGetExecutablePath()
function in K/N macos target.
l

Landry Norris

03/14/2023, 1:24 PM
You may need to add a def file for mach-o/dyld.h
w

willflier

03/14/2023, 1:47 PM
Copy code
actual val executablePath: String = memScoped {
    val buff = allocArray<ByteVar>(pathBufferSize)
    val pid = getpid()
    val ret = proc_pidpath(pid, buff, pathBufferSize.toUInt())
    if(ret < 0) {
        perror("Error getting pidpath")
        return@memScoped ""
    }
       buff.toKStringFromUtf8()
}
I found this
29 Views