[comp.lang.perl] my ioctl's don't work

eastick@me.utoronto.ca (Doug Eastick) (04/12/90)

I'm trying to get a program to work in cbreak mode.  I stole this
from someone (Randal, I think).  I'm including sys/ioctl.h (after
makelib'ing it).  The problem lies with the TIOCGETP ioctl:
***
Can't ioctl TIOCGETP: Inappropriate ioctl for device at blah line 83.
***
The answer is simple, I just don't know what it is :-(.  Any help is
appreciated.  Thanks very much.

Specifics:	Patchlevel 18
		UMIPS-BSD 2.1 (BSD 4.3 like)
	or	SunOS 3.5 (breaks on both)

-------
sub cbreak {
    &set_cbreak(1);
} 

sub cooked {
    &set_cbreak(0);
} 

sub set_cbreak {
    local($on) = $_[0];
    local($sgttyb);

    $sgttyb_t = 'C4 S' unless $sgttyb_t;

    ioctl(STDIN,$TIOCGETP,$sgttyb) 
	|| die "Can't ioctl TIOCGETP: $!";


    @ary = unpack($sgttyb_t,$sgttyb);
    if ($on) {
	$ary[4] |= $CBREAK;
	$ary[4] &= ~$ECHO;
    } else {
	$ary[4] &= ~$CBREAK;
	$ary[4] |= $ECHO;
    }
    $sgttyb = pack($sgttyb_t,@ary);
    ioctl(STDIN,$TIOCSETP,$sgttyb)
	    || die "Can't ioctl TIOCSETP: $!";

}

--
Doug Eastick -- eastick@me.utoronto.ca
"I'm going to the backseat of my car with my wife, and I
 won't be back for TEN MINUTES!" -- Homer Simpson in Jacques to be Wild

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (04/12/90)

In article <1990Apr11.142002.26192@me.toronto.edu> eastick@me.utoronto.ca (Doug Eastick) writes:
: I'm trying to get a program to work in cbreak mode.  I stole this
: from someone (Randal, I think).  I'm including sys/ioctl.h (after
: makelib'ing it).  The problem lies with the TIOCGETP ioctl:
: ***
: Can't ioctl TIOCGETP: Inappropriate ioctl for device at blah line 83.
: ***
: The answer is simple, I just don't know what it is :-(.  Any help is
: appreciated.  Thanks very much.

I'd suggest you check the value of $TIOCGETP at the point of the ioctl.
If it's 0 then you may need to say $TIOCGETP = &TIOCGETP; at some point.
Likewise for $TIOCSETP.

It's also possible the 'do' is failing for some reason.

Larry

eastick@me.utoronto.ca (Doug Eastick) (04/12/90)

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
>I wrote:
>: The problem lies with the TIOCGETP ioctl:
>: Can't ioctl TIOCGETP: Inappropriate ioctl for device at blah line 83.

>I'd suggest you check the value of $TIOCGETP at the point of the ioctl.
>If it's 0 then you may need to say $TIOCGETP = &TIOCGETP; at some point.
>Likewise for $TIOCSETP.

Checked it.  In the debugger, "print $TIOCGETP" gives nothing (either
spaces, or nulls).  The $TIOCGETP = &TIOCGETP didn't help either.  Any
other suggestions?  This seems too simple.

From ioctl.h, if it helps:
	eval 'sub _IOR {
	    local($x,$y,$t) = @_;
	    eval "(&IOC_OUT|(($sizeof{$t}&&IOCPARM_MASK)<<16)|(ord(\'$x\')<<8)|$y)";
	}';
    eval 'sub TIOCGETP {&_IOR("t", 8,\'struct sgttyb\');}';
    eval 'sub TIOCSETP {&_IOW("t", 9,\'struct sgttyb\');}';

BTW, the code came from T. Christiansen's package.  His program barfs
too.
--
Doug Eastick -- eastick@me.utoronto.ca
"I'm going to the backseat of my car with my wife, and I
 won't be back for TEN MINUTES!" -- Homer Simpson in Jacques to be Wild

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (04/12/90)

In article <1990Apr12.094108.24785@me.toronto.edu> eastick@me.utoronto.ca (Doug Eastick) writes:
: From ioctl.h, if it helps:
: 	eval 'sub _IOR {
: 	    local($x,$y,$t) = @_;
: 	    eval "(&IOC_OUT|(($sizeof{$t}&&IOCPARM_MASK)<<16)|(ord(\'$x\')<<8)|$y)";
: 	}';

Oh, that's the && bug.  It should read $sizeof{$t} & &IOCPARM_MASK.

Larry