Paul Eggert wrote:
I fixed it as part of installing the attached patches.

Come to think of it, grep shouldn't call strcasecmp here. It should call c_strcasecmp instead because the matching should be locale-independent. So I installed the attached further patch and there is no longer a need to include strings.h even on non-GNU platforms.

>From 65779292d28dd3e57de147dc27db0a125d99b5ed Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 3 Feb 2019 11:46:36 -0800
Subject: [PATCH] grep: parse --color arg independent of locale

This is a better fix for Bug#34285.
* bootstrap.conf (gnulib_modules): Add c-strcase.
* src/grep.c: Include c-strcase.h, not strings.h.
(main): Use c_strcasecmp, not strcasecmp.
---
 bootstrap.conf |  1 +
 src/grep.c     | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index ea3eddf..d453b3e 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -28,6 +28,7 @@ announce-gen
 argmatch
 c-ctype
 c-stack
+c-strcase
 closeout
 configmake
 dfa
diff --git a/src/grep.c b/src/grep.c
index fcc07b8..ef6abb8 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -25,7 +25,6 @@
 #include <inttypes.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <strings.h>
 #include "system.h"
 
 #include "argmatch.h"
@@ -47,6 +46,7 @@
 #include "quote.h"
 #include "safe-read.h"
 #include "search.h"
+#include "c-strcase.h"
 #include "version-etc.h"
 #include "xalloc.h"
 #include "xbinary-io.h"
@@ -2698,14 +2698,17 @@ main (int argc, char **argv)
       case COLOR_OPTION:
         if (optarg)
           {
-            if (!strcasecmp (optarg, "always") || !strcasecmp (optarg, "yes")
-                || !strcasecmp (optarg, "force"))
+            if (!c_strcasecmp (optarg, "always")
+                || !c_strcasecmp (optarg, "yes")
+                || !c_strcasecmp (optarg, "force"))
               color_option = 1;
-            else if (!strcasecmp (optarg, "never") || !strcasecmp (optarg, "no")
-                     || !strcasecmp (optarg, "none"))
+            else if (!c_strcasecmp (optarg, "never")
+                     || !c_strcasecmp (optarg, "no")
+                     || !c_strcasecmp (optarg, "none"))
               color_option = 0;
-            else if (!strcasecmp (optarg, "auto") || !strcasecmp (optarg, "tty")
-                     || !strcasecmp (optarg, "if-tty"))
+            else if (!c_strcasecmp (optarg, "auto")
+                     || !c_strcasecmp (optarg, "tty")
+                     || !c_strcasecmp (optarg, "if-tty"))
               color_option = 2;
             else
               show_help = 1;
-- 
2.17.1

Reply via email to