annotate Modules/fcntlmodule.c @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 1e2c3e7fe63c
children fd25030223b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* fcntl module */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
36793
1e8cb47beaaa Make Py_ssize_t-clean
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
4 #define PY_SSIZE_T_CLEAN
1e8cb47beaaa Make Py_ssize_t-clean
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
5
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
6 #include "Python.h"
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
8 #ifdef HAVE_SYS_FILE_H
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
9 #include <sys/file.h>
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
10 #endif
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
11
4623
1fab981465c8 Include <sys/ioctl.h>, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
12 #include <sys/ioctl.h>
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
13 #include <fcntl.h>
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
14 #ifdef HAVE_STROPTS_H
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
15 #include <stropts.h>
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
16 #endif
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
18 static int
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
19 conv_descriptor(PyObject *object, int *target)
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
20 {
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
21 int fd = PyObject_AsFileDescriptor(object);
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
22
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
23 if (fd < 0)
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
24 return 0;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
25 *target = fd;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
26 return 1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
27 }
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
28
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
29
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 /* fcntl(fd, opt, [arg]) */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
32 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
33 fcntl_fcntl(PyObject *self, PyObject *args)
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 {
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 int fd;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 int code;
54306
1e2c3e7fe63c Merged revisions 72887 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 48192
diff changeset
37 long arg;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 int ret;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 char *str;
36793
1e8cb47beaaa Make Py_ssize_t-clean
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
40 Py_ssize_t len;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 char buf[1024];
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
43 if (PyArg_ParseTuple(args, "O&is#:fcntl",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
44 conv_descriptor, &fd, &code, &str, &len)) {
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 if (len > sizeof buf) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
46 PyErr_SetString(PyExc_ValueError,
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
47 "fcntl string arg too long");
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 memcpy(buf, str, len);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
51 Py_BEGIN_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
52 ret = fcntl(fd, code, buf);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
53 Py_END_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
54 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
55 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
58 return PyString_FromStringAndSize(buf, len);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
61 PyErr_Clear();
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
62 arg = 0;
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
63 if (!PyArg_ParseTuple(args,
54306
1e2c3e7fe63c Merged revisions 72887 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 48192
diff changeset
64 "O&i|l;fcntl requires a file or file descriptor,"
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
65 " an integer and optionally a third integer or a string",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
66 conv_descriptor, &fd, &code, &arg)) {
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
67 return NULL;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
69 Py_BEGIN_ALLOW_THREADS
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 ret = fcntl(fd, code, arg);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
71 Py_END_ALLOW_THREADS
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
73 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
76 return PyInt_FromLong((long)ret);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
79 PyDoc_STRVAR(fcntl_doc,
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
80 "fcntl(fd, opt, [arg])\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
81 \n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
82 Perform the requested operation on file descriptor fd. The operation\n\
17765
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
83 is defined by op and is operating system dependent. These constants are\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
84 available from the fcntl module. The argument arg is optional, and\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
85 defaults to 0; it may be an int or a string. If arg is given as a string,\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
86 the return value of fcntl is a string of that length, containing the\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
87 resulting value put in the arg buffer by the operating system.The length\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
88 of the arg string is not allowed to exceed 1024 bytes. If the arg given\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
89 is an integer or if none is specified, the result value is an integer\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
90 corresponding to the return value of the fcntl call in the C code.");
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
91
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 /* ioctl(fd, opt, [arg]) */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
95 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
96 fcntl_ioctl(PyObject *self, PyObject *args)
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 {
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
98 #define IOCTL_BUFSZ 1024
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 int fd;
45939
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
100 /* In PyArg_ParseTuple below, we use the unsigned non-checked 'I'
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
101 format for the 'code' parameter because Python turns 0x8000000
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
102 into either a large positive number (PyLong or PyInt on 64-bit
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
103 platforms) or a negative number on others (32-bit PyInt)
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
104 whereas the system expects it to be a 32bit bit field value
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
105 regardless of it being passed as an int or unsigned long on
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
106 various platforms. See the termios.TIOCSWINSZ constant across
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
107 platforms for an example of thise.
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
108
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
109 If any of the 64bit platforms ever decide to use more than 32bits
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
110 in their unsigned long ioctl codes this will break and need
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
111 special casing based on the platform being built on.
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
112 */
cbad1f5cabb1 Prevent ioctl op codes from being sign extended from int to unsigned long
Gregory P. Smith <greg@mad-scientist.com>
parents: 44497
diff changeset
113 unsigned int code;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 int arg;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 int ret;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 char *str;
36793
1e8cb47beaaa Make Py_ssize_t-clean
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
117 Py_ssize_t len;
34048
38432ad11c2a Hear the #error: change the default value of the mutable_arg argument
Michael W. Hudson <mwh@python.net>
parents: 32219
diff changeset
118 int mutate_arg = 1;
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
119 char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
120
35285
1774fe7ec0c7 This is barry-scott's patch:
Michael W. Hudson <mwh@python.net>
parents: 34048
diff changeset
121 if (PyArg_ParseTuple(args, "O&Iw#|i:ioctl",
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
122 conv_descriptor, &fd, &code,
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
123 &str, &len, &mutate_arg)) {
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
124 char *arg;
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
125
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
126 if (mutate_arg) {
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
127 if (len <= IOCTL_BUFSZ) {
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
128 memcpy(buf, str, len);
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
129 buf[len] = '\0';
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
130 arg = buf;
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
131 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
132 else {
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
133 arg = str;
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
134 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
135 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
136 else {
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
137 if (len > IOCTL_BUFSZ) {
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
138 PyErr_SetString(PyExc_ValueError,
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
139 "ioctl string arg too long");
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
140 return NULL;
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
141 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
142 else {
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
143 memcpy(buf, str, len);
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
144 buf[len] = '\0';
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
145 arg = buf;
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
146 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
147 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
148 if (buf == arg) {
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
149 Py_BEGIN_ALLOW_THREADS /* think array.resize() */
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
150 ret = ioctl(fd, code, arg);
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
151 Py_END_ALLOW_THREADS
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
152 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
153 else {
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
154 ret = ioctl(fd, code, arg);
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
155 }
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
156 if (mutate_arg && (len < IOCTL_BUFSZ)) {
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
157 memcpy(str, buf, len);
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
158 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
159 if (ret < 0) {
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
160 PyErr_SetFromErrno(PyExc_IOError);
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
161 return NULL;
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
162 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
163 if (mutate_arg) {
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
164 return PyInt_FromLong(ret);
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
165 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
166 else {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
167 return PyString_FromStringAndSize(buf, len);
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
168 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
169 }
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
170
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
171 PyErr_Clear();
35285
1774fe7ec0c7 This is barry-scott's patch:
Michael W. Hudson <mwh@python.net>
parents: 34048
diff changeset
172 if (PyArg_ParseTuple(args, "O&Is#:ioctl",
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
173 conv_descriptor, &fd, &code, &str, &len)) {
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
174 if (len > IOCTL_BUFSZ) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
175 PyErr_SetString(PyExc_ValueError,
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
176 "ioctl string arg too long");
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 memcpy(buf, str, len);
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
180 buf[len] = '\0';
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
181 Py_BEGIN_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
182 ret = ioctl(fd, code, buf);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
183 Py_END_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
184 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
185 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
188 return PyString_FromStringAndSize(buf, len);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
190
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
191 PyErr_Clear();
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
192 arg = 0;
17830
d890a21bebda fcntl.ioctl(): Update error message; necessity noted by Michael Hudson.
Fred Drake <fdrake@acm.org>
parents: 17765
diff changeset
193 if (!PyArg_ParseTuple(args,
35285
1774fe7ec0c7 This is barry-scott's patch:
Michael W. Hudson <mwh@python.net>
parents: 34048
diff changeset
194 "O&I|i;ioctl requires a file or file descriptor,"
35286
298d3fa4ec39 Fix a typo. (found by Jong-uk Kim)
Hye-Shik Chang <hyeshik@gmail.com>
parents: 35285
diff changeset
195 " an integer and optionally an integer or buffer argument",
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
196 conv_descriptor, &fd, &code, &arg)) {
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
197 return NULL;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
199 Py_BEGIN_ALLOW_THREADS
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28145
diff changeset
200 #ifdef __VMS
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28145
diff changeset
201 ret = ioctl(fd, code, (void *)arg);
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28145
diff changeset
202 #else
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 ret = ioctl(fd, code, arg);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28145
diff changeset
204 #endif
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
205 Py_END_ALLOW_THREADS
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
207 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
210 return PyInt_FromLong((long)ret);
37977
1843710f32e8 SF bug/patch #1433877: string parameter to ioctl not null terminated
Thomas Wouters <thomas@python.org>
parents: 36806
diff changeset
211 #undef IOCTL_BUFSZ
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
214 PyDoc_STRVAR(ioctl_doc,
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
215 "ioctl(fd, opt[, arg[, mutate_flag]])\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
216 \n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
217 Perform the requested operation on file descriptor fd. The operation is\n\
29693
d7164fbec7ce Fix typo, refer to proper argument name
Neal Norwitz <nnorwitz@gmail.com>
parents: 29045
diff changeset
218 defined by opt and is operating system dependent. Typically these codes are\n\
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
219 retrieved from the fcntl or termios library modules.\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
220 \n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
221 The argument arg is optional, and defaults to 0; it may be an int or a\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
222 buffer containing character data (most likely a string or an array). \n\
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
223 \n\
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
224 If the argument is a mutable buffer (such as an array) and if the\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
225 mutate_flag argument (which is only allowed in this case) is true then the\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
226 buffer is (in effect) passed to the operating system and changes made by\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
227 the OS will be reflected in the contents of the buffer after the call has\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
228 returned. The return value is the integer returned by the ioctl system\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
229 call.\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
230 \n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
231 If the argument is a mutable buffer and the mutable_flag argument is not\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
232 passed or is false, the behavior is as if a string had been passed. This\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
233 behavior will change in future releases of Python.\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
234 \n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
235 If the argument is an immutable buffer (most likely a string) then a copy\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
236 of the buffer is passed to the operating system and the return value is a\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
237 string of the same length containing whatever the operating system put in\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
238 the buffer. The length of the arg buffer in this case is not allowed to\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
239 exceed 1024 bytes.\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
240 \n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
241 If the arg given is an integer or if none is specified, the result value is\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
242 an integer corresponding to the return value of the ioctl call in the C\n\
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
243 code.");
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
244
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
245
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
246 /* flock(fd, operation) */
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
247
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
248 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
249 fcntl_flock(PyObject *self, PyObject *args)
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
250 {
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
251 int fd;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
252 int code;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
253 int ret;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
254
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
255 if (!PyArg_ParseTuple(args, "O&i:flock",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
256 conv_descriptor, &fd, &code))
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
257 return NULL;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
258
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
259 #ifdef HAVE_FLOCK
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
260 Py_BEGIN_ALLOW_THREADS
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
261 ret = flock(fd, code);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
262 Py_END_ALLOW_THREADS
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
263 #else
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
264
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
265 #ifndef LOCK_SH
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
266 #define LOCK_SH 1 /* shared lock */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
267 #define LOCK_EX 2 /* exclusive lock */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
268 #define LOCK_NB 4 /* don't block when locking */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
269 #define LOCK_UN 8 /* unlock */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
270 #endif
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
271 {
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
272 struct flock l;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
273 if (code == LOCK_UN)
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
274 l.l_type = F_UNLCK;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
275 else if (code & LOCK_SH)
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
276 l.l_type = F_RDLCK;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
277 else if (code & LOCK_EX)
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
278 l.l_type = F_WRLCK;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
279 else {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
280 PyErr_SetString(PyExc_ValueError,
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
281 "unrecognized flock argument");
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
282 return NULL;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
283 }
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
284 l.l_whence = l.l_start = l.l_len = 0;
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
285 Py_BEGIN_ALLOW_THREADS
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
286 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
287 Py_END_ALLOW_THREADS
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
288 }
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
289 #endif /* HAVE_FLOCK */
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
290 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
291 PyErr_SetFromErrno(PyExc_IOError);
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
292 return NULL;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
293 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
294 Py_INCREF(Py_None);
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
295 return Py_None;
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
296 }
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
297
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
298 PyDoc_STRVAR(flock_doc,
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
299 "flock(fd, operation)\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
300 \n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
301 Perform the lock operation op on file descriptor fd. See the Unix \n\
39271
6a8995c2e8bc Tweak wording
Andrew M. Kuchling <amk@amk.ca>
parents: 39068
diff changeset
302 manual page for flock(3) for details. (On some systems, this function is\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
303 emulated using fcntl().)");
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
304
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
305
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
306 /* lockf(fd, operation) */
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
307 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
308 fcntl_lockf(PyObject *self, PyObject *args)
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
309 {
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
310 int fd, code, ret, whence = 0;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
311 PyObject *lenobj = NULL, *startobj = NULL;
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
312
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
313 if (!PyArg_ParseTuple(args, "O&i|OOi:lockf",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
314 conv_descriptor, &fd, &code,
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
315 &lenobj, &startobj, &whence))
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
316 return NULL;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
317
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21712
diff changeset
318 #if defined(PYOS_OS2) && defined(PYCC_GCC)
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21712
diff changeset
319 PyErr_SetString(PyExc_NotImplementedError,
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21712
diff changeset
320 "lockf not supported on OS/2 (EMX)");
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21712
diff changeset
321 return NULL;
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21712
diff changeset
322 #else
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
323 #ifndef LOCK_SH
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
324 #define LOCK_SH 1 /* shared lock */
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
325 #define LOCK_EX 2 /* exclusive lock */
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
326 #define LOCK_NB 4 /* don't block when locking */
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
327 #define LOCK_UN 8 /* unlock */
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21712
diff changeset
328 #endif /* LOCK_SH */
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
329 {
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
330 struct flock l;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
331 if (code == LOCK_UN)
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
332 l.l_type = F_UNLCK;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
333 else if (code & LOCK_SH)
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
334 l.l_type = F_RDLCK;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
335 else if (code & LOCK_EX)
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
336 l.l_type = F_WRLCK;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
337 else {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
338 PyErr_SetString(PyExc_ValueError,
39068
b1bb179a8ab0 Fix function name in error msg
Neal Norwitz <nnorwitz@gmail.com>
parents: 37977
diff changeset
339 "unrecognized lockf argument");
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
340 return NULL;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
341 }
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
342 l.l_start = l.l_len = 0;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
343 if (startobj != NULL) {
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
344 #if !defined(HAVE_LARGEFILE_SUPPORT)
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
345 l.l_start = PyInt_AsLong(startobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
346 #else
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
347 l.l_start = PyLong_Check(startobj) ?
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
348 PyLong_AsLongLong(startobj) :
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
349 PyInt_AsLong(startobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
350 #endif
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
351 if (PyErr_Occurred())
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
352 return NULL;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
353 }
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
354 if (lenobj != NULL) {
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
355 #if !defined(HAVE_LARGEFILE_SUPPORT)
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
356 l.l_len = PyInt_AsLong(lenobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
357 #else
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
358 l.l_len = PyLong_Check(lenobj) ?
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
359 PyLong_AsLongLong(lenobj) :
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
360 PyInt_AsLong(lenobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
361 #endif
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
362 if (PyErr_Occurred())
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
363 return NULL;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
364 }
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
365 l.l_whence = whence;
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
366 Py_BEGIN_ALLOW_THREADS
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
367 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
368 Py_END_ALLOW_THREADS
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
369 }
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
370 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
371 PyErr_SetFromErrno(PyExc_IOError);
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
372 return NULL;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
373 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
374 Py_INCREF(Py_None);
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
375 return Py_None;
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21712
diff changeset
376 #endif /* defined(PYOS_OS2) && defined(PYCC_GCC) */
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
377 }
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
378
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
379 PyDoc_STRVAR(lockf_doc,
16245
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
380 "lockf (fd, operation, length=0, start=0, whence=0)\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
381 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
382 This is essentially a wrapper around the fcntl() locking calls. fd is the\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
383 file descriptor of the file to lock or unlock, and operation is one of the\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
384 following values:\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
385 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
386 LOCK_UN - unlock\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
387 LOCK_SH - acquire a shared lock\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
388 LOCK_EX - acquire an exclusive lock\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
389 \n\
44497
01d5b8e7d121 Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
Georg Brandl <georg@python.org>
parents: 39271
diff changeset
390 When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with\n\
16245
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
391 LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
392 lock cannot be acquired, an IOError will be raised and the exception will\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
393 have an errno attribute set to EACCES or EAGAIN (depending on the operating\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
394 system -- for portability, check for either value).\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
395 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
396 length is the number of bytes to lock, with the default meaning to lock to\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
397 EOF. start is the byte offset, relative to whence, to that the lock\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
398 starts. whence is as with fileobj.seek(), specifically:\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
399 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
400 0 - relative to the start of the file (SEEK_SET)\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
401 1 - relative to the current buffer position (SEEK_CUR)\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
402 2 - relative to the end of the file (SEEK_END)");
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
403
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 /* List of functions */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
406 static PyMethodDef fcntl_methods[] = {
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
407 {"fcntl", fcntl_fcntl, METH_VARARGS, fcntl_doc},
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
408 {"ioctl", fcntl_ioctl, METH_VARARGS, ioctl_doc},
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
409 {"flock", fcntl_flock, METH_VARARGS, flock_doc},
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
410 {"lockf", fcntl_lockf, METH_VARARGS, lockf_doc},
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 {NULL, NULL} /* sentinel */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 };
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
413
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
414
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
415 PyDoc_STRVAR(module_doc,
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
416 "This module performs file control and I/O control on file \n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
417 descriptors. It is an interface to the fcntl() and ioctl() Unix\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
418 routines. File descriptors can be obtained with the fileno() method of\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22114
diff changeset
419 a file or socket object.");
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
420
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 /* Module initialisation */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
422
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
423 static int
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
424 ins(PyObject* d, char* symbol, long value)
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
425 {
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
426 PyObject* v = PyInt_FromLong(value);
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
427 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
428 return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
429
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
430 Py_DECREF(v);
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
431 return 0;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
432 }
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
433
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
434 #define INS(x) if (ins(d, #x, (long)x)) return -1
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
435
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
436 static int
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
437 all_ins(PyObject* d)
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
438 {
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
439 if (ins(d, "LOCK_SH", (long)LOCK_SH)) return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
440 if (ins(d, "LOCK_EX", (long)LOCK_EX)) return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
441 if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
442 if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1;
21585
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
443 /* GNU extensions, as of glibc 2.2.4 */
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
444 #ifdef LOCK_MAND
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
445 if (ins(d, "LOCK_MAND", (long)LOCK_MAND)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
446 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
447 #ifdef LOCK_READ
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
448 if (ins(d, "LOCK_READ", (long)LOCK_READ)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
449 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
450 #ifdef LOCK_WRITE
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
451 if (ins(d, "LOCK_WRITE", (long)LOCK_WRITE)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
452 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
453 #ifdef LOCK_RW
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
454 if (ins(d, "LOCK_RW", (long)LOCK_RW)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
455 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
456
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
457 #ifdef F_DUPFD
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
458 if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
459 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
460 #ifdef F_GETFD
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
461 if (ins(d, "F_GETFD", (long)F_GETFD)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
462 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
463 #ifdef F_SETFD
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
464 if (ins(d, "F_SETFD", (long)F_SETFD)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
465 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
466 #ifdef F_GETFL
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
467 if (ins(d, "F_GETFL", (long)F_GETFL)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
468 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
469 #ifdef F_SETFL
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
470 if (ins(d, "F_SETFL", (long)F_SETFL)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
471 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
472 #ifdef F_GETLK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
473 if (ins(d, "F_GETLK", (long)F_GETLK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
474 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
475 #ifdef F_SETLK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
476 if (ins(d, "F_SETLK", (long)F_SETLK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
477 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
478 #ifdef F_SETLKW
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
479 if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
480 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
481 #ifdef F_GETOWN
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
482 if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
483 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
484 #ifdef F_SETOWN
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
485 if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
486 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
487 #ifdef F_GETSIG
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
488 if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
489 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
490 #ifdef F_SETSIG
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
491 if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
492 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
493 #ifdef F_RDLCK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
494 if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
495 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
496 #ifdef F_WRLCK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
497 if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
498 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
499 #ifdef F_UNLCK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
500 if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
501 #endif
21585
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
502 /* LFS constants */
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
503 #ifdef F_GETLK64
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
504 if (ins(d, "F_GETLK64", (long)F_GETLK64)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
505 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
506 #ifdef F_SETLK64
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
507 if (ins(d, "F_SETLK64", (long)F_SETLK64)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
508 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
509 #ifdef F_SETLKW64
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
510 if (ins(d, "F_SETLKW64", (long)F_SETLKW64)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
511 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
512 /* GNU extensions, as of glibc 2.2.4. */
47094
aa8e13279b5b #2890: support os.O_ASYNC and fcntl.FASYNC.
Georg Brandl <georg@python.org>
parents: 45939
diff changeset
513 #ifdef FASYNC
aa8e13279b5b #2890: support os.O_ASYNC and fcntl.FASYNC.
Georg Brandl <georg@python.org>
parents: 45939
diff changeset
514 if (ins(d, "FASYNC", (long)FASYNC)) return -1;
aa8e13279b5b #2890: support os.O_ASYNC and fcntl.FASYNC.
Georg Brandl <georg@python.org>
parents: 45939
diff changeset
515 #endif
21585
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
516 #ifdef F_SETLEASE
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
517 if (ins(d, "F_SETLEASE", (long)F_SETLEASE)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
518 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
519 #ifdef F_GETLEASE
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
520 if (ins(d, "F_GETLEASE", (long)F_GETLEASE)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
521 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
522 #ifdef F_NOTIFY
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
523 if (ins(d, "F_NOTIFY", (long)F_NOTIFY)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
524 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
525 /* Old BSD flock(). */
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
526 #ifdef F_EXLCK
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
527 if (ins(d, "F_EXLCK", (long)F_EXLCK)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
528 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
529 #ifdef F_SHLCK
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
530 if (ins(d, "F_SHLCK", (long)F_SHLCK)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
531 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
532
48192
c8c9e78fc082 Patch by Ian Charnas from issue 3517.
Guido van Rossum <guido@python.org>
parents: 47527
diff changeset
533 /* OS X (and maybe others) let you tell the storage device to flush to physical media */
c8c9e78fc082 Patch by Ian Charnas from issue 3517.
Guido van Rossum <guido@python.org>
parents: 47527
diff changeset
534 #ifdef F_FULLFSYNC
c8c9e78fc082 Patch by Ian Charnas from issue 3517.
Guido van Rossum <guido@python.org>
parents: 47527
diff changeset
535 if (ins(d, "F_FULLFSYNC", (long)F_FULLFSYNC)) return -1;
c8c9e78fc082 Patch by Ian Charnas from issue 3517.
Guido van Rossum <guido@python.org>
parents: 47527
diff changeset
536 #endif
c8c9e78fc082 Patch by Ian Charnas from issue 3517.
Guido van Rossum <guido@python.org>
parents: 47527
diff changeset
537
21585
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
538 /* For F_{GET|SET}FL */
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
539 #ifdef FD_CLOEXEC
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
540 if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
541 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
542
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
543 /* For F_NOTIFY */
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
544 #ifdef DN_ACCESS
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
545 if (ins(d, "DN_ACCESS", (long)DN_ACCESS)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
546 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
547 #ifdef DN_MODIFY
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
548 if (ins(d, "DN_MODIFY", (long)DN_MODIFY)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
549 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
550 #ifdef DN_CREATE
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
551 if (ins(d, "DN_CREATE", (long)DN_CREATE)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
552 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
553 #ifdef DN_DELETE
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
554 if (ins(d, "DN_DELETE", (long)DN_DELETE)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
555 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
556 #ifdef DN_RENAME
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
557 if (ins(d, "DN_RENAME", (long)DN_RENAME)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
558 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
559 #ifdef DN_ATTRIB
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
560 if (ins(d, "DN_ATTRIB", (long)DN_ATTRIB)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
561 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
562 #ifdef DN_MULTISHOT
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
563 if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1;
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
564 #endif
fdc39e27a494 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
565
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
566 #ifdef HAVE_STROPTS_H
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
567 /* Unix 98 guarantees that these are in stropts.h. */
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
568 INS(I_PUSH);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
569 INS(I_POP);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
570 INS(I_LOOK);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
571 INS(I_FLUSH);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
572 INS(I_FLUSHBAND);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
573 INS(I_SETSIG);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
574 INS(I_GETSIG);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
575 INS(I_FIND);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
576 INS(I_PEEK);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
577 INS(I_SRDOPT);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
578 INS(I_GRDOPT);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
579 INS(I_NREAD);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
580 INS(I_FDINSERT);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
581 INS(I_STR);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
582 INS(I_SWROPT);
29045
de564a8733d2 Simple fix for
Michael W. Hudson <mwh@python.net>
parents: 28949
diff changeset
583 #ifdef I_GWROPT
de564a8733d2 Simple fix for
Michael W. Hudson <mwh@python.net>
parents: 28949
diff changeset
584 /* despite the comment above, old-ish glibcs miss a couple... */
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
585 INS(I_GWROPT);
29045
de564a8733d2 Simple fix for
Michael W. Hudson <mwh@python.net>
parents: 28949
diff changeset
586 #endif
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
587 INS(I_SENDFD);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
588 INS(I_RECVFD);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
589 INS(I_LIST);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
590 INS(I_ATMARK);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
591 INS(I_CKBAND);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
592 INS(I_GETBAND);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
593 INS(I_CANPUT);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
594 INS(I_SETCLTIME);
29045
de564a8733d2 Simple fix for
Michael W. Hudson <mwh@python.net>
parents: 28949
diff changeset
595 #ifdef I_GETCLTIME
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
596 INS(I_GETCLTIME);
29045
de564a8733d2 Simple fix for
Michael W. Hudson <mwh@python.net>
parents: 28949
diff changeset
597 #endif
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
598 INS(I_LINK);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
599 INS(I_UNLINK);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
600 INS(I_PLINK);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
601 INS(I_PUNLINK);
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
602 #endif
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
603
6055
72d004971b26 Keep gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5912
diff changeset
604 return 0;
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
605 }
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
606
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
607 PyMODINIT_FUNC
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13519
diff changeset
608 initfcntl(void)
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
610 PyObject *m, *d;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
611
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
612 /* Create the module and add the functions and documentation */
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
613 m = Py_InitModule3("fcntl", fcntl_methods, module_doc);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35286
diff changeset
614 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35286
diff changeset
615 return;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
616
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 /* Add some symbolic constants to the module */
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
618 d = PyModule_GetDict(m);
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
619 all_ins(d);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 }