summaryrefslogtreecommitdiffstats
path: root/builtins/psize.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:17:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:17:24 +0000
commit9d8085074991d5c0a42d6fc96a2d1a3ee918aad1 (patch)
treec85bca1e6c11eb872edfc64c524d20f2b7e3307b /builtins/psize.sh
parentInitial commit. (diff)
downloadbash-9d8085074991d5c0a42d6fc96a2d1a3ee918aad1.tar.xz
bash-9d8085074991d5c0a42d6fc96a2d1a3ee918aad1.zip
Adding upstream version 5.1.upstream/5.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'builtins/psize.sh')
-rw-r--r--builtins/psize.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/builtins/psize.sh b/builtins/psize.sh
new file mode 100644
index 0000000..29bc115
--- /dev/null
+++ b/builtins/psize.sh
@@ -0,0 +1,45 @@
+#! /bin/sh
+#
+# psize.sh -- determine this system's pipe size, and write a define to
+# pipesize.h so ulimit.c can use it.
+
+: ${TMPDIR:=/tmp}
+# try to use mktemp(1) if the system supports it
+{ TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null
+used_mktemp=true
+
+if [ -z "$TMPFILE" ]; then
+ TMPNAME=pipsize.$$
+ TMPFILE=$TMPDIR/$TMPNAME
+ used_mktemp=false
+fi
+
+trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15
+trap 'rm -f "$TMPFILE"' 0
+
+echo "/*"
+echo " * pipesize.h"
+echo " *"
+echo " * This file is automatically generated by psize.sh"
+echo " * Do not edit!"
+echo " */"
+echo ""
+
+#
+# Try to avoid tempfile races. We can't really check for the file's
+# existence before we run psize.aux, because `test -e' is not portable,
+# `test -h' (test for symlinks) is not portable, and `test -f' only
+# checks for regular files. If we used mktemp(1), we're ahead of the
+# game.
+#
+$used_mktemp || rm -f "$TMPFILE"
+
+./psize.aux 2>"$TMPFILE" | sleep 3
+
+if [ -s "$TMPFILE" ]; then
+ echo "#define PIPESIZE `cat "$TMPFILE"`"
+else
+ echo "#define PIPESIZE 512"
+fi
+
+exit 0