| 1 | (* Over the C library: a file open gives is closed in the program exec |
| 2 | runs, unless keepOnExec says to keep it: of two opened files, sh sees |
| 3 | the second, in /dev/fd, which Linux and macOS have alike. *) |
| 4 | module ExecOpenedC; |
| 5 | import Sys; |
| 6 | |
| 7 | proc main*: INT; |
| 8 | var a, b: INT; |
| 9 | begin |
| 10 | a := Sys.openRead("/dev/null"); |
| 11 | b := Sys.create("/dev/null"); |
| 12 | if (a # 3) or (b # 4) or (Sys.keepOnExec(b, true) # 0) then return 1; end; |
| 13 | return Sys.exec({path: "sh", |
| 14 | args: ["sh", "-c", "for n in 3 4; do if [ -e /dev/fd/$n ]; then echo open $n; else echo closed $n; fi; done"]}); |
| 15 | end; |
| 16 | |
| 17 | end ExecOpenedC. |