icon Top 9 categories map      RocketAware > Perl >

ioctl FILEHANDLE,FUNCTION,SCALAR

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.



Home

Search Perl pages


Subjects

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

    
ioctl FILEHANDLE,FUNCTION,SCALAR
Implements the ioctl(2) function. You'll probably have to say

    require "ioctl.ph"; # probably in /usr/local/lib/perl/ioctl.ph

first to get the correct function definitions. If ioctl.ph 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 which 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 'ioctl.ph';
    $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);
        ioctl(STDIN,&TIOCSETP,$sgttyb)
            || 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;

Source: Perl builtin functions
Copyright: Larry Wall, et al.
Next: join EXPR,LIST

Previous: int EXPR



(Corrections, notes, and links courtesy of RocketAware.com)


[Overview Topics]

Up to: Low level file and device operations
Up to: File Access




Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perlfunc/ioctl.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments