diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2022-04-04 23:52:49 -0700 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2022-04-07 09:28:24 -0700 |
commit | 5e1fc8b92c1af9382365aef0f9130341ee1d2c76 (patch) | |
tree | d88ed0b7fb7da1a57dddff365665b59e726e5a38 | |
parent | 0e2d07fc2c4393cfb9dbab580d0bee4525b9c9b3 (diff) | |
download | gzip-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.in | 4 | ||||
-rwxr-xr-x | sample/zfile | 3 | ||||
-rw-r--r-- | zdiff.in | 4 | ||||
-rw-r--r-- | zgrep.in | 29 | ||||
-rw-r--r-- | znew.in | 3 |
5 files changed, 27 insertions, 16 deletions
@@ -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... @@ -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>&- | @@ -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 @@ -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 |