scoop:scoop.platform:0.1.0
platform/posix/process_paths.scoop
Selected production source · platform/posix/process_paths.scoop
1
package scoop.platform.process3
import scoop.collections.Map4
import scoop.platform.fs.Path5
import scoop.platform.system.OsString7
internal fun searchCandidates(executable: Path, environment: Map<OsString, OsString>): Array<Path> {8
val name = executable.toOsString().toByteArray()9
for (byte in name) {10
if (byte == 47)11
return [executable]12
}13
val path =14
(15
environment[OsString.fromString("PATH")] ?: OsString.fromString("/bin:/usr/bin")16
).toByteArray()17
val result = ArrayList<Path>()18
var start = 0L19
var index = 0L20
while (index <= path.size) {21
if (index == path.size || path[index] == 58) {22
val from = start23
val length = index - start24
val directory =25
Path.fromOsString(OsString.fromByteArray(Array<Byte>(length) { path[from + it] }))26
result.add(directory.resolve(executable))27
start = index + 1L28
}29
index += 1L30
}31
return Array<Path>(result.size) { result[it] }32
}