From 04650ef7f6167d59aad19d4cd6fc78b2d84c83e5 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 10 Jul 2014 19:38:01 -0700 Subject: [PATCH] Sync with upstream grep. Change-Id: Ie1da2e95ee7e3513afb87f357be983dc80cd1515 --- toolbox/bsd-compatibility.h | 3 +++ toolbox/grep/grep.c | 10 +++++----- toolbox/grep/grep.h | 4 ---- toolbox/grep/util.c | 21 +++++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/toolbox/bsd-compatibility.h b/toolbox/bsd-compatibility.h index a3046317a..abc306490 100644 --- a/toolbox/bsd-compatibility.h +++ b/toolbox/bsd-compatibility.h @@ -31,6 +31,9 @@ /* We want chown to support user.group as well as user:group. */ #define SUPPORT_DOT +/* We don't localize /system/bin! */ +#define WITHOUT_NLS + __BEGIN_DECLS extern int uid_from_user(const char* name, uid_t* uid); diff --git a/toolbox/grep/grep.c b/toolbox/grep/grep.c index 7dc4bcc39..7314e13f3 100644 --- a/toolbox/grep/grep.c +++ b/toolbox/grep/grep.c @@ -402,7 +402,7 @@ grep_main(int argc, char *argv[]) Aflag = 0; else if (Aflag > LLONG_MAX / 10) { errno = ERANGE; - err(2, "%llu", Aflag); + err(2, NULL); } Aflag = Bflag = (Aflag * 10) + (c - '0'); break; @@ -419,10 +419,10 @@ grep_main(int argc, char *argv[]) l = strtoull(optarg, &ep, 10); if (((errno == ERANGE) && (l == ULLONG_MAX)) || ((errno == EINVAL) && (l == 0))) - err(2, "strtoull"); + err(2, NULL); else if (ep[0] != '\0') { errno = EINVAL; - err(2, "empty"); + err(2, NULL); } if (c == 'A') Aflag = l; @@ -508,10 +508,10 @@ grep_main(int argc, char *argv[]) mcount = strtoull(optarg, &ep, 10); if (((errno == ERANGE) && (mcount == ULLONG_MAX)) || ((errno == EINVAL) && (mcount == 0))) - err(2, "strtoull"); + err(2, NULL); else if (ep[0] != '\0') { errno = EINVAL; - err(2, "empty"); + err(2, NULL); } break; case 'n': diff --git a/toolbox/grep/grep.h b/toolbox/grep/grep.h index 6454f9362..eafb00e21 100644 --- a/toolbox/grep/grep.h +++ b/toolbox/grep/grep.h @@ -29,10 +29,6 @@ * SUCH DAMAGE. */ -#ifdef ANDROID -#define WITHOUT_NLS -#endif - #ifndef ANDROID #include #endif diff --git a/toolbox/grep/util.c b/toolbox/grep/util.c index 5712feeac..c1c17e449 100644 --- a/toolbox/grep/util.c +++ b/toolbox/grep/util.c @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $ */ +/* $NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $"); #include #include @@ -74,9 +74,10 @@ file_matching(const char *fname) for (i = 0; i < fpatterns; ++i) { if (fnmatch(fpattern[i].pat, fname, 0) == 0 || fnmatch(fpattern[i].pat, fname_base, 0) == 0) { - if (fpattern[i].mode == EXCL_PAT) + if (fpattern[i].mode == EXCL_PAT) { + free(fname_copy); return (false); - else + } else ret = true; } } @@ -128,7 +129,7 @@ grep_tree(char **argv) break; default: fts_flags = FTS_LOGICAL; - + } fts_flags |= FTS_NOSTAT | FTS_NOCHDIR; @@ -273,7 +274,7 @@ procfile(const char *fn) return (c); } -#define iswword(x) (iswalnum((wint_t)(x)) || (x) == L'_') +#define iswword(x) (iswalnum((x)) || (x) == L'_') /* * Processes a line comparing it with the specified patterns. Each pattern @@ -323,7 +324,7 @@ procline(struct str *l, int nottext) continue; /* Check for whole word match */ if (fg_pattern[i].word && pmatch.rm_so != 0) { - wchar_t wbegin, wend; + wint_t wbegin, wend; wbegin = wend = L' '; if (pmatch.rm_so != 0 && @@ -474,13 +475,13 @@ printline(struct str *line, int sep, regmatch_t *matches, int m) if (!oflag) fwrite(line->dat + a, matches[i].rm_so - a, 1, stdout); - if (color) + if (color) fprintf(stdout, "\33[%sm\33[K", color); - fwrite(line->dat + matches[i].rm_so, + fwrite(line->dat + matches[i].rm_so, matches[i].rm_eo - matches[i].rm_so, 1, stdout); - if (color) + if (color) fprintf(stdout, "\33[m\33[K"); a = matches[i].rm_eo; if (oflag)