upgrade
[rrq/rrqforth.git] / examples / fds.f
1 #!/home/ralph/src/devuan/rrqforth/rrqforth
2 #
3 # List file descriptors
4
5 SYSTEM DEFINITIONS
6
7 ### using execve
8 # Prepare empty environment on data stack and save pointer on return stack
9 0 0 D[n] >R
10
11 # Prepare the arg array on data stack and save pointer on return stack
12 0 " /proc/self/fd" DROP " -l" DROP " /bin/ls" DROP 0 D[n] >R
13
14 # The program to execute, arguments and environment
15 " /bin/ls" DROP  0 R[n] @  1 R[n] @  SYS_EXECVE
16
17 # Shouldn't come here, but in case...
18 " ERROR" TELL NL EMIT
19 1 EXIT