1994-05-19 06:09:50 -03:00
|
|
|
% Manual text by Jaap Vermeulen
|
1995-03-17 12:07:09 -04:00
|
|
|
\section{Built-in Module \sectcode{fcntl}}
|
1994-05-19 06:09:50 -03:00
|
|
|
\bimodindex{fcntl}
|
1995-03-13 06:03:32 -04:00
|
|
|
\indexii{\UNIX{}}{file control}
|
|
|
|
\indexii{\UNIX{}}{I/O control}
|
1994-05-19 06:09:50 -03:00
|
|
|
|
1995-03-13 06:03:32 -04:00
|
|
|
This module performs file control and I/O control on file descriptors.
|
|
|
|
It is an interface to the \dfn{fcntl()} and \dfn{ioctl()} \UNIX{} routines.
|
1994-05-19 06:09:50 -03:00
|
|
|
File descriptors can be obtained with the \dfn{fileno()} method of a
|
|
|
|
file or socket object.
|
|
|
|
|
|
|
|
The module defines the following functions:
|
|
|
|
|
|
|
|
\renewcommand{\indexsubitem}{(in module struct)}
|
|
|
|
|
1994-08-08 09:30:22 -03:00
|
|
|
\begin{funcdesc}{fcntl}{fd\, op\optional{\, arg}}
|
1994-05-19 06:09:50 -03:00
|
|
|
Perform the requested operation on file descriptor \code{\var{fd}}.
|
|
|
|
The operation is defined by \code{\var{op}} and is operating system
|
|
|
|
dependent. Typically these codes can be retrieved from the library
|
1994-08-08 09:30:22 -03:00
|
|
|
module \code{FCNTL}. The argument \code{\var{arg}} is optional, and
|
|
|
|
defaults to the integer value \code{0}. When
|
1994-05-19 06:09:50 -03:00
|
|
|
it is present, it can either be an integer value, or a string. With
|
|
|
|
the argument missing or an integer value, the return value of this
|
|
|
|
function is the integer return value of the real \code{fcntl()}
|
|
|
|
call. When the argument is a string it represents a binary
|
1995-03-13 06:03:32 -04:00
|
|
|
structure, e.g.\ created by \code{struct.pack()}. The binary data is
|
1994-05-19 06:09:50 -03:00
|
|
|
copied to a buffer whose address is passed to the real \code{fcntl()}
|
|
|
|
call. The return value after a successful call is the contents of
|
1995-03-13 06:03:32 -04:00
|
|
|
the buffer, converted to a string object. In case the
|
1994-05-19 06:09:50 -03:00
|
|
|
\code{fcntl()} fails, an \code{IOError} will be raised.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{ioctl}{fd\, op\, arg}
|
|
|
|
This function is identical to the \code{fcntl()} function, except
|
|
|
|
that the operations are typically defined in the library module
|
|
|
|
\code{IOCTL}.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
1996-06-26 16:20:33 -03:00
|
|
|
\begin{funcdesc}{flock}{fd\, op}
|
|
|
|
Perform the lock operation \var{op} on file descriptor \var{fd}.
|
|
|
|
See the Unix manual for details. (On some systems, this function is
|
|
|
|
emulated using \code{fcntl}.)
|
|
|
|
\end{funcdesc}
|
|
|
|
|
1996-10-11 14:43:34 -03:00
|
|
|
\begin{funcdesc}{lockf}{fd\, code\, \optional{len\, \optional{start\, \optional{whence}}}}
|
|
|
|
This is a wrapper around the \code{F_SETLK} and \code{F_SETLKW}
|
|
|
|
\code{fcntl()} calls. See the Unix manual for details.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
1994-05-19 06:09:50 -03:00
|
|
|
If the library modules \code{FCNTL} or \code{IOCTL} are missing, you
|
|
|
|
can find the opcodes in the C include files \code{sys/fcntl} and
|
|
|
|
\code{sys/ioctl}. You can create the modules yourself with the h2py
|
1995-08-10 11:21:11 -03:00
|
|
|
script, found in the \code{Tools/scripts} directory.
|
|
|
|
\stmodindex{FCNTL}
|
|
|
|
\stmodindex{IOCTL}
|
1994-05-19 06:09:50 -03:00
|
|
|
|
|
|
|
Examples (all on a SVR4 compliant system):
|
|
|
|
|
|
|
|
\bcode\begin{verbatim}
|
|
|
|
import struct, FCNTL
|
|
|
|
|
|
|
|
file = open(...)
|
|
|
|
rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1)
|
|
|
|
|
|
|
|
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
|
|
|
|
rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
|
|
|
|
\end{verbatim}\ecode
|
|
|
|
|
|
|
|
Note that in the first example the return value variable \code{rv} will
|
|
|
|
hold an integer value; in the second example it will hold a string
|
1996-06-26 16:20:33 -03:00
|
|
|
value. The structure lay-out for the \var{lockadata} variable is
|
|
|
|
system dependent -- therefore using the \code{flock()} call may be
|
|
|
|
better.
|