[gnu.gcc.bug] Possible ioctl bug?

dwho@nmtsun.nmt.edu (David Olix) (07/10/89)

Compiler: gcc 1.35
Machine:  VAX 11/750
OS:       Unix 4.3 BSD
Problem:  ioctl function call returns error
Program:  test.c

#include <sys/ioctl.h>

struct sgttyb arg;

void main()
{
  if (ioctl(0, TIOCGETP, &arg) < 0)
    perror("ioctl");
}

Compiled with:
  gcc -g -o test test.c

Output:
  ioctl: Inappropriate ioctl for device

I don't know if this a problem with gcc or what, but when I compile the
same program using cc, there is no output (as expected).  Any help would
be useful.  Please respond via e-mail

TIA,

--David Olix (dwho@nmtsun.nmt.edu)

mujica@ra.cs.ucla.edu (S. Mujica) (07/11/89)

on 9 Jul 89 22:33:18 GMT,
dwho@nmtsun.nmt.edu (David Olix) said:
> Path: ucla-cs!usc!cs.utexas.edu!uunet!deimos.cis.ksu.edu!unmvax!nmtsun!dwho
> Lines: 29

> Compiler: gcc 1.35
> Machine:  VAX 11/750
> OS:       Unix 4.3 BSD
> Problem:  ioctl function call returns error
> Program:  test.c

> #include <sys/ioctl.h>

> struct sgttyb arg;

> void main()
> {
>   if (ioctl(0, TIOCGETP, &arg) < 0)
>     perror("ioctl");
> }

> Compiled with:
>   gcc -g -o test test.c

> Output:
>   ioctl: Inappropriate ioctl for device

> I don't know if this a problem with gcc or what, but when I compile the
> same program using cc, there is no output (as expected).  Any help would
> be useful.  Please respond via e-mail

> TIA,

> --David Olix (dwho@nmtsun.nmt.edu)


The following is in the node (gcc)Installation node of the gcc Info
files ( I have installed gcc with the fixed include files, and your
test program seems to work ok, SunOS 4.0, SUN 3/280, gcc 1.35):

     *Warning: the GNU CPP may not work for `ioctl.h', `ttychars.h'
     and other system header files unless the `-traditional' option
     is used.*  The bug is in the header files: at least on some
     machines, they rely on behavior that is incompatible with ANSI
     C.  This behavior consists of substituting for macro argument
     names when they appear inside of character constants.  The
     `-traditional' option tells GNU CC to behave the way these
     headers expect.

     Because of this problem, you might prefer to configure GNU CC to
     use the system's own C preprocessor.  To do so, make the file
     `/usr/local/lib/gcc-cpp' a link to `/lib/cpp'.

     Alternatively, on Sun systems and 4.3BSD at least, you can
     correct the include files by running the shell script
     `fixincludes'.  This installs modified, corrected copies of the
     files `ioctl.h', `ttychars.h' and many others, in a special
     directory where only GNU CC will normally look for them.  This
     script will work on various systems because it choose the files
     by searching all the system headers for the problem cases that
     we know about.



Sergio Mujica		mujica@cs.ucla.edu
Computer Science Department, UCLA