]> git.ipfire.org Git - thirdparty/bash.git/blame - builtins/psize.sh
Bash-5.2 patch 26: fix typo when specifying readline's custom color prefix
[thirdparty/bash.git] / builtins / psize.sh
CommitLineData
726f6388
JA
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
bb70624e 6: ${TMPDIR:=/tmp}
f73dda09
JA
7# try to use mktemp(1) if the system supports it
8{ TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null
9used_mktemp=true
cce855bc 10
f73dda09
JA
11if [ -z "$TMPFILE" ]; then
12 TMPNAME=pipsize.$$
13 TMPFILE=$TMPDIR/$TMPNAME
14 used_mktemp=false
15fi
16
17trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15
18trap 'rm -f "$TMPFILE"' 0
cce855bc 19
726f6388
JA
20echo "/*"
21echo " * pipesize.h"
22echo " *"
23echo " * This file is automatically generated by psize.sh"
24echo " * Do not edit!"
25echo " */"
26echo ""
27
cce855bc
JA
28#
29# Try to avoid tempfile races. We can't really check for the file's
ac50fbac 30# existence before we run psize.aux, because `test -e' is not portable,
cce855bc 31# `test -h' (test for symlinks) is not portable, and `test -f' only
f73dda09
JA
32# checks for regular files. If we used mktemp(1), we're ahead of the
33# game.
cce855bc 34#
f73dda09 35$used_mktemp || rm -f "$TMPFILE"
cce855bc 36
f73dda09 37./psize.aux 2>"$TMPFILE" | sleep 3
726f6388 38
f73dda09
JA
39if [ -s "$TMPFILE" ]; then
40 echo "#define PIPESIZE `cat "$TMPFILE"`"
726f6388
JA
41else
42 echo "#define PIPESIZE 512"
43fi
44
726f6388 45exit 0