delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/04/10/23:29:05

Date: Sun, 10 Apr 1994 19:33:18 -0700
From: drupp AT cs DOT washington DOT edu (Douglas Rupp)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Strange behavior of _setmode (and setmode)

I want to set STDOUT to raw mode, but leave STDIN in cooked mode but I
can't, WHY?

Consider the following program:

#include <fcntl.h>
main ()
{
   char buf[10];
   int r;
   r = read(0,buf,10);
   printf("r=%d\n", r);
   _setmode(1, O_BINARY);
   r = read(0,buf,10);
   _setmode(1, O_TEXT);
   printf("r=%d\n", r);
}

If <Enter> is input, the first read returns immediately with 1 character
read (r=1).  The second read will not return until 10 more <Enter> keys
are pressed, but still reports r=1.  And I'm not setting the mode for STDIN,
but only STDOUT.

What's going on?

Doug Rupp

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019