raz / test / libc / ExecOpenedC.raz

17 lines · 605 B · raw · history · last change 89524972

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. *)
4module ExecOpenedC;
5import Sys;
6
7proc main*: INT;
8var a, b: INT;
9begin
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"]});
15end;
16
17end ExecOpenedC.