home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.aix
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!purdue!yuma!sorensej
- From: sorensej@CS.ColoState.EDU (james a sorensen)
- Subject: Re: Non blocking reads from stdin
- Sender: news@yuma.ACNS.ColoState.EDU (News Account)
- Message-ID: <Nov20.200452.38395@yuma.ACNS.ColoState.EDU>
- Date: Fri, 20 Nov 1992 20:04:52 GMT
- References: <Nov.19.11.24.21.1992.26240@gauss.rutgers.edu>
- Nntp-Posting-Host: handel.cs.colostate.edu
- Organization: Sleuthworks, Inc.
- Keywords: non blocking getchar()
- Lines: 40
-
- The following code is what I have used to reconfigure stdin for polling.
- You have to store a copy of the current configuration and then restore it
- before leaving your program. The same applies if your program does interactive
- system calls or allows a escape to the shell. You should also trap any
- signals that may cause an abrupt end to your program and restore the original
- terminal configuration before exiting.
-
- For (a lot) more information, plow through the man page for termio.
- I use getc(stdin) instead of getchar but it should work the same.
-
- You can also do this using curses.
-
- James Sorensen
- Sleuthworks, Inc.
-
-
- {
- struct termio orgterm, term;
-
- /* Get current io configuration */
- if (ioctl (0,TCGETA, &term) == -1)
- {
- fprintf (stderr,"standard input is not a tty\n");
- exit();
- }
-
- /* Save current io configuration */
- orgterm = term;
-
- /* Disable canonical processing and echoing */
- term.c_lflag &= ~(ICANON | ECHO); /* disable icanonical processing */
-
- term.c_cc[VMIN] = 0; /* Set minimum number of characters to 0 */
- term.c_cc[VTIME] = 0; /* Set minimum time to 0 */
-
- ioctl (0,TCSETA,&term);
- }
-
-
-
-