From 593bd728fc12573885191471b2978ae4fb0e28fa Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 20 Sep 2023 06:46:07 -0500 Subject: [PATCH] Remove TOYFLAG_LOCALE. We've unconditionally set a utf8 locale in main.c for a while, and sprintf("%.*s", len, str) is explicitly a _byte_ restriction in posix. --- lib/toyflags.h | 8 ++------ toys/other/fmt.c | 2 +- toys/other/hexedit.c | 2 +- toys/other/watch.c | 2 +- toys/pending/bc.c | 2 +- toys/posix/expand.c | 2 +- toys/posix/ls.c | 2 +- toys/posix/paste.c | 2 +- toys/posix/ps.c | 6 +++--- toys/posix/sed.c | 2 +- toys/posix/wc.c | 2 +- 11 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/toyflags.h b/lib/toyflags.h index 0c65735c..ab8e4f5b 100644 --- a/lib/toyflags.h +++ b/lib/toyflags.h @@ -25,15 +25,11 @@ #define TOYFLAG_NEEDROOT (1<<8) // Refuse to run if real uid != 0 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT) -// Call setlocale to listen to environment variables. -// This invalidates sprintf("%.*s", size, string) as a valid length constraint. -#define TOYFLAG_LOCALE (1<<9) - // Suppress default --help processing -#define TOYFLAG_NOHELP (1<<10) +#define TOYFLAG_NOHELP (1<<9) // Line buffered stdout -#define TOYFLAG_LINEBUF (1<<11) +#define TOYFLAG_LINEBUF (1<<10) // Error code to return if argument parsing fails (default 1) #define TOYFLAG_ARGFAIL(x) (x<<24) diff --git a/toys/other/fmt.c b/toys/other/fmt.c index 744d67a3..0061cc0d 100644 --- a/toys/other/fmt.c +++ b/toys/other/fmt.c @@ -9,7 +9,7 @@ * together runs of whitespace. No header/footer logic, no end-of-sentence * double-space, preserves initial tab/space mix when indenting new lines. -USE_FMT(NEWTOY(fmt, "w#<0=75", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_FMT(NEWTOY(fmt, "w#<0=75", TOYFLAG_USR|TOYFLAG_BIN)) config FMT bool "fmt" diff --git a/toys/other/hexedit.c b/toys/other/hexedit.c index 4550dc34..80631ac1 100644 --- a/toys/other/hexedit.c +++ b/toys/other/hexedit.c @@ -4,7 +4,7 @@ * * No standard. -USE_HEXEDIT(NEWTOY(hexedit, "<1>1r", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_HEXEDIT(NEWTOY(hexedit, "<1>1r", TOYFLAG_USR|TOYFLAG_BIN)) config HEXEDIT bool "hexedit" diff --git a/toys/other/watch.c b/toys/other/watch.c index 06559e25..424b0ae0 100644 --- a/toys/other/watch.c +++ b/toys/other/watch.c @@ -6,7 +6,7 @@ * No standard. See http://man7.org/linux/man-pages/man1/watch.1.html * * TODO: trailing combining characters -USE_WATCH(NEWTOY(watch, "^<1n%<100=2000tebx", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_WATCH(NEWTOY(watch, "^<1n%<100=2000tebx", TOYFLAG_USR|TOYFLAG_BIN)) config WATCH bool "watch" diff --git a/toys/pending/bc.c b/toys/pending/bc.c index 1288fabb..c5af1405 100644 --- a/toys/pending/bc.c +++ b/toys/pending/bc.c @@ -4,7 +4,7 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html -USE_BC(NEWTOY(bc, "i(interactive)l(mathlib)q(quiet)s(standard)w(warn)", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_BC(NEWTOY(bc, "i(interactive)l(mathlib)q(quiet)s(standard)w(warn)", TOYFLAG_USR|TOYFLAG_BIN)) config BC bool "bc" diff --git a/toys/posix/expand.c b/toys/posix/expand.c index e15d30d3..baa75633 100644 --- a/toys/posix/expand.c +++ b/toys/posix/expand.c @@ -4,7 +4,7 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expand.html -USE_EXPAND(NEWTOY(expand, "t*", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_EXPAND(NEWTOY(expand, "t*", TOYFLAG_USR|TOYFLAG_BIN)) config EXPAND bool "expand" diff --git a/toys/posix/ls.c b/toys/posix/ls.c index f3a5e92b..3addd451 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -13,7 +13,7 @@ * Deviations from gnu: -N switches off -q (no --show-control-chars) * No --quoting-style=shell-escape, mostly because no short or long opt for it -USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\377(block-size)#=1024<1\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb][-k\377]", TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\377(block-size)#=1024<1\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb][-k\377]", TOYFLAG_BIN)) config LS bool "ls" diff --git a/toys/posix/paste.c b/toys/posix/paste.c index 43c25696..173c97f3 100644 --- a/toys/posix/paste.c +++ b/toys/posix/paste.c @@ -6,7 +6,7 @@ * * Deviations from posix: the FILE argument isn't mandatory, none == '-' -USE_PASTE(NEWTOY(paste, "d:s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_PASTE(NEWTOY(paste, "d:s", TOYFLAG_USR|TOYFLAG_BIN)) config PASTE bool "paste" diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 2ff3ba73..d0992619 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -45,12 +45,12 @@ * TODO: pgrep -f only searches the amount of cmdline that fits in toybuf. * TODO: pgrep qemu-system-i386 never matches because one char too long -USE_PS(NEWTOY(ps, "k(sort)*P(ppid)*aAdeflMno*O*p(pid)*s*t*Tu*U*g*G*wZ[!ol][+Ae][!oO]", TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_PS(NEWTOY(ps, "k(sort)*P(ppid)*aAdeflMno*O*p(pid)*s*t*Tu*U*g*G*wZ[!ol][+Ae][!oO]", TOYFLAG_BIN)) // stayroot because iotop needs root to read other process' proc/$$/io // TOP and IOTOP have a large common option block used for common processing, // the default values are different but the flags are in the same order. -USE_TOP(NEWTOY(top, ">0O*h" "Hk*o*p*u*s#<1d%<100=3000m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) -USE_IOTOP(NEWTOY(iotop, ">0AaKO" "Hk*o*p*u*s#<1=7d%<100=3000m#n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE)) +USE_TOP(NEWTOY(top, ">0O*h" "Hk*o*p*u*s#<1d%<100=3000m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_IOTOP(NEWTOY(iotop, ">0AaKO" "Hk*o*p*u*s#<1=7d%<100=3000m#n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT)) USE_PGREP(NEWTOY(pgrep, "?cld:u*U*t*s*P*g*G*fnovxL:[-no]", TOYFLAG_USR|TOYFLAG_BIN)) USE_PKILL(NEWTOY(pkill, "?Vu*U*t*s*P*g*G*fnovxl:[-no]", TOYFLAG_USR|TOYFLAG_BIN)) diff --git a/toys/posix/sed.c b/toys/posix/sed.c index a2469fa7..e6e13972 100644 --- a/toys/posix/sed.c +++ b/toys/posix/sed.c @@ -22,7 +22,7 @@ * print, l escapes \n * Added --tarxform mode to support tar --xform -USE_SED(NEWTOY(sed, "(help)(version)(tarxform)e*f*i:;nErz(null-data)s[+Er]", TOYFLAG_BIN|TOYFLAG_LOCALE|TOYFLAG_NOHELP)) +USE_SED(NEWTOY(sed, "(help)(version)(tarxform)e*f*i:;nErz(null-data)s[+Er]", TOYFLAG_BIN|TOYFLAG_NOHELP)) config SED bool "sed" diff --git a/toys/posix/wc.c b/toys/posix/wc.c index 118e7750..31df00e5 100644 --- a/toys/posix/wc.c +++ b/toys/posix/wc.c @@ -4,7 +4,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/wc.html -USE_WC(NEWTOY(wc, "mcwl", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_WC(NEWTOY(wc, "mcwl", TOYFLAG_USR|TOYFLAG_BIN)) config WC bool "wc" -- 2.39.2