Scoop API

scoop:scoop.platform:0.1.0

platform/posix/process_paths.scoop

Selected production source · platform/posix/process_paths.scoop

1package scoop.platform.process
3import scoop.collections.Map
4import scoop.platform.fs.Path
5import scoop.platform.system.OsString
7internal 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 = 0L
19 var index = 0L
20 while (index <= path.size) {
21 if (index == path.size || path[index] == 58) {
22 val from = start
23 val length = index - start
24 val directory =
25 Path.fromOsString(OsString.fromByteArray(Array<Byte>(length) { path[from + it] }))
26 result.add(directory.resolve(executable))
27 start = index + 1L
28 }
29 index += 1L
30 }
31 return Array<Path>(result.size) { result[it] }