[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #25414] grep on win32 gives "not enough space" when reading from st

From: Dimitry Andric
Subject: [bug #25414] grep on win32 gives "not enough space" when reading from stdin
Date: Mon, 26 Jan 2009 21:04:37 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2a1pre) Gecko/20090124 Minefield/3.2a1pre


                 Summary: grep on win32 gives "not enough space" when reading
from stdin
                 Project: grep
            Submitted by: dim
            Submitted on: Mon 26 Jan 2009 10:04:35 PM CET
                Category: None
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any



I have built grep 2.5.3 successfully on Win32, using MinGW.  This needed
just a few minor patches.  The test suite mostly passes, except for
some in the infamous foad1.sh, which seem to have been commented out in
the HEAD version in CVS. :)

However, running grep in the following fashion:

  grep foo

e.g. expecting it to read from stdin, you always get the error:

  grep: (standard input): Not enough space

After some digging, I found out this is caused by the default read()
buffer size in fillbuf(), INITIAL_BUFSIZE, which is 32 kiB.

Now, for some unfathomable reason, Microsoft has not deemed the Win32
standard input handle to be able to read 32767 bytes.  The actual Win32
ReadFile() API call fails with ENOMEM.

After some experimenting, I have determined that at least on my version
of Windows XP, the maximum input buffer size for stdin is 24546 bytes.

I would like to propose the following patch, which sets INITIAL_BUFSIZE
at 16384 bytes for Win32, which looks safely under the maximum.  If you
would rather have this in a header file somewhere, please let me know.

diff -uprd grep-2.5.3-orig/src/grep.c grep-2.5.3/src/grep.c
--- grep-2.5.3-orig/src/grep.c  Thu Jun 28 19:57:19 2007
+++ grep-2.5.3/src/grep.c       Fri Jan 23 14:19:52 2009
@@ -412,7 +412,11 @@ context_length_arg (char const *str, int
 static char *buffer;           /* Base of buffer. */
 static size_t bufalloc;                /* Allocated buffer size, counting 
slop. */
+#ifdef _WIN32
+#define INITIAL_BUFSIZE 16384  /* Initial buffer size, not counting slop. */
 #define INITIAL_BUFSIZE 32768  /* Initial buffer size, not counting slop. */
 static int bufdesc;            /* File descriptor. */
 static char *bufbeg;           /* Beginning of user-visible stuff. */
 static char *buflim;           /* Limit of user-visible stuff. */


Reply to this item at:


  Message sent via/by Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]