[comp.sys.hp] Unbuffered Stdio Input

paul@mecazh.UUCP (Paul Breslaw) (02/20/90)

I have a little program that opens a master side pty and reads from it.
I have another little program that opens the corresponding slave side
and writes to it.

If the master side is coded something like:-

    FILE *f;
    char buf[ BF ];
    int  nr;

    f = fopen( master, "a+" );
    nr = fread( buf, sizeof( char ), BF, f );

then the program hangs on the fread.

If, however, I replace the last line with

    nr = read( fileno( f ), buf, BF );

then the read succeeds. An optional 

    setbuf( f, NULL );

does not alter the situation.

I have tested the program on an HP9000/340 (HP-UX 6.5) and a 
Sun3/50 (SunOS 3.5) with not quite identical non-events :-)

Any suggestions what I've done wrong?


Paul Breslaw




-- 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Paul Breslaw, Mecasoft SA,          |  telephone :  41 1 362 2040
Guggachstrasse 10, CH-8057 Zurich,  |  e-mail    :  mcsun!chx400!mecazh!paul
Switzerland.                        |               paul@mecazh.UUCP

meissner@osf.org (Michael Meissner) (02/21/90)

In article <378@node17.mecazh.UUCP> paul@mecazh.UUCP (Paul Breslaw) writes:

| I have a little program that opens a master side pty and reads from it.
| I have another little program that opens the corresponding slave side
| and writes to it.
| 
| If the master side is coded something like:-
| 
|     FILE *f;
|     char buf[ BF ];
|     int  nr;
| 
|     f = fopen( master, "a+" );
|     nr = fread( buf, sizeof( char ), BF, f );
| 
| then the program hangs on the fread.

Fread will loop attempting to fill the entire buffer.  If your records
are line oriented, I would recomend using fgets.  If you need to get
the characters as soon as possible, I would recomend switching the pty
to CBREAK or RAW modes, and using getc() to read bytes as you need
them.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA

Catproof is an oxymoron, Childproof is nearly so