[uClibc-cvs] uClibc/libc/stdio stdio.c,1.74,1.75

Manuel Novoa III mjn3 at uclibc.org
Fri Jan 2 09:21:36 UTC 2004


Update of /var/cvs/uClibc/libc/stdio
In directory nail:/tmp/cvs-serv25636

Modified Files:
	stdio.c 
Log Message:
Fix __freadable and __fwritable... were using '~' instead of '!'. (ugh)
Fix (hopefully) a potential problem with failed freopen() calls.  The
  fix isn't tested since I've been working on the replacement stdio
  core code which will go in after the next release.


Index: stdio.c
===================================================================
RCS file: /var/cvs/uClibc/libc/stdio/stdio.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- stdio.c	27 Dec 2003 23:30:42 -0000	1.74
+++ stdio.c	2 Jan 2004 09:21:33 -0000	1.75
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2002     Manuel Novoa III
+/*  Copyright (C) 2002,2003,2004     Manuel Novoa III
  *  My stdio library for linux and (soon) elks.
  *
  *  This library is free software; you can redistribute it and/or
@@ -80,6 +80,12 @@
  *
  * Nov 17, 2003
  * Fix the return value for fputs when passed an empty string.
+ *
+ * Jan 1, 2004
+ * Fix __freadable and __fwritable... were using '~' instead of '!'. (ugh)
+ * Fix (hopefully) a potential problem with failed freopen() calls.  The
+ *   fix isn't tested since I've been working on the replacement stdio
+ *   core code which will go in after the next release.
  */
 
 /* Before we include anything, convert L_ctermid to L_ctermid_function
@@ -984,7 +990,7 @@
 
 int __freadable(FILE * __restrict stream)
 {
-	return ~(stream->modeflags & __FLAG_WRITEONLY);
+	return !(stream->modeflags & __FLAG_WRITEONLY);
 }
 
 #endif
@@ -995,7 +1001,7 @@
 
 int __fwritable(FILE * __restrict stream)
 {
-	return ~(stream->modeflags & __FLAG_READONLY);
+	return !(stream->modeflags & __FLAG_READONLY);
 }
 
 #endif
@@ -2352,9 +2358,6 @@
 			open_mode = (O_WRONLY | O_CREAT | O_APPEND);
 			if (*mode != 'a') {	/* not write (create or append) */
 				__set_errno(EINVAL); /* then illegal mode */
-				if (stream) {	/* If this is freopen, free the stream. */
-					goto FREE_STREAM;
-				}
 				return NULL;
 			}
 		}
@@ -2450,7 +2453,6 @@
 	}
 
 	if (stream->filedes < 0) {
-	FREE_STREAM:
 #ifdef __STDIO_BUFFERS
 		if (stream->modeflags & __FLAG_FREEBUF) {
 			free(stream->bufstart);
@@ -2543,8 +2545,8 @@
 	 * supports this, so we don't here.
 	 *
 	 * NOTE: Whether or not the stream is free'd on failure is unclear
-	 *       w.r.t. ANSI/ISO.  This implementation chooses to free the
-	 *       stream and associated buffer if they were dynamically
+	 *       w.r.t. ANSI/ISO.  This implementation chooses to NOT free
+	 *       the stream and associated buffer if they were dynamically
 	 *       allocated.
 	 * TODO: Check the above.
 	 * TODO: Apparently linux allows setting append mode.  Implement?
@@ -2564,10 +2566,11 @@
 
 	stream->modeflags &= ~(__FLAG_FREEBUF|__FLAG_FREEFILE);
 	fclose(stream);				/* Failures are ignored. */
-	stream->modeflags = dynmode;
 
 	fp = _stdio_fopen(filename, mode, stream, -1);
 
+	stream->modeflags |= dynmode;
+
 	__STDIO_THREADUNLOCK(stream);
 
 	return fp;




More information about the uClibc-cvs mailing list