logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://hacktivis.me/git/make-initrd.git
commit: fa3c8dc0ab7411a1d9b1db3bd043c228b689aaa7
parent 5d0060926e2f20e59fc1687f7417669fec0f4c8f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri,  3 May 2024 14:31:08 +0200

grep-stub.c: Handle case insensitive substring

Diffstat:

Mgrep-stub.c7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/grep-stub.c b/grep-stub.c @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L +#define _GNU_SOURCE // strcasestr #include <assert.h> #include <errno.h> @@ -30,6 +31,8 @@ static regex_t *patterns_r = NULL; static bool fixed_str = false, invert = false, count_only = false, opt_n = false; static bool multiple_files = false; +static char *(*find_substring)(const char *, const char *) = &strstr; + static int do_grep(FILE *stream, char *filename) { @@ -50,8 +53,7 @@ do_grep(FILE *stream, char *filename) { for(struct char_list *pattern = patterns; pattern != NULL; pattern = pattern->next) { - // FIXME: Case insensitive (strcasestr) - if(strstr(line, pattern->data) != NULL) + if(find_substring(line, pattern->data) != NULL) { found = true; break; @@ -178,6 +180,7 @@ main(int argc, char *argv[]) break; case 'i': regcomp_flags |= REG_ICASE; + find_substring = &strcasestr; break; case 'l': // (standard input)