From a8938c2781a66b386eb0807f9149b871d03f4c6e Mon Sep 17 00:00:00 2001 From: Manuel Novoa III Date: Thu, 15 May 2003 21:32:31 +0000 Subject: Fix (hopefully) scanf behavior for nul bytes in the stream when processing %c, %s, and %[ specifiers. Note that scanf is undergoing rewrite so I didn't bother optimizing this. I did run all my regression tests though. Set EOF correctly for fmemopen on readonly streams. I really need to check what glibc behavior is for the various open modes though. --- libc/stdio/stdio.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'libc/stdio/stdio.c') diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c index 0599f2353..eec8bdda3 100644 --- a/libc/stdio/stdio.c +++ b/libc/stdio/stdio.c @@ -59,6 +59,12 @@ * Also fix _stdio_fopen to support fdopen() with append specified when * the underlying file didn't have O_APPEND set. It now sets the * O_APPEND flag as recommended by SUSv3 and is done by glibc. + * + * May 15, 2003 + * Modify __stdio_fread to deal with fake streams used by *sscanf. + * Set EOF to end of buffer when fmemopen used on a readonly stream. + * Note: I really need to run some tests on this to see what the + * glibc code does in each case. */ /* Before we include anything, convert L_ctermid to L_ctermid_function @@ -639,6 +645,9 @@ FILE *fmemopen(void *s, size_t len, const char *modes) if (fp != NULL) { cookie->fp = fp; + if (fp->modeflags & __FLAG_READONLY) { + cookie->eof = len; + } if ((fp->modeflags & __FLAG_APPEND) && (len > 0)) { for (i = 0 ; i < len ; i++) { if (cookie->buf[i] == 0) { @@ -1406,7 +1415,7 @@ size_t _stdio_fread(unsigned char *buffer, size_t bytes, register FILE *stream) *p++ = *stream->bufpos++; } - if (bytes > 0) { + if ((bytes > 0) && (stream->filedes != -2)) { ssize_t len; /* The buffer is exhausted, but we still need chars. */ -- cgit v1.2.3