This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug: ios_base::sync_with_stdio(false) creates empty files



The 27_io/ios_base_members_static.cc test is creating empty files named
"stdout" and "stderr" in either the library builddir or builddir/testsuite,
depending on whether you're running the binary from inside the debugger
or not.  (That bothers me in itself, but whatever.)

The culprit is these lines from src/ios.cc, in sync_with_stdio(), when
synchronization is being disabled:

        // Need to dispose of the buffers created at initialization.
        __ioinit._M_cout->~filebuf();
        __ioinit._M_cin->~filebuf();
        __ioinit._M_cerr->~filebuf();
        __ioinit._M_cout = new filebuf();
        __ioinit._M_cin = new filebuf();
        __ioinit._M_cerr = new filebuf();
 -->    __ioinit._M_cout->open("stdout", ios_base::out);
 -->    __ioinit._M_cin->open("stdin", ios_base::in);
 -->    __ioinit._M_cerr->open("stderr", ios_base::out);
        cout.rdbuf(__ioinit._M_cout);
        cin.rdbuf(__ioinit._M_cin);
        cerr.rdbuf(__ioinit._M_cerr);

The idea was obviously to re-open the standard streams using entirely new
buffers, etc.  But they actually open regular files named "stdout" and
"stderr" (but not stdin for obvious reasons).

These files have been appearing for as long as I can recall; I just finally
decided to track them down while waiting for feedback on the ini_priority
thing.


A simple test:

    #include <iostream>

    int main()
    {
        std::ios::sync_with_stdio(false);
        std::cout << "Hello, Filesystem World!" << std::endl;
        return 0;
    }

gives me:

    % s
    total 64
    -rwxr-xr-x   1 pedwards sysadmin    9122 Dec 22 18:34 a.out*
    -rw-r--r--   1 pedwards sysadmin     356 Dec 21 17:22 i.cc
    -rw-r--r--   1 pedwards sysadmin     149 Dec 22 18:34 ouch.cc
    % ./a.out 
    % s
    total 80
    -rwxr-xr-x   1 pedwards sysadmin    9122 Dec 22 18:34 a.out*
    -rw-r--r--   1 pedwards sysadmin     356 Dec 21 17:22 i.cc
    -rw-r--r--   1 pedwards sysadmin     149 Dec 22 18:34 ouch.cc
    -rw-r--r--   1 pedwards sysadmin       0 Dec 22 18:34 stderr
    -rw-r--r--   1 pedwards sysadmin      25 Dec 22 18:34 stdout
    % cat stdout
    Hello, Filesystem World!
    % 

Ugh.

I'll play with some patches in between swigs of egg nog.


Phil

-- 
pedwards at disaster dot jaj dot com  |  pme at sources dot redhat dot com
devphil at several other less interesting addresses in various dot domains
The gods do not protect fools.  Fools are protected by more capable fools.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]