Added support for ignoring '-g' per GNU ls, thanks to David Vrabel
[oweals/busybox.git] / grep.c
diff --git a/grep.c b/grep.c
index aca469e2f21acc0925be4fb96d567a0250e9dd57..a2e2ff813e20e596e004e4fcd2c682a640e541a5 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -46,8 +46,6 @@ static const char grep_usage[] =
 #endif
        ;
 
-static const int GROWBY = 80; /* how large we will grow strings by */
-
 /* options */
 static int ignore_case       = 0;
 static int print_filename    = 0;
@@ -62,35 +60,6 @@ static int nmatches = 0; /* keeps track of the number of matches */
 static char *cur_file = NULL; /* the current file we are reading */
 
 
-/* This returns a malloc'ed char * which must be stored and free'ed */
-/* XXX: This function should probably go in a 'common'/'util'/'misc' file
- * somewhere so it can be used by other folks. */
-static char *get_line_from_file(FILE *file)
-{
-       int ch;
-       int idx = 0;
-       char *linebuf = NULL;
-       int linebufsz = 0;
-
-       while (1) {
-               ch = fgetc(file);
-               if (ch == EOF)
-                       break;
-               /* grow the line buffer as necessary */
-               if (idx > linebufsz-1)
-                       linebuf = realloc(linebuf, linebufsz += GROWBY);
-               linebuf[idx++] = (char)ch;
-               if ((char)ch == '\n')
-                       break;
-       }
-
-       if (idx == 0)
-               return NULL;
-
-       linebuf[idx] = 0;
-       return linebuf;
-}
-
 static void print_matched_line(char *line, int linenum)
 {
        if (print_filename)
@@ -196,9 +165,9 @@ extern int grep_main(int argc, char **argv)
        if ((argc-1) - (optind+1) > 0)
                print_filename++;
 
-       /* If no files were specified, take input from stdin. Otherwise, we grep
-        * through all the files specified. */
-       if (argv[optind+1] == NULL) {
+       /* If no files were specified, or '-' was specified, take input from
+        * stdin. Otherwise, we grep through all the files specified. */
+       if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) {
                grep_file(stdin);
        } else {
                int i;