3aa99676b4
This version fixes a regression with regard to tradtional behavior of the non-standard FreeBSD option "-e". In the previous version "-e quit" caused bc to exit before any computations had been performed, since all -e option parameters were concatenated and parsed as a whole, with quit causing the program to exit as soon as it was parsed. This version parses and executes commands passed with -e one by one and only exits after all prior commands have been executed. This commit is not a SVN merge, since the vendor import had been performed after the import to contrib. Instead the contents of contrib/bc has been removed and the new version is copied over unchanged from vendor/bc/dist.
68 lines
1.0 KiB
Bash
Executable File
68 lines
1.0 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Written by Rich Felker, originally as part of musl libc.
|
|
# Multi-licensed under MIT, 0BSD, and CC0.
|
|
#
|
|
# This is an actually-safe install command which installs the new
|
|
# file atomically in the new location, rather than overwriting
|
|
# existing files.
|
|
#
|
|
|
|
usage() {
|
|
printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
|
|
exit 1
|
|
}
|
|
|
|
mkdirp=
|
|
symlink=
|
|
mode=755
|
|
|
|
while getopts Dlm: name ; do
|
|
case "$name" in
|
|
D) mkdirp=yes ;;
|
|
l) symlink=yes ;;
|
|
m) mode=$OPTARG ;;
|
|
?) usage ;;
|
|
esac
|
|
done
|
|
shift $(($OPTIND - 1))
|
|
|
|
test "$#" -eq 2 || usage
|
|
src=$1
|
|
dst=$2
|
|
tmp="$dst.tmp.$$"
|
|
|
|
case "$dst" in
|
|
*/) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
|
|
esac
|
|
|
|
set -C
|
|
set -e
|
|
|
|
if test "$mkdirp" ; then
|
|
umask 022
|
|
case "$2" in
|
|
*/*) mkdir -p "${dst%/*}" ;;
|
|
esac
|
|
fi
|
|
|
|
trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
|
|
|
|
umask 077
|
|
|
|
if test "$symlink" ; then
|
|
ln -s "$1" "$tmp"
|
|
else
|
|
cat < "$1" > "$tmp"
|
|
chmod "$mode" "$tmp"
|
|
fi
|
|
|
|
mv -f "$tmp" "$2"
|
|
test -d "$2" && {
|
|
rm -f "$2/$tmp"
|
|
printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
|
|
exit 1
|
|
}
|
|
|
|
exit 0
|