aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-12-11 19:50:36 -0600
committerRob Landley <rob@landley.net>2020-12-11 19:50:36 -0600
commit4e47b8e583903752c08a29873ffcb868173c70d8 (patch)
tree08311d13e1942b49cd64671ad83e63b9336b6033
parent2fa16e73fba0e908309aadad4d4668b86a1134e5 (diff)
downloadtoybox-4e47b8e583903752c08a29873ffcb868173c70d8.tar.gz
The "fall back to C.UTF-8" check was backwards, and make TOYFLAG_LINEBUF
configurable.
-rw-r--r--lib/toyflags.h3
-rw-r--r--main.c7
-rw-r--r--toys/posix/grep.c6
3 files changed, 10 insertions, 6 deletions
diff --git a/lib/toyflags.h b/lib/toyflags.h
index b158ba88..c8830874 100644
--- a/lib/toyflags.h
+++ b/lib/toyflags.h
@@ -32,6 +32,9 @@
// Suppress default --help processing
#define TOYFLAG_NOHELP (1<<10)
+// Line buffered stdout
+#define TOYFLAG_LINEBUF (1<<11)
+
// Error code to return if argument parsing fails (default 1)
#define TOYFLAG_ARGFAIL(x) (x<<24)
diff --git a/main.c b/main.c
index 25e4c472..430e7f95 100644
--- a/main.c
+++ b/main.c
@@ -101,8 +101,8 @@ void toy_singleinit(struct toy_list *which, char *argv[])
// Try user's locale, falling back to C.UTF-8
setlocale(LC_CTYPE, "");
- if (!strcmp("UTF-8", nl_langinfo(CODESET))) setlocale(LC_CTYPE, "C.UTF-8");
- setlinebuf(stdout);
+ if (strcmp("UTF-8", nl_langinfo(CODESET))) setlocale(LC_CTYPE, "C.UTF-8");
+ setvbuf(stdout, 0, (which->flags & TOYFLAG_LINEBUF) ? _IOLBF : _IONBF, 0);
}
}
@@ -213,11 +213,12 @@ void toybox_main(void)
xputc('\n');
}
+#include <malloc.h>
int main(int argc, char *argv[])
{
// don't segfault if our environment is crazy
if (!*argv) return 127;
-
+mallopt(M_CHECK_ACTION, 1);
// Snapshot stack location so we can detect recursion depth later.
// Nommu has special reentry path, !stacktop = "vfork/exec self happened"
if (!CFG_TOYBOX_FORK && (0x80 & **argv)) **argv &= 0x7f;
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 9f445fca..fce8d564 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -10,9 +10,9 @@
* echo hello | grep -f </dev/null
*
-USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
-USE_EGREP(OLDTOY(egrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
-USE_FGREP(OLDTOY(fgrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)))
+USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
+USE_EGREP(OLDTOY(egrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
+USE_FGREP(OLDTOY(fgrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
config GREP
bool "grep"