[net.unix-wizards] cbreak problem

cnrdean@ucbtopaz.BERKELEY.EDU (02/06/86)

I am porting a program on to a Berkeley 4.2  Vax, and I'm having
trouble with my cbreak mode:  I need to process characters as they come
in.  My problem is that when I try to print the characters, they don't
get printed at the point that I request them to, unless I put a fflush
in.  I thought that when I was in cbreak mode, putchar() would show up
immediately, without fflushing.

Can you help?  I've read TTY(4), and tried fooling with some of the
flushing mechanisms in there, to no avail.

Following is an example of my code:

#include <sgtty.h>
. . .
char c;
struct sgttyb
cbrmode,			/* Controlling tty cbreak mode */
cookedmode;			/* Controlling tty cooked mode */
. . .
gtty(0,&cbrmode);
cbrmode.sg_flags |= (CBREAK);
cbrmode.sg_flags &= ~(ECHO|XTABS|CRMOD);
stty(0,&cbrmode);			/* Put tty in cbreak mode */
. . .
read(0,&c,1);		/* Get a character */
c =  c & 0177;
putchar(c);

gwyn@brl-smoke.ARPA (Doug Gwyn ) (02/09/86)

In article <299@ucbjade.BERKELEY.EDU> cnrdean@ucbtopaz.BERKELEY.EDU () writes:
>I am porting a program on to a Berkeley 4.2  Vax, and I'm having
>trouble with my cbreak mode:  I need to process characters as they come
>in.  My problem is that when I try to print the characters, they don't
>get printed at the point that I request them to, unless I put a fflush
>in.  I thought that when I was in cbreak mode, putchar() would show up
>immediately, without fflushing.

No, STDIO does not pay attention to the terminal mode.
By default, output to a terminal (except stderr) will
be line-buffered.  You can override this by invoking
setbuf(stdout,(char *)NULL) before doing any output.