- ioctl FILEHANDLE,FUNCTION,SCALAR
-
Implements the ioctl(2) function. You'll probably first have to say
ioctl(2) 関数を実装します。 正しい関数の定義を得るために、おそらく最初に
require "sys/ioctl.ph"; # probably in # $Config{archlib}/sys/ioctl.ph
to get the correct function definitions. If sys/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 that may help you in this, but it's nontrivial.) SCALAR will be read and/or written depending on the FUNCTION; a C 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 a0
to the scalar before using it.) Thepack
andunpack
functions may be needed to manipulate the values of structures used byioctl
.としなくてはならないでしょう。 sys/ioctl.ph がないか、間違った定義をしている場合には、 <sys/ioctl.h>のような C のヘッダファイルをもとに、 自分で作らなければなりません。 (Perl の配布キットに入っている h2ph という Perl スクリプトが これを手助けしてくれるでしょうが、これは自明ではありません。) FOUNCTION に応じて SCALAR が読み書きされます; SCALAR の文字列値へのポインタが、実際の
ioctl
コールの 3 番目の引数として渡されます。 (SCALAR が文字列値を持っておらず、数値を持っている場合には、 文字列値へのポインタの代わりに、その値が渡されます。 このことを保証するためには、使用する前に SCALAR に0
を足してください。)ioctl
で使われる構造体の値を 操作するには、pack
関数とunpack
関数が必要となるでしょう。ioctl
(とfcntl
) の返り値は、 以下のようになります:if OS returns: then Perl returns: -1 undefined value 0 string "0 but true" anything else that number
OS が返した値: Perl が返す値: -1 未定義値 0 「0 だが真」の文字列 その他 その値そのもの
Thus Perl returns true on success and false on failure, yet you can still easily determine the actual value returned by the operating system:
つまり Perl は、成功時に「真」、失敗時に「偽」を返す ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
my $retval = ioctl(...) || -1; printf "System returned %d\n", $retval;
The special string
"0 but true"
is exempt fromArgument "..." isn't numeric
warnings on improper numeric conversions.特別な文字列
"0 だが真"
は、不適切な数値変換に関するArgument "..." isn't numeric
warnings 警告を回避します。Portability issues: "ioctl" in perlport.
移植性の問題: "ioctl" in perlport。