home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:19321 comp.unix.questions:15217
- Newsgroups: comp.lang.c,comp.unix.questions
- Path: sparky!uunet!noc.near.net!nic.umass.edu!risky.ecs.umass.edu!umvlsi.ecs.umass.edu!chou
- From: chou@umvlsi.ecs.umass.edu ()
- Subject: Non-Blocking I/O
- Message-ID: <1993Jan6.184330.4041@risky.ecs.umass.edu>
- Originator: chou@umvlsi.ecs.umass.edu
- Sender: usenet@risky.ecs.umass.edu (USENET News System)
- Nntp-Posting-Host: umvlsi.ecs.umass.edu
- Organization: University of Massachusetts, Amherst
- Date: Wed, 6 Jan 1993 18:43:30 GMT
- Lines: 32
-
-
-
- I am trying to use non-blocking I/O in C and am having difficulties.
- I would like to have a read routine that would return immediately if
- there is no input available in standard input. This is what I have
- tried:
-
- #include <stdio.h>
- #include <fcntl.h>
-
- main ()
- {
- char buf[1];
- size_t size = 1;
-
- /* Set stdin to be non-blocking. */
- fcntl (stdin, F_SETFL, O_NDELAY);
-
- /* Prompt for some input. */
- printf ("Input a character: ");
-
- /* Get a character from stdin. If there is nothing in stdin, I want
- this to return immediately. */
- fread (buf, size, 1, stdin);
- }
-
- Any help with this would be appreciated.
-
- Please send your mail to chou@ecs.umass.edu
-
- Thanks,
- Yon
-