blob: 9f84a2c1432140d06d01dc8f053d58b277b21b8e [file] [log] [blame]
Guido van Rossum02975121992-08-17 08:55:12 +00001
2/* fcntl module */
3
Roger E. Masse919213a1996-12-17 17:42:22 +00004#include "Python.h"
Guido van Rossum02975121992-08-17 08:55:12 +00005
Guido van Rossuma376cc51996-12-05 23:43:35 +00006#ifdef HAVE_SYS_FILE_H
7#include <sys/file.h>
8#endif
9
Guido van Rossum3d65fa31996-12-09 18:49:14 +000010#include <sys/ioctl.h>
Guido van Rossum3c0b79c1996-06-11 15:11:34 +000011#include <fcntl.h>
12
Guido van Rossum02975121992-08-17 08:55:12 +000013
Fred Drake152a25e2001-05-09 21:02:02 +000014static int
15conv_descriptor(PyObject *object, int *target)
16{
17 int fd = PyObject_AsFileDescriptor(object);
18
19 if (fd < 0)
20 return 0;
21 *target = fd;
22 return 1;
23}
24
25
Guido van Rossum02975121992-08-17 08:55:12 +000026/* fcntl(fd, opt, [arg]) */
27
Roger E. Masse919213a1996-12-17 17:42:22 +000028static PyObject *
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +000029fcntl_fcntl(PyObject *self, PyObject *args)
Guido van Rossum02975121992-08-17 08:55:12 +000030{
31 int fd;
32 int code;
33 int arg;
34 int ret;
35 char *str;
36 int len;
37 char buf[1024];
38
Fred Drake152a25e2001-05-09 21:02:02 +000039 if (PyArg_ParseTuple(args, "O&is#:fcntl",
40 conv_descriptor, &fd, &code, &str, &len)) {
Guido van Rossum02975121992-08-17 08:55:12 +000041 if (len > sizeof buf) {
Roger E. Masse919213a1996-12-17 17:42:22 +000042 PyErr_SetString(PyExc_ValueError,
43 "fcntl string arg too long");
Guido van Rossum02975121992-08-17 08:55:12 +000044 return NULL;
45 }
46 memcpy(buf, str, len);
Roger E. Masse919213a1996-12-17 17:42:22 +000047 Py_BEGIN_ALLOW_THREADS
Guido van Rossum903f4871995-10-07 19:18:22 +000048 ret = fcntl(fd, code, buf);
Roger E. Masse919213a1996-12-17 17:42:22 +000049 Py_END_ALLOW_THREADS
Guido van Rossum903f4871995-10-07 19:18:22 +000050 if (ret < 0) {
Roger E. Masse919213a1996-12-17 17:42:22 +000051 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum02975121992-08-17 08:55:12 +000052 return NULL;
53 }
Roger E. Masse919213a1996-12-17 17:42:22 +000054 return PyString_FromStringAndSize(buf, len);
Guido van Rossum02975121992-08-17 08:55:12 +000055 }
56
Roger E. Masse919213a1996-12-17 17:42:22 +000057 PyErr_Clear();
Guido van Rossuma2214c32000-08-02 20:46:51 +000058 arg = 0;
Fred Drake152a25e2001-05-09 21:02:02 +000059 if (!PyArg_ParseTuple(args,
60 "O&i|i;fcntl requires a file or file descriptor,"
61 " an integer and optionally a third integer or a string",
62 conv_descriptor, &fd, &code, &arg)) {
Guido van Rossuma2214c32000-08-02 20:46:51 +000063 return NULL;
Guido van Rossum02975121992-08-17 08:55:12 +000064 }
Roger E. Masse919213a1996-12-17 17:42:22 +000065 Py_BEGIN_ALLOW_THREADS
Guido van Rossum02975121992-08-17 08:55:12 +000066 ret = fcntl(fd, code, arg);
Roger E. Masse919213a1996-12-17 17:42:22 +000067 Py_END_ALLOW_THREADS
Guido van Rossum02975121992-08-17 08:55:12 +000068 if (ret < 0) {
Roger E. Masse919213a1996-12-17 17:42:22 +000069 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum02975121992-08-17 08:55:12 +000070 return NULL;
71 }
Roger E. Masse919213a1996-12-17 17:42:22 +000072 return PyInt_FromLong((long)ret);
Guido van Rossum02975121992-08-17 08:55:12 +000073}
74
Guido van Rossum185ead61998-11-23 15:32:55 +000075static char fcntl_doc [] =
76
77"fcntl(fd, opt, [arg])\n\
78\n\
79Perform the requested operation on file descriptor fd. The operation\n\
Fred Drake1d531992001-05-10 15:54:32 +000080is defined by op and is operating system dependent. These constants are\n\
81available from the fcntl module. The argument arg is optional, and\n\
82defaults to 0; it may be an int or a string. If arg is given as a string,\n\
83the return value of fcntl is a string of that length, containing the\n\
84resulting value put in the arg buffer by the operating system.The length\n\
85of the arg string is not allowed to exceed 1024 bytes. If the arg given\n\
86is an integer or if none is specified, the result value is an integer\n\
Guido van Rossuma2214c32000-08-02 20:46:51 +000087corresponding to the return value of the fcntl call in the C code.";
Guido van Rossum185ead61998-11-23 15:32:55 +000088
Guido van Rossum02975121992-08-17 08:55:12 +000089
90/* ioctl(fd, opt, [arg]) */
91
Roger E. Masse919213a1996-12-17 17:42:22 +000092static PyObject *
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +000093fcntl_ioctl(PyObject *self, PyObject *args)
Guido van Rossum02975121992-08-17 08:55:12 +000094{
95 int fd;
96 int code;
97 int arg;
98 int ret;
99 char *str;
100 int len;
101 char buf[1024];
102
Fred Drake152a25e2001-05-09 21:02:02 +0000103 if (PyArg_ParseTuple(args, "O&is#:ioctl",
104 conv_descriptor, &fd, &code, &str, &len)) {
Guido van Rossum02975121992-08-17 08:55:12 +0000105 if (len > sizeof buf) {
Roger E. Masse919213a1996-12-17 17:42:22 +0000106 PyErr_SetString(PyExc_ValueError,
107 "ioctl string arg too long");
Guido van Rossum02975121992-08-17 08:55:12 +0000108 return NULL;
109 }
110 memcpy(buf, str, len);
Roger E. Masse919213a1996-12-17 17:42:22 +0000111 Py_BEGIN_ALLOW_THREADS
Guido van Rossum903f4871995-10-07 19:18:22 +0000112 ret = ioctl(fd, code, buf);
Roger E. Masse919213a1996-12-17 17:42:22 +0000113 Py_END_ALLOW_THREADS
Guido van Rossum903f4871995-10-07 19:18:22 +0000114 if (ret < 0) {
Roger E. Masse919213a1996-12-17 17:42:22 +0000115 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum02975121992-08-17 08:55:12 +0000116 return NULL;
117 }
Roger E. Masse919213a1996-12-17 17:42:22 +0000118 return PyString_FromStringAndSize(buf, len);
Guido van Rossum02975121992-08-17 08:55:12 +0000119 }
120
Roger E. Masse919213a1996-12-17 17:42:22 +0000121 PyErr_Clear();
Guido van Rossuma2214c32000-08-02 20:46:51 +0000122 arg = 0;
Fred Drake460f0692001-05-14 21:02:36 +0000123 if (!PyArg_ParseTuple(args,
124 "O&i|i;ioctl requires a file or file descriptor,"
125 " an integer and optionally a third integer or a string",
Fred Drake152a25e2001-05-09 21:02:02 +0000126 conv_descriptor, &fd, &code, &arg)) {
Guido van Rossuma2214c32000-08-02 20:46:51 +0000127 return NULL;
Guido van Rossum02975121992-08-17 08:55:12 +0000128 }
Roger E. Masse919213a1996-12-17 17:42:22 +0000129 Py_BEGIN_ALLOW_THREADS
Guido van Rossum02975121992-08-17 08:55:12 +0000130 ret = ioctl(fd, code, arg);
Roger E. Masse919213a1996-12-17 17:42:22 +0000131 Py_END_ALLOW_THREADS
Guido van Rossum02975121992-08-17 08:55:12 +0000132 if (ret < 0) {
Roger E. Masse919213a1996-12-17 17:42:22 +0000133 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum02975121992-08-17 08:55:12 +0000134 return NULL;
135 }
Roger E. Masse919213a1996-12-17 17:42:22 +0000136 return PyInt_FromLong((long)ret);
Guido van Rossum02975121992-08-17 08:55:12 +0000137}
138
Guido van Rossum185ead61998-11-23 15:32:55 +0000139static char ioctl_doc [] =
140"ioctl(fd, opt, [arg])\n\
141\n\
142Perform the requested operation on file descriptor fd. The operation\n\
143is defined by op and is operating system dependent. Typically these\n\
144codes can be retrieved from the library module IOCTL. The argument arg\n\
Guido van Rossuma2214c32000-08-02 20:46:51 +0000145is optional, and defaults to 0; it may be an int or a string. If arg is\n\
146given as a string, the return value of ioctl is a string of that length,\n\
147containing the resulting value put in the arg buffer by the operating system.\n\
148The length of the arg string is not allowed to exceed 1024 bytes. If the arg\n\
149given is an integer or if none is specified, the result value is an integer\n\
150corresponding to the return value of the ioctl call in the C code.";
Guido van Rossum185ead61998-11-23 15:32:55 +0000151
Guido van Rossum02975121992-08-17 08:55:12 +0000152
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000153/* flock(fd, operation) */
154
Roger E. Masse919213a1996-12-17 17:42:22 +0000155static PyObject *
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +0000156fcntl_flock(PyObject *self, PyObject *args)
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000157{
158 int fd;
159 int code;
160 int ret;
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000161
Fred Drake152a25e2001-05-09 21:02:02 +0000162 if (!PyArg_ParseTuple(args, "O&i:flock",
163 conv_descriptor, &fd, &code))
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000164 return NULL;
165
Guido van Rossum3c0b79c1996-06-11 15:11:34 +0000166#ifdef HAVE_FLOCK
Guido van Rossum056bad91999-01-06 18:44:23 +0000167 Py_BEGIN_ALLOW_THREADS
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000168 ret = flock(fd, code);
Guido van Rossum056bad91999-01-06 18:44:23 +0000169 Py_END_ALLOW_THREADS
Guido van Rossum3c0b79c1996-06-11 15:11:34 +0000170#else
171
172#ifndef LOCK_SH
173#define LOCK_SH 1 /* shared lock */
174#define LOCK_EX 2 /* exclusive lock */
175#define LOCK_NB 4 /* don't block when locking */
176#define LOCK_UN 8 /* unlock */
177#endif
178 {
179 struct flock l;
180 if (code == LOCK_UN)
181 l.l_type = F_UNLCK;
182 else if (code & LOCK_SH)
183 l.l_type = F_RDLCK;
184 else if (code & LOCK_EX)
185 l.l_type = F_WRLCK;
186 else {
Roger E. Masse919213a1996-12-17 17:42:22 +0000187 PyErr_SetString(PyExc_ValueError,
188 "unrecognized flock argument");
Guido van Rossum3c0b79c1996-06-11 15:11:34 +0000189 return NULL;
190 }
191 l.l_whence = l.l_start = l.l_len = 0;
Guido van Rossum056bad91999-01-06 18:44:23 +0000192 Py_BEGIN_ALLOW_THREADS
Guido van Rossum3c0b79c1996-06-11 15:11:34 +0000193 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
Guido van Rossum056bad91999-01-06 18:44:23 +0000194 Py_END_ALLOW_THREADS
Guido van Rossum3c0b79c1996-06-11 15:11:34 +0000195 }
196#endif /* HAVE_FLOCK */
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000197 if (ret < 0) {
Roger E. Masse919213a1996-12-17 17:42:22 +0000198 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000199 return NULL;
200 }
Roger E. Masse919213a1996-12-17 17:42:22 +0000201 Py_INCREF(Py_None);
202 return Py_None;
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000203}
204
Guido van Rossum185ead61998-11-23 15:32:55 +0000205static char flock_doc [] =
206"flock(fd, operation)\n\
207\n\
208Perform the lock operation op on file descriptor fd. See the Unix \n\
209manual flock(3) for details. (On some systems, this function is\n\
210emulated using fcntl().)";
211
212
Guido van Rossumc8643641996-09-11 23:17:20 +0000213/* lockf(fd, operation) */
Roger E. Masse919213a1996-12-17 17:42:22 +0000214static PyObject *
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +0000215fcntl_lockf(PyObject *self, PyObject *args)
Guido van Rossumc8643641996-09-11 23:17:20 +0000216{
Guido van Rossum056bad91999-01-06 18:44:23 +0000217 int fd, code, ret, whence = 0;
218 PyObject *lenobj = NULL, *startobj = NULL;
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000219
Fred Drake152a25e2001-05-09 21:02:02 +0000220 if (!PyArg_ParseTuple(args, "O&i|OOi:lockf",
221 conv_descriptor, &fd, &code,
Guido van Rossum056bad91999-01-06 18:44:23 +0000222 &lenobj, &startobj, &whence))
Guido van Rossumc8643641996-09-11 23:17:20 +0000223 return NULL;
224
Guido van Rossumc8643641996-09-11 23:17:20 +0000225#ifndef LOCK_SH
226#define LOCK_SH 1 /* shared lock */
227#define LOCK_EX 2 /* exclusive lock */
228#define LOCK_NB 4 /* don't block when locking */
229#define LOCK_UN 8 /* unlock */
230#endif
231 {
232 struct flock l;
233 if (code == LOCK_UN)
234 l.l_type = F_UNLCK;
235 else if (code & LOCK_SH)
236 l.l_type = F_RDLCK;
237 else if (code & LOCK_EX)
238 l.l_type = F_WRLCK;
239 else {
Roger E. Masse919213a1996-12-17 17:42:22 +0000240 PyErr_SetString(PyExc_ValueError,
241 "unrecognized flock argument");
Guido van Rossumc8643641996-09-11 23:17:20 +0000242 return NULL;
243 }
Guido van Rossum056bad91999-01-06 18:44:23 +0000244 l.l_start = l.l_len = 0;
245 if (startobj != NULL) {
246#if !defined(HAVE_LARGEFILE_SUPPORT)
247 l.l_start = PyInt_AsLong(startobj);
248#else
249 l.l_start = PyLong_Check(startobj) ?
250 PyLong_AsLongLong(startobj) :
251 PyInt_AsLong(startobj);
252#endif
253 if (PyErr_Occurred())
254 return NULL;
255 }
256 if (lenobj != NULL) {
257#if !defined(HAVE_LARGEFILE_SUPPORT)
258 l.l_len = PyInt_AsLong(lenobj);
259#else
260 l.l_len = PyLong_Check(lenobj) ?
261 PyLong_AsLongLong(lenobj) :
262 PyInt_AsLong(lenobj);
263#endif
264 if (PyErr_Occurred())
265 return NULL;
266 }
Guido van Rossumc8643641996-09-11 23:17:20 +0000267 l.l_whence = whence;
Guido van Rossum056bad91999-01-06 18:44:23 +0000268 Py_BEGIN_ALLOW_THREADS
Guido van Rossumc8643641996-09-11 23:17:20 +0000269 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
Guido van Rossum056bad91999-01-06 18:44:23 +0000270 Py_END_ALLOW_THREADS
Guido van Rossumc8643641996-09-11 23:17:20 +0000271 }
Guido van Rossumc8643641996-09-11 23:17:20 +0000272 if (ret < 0) {
Roger E. Masse919213a1996-12-17 17:42:22 +0000273 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossumc8643641996-09-11 23:17:20 +0000274 return NULL;
275 }
Roger E. Masse919213a1996-12-17 17:42:22 +0000276 Py_INCREF(Py_None);
277 return Py_None;
Guido van Rossumc8643641996-09-11 23:17:20 +0000278}
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000279
Guido van Rossum185ead61998-11-23 15:32:55 +0000280static char lockf_doc [] =
Sjoerd Mullender82e00d62001-01-25 10:10:39 +0000281"lockf (fd, operation, length=0, start=0, whence=0)\n\
282\n\
283This is essentially a wrapper around the fcntl() locking calls. fd is the\n\
284file descriptor of the file to lock or unlock, and operation is one of the\n\
285following values:\n\
286\n\
287 LOCK_UN - unlock\n\
288 LOCK_SH - acquire a shared lock\n\
289 LOCK_EX - acquire an exclusive lock\n\
290\n\
291When operation is LOCK_SH or LOCK_EX, it can also be bit-wise OR'd with\n\
292LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the\n\
293lock cannot be acquired, an IOError will be raised and the exception will\n\
294have an errno attribute set to EACCES or EAGAIN (depending on the operating\n\
295system -- for portability, check for either value).\n\
296\n\
297length is the number of bytes to lock, with the default meaning to lock to\n\
298EOF. start is the byte offset, relative to whence, to that the lock\n\
299starts. whence is as with fileobj.seek(), specifically:\n\
300\n\
301 0 - relative to the start of the file (SEEK_SET)\n\
302 1 - relative to the current buffer position (SEEK_CUR)\n\
Barry Warsawbd3dc1f2001-01-25 00:20:13 +0000303 2 - relative to the end of the file (SEEK_END)";
Guido van Rossum185ead61998-11-23 15:32:55 +0000304
Guido van Rossum02975121992-08-17 08:55:12 +0000305/* List of functions */
306
Roger E. Masse919213a1996-12-17 17:42:22 +0000307static PyMethodDef fcntl_methods[] = {
Guido van Rossuma2214c32000-08-02 20:46:51 +0000308 {"fcntl", fcntl_fcntl, METH_VARARGS, fcntl_doc},
309 {"ioctl", fcntl_ioctl, METH_VARARGS, ioctl_doc},
310 {"flock", fcntl_flock, METH_VARARGS, flock_doc},
311 {"lockf", fcntl_lockf, METH_VARARGS, lockf_doc},
Guido van Rossum02975121992-08-17 08:55:12 +0000312 {NULL, NULL} /* sentinel */
313};
314
315
Guido van Rossum185ead61998-11-23 15:32:55 +0000316static char module_doc [] =
317
318"This module performs file control and I/O control on file \n\
319descriptors. It is an interface to the fcntl() and ioctl() Unix\n\
320routines. File descriptors can be obtained with the fileno() method of\n\
321a file or socket object.";
322
Guido van Rossum02975121992-08-17 08:55:12 +0000323/* Module initialisation */
324
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000325static int
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +0000326ins(PyObject* d, char* symbol, long value)
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000327{
328 PyObject* v = PyInt_FromLong(value);
329 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
330 return -1;
331
332 Py_DECREF(v);
333 return 0;
334}
335
336static int
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +0000337all_ins(PyObject* d)
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000338{
339 if (ins(d, "LOCK_SH", (long)LOCK_SH)) return -1;
340 if (ins(d, "LOCK_EX", (long)LOCK_EX)) return -1;
341 if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1;
342 if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1;
Martin v. Löwis1baeba62001-12-28 21:08:12 +0000343/* GNU extensions, as of glibc 2.2.4 */
344#ifdef LOCK_MAND
345 if (ins(d, "LOCK_MAND", (long)LOCK_MAND)) return -1;
346#endif
347#ifdef LOCK_READ
348 if (ins(d, "LOCK_READ", (long)LOCK_READ)) return -1;
349#endif
350#ifdef LOCK_WRITE
351 if (ins(d, "LOCK_WRITE", (long)LOCK_WRITE)) return -1;
352#endif
353#ifdef LOCK_RW
354 if (ins(d, "LOCK_RW", (long)LOCK_RW)) return -1;
355#endif
356
Fred Drake152a25e2001-05-09 21:02:02 +0000357#ifdef F_DUPFD
358 if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1;
359#endif
360#ifdef F_GETFD
361 if (ins(d, "F_GETFD", (long)F_GETFD)) return -1;
362#endif
363#ifdef F_SETFD
364 if (ins(d, "F_SETFD", (long)F_SETFD)) return -1;
365#endif
366#ifdef F_GETFL
367 if (ins(d, "F_GETFL", (long)F_GETFL)) return -1;
368#endif
369#ifdef F_SETFL
370 if (ins(d, "F_SETFL", (long)F_SETFL)) return -1;
371#endif
372#ifdef F_GETLK
373 if (ins(d, "F_GETLK", (long)F_GETLK)) return -1;
374#endif
375#ifdef F_SETLK
376 if (ins(d, "F_SETLK", (long)F_SETLK)) return -1;
377#endif
378#ifdef F_SETLKW
379 if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1;
380#endif
381#ifdef F_GETOWN
382 if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1;
383#endif
384#ifdef F_SETOWN
385 if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1;
386#endif
387#ifdef F_GETSIG
388 if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1;
389#endif
390#ifdef F_SETSIG
391 if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1;
392#endif
393#ifdef F_RDLCK
394 if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1;
395#endif
396#ifdef F_WRLCK
397 if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1;
398#endif
399#ifdef F_UNLCK
400 if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1;
401#endif
Martin v. Löwis1baeba62001-12-28 21:08:12 +0000402/* LFS constants */
403#ifdef F_GETLK64
404 if (ins(d, "F_GETLK64", (long)F_GETLK64)) return -1;
405#endif
406#ifdef F_SETLK64
407 if (ins(d, "F_SETLK64", (long)F_SETLK64)) return -1;
408#endif
409#ifdef F_SETLKW64
410 if (ins(d, "F_SETLKW64", (long)F_SETLKW64)) return -1;
411#endif
412/* GNU extensions, as of glibc 2.2.4. */
413#ifdef F_SETLEASE
414 if (ins(d, "F_SETLEASE", (long)F_SETLEASE)) return -1;
415#endif
416#ifdef F_GETLEASE
417 if (ins(d, "F_GETLEASE", (long)F_GETLEASE)) return -1;
418#endif
419#ifdef F_NOTIFY
420 if (ins(d, "F_NOTIFY", (long)F_NOTIFY)) return -1;
421#endif
422/* Old BSD flock(). */
423#ifdef F_EXLCK
424 if (ins(d, "F_EXLCK", (long)F_EXLCK)) return -1;
425#endif
426#ifdef F_SHLCK
427 if (ins(d, "F_SHLCK", (long)F_SHLCK)) return -1;
428#endif
429
430/* For F_{GET|SET}FL */
431#ifdef FD_CLOEXEC
432 if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) return -1;
433#endif
434
435/* For F_NOTIFY */
436#ifdef DN_ACCESS
437 if (ins(d, "DN_ACCESS", (long)DN_ACCESS)) return -1;
438#endif
439#ifdef DN_MODIFY
440 if (ins(d, "DN_MODIFY", (long)DN_MODIFY)) return -1;
441#endif
442#ifdef DN_CREATE
443 if (ins(d, "DN_CREATE", (long)DN_CREATE)) return -1;
444#endif
445#ifdef DN_DELETE
446 if (ins(d, "DN_DELETE", (long)DN_DELETE)) return -1;
447#endif
448#ifdef DN_RENAME
449 if (ins(d, "DN_RENAME", (long)DN_RENAME)) return -1;
450#endif
451#ifdef DN_ATTRIB
452 if (ins(d, "DN_ATTRIB", (long)DN_ATTRIB)) return -1;
453#endif
454#ifdef DN_MULTISHOT
455 if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1;
456#endif
457
Guido van Rossum7c141031997-08-15 02:52:08 +0000458 return 0;
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000459}
460
Guido van Rossum3886bb61998-12-04 18:50:17 +0000461DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000462initfcntl(void)
Guido van Rossum02975121992-08-17 08:55:12 +0000463{
Roger E. Masse919213a1996-12-17 17:42:22 +0000464 PyObject *m, *d;
Guido van Rossum02975121992-08-17 08:55:12 +0000465
Guido van Rossum185ead61998-11-23 15:32:55 +0000466 /* Create the module and add the functions and documentation */
467 m = Py_InitModule3("fcntl", fcntl_methods, module_doc);
Guido van Rossum02975121992-08-17 08:55:12 +0000468
469 /* Add some symbolic constants to the module */
Roger E. Masse919213a1996-12-17 17:42:22 +0000470 d = PyModule_GetDict(m);
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000471 all_ins(d);
Guido van Rossum02975121992-08-17 08:55:12 +0000472}