interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / host / tests / location.om

125 lines · 2457 bytes Raw Blame History
1note cwd includes its trailing zero in the count; readlnk returns raw bytes without a terminator.
2global here uchar 4096
3global target uchar 4096
4text procwd "/proc/self/cwd"
5text padded "_/proc/self/cwd_"
6text procexe "/proc/self/exe"
7text suffix "/location"
8text absent "missing-link-target"
9text regular "regular-file"
10fn localcwd result edit uchar 4096 to long
11ret add long 7 cwd result 3 4000
12end
13fn locallnk path view uchar 16 result edit uchar 4096 to long
14ret add long 11 readlnk path 1 14 result 7 4000
15end
16fn main to int
17local = new uchar 4096 85
18pathcopy = new uchar 16 0
19n = sub localcwd local 7
20if or le n 1 gt n 4000
21ret 1
22end
23if or ne get local 2 85 ne get local add 3 ulong n 85
24ret 2
25end
26if or ne get local 3 47 ne get local add 2 ulong n 0
27ret 3
28end
29m = cwd here 0 ulong n
30if ne m n
31ret 4
32end
33for i ulong ulong n
34if ne get here i get local add 3 i
35ret 5
36end
37end
38if ne cwd here 0 sub ulong n 1 neg long 34
39ret 6
40end
41if ne cwd here 0 0 neg long 34
42ret 7
43end
44for i ulong len target
45put target i 85
46end
47m = readlnk procwd 0 len procwd target 5 4000
48if ne m sub n 1
49ret 8
50end
51for i ulong ulong m
52if ne get target add 5 i get local add 3 i
53ret 9
54end
55end
56if or ne get target 4 85 ne get target add 5 ulong m 85
57ret 10
58end
59m = readlnk procwd 0 len procwd target 0 1
60if or ne m 1 ne get target 0 47
61ret 11
62end
63if ne readlnk procwd 0 len procwd target 0 0 neg long 22
64ret 12
65end
66m = readlnk procexe 0 len procexe target 0 len target
67if ne m long add sub ulong n 1 len suffix
68ret 13
69end
70for i ulong sub ulong n 1
71if ne get target i get local add 3 i
72ret 14
73end
74end
75for i ulong len suffix
76if ne get target add sub ulong n 1 i get suffix i
77ret 15
78end
79end
80if ne readlnk absent 0 len absent target 0 len target neg long 2
81ret 16
82end
83fd = fopen regular 0 len regular 194 384
84if lt fd 0
85ret 17
86end
87r = fclose int fd
88if ne r 0
89ret 18
90end
91r = readlnk regular 0 len regular target 0 len target
92if ne r neg long 22
93ret 19
94end
95r = unlink regular 0 len regular
96if ne r 0
97ret 20
98end
99for i ulong len padded
100put pathcopy i get padded i
101end
102m = sub locallnk pathcopy local 11
103if ne m sub n 1
104ret 21
105end
106for i ulong ulong m
107if ne get local add 7 i get here i
108ret 22
109end
110end
111note The private path copy permits the output slice to overlap the input path safely.
112for i ulong len procwd
113put target i get procwd i
114end
115m = readlnk target 0 len procwd target 0 len target
116if ne m sub n 1
117ret 23
118end
119for i ulong ulong m
120if ne get target i get here i
121ret 24
122end
123end
124ret 0
125end