This is the mail archive of the ecos-bugs@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug 19838] New: stdio line buffered output not flushed correctly


http://bugs.ecos.sourceware.org/show_bug.cgi?id=19838

           Summary: stdio line buffered output not flushed correctly
           Product: eCos
           Version: 1.1
          Platform: All
        OS/Version: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: low
         Component: Other
        AssignedTo: jifl at ecoscentric dot com
        ReportedBy: anonymous at egcs dot cygnus dot com


When using stdio for console output in the default (line
buffered) mode, an output line with no trailing "\n" is
not flushed when followed by console input.

How-To-Repeat:
In the following program, the message "enter reply: " is
printed without a trailing newline, but is followed by gets().
On eCos, this message comes out too late, after the input.
It works correcly on Unix, flushing the output at the time
of the gets() call.

#include <stdio.h>
/* XXX ECOS */
#include <pkgconf/libc.h>
#define BUFSIZ BUFSIZE
/* end XXX ECOS */

void prs(char *);
char buf[BUFSIZ];

int
main()
{
        char reply[80];

        setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
        prs("starting\n");
        prs("enter reply: ");
        gets(reply);
        prs("reply = ");
        prs(reply);
        prs("\n");
        prs("unterminated line...");

        return(0);
}

void
prs(char *s)
{
        while (*s)
                putchar(*s++);
}

Fix:
None.
The problem does not show up using "printf()" since there is
(effectively) a call to fflush() at the end of printf() in eCos.
Otherwise, explicit use of fflush seems to be required.

Under Unix, the behaviour can best be seen by placing a call
to sleep - e.g. sleep(5) - between the prs("enter reply: )
and the gets().  It applies to printf() as well.
The man page for setvbuf() says:

_IOLBF      causes output to be line  buffered;  the  buffer
            will  be  flushed when a newline is written, the
            buffer is full, or input is requested.

This does not explain, however, how input on one stream is
coupled to output on another.

---------------------------------------------------------------------------

Originator:
Peter Skan

Organization:
Insignia Solutions plc

Audit-Trail:
Responsible-Changed-From-To: alexs->jlarmour 
Responsible-Changed-By: alexs 
Responsible-Changed-When: Wed Apr 14 06:02:29 PDT 1999 
Responsible-Changed-Why:  
Another libc issue for Jonathan to take responsibility for. 

State-Changed-From-To: open-analyzed 
State-Changed-By: jlarmour 
State-Changed-When: Thu Apr 15 05:49:36 PDT 1999 
State-Changed-Why:  

Firstly, thanks for the useful analysis, and test case. That saves 
a lot of time and potential ambiguity. 

I have fixed some libc issues to do with this problem, and these will 
be in the next release of eCos. These reduce the problem so that it 
should now be possible to achieve the desired effect, but only if you 
are using proper eCos serial device drivers. 

The changes required to make the "haldiag" pseudo-device (which is the 
default one) are too radical to go into the next release at this late 
stage. I hope this won't be a problem. 

I'll leave this PR as "analyzed" so that I remain aware that more work 
needs to be done. 

Jonathan Larmour

Unformatted:
Originator:  

page: sourceware.cygnus.com/ecos/problemreport.html

Send_PR_form: Sent_from_sourceware.cygnus.com

------- Additional Comments From alexs at ecoscentric dot com  2003-24-04 16:04 BST -------
This has probably been fixed but you need to confirm



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


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