On Tue, 18 Nov 2014, enh wrote:
> On Tue, Nov 18, 2014 at 10:01 PM, Philip Guenther <[email protected]> wrote:
...
> > Maybe it would be better to do
> >         if (!__sdidinit)
> >                 __sinit();
> >
> > like other places?
> 
> good point. i hadn't considered that stdin/stdout/stderr aren't
> arrived at via __sfp.
> 
> adding the __sinit stanza here would match the other places it currently 
> exists: places where buffers are filled/invalidated.

This passes my test program above; oks?


Philip


Index: makebuf.c
===================================================================
RCS file: /cvs/src/lib/libc/stdio/makebuf.c,v
retrieving revision 1.8
diff -u -p -r1.8 makebuf.c
--- makebuf.c   28 Dec 2005 18:50:22 -0000      1.8
+++ makebuf.c   19 Nov 2014 07:00:53 -0000
@@ -65,7 +65,6 @@ __smakebuf(FILE *fp)
                fp->_bf._size = 1;
                return;
        }
-       __atexit_register_cleanup(_cleanup);
        flags |= __SMBF;
        fp->_bf._base = fp->_p = p;
        fp->_bf._size = size;
Index: setvbuf.c
===================================================================
RCS file: /cvs/src/lib/libc/stdio/setvbuf.c,v
retrieving revision 1.11
diff -u -p -r1.11 setvbuf.c
--- setvbuf.c   9 Nov 2009 00:18:27 -0000       1.11
+++ setvbuf.c   19 Nov 2014 07:00:53 -0000
@@ -115,6 +115,13 @@ nbf:
        }
 
        /*
+        * We're committed to buffering from here, so make sure we've
+        * registered to flush buffers on exit.
+        */
+       if (!__sdidinit)
+               __sinit();
+
+       /*
         * Kill any seek optimization if the buffer is not the
         * right size.
         *
@@ -148,7 +155,6 @@ nbf:
                fp->_w = 0;
        }
        FUNLOCKFILE(fp);
-       __atexit_register_cleanup(_cleanup);
 
        return (ret);
 }

Reply via email to