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

Skip to content

Commit d5a2f0b

Browse files
committed
#18985: Improve fcntl documentation.
Original patch by Vajrasky Kok, further improved (I hope) by me.
1 parent 7c934da commit d5a2f0b

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

Doc/library/fcntl.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ The module defines the following functions:
3030

3131
.. function:: fcntl(fd, op[, arg])
3232

33-
Perform the requested operation on file descriptor *fd* (file objects providing
34-
a :meth:`~io.IOBase.fileno` method are accepted as well). The operation is
35-
defined by *op*
36-
and is operating system dependent. These codes are also found in the
37-
:mod:`fcntl` module. The argument *arg* is optional, and defaults to the integer
33+
Perform the operation *op* on file descriptor *fd* (file objects providing
34+
a :meth:`~io.IOBase.fileno` method are accepted as well). The values used
35+
for *op* are operating system dependent, and are available as constants
36+
in the :mod:`fcntl` module, using the same names as used in the relevant C
37+
header files. The argument *arg* is optional, and defaults to the integer
3838
value ``0``. When present, it can either be an integer value, or a string.
3939
With the argument missing or an integer value, the return value of this function
4040
is the integer return value of the C :c:func:`fcntl` call. When the argument is
@@ -56,6 +56,9 @@ The module defines the following functions:
5656
that the argument handling is even more complicated.
5757

5858
The op parameter is limited to values that can fit in 32-bits.
59+
Additional constants of interest for use as the *op* argument can be
60+
found in the :mod:`termios` module, under the same names as used in
61+
the relevant C header files.
5962

6063
The parameter *arg* can be one of an integer, absent (treated identically to the
6164
integer ``0``), an object supporting the read-only buffer interface (most likely

Modules/fcntlmodule.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ conv_descriptor(PyObject *object, int *target)
2727
}
2828

2929

30-
/* fcntl(fd, opt, [arg]) */
30+
/* fcntl(fd, op, [arg]) */
3131

3232
static PyObject *
3333
fcntl_fcntl(PyObject *self, PyObject *args)
@@ -77,11 +77,12 @@ fcntl_fcntl(PyObject *self, PyObject *args)
7777
}
7878

7979
PyDoc_STRVAR(fcntl_doc,
80-
"fcntl(fd, opt, [arg])\n\
80+
"fcntl(fd, op, [arg])\n\
8181
\n\
82-
Perform the requested operation on file descriptor fd. The operation\n\
83-
is defined by op and is operating system dependent. These constants are\n\
84-
available from the fcntl module. The argument arg is optional, and\n\
82+
Perform the operation op on file descriptor fd. The values used\n\
83+
for op are operating system dependent, and are available\n\
84+
as constants in the fcntl module, using the same names as used in\n\
85+
the relevant C header files. The argument arg is optional, and\n\
8586
defaults to 0; it may be an int or a string. If arg is given as a string,\n\
8687
the return value of fcntl is a string of that length, containing the\n\
8788
resulting value put in the arg buffer by the operating system. The length\n\
@@ -90,7 +91,7 @@ is an integer or if none is specified, the result value is an integer\n\
9091
corresponding to the return value of the fcntl call in the C code.");
9192

9293

93-
/* ioctl(fd, opt, [arg]) */
94+
/* ioctl(fd, op, [arg]) */
9495

9596
static PyObject *
9697
fcntl_ioctl(PyObject *self, PyObject *args)
@@ -104,7 +105,7 @@ fcntl_ioctl(PyObject *self, PyObject *args)
104105
whereas the system expects it to be a 32bit bit field value
105106
regardless of it being passed as an int or unsigned long on
106107
various platforms. See the termios.TIOCSWINSZ constant across
107-
platforms for an example of thise.
108+
platforms for an example of this.
108109
109110
If any of the 64bit platforms ever decide to use more than 32bits
110111
in their unsigned long ioctl codes this will break and need
@@ -222,11 +223,12 @@ fcntl_ioctl(PyObject *self, PyObject *args)
222223
}
223224

224225
PyDoc_STRVAR(ioctl_doc,
225-
"ioctl(fd, opt[, arg[, mutate_flag]])\n\
226+
"ioctl(fd, op[, arg[, mutate_flag]])\n\
226227
\n\
227-
Perform the requested operation on file descriptor fd. The operation is\n\
228-
defined by opt and is operating system dependent. Typically these codes are\n\
229-
retrieved from the fcntl or termios library modules.\n\
228+
Perform the operation op on file descriptor fd. The values used for op\n\
229+
are operating system dependent, and are available as constants in the\n\
230+
fcntl or termios library modules, using the same names as used in the\n\
231+
relevant C header files.\n\
230232
\n\
231233
The argument arg is optional, and defaults to 0; it may be an int or a\n\
232234
buffer containing character data (most likely a string or an array). \n\

0 commit comments

Comments
 (0)