i-bash/builtins/psize.sh

46 lines
1 KiB
Bash
Raw Normal View History

1996-08-26 18:22:31 +00:00
#! /bin/sh
#
# psize.sh -- determine this system's pipe size, and write a define to
# pipesize.h so ulimit.c can use it.
2000-03-17 21:46:59 +00:00
: ${TMPDIR:=/tmp}
2001-11-13 17:56:06 +00:00
# try to use mktemp(1) if the system supports it
{ TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null
used_mktemp=true
1998-04-17 19:52:44 +00:00
2001-11-13 17:56:06 +00:00
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
1998-04-17 19:52:44 +00:00
1996-08-26 18:22:31 +00:00
echo "/*"
echo " * pipesize.h"
echo " *"
echo " * This file is automatically generated by psize.sh"
echo " * Do not edit!"
echo " */"
echo ""
1998-04-17 19:52:44 +00:00
#
# 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,
1998-04-17 19:52:44 +00:00
# `test -h' (test for symlinks) is not portable, and `test -f' only
2001-11-13 17:56:06 +00:00
# checks for regular files. If we used mktemp(1), we're ahead of the
# game.
1998-04-17 19:52:44 +00:00
#
2001-11-13 17:56:06 +00:00
$used_mktemp || rm -f "$TMPFILE"
1998-04-17 19:52:44 +00:00
2001-11-13 17:56:06 +00:00
./psize.aux 2>"$TMPFILE" | sleep 3
1996-08-26 18:22:31 +00:00
2001-11-13 17:56:06 +00:00
if [ -s "$TMPFILE" ]; then
echo "#define PIPESIZE `cat "$TMPFILE"`"
1996-08-26 18:22:31 +00:00
else
echo "#define PIPESIZE 512"
fi
exit 0