annotate Modules/fcntlmodule.c @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents e223397b26fa
children c454b76d51e7
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
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
4 #include "Python.h"
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
6 #ifdef HAVE_SYS_FILE_H
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
7 #include <sys/file.h>
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
8 #endif
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
9
4623
1fab981465c8 Include <sys/ioctl.h>, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
10 #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
11 #include <fcntl.h>
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
12
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
14 static int
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
15 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
16 {
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
17 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
18
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
19 if (fd < 0)
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
20 return 0;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
21 *target = fd;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
22 return 1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
23 }
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
24
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
25
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 /* fcntl(fd, opt, [arg]) */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
28 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
29 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
30 {
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 int fd;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 int code;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 int arg;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 int ret;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 char *str;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 int len;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 char buf[1024];
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
39 if (PyArg_ParseTuple(args, "O&is#:fcntl",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
40 conv_descriptor, &fd, &code, &str, &len)) {
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 if (len > sizeof buf) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
42 PyErr_SetString(PyExc_ValueError,
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
43 "fcntl string arg too long");
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 memcpy(buf, str, len);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
47 Py_BEGIN_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
48 ret = fcntl(fd, code, buf);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
49 Py_END_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
50 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
51 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
54 return PyString_FromStringAndSize(buf, len);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
57 PyErr_Clear();
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
58 arg = 0;
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
59 if (!PyArg_ParseTuple(args,
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
60 "O&i|i;fcntl requires a file or file descriptor,"
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
61 " an integer and optionally a third integer or a string",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
62 conv_descriptor, &fd, &code, &arg)) {
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
63 return NULL;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
65 Py_BEGIN_ALLOW_THREADS
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 ret = fcntl(fd, code, arg);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
67 Py_END_ALLOW_THREADS
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
69 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
72 return PyInt_FromLong((long)ret);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
75 static char fcntl_doc [] =
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
76
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
77 "fcntl(fd, opt, [arg])\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
78 \n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
79 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
80 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
81 available from the fcntl module. The argument arg is optional, and\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
82 defaults to 0; it may be an int or a string. If arg is given as a string,\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
83 the return value of fcntl is a string of that length, containing the\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
84 resulting value put in the arg buffer by the operating system.The length\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
85 of the arg string is not allowed to exceed 1024 bytes. If the arg given\n\
2f0df9f0b088 Fix the fcntl() docstring so the user is not mis-directed to the FCNTL
Fred Drake <fdrake@acm.org>
parents: 17743
diff changeset
86 is an integer or if none is specified, the result value is an integer\n\
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
87 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
88
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 /* ioctl(fd, opt, [arg]) */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
92 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
93 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
94 {
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 int fd;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 int code;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 int arg;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 int ret;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 char *str;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 int len;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 char buf[1024];
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
103 if (PyArg_ParseTuple(args, "O&is#:ioctl",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
104 conv_descriptor, &fd, &code, &str, &len)) {
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 if (len > sizeof buf) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
106 PyErr_SetString(PyExc_ValueError,
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
107 "ioctl string arg too long");
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 memcpy(buf, str, len);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
111 Py_BEGIN_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
112 ret = ioctl(fd, code, buf);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
113 Py_END_ALLOW_THREADS
3153
9a896086d3c3 add BGN/END_SAVE macros around fcntl/ioctl calls
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
114 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
115 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
118 return PyString_FromStringAndSize(buf, len);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
120
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
121 PyErr_Clear();
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
122 arg = 0;
17830
d890a21bebda fcntl.ioctl(): Update error message; necessity noted by Michael Hudson.
Fred Drake <fdrake@acm.org>
parents: 17765
diff changeset
123 if (!PyArg_ParseTuple(args,
d890a21bebda fcntl.ioctl(): Update error message; necessity noted by Michael Hudson.
Fred Drake <fdrake@acm.org>
parents: 17765
diff changeset
124 "O&i|i;ioctl requires a file or file descriptor,"
d890a21bebda fcntl.ioctl(): Update error message; necessity noted by Michael Hudson.
Fred Drake <fdrake@acm.org>
parents: 17765
diff changeset
125 " an integer and optionally a third integer or a string",
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
126 conv_descriptor, &fd, &code, &arg)) {
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
127 return NULL;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
129 Py_BEGIN_ALLOW_THREADS
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 ret = ioctl(fd, code, arg);
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
131 Py_END_ALLOW_THREADS
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
133 PyErr_SetFromErrno(PyExc_IOError);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 return NULL;
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
136 return PyInt_FromLong((long)ret);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 }
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
139 static char ioctl_doc [] =
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
140 "ioctl(fd, opt, [arg])\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
141 \n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
142 Perform the requested operation on file descriptor fd. The operation\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
143 is defined by op and is operating system dependent. Typically these\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
144 codes can be retrieved from the library module IOCTL. The argument arg\n\
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
145 is optional, and defaults to 0; it may be an int or a string. If arg is\n\
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
146 given as a string, the return value of ioctl is a string of that length,\n\
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
147 containing the resulting value put in the arg buffer by the operating system.\n\
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
148 The length of the arg string is not allowed to exceed 1024 bytes. If the arg\n\
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
149 given is an integer or if none is specified, the result value is an integer\n\
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
150 corresponding to the return value of the ioctl call in the C code.";
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
151
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
153 /* flock(fd, operation) */
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
154
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
155 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
156 fcntl_flock(PyObject *self, PyObject *args)
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
157 {
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
158 int fd;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
159 int code;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
160 int ret;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
161
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
162 if (!PyArg_ParseTuple(args, "O&i:flock",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
163 conv_descriptor, &fd, &code))
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
164 return NULL;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
165
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
166 #ifdef HAVE_FLOCK
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
167 Py_BEGIN_ALLOW_THREADS
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
168 ret = flock(fd, code);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
169 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
170 #else
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
171
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
172 #ifndef LOCK_SH
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
173 #define LOCK_SH 1 /* shared lock */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
174 #define LOCK_EX 2 /* exclusive lock */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
175 #define LOCK_NB 4 /* don't block when locking */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
176 #define LOCK_UN 8 /* unlock */
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
177 #endif
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
178 {
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
179 struct flock l;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
180 if (code == LOCK_UN)
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
181 l.l_type = F_UNLCK;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
182 else if (code & LOCK_SH)
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
183 l.l_type = F_RDLCK;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
184 else if (code & LOCK_EX)
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
185 l.l_type = F_WRLCK;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
186 else {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
187 PyErr_SetString(PyExc_ValueError,
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
188 "unrecognized flock argument");
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
189 return NULL;
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
190 }
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
191 l.l_whence = l.l_start = l.l_len = 0;
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
192 Py_BEGIN_ALLOW_THREADS
3662
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
193 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
194 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
195 }
399470a958c2 A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents: 3598
diff changeset
196 #endif /* HAVE_FLOCK */
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
197 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
198 PyErr_SetFromErrno(PyExc_IOError);
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
199 return NULL;
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
200 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
201 Py_INCREF(Py_None);
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
202 return Py_None;
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
203 }
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
204
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
205 static char flock_doc [] =
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
206 "flock(fd, operation)\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
207 \n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
208 Perform the lock operation op on file descriptor fd. See the Unix \n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
209 manual flock(3) for details. (On some systems, this function is\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
210 emulated using fcntl().)";
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
211
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
212
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
213 /* lockf(fd, operation) */
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
214 static PyObject *
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
215 fcntl_lockf(PyObject *self, PyObject *args)
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
216 {
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
217 int fd, code, ret, whence = 0;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
218 PyObject *lenobj = NULL, *startobj = NULL;
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
219
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
220 if (!PyArg_ParseTuple(args, "O&i|OOi:lockf",
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
221 conv_descriptor, &fd, &code,
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
222 &lenobj, &startobj, &whence))
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
223 return NULL;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
224
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
225 #ifndef LOCK_SH
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
226 #define LOCK_SH 1 /* shared lock */
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
227 #define LOCK_EX 2 /* exclusive lock */
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
228 #define LOCK_NB 4 /* don't block when locking */
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
229 #define LOCK_UN 8 /* unlock */
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
230 #endif
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
231 {
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
232 struct flock l;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
233 if (code == LOCK_UN)
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
234 l.l_type = F_UNLCK;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
235 else if (code & LOCK_SH)
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
236 l.l_type = F_RDLCK;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
237 else if (code & LOCK_EX)
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
238 l.l_type = F_WRLCK;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
239 else {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
240 PyErr_SetString(PyExc_ValueError,
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
241 "unrecognized flock argument");
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
242 return NULL;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
243 }
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
244 l.l_start = l.l_len = 0;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
245 if (startobj != NULL) {
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
246 #if !defined(HAVE_LARGEFILE_SUPPORT)
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
247 l.l_start = PyInt_AsLong(startobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
248 #else
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
249 l.l_start = PyLong_Check(startobj) ?
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
250 PyLong_AsLongLong(startobj) :
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
251 PyInt_AsLong(startobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
252 #endif
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
253 if (PyErr_Occurred())
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
254 return NULL;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
255 }
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
256 if (lenobj != NULL) {
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
257 #if !defined(HAVE_LARGEFILE_SUPPORT)
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
258 l.l_len = PyInt_AsLong(lenobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
259 #else
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
260 l.l_len = PyLong_Check(lenobj) ?
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
261 PyLong_AsLongLong(lenobj) :
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
262 PyInt_AsLong(lenobj);
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
263 #endif
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
264 if (PyErr_Occurred())
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
265 return NULL;
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
266 }
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
267 l.l_whence = whence;
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
268 Py_BEGIN_ALLOW_THREADS
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
269 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
9786
40f723ac26e8 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
270 Py_END_ALLOW_THREADS
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
271 }
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
272 if (ret < 0) {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
273 PyErr_SetFromErrno(PyExc_IOError);
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
274 return NULL;
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
275 }
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
276 Py_INCREF(Py_None);
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
277 return Py_None;
4293
69bbc21f55cf Added lockf() call
Guido van Rossum <guido@python.org>
parents: 3662
diff changeset
278 }
3598
6c9260ae0d16 Added flock().
Guido van Rossum <guido@python.org>
parents: 3153
diff changeset
279
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
280 static char lockf_doc [] =
16245
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
281 "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
282 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
283 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
284 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
285 following values:\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
286 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
287 LOCK_UN - unlock\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
288 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
289 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
290 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
291 When operation is LOCK_SH or LOCK_EX, it can also be bit-wise OR'd with\n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
292 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
293 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
294 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
295 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
296 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
297 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
298 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
299 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
300 \n\
09736aeab831 Let's keep things portable to non GCC compilers, please.
Sjoerd Mullender <sjoerd@acm.org>
parents: 16238
diff changeset
301 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
302 1 - relative to the current buffer position (SEEK_CUR)\n\
16238
b4d4f2021114 lockf_doc: a much better description of the lockf() function, based on
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
303 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
304
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 /* List of functions */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
306
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
307 static PyMethodDef fcntl_methods[] = {
13814
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
308 {"fcntl", fcntl_fcntl, METH_VARARGS, fcntl_doc},
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
309 {"ioctl", fcntl_ioctl, METH_VARARGS, ioctl_doc},
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
310 {"flock", fcntl_flock, METH_VARARGS, flock_doc},
45d8f23df218 Rob Hooft (Patch #101046): use PyArg_ParseTuple everywhere.
Guido van Rossum <guido@python.org>
parents: 13651
diff changeset
311 {"lockf", fcntl_lockf, METH_VARARGS, lockf_doc},
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 {NULL, NULL} /* sentinel */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 };
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
314
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
315
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
316 static char module_doc [] =
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
317
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
318 "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
319 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
320 routines. File descriptors can be obtained with the fileno() method of\n\
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
321 a file or socket object.";
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
322
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 /* Module initialisation */
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
324
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
325 static int
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
326 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
327 {
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
328 PyObject* v = PyInt_FromLong(value);
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
329 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
330 return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
331
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
332 Py_DECREF(v);
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
333 return 0;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
334 }
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
335
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
336 static int
13519
070e41f2697b ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13256
diff changeset
337 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
338 {
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
339 if (ins(d, "LOCK_SH", (long)LOCK_SH)) return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
340 if (ins(d, "LOCK_EX", (long)LOCK_EX)) return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
341 if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1;
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
342 if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1;
21586
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
343 /* GNU extensions, as of glibc 2.2.4 */
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
344 #ifdef LOCK_MAND
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
345 if (ins(d, "LOCK_MAND", (long)LOCK_MAND)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
346 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
347 #ifdef LOCK_READ
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
348 if (ins(d, "LOCK_READ", (long)LOCK_READ)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
349 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
350 #ifdef LOCK_WRITE
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
351 if (ins(d, "LOCK_WRITE", (long)LOCK_WRITE)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
352 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
353 #ifdef LOCK_RW
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
354 if (ins(d, "LOCK_RW", (long)LOCK_RW)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
355 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
356
17743
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
357 #ifdef F_DUPFD
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
358 if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
359 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
360 #ifdef F_GETFD
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
361 if (ins(d, "F_GETFD", (long)F_GETFD)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
362 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
363 #ifdef F_SETFD
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
364 if (ins(d, "F_SETFD", (long)F_SETFD)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
365 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
366 #ifdef F_GETFL
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
367 if (ins(d, "F_GETFL", (long)F_GETFL)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
368 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
369 #ifdef F_SETFL
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
370 if (ins(d, "F_SETFL", (long)F_SETFL)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
371 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
372 #ifdef F_GETLK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
373 if (ins(d, "F_GETLK", (long)F_GETLK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
374 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
375 #ifdef F_SETLK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
376 if (ins(d, "F_SETLK", (long)F_SETLK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
377 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
378 #ifdef F_SETLKW
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
379 if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
380 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
381 #ifdef F_GETOWN
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
382 if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
383 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
384 #ifdef F_SETOWN
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
385 if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
386 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
387 #ifdef F_GETSIG
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
388 if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
389 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
390 #ifdef F_SETSIG
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
391 if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
392 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
393 #ifdef F_RDLCK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
394 if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
395 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
396 #ifdef F_WRLCK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
397 if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
398 #endif
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
399 #ifdef F_UNLCK
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
400 if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1;
3ee9a3f60bc7 Modify to allow file objects wherever file descriptors are needed.
Fred Drake <fdrake@acm.org>
parents: 16245
diff changeset
401 #endif
21586
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
402 /* LFS constants */
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
403 #ifdef F_GETLK64
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
404 if (ins(d, "F_GETLK64", (long)F_GETLK64)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
405 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
406 #ifdef F_SETLK64
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
407 if (ins(d, "F_SETLK64", (long)F_SETLK64)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
408 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
409 #ifdef F_SETLKW64
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
410 if (ins(d, "F_SETLKW64", (long)F_SETLKW64)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
411 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
412 /* GNU extensions, as of glibc 2.2.4. */
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
413 #ifdef F_SETLEASE
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
414 if (ins(d, "F_SETLEASE", (long)F_SETLEASE)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
415 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
416 #ifdef F_GETLEASE
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
417 if (ins(d, "F_GETLEASE", (long)F_GETLEASE)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
418 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
419 #ifdef F_NOTIFY
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
420 if (ins(d, "F_NOTIFY", (long)F_NOTIFY)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
421 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
422 /* Old BSD flock(). */
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
423 #ifdef F_EXLCK
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
424 if (ins(d, "F_EXLCK", (long)F_EXLCK)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
425 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
426 #ifdef F_SHLCK
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
427 if (ins(d, "F_SHLCK", (long)F_SHLCK)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
428 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
429
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
430 /* For F_{GET|SET}FL */
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
431 #ifdef FD_CLOEXEC
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
432 if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
433 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
434
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
435 /* For F_NOTIFY */
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
436 #ifdef DN_ACCESS
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
437 if (ins(d, "DN_ACCESS", (long)DN_ACCESS)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
438 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
439 #ifdef DN_MODIFY
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
440 if (ins(d, "DN_MODIFY", (long)DN_MODIFY)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
441 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
442 #ifdef DN_CREATE
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
443 if (ins(d, "DN_CREATE", (long)DN_CREATE)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
444 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
445 #ifdef DN_DELETE
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
446 if (ins(d, "DN_DELETE", (long)DN_DELETE)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
447 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
448 #ifdef DN_RENAME
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
449 if (ins(d, "DN_RENAME", (long)DN_RENAME)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
450 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
451 #ifdef DN_ATTRIB
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
452 if (ins(d, "DN_ATTRIB", (long)DN_ATTRIB)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
453 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
454 #ifdef DN_MULTISHOT
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
455 if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1;
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
456 #endif
29c1a58dda53 Add fcntl.h constants from glibc 2.2.4. Fixes #496171.
Martin v. Löwis <martin@v.loewis.de>
parents: 17830
diff changeset
457
6055
72d004971b26 Keep gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5912
diff changeset
458 return 0;
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
459 }
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
460
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 9506
diff changeset
461 DL_EXPORT(void)
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13519
diff changeset
462 initfcntl(void)
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 {
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
464 PyObject *m, *d;
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
465
9506
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
466 /* Create the module and add the functions and documentation */
04426224302a Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents: 6055
diff changeset
467 m = Py_InitModule3("fcntl", fcntl_methods, module_doc);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
468
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
469 /* Add some symbolic constants to the module */
4757
e1f1725cae6d Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4623
diff changeset
470 d = PyModule_GetDict(m);
5912
f527c12f2e55 Add definitions for symbolic constants LOCK_{EX,NB,SH,UN}.
Guido van Rossum <guido@python.org>
parents: 4758
diff changeset
471 all_ins(d);
960
7d3a053c6765 struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 }