From f316a2ed52195135a35e32d7096e876357c48c69 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 20:03:23 +0000 Subject: initial commit: rc for execline-2.0.0.0 --- doc/fdreserve.html | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 doc/fdreserve.html (limited to 'doc/fdreserve.html') diff --git a/doc/fdreserve.html b/doc/fdreserve.html new file mode 100644 index 0000000..ef047dc --- /dev/null +++ b/doc/fdreserve.html @@ -0,0 +1,92 @@ + + + + + execline: the fdreserve program + + + + + + +

+execline
+Software
+skarnet.org +

+ +

The fdreserve program

+ +

+fdreserve updates the environment with file descriptors that +are guaranteed safe to use, then executes a program. +

+ +

Interface

+ +
+     fdreserve n prog...
+
+ + + +

Common use

+ +

+fdreserve can be used when you do not want to hardcode file +descriptors in your scripts. For instance, to create a pipe, you could +use: +

+ +
+ #!/command/execlineb
+ fdreserve 2
+ multisubstitute
+ {
+   importas fdr FD0
+   importas fdw FD1
+  }
+ piperw $fdr $fdw
+ prog...
+
+ +

+ Warning: fdreserve does not allocate descriptors, it merely returns +descriptors that are free at the time it is run. A program like +

+ +
+ #!/command/execlineb
+ fdreserve 3
+ multisubstitute
+ {
+   importas fdr FD0
+   importas fdw FD1
+ }
+ piperw $fdr $fdw
+ fdreserve 1
+ multisubstitute
+ {
+   importas oldfd FD2
+   importas newfd FD0
+ }
+ prog...
+
+ +

+may fail, because oldfd and newfd may be the same. +To avoid that, you should make sure that all descriptors returned by +fdreserve are actually allocated before calling fdreserve +again. +(Thanks to Paul Jarc for having +spotted that case.) +

+ + + -- cgit v1.2.3