[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 1/2] grep: Support -f emptyfile
From:       "Lauri Kasanen" <curaga () operamail ! com>
Date:       2011-08-23 9:14:12
Message-ID: 1314090852.10631.140258132698893 () webmail ! messagingengine ! com
[Download RAW message or body]

Main patch.

- Lauri

-- 
http://www.fastmail.fm - IMAP accessible web-mail


["0001-grep-Support-f-emptyfile.patch" (0001-grep-Support-f-emptyfile.patch)]

From 8ca7017c19ce188768d3646df73890caf690201a Mon Sep 17 00:00:00 2001
From: Lauri Kasanen <curaga@operamail.com>
Date: Tue, 23 Aug 2011 12:06:28 +0300
Subject: [PATCH 1/2] grep: Support -f emptyfile


Signed-off-by: Lauri Kasanen <curaga@operamail.com>
---
 findutils/grep.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/findutils/grep.c b/findutils/grep.c
index 3acfa91..ff470d1 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -564,6 +564,8 @@ static void load_regexes_from_file(llist_t *fopt)
 {
 	char *line;
 	FILE *f;
+	long size;
+	char empty = '\0';
 
 	while (fopt) {
 		llist_t *cur = fopt;
@@ -572,6 +574,18 @@ static void load_regexes_from_file(llist_t *fopt)
 		fopt = cur->link;
 		free(cur);
 		f = xfopen_stdin(ffile);
+
+		fseek(f, 0, SEEK_END);
+		size = ftell(f);
+		rewind(f);
+
+		if (size == 0) {
+			llist_add_to(&pattern_head,
+				new_grep_list_data(&empty, 0));
+			invert_search ^= 1;
+			continue;
+		}
+
 		while ((line = xmalloc_fgetline(f)) != NULL) {
 			llist_add_to(&pattern_head,
 				new_grep_list_data(line, ALLOCATED));
-- 
1.7.2.1



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic