home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19321 < prev    next >
Encoding:
Text File  |  1993-01-06  |  1.2 KB  |  46 lines

  1. Xref: sparky comp.lang.c:19321 comp.unix.questions:15217
  2. Newsgroups: comp.lang.c,comp.unix.questions
  3. Path: sparky!uunet!noc.near.net!nic.umass.edu!risky.ecs.umass.edu!umvlsi.ecs.umass.edu!chou
  4. From: chou@umvlsi.ecs.umass.edu ()
  5. Subject: Non-Blocking I/O
  6. Message-ID: <1993Jan6.184330.4041@risky.ecs.umass.edu>
  7. Originator: chou@umvlsi.ecs.umass.edu
  8. Sender: usenet@risky.ecs.umass.edu (USENET News System)
  9. Nntp-Posting-Host: umvlsi.ecs.umass.edu
  10. Organization: University of Massachusetts, Amherst
  11. Date: Wed, 6 Jan 1993 18:43:30 GMT
  12. Lines: 32
  13.  
  14.  
  15.  
  16. I am trying to use non-blocking I/O in C and am having difficulties.
  17. I would like to have a read routine that would return immediately if
  18. there is no input available in standard input.  This is what I have
  19. tried:
  20.  
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23.  
  24. main ()
  25. {
  26.     char buf[1];
  27.     size_t size = 1;
  28.  
  29.     /*  Set stdin to be non-blocking.  */
  30.     fcntl (stdin, F_SETFL, O_NDELAY);
  31.  
  32.     /*  Prompt for some input.  */
  33.     printf ("Input a character:  ");
  34.  
  35.     /*  Get a character from stdin.  If there is nothing in stdin, I want
  36.     this to return immediately.  */
  37.     fread (buf, size, 1, stdin);
  38. }
  39.  
  40. Any help with this would be appreciated.
  41.  
  42. Please send your mail to chou@ecs.umass.edu
  43.  
  44. Thanks,
  45. Yon
  46.