Bash-4.3 distribution sources and documentation
[platform/upstream/bash.git] / builtins / psize.sh
1 #! /bin/sh
2 #
3 # psize.sh -- determine this system's pipe size, and write a define to
4 #             pipesize.h so ulimit.c can use it.
5
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
10
11 if [ -z "$TMPFILE" ]; then
12         TMPNAME=pipsize.$$
13         TMPFILE=$TMPDIR/$TMPNAME
14         used_mktemp=false
15 fi
16
17 trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15
18 trap 'rm -f "$TMPFILE"' 0
19
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 ""
27
28 #
29 # Try to avoid tempfile races.  We can't really check for the file's
30 # existence 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.
34 #
35 $used_mktemp || rm -f "$TMPFILE"
36
37 ./psize.aux 2>"$TMPFILE" | sleep 3
38
39 if [ -s "$TMPFILE" ]; then
40         echo "#define PIPESIZE `cat "$TMPFILE"`"
41 else
42         echo "#define PIPESIZE 512"
43 fi
44
45 exit 0