Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine


by gods (Initiate)
on Aug 24, 1999 at 22:42 UTC ( [id://273]=perlfunc: print w/replies, xml ) Need Help??


See the current Perl documentation for ioctl.

Here is our local, out-dated (pre-5.6) version:

ioctl - system-dependent device control system call


Implements the ioctl(2) function. You'll probably have to say

    require ""; # probably in /usr/local/lib/perl/

first to get the correct function definitions. If doesn't exist or doesn't have the correct definitions you'll have to roll your own, based on your C header files such as <sys/ioctl.h>. (There is a Perl script called h2ph that comes with the Perl kit that may help you in this, but it's nontrivial.) SCALAR will be read and/or written depending on the FUNCTION--a pointer to the string value of SCALAR will be passed as the third argument of the actual ioctl() call. (If SCALAR has no string value but does have a numeric value, that value will be passed rather than a pointer to the string value. To guarantee this to be TRUE, add a 0 to the scalar before using it.) The pack() and unpack() functions are useful for manipulating the values of structures used by ioctl(). The following example sets the erase character to DEL.

    require '';
    $getp = &TIOCGETP;
    die "NO TIOCGETP" if $@ || !$getp;
    $sgttyb_t = "ccccs";                # 4 chars and a short
    if (ioctl(STDIN,$getp,$sgttyb)) {
        @ary = unpack($sgttyb_t,$sgttyb);
        $ary[2] = 127;
        $sgttyb = pack($sgttyb_t,@ary);
            || die "Can't ioctl: $!";

The return value of ioctl() (and fcntl()) is as follows:

        if OS returns:          then Perl returns:
            -1                    undefined value
             0                  string "0 but true"
        anything else               that number

Thus Perl returns TRUE on success and FALSE on failure, yet you can still easily determine the actual value returned by the operating system:

    ($retval = ioctl(...)) || ($retval = -1);
    printf "System returned %d\n", $retval;

The special string ``0 but true'' is excempt from -w complaints about improper numeric conversions.

Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-07-21 19:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.