One reason to use toybox on the host is to get the same behavior across
Android/Linux/macOS. Unfortunately (as we've seen from a few bugs) one
area where that doesn't quite work is that toybox uses the libc regular
expression implementation. That's fine, and mostly what users want, but
those folks trying to get the exact same behavior everywhere might want
to switch in a known regex implementation (bionic's NetBSD regex
implementation, say) for increased consistency.

That actually works pretty well, but portability.h has an #ifndef test
for REG_STARTEND before including <regex.h> that gets in the way. To
make up for that, this patch removes the unnecessary #include <regex.h>
from grep.c itself.
---
 lib/portability.h | 1 +
 toys/posix/grep.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
From a9a1734cab78f5a44e8c098b1b4f21ffe5ec58dd Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Wed, 28 Oct 2020 16:48:14 -0700
Subject: [PATCH] Make it easier to switch regex implementations.

One reason to use toybox on the host is to get the same behavior across
Android/Linux/macOS. Unfortunately (as we've seen from a few bugs) one
area where that doesn't quite work is that toybox uses the libc regular
expression implementation. That's fine, and mostly what users want, but
those folks trying to get the exact same behavior everywhere might want
to switch in a known regex implementation (bionic's NetBSD regex
implementation, say) for increased consistency.

That actually works pretty well, but portability.h has an #ifndef test
for REG_STARTEND before including <regex.h> that gets in the way. To
make up for that, this patch removes the unnecessary #include <regex.h>
from grep.c itself.
---
 lib/portability.h | 1 +
 toys/posix/grep.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/portability.h b/lib/portability.h
index acc32fd4..05a449ee 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -6,6 +6,7 @@
 
 // For musl
 #define _ALL_SOURCE
+#include <regex.h>
 #ifndef REG_STARTEND
 #define REG_STARTEND 0
 #endif
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 1fa1a7c4..9f445fca 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -65,7 +65,6 @@ config FGREP
 
 #define FOR_grep
 #include "toys.h"
-#include <regex.h>
 
 GLOBALS(
   long m, A, B, C;
-- 
2.29.1.341.ge80a0c044ae-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to