summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-04-04 23:52:49 -0700
committerJim Meyering <meyering@fb.com>2022-04-07 09:28:24 -0700
commit5e1fc8b92c1af9382365aef0f9130341ee1d2c76 (patch)
treed88ed0b7fb7da1a57dddff365665b59e726e5a38
parent0e2d07fc2c4393cfb9dbab580d0bee4525b9c9b3 (diff)
downloadgzip-5e1fc8b92c1af9382365aef0f9130341ee1d2c76.tar.gz
maint: use C locale more often
* gzexe.in, zdiff.in, zgrep.in: Run expr and sed in the C locale when it might help to avoid undefined behavior on non-GNU platforms. * sample/zfile, znew.in: Run in the C locale, for simplicity and to avoid undefined behavior on non-GNU platforms.
-rw-r--r--gzexe.in4
-rwxr-xr-xsample/zfile3
-rw-r--r--zdiff.in4
-rw-r--r--zgrep.in29
-rw-r--r--znew.in3
5 files changed, 27 insertions, 16 deletions
diff --git a/gzexe.in b/gzexe.in
index 1a691e0..5fc7204 100644
--- a/gzexe.in
+++ b/gzexe.in
@@ -91,7 +91,7 @@ for i do
continue
fi
if test $decomp -eq 0; then
- case `sed -n -e 1d -e '/^skip=[0-9][0-9]*$/p' -e 2q "$file"` in
+ case `LC_ALL=C sed -n -e 1d -e '/^skip=[0-9][0-9]*$/p' -e 2q "$file"` in
skip=[0-9] | skip=[0-9][0-9] | skip=[0-9][0-9][0-9])
printf >&2 '%s\n' "$0: $i is already gzexe'd"
continue;;
@@ -203,7 +203,7 @@ EOF
else
# decompression
skip=44
- skip_line=`sed -e 1d -e 2q "$file"`
+ skip_line=`LC_ALL=C sed -e 1d -e 2q "$file"`
case $skip_line in
skip=[0-9] | skip=[0-9][0-9] | skip=[0-9][0-9][0-9])
eval "$skip_line";;
diff --git a/sample/zfile b/sample/zfile
index 6b4514c..d6e7a59 100755
--- a/sample/zfile
+++ b/sample/zfile
@@ -1,5 +1,8 @@
#!/bin/sh
+LC_ALL=C
+export LC_ALL
+
if test $# = 0; then
echo 'zfile: file(1) for programs which may be compressed with gzexe'
echo usage: `basename $0` files...
diff --git a/zdiff.in b/zdiff.in
index 012024e..eb4752b 100644
--- a/zdiff.in
+++ b/zdiff.in
@@ -59,7 +59,7 @@ do
--h*) printf '%s\n' "$usage" || exit 2; exit;;
--v*) printf '%s\n' "$version" || exit 2; exit;;
--) filesonly=t;;
- -*\'*) cmp="$cmp '"`printf '%sX\n' "$arg" | sed "$escape"`;;
+ -*\'*) cmp="$cmp '"`printf '%sX\n' "$arg" | LC_ALL=C sed "$escape"`;;
-[CDFISUWXx]) needop="'$arg'";;
-?*) cmp="$cmp '$arg'";;
*) case $needop in
@@ -103,7 +103,7 @@ case $file2 in
'')
case $file1 in
*[-.]gz* | *[-.][zZ] | *.t[ga]z)
- FILE=`expr "X$file1" : 'X\(.*\)[-.][zZtga]*$'`
+ FILE=`LC_ALL=C expr "X$file1" : 'X\(.*\)[-.][zZtga]*$'`
gzip_status=$(
exec 4>&1
('gzip' -cd -- "$file1" 4>&-; echo $? >&4) 3>&- |
diff --git a/zgrep.in b/zgrep.in
index 6a16dd1..2cb2426 100644
--- a/zgrep.in
+++ b/zgrep.in
@@ -64,30 +64,33 @@ while test $# -ne 0; do
case $option in
(-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]*[!0123456789]*)
- arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
+ arg2=-\'$(LC_ALL=C expr "X$option" : 'X-.[0-9]*\(.*\)' |
+ LC_ALL=C sed "$escape")
eval "set -- $arg2 "'${1+"$@"}'
- option=$(expr "X$option" : 'X\(-.[0-9]*\)');;
+ option=$(LC_ALL=C expr "X$option" : 'X\(-.[0-9]*\)');;
(--binary-*=* | --[lm]a*=* | --reg*=*)
;;
(-[ABCDXdefm] | --binary-* | --file | --[lm]a* | --reg*)
case ${1?"$option option requires an argument"} in
(*\'*)
- optarg=" '"$(printf '%s\n' "$1" | sed "$escape");;
+ optarg=" '"$(printf '%s\n' "$1" | LC_ALL=C sed "$escape");;
(*)
optarg=" '$1'";;
esac
shift;;
(-f?*\'*)
- optarg=" '"$(expr "X$option" : 'X-f\(.*\)' | sed "$escape")
+ optarg=" '"$(LC_ALL=C expr "X$option" : 'X-f\(.*\)' |
+ LC_ALL=C sed "$escape")
option=-f;;
(-f?*)
- optarg=" '"$(expr "X$option" : 'X-f\(.*\)')\'
+ optarg=" '"$(LC_ALL=C expr "X$option" : 'X-f\(.*\)')\'
option=-f;;
(--file=*\'*)
- optarg=" '"$(expr "X$option" : 'X--file=\(.*\)' | sed "$escape")
+ optarg=" '"$(LC_ALL=C expr "X$option" : 'X--file=\(.*\)' |
+ LC_ALL=C sed "$escape")
option=--file;;
(--file=*)
- optarg=" '"$(expr "X$option" : 'X--file=\(.*\)')\'
+ optarg=" '"$(LC_ALL=C expr "X$option" : 'X--file=\(.*\)')\'
option=--file;;
(--)
break;;
@@ -96,7 +99,8 @@ while test $# -ne 0; do
(*)
case $option in
(*\'*)
- operands="$operands '"$(printf '%s\n' "$option" | sed "$escape");;
+ operands="$operands '"$(printf '%s\n' "$option" | LC_ALL=C sed "$escape")
+ ;;
(*)
operands="$operands '$option'";;
esac
@@ -169,7 +173,7 @@ while test $# -ne 0; do
case $option in
(*\'?*)
- option=\'$(printf '%s\n' "$option" | sed "$escape");;
+ option=\'$(printf '%s\n' "$option" | LC_ALL=C sed "$escape");;
(*)
option="'$option'";;
esac
@@ -182,7 +186,7 @@ eval "set -- $operands "'${1+"$@"}'
if test $have_pat -eq 0; then
case ${1?"missing pattern; try \`$0 --help' for help"} in
(*\'*)
- grep="$grep -- '"$(printf '%s\n' "$1" | sed "$escape");;
+ grep="$grep -- '"$(printf '%s\n' "$1" | LC_ALL=C sed "$escape");;
(*)
grep="$grep -- '$1'";;
esac
@@ -221,7 +225,7 @@ do
(*'
'* | *'&'* | *'\'* | *'|'*)
icolon=$(printf '%s\n' "$i:" |
- sed -e 's/[&\|]/\\&/g' -e '$!s/$/\\/');;
+ LC_ALL=C sed -e 's/[&\|]/\\&/g' -e '$!s/$/\\/');;
(*) icolon="$i:";;
esac
sed_script="s|^|$icolon|"
@@ -229,7 +233,8 @@ do
# Fail if grep or sed fails.
r=$(
exec 4>&1
- (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&-
+ (eval "$grep" 4>&-; echo $? >&4) 3>&- |
+ LC_ALL=C sed "$sed_script" >&3 4>&-
) || { r=$?; test $r -lt 2 && r=2; }
test 256 -le $r && r=$(expr 128 + $r % 128)
exit $r
diff --git a/znew.in b/znew.in
index 45d0764..ea76a22 100644
--- a/znew.in
+++ b/znew.in
@@ -18,6 +18,9 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+LC_ALL=C
+export LC_ALL
+
version="znew (gzip) @VERSION@
Copyright (C) 2010-2018 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of