home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 15023 < prev    next >
Encoding:
Text File  |  1992-12-29  |  2.1 KB  |  53 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!cis.ohio-state.edu!public.btr.com!rem
  3. From: rem@public.btr.com (Robert E. Maas  rem@btr.com)
  4. Subject: Novice programming question: How to pass stdin to tcgetattr?
  5. Message-ID: <9212291904.AA07073@public.btr.com.BTR.COM>
  6. Sender: daemon@cis.ohio-state.edu
  7. Organization: The Ohio State University Department of Computer and Information Science
  8. Date: Tue, 29 Dec 1992 19:04:29 GMT
  9. Lines: 42
  10.  
  11. I'm just starting to program on Unix, and having trouble (please e-mail
  12. any answers to rem@BTR.Com):
  13.  
  14. How do I convert stdin (a pointer to a word containing the number zero)
  15. to a valid integer fd (file descriptor I presume) for passing to
  16. tcgetattr and related functions? I tried passing stdin and stdin* but
  17. each produced runtime errors (errno=9 and 14 respectively).
  18. #define EBADF           9               /* Bad file number */
  19. #define EFAULT          14              /* Bad address */
  20.  
  21. Where do I find stdio.h? (It's not on /sys/sys with termio.h etc.)
  22. More general question, given that cc can find some header file such as
  23. stdio.h just fine, how do I find out where it's finding it from?
  24. (What's the equivalent of 'whereis' for C header files?)
  25.  
  26. In case it makes any difference, this is SunOS 4.1.1
  27.  
  28. Here's my complete source code in case it helps diagnose what I'm trying.
  29.  
  30. #include <stdio.h>
  31. #include <termios.h>
  32. #include <unistd.h>
  33. #include <errno.h>
  34. main()
  35.   {printf("Hello on Unix stdin=[%d]->[%d]\n",stdin,*stdin); /* *stdin is 0 */
  36.    tryTermios();
  37.    printf("All Done.\n");
  38.   }
  39.  
  40. tryTermios()
  41.   {int fd,res;
  42.    struct termios *termios_p,ti;
  43.    termios_p=&ti; /* Want to use malloc here, that's a different question. */
  44.    printf("Going to call it ...\n");
  45.    res = tcgetattr(stdin, termios_p); /* res=-1 errno=9 How to fix it? */
  46.    printf("Called it, res=%d",res);
  47.    if (res<0) {printf(" errno=%d\n",errno); return; }
  48.    printf(" going to get fields ...\n");
  49.    printf(" c_iflag=%o c_oflag=%o\n c_cflag=%o c_lflag=%o c_line=%o\n",
  50.           (*termios_p).c_iflag,(*termios_p).c_oflag,(*termios_p).c_cflag,
  51.           (*termios_p).c_lflag,(*termios_p).c_line);
  52.    }
  53.