Loading...
stdio/FreeBSD/freopen.c.patch Libc-391.1.21 Libc-594.9.4
--- Libc/Libc-391.1.21/stdio/FreeBSD/freopen.c.patch
+++ Libc/Libc-594.9.4/stdio/FreeBSD/freopen.c.patch
@@ -1,6 +1,15 @@
---- freopen.c.orig	2004-10-28 23:51:35.000000000 -0700
-+++ freopen.c	2004-10-28 23:53:14.000000000 -0700
-@@ -136,6 +136,8 @@
+--- freopen.c.orig	2009-02-15 03:11:22.000000000 -0800
++++ freopen.c	2009-02-15 14:26:16.000000000 -0800
+@@ -99,7 +99,7 @@ freopen(file, mode, fp)
+ 		    (oflags & O_ACCMODE)) {
+ 			fclose(fp);
+ 			FUNLOCKFILE(fp);
+-			errno = EINVAL;
++			errno = EBADF;
+ 			return (NULL);
+ 		}
+ 		if ((oflags ^ dflags) & O_APPEND) {
+@@ -136,6 +136,8 @@ freopen(file, mode, fp)
  	 * descriptor (if any) was associated with it.  If it was attached to
  	 * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)
  	 * should work.  This is unnecessary if it was not a Unix file.
@@ -9,7 +18,7 @@
  	 */
  	if (fp->_flags == 0) {
  		fp->_flags = __SEOF;	/* hold on to it */
-@@ -146,11 +148,18 @@
+@@ -146,11 +148,18 @@ freopen(file, mode, fp)
  		if (fp->_flags & __SWR)
  			(void) __sflush(fp);
  		/* if close is NULL, closing is a no-op, hence pointless */
@@ -28,3 +37,12 @@
  	}
  
  	/* Get a new descriptor to refer to the new file. */
+@@ -191,7 +200,7 @@ finish:
+ 	memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
+ 
+ 	if (f < 0) {			/* did not get it after all */
+-		fp->_flags = 0;		/* set it free */
++		__sfprelease(fp);	/* set it free */
+ 		errno = sverrno;	/* restore in case _close clobbered */
+ 		FUNLOCKFILE(fp);
+ 		return (NULL);