From 772f20abb0a3a0979c440114bf3a1cff5b3cef03 Mon Sep 17 00:00:00 2001 From: cvpcs Date: Wed, 2 Jun 2010 11:02:31 -0500 Subject: initial import of bash 4.1 --- builtins/psize.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 builtins/psize.sh (limited to 'builtins/psize.sh') diff --git a/builtins/psize.sh b/builtins/psize.sh new file mode 100644 index 0000000..c4d73e1 --- /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 +# existance 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 -- cgit v1.1