]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/freopen.c.patch
899579c4a37f2183bbf2f7c4ab12cd9ebe8b55df
[apple/libc.git] / stdio / FreeBSD / freopen.c.patch
1 Index: freopen.c
2 ===================================================================
3 RCS file: /cvs/root/Libc/stdio/FreeBSD/freopen.c,v
4 retrieving revision 1.3
5 diff -u -d -b -w -p -r1.3 freopen.c
6 --- freopen.c 2004/11/25 19:38:34 1.3
7 +++ freopen.c 2005/01/25 18:01:26
8 @@ -99,7 +99,7 @@ freopen(file, mode, fp)
9 (oflags & O_ACCMODE)) {
10 fclose(fp);
11 FUNLOCKFILE(fp);
12 - errno = EINVAL;
13 + errno = EBADF;
14 return (NULL);
15 }
16 if ((oflags ^ dflags) & O_APPEND) {
17 @@ -136,6 +136,8 @@ freopen(file, mode, fp)
18 * descriptor (if any) was associated with it. If it was attached to
19 * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)
20 * should work. This is unnecessary if it was not a Unix file.
21 + *
22 + * For UNIX03, we always close if it was open.
23 */
24 if (fp->_flags == 0) {
25 fp->_flags = __SEOF; /* hold on to it */
26 @@ -146,11 +148,18 @@ freopen(file, mode, fp)
27 if (fp->_flags & __SWR)
28 (void) __sflush(fp);
29 /* if close is NULL, closing is a no-op, hence pointless */
30 +#if __DARWIN_UNIX03
31 + if (fp->_close)
32 + (void) (*fp->_close)(fp->_cookie);
33 + isopen = 0;
34 + wantfd = -1;
35 +#else /* !__DARWIN_UNIX03 */
36 isopen = fp->_close != NULL;
37 if ((wantfd = fp->_file) < 0 && isopen) {
38 (void) (*fp->_close)(fp->_cookie);
39 isopen = 0;
40 }
41 +#endif /* __DARWIN_UNIX03 */
42 }
43
44 /* Get a new descriptor to refer to the new file. */