Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f61b35

Browse files
committed
README: correct typo (lib.index)
lib.tex: include libfcntl, libposixfile myformat.sty: add tableii environment libfcntl.tex, libposixfile.tex: docs contributed by Jaap V
1 parent c762bec commit 7f61b35

4 files changed

Lines changed: 424 additions & 0 deletions

File tree

Doc/lib/libfcntl.tex

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
% Manual text by Jaap Vermeulen
2+
\section{Built-in module \sectcode{fcntl}}
3+
\bimodindex{fcntl}
4+
\indexii{UNIX}{file control}
5+
\indexii{UNIX}{IO control}
6+
7+
This module performs file control and IO control on file descriptors.
8+
It is an interface to the \dfn{fcntl()} and \dfn{ioctl()} \UNIX routines.
9+
File descriptors can be obtained with the \dfn{fileno()} method of a
10+
file or socket object.
11+
12+
The module defines the following functions:
13+
14+
\renewcommand{\indexsubitem}{(in module struct)}
15+
16+
\begin{funcdesc}{fcntl}{fd\, op\, arg}
17+
Perform the requested operation on file descriptor \code{\var{fd}}.
18+
The operation is defined by \code{\var{op}} and is operating system
19+
dependent. Typically these codes can be retrieved from the library
20+
module \code{FCNTL}. The argument \code{\var{arg}} is optional. When
21+
it is missing it is interpreted as the integer value \code{0}. When
22+
it is present, it can either be an integer value, or a string. With
23+
the argument missing or an integer value, the return value of this
24+
function is the integer return value of the real \code{fcntl()}
25+
call. When the argument is a string it represents a binary
26+
structure, e.g. created by \code{struct.pack()}. The binary data is
27+
copied to a buffer whose address is passed to the real \code{fcntl()}
28+
call. The return value after a successful call is the contents of
29+
the buffer, converted to a string object. In the case the
30+
\code{fcntl()} fails, an \code{IOError} will be raised.
31+
\end{funcdesc}
32+
33+
\begin{funcdesc}{ioctl}{fd\, op\, arg}
34+
This function is identical to the \code{fcntl()} function, except
35+
that the operations are typically defined in the library module
36+
\code{IOCTL}.
37+
\end{funcdesc}
38+
39+
If the library modules \code{FCNTL} or \code{IOCTL} are missing, you
40+
can find the opcodes in the C include files \code{sys/fcntl} and
41+
\code{sys/ioctl}. You can create the modules yourself with the h2py
42+
script, found in the \code{Demo/scripts} directory.
43+
44+
Examples (all on a SVR4 compliant system):
45+
46+
\bcode\begin{verbatim}
47+
import struct, FCNTL
48+
49+
file = open(...)
50+
rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1)
51+
52+
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
53+
rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
54+
\end{verbatim}\ecode
55+
56+
Note that in the first example the return value variable \code{rv} will
57+
hold an integer value; in the second example it will hold a string
58+
value.

Doc/lib/libposixfile.tex

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
% Manual text and implementation by Jaap Vermeulen
2+
\section{Standard Module \sectcode{posixfile}}
3+
\bimodindex{posixfile}
4+
\indexii{posix}{file object}
5+
6+
This module implements some additional functionality over the built-in
7+
file objects. In particular, it implements file locking, control over
8+
the file flags, and an easy interface to duplicate the file object.
9+
The module defines a new file object, the posixfile object. It
10+
inherits all the standard file object methods and adds the methods
11+
described below.
12+
13+
To instantiate a posixfile object, use the \code{open()} function in
14+
the posixfile module. The resulting object looks and feels the same as
15+
a standard file object.
16+
17+
The posixfile module defines the following constants:
18+
19+
\renewcommand{\indexsubitem}{(in module posixfile)}
20+
\begin{datadesc}{SEEK_SET}
21+
offset is calculated from the start of the file
22+
\end{datadesc}
23+
24+
\begin{datadesc}{SEEK_CUR}
25+
offset is calculated from the current position in the file
26+
\end{datadesc}
27+
28+
\begin{datadesc}{SEEK_END}
29+
offset is calculated from the end of the file
30+
\end{datadesc}
31+
32+
The posixfile module defines the following functions:
33+
34+
\renewcommand{\indexsubitem}{(in module posixfile)}
35+
\begin{funcdesc}{open}{filename\, mode}
36+
Create a new posixfile object with the given filename and mode. The
37+
filename and mode are interpreted the same way as the \code{open()}
38+
builtin function.
39+
\end{funcdesc}
40+
41+
\begin{funcdesc}{openfile}{fileobject}
42+
Create a new posixfile object with the given standard file object.
43+
The resulting object has the same filename and mode as the original
44+
file object.
45+
\end{funcdesc}
46+
47+
The posixfile object defines the following additional methods:
48+
49+
\renewcommand{\indexsubitem}{(posixfile method)}
50+
\begin{funcdesc}{lock}{fmt\, len\, start\, whence}
51+
Lock the specified section of the file that the file object is
52+
referring to. The arguments \code{\var{len}}, \code{\var{start}}
53+
and \code{\var{whence}} are optional with the understanding that
54+
if \code{\var{start}} is used \code{\var{len}} becomes mandatory,
55+
and if \code{\var{whence}} is used \code{\var{len}} and
56+
\code{\var{start}} become mandatory. The format is explained
57+
below in a table. The length argument specifies the length of the
58+
section that should be locked. The default is \code{0}. The start
59+
specifies the starting offset of the section. The default is
60+
\code{0}. The whence argument specifies where the offset is
61+
relative to. It accepts one of the constants \code{SEEK_SET},
62+
\code{SEEK_CUR} or \code{SEEK_END}. The default is \code{SEEK_SET}.
63+
For more information about the arguments refer to the fcntl
64+
manual page on your system.
65+
\end{funcdesc}
66+
67+
\begin{funcdesc}{flags}{fmt}
68+
Set the specified flags for the file that the file object is referring
69+
to. The new flags are ORed with the old flags, unless specified
70+
otherwise. The format is explained below in a table. Without
71+
arguments a string indicating the current flags is returned (this is
72+
the same as the '?'modifier). For more information about the flags
73+
refer to the fcntl manual page on your system.
74+
\end{funcdesc}
75+
76+
\begin{funcdesc}{dup}{}
77+
Duplicate the file object and the underlying file pointer and file
78+
descriptor. The resulting object behaves as if it were newly
79+
opened.
80+
\end{funcdesc}
81+
82+
\begin{funcdesc}{dup2}{fd}
83+
Duplicate the file object and the underlying file pointer and file
84+
descriptor. The new object will have the given file descriptor.
85+
Otherwise the resulting object behaves as if it were newly opened.
86+
\end{funcdesc}
87+
88+
\begin{funcdesc}{file}{}
89+
Return the standard file object that the posixfile object is based
90+
on. This is sometimes necessary for functions that insist on a
91+
standard file object.
92+
\end{funcdesc}
93+
94+
All methods return \code{IOError} when the request fails.
95+
96+
Format characters for the \code{lock()} method have the following meaning:
97+
98+
\begin{tableii}{|c|l|}{samp}{Format}{Meaning}
99+
\lineii{u}{unlock the specified region}
100+
\lineii{r}{request a read lock for the specified section}
101+
\lineii{w}{request a write lock for the specified section}
102+
\end{tableii}
103+
104+
In addition the following modifiers can be added to the format:
105+
106+
\begin{tableiii}{|c|l|c|}{samp}{Modifier}{Meaning}{Notes}
107+
\lineiii{|}{wait until the lock has been granted}{}
108+
\lineiii{?}{return the first lock conflicting with the requested lock,
109+
or \code{None} if there is no conflict.}{(1)}
110+
\end{tableiii}
111+
112+
Note:
113+
114+
(1) The lock returned is in the format \code{(mode, len, start,
115+
whence, pid)} where mode is a character representing the type of lock
116+
('r' or 'w'). This modifier prevents a request from being granted; it
117+
is for query purposes only.
118+
119+
Format character for the \code{flags()} method have the following meaning:
120+
121+
\begin{tableii}{|c|l|}{samp}{Format}{Meaning}
122+
\lineii{a}{append only flag}
123+
\lineii{c}{close on exec flag}
124+
\lineii{n}{no delay flag (also called non-blocking flag)}
125+
\lineii{s}{synchronization flag}
126+
\end{tableii}
127+
128+
In addition the following modifiers can be added to the format:
129+
130+
\begin{tableiii}{|c|l|c|}{samp}{Modifier}{Meaning}{Notes}
131+
\lineiii{!}{turn the specified flags 'off', instead of the default 'on'}{(1)}
132+
\lineiii{=}{replace the flags, instead of the default 'OR' operation}{(1)}
133+
\lineiii{?}{return a string in which the characters represent the flags that
134+
are set.}{(2)}
135+
\end{tableiii}
136+
137+
Note:
138+
139+
(1) The \code{!} and \code{=} modifiers are mutually exclusive.
140+
141+
(2) This string represents the flag after they may have been altered
142+
by the same call.
143+
144+
Examples:
145+
146+
\bcode\begin{verbatim}
147+
from posixfile import *
148+
149+
file = open('/tmp/test', 'w')
150+
file.lock('w|')
151+
...
152+
file.lock('u')
153+
file.close()
154+
\end{verbatim}\ecode

Doc/libfcntl.tex

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
% Manual text by Jaap Vermeulen
2+
\section{Built-in module \sectcode{fcntl}}
3+
\bimodindex{fcntl}
4+
\indexii{UNIX}{file control}
5+
\indexii{UNIX}{IO control}
6+
7+
This module performs file control and IO control on file descriptors.
8+
It is an interface to the \dfn{fcntl()} and \dfn{ioctl()} \UNIX routines.
9+
File descriptors can be obtained with the \dfn{fileno()} method of a
10+
file or socket object.
11+
12+
The module defines the following functions:
13+
14+
\renewcommand{\indexsubitem}{(in module struct)}
15+
16+
\begin{funcdesc}{fcntl}{fd\, op\, arg}
17+
Perform the requested operation on file descriptor \code{\var{fd}}.
18+
The operation is defined by \code{\var{op}} and is operating system
19+
dependent. Typically these codes can be retrieved from the library
20+
module \code{FCNTL}. The argument \code{\var{arg}} is optional. When
21+
it is missing it is interpreted as the integer value \code{0}. When
22+
it is present, it can either be an integer value, or a string. With
23+
the argument missing or an integer value, the return value of this
24+
function is the integer return value of the real \code{fcntl()}
25+
call. When the argument is a string it represents a binary
26+
structure, e.g. created by \code{struct.pack()}. The binary data is
27+
copied to a buffer whose address is passed to the real \code{fcntl()}
28+
call. The return value after a successful call is the contents of
29+
the buffer, converted to a string object. In the case the
30+
\code{fcntl()} fails, an \code{IOError} will be raised.
31+
\end{funcdesc}
32+
33+
\begin{funcdesc}{ioctl}{fd\, op\, arg}
34+
This function is identical to the \code{fcntl()} function, except
35+
that the operations are typically defined in the library module
36+
\code{IOCTL}.
37+
\end{funcdesc}
38+
39+
If the library modules \code{FCNTL} or \code{IOCTL} are missing, you
40+
can find the opcodes in the C include files \code{sys/fcntl} and
41+
\code{sys/ioctl}. You can create the modules yourself with the h2py
42+
script, found in the \code{Demo/scripts} directory.
43+
44+
Examples (all on a SVR4 compliant system):
45+
46+
\bcode\begin{verbatim}
47+
import struct, FCNTL
48+
49+
file = open(...)
50+
rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1)
51+
52+
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
53+
rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
54+
\end{verbatim}\ecode
55+
56+
Note that in the first example the return value variable \code{rv} will
57+
hold an integer value; in the second example it will hold a string
58+
value.

0 commit comments

Comments
 (0)