another example
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 11 Jun 2021 10:24:17 +0000 (20:24 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 11 Jun 2021 10:24:17 +0000 (20:24 +1000)
examples/fds.f [new file with mode: 0755]

diff --git a/examples/fds.f b/examples/fds.f
new file mode 100755 (executable)
index 0000000..9211ef0
--- /dev/null
@@ -0,0 +1,19 @@
+#!/home/ralph/src/devuan/rrqforth/rrqforth
+#
+# List file descriptors
+
+SYSTEM DEFINITIONS
+
+### using execve
+# Prepare empty environment on data stack and save pointer on return stack
+0 0 D[n] >R
+
+# Prepare the arg array on data stack and save pointer on return stack
+0 " /proc/self/fd" DROP " -l" DROP " /bin/ls" DROP 0 D[n] >R
+
+# The program to execute, arguments and environment
+" /bin/ls" DROP  0 R[n] @  1 R[n] @  SYS_EXECVE
+
+# Shouldn't come here, but in case...
+" ERROR" TELL NL EMIT
+1 EXIT