Mercurial > cpython-lru_cache-weakref
annotate Modules/fcntlmodule.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 605fba02e195 |
| children | f527c12f2e55 |
| rev | line source |
|---|---|
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
3 The Netherlands. |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
15 permission. |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4293
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
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 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 /* fcntl module */ |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
34 #include "Python.h" |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
| 4600 | 36 #ifdef HAVE_UNISTD_H |
| 37 #include <unistd.h> | |
| 38 #endif | |
| 39 | |
| 40 #ifdef HAVE_SYS_FILE_H | |
| 41 #include <sys/file.h> | |
| 42 #endif | |
| 43 | |
|
4623
1fab981465c8
Include <sys/ioctl.h>, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
44 #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
|
45 #include <fcntl.h> |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
46 |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 /* fcntl(fd, opt, [arg]) */ |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
50 static PyObject * |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 fcntl_fcntl(self, args) |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
52 PyObject *self; /* Not used */ |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
53 PyObject *args; |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 { |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 int fd; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 int code; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 int arg; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 int ret; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 char *str; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 int len; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 char buf[1024]; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
63 if (PyArg_Parse(args, "(iis#)", &fd, &code, &str, &len)) { |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 if (len > sizeof buf) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
65 PyErr_SetString(PyExc_ValueError, |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
66 "fcntl string arg too long"); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 return NULL; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 } |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 memcpy(buf, str, len); |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
70 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
|
71 ret = fcntl(fd, code, buf); |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
72 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
|
73 if (ret < 0) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
74 PyErr_SetFromErrno(PyExc_IOError); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 return NULL; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 } |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
77 return PyString_FromStringAndSize(buf, len); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 } |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
80 PyErr_Clear(); |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
81 if (PyArg_Parse(args, "(ii)", &fd, &code)) |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 arg = 0; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 else { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
84 PyErr_Clear(); |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
85 if (!PyArg_Parse(args, "(iii)", &fd, &code, &arg)) |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 return NULL; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 } |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
88 Py_BEGIN_ALLOW_THREADS |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 ret = fcntl(fd, code, arg); |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
90 Py_END_ALLOW_THREADS |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 if (ret < 0) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
92 PyErr_SetFromErrno(PyExc_IOError); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 return NULL; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 } |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
95 return PyInt_FromLong((long)ret); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 } |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 /* ioctl(fd, opt, [arg]) */ |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
101 static PyObject * |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 fcntl_ioctl(self, args) |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
103 PyObject *self; /* Not used */ |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
104 PyObject *args; |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 { |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 int fd; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 int code; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 int arg; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 int ret; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 char *str; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 int len; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 char buf[1024]; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
114 if (PyArg_Parse(args, "(iis#)", &fd, &code, &str, &len)) { |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 if (len > sizeof buf) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
116 PyErr_SetString(PyExc_ValueError, |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
117 "ioctl string arg too long"); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 return NULL; |
|
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 memcpy(buf, str, len); |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
121 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
|
122 ret = ioctl(fd, code, buf); |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
123 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
|
124 if (ret < 0) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
125 PyErr_SetFromErrno(PyExc_IOError); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 return NULL; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 } |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
128 return PyString_FromStringAndSize(buf, len); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 } |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
131 PyErr_Clear(); |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
132 if (PyArg_Parse(args, "(ii)", &fd, &code)) |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 arg = 0; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 else { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
135 PyErr_Clear(); |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
136 if (!PyArg_Parse(args, "(iii)", &fd, &code, &arg)) |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 return NULL; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 } |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
139 Py_BEGIN_ALLOW_THREADS |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 ret = ioctl(fd, code, arg); |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
141 Py_END_ALLOW_THREADS |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 if (ret < 0) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
143 PyErr_SetFromErrno(PyExc_IOError); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 return NULL; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 } |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
146 return PyInt_FromLong((long)ret); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 } |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
| 3598 | 150 /* flock(fd, operation) */ |
| 151 | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
152 static PyObject * |
| 3598 | 153 fcntl_flock(self, args) |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
154 PyObject *self; /* Not used */ |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
155 PyObject *args; |
| 3598 | 156 { |
| 157 int fd; | |
| 158 int code; | |
| 159 int ret; | |
| 160 | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
161 if (!PyArg_Parse(args, "(ii)", &fd, &code)) |
| 3598 | 162 return NULL; |
| 163 | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
164 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
|
165 #ifdef HAVE_FLOCK |
| 3598 | 166 ret = flock(fd, code); |
|
3662
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
167 #else |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
168 |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
169 #ifndef LOCK_SH |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
170 #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
|
171 #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
|
172 #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
|
173 #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
|
174 #endif |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
175 { |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
176 struct flock l; |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 else { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
184 PyErr_SetString(PyExc_ValueError, |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
185 "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
|
186 return NULL; |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
187 } |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
188 l.l_whence = l.l_start = l.l_len = 0; |
|
399470a958c2
A fcntl implementation for systems (like Solaris) without flock() call.
Guido van Rossum <guido@python.org>
parents:
3598
diff
changeset
|
189 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); |
|
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 #endif /* HAVE_FLOCK */ |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
192 Py_END_ALLOW_THREADS |
| 3598 | 193 if (ret < 0) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
194 PyErr_SetFromErrno(PyExc_IOError); |
| 3598 | 195 return NULL; |
| 196 } | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
197 Py_INCREF(Py_None); |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
198 return Py_None; |
| 3598 | 199 } |
| 200 | |
| 4293 | 201 /* lockf(fd, operation) */ |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
202 static PyObject * |
| 4293 | 203 fcntl_lockf(self, args) |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
204 PyObject *self; /* Not used */ |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
205 PyObject *args; |
| 4293 | 206 { |
| 207 int fd, code, len = 0, start = 0, whence = 0, ret; | |
| 3598 | 208 |
| 4293 | 209 if (!PyArg_ParseTuple(args, "ii|iii", &fd, &code, &len, |
| 210 &start, &whence)) | |
| 211 return NULL; | |
| 212 | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
213 Py_BEGIN_ALLOW_THREADS |
| 4293 | 214 #ifndef LOCK_SH |
| 215 #define LOCK_SH 1 /* shared lock */ | |
| 216 #define LOCK_EX 2 /* exclusive lock */ | |
| 217 #define LOCK_NB 4 /* don't block when locking */ | |
| 218 #define LOCK_UN 8 /* unlock */ | |
| 219 #endif | |
| 220 { | |
| 221 struct flock l; | |
| 222 if (code == LOCK_UN) | |
| 223 l.l_type = F_UNLCK; | |
| 224 else if (code & LOCK_SH) | |
| 225 l.l_type = F_RDLCK; | |
| 226 else if (code & LOCK_EX) | |
| 227 l.l_type = F_WRLCK; | |
| 228 else { | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
229 PyErr_SetString(PyExc_ValueError, |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
230 "unrecognized flock argument"); |
| 4293 | 231 return NULL; |
| 232 } | |
| 233 l.l_len = len; | |
| 234 l.l_start = start; | |
| 235 l.l_whence = whence; | |
| 236 ret = fcntl(fd, (code & LOCK_NB) ? F_SETLK : F_SETLKW, &l); | |
| 237 } | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
238 Py_END_ALLOW_THREADS |
| 4293 | 239 if (ret < 0) { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
240 PyErr_SetFromErrno(PyExc_IOError); |
| 4293 | 241 return NULL; |
| 242 } | |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
243 Py_INCREF(Py_None); |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
244 return Py_None; |
| 4293 | 245 } |
| 3598 | 246 |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 /* List of functions */ |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
249 static PyMethodDef fcntl_methods[] = { |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 {"fcntl", fcntl_fcntl}, |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 {"ioctl", fcntl_ioctl}, |
| 3598 | 252 {"flock", fcntl_flock}, |
| 4293 | 253 {"lockf", fcntl_lockf, 1}, |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 {NULL, NULL} /* sentinel */ |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 }; |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 /* Module initialisation */ |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 void |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 initfcntl() |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 { |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
263 PyObject *m, *d; |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 /* Create the module and add the functions */ |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
266 m = Py_InitModule("fcntl", fcntl_methods); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 /* Add some symbolic constants to the module */ |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
269 d = PyModule_GetDict(m); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 |
|
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 /* Check for errors */ |
|
4757
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
272 if (PyErr_Occurred()) |
|
e1f1725cae6d
Grandly renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4623
diff
changeset
|
273 Py_FatalError("can't initialize module fcntl"); |
|
960
7d3a053c6765
struct: pack/unpack binary structs; fcntl: fcntl(), ioctl().
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 } |
