annotate Modules/fcntlmodule.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents b36cb4602e21
children 43064ded64cb
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)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
24 return 0;
17743
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
35 int fd;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
36 int code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
37 long arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
38 int ret;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
39 char *str;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
40 Py_ssize_t len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
41 char buf[1024];
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
43 if (PyArg_ParseTuple(args, "O&is#:fcntl",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
44 conv_descriptor, &fd, &code, &str, &len)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
45 if (len > sizeof buf) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
46 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
47 "fcntl string arg too long");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
48 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
49 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
50 memcpy(buf, str, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
51 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
52 ret = fcntl(fd, code, buf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
53 Py_END_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
54 if (ret < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
55 PyErr_SetFromErrno(PyExc_IOError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
56 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
57 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
58 return PyString_FromStringAndSize(buf, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
59 }
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
61 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
62 arg = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
63 if (!PyArg_ParseTuple(args,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
64 "O&i|l;fcntl requires a file or file descriptor,"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
65 " an integer and optionally a third integer or a string",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
66 conv_descriptor, &fd, &code, &arg)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
67 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
68 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
69 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
70 ret = fcntl(fd, code, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
71 Py_END_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
72 if (ret < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
73 PyErr_SetFromErrno(PyExc_IOError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
74 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
75 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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\
65127
ff734f225b47 Merged revisions 82798,82805,83659,83977,84015,84018,84141,84264,84326-84327,84480,84482,84484,84530-84531,84553,84619,84915-84916 via svnmerge from
Georg Brandl <georg@python.org>
parents: 64527
diff changeset
85 defaults to 0; it may be an int or a string. If arg is given as a string,\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
86 the return value of fcntl is a string of that length, containing the\n\
65127
ff734f225b47 Merged revisions 82798,82805,83659,83977,84015,84018,84141,84264,84326-84327,84480,84482,84484,84530-84531,84553,84619,84915-84916 via svnmerge from
Georg Brandl <georg@python.org>
parents: 64527
diff changeset
87 resulting value put in the arg buffer by the operating system. The length\n\
ff734f225b47 Merged revisions 82798,82805,83659,83977,84015,84018,84141,84264,84326-84327,84480,84482,84484,84530-84531,84553,84619,84915-84916 via svnmerge from
Georg Brandl <georg@python.org>
parents: 64527
diff changeset
88 of the arg string is not allowed to exceed 1024 bytes. If the arg given\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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
99 int fd;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
100 /* In PyArg_ParseTuple below, we use the unsigned non-checked 'I'
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
101 format for the 'code' parameter because Python turns 0x8000000
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
102 into either a large positive number (PyLong or PyInt on 64-bit
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
103 platforms) or a negative number on others (32-bit PyInt)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
104 whereas the system expects it to be a 32bit bit field value
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
105 regardless of it being passed as an int or unsigned long on
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
106 various platforms. See the termios.TIOCSWINSZ constant across
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
107 platforms for an example of thise.
48159
1c24a09acb97 (backport of r61652 and r61665 from trunk)
Gregory P. Smith <greg@mad-scientist.com>
parents: 39271
diff changeset
108
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
109 If any of the 64bit platforms ever decide to use more than 32bits
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
110 in their unsigned long ioctl codes this will break and need
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
111 special casing based on the platform being built on.
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
112 */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
113 unsigned int code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
114 int arg;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
115 int ret;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
116 char *str;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
117 Py_ssize_t len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
118 int mutate_arg = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
121 if (PyArg_ParseTuple(args, "O&Iw#|i:ioctl",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
122 conv_descriptor, &fd, &code,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
123 &str, &len, &mutate_arg)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
124 char *arg;
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
125
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
126 if (mutate_arg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
127 if (len <= IOCTL_BUFSZ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
128 memcpy(buf, str, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
129 buf[len] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
130 arg = buf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
131 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
132 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
133 arg = str;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
134 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
135 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
136 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
137 if (len > IOCTL_BUFSZ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
138 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
139 "ioctl string arg too long");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
140 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
141 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
142 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
143 memcpy(buf, str, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
144 buf[len] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
145 arg = buf;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
146 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
147 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
148 if (buf == arg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
149 Py_BEGIN_ALLOW_THREADS /* think array.resize() */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
150 ret = ioctl(fd, code, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
151 Py_END_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
152 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
153 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
154 ret = ioctl(fd, code, arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
155 }
64527
7432e508eb66 Merged revisions 84589 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61463
diff changeset
156 if (mutate_arg && (len <= IOCTL_BUFSZ)) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
157 memcpy(str, buf, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
158 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
159 if (ret < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
160 PyErr_SetFromErrno(PyExc_IOError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
161 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
162 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
163 if (mutate_arg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
164 return PyInt_FromLong(ret);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
165 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
166 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
167 return PyString_FromStringAndSize(buf, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
168 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
169 }
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents: 26998
diff changeset
170
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
171 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
172 if (PyArg_ParseTuple(args, "O&Is#:ioctl",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
173 conv_descriptor, &fd, &code, &str, &len)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
174 if (len > IOCTL_BUFSZ) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
175 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
176 "ioctl string arg too long");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
177 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
178 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
179 memcpy(buf, str, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
180 buf[len] = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
181 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
182 ret = ioctl(fd, code, buf);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
183 Py_END_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
184 if (ret < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
185 PyErr_SetFromErrno(PyExc_IOError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
186 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
187 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
188 return PyString_FromStringAndSize(buf, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
189 }
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
190
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
191 PyErr_Clear();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
192 arg = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
193 if (!PyArg_ParseTuple(args,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
194 "O&I|i;ioctl requires a file or file descriptor,"
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
195 " an integer and optionally an integer or buffer argument",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
196 conv_descriptor, &fd, &code, &arg)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
197 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
198 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
201 ret = ioctl(fd, code, (void *)arg);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28145
diff changeset
202 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
205 Py_END_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
206 if (ret < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
207 PyErr_SetFromErrno(PyExc_IOError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
208 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
209 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
251 int fd;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
252 int code;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
253 int ret;
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
254
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
255 if (!PyArg_ParseTuple(args, "O&i:flock",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
256 conv_descriptor, &fd, &code))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
257 return NULL;
3598
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
260 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
261 ret = flock(fd, code);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
266 #define LOCK_SH 1 /* shared lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
267 #define LOCK_EX 2 /* exclusive lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
268 #define LOCK_NB 4 /* don't block when locking */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
269 #define LOCK_UN 8 /* unlock */
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
270 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
271 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
272 struct flock l;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
273 if (code == LOCK_UN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
274 l.l_type = F_UNLCK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
275 else if (code & LOCK_SH)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
276 l.l_type = F_RDLCK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
277 else if (code & LOCK_EX)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
278 l.l_type = F_WRLCK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
279 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
280 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
281 "unrecognized flock argument");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
282 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
283 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
284 l.l_whence = l.l_start = l.l_len = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
285 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
286 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
287 Py_END_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
288 }
3662
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 */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
290 if (ret < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
291 PyErr_SetFromErrno(PyExc_IOError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
292 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
293 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
294 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
310 int fd, code, ret, whence = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
311 PyObject *lenobj = NULL, *startobj = NULL;
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
312
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
313 if (!PyArg_ParseTuple(args, "O&i|OOi:lockf",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
314 conv_descriptor, &fd, &code,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
315 &lenobj, &startobj, &whence))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
316 return NULL;
4293
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)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
319 PyErr_SetString(PyExc_NotImplementedError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
320 "lockf not supported on OS/2 (EMX)");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
321 return NULL;
22114
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
324 #define LOCK_SH 1 /* shared lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
325 #define LOCK_EX 2 /* exclusive lock */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
326 #define LOCK_NB 4 /* don't block when locking */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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 */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
329 {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
330 struct flock l;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
331 if (code == LOCK_UN)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
332 l.l_type = F_UNLCK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
333 else if (code & LOCK_SH)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
334 l.l_type = F_RDLCK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
335 else if (code & LOCK_EX)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
336 l.l_type = F_WRLCK;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
337 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
338 PyErr_SetString(PyExc_ValueError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
339 "unrecognized lockf argument");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
340 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
341 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
342 l.l_start = l.l_len = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
343 if (startobj != NULL) {
9786
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)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
345 l.l_start = PyInt_AsLong(startobj);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
346 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
347 l.l_start = PyLong_Check(startobj) ?
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
348 PyLong_AsLongLong(startobj) :
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
349 PyInt_AsLong(startobj);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
350 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
351 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
352 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
353 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
354 if (lenobj != NULL) {
9786
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)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
356 l.l_len = PyInt_AsLong(lenobj);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
357 #else
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
358 l.l_len = PyLong_Check(lenobj) ?
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
359 PyLong_AsLongLong(lenobj) :
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
360 PyInt_AsLong(lenobj);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
361 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
362 if (PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
363 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
364 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
365 l.l_whence = whence;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
366 Py_BEGIN_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
367 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
368 Py_END_ALLOW_THREADS
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
369 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
370 if (ret < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
371 PyErr_SetFromErrno(PyExc_IOError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
372 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
373 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
374 Py_INCREF(Py_None);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
407 {"fcntl", fcntl_fcntl, METH_VARARGS, fcntl_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
408 {"ioctl", fcntl_ioctl, METH_VARARGS, ioctl_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
409 {"flock", fcntl_flock, METH_VARARGS, flock_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
410 {"lockf", fcntl_lockf, METH_VARARGS, lockf_doc},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
411 {NULL, NULL} /* sentinel */
960
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
426 PyObject* v = PyInt_FromLong(value);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
427 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
428 return -1;
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
429
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
430 Py_DECREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
431 return 0;
5912
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
439 if (ins(d, "LOCK_SH", (long)LOCK_SH)) return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
440 if (ins(d, "LOCK_EX", (long)LOCK_EX)) return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
441 if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
445 if (ins(d, "LOCK_MAND", (long)LOCK_MAND)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
448 if (ins(d, "LOCK_READ", (long)LOCK_READ)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
451 if (ins(d, "LOCK_WRITE", (long)LOCK_WRITE)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
454 if (ins(d, "LOCK_RW", (long)LOCK_RW)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
458 if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
461 if (ins(d, "F_GETFD", (long)F_GETFD)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
464 if (ins(d, "F_SETFD", (long)F_SETFD)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
467 if (ins(d, "F_GETFL", (long)F_GETFL)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
470 if (ins(d, "F_SETFL", (long)F_SETFL)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
473 if (ins(d, "F_GETLK", (long)F_GETLK)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
476 if (ins(d, "F_SETLK", (long)F_SETLK)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
479 if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
482 if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
485 if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
488 if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
491 if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
494 if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
497 if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
500 if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1;
17743
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
504 if (ins(d, "F_GETLK64", (long)F_GETLK64)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
507 if (ins(d, "F_SETLK64", (long)F_SETLK64)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
510 if (ins(d, "F_SETLKW64", (long)F_SETLKW64)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
514 if (ins(d, "FASYNC", (long)FASYNC)) return -1;
47094
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
517 if (ins(d, "F_SETLEASE", (long)F_SETLEASE)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
520 if (ins(d, "F_GETLEASE", (long)F_GETLEASE)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
523 if (ins(d, "F_NOTIFY", (long)F_NOTIFY)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
527 if (ins(d, "F_EXLCK", (long)F_EXLCK)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
530 if (ins(d, "F_SHLCK", (long)F_SHLCK)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
535 if (ins(d, "F_FULLFSYNC", (long)F_FULLFSYNC)) 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
536 #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
537
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
540 if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
545 if (ins(d, "DN_ACCESS", (long)DN_ACCESS)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
548 if (ins(d, "DN_MODIFY", (long)DN_MODIFY)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
551 if (ins(d, "DN_CREATE", (long)DN_CREATE)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
554 if (ins(d, "DN_DELETE", (long)DN_DELETE)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
557 if (ins(d, "DN_RENAME", (long)DN_RENAME)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
560 if (ins(d, "DN_ATTRIB", (long)DN_ATTRIB)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
563 if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) 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
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
567 /* Unix 98 guarantees that these are in stropts.h. */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
568 INS(I_PUSH);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
569 INS(I_POP);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
570 INS(I_LOOK);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
571 INS(I_FLUSH);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
572 INS(I_FLUSHBAND);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
573 INS(I_SETSIG);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
574 INS(I_GETSIG);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
575 INS(I_FIND);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
576 INS(I_PEEK);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
577 INS(I_SRDOPT);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
578 INS(I_GRDOPT);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
579 INS(I_NREAD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
580 INS(I_FDINSERT);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
581 INS(I_STR);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
584 /* despite the comment above, old-ish glibcs miss a couple... */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
585 INS(I_GWROPT);
29045
de564a8733d2 Simple fix for
Michael W. Hudson <mwh@python.net>
parents: 28949
diff changeset
586 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
587 INS(I_SENDFD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
588 INS(I_RECVFD);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
589 INS(I_LIST);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
590 INS(I_ATMARK);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
591 INS(I_CKBAND);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
592 INS(I_GETBAND);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
593 INS(I_CANPUT);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
596 INS(I_GETCLTIME);
29045
de564a8733d2 Simple fix for
Michael W. Hudson <mwh@python.net>
parents: 28949
diff changeset
597 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
598 INS(I_LINK);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
599 INS(I_UNLINK);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
600 INS(I_PLINK);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
601 INS(I_PUNLINK);
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
602 #endif
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
603
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
612 /* Create the module and add the functions and documentation */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
613 m = Py_InitModule3("fcntl", fcntl_methods, module_doc);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
614 if (m == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
615 return;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
616
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
617 /* Add some symbolic constants to the module */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
diff changeset
618 d = PyModule_GetDict(m);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 54306
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 }