PERFORCE change 229958 for review
John Baldwin
jhb at FreeBSD.org
Wed Jun 19 16:01:26 UTC 2013
http://p4web.freebsd.org/@@229958?ac=10
Change 229958 by jhb at jhb_jhbbsd on 2013/06/19 16:00:32
Base patch to expand _file to an int.
Affected files ...
.. //depot/projects/stdio_file/include/stdio.h#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/Symbol.map#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/fclose.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/fdopen.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/fileno.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/findfp.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/fopen.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/freopen.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/funopen.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/local.h#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/vdprintf.c#2 edit
.. //depot/projects/stdio_file/lib/libc/stdio/vfwprintf.c#2 edit
Differences ...
==== //depot/projects/stdio_file/include/stdio.h#2 (text+ko) ====
@@ -112,7 +112,7 @@
int _r; /* (*) read space left for getc() */
int _w; /* (*) write space left for putc() */
short _flags; /* (*) flags, below; this FILE is free if 0 */
- short _file; /* (*) fileno, if Unix descriptor, else -1 */
+ short _ofile; /* (*) compat fileno for old binaries */
struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */
int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */
@@ -144,6 +144,7 @@
int _fl_count; /* recursive lock count */
int _orientation; /* orientation for fwide() */
__mbstate_t _mbstate; /* multibyte conversion state */
+ int _file; /* fileno, if Unix descriptor, else -1 */
};
#ifndef _STDFILE_DECLARED
#define _STDFILE_DECLARED
@@ -483,17 +484,12 @@
#define __sfeof(p) (((p)->_flags & __SEOF) != 0)
#define __sferror(p) (((p)->_flags & __SERR) != 0)
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
-#define __sfileno(p) ((p)->_file)
#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p))
#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p))
#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
-#if __POSIX_VISIBLE
-#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
-#endif
-
#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
@@ -508,7 +504,6 @@
#define feof_unlocked(p) __sfeof(p)
#define ferror_unlocked(p) __sferror(p)
#define clearerr_unlocked(p) __sclearerr(p)
-#define fileno_unlocked(p) __sfileno(p)
#endif
#if __POSIX_VISIBLE >= 199506
#define getc_unlocked(fp) __sgetc(fp)
==== //depot/projects/stdio_file/lib/libc/stdio/Symbol.map#2 (text) ====
@@ -10,7 +10,6 @@
clearerr;
fclose;
fcloseall;
- fdopen;
feof;
ferror;
fflush;
@@ -27,7 +26,6 @@
__stdoutp;
__stderrp;
f_prealloc; /* deprecated??? */
- fopen;
fprintf;
fpurge;
fputc;
@@ -35,7 +33,6 @@
fputwc;
fputws;
fread;
- freopen;
fscanf;
fseek;
fseeko;
@@ -118,6 +115,9 @@
};
FBSD_1.3 {
+ fdopen;
+ fopen;
+ freopen;
asprintf_l;
fprintf_l;
fwprintf_l;
==== //depot/projects/stdio_file/lib/libc/stdio/fclose.c#2 (text+ko) ====
@@ -65,6 +65,7 @@
if (HASLB(fp))
FREELB(fp);
fp->_file = -1;
+ fp->_ofile = -1;
fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
/*
==== //depot/projects/stdio_file/lib/libc/stdio/fdopen.c#2 (text+ko) ====
@@ -52,18 +52,6 @@
FILE *fp;
int flags, oflags, fdflags, tmp;
- /*
- * File descriptors are a full int, but _file is only a short.
- * If we get a valid file descriptor that is greater than
- * SHRT_MAX, then the fd will get sign-extended into an
- * invalid file descriptor. Handle this case by failing the
- * open.
- */
- if (fd > SHRT_MAX) {
- errno = EMFILE;
- return (NULL);
- }
-
if ((flags = __sflags(mode, &oflags)) == 0)
return (NULL);
@@ -93,6 +81,10 @@
if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
fp->_flags |= __SAPP;
fp->_file = fd;
+ if (fd > SHRT_MAX)
+ fp->_ofile = -1;
+ else
+ fp->_ofile = fd;
fp->_cookie = fp;
fp->_read = __sread;
fp->_write = __swrite;
@@ -100,3 +92,25 @@
fp->_close = __sclose;
return (fp);
}
+
+FILE *
+fdopen_ofile(fd, mode)
+ int fd;
+ const char *mode;
+{
+
+ /*
+ * File descriptors are a full int, but _ofile is only a short.
+ * If we get a valid file descriptor that is greater than
+ * SHRT_MAX, then the fd will get sign-extended into an
+ * invalid file descriptor. Handle this case by failing the
+ * open.
+ */
+ if (fd > SHRT_MAX) {
+ errno = EMFILE;
+ return (NULL);
+ }
+ return (fdopen(fd, mode));
+}
+
+__sym_compat(fdopen, fdopen_ofile, FBSD_1.0);
==== //depot/projects/stdio_file/lib/libc/stdio/fileno.c#2 (text+ko) ====
@@ -50,7 +50,7 @@
int fd;
FLOCKFILE(fp);
- fd = __sfileno(fp);
+ fd = fp->_file;
FUNLOCKFILE(fp);
return (fd);
@@ -60,5 +60,5 @@
fileno_unlocked(FILE *fp)
{
- return (__sfileno(fp));
+ return (fp->_file);
}
==== //depot/projects/stdio_file/lib/libc/stdio/findfp.c#2 (text+ko) ====
@@ -56,6 +56,7 @@
#define std(flags, file) { \
._flags = (flags), \
._file = (file), \
+ ._ofile = (file), \
._cookie = __sF + (file), \
._close = __sclose, \
._read = __sread, \
@@ -147,6 +148,7 @@
fp->_bf._size = 0;
fp->_lbfsize = 0; /* not line buffered */
fp->_file = -1; /* no file */
+ fp->_ofile = -1;
/* fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */
fp->_ub._base = NULL; /* no ungetc buffer */
fp->_ub._size = 0;
==== //depot/projects/stdio_file/lib/libc/stdio/fopen.c#2 (text+ko) ====
@@ -48,8 +48,9 @@
#include "local.h"
-FILE *
-fopen(const char * __restrict file, const char * __restrict mode)
+static FILE *
+fopen_internal(const char * __restrict file, const char * __restrict mode,
+ int ofile)
{
FILE *fp;
int f;
@@ -64,19 +65,23 @@
return (NULL);
}
/*
- * File descriptors are a full int, but _file is only a short.
+ * File descriptors are a full int, but _ofile is only a short.
* If we get a valid file descriptor that is greater than
* SHRT_MAX, then the fd will get sign-extended into an
* invalid file descriptor. Handle this case by failing the
* open.
*/
- if (f > SHRT_MAX) {
+ if (f > SHRT_MAX && ofile) {
fp->_flags = 0; /* release */
_close(f);
errno = EMFILE;
return (NULL);
}
fp->_file = f;
+ if (f > SHRT_MAX)
+ fp->_ofile = -1;
+ else
+ fp->_ofile = f;
fp->_flags = flags;
fp->_cookie = fp;
fp->_read = __sread;
@@ -95,3 +100,19 @@
(void)_sseek(fp, (fpos_t)0, SEEK_END);
return (fp);
}
+
+FILE *
+fopen(const char * __restrict file, const char * __restrict mode)
+{
+
+ return (fopen_internal(file, mode, 0));
+}
+
+FILE *
+fopen_ofile(const char * __restrict file, const char * __restrict mode)
+{
+
+ return (fopen_internal(file, mode, 1));
+}
+
+__sym_compat(fopen, fopen_ofile, FBSD_1.0);
==== //depot/projects/stdio_file/lib/libc/stdio/freopen.c#2 (text+ko) ====
@@ -54,9 +54,9 @@
* ANSI is written such that the original file gets closed if at
* all possible, no matter what.
*/
-FILE *
-freopen(const char * __restrict file, const char * __restrict mode,
- FILE * __restrict fp)
+static FILE *
+freopen_internal(const char * __restrict file, const char * __restrict mode,
+ FILE * __restrict fp, int ofile)
{
int f;
int dflags, flags, isopen, oflags, sverrno, wantfd;
@@ -203,13 +203,13 @@
}
/*
- * File descriptors are a full int, but _file is only a short.
+ * File descriptors are a full int, but _ofile is only a short.
* If we get a valid file descriptor that is greater than
* SHRT_MAX, then the fd will get sign-extended into an
* invalid file descriptor. Handle this case by failing the
* open.
*/
- if (f > SHRT_MAX) {
+ if (f > SHRT_MAX && ofile) {
fp->_flags = 0; /* set it free */
FUNLOCKFILE(fp);
errno = EMFILE;
@@ -218,6 +218,10 @@
fp->_flags = flags;
fp->_file = f;
+ if (f > SHRT_MAX)
+ fp->_ofile = -1;
+ else
+ fp->_ofile = f;
fp->_cookie = fp;
fp->_read = __sread;
fp->_write = __swrite;
@@ -236,3 +240,21 @@
FUNLOCKFILE(fp);
return (fp);
}
+
+FILE *
+freopen(const char * __restrict file, const char * __restrict mode,
+ FILE * __restrict fp)
+{
+
+ return (freopen_internal(file, mode, fp, 0));
+}
+
+FILE *
+freopen_ofile(const char * __restrict file, const char * __restrict mode,
+ FILE * __restrict fp)
+{
+
+ return (freopen_internal(file, mode, fp, 1));
+}
+
+__sym_compat(freopen, freopen_ofile, FBSD_1.0);
==== //depot/projects/stdio_file/lib/libc/stdio/funopen.c#2 (text+ko) ====
@@ -67,6 +67,7 @@
return (NULL);
fp->_flags = flags;
fp->_file = -1;
+ fp->_ofile = -1;
fp->_cookie = (void *)cookie;
fp->_read = readfn;
fp->_write = writefn;
==== //depot/projects/stdio_file/lib/libc/stdio/local.h#2 (text+ko) ====
@@ -128,6 +128,7 @@
#define FAKE_FILE { \
._file = -1, \
._fl_mutex = PTHREAD_MUTEX_INITIALIZER, \
+ ._ofile = -1, \
}
/*
==== //depot/projects/stdio_file/lib/libc/stdio/vdprintf.c#2 (text+ko) ====
@@ -49,11 +49,6 @@
unsigned char buf[BUFSIZ];
int ret;
- if (fd > SHRT_MAX) {
- errno = EMFILE;
- return (EOF);
- }
-
f._p = buf;
f._w = sizeof(buf);
f._flags = __SWR;
==== //depot/projects/stdio_file/lib/libc/stdio/vfwprintf.c#2 (text+ko) ====
@@ -215,7 +215,7 @@
__sbprintf(FILE *fp, locale_t locale, const wchar_t *fmt, va_list ap)
{
int ret;
- FILE fake;
+ FILE fake = FAKE_FILE;
unsigned char buf[BUFSIZ];
/* XXX This is probably not needed. */
More information about the p4-projects
mailing list