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