Debian Codegraph @

Modules/clinic/fcntlmodule.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(fcntl_fcntl__doc__,
6 "fcntl($module, fd, cmd, arg=0, /)\n"
7 "--\n"
8 "\n"
9 "Perform the operation cmd on file descriptor fd.\n"
10 "\n"
11 "The values used for cmd are operating system dependent, and are\n"
12 "available as constants in the fcntl module, using the same names as used\n"
13 "in the relevant C header files. The argument arg is optional, and\n"
14 "defaults to 0; it may be an integer, a bytes-like object or a string.\n"
15 "If arg is given as a string, it will be encoded to binary using the\n"
16 "UTF-8 encoding.\n"
17 "\n"
18 "If the arg given is an integer or if none is specified, the result value\n"
19 "is an integer corresponding to the return value of the fcntl() call in\n"
20 "the C code.\n"
21 "\n"
22 "If arg is given as a bytes-like object, the return value of fcntl() is a\n"
23 "bytes object of that length, containing the resulting value put in the\n"
24 "arg buffer by the operating system. The length of the arg buffer is not\n"
25 "allowed to exceed 1024 bytes.");
26
27 #define FCNTL_FCNTL_METHODDEF \
28 {"fcntl", (PyCFunction)(void(*)(void))fcntl_fcntl, METH_FASTCALL, fcntl_fcntl__doc__},
29
30 static PyObject *
31 fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg);
32
33 static PyObject *
34 fcntl_fcntl(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
35 {
36 PyObject *return_value = NULL;
37 int fd;
38 int code;
39 PyObject *arg = NULL;
40
41 if (nargs < 2) {
42 PyErr_Format(PyExc_TypeError, "fcntl expected at least 2 arguments, got %zd", nargs);
43 goto exit;
44 }
45 if (nargs > 3) {
46 PyErr_Format(PyExc_TypeError, "fcntl expected at most 3 arguments, got %zd", nargs);
47 goto exit;
48 }
49 fd = PyObject_AsFileDescriptor(args[0]);
50 if (fd < 0) {
51 goto exit;
52 }
53 code = PyLong_AsInt(args[1]);
54 if (code == -1 && PyErr_Occurred()) {
55 goto exit;
56 }
57 if (nargs < 3) {
58 goto skip_optional;
59 }
60 arg = args[2];
61 skip_optional:
62 return_value = fcntl_fcntl_impl(module, fd, code, arg);
63
64 exit:
65 return return_value;
66 }
67
68 PyDoc_STRVAR(fcntl_ioctl__doc__,
69 "ioctl($module, fd, request, arg=0, mutate_flag=True, /)\n"
70 "--\n"
71 "\n"
72 "Perform the operation request on file descriptor fd.\n"
73 "\n"
74 "The values used for request are operating system dependent, and are\n"
75 "available as constants in the fcntl or termios library modules, using\n"
76 "the same names as used in the relevant C header files.\n"
77 "\n"
78 "The argument arg is optional, and defaults to 0; it may be an integer, a\n"
79 "bytes-like object or a string. If arg is given as a string, it will be\n"
80 "encoded to binary using the UTF-8 encoding.\n"
81 "\n"
82 "If the arg given is an integer or if none is specified, the result value\n"
83 "is an integer corresponding to the return value of the ioctl() call in\n"
84 "the C code.\n"
85 "\n"
86 "If the argument is a mutable buffer (such as a bytearray) and the\n"
87 "mutate_flag argument is true (default) then the buffer is (in effect)\n"
88 "passed to the operating system and changes made by the OS will be\n"
89 "reflected in the contents of the buffer after the call has returned.\n"
90 "The return value is the integer returned by the ioctl() system call.\n"
91 "\n"
92 "If the argument is a mutable buffer and the mutable_flag argument is\n"
93 "false, the behavior is as if an immutable buffer had been passed.\n"
94 "\n"
95 "If the argument is an immutable buffer then a copy of the buffer is\n"
96 "passed to the operating system and the return value is a bytes object of\n"
97 "the same length containing whatever the operating system put in the\n"
98 "buffer. The length of the arg buffer in this case is not allowed to\n"
99 "exceed 1024 bytes.");
100
101 #define FCNTL_IOCTL_METHODDEF \
102 {"ioctl", (PyCFunction)(void(*)(void))fcntl_ioctl, METH_FASTCALL, fcntl_ioctl__doc__},
103
104 static PyObject *
105 fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
106 PyObject *ob_arg, int mutate_arg);
107
108 static PyObject *
109 fcntl_ioctl(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
110 {
111 PyObject *return_value = NULL;
112 int fd;
113 unsigned int code;
114 PyObject *ob_arg = NULL;
115 int mutate_arg = 1;
116
117 if (nargs < 2) {
118 PyErr_Format(PyExc_TypeError, "ioctl expected at least 2 arguments, got %zd", nargs);
119 goto exit;
120 }
121 if (nargs > 4) {
122 PyErr_Format(PyExc_TypeError, "ioctl expected at most 4 arguments, got %zd", nargs);
123 goto exit;
124 }
125 fd = PyObject_AsFileDescriptor(args[0]);
126 if (fd < 0) {
127 goto exit;
128 }
129 code = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
130 if (code == (unsigned int)-1 && PyErr_Occurred()) {
131 goto exit;
132 }
133 if (nargs < 3) {
134 goto skip_optional;
135 }
136 ob_arg = args[2];
137 if (nargs < 4) {
138 goto skip_optional;
139 }
140 mutate_arg = PyObject_IsTrue(args[3]);
141 if (mutate_arg < 0) {
142 goto exit;
143 }
144 skip_optional:
145 return_value = fcntl_ioctl_impl(module, fd, code, ob_arg, mutate_arg);
146
147 exit:
148 return return_value;
149 }
150
151 PyDoc_STRVAR(fcntl_flock__doc__,
152 "flock($module, fd, operation, /)\n"
153 "--\n"
154 "\n"
155 "Perform the lock operation on file descriptor fd.\n"
156 "\n"
157 "See the Unix manual page for flock(2) for details (On some systems, this\n"
158 "function is emulated using fcntl()).");
159
160 #define FCNTL_FLOCK_METHODDEF \
161 {"flock", (PyCFunction)(void(*)(void))fcntl_flock, METH_FASTCALL, fcntl_flock__doc__},
162
163 static PyObject *
164 fcntl_flock_impl(PyObject *module, int fd, int code);
165
166 static PyObject *
167 fcntl_flock(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
168 {
169 PyObject *return_value = NULL;
170 int fd;
171 int code;
172
173 if (nargs != 2) {
174 PyErr_Format(PyExc_TypeError, "flock expected 2 arguments, got %zd", nargs);
175 goto exit;
176 }
177 fd = PyObject_AsFileDescriptor(args[0]);
178 if (fd < 0) {
179 goto exit;
180 }
181 code = PyLong_AsInt(args[1]);
182 if (code == -1 && PyErr_Occurred()) {
183 goto exit;
184 }
185 return_value = fcntl_flock_impl(module, fd, code);
186
187 exit:
188 return return_value;
189 }
190
191 PyDoc_STRVAR(fcntl_lockf__doc__,
192 "lockf($module, fd, cmd, len=0, start=0, whence=0, /)\n"
193 "--\n"
194 "\n"
195 "A wrapper around the fcntl() locking calls.\n"
196 "\n"
197 "fd is the file descriptor of the file to lock or unlock, and operation\n"
198 "is one of the following values:\n"
199 "\n"
200 " LOCK_UN - unlock\n"
201 " LOCK_SH - acquire a shared lock\n"
202 " LOCK_EX - acquire an exclusive lock\n"
203 "\n"
204 "When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with\n"
205 "LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and\n"
206 "the lock cannot be acquired, an OSError will be raised and the exception\n"
207 "will have an errno attribute set to EACCES or EAGAIN (depending on the\n"
208 "operating system -- for portability, check for either value).\n"
209 "\n"
210 "len is the number of bytes to lock, with the default meaning to lock to\n"
211 "EOF. start is the byte offset, relative to whence, to that the lock\n"
212 "starts. whence is as with fileobj.seek(), specifically:\n"
213 "\n"
214 " 0 - relative to the start of the file (SEEK_SET)\n"
215 " 1 - relative to the current buffer position (SEEK_CUR)\n"
216 " 2 - relative to the end of the file (SEEK_END)");
217
218 #define FCNTL_LOCKF_METHODDEF \
219 {"lockf", (PyCFunction)(void(*)(void))fcntl_lockf, METH_FASTCALL, fcntl_lockf__doc__},
220
221 static PyObject *
222 fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
223 PyObject *startobj, int whence);
224
225 static PyObject *
226 fcntl_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
227 {
228 PyObject *return_value = NULL;
229 int fd;
230 int code;
231 PyObject *lenobj = NULL;
232 PyObject *startobj = NULL;
233 int whence = 0;
234
235 if (nargs < 2) {
236 PyErr_Format(PyExc_TypeError, "lockf expected at least 2 arguments, got %zd", nargs);
237 goto exit;
238 }
239 if (nargs > 5) {
240 PyErr_Format(PyExc_TypeError, "lockf expected at most 5 arguments, got %zd", nargs);
241 goto exit;
242 }
243 fd = PyObject_AsFileDescriptor(args[0]);
244 if (fd < 0) {
245 goto exit;
246 }
247 code = PyLong_AsInt(args[1]);
248 if (code == -1 && PyErr_Occurred()) {
249 goto exit;
250 }
251 if (nargs < 3) {
252 goto skip_optional;
253 }
254 lenobj = args[2];
255 if (nargs < 4) {
256 goto skip_optional;
257 }
258 startobj = args[3];
259 if (nargs < 5) {
260 goto skip_optional;
261 }
262 whence = PyLong_AsInt(args[4]);
263 if (whence == -1 && PyErr_Occurred()) {
264 goto exit;
265 }
266 skip_optional:
267 return_value = fcntl_lockf_impl(module, fd, code, lenobj, startobj, whence);
268
269 exit:
270 return return_value;
271 }
272 /*[clinic end generated code: output=d9d2cfd8f11c2c15 input=a9049054013a1b77]*/