blob: 13cd0f76e4ca7bbe78954003d0ca80ba11c343f1 [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
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000225#if defined(PYOS_OS2) && defined(PYCC_GCC)
226 PyErr_SetString(PyExc_NotImplementedError,
227 "lockf not supported on OS/2 (EMX)");
228 return NULL;
229#else
Guido van Rossumc8643641996-09-11 23:17:20 +0000230#ifndef LOCK_SH
231#define LOCK_SH 1 /* shared lock */
232#define LOCK_EX 2 /* exclusive lock */
233#define LOCK_NB 4 /* don't block when locking */
234#define LOCK_UN 8 /* unlock */
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000235#endif /* LOCK_SH */
Guido van Rossumc8643641996-09-11 23:17:20 +0000236 {
237 struct flock l;
238 if (code == LOCK_UN)
239 l.l_type = F_UNLCK;
240 else if (code & LOCK_SH)
241 l.l_type = F_RDLCK;
242 else if (code & LOCK_EX)
243 l.l_type = F_WRLCK;
244 else {
Roger E. Masse919213a1996-12-17 17:42:22 +0000245 PyErr_SetString(PyExc_ValueError,
246 "unrecognized flock argument");
Guido van Rossumc8643641996-09-11 23:17:20 +0000247 return NULL;
248 }
Guido van Rossum056bad91999-01-06 18:44:23 +0000249 l.l_start = l.l_len = 0;
250 if (startobj != NULL) {
251#if !defined(HAVE_LARGEFILE_SUPPORT)
252 l.l_start = PyInt_AsLong(startobj);
253#else
254 l.l_start = PyLong_Check(startobj) ?
255 PyLong_AsLongLong(startobj) :
256 PyInt_AsLong(startobj);
257#endif
258 if (PyErr_Occurred())
259 return NULL;
260 }
261 if (lenobj != NULL) {
262#if !defined(HAVE_LARGEFILE_SUPPORT)
263 l.l_len = PyInt_AsLong(lenobj);
264#else
265 l.l_len = PyLong_Check(lenobj) ?
266 PyLong_AsLongLong(lenobj) :
267 PyInt_AsLong(lenobj);
268#endif
269 if (PyErr_Occurred())
270 return NULL;
271 }
Guido van Rossumc8643641996-09-11 23:17:20 +0000272 l.l_whence = whence;
Guido van Rossum056bad91999-01-06 18:44:23 +0000273 Py_BEGIN_ALLOW_THREADS
Guido van Rossumc8643641996-09-11 23:17:20 +0000274 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
Guido van Rossum056bad91999-01-06 18:44:23 +0000275 Py_END_ALLOW_THREADS
Guido van Rossumc8643641996-09-11 23:17:20 +0000276 }
Guido van Rossumc8643641996-09-11 23:17:20 +0000277 if (ret < 0) {
Roger E. Masse919213a1996-12-17 17:42:22 +0000278 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossumc8643641996-09-11 23:17:20 +0000279 return NULL;
280 }
Roger E. Masse919213a1996-12-17 17:42:22 +0000281 Py_INCREF(Py_None);
282 return Py_None;
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000283#endif /* defined(PYOS_OS2) && defined(PYCC_GCC) */
Guido van Rossumc8643641996-09-11 23:17:20 +0000284}
Guido van Rossum3539b1e1996-05-23 22:56:38 +0000285
Guido van Rossum185ead61998-11-23 15:32:55 +0000286static char lockf_doc [] =
Sjoerd Mullender82e00d62001-01-25 10:10:39 +0000287"lockf (fd, operation, length=0, start=0, whence=0)\n\
288\n\
289This is essentially a wrapper around the fcntl() locking calls. fd is the\n\
290file descriptor of the file to lock or unlock, and operation is one of the\n\
291following values:\n\
292\n\
293 LOCK_UN - unlock\n\
294 LOCK_SH - acquire a shared lock\n\
295 LOCK_EX - acquire an exclusive lock\n\
296\n\
297When operation is LOCK_SH or LOCK_EX, it can also be bit-wise OR'd with\n\
298LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the\n\
299lock cannot be acquired, an IOError will be raised and the exception will\n\
300have an errno attribute set to EACCES or EAGAIN (depending on the operating\n\
301system -- for portability, check for either value).\n\
302\n\
303length is the number of bytes to lock, with the default meaning to lock to\n\
304EOF. start is the byte offset, relative to whence, to that the lock\n\
305starts. whence is as with fileobj.seek(), specifically:\n\
306\n\
307 0 - relative to the start of the file (SEEK_SET)\n\
308 1 - relative to the current buffer position (SEEK_CUR)\n\
Barry Warsawbd3dc1f2001-01-25 00:20:13 +0000309 2 - relative to the end of the file (SEEK_END)";
Guido van Rossum185ead61998-11-23 15:32:55 +0000310
Guido van Rossum02975121992-08-17 08:55:12 +0000311/* List of functions */
312
Roger E. Masse919213a1996-12-17 17:42:22 +0000313static PyMethodDef fcntl_methods[] = {
Guido van Rossuma2214c32000-08-02 20:46:51 +0000314 {"fcntl", fcntl_fcntl, METH_VARARGS, fcntl_doc},
315 {"ioctl", fcntl_ioctl, METH_VARARGS, ioctl_doc},
316 {"flock", fcntl_flock, METH_VARARGS, flock_doc},
317 {"lockf", fcntl_lockf, METH_VARARGS, lockf_doc},
Guido van Rossum02975121992-08-17 08:55:12 +0000318 {NULL, NULL} /* sentinel */
319};
320
321
Guido van Rossum185ead61998-11-23 15:32:55 +0000322static char module_doc [] =
323
324"This module performs file control and I/O control on file \n\
325descriptors. It is an interface to the fcntl() and ioctl() Unix\n\
326routines. File descriptors can be obtained with the fileno() method of\n\
327a file or socket object.";
328
Guido van Rossum02975121992-08-17 08:55:12 +0000329/* Module initialisation */
330
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000331static int
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +0000332ins(PyObject* d, char* symbol, long value)
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000333{
334 PyObject* v = PyInt_FromLong(value);
335 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
336 return -1;
337
338 Py_DECREF(v);
339 return 0;
340}
341
342static int
Peter Schneider-Kamp8bc8f0d2000-07-10 17:15:07 +0000343all_ins(PyObject* d)
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000344{
345 if (ins(d, "LOCK_SH", (long)LOCK_SH)) return -1;
346 if (ins(d, "LOCK_EX", (long)LOCK_EX)) return -1;
347 if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1;
348 if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1;
Martin v. Löwis1baeba62001-12-28 21:08:12 +0000349/* GNU extensions, as of glibc 2.2.4 */
350#ifdef LOCK_MAND
351 if (ins(d, "LOCK_MAND", (long)LOCK_MAND)) return -1;
352#endif
353#ifdef LOCK_READ
354 if (ins(d, "LOCK_READ", (long)LOCK_READ)) return -1;
355#endif
356#ifdef LOCK_WRITE
357 if (ins(d, "LOCK_WRITE", (long)LOCK_WRITE)) return -1;
358#endif
359#ifdef LOCK_RW
360 if (ins(d, "LOCK_RW", (long)LOCK_RW)) return -1;
361#endif
362
Fred Drake152a25e2001-05-09 21:02:02 +0000363#ifdef F_DUPFD
364 if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1;
365#endif
366#ifdef F_GETFD
367 if (ins(d, "F_GETFD", (long)F_GETFD)) return -1;
368#endif
369#ifdef F_SETFD
370 if (ins(d, "F_SETFD", (long)F_SETFD)) return -1;
371#endif
372#ifdef F_GETFL
373 if (ins(d, "F_GETFL", (long)F_GETFL)) return -1;
374#endif
375#ifdef F_SETFL
376 if (ins(d, "F_SETFL", (long)F_SETFL)) return -1;
377#endif
378#ifdef F_GETLK
379 if (ins(d, "F_GETLK", (long)F_GETLK)) return -1;
380#endif
381#ifdef F_SETLK
382 if (ins(d, "F_SETLK", (long)F_SETLK)) return -1;
383#endif
384#ifdef F_SETLKW
385 if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1;
386#endif
387#ifdef F_GETOWN
388 if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1;
389#endif
390#ifdef F_SETOWN
391 if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1;
392#endif
393#ifdef F_GETSIG
394 if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1;
395#endif
396#ifdef F_SETSIG
397 if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1;
398#endif
399#ifdef F_RDLCK
400 if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1;
401#endif
402#ifdef F_WRLCK
403 if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1;
404#endif
405#ifdef F_UNLCK
406 if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1;
407#endif
Martin v. Löwis1baeba62001-12-28 21:08:12 +0000408/* LFS constants */
409#ifdef F_GETLK64
410 if (ins(d, "F_GETLK64", (long)F_GETLK64)) return -1;
411#endif
412#ifdef F_SETLK64
413 if (ins(d, "F_SETLK64", (long)F_SETLK64)) return -1;
414#endif
415#ifdef F_SETLKW64
416 if (ins(d, "F_SETLKW64", (long)F_SETLKW64)) return -1;
417#endif
418/* GNU extensions, as of glibc 2.2.4. */
419#ifdef F_SETLEASE
420 if (ins(d, "F_SETLEASE", (long)F_SETLEASE)) return -1;
421#endif
422#ifdef F_GETLEASE
423 if (ins(d, "F_GETLEASE", (long)F_GETLEASE)) return -1;
424#endif
425#ifdef F_NOTIFY
426 if (ins(d, "F_NOTIFY", (long)F_NOTIFY)) return -1;
427#endif
428/* Old BSD flock(). */
429#ifdef F_EXLCK
430 if (ins(d, "F_EXLCK", (long)F_EXLCK)) return -1;
431#endif
432#ifdef F_SHLCK
433 if (ins(d, "F_SHLCK", (long)F_SHLCK)) return -1;
434#endif
435
436/* For F_{GET|SET}FL */
437#ifdef FD_CLOEXEC
438 if (ins(d, "FD_CLOEXEC", (long)FD_CLOEXEC)) return -1;
439#endif
440
441/* For F_NOTIFY */
442#ifdef DN_ACCESS
443 if (ins(d, "DN_ACCESS", (long)DN_ACCESS)) return -1;
444#endif
445#ifdef DN_MODIFY
446 if (ins(d, "DN_MODIFY", (long)DN_MODIFY)) return -1;
447#endif
448#ifdef DN_CREATE
449 if (ins(d, "DN_CREATE", (long)DN_CREATE)) return -1;
450#endif
451#ifdef DN_DELETE
452 if (ins(d, "DN_DELETE", (long)DN_DELETE)) return -1;
453#endif
454#ifdef DN_RENAME
455 if (ins(d, "DN_RENAME", (long)DN_RENAME)) return -1;
456#endif
457#ifdef DN_ATTRIB
458 if (ins(d, "DN_ATTRIB", (long)DN_ATTRIB)) return -1;
459#endif
460#ifdef DN_MULTISHOT
461 if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1;
462#endif
463
Guido van Rossum7c141031997-08-15 02:52:08 +0000464 return 0;
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000465}
466
Guido van Rossum3886bb61998-12-04 18:50:17 +0000467DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000468initfcntl(void)
Guido van Rossum02975121992-08-17 08:55:12 +0000469{
Roger E. Masse919213a1996-12-17 17:42:22 +0000470 PyObject *m, *d;
Guido van Rossum02975121992-08-17 08:55:12 +0000471
Guido van Rossum185ead61998-11-23 15:32:55 +0000472 /* Create the module and add the functions and documentation */
473 m = Py_InitModule3("fcntl", fcntl_methods, module_doc);
Guido van Rossum02975121992-08-17 08:55:12 +0000474
475 /* Add some symbolic constants to the module */
Roger E. Masse919213a1996-12-17 17:42:22 +0000476 d = PyModule_GetDict(m);
Guido van Rossumf4e32c71997-07-31 19:39:54 +0000477 all_ins(d);
Guido van Rossum02975121992-08-17 08:55:12 +0000478}