Patch-ID: bash32-017
[bash.git] / builtins / psize.sh
blobc4d73e1ad0f403b06957f80af1e9905d0beae4c6
1 #! /bin/sh
3 # psize.sh -- determine this system's pipe size, and write a define to
4 # pipesize.h so ulimit.c can use it.
6 : ${TMPDIR:=/tmp}
7 # try to use mktemp(1) if the system supports it
8 { TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null
9 used_mktemp=true
11 if [ -z "$TMPFILE" ]; then
12 TMPNAME=pipsize.$$
13 TMPFILE=$TMPDIR/$TMPNAME
14 used_mktemp=false
17 trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15
18 trap 'rm -f "$TMPFILE"' 0
20 echo "/*"
21 echo " * pipesize.h"
22 echo " *"
23 echo " * This file is automatically generated by psize.sh"
24 echo " * Do not edit!"
25 echo " */"
26 echo ""
29 # Try to avoid tempfile races. We can't really check for the file's
30 # existance before we run psize.aux, because `test -e' is not portable,
31 # `test -h' (test for symlinks) is not portable, and `test -f' only
32 # checks for regular files. If we used mktemp(1), we're ahead of the
33 # game.
35 $used_mktemp || rm -f "$TMPFILE"
37 ./psize.aux 2>"$TMPFILE" | sleep 3
39 if [ -s "$TMPFILE" ]; then
40 echo "#define PIPESIZE `cat "$TMPFILE"`"
41 else
42 echo "#define PIPESIZE 512"
45 exit 0