On Mon, Nov 3, 2014 at 12:24 PM, Elliott Hughes <[email protected]> wrote:
> __sinit unconditionally calls __atexit_register_cleanup.
>
> --- stdio/makebuf.c     28 Dec 2005 18:50:22 -0000      1.8
> +++ stdio/makebuf.c     3 Nov 2014 20:21:15 -0000
> @@ -65,7 +65,6 @@
>                 fp->_bf._size = 1;
>                 return;
>         }
> -       __atexit_register_cleanup(_cleanup);
>         flags |= __SMBF;
>         fp->_bf._base = fp->_p = p;
>         fp->_bf._size = size;

Yes, all the places that call __smakebuf() call __sinit() first.

[Side note: diffs are better with the -p option.]


> --- stdio/setvbuf.c     9 Nov 2009 00:18:27 -0000       1.11
> +++ stdio/setvbuf.c     3 Nov 2014 20:21:15 -0000
> @@ -124,8 +124,7 @@
>                 flags |= __SNPT;
>
>         /*
> -        * Fix up the FILE fields, and set __cleanup for output flush on
> -        * exit (since we are buffered in some way).
> +        * Fix up the FILE fields.
>          */
>         if (mode == _IOLBF)
>                 flags |= __SLBF;
> @@ -148,7 +147,6 @@
>                 fp->_w = 0;
>         }
>         FUNLOCKFILE(fp);
> -       __atexit_register_cleanup(_cleanup);
>
>         return (ret);
>  }

I'm not convinced on this one.  Does this break a program that sets
the output to buffered and then doesn't write enough to cause a flush?
 e.g.:

#include <stdio.h>
char buf[BUFSIZ];
int
main(void)
{
        setvbuf(stdout, buf, _IOLBF, sizeof buf);
        putchar('@');
        return 0;
}

That should output just an '@', but the setvbuf.c diff breaks that.

Maybe it would be better to do
        if (!__sdidinit)
                __sinit();

like other places?


Philip Guenther

Reply via email to