From 4e47b8e583903752c08a29873ffcb868173c70d8 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 11 Dec 2020 19:50:36 -0600 Subject: The "fall back to C.UTF-8" check was backwards, and make TOYFLAG_LINEBUF configurable. --- lib/toyflags.h | 3 +++ main.c | 7 ++++--- toys/posix/grep.c | 6 +++--- 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 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