ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
3.2.77 ioctlioctl This function implements the ioctl(2) system call. 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>. (The Perl distribution includes a script called
h2ph to help you do this, but it's non-trivial.)
require 'ioctl.ph'; $getp = &TIOCGETP or die "NO TIOCGETP"; $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 or die "Can't ioctl TIOCSETP: $!"; } The return value of ioctl (and fcntl) is as follows:
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(...) or $retval = -1; printf "System returned %d\n", $retval; Calls to ioctl should not be considered portable. If, say, you're merely turning off echo once for the whole script, it's much more portable (and not much slower) to say: system "stty -echo"; # Works on most UNIX boxen. Just because you can do something in Perl doesn't mean you ought to. To quote the Apostle Paul, "Everything is permissible - but not everything is beneficial." |