true unbuffered input.

David Burhans dwb at sppy00.UUCP
Wed Jan 17 05:29:46 AEST 1990


In article <1990Jan15.222652.21085 at hellgate.utah.edu> efinley%ug.utah.edu at cs.utah.edu (Elliott Finley) writes:
>
>I can't seem to get true unbuffered input.   ...stuff deleted...

 To do this you meed to change the your mode from cooked to CBREAK or RAW.
 Use ioctl(2) to accomplish this change.

 Man pages of interest: ioctl(2), tty(4).
 Include files of interest: sgtty.h, sys/ioctl.h.
 An example program follows:
---------------------------<Cut Here>-------------------------------------
#include <stdio.h>
#include <sgtty.h>
main() {
  int c;
  struct sgttyb oldargs, newargs;

  printf("stdin:%d\n",fileno(stdin));
  ioctl(fileno(stdin), TIOCGETP, &oldargs);

  newargs = oldargs;
  newargs.sg_flags |= CBREAK;
  newargs.sg_flags &= ~(ECHO | CRMOD);
  ioctl(fileno(stdin), TIOCSETP, &newargs);

  while(c = getchar(), c != '\004') {  /* while c != ^D */
    switch (c) {
      case '\033': fputs("<Esc>", stdout); break;
      case '\n':   fputs("\\n\n\r", stdout); break;
      case '\r':   fputs("\\r\n\r", stdout); break;
      case '\t':   fputs("\\t", stdout); break;
      default:     fprintf(stdout,"%c",c); break;
    }
  }
  ioctl(fileno(stdin), TIOCSETP, &oldargs);
}
-- 
dwb at sppy00	{att|killer|pyramid}!osu-cis!sppy00!dwb	
David Burhans/6565 Frantz Rd./Columbus, Oh 43017
  ****  Views expressed above were randomly generated with a six
  	sided die and as such are not the views of my employer.   *****



More information about the Comp.lang.c mailing list