When locale is enabled, sprintf("%.123s", str) is counting characters, not bytes...
authorRob Landley <rob@landley.net>
Mon, 9 Jun 2014 10:51:04 +0000 (05:51 -0500)
committerRob Landley <rob@landley.net>
Mon, 9 Jun 2014 10:51:04 +0000 (05:51 -0500)
toys.h
toys/posix/expand.c
toys/posix/wc.c

diff --git a/toys.h b/toys.h
index 6666cfb..9fd338a 100644 (file)
--- a/toys.h
+++ b/toys.h
@@ -105,6 +105,10 @@ void toy_exec(char *argv[]);
 #define TOYFLAG_NEEDROOT (1<<7)
 #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<<8)
+
 // Array of available commands
 
 extern struct toy_list {
index e23dc27..7e668fa 100644 (file)
@@ -4,7 +4,7 @@
  *
  * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expand.html
 
-USE_EXPAND(NEWTOY(expand, "t*", TOYFLAG_USR|TOYFLAG_BIN))
+USE_EXPAND(NEWTOY(expand, "t*", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
 
 config EXPAND
   bool "expand"
index 3a6540b..815e08b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * See http://opengroup.org/onlinepubs/9699919799/utilities/wc.html
 
-USE_WC(NEWTOY(wc, USE_TOYBOX_I18N("m")"cwl", TOYFLAG_USR|TOYFLAG_BIN))
+USE_WC(NEWTOY(wc, USE_TOYBOX_I18N("m")"cwl", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
 
 config WC
   bool "wc"