ยปCore Development>Code coverage>Modules/fcntlmodule.c

Python code coverage for Modules/fcntlmodule.c

#countcontent
1n/a
2n/a/* fcntl module */
3n/a
4n/a#define PY_SSIZE_T_CLEAN
5n/a
6n/a#include "Python.h"
7n/a
8n/a#ifdef HAVE_SYS_FILE_H
9n/a#include <sys/file.h>
10n/a#endif
11n/a
12n/a#include <sys/ioctl.h>
13n/a#include <fcntl.h>
14n/a#ifdef HAVE_STROPTS_H
15n/a#include <stropts.h>
16n/a#endif
17n/a
18n/a/*[clinic input]
19n/amodule fcntl
20n/a[clinic start generated code]*/
21n/a/*[clinic end generated code: output=da39a3ee5e6b4b0d input=124b58387c158179]*/
22n/a
23n/astatic int
24n/aconv_descriptor(PyObject *object, int *target)
25n/a{
26n/a int fd = PyObject_AsFileDescriptor(object);
27n/a
28n/a if (fd < 0)
29n/a return 0;
30n/a *target = fd;
31n/a return 1;
32n/a}
33n/a
34n/a/* Must come after conv_descriptor definition. */
35n/a#include "clinic/fcntlmodule.c.h"
36n/a
37n/a/*[clinic input]
38n/afcntl.fcntl
39n/a
40n/a fd: object(type='int', converter='conv_descriptor')
41n/a cmd as code: int
42n/a arg: object(c_default='NULL') = 0
43n/a /
44n/a
45n/aPerform the operation `cmd` on file descriptor fd.
46n/a
47n/aThe values used for `cmd` are operating system dependent, and are available
48n/aas constants in the fcntl module, using the same names as used in
49n/athe relevant C header files. The argument arg is optional, and
50n/adefaults to 0; it may be an int or a string. If arg is given as a string,
51n/athe return value of fcntl is a string of that length, containing the
52n/aresulting value put in the arg buffer by the operating system. The length
53n/aof the arg string is not allowed to exceed 1024 bytes. If the arg given
54n/ais an integer or if none is specified, the result value is an integer
55n/acorresponding to the return value of the fcntl call in the C code.
56n/a[clinic start generated code]*/
57n/a
58n/astatic PyObject *
59n/afcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
60n/a/*[clinic end generated code: output=888fc93b51c295bd input=8cefbe59b29efbe2]*/
61n/a{
62n/a unsigned int int_arg = 0;
63n/a int ret;
64n/a char *str;
65n/a Py_ssize_t len;
66n/a char buf[1024];
67n/a
68n/a if (arg != NULL) {
69n/a int parse_result;
70n/a
71n/a if (PyArg_Parse(arg, "s#", &str, &len)) {
72n/a if ((size_t)len > sizeof buf) {
73n/a PyErr_SetString(PyExc_ValueError,
74n/a "fcntl string arg too long");
75n/a return NULL;
76n/a }
77n/a memcpy(buf, str, len);
78n/a Py_BEGIN_ALLOW_THREADS
79n/a ret = fcntl(fd, code, buf);
80n/a Py_END_ALLOW_THREADS
81n/a if (ret < 0) {
82n/a PyErr_SetFromErrno(PyExc_IOError);
83n/a return NULL;
84n/a }
85n/a return PyBytes_FromStringAndSize(buf, len);
86n/a }
87n/a
88n/a PyErr_Clear();
89n/a parse_result = PyArg_Parse(arg,
90n/a "I;fcntl requires a file or file descriptor,"
91n/a " an integer and optionally a third integer or a string",
92n/a &int_arg);
93n/a if (!parse_result) {
94n/a return NULL;
95n/a }
96n/a }
97n/a
98n/a Py_BEGIN_ALLOW_THREADS
99n/a ret = fcntl(fd, code, (int)int_arg);
100n/a Py_END_ALLOW_THREADS
101n/a if (ret < 0) {
102n/a PyErr_SetFromErrno(PyExc_IOError);
103n/a return NULL;
104n/a }
105n/a return PyLong_FromLong((long)ret);
106n/a}
107n/a
108n/a
109n/a/*[clinic input]
110n/afcntl.ioctl
111n/a
112n/a fd: object(type='int', converter='conv_descriptor')
113n/a request as code: unsigned_int(bitwise=True)
114n/a arg as ob_arg: object(c_default='NULL') = 0
115n/a mutate_flag as mutate_arg: bool = True
116n/a /
117n/a
118n/aPerform the operation `request` on file descriptor `fd`.
119n/a
120n/aThe values used for `request` are operating system dependent, and are available
121n/aas constants in the fcntl or termios library modules, using the same names as
122n/aused in the relevant C header files.
123n/a
124n/aThe argument `arg` is optional, and defaults to 0; it may be an int or a
125n/abuffer containing character data (most likely a string or an array).
126n/a
127n/aIf the argument is a mutable buffer (such as an array) and if the
128n/amutate_flag argument (which is only allowed in this case) is true then the
129n/abuffer is (in effect) passed to the operating system and changes made by
130n/athe OS will be reflected in the contents of the buffer after the call has
131n/areturned. The return value is the integer returned by the ioctl system
132n/acall.
133n/a
134n/aIf the argument is a mutable buffer and the mutable_flag argument is false,
135n/athe behavior is as if a string had been passed.
136n/a
137n/aIf the argument is an immutable buffer (most likely a string) then a copy
138n/aof the buffer is passed to the operating system and the return value is a
139n/astring of the same length containing whatever the operating system put in
140n/athe buffer. The length of the arg buffer in this case is not allowed to
141n/aexceed 1024 bytes.
142n/a
143n/aIf the arg given is an integer or if none is specified, the result value is
144n/aan integer corresponding to the return value of the ioctl call in the C
145n/acode.
146n/a[clinic start generated code]*/
147n/a
148n/astatic PyObject *
149n/afcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
150n/a PyObject *ob_arg, int mutate_arg)
151n/a/*[clinic end generated code: output=7f7f5840c65991be input=ede70c433cccbbb2]*/
152n/a{
153n/a#define IOCTL_BUFSZ 1024
154n/a /* We use the unsigned non-checked 'I' format for the 'code' parameter
155n/a because the system expects it to be a 32bit bit field value
156n/a regardless of it being passed as an int or unsigned long on
157n/a various platforms. See the termios.TIOCSWINSZ constant across
158n/a platforms for an example of this.
159n/a
160n/a If any of the 64bit platforms ever decide to use more than 32bits
161n/a in their unsigned long ioctl codes this will break and need
162n/a special casing based on the platform being built on.
163n/a */
164n/a int arg = 0;
165n/a int ret;
166n/a Py_buffer pstr;
167n/a char *str;
168n/a Py_ssize_t len;
169n/a char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */
170n/a
171n/a if (ob_arg != NULL) {
172n/a if (PyArg_Parse(ob_arg, "w*:ioctl", &pstr)) {
173n/a char *arg;
174n/a str = pstr.buf;
175n/a len = pstr.len;
176n/a
177n/a if (mutate_arg) {
178n/a if (len <= IOCTL_BUFSZ) {
179n/a memcpy(buf, str, len);
180n/a buf[len] = '\0';
181n/a arg = buf;
182n/a }
183n/a else {
184n/a arg = str;
185n/a }
186n/a }
187n/a else {
188n/a if (len > IOCTL_BUFSZ) {
189n/a PyBuffer_Release(&pstr);
190n/a PyErr_SetString(PyExc_ValueError,
191n/a "ioctl string arg too long");
192n/a return NULL;
193n/a }
194n/a else {
195n/a memcpy(buf, str, len);
196n/a buf[len] = '\0';
197n/a arg = buf;
198n/a }
199n/a }
200n/a if (buf == arg) {
201n/a Py_BEGIN_ALLOW_THREADS /* think array.resize() */
202n/a ret = ioctl(fd, code, arg);
203n/a Py_END_ALLOW_THREADS
204n/a }
205n/a else {
206n/a ret = ioctl(fd, code, arg);
207n/a }
208n/a if (mutate_arg && (len <= IOCTL_BUFSZ)) {
209n/a memcpy(str, buf, len);
210n/a }
211n/a PyBuffer_Release(&pstr); /* No further access to str below this point */
212n/a if (ret < 0) {
213n/a PyErr_SetFromErrno(PyExc_IOError);
214n/a return NULL;
215n/a }
216n/a if (mutate_arg) {
217n/a return PyLong_FromLong(ret);
218n/a }
219n/a else {
220n/a return PyBytes_FromStringAndSize(buf, len);
221n/a }
222n/a }
223n/a
224n/a PyErr_Clear();
225n/a if (PyArg_Parse(ob_arg, "s*:ioctl", &pstr)) {
226n/a str = pstr.buf;
227n/a len = pstr.len;
228n/a if (len > IOCTL_BUFSZ) {
229n/a PyBuffer_Release(&pstr);
230n/a PyErr_SetString(PyExc_ValueError,
231n/a "ioctl string arg too long");
232n/a return NULL;
233n/a }
234n/a memcpy(buf, str, len);
235n/a buf[len] = '\0';
236n/a Py_BEGIN_ALLOW_THREADS
237n/a ret = ioctl(fd, code, buf);
238n/a Py_END_ALLOW_THREADS
239n/a if (ret < 0) {
240n/a PyBuffer_Release(&pstr);
241n/a PyErr_SetFromErrno(PyExc_IOError);
242n/a return NULL;
243n/a }
244n/a PyBuffer_Release(&pstr);
245n/a return PyBytes_FromStringAndSize(buf, len);
246n/a }
247n/a
248n/a PyErr_Clear();
249n/a if (!PyArg_Parse(ob_arg,
250n/a "i;ioctl requires a file or file descriptor,"
251n/a " an integer and optionally an integer or buffer argument",
252n/a &arg)) {
253n/a return NULL;
254n/a }
255n/a // Fall-through to outside the 'if' statement.
256n/a }
257n/a Py_BEGIN_ALLOW_THREADS
258n/a ret = ioctl(fd, code, arg);
259n/a Py_END_ALLOW_THREADS
260n/a if (ret < 0) {
261n/a PyErr_SetFromErrno(PyExc_IOError);
262n/a return NULL;
263n/a }
264n/a return PyLong_FromLong((long)ret);
265n/a#undef IOCTL_BUFSZ
266n/a}
267n/a
268n/a/*[clinic input]
269n/afcntl.flock
270n/a
271n/a fd: object(type='int', converter='conv_descriptor')
272n/a operation as code: int
273n/a /
274n/a
275n/aPerform the lock operation `operation` on file descriptor `fd`.
276n/a
277n/aSee the Unix manual page for flock(2) for details (On some systems, this
278n/afunction is emulated using fcntl()).
279n/a[clinic start generated code]*/
280n/a
281n/astatic PyObject *
282n/afcntl_flock_impl(PyObject *module, int fd, int code)
283n/a/*[clinic end generated code: output=84059e2b37d2fc64 input=b70a0a41ca22a8a0]*/
284n/a{
285n/a int ret;
286n/a
287n/a#ifdef HAVE_FLOCK
288n/a Py_BEGIN_ALLOW_THREADS
289n/a ret = flock(fd, code);
290n/a Py_END_ALLOW_THREADS
291n/a#else
292n/a
293n/a#ifndef LOCK_SH
294n/a#define LOCK_SH 1 /* shared lock */
295n/a#define LOCK_EX 2 /* exclusive lock */
296n/a#define LOCK_NB 4 /* don't block when locking */
297n/a#define LOCK_UN 8 /* unlock */
298n/a#endif
299n/a {
300n/a struct flock l;
301n/a if (code == LOCK_UN)
302n/a l.l_type = F_UNLCK;
303n/a else if (code & LOCK_SH)
304n/a l.l_type = F_RDLCK;
305n/a else if (code & LOCK_EX)
306n/a l.l_type = F_WRLCK;
307n/a else {
308n/a PyErr_SetString(PyExc_ValueError,
309n/a "unrecognized flock argument");
310n/a return NULL;
311n/a }
312n/a l.l_whence = l.l_start = l.l_len = 0;
313n/a Py_BEGIN_ALLOW_THREADS
314n/a ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
315n/a Py_END_ALLOW_THREADS
316n/a }
317n/a#endif /* HAVE_FLOCK */
318n/a if (ret < 0) {
319n/a PyErr_SetFromErrno(PyExc_IOError);
320n/a return NULL;
321n/a }
322n/a Py_RETURN_NONE;
323n/a}
324n/a
325n/a
326n/a/*[clinic input]
327n/afcntl.lockf
328n/a
329n/a fd: object(type='int', converter='conv_descriptor')
330n/a cmd as code: int
331n/a len as lenobj: object(c_default='NULL') = 0
332n/a start as startobj: object(c_default='NULL') = 0
333n/a whence: int = 0
334n/a /
335n/a
336n/aA wrapper around the fcntl() locking calls.
337n/a
338n/a`fd` is the file descriptor of the file to lock or unlock, and operation is one
339n/aof the following values:
340n/a
341n/a LOCK_UN - unlock
342n/a LOCK_SH - acquire a shared lock
343n/a LOCK_EX - acquire an exclusive lock
344n/a
345n/aWhen operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with
346n/aLOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the
347n/alock cannot be acquired, an OSError will be raised and the exception will
348n/ahave an errno attribute set to EACCES or EAGAIN (depending on the operating
349n/asystem -- for portability, check for either value).
350n/a
351n/a`len` is the number of bytes to lock, with the default meaning to lock to
352n/aEOF. `start` is the byte offset, relative to `whence`, to that the lock
353n/astarts. `whence` is as with fileobj.seek(), specifically:
354n/a
355n/a 0 - relative to the start of the file (SEEK_SET)
356n/a 1 - relative to the current buffer position (SEEK_CUR)
357n/a 2 - relative to the end of the file (SEEK_END)
358n/a[clinic start generated code]*/
359n/a
360n/astatic PyObject *
361n/afcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
362n/a PyObject *startobj, int whence)
363n/a/*[clinic end generated code: output=4985e7a172e7461a input=3a5dc01b04371f1a]*/
364n/a{
365n/a int ret;
366n/a
367n/a#ifndef LOCK_SH
368n/a#define LOCK_SH 1 /* shared lock */
369n/a#define LOCK_EX 2 /* exclusive lock */
370n/a#define LOCK_NB 4 /* don't block when locking */
371n/a#define LOCK_UN 8 /* unlock */
372n/a#endif /* LOCK_SH */
373n/a {
374n/a struct flock l;
375n/a if (code == LOCK_UN)
376n/a l.l_type = F_UNLCK;
377n/a else if (code & LOCK_SH)
378n/a l.l_type = F_RDLCK;
379n/a else if (code & LOCK_EX)
380n/a l.l_type = F_WRLCK;
381n/a else {
382n/a PyErr_SetString(PyExc_ValueError,
383n/a "unrecognized lockf argument");
384n/a return NULL;
385n/a }
386n/a l.l_start = l.l_len = 0;
387n/a if (startobj != NULL) {
388n/a#if !defined(HAVE_LARGEFILE_SUPPORT)
389n/a l.l_start = PyLong_AsLong(startobj);
390n/a#else
391n/a l.l_start = PyLong_Check(startobj) ?
392n/a PyLong_AsLongLong(startobj) :
393n/a PyLong_AsLong(startobj);
394n/a#endif
395n/a if (PyErr_Occurred())
396n/a return NULL;
397n/a }
398n/a if (lenobj != NULL) {
399n/a#if !defined(HAVE_LARGEFILE_SUPPORT)
400n/a l.l_len = PyLong_AsLong(lenobj);
401n/a#else
402n/a l.l_len = PyLong_Check(lenobj) ?
403n/a PyLong_AsLongLong(lenobj) :
404n/a PyLong_AsLong(lenobj);
405n/a#endif
406n/a if (PyErr_Occurred())
407n/a return NULL;
408n/a }
409n/a l.l_whence = whence;
410n/a Py_BEGIN_ALLOW_THREADS
411n/a ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l);
412n/a Py_END_ALLOW_THREADS
413n/a }
414n/a if (ret < 0) {
415n/a PyErr_SetFromErrno(PyExc_IOError);
416n/a return NULL;
417n/a }
418n/a Py_RETURN_NONE;
419n/a}
420n/a
421n/a/* List of functions */
422n/a
423n/astatic PyMethodDef fcntl_methods[] = {
424n/a FCNTL_FCNTL_METHODDEF
425n/a FCNTL_IOCTL_METHODDEF
426n/a FCNTL_FLOCK_METHODDEF
427n/a FCNTL_LOCKF_METHODDEF
428n/a {NULL, NULL} /* sentinel */
429n/a};
430n/a
431n/a
432n/aPyDoc_STRVAR(module_doc,
433n/a"This module performs file control and I/O control on file \n\
434n/adescriptors. It is an interface to the fcntl() and ioctl() Unix\n\
435n/aroutines. File descriptors can be obtained with the fileno() method of\n\
436n/aa file or socket object.");
437n/a
438n/a/* Module initialisation */
439n/a
440n/a
441n/astatic int
442n/aall_ins(PyObject* m)
443n/a{
444n/a if (PyModule_AddIntMacro(m, LOCK_SH)) return -1;
445n/a if (PyModule_AddIntMacro(m, LOCK_EX)) return -1;
446n/a if (PyModule_AddIntMacro(m, LOCK_NB)) return -1;
447n/a if (PyModule_AddIntMacro(m, LOCK_UN)) return -1;
448n/a/* GNU extensions, as of glibc 2.2.4 */
449n/a#ifdef LOCK_MAND
450n/a if (PyModule_AddIntMacro(m, LOCK_MAND)) return -1;
451n/a#endif
452n/a#ifdef LOCK_READ
453n/a if (PyModule_AddIntMacro(m, LOCK_READ)) return -1;
454n/a#endif
455n/a#ifdef LOCK_WRITE
456n/a if (PyModule_AddIntMacro(m, LOCK_WRITE)) return -1;
457n/a#endif
458n/a#ifdef LOCK_RW
459n/a if (PyModule_AddIntMacro(m, LOCK_RW)) return -1;
460n/a#endif
461n/a
462n/a#ifdef F_DUPFD
463n/a if (PyModule_AddIntMacro(m, F_DUPFD)) return -1;
464n/a#endif
465n/a#ifdef F_DUPFD_CLOEXEC
466n/a if (PyModule_AddIntMacro(m, F_DUPFD_CLOEXEC)) return -1;
467n/a#endif
468n/a#ifdef F_GETFD
469n/a if (PyModule_AddIntMacro(m, F_GETFD)) return -1;
470n/a#endif
471n/a#ifdef F_SETFD
472n/a if (PyModule_AddIntMacro(m, F_SETFD)) return -1;
473n/a#endif
474n/a#ifdef F_GETFL
475n/a if (PyModule_AddIntMacro(m, F_GETFL)) return -1;
476n/a#endif
477n/a#ifdef F_SETFL
478n/a if (PyModule_AddIntMacro(m, F_SETFL)) return -1;
479n/a#endif
480n/a#ifdef F_GETLK
481n/a if (PyModule_AddIntMacro(m, F_GETLK)) return -1;
482n/a#endif
483n/a#ifdef F_SETLK
484n/a if (PyModule_AddIntMacro(m, F_SETLK)) return -1;
485n/a#endif
486n/a#ifdef F_SETLKW
487n/a if (PyModule_AddIntMacro(m, F_SETLKW)) return -1;
488n/a#endif
489n/a#ifdef F_GETOWN
490n/a if (PyModule_AddIntMacro(m, F_GETOWN)) return -1;
491n/a#endif
492n/a#ifdef F_SETOWN
493n/a if (PyModule_AddIntMacro(m, F_SETOWN)) return -1;
494n/a#endif
495n/a#ifdef F_GETSIG
496n/a if (PyModule_AddIntMacro(m, F_GETSIG)) return -1;
497n/a#endif
498n/a#ifdef F_SETSIG
499n/a if (PyModule_AddIntMacro(m, F_SETSIG)) return -1;
500n/a#endif
501n/a#ifdef F_RDLCK
502n/a if (PyModule_AddIntMacro(m, F_RDLCK)) return -1;
503n/a#endif
504n/a#ifdef F_WRLCK
505n/a if (PyModule_AddIntMacro(m, F_WRLCK)) return -1;
506n/a#endif
507n/a#ifdef F_UNLCK
508n/a if (PyModule_AddIntMacro(m, F_UNLCK)) return -1;
509n/a#endif
510n/a/* LFS constants */
511n/a#ifdef F_GETLK64
512n/a if (PyModule_AddIntMacro(m, F_GETLK64)) return -1;
513n/a#endif
514n/a#ifdef F_SETLK64
515n/a if (PyModule_AddIntMacro(m, F_SETLK64)) return -1;
516n/a#endif
517n/a#ifdef F_SETLKW64
518n/a if (PyModule_AddIntMacro(m, F_SETLKW64)) return -1;
519n/a#endif
520n/a/* GNU extensions, as of glibc 2.2.4. */
521n/a#ifdef FASYNC
522n/a if (PyModule_AddIntMacro(m, FASYNC)) return -1;
523n/a#endif
524n/a#ifdef F_SETLEASE
525n/a if (PyModule_AddIntMacro(m, F_SETLEASE)) return -1;
526n/a#endif
527n/a#ifdef F_GETLEASE
528n/a if (PyModule_AddIntMacro(m, F_GETLEASE)) return -1;
529n/a#endif
530n/a#ifdef F_NOTIFY
531n/a if (PyModule_AddIntMacro(m, F_NOTIFY)) return -1;
532n/a#endif
533n/a/* Old BSD flock(). */
534n/a#ifdef F_EXLCK
535n/a if (PyModule_AddIntMacro(m, F_EXLCK)) return -1;
536n/a#endif
537n/a#ifdef F_SHLCK
538n/a if (PyModule_AddIntMacro(m, F_SHLCK)) return -1;
539n/a#endif
540n/a
541n/a/* OS X specifics */
542n/a#ifdef F_FULLFSYNC
543n/a if (PyModule_AddIntMacro(m, F_FULLFSYNC)) return -1;
544n/a#endif
545n/a#ifdef F_NOCACHE
546n/a if (PyModule_AddIntMacro(m, F_NOCACHE)) return -1;
547n/a#endif
548n/a
549n/a/* For F_{GET|SET}FL */
550n/a#ifdef FD_CLOEXEC
551n/a if (PyModule_AddIntMacro(m, FD_CLOEXEC)) return -1;
552n/a#endif
553n/a
554n/a/* For F_NOTIFY */
555n/a#ifdef DN_ACCESS
556n/a if (PyModule_AddIntMacro(m, DN_ACCESS)) return -1;
557n/a#endif
558n/a#ifdef DN_MODIFY
559n/a if (PyModule_AddIntMacro(m, DN_MODIFY)) return -1;
560n/a#endif
561n/a#ifdef DN_CREATE
562n/a if (PyModule_AddIntMacro(m, DN_CREATE)) return -1;
563n/a#endif
564n/a#ifdef DN_DELETE
565n/a if (PyModule_AddIntMacro(m, DN_DELETE)) return -1;
566n/a#endif
567n/a#ifdef DN_RENAME
568n/a if (PyModule_AddIntMacro(m, DN_RENAME)) return -1;
569n/a#endif
570n/a#ifdef DN_ATTRIB
571n/a if (PyModule_AddIntMacro(m, DN_ATTRIB)) return -1;
572n/a#endif
573n/a#ifdef DN_MULTISHOT
574n/a if (PyModule_AddIntMacro(m, DN_MULTISHOT)) return -1;
575n/a#endif
576n/a
577n/a#ifdef HAVE_STROPTS_H
578n/a /* Unix 98 guarantees that these are in stropts.h. */
579n/a if (PyModule_AddIntMacro(m, I_PUSH)) return -1;
580n/a if (PyModule_AddIntMacro(m, I_POP)) return -1;
581n/a if (PyModule_AddIntMacro(m, I_LOOK)) return -1;
582n/a if (PyModule_AddIntMacro(m, I_FLUSH)) return -1;
583n/a if (PyModule_AddIntMacro(m, I_FLUSHBAND)) return -1;
584n/a if (PyModule_AddIntMacro(m, I_SETSIG)) return -1;
585n/a if (PyModule_AddIntMacro(m, I_GETSIG)) return -1;
586n/a if (PyModule_AddIntMacro(m, I_FIND)) return -1;
587n/a if (PyModule_AddIntMacro(m, I_PEEK)) return -1;
588n/a if (PyModule_AddIntMacro(m, I_SRDOPT)) return -1;
589n/a if (PyModule_AddIntMacro(m, I_GRDOPT)) return -1;
590n/a if (PyModule_AddIntMacro(m, I_NREAD)) return -1;
591n/a if (PyModule_AddIntMacro(m, I_FDINSERT)) return -1;
592n/a if (PyModule_AddIntMacro(m, I_STR)) return -1;
593n/a if (PyModule_AddIntMacro(m, I_SWROPT)) return -1;
594n/a#ifdef I_GWROPT
595n/a /* despite the comment above, old-ish glibcs miss a couple... */
596n/a if (PyModule_AddIntMacro(m, I_GWROPT)) return -1;
597n/a#endif
598n/a if (PyModule_AddIntMacro(m, I_SENDFD)) return -1;
599n/a if (PyModule_AddIntMacro(m, I_RECVFD)) return -1;
600n/a if (PyModule_AddIntMacro(m, I_LIST)) return -1;
601n/a if (PyModule_AddIntMacro(m, I_ATMARK)) return -1;
602n/a if (PyModule_AddIntMacro(m, I_CKBAND)) return -1;
603n/a if (PyModule_AddIntMacro(m, I_GETBAND)) return -1;
604n/a if (PyModule_AddIntMacro(m, I_CANPUT)) return -1;
605n/a if (PyModule_AddIntMacro(m, I_SETCLTIME)) return -1;
606n/a#ifdef I_GETCLTIME
607n/a if (PyModule_AddIntMacro(m, I_GETCLTIME)) return -1;
608n/a#endif
609n/a if (PyModule_AddIntMacro(m, I_LINK)) return -1;
610n/a if (PyModule_AddIntMacro(m, I_UNLINK)) return -1;
611n/a if (PyModule_AddIntMacro(m, I_PLINK)) return -1;
612n/a if (PyModule_AddIntMacro(m, I_PUNLINK)) return -1;
613n/a#endif
614n/a
615n/a return 0;
616n/a}
617n/a
618n/a
619n/astatic struct PyModuleDef fcntlmodule = {
620n/a PyModuleDef_HEAD_INIT,
621n/a "fcntl",
622n/a module_doc,
623n/a -1,
624n/a fcntl_methods,
625n/a NULL,
626n/a NULL,
627n/a NULL,
628n/a NULL
629n/a};
630n/a
631n/aPyMODINIT_FUNC
632n/aPyInit_fcntl(void)
633n/a{
634n/a PyObject *m;
635n/a
636n/a /* Create the module and add the functions and documentation */
637n/a m = PyModule_Create(&fcntlmodule);
638n/a if (m == NULL)
639n/a return NULL;
640n/a
641n/a /* Add some symbolic constants to the module */
642n/a if (all_ins(m) < 0)
643n/a return NULL;
644n/a
645n/a return m;
646n/a}