mayer@sun.com (Ronald &) (03/12/91)
On a sparcstation, SunOS 4.1 I am having a problem using the termio
ioctl TIOCSTI [simulate terminal input] when using gcc. While it
works as expected under cc, under gcc I get an "Inappropriate ioctl
for device" error message. Any ideas what I'm missing?
Ron Mayer
sun!sono!mayer mayer@sono.uucp
[A (short) example program and OS/system info follows:]
% cat ioc.c
/* This program works differently under gcc and cc. Why? */
#include <stdio.h>
#include <fcntl.h>
#include <sys/termios.h>
#include <errno.h>
main()
{
char a;
int fd=open("/dev/tty",O_RDWR);
int ioctl_return;
if (fd == -1) perror(NULL);
a='l';
ioctl(fd,TIOCSTI,&a); /* should send characters as if typed to the tty*/
a='s';
ioctl(fd,TIOCSTI,&a);
a='\n';
ioctl_return = ioctl(fd,TIOCSTI,&a);
if (ioctl_return == -1) perror(NULL);
}
%
% cc ioc.c
% a.out
ls
% ls [Note: The program "typed" this command]
a.out ice.lst ioc.c vhdl
%
%
% gcc ioc.c
% a.out
Inappropriate ioctl for device
%
%
%
% more /etc/motd
SunOS Release 4.1 (STANDALONE_1.2) #1: Wed Jul 25 00:05:22 PDT 1990
% arch -k
sun4c
%
pfalstad@phoenix.Princeton.EDU (Paul Falstad) (03/13/91)
sono!mayer@sun.com (Ronald &) wrote: >On a sparcstation, SunOS 4.1 I am having a problem using the termio >ioctl TIOCSTI [simulate terminal input] when using gcc. While it >works as expected under cc, under gcc I get an "Inappropriate ioctl >for device" error message. Any ideas what I'm missing? >/* This program works differently under gcc and cc. Why? */ > ioctl_return = ioctl(fd,TIOCSTI,&a); Most ioctl's have this problem with ANSI C compilers. The offending code is stuff like this in <sys/ioccom.h>: #define _IOW(x,y,t) (_IOC_IN|((sizeof(t)&_IOCPARM_MASK)<<16)|('x'<<8)|y) #define TIOCSTI _IOW(t, 114, char) /* simulate terminal input */ Putting a macro argument in single quotes is non-ANSI. The solution is to run the fixincludes script that comes with gcc. (Note that I erroneously called this problem a bug in gcc in the zsh documentation.) -- pfalstad@phoenix.princeton.edu The Germans are disputing it! Hegel is arguing that the reality is merely an a priori adjunct of non-absolutistic ethics; Kant, by the categorical imperative, is holding it ontologically exists only in the imagination; and Marx is claiming it was off sides.
rfg@NCD.COM (Ron Guilmette) (03/25/91)
In article <MAYER.91Mar11104808@porky.sono.uucp> sono!mayer@sun.com (Ronald &) writes: >On a sparcstation, SunOS 4.1 I am having a problem using the termio >ioctl TIOCSTI [simulate terminal input] when using gcc. While it >works as expected under cc, under gcc I get an "Inappropriate ioctl >for device" error message. Any ideas what I'm missing? On many machines, it is critically important that you run the fixincludes script before trying to use your system's own native <ioctl.h> in any programs which get compiled with gcc. -- // Ron ("Shoot From The Hip") Guilmette // Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg // New motto: If it ain't broke, try using a bigger hammer.