]> xenbits.xensource.com Git - people/julieng/freebsd.git/commitdiff
Add _flags2 per jhb@ suggestion since no room left in _flags.
authorache <ache@FreeBSD.org>
Wed, 28 Oct 2015 14:40:02 +0000 (14:40 +0000)
committerache <ache@FreeBSD.org>
Wed, 28 Oct 2015 14:40:02 +0000 (14:40 +0000)
Rewrite O_APPEND flag checking using new __S2OAP flag.

MFC after:      3 weeks

include/stdio.h
lib/libc/stdio/fdopen.c
lib/libc/stdio/findfp.c
lib/libc/stdio/fopen.c
lib/libc/stdio/freopen.c
lib/libc/stdio/ftell.c
lib/libc/stdio/stdio.c

index 5a5b82bc665ea1b76aaf8b94ea785e34e7b5c738..f55aaf7c72741974e22fd462c3a3ae96439ef541 100644 (file)
@@ -144,6 +144,7 @@ struct __sFILE {
        int     _fl_count;      /* recursive lock count */
        int     _orientation;   /* orientation for fwide() */
        __mbstate_t _mbstate;   /* multibyte conversion state */
+       int     _flags2;        /* additional flags */
 };
 #ifndef _STDFILE_DECLARED
 #define _STDFILE_DECLARED
@@ -176,6 +177,8 @@ __END_DECLS
 #define        __SALC  0x4000          /* allocate string space dynamically */
 #define        __SIGN  0x8000          /* ignore this file in _fwalk */
 
+#define        __S2OAP 0x0001          /* O_APPEND mode is set */
+
 /*
  * The following three definitions are for ANSI C, which took them
  * from System V, which brilliantly took internal interface macros and
index 8bd9c2ddbe01cbb34430a5a5eabc6467c8d6557e..fbe37e881428017ef8ce52fd809d5c002545a688 100644 (file)
@@ -91,9 +91,8 @@ fdopen(int fd, const char *mode)
         * O_APPEND bit set, assert __SAPP so that __swrite() caller
         * will _sseek() to the end before write.
         */
-       /* XXX: Reuse __SALC for O_APPEND. */
        if (fdflags & O_APPEND)
-               fp->_flags |= __SALC;
+               fp->_flags2 |= __S2OAP;
        else if (oflags & O_APPEND)
                fp->_flags |= __SAPP;
        fp->_file = fd;
index 0eabe82d753fb0ee341366463f291410d66c7631..b8bb5afb551c18428b294c1766574429a8980d47 100644 (file)
@@ -155,6 +155,7 @@ found:
 /*     fp->_fl_mutex = NULL; */ /* once set always set (reused) */
        fp->_orientation = 0;
        memset(&fp->_mbstate, 0, sizeof(mbstate_t));
+       fp->_flags2 = 0;
        return (fp);
 }
 
index b26f63734d995aba016cb218bbd612bc8d45cc8b..9ab61ba157a42501f400a0b6782b6597c6df2b19 100644 (file)
@@ -92,8 +92,7 @@ fopen(const char * __restrict file, const char * __restrict mode)
         * fseek and ftell.)
         */
        if (oflags & O_APPEND) {
-               /* XXX: Reuse __SALC for O_APPEND. */
-               fp->_flags |= __SALC;
+               fp->_flags2 |= __S2OAP;
                (void)_sseek(fp, (fpos_t)0, SEEK_END);
        }
        return (fp);
index 8b68bacc3f6a73ba3cd9c805ef3e6ef3c8b16a2c..e0104c88eef6df74f79b13ce008db8cf1704e18e 100644 (file)
@@ -187,6 +187,7 @@ finish:
        fp->_lb._size = 0;
        fp->_orientation = 0;
        memset(&fp->_mbstate, 0, sizeof(mbstate_t));
+       fp->_flags2 = 0;
 
        if (f < 0) {                    /* did not get it after all */
                if (isopen)
@@ -241,8 +242,7 @@ finish:
         * fseek and ftell.)
         */
        if (oflags & O_APPEND) {
-               /* XXX: Reuse __SALC for O_APPEND. */
-               fp->_flags |= __SALC;
+               fp->_flags2 |= __S2OAP;
                (void) _sseek(fp, (fpos_t)0, SEEK_END);
        }
        FUNLOCKFILE(fp);
index 0d2222b6958f91da5e4b1258101903460402f46e..abb6da11966c908ec9c2322536441d6d62573c3e 100644 (file)
@@ -119,8 +119,7 @@ _ftello(FILE *fp, fpos_t *offset)
                if (HASUB(fp))
                        pos -= fp->_r;  /* Can be negative at this point. */
        } else if ((fp->_flags & __SWR) && fp->_p != NULL) {
-               /* XXX: Reuse __SALC for O_APPEND. */
-               if (fp->_flags & (__SAPP|__SALC)) {
+               if ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP)) {
                        int serrno = errno;
 
                        errno = 0;
index fc2e74b356b9d56f6a69405176271279ac669304..5d6fb9ac56442003a8337a6a4091942c71b4f715 100644 (file)
@@ -117,8 +117,7 @@ _swrite(FILE *fp, char const *buf, int n)
        ret = (*fp->_write)(fp->_cookie, buf, n);
        /* __SOFF removed even on success in case O_APPEND mode is set. */
        if (ret >= 0) {
-               /* XXX: Reuse __SALC for O_APPEND. */
-               if ((fp->_flags & __SOFF) && !(fp->_flags & __SALC) &&
+               if ((fp->_flags & __SOFF) && !(fp->_flags2 & __S2OAP) &&
                    fp->_offset <= OFF_MAX - ret)
                        fp->_offset += ret;
                else