Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- PERL 4.0 Reference Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

     ioctl(FILEHANDLE,FUNCTION,SCALAR)

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

                  require "ioctl.ph"; # probably /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
             Unix  perl  kit which may help you in this.)  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';
                  $sgttyb_t = "ccccs";          # 4 chars and a short
                  if (ioctl(STDIN,$TIOCGETP,$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:           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;

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson