Krystian
09/16/2023, 2:56 PMgetpid
and using proc
on Linux, however. For some reason the first parts of the path I'm getting back looks garbled and I'm unsure why. I have a macOS version working perfectly fine. Code inside the thread:Krystian
09/16/2023, 2:57 PMinline val resourcePath: String?
get() {
val pid = getpid()
val buffer = ByteArray(PATH_MAX)
// Build the path to the '/proc' directory for the process
val procPath = "/proc/$pid/exe"
// Use readlink to get the symbolic link pointing to the executable
val pathLength = readlink(procPath, buffer.refTo(0), buffer.size.convert())
if (pathLength <= 0) {
return null
}
// Convert the buffer to a Kotlin string
val path = buffer.toKString()
return memScoped {
val dirReturn = dirname(path.cstr)
dirReturn?.getPointer(this)?.toKString() + "/resources"
}
}
Krystian
09/16/2023, 2:59 PMp���W:%nta/Documents/Programming/untitled/build/bin/native/releaseExecutable/resources
the first part which is the username is messed up?Krystian
09/16/2023, 7:17 PMinline val resourcePath: String?
get() {
// Get the process ID (PID) of the current process
val pid = getpid()
// Create a buffer to store the path
val buffer = ByteArray(PATH_MAX)
// Build the path to the '/proc' directory for the process
val procPath = "/proc/$pid/exe"
// Use the realpath function to get the canonicalized absolute pathname of the executable
if (realpath(procPath, buffer.refTo(0)) == null) {
// If realpath fails, return null to indicate that the resource path could not be determined
return null
}
// Convert the buffer, which contains the absolute path, to a Kotlin string
val executablePath = buffer.toKString()
// Find the last '/' character to extract the directory path
val lastSlashIndex = executablePath.lastIndexOf('/')
val executableDir = executablePath.substring(0, lastSlashIndex + 1)
// Construct the resource path by appending "/resources" to the executable directory
return executableDir + "resources"
}