annotate Doc/libfcntl.tex @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 6f032ea26642
children 3468ea8645ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 % Manual text by Jaap Vermeulen
2576
f47bc5554418 mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents: 2527
diff changeset
2 \section{Built-in Module \sectcode{fcntl}}
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 \bimodindex{fcntl}
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 1767
diff changeset
4 \indexii{\UNIX{}}{file control}
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 1767
diff changeset
5 \indexii{\UNIX{}}{I/O control}
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 1767
diff changeset
7 This module performs file control and I/O control on file descriptors.
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 1767
diff changeset
8 It is an interface to the \dfn{fcntl()} and \dfn{ioctl()} \UNIX{} routines.
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 File descriptors can be obtained with the \dfn{fileno()} method of a
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 file or socket object.
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 The module defines the following functions:
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 \renewcommand{\indexsubitem}{(in module struct)}
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
1767
907605320a5f Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents: 1644
diff changeset
16 \begin{funcdesc}{fcntl}{fd\, op\optional{\, arg}}
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 Perform the requested operation on file descriptor \code{\var{fd}}.
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 The operation is defined by \code{\var{op}} and is operating system
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 dependent. Typically these codes can be retrieved from the library
1767
907605320a5f Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents: 1644
diff changeset
20 module \code{FCNTL}. The argument \code{\var{arg}} is optional, and
907605320a5f Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents: 1644
diff changeset
21 defaults to the integer value \code{0}. When
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 it is present, it can either be an integer value, or a string. With
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 the argument missing or an integer value, the return value of this
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 function is the integer return value of the real \code{fcntl()}
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 call. When the argument is a string it represents a binary
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 1767
diff changeset
26 structure, e.g.\ created by \code{struct.pack()}. The binary data is
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 copied to a buffer whose address is passed to the real \code{fcntl()}
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 call. The return value after a successful call is the contents of
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 1767
diff changeset
29 the buffer, converted to a string object. In case the
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 \code{fcntl()} fails, an \code{IOError} will be raised.
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 \end{funcdesc}
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 \begin{funcdesc}{ioctl}{fd\, op\, arg}
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 This function is identical to the \code{fcntl()} function, except
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 that the operations are typically defined in the library module
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 \code{IOCTL}.
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 \end{funcdesc}
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
3708
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
39 \begin{funcdesc}{flock}{fd\, op}
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
40 Perform the lock operation \var{op} on file descriptor \var{fd}.
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
41 See the Unix manual for details. (On some systems, this function is
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
42 emulated using \code{fcntl}.)
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
43 \end{funcdesc}
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
44
4406
6f032ea26642 Added embryonic description of fcntl.lockf(). Added pointer to that
Guido van Rossum <guido@python.org>
parents: 3708
diff changeset
45 \begin{funcdesc}{lockf}{fd\, code\, \optional{len\, \optional{start\, \optional{whence}}}}
6f032ea26642 Added embryonic description of fcntl.lockf(). Added pointer to that
Guido van Rossum <guido@python.org>
parents: 3708
diff changeset
46 This is a wrapper around the \code{F_SETLK} and \code{F_SETLKW}
6f032ea26642 Added embryonic description of fcntl.lockf(). Added pointer to that
Guido van Rossum <guido@python.org>
parents: 3708
diff changeset
47 \code{fcntl()} calls. See the Unix manual for details.
6f032ea26642 Added embryonic description of fcntl.lockf(). Added pointer to that
Guido van Rossum <guido@python.org>
parents: 3708
diff changeset
48 \end{funcdesc}
6f032ea26642 Added embryonic description of fcntl.lockf(). Added pointer to that
Guido van Rossum <guido@python.org>
parents: 3708
diff changeset
49
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 If the library modules \code{FCNTL} or \code{IOCTL} are missing, you
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 can find the opcodes in the C include files \code{sys/fcntl} and
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 \code{sys/ioctl}. You can create the modules yourself with the h2py
2943
8edbeaa2bbf7 typos only
Guido van Rossum <guido@python.org>
parents: 2576
diff changeset
53 script, found in the \code{Tools/scripts} directory.
8edbeaa2bbf7 typos only
Guido van Rossum <guido@python.org>
parents: 2576
diff changeset
54 \stmodindex{FCNTL}
8edbeaa2bbf7 typos only
Guido van Rossum <guido@python.org>
parents: 2576
diff changeset
55 \stmodindex{IOCTL}
1644
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 Examples (all on a SVR4 compliant system):
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 \bcode\begin{verbatim}
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 import struct, FCNTL
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 file = open(...)
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1)
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 \end{verbatim}\ecode
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 Note that in the first example the return value variable \code{rv} will
fa50d4bd5537 README: correct typo (lib.index)
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 hold an integer value; in the second example it will hold a string
3708
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
71 value. The structure lay-out for the \var{lockadata} variable is
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
72 system dependent -- therefore using the \code{flock()} call may be
0f6f0e98e3b6 Add flock; warn about lockdata system dependency when using fcntl.
Guido van Rossum <guido@python.org>
parents: 2943
diff changeset
73 better.