pke@public.BTR.COM (Peter Espen pke@btr.com) (03/09/91)
Can someone explain to me why the first ioctl call in the following test program fails with an invalid argument error? I am running A/UX 2.0. /***********************************************/ #define _SYSV_SOURCE #include <stdio.h> #include <termio.h> #include <fcntl.h> #include <sys/errno.h> extern int errno; int fp; char *c_on = "TEST OUTPUT"; char *name = "/dev/tty0"; main () { ttyout ( ); } ttyout( ) { int i, tt; struct termio my_termio; char *buf; if ((fp = open( name, O_RDWR | O_NDELAY)) == NULL) { printf("error opening /dev/tty0"); exit(0); } if ( (i = ioctl( fp, TCGETA, &my_termio)) < 0) { perror("TCGETA:"); fprintf(stderr, "%d: ioctl error on TCGETA op. \n", errno); exit(0); } my_termio.c_cflag |= B9600; if ( (i = ioctl( fp, TCSETA, &my_termio)) < 0) { fprintf(stderr, "ioctl error on TCSETA operation. \n"); exit(0); } buf = c_on; if (fputs(buf, fp) == NULL) fprintf(stderr, "can't fprintf to %s\n", name); else return; close(fp); } /************************************************/ Thanks, Peter Espen pke@btr.com peter@sophia.com
ksand@Apple.COM (Kent Sandvik) (03/09/91)
In article <2041@public.BTR.COM> pke@public.BTR.COM (Peter Espen pke@btr.com) writes: > >Can someone explain to me why the first ioctl call in the following test >program fails with an invalid argument error? > >I am running A/UX 2.0. > > >/***********************************************/ >#define _SYSV_SOURCE > >#include <stdio.h> >#include <termio.h> >#include <fcntl.h> >#include <sys/errno.h> > > >extern int errno; >int fp; > >char *c_on = "TEST OUTPUT"; >char *name = "/dev/tty0"; > >main () >{ > ttyout ( ); >} > >ttyout( ) >{ > int i, tt; > > struct termio my_termio; > char *buf; > > if ((fp = open( name, O_RDWR | O_NDELAY)) == NULL) { > printf("error opening /dev/tty0"); > exit(0); > } > > > if ( (i = ioctl( fp, TCGETA, &my_termio)) < 0) { > perror("TCGETA:"); > fprintf(stderr, "%d: ioctl error on TCGETA op. \n", errno); > exit(0); > } > > my_termio.c_cflag |= B9600; > > if ( (i = ioctl( fp, TCSETA, &my_termio)) < 0) { > fprintf(stderr, "ioctl error on TCSETA operation. \n"); > exit(0); > } > > buf = c_on; > > if (fputs(buf, fp) == NULL) > fprintf(stderr, "can't fprintf to %s\n", name); > else > return; > >close(fp); > >} >/************************************************/ Hmmm, I did a quick test on my 2.0.1 system sitting behind my back, and it did not bang out with the first ioctl call, neither the second. Sometimes ioctl and open on tty1, i.e. the printer port, fails because Localtalk/AppleTalk is operating on that port (default setting). Anyway, maybe someone else has an explanation, or this is gone in A/UX 2.0.1. regards, Kent Sandvik -- Kent Sandvik, Apple Computer Inc, Developer Technical Support NET:ksand@apple.com, AppleLink: KSAND DISCLAIMER: Private mumbo-jumbo Zippy++ says: "C++ was given to mankind, so that we might learn patience"
rmtodd@servalan.uucp (Richard Todd) (03/09/91)
pke@public.BTR.COM (Peter Espen pke@btr.com) writes: >Can someone explain to me why the first ioctl call in the following test >program fails with an invalid argument error? Afraid not. It gets past that ioctl with no problems for me. >I am running A/UX 2.0. So am I. I don't know offhand why that ioctl should fail, unless somehow the char. special file "/dev/tty0" has gotten its major/minor numbers munged. (They're 0,0 on my system; I think they should be the same on all A/UX systems, though I'm not sure on this). While I'm here, however, I might as well point out one thing I noticed about your program, namely that it did segfault later on when I ran it, right at the fputs() : > if ((fp = open( name, O_RDWR | O_NDELAY)) == NULL) { >... > if (fputs(buf, fp) == NULL) open returns a file descriptor, and fputs, expecting a FILE pointer, gets rather out of sorts at being passed a file descriptor instead. -- Richard Todd rmtodd@uokmax.ecn.uoknor.edu rmtodd@chinet.chi.il.us rmtodd@servalan.uucp "Try looking in the Yellow Pages under 'Psychotics'." -- Michael Santana
ron@xwind.UUCP (Ronald P. Hughes) (03/10/91)
In article <2041@public.BTR.COM> pke@public.BTR.COM (Peter Espen pke@btr.com) writes: > >Can someone explain to me why the first ioctl call in the following test >program fails with an invalid argument error? > This is just a wild guess, but are you using gcc? And, if so, did you run fixincludes? If you are running gcc and the file /usr/local/lib/gcc-include/sys/ioctl.h doesn't exist (I suppose your gcc could have been built to expect it elsewhere, but that's the most common location), then you haven't run fixincludes. Fixincludes is a shell script that copies all the standard include hierarchy from /usr/include to /usr/local/lib/gcc-include, makes whatever changes to the .h files contained therein to make them ansi compliant, then deletes whatever hasn't been modified. Gcc looks in /usr/local/lib/gcc-include before /usr/include. If this is your problem, then you either need to run fixincludes (I can email it to you if you like), or use the -traditional flag to gcc. The source of the problem? Consider the following macro definition: #define GRAUNCH(x,y,z) foobar('x' | ((y) << 8) + (z)) Is the 'x' (the one in single quotes) expanded as a macro arg, or is it a literal? What should it's behavior be? Check the ansi spec. Then examine /usr/include/sys/ioctl.h. You'll be amazed. Ronald P. Hughes ron@xwind.com (or ...!uunet!xwind!ron) CrossWind Technologies, Inc. 408-335-4988 "The fastest-growing software company in Felton!"
pke@public.BTR.COM (Peter Espen pke@btr.com) (03/10/91)
In article <2041@public.BTR.COM>, pke@public.BTR.COM (Peter Espen pke@btr.com) writes: > > Can someone explain to me why the first ioctl call in the following test > program fails with an invalid argument error? > ......... > > if ( (i = ioctl( fp, TCGETA, &my_termio)) < 0) { > perror("TCGETA:"); > fprintf(stderr, "%d: ioctl error on TCGETA op. \n", errno); > exit(0); > } > Well, I just needed to make sure that I had all the proper include files in /usr/local/lib/gcc-include by running the most recent fixincludes. Thanks for all the replies! Peter Espen pke@btr.com