Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/host/tests/location.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / host / tests / location.om` 125 lines ยท 2457 bytes Raw Blame History 1 note cwd includes its trailing zero in the count; readlnk returns raw bytes without a terminator. 2 global here uchar 4096 3 global target uchar 4096 4 text procwd "/proc/self/cwd" 5 text padded "_/proc/self/cwd_" 6 text procexe "/proc/self/exe" 7 text suffix "/location" 8 text absent "missing-link-target" 9 text regular "regular-file" 10 fn localcwd result edit uchar 4096 to long 11 ret add long 7 cwd result 3 4000 12 end 13 fn locallnk path view uchar 16 result edit uchar 4096 to long 14 ret add long 11 readlnk path 1 14 result 7 4000 15 end 16 fn main to int 17 local = new uchar 4096 85 18 pathcopy = new uchar 16 0 19 n = sub localcwd local 7 20 if or le n 1 gt n 4000 21 ret 1 22 end 23 if or ne get local 2 85 ne get local add 3 ulong n 85 24 ret 2 25 end 26 if or ne get local 3 47 ne get local add 2 ulong n 0 27 ret 3 28 end 29 m = cwd here 0 ulong n 30 if ne m n 31 ret 4 32 end 33 for i ulong ulong n 34 if ne get here i get local add 3 i 35 ret 5 36 end 37 end 38 if ne cwd here 0 sub ulong n 1 neg long 34 39 ret 6 40 end 41 if ne cwd here 0 0 neg long 34 42 ret 7 43 end 44 for i ulong len target 45 put target i 85 46 end 47 m = readlnk procwd 0 len procwd target 5 4000 48 if ne m sub n 1 49 ret 8 50 end 51 for i ulong ulong m 52 if ne get target add 5 i get local add 3 i 53 ret 9 54 end 55 end 56 if or ne get target 4 85 ne get target add 5 ulong m 85 57 ret 10 58 end 59 m = readlnk procwd 0 len procwd target 0 1 60 if or ne m 1 ne get target 0 47 61 ret 11 62 end 63 if ne readlnk procwd 0 len procwd target 0 0 neg long 22 64 ret 12 65 end 66 m = readlnk procexe 0 len procexe target 0 len target 67 if ne m long add sub ulong n 1 len suffix 68 ret 13 69 end 70 for i ulong sub ulong n 1 71 if ne get target i get local add 3 i 72 ret 14 73 end 74 end 75 for i ulong len suffix 76 if ne get target add sub ulong n 1 i get suffix i 77 ret 15 78 end 79 end 80 if ne readlnk absent 0 len absent target 0 len target neg long 2 81 ret 16 82 end 83 fd = fopen regular 0 len regular 194 384 84 if lt fd 0 85 ret 17 86 end 87 r = fclose int fd 88 if ne r 0 89 ret 18 90 end 91 r = readlnk regular 0 len regular target 0 len target 92 if ne r neg long 22 93 ret 19 94 end 95 r = unlink regular 0 len regular 96 if ne r 0 97 ret 20 98 end 99 for i ulong len padded 100 put pathcopy i get padded i 101 end 102 m = sub locallnk pathcopy local 11 103 if ne m sub n 1 104 ret 21 105 end 106 for i ulong ulong m 107 if ne get local add 7 i get here i 108 ret 22 109 end 110 end 111 note The private path copy permits the output slice to overlap the input path safely. 112 for i ulong len procwd 113 put target i get procwd i 114 end 115 m = readlnk target 0 len procwd target 0 len target 116 if ne m sub n 1 117 ret 23 118 end 119 for i ulong ulong m 120 if ne get target i get here i 121 ret 24 122 end 123 end 124 ret 0 125 end