]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/freopen.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / stdio / FreeBSD / freopen.c.patch
1 --- freopen.c.orig 2009-02-15 03:11:22.000000000 -0800
2 +++ freopen.c 2009-02-15 14:26:16.000000000 -0800
3 @@ -99,7 +99,7 @@ freopen(file, mode, fp)
4 (oflags & O_ACCMODE)) {
5 fclose(fp);
6 FUNLOCKFILE(fp);
7 - errno = EINVAL;
8 + errno = EBADF;
9 return (NULL);
10 }
11 if ((oflags ^ dflags) & O_APPEND) {
12 @@ -136,6 +136,8 @@ freopen(file, mode, fp)
13 * descriptor (if any) was associated with it. If it was attached to
14 * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)
15 * should work. This is unnecessary if it was not a Unix file.
16 + *
17 + * For UNIX03, we always close if it was open.
18 */
19 if (fp->_flags == 0) {
20 fp->_flags = __SEOF; /* hold on to it */
21 @@ -146,11 +148,18 @@ freopen(file, mode, fp)
22 if (fp->_flags & __SWR)
23 (void) __sflush(fp);
24 /* if close is NULL, closing is a no-op, hence pointless */
25 +#if __DARWIN_UNIX03
26 + if (fp->_close)
27 + (void) (*fp->_close)(fp->_cookie);
28 + isopen = 0;
29 + wantfd = -1;
30 +#else /* !__DARWIN_UNIX03 */
31 isopen = fp->_close != NULL;
32 if ((wantfd = fp->_file) < 0 && isopen) {
33 (void) (*fp->_close)(fp->_cookie);
34 isopen = 0;
35 }
36 +#endif /* __DARWIN_UNIX03 */
37 }
38
39 /* Get a new descriptor to refer to the new file. */
40 @@ -191,7 +200,7 @@ finish:
41 memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
42
43 if (f < 0) { /* did not get it after all */
44 - fp->_flags = 0; /* set it free */
45 + __sfprelease(fp); /* set it free */
46 errno = sverrno; /* restore in case _close clobbered */
47 FUNLOCKFILE(fp);
48 return (NULL);