[uClibc-cvs] uClibc/libc/stdio stdio.c,1.66,1.67 scanf.c,1.24,1.25

Manuel Novoa III mjn3 at uclibc.org
Thu May 15 21:32:36 UTC 2003


Update of /var/cvs/uClibc/libc/stdio
In directory winder:/tmp/cvs-serv32280

Modified Files:
	stdio.c scanf.c 
Log Message:
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.


Index: stdio.c
===================================================================
RCS file: /var/cvs/uClibc/libc/stdio/stdio.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- stdio.c	23 Jan 2003 16:55:06 -0000	1.66
+++ stdio.c	15 May 2003 21:32:31 -0000	1.67
@@ -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 @@
 
 		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 @@
 			*p++ = *stream->bufpos++;
 		}
 
-		if (bytes > 0) {
+		if ((bytes > 0) && (stream->filedes != -2)) {
 			ssize_t len;
 
 			/* The buffer is exhausted, but we still need chars.  */

Index: scanf.c
===================================================================
RCS file: /var/cvs/uClibc/libc/stdio/scanf.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- scanf.c	6 Sep 2002 15:34:42 -0000	1.24
+++ scanf.c	15 May 2003 21:32:31 -0000	1.25
@@ -32,6 +32,9 @@
  *
  * Sep 6, 2002
  * Patch from Tero_Lyytikäinen <tero at paravant.fi> to fix bug in matchchar case.
+ *
+ * May 15, 2003
+ * Hopefully fix handling of 0 bytes with %s, %c, and %[ specifiers.
  */
 
 #define _ISOC99_SOURCE			/* for LLONG_MAX primarily... */
@@ -122,10 +125,10 @@
 {
 	FILE string[1];
 
-	string->filedes = -2;		/* for debugging */
+	string->filedes = -2;
 	string->modeflags = (__FLAG_NARROW|__FLAG_READONLY);
 	string->bufstart = string->bufpos = (unsigned char *) ((void *) sp);
-	string->bufgetc = (char *) ((unsigned) -1);
+	string->bufgetc = string->bufstart + strlen(sp);
 
 #ifdef __STDIO_MBSTATE
 	__INIT_MBSTATE(&(string->state));
@@ -241,7 +244,7 @@
 	sc->width_flag = 1;
 	if (--sc->width < 0) {
 		sc->ungot_flag = 1;
-		return 0;
+		return -1;
 	}
 	sc->ungot_flag = 0;
 	if (sc->ungot_char > 0) {
@@ -347,7 +350,7 @@
 				if (p-spec < 5) { /* [,c,s - string conversions */
 					invert = 0;
 					if (*p == 'c') {
-						invert = 1;
+						invert = 0;
 						if (sc.width == INT_MAX) {
 							sc.width = 1;
 						}
@@ -399,12 +402,16 @@
 						b = buf;
 					}
 					cc = scan_getc(&sc);
-					if (cc <= 0) {
+					if (cc < 0) {
 						scan_ungetc(&sc);
 						goto done; /* return EOF if cnt == 0 */
 					}
+					if (*p == 'c') {
+						goto c_spec;
+					}
 					i = 0;
-					while ((cc>0) && (scanset[cc] != invert)) {
+					while ((cc>=0) && (scanset[cc] != invert)) {
+					c_spec:
 						i = 1; /* yes, we stored something */
 						*b = cc;
 						b += store;



More information about the uClibc-cvs mailing list