/src/cpython/Modules/clinic/posixmodule.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_abstract.h" // _PyNumber_Index() |
10 | | #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() |
11 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
12 | | |
13 | | PyDoc_STRVAR(os_stat__doc__, |
14 | | "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n" |
15 | | "--\n" |
16 | | "\n" |
17 | | "Perform a stat system call on the given path.\n" |
18 | | "\n" |
19 | | " path\n" |
20 | | " Path to be examined; can be string, bytes, a path-like object or\n" |
21 | | " open-file-descriptor int.\n" |
22 | | " dir_fd\n" |
23 | | " If not None, it should be a file descriptor open to a directory,\n" |
24 | | " and path should be a relative string; path will then be relative to\n" |
25 | | " that directory.\n" |
26 | | " follow_symlinks\n" |
27 | | " If False, and the last element of the path is a symbolic link,\n" |
28 | | " stat will examine the symbolic link itself instead of the file\n" |
29 | | " the link points to.\n" |
30 | | "\n" |
31 | | "dir_fd and follow_symlinks may not be implemented\n" |
32 | | " on your platform. If they are unavailable, using them will raise a\n" |
33 | | " NotImplementedError.\n" |
34 | | "\n" |
35 | | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
36 | | " an open file descriptor."); |
37 | | |
38 | | #define OS_STAT_METHODDEF \ |
39 | | {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__}, |
40 | | |
41 | | static PyObject * |
42 | | os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks); |
43 | | |
44 | | static PyObject * |
45 | | os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
46 | 5.31k | { |
47 | 5.31k | PyObject *return_value = NULL; |
48 | 5.31k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
49 | | |
50 | 5.31k | #define NUM_KEYWORDS 3 |
51 | 5.31k | static struct { |
52 | 5.31k | PyGC_Head _this_is_not_used; |
53 | 5.31k | PyObject_VAR_HEAD |
54 | 5.31k | Py_hash_t ob_hash; |
55 | 5.31k | PyObject *ob_item[NUM_KEYWORDS]; |
56 | 5.31k | } _kwtuple = { |
57 | 5.31k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
58 | 5.31k | .ob_hash = -1, |
59 | 5.31k | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
60 | 5.31k | }; |
61 | 5.31k | #undef NUM_KEYWORDS |
62 | 5.31k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
63 | | |
64 | | #else // !Py_BUILD_CORE |
65 | | # define KWTUPLE NULL |
66 | | #endif // !Py_BUILD_CORE |
67 | | |
68 | 5.31k | static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; |
69 | 5.31k | static _PyArg_Parser _parser = { |
70 | 5.31k | .keywords = _keywords, |
71 | 5.31k | .fname = "stat", |
72 | 5.31k | .kwtuple = KWTUPLE, |
73 | 5.31k | }; |
74 | 5.31k | #undef KWTUPLE |
75 | 5.31k | PyObject *argsbuf[3]; |
76 | 5.31k | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
77 | 5.31k | path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1); |
78 | 5.31k | int dir_fd = DEFAULT_DIR_FD; |
79 | 5.31k | int follow_symlinks = 1; |
80 | | |
81 | 5.31k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
82 | 5.31k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
83 | 5.31k | if (!args) { |
84 | 0 | goto exit; |
85 | 0 | } |
86 | 5.31k | if (!path_converter(args[0], &path)) { |
87 | 0 | goto exit; |
88 | 0 | } |
89 | 5.31k | if (!noptargs) { |
90 | 5.31k | goto skip_optional_kwonly; |
91 | 5.31k | } |
92 | 0 | if (args[1]) { |
93 | 0 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
94 | 0 | goto exit; |
95 | 0 | } |
96 | 0 | if (!--noptargs) { |
97 | 0 | goto skip_optional_kwonly; |
98 | 0 | } |
99 | 0 | } |
100 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
101 | 0 | if (follow_symlinks < 0) { |
102 | 0 | goto exit; |
103 | 0 | } |
104 | 5.31k | skip_optional_kwonly: |
105 | 5.31k | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
106 | | |
107 | 5.31k | exit: |
108 | | /* Cleanup for path */ |
109 | 5.31k | path_cleanup(&path); |
110 | | |
111 | 5.31k | return return_value; |
112 | 5.31k | } |
113 | | |
114 | | PyDoc_STRVAR(os_lstat__doc__, |
115 | | "lstat($module, /, path, *, dir_fd=None)\n" |
116 | | "--\n" |
117 | | "\n" |
118 | | "Perform a stat system call on the given path, without following symbolic links.\n" |
119 | | "\n" |
120 | | "Like stat(), but do not follow symbolic links.\n" |
121 | | "Equivalent to stat(path, follow_symlinks=False)."); |
122 | | |
123 | | #define OS_LSTAT_METHODDEF \ |
124 | | {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__}, |
125 | | |
126 | | static PyObject * |
127 | | os_lstat_impl(PyObject *module, path_t *path, int dir_fd); |
128 | | |
129 | | static PyObject * |
130 | | os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
131 | 0 | { |
132 | 0 | PyObject *return_value = NULL; |
133 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
134 | |
|
135 | 0 | #define NUM_KEYWORDS 2 |
136 | 0 | static struct { |
137 | 0 | PyGC_Head _this_is_not_used; |
138 | 0 | PyObject_VAR_HEAD |
139 | 0 | Py_hash_t ob_hash; |
140 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
141 | 0 | } _kwtuple = { |
142 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
143 | 0 | .ob_hash = -1, |
144 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
145 | 0 | }; |
146 | 0 | #undef NUM_KEYWORDS |
147 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
148 | |
|
149 | | #else // !Py_BUILD_CORE |
150 | | # define KWTUPLE NULL |
151 | | #endif // !Py_BUILD_CORE |
152 | |
|
153 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
154 | 0 | static _PyArg_Parser _parser = { |
155 | 0 | .keywords = _keywords, |
156 | 0 | .fname = "lstat", |
157 | 0 | .kwtuple = KWTUPLE, |
158 | 0 | }; |
159 | 0 | #undef KWTUPLE |
160 | 0 | PyObject *argsbuf[2]; |
161 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
162 | 0 | path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0); |
163 | 0 | int dir_fd = DEFAULT_DIR_FD; |
164 | |
|
165 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
166 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
167 | 0 | if (!args) { |
168 | 0 | goto exit; |
169 | 0 | } |
170 | 0 | if (!path_converter(args[0], &path)) { |
171 | 0 | goto exit; |
172 | 0 | } |
173 | 0 | if (!noptargs) { |
174 | 0 | goto skip_optional_kwonly; |
175 | 0 | } |
176 | 0 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
177 | 0 | goto exit; |
178 | 0 | } |
179 | 0 | skip_optional_kwonly: |
180 | 0 | return_value = os_lstat_impl(module, &path, dir_fd); |
181 | |
|
182 | 0 | exit: |
183 | | /* Cleanup for path */ |
184 | 0 | path_cleanup(&path); |
185 | |
|
186 | 0 | return return_value; |
187 | 0 | } |
188 | | |
189 | | #if defined(HAVE_STATX) |
190 | | |
191 | | PyDoc_STRVAR(os_statx__doc__, |
192 | | "statx($module, /, path, mask, *, flags=0, dir_fd=None,\n" |
193 | | " follow_symlinks=True)\n" |
194 | | "--\n" |
195 | | "\n" |
196 | | "Perform a statx system call on the given path.\n" |
197 | | "\n" |
198 | | " path\n" |
199 | | " Path to be examined; can be string, bytes, a path-like object or\n" |
200 | | " open-file-descriptor int.\n" |
201 | | " mask\n" |
202 | | " A bitmask of STATX_* constants defining the requested information.\n" |
203 | | " flags\n" |
204 | | " A bitmask of AT_NO_AUTOMOUNT and/or AT_STATX_* flags.\n" |
205 | | " dir_fd\n" |
206 | | " If not None, it should be a file descriptor open to a directory,\n" |
207 | | " and path should be a relative string; path will then be relative to\n" |
208 | | " that directory.\n" |
209 | | " follow_symlinks\n" |
210 | | " If False, and the last element of the path is a symbolic link,\n" |
211 | | " statx will examine the symbolic link itself instead of the file\n" |
212 | | " the link points to.\n" |
213 | | "\n" |
214 | | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
215 | | " an open file descriptor."); |
216 | | |
217 | | #define OS_STATX_METHODDEF \ |
218 | | {"statx", _PyCFunction_CAST(os_statx), METH_FASTCALL|METH_KEYWORDS, os_statx__doc__}, |
219 | | |
220 | | static PyObject * |
221 | | os_statx_impl(PyObject *module, path_t *path, unsigned int mask, int flags, |
222 | | int dir_fd, int follow_symlinks); |
223 | | |
224 | | static PyObject * |
225 | | os_statx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
226 | 0 | { |
227 | 0 | PyObject *return_value = NULL; |
228 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
229 | |
|
230 | 0 | #define NUM_KEYWORDS 5 |
231 | 0 | static struct { |
232 | 0 | PyGC_Head _this_is_not_used; |
233 | 0 | PyObject_VAR_HEAD |
234 | 0 | Py_hash_t ob_hash; |
235 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
236 | 0 | } _kwtuple = { |
237 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
238 | 0 | .ob_hash = -1, |
239 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mask), &_Py_ID(flags), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
240 | 0 | }; |
241 | 0 | #undef NUM_KEYWORDS |
242 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
243 | |
|
244 | | #else // !Py_BUILD_CORE |
245 | | # define KWTUPLE NULL |
246 | | #endif // !Py_BUILD_CORE |
247 | |
|
248 | 0 | static const char * const _keywords[] = {"path", "mask", "flags", "dir_fd", "follow_symlinks", NULL}; |
249 | 0 | static _PyArg_Parser _parser = { |
250 | 0 | .keywords = _keywords, |
251 | 0 | .fname = "statx", |
252 | 0 | .kwtuple = KWTUPLE, |
253 | 0 | }; |
254 | 0 | #undef KWTUPLE |
255 | 0 | PyObject *argsbuf[5]; |
256 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
257 | 0 | path_t path = PATH_T_INITIALIZE_P("statx", "path", 0, 0, 0, 1); |
258 | 0 | unsigned int mask; |
259 | 0 | int flags = 0; |
260 | 0 | int dir_fd = DEFAULT_DIR_FD; |
261 | 0 | int follow_symlinks = 1; |
262 | |
|
263 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
264 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
265 | 0 | if (!args) { |
266 | 0 | goto exit; |
267 | 0 | } |
268 | 0 | if (!path_converter(args[0], &path)) { |
269 | 0 | goto exit; |
270 | 0 | } |
271 | 0 | { |
272 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &mask, sizeof(unsigned int), |
273 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
274 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
275 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
276 | 0 | if (_bytes < 0) { |
277 | 0 | goto exit; |
278 | 0 | } |
279 | 0 | if ((size_t)_bytes > sizeof(unsigned int)) { |
280 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
281 | 0 | "integer value out of range", 1) < 0) |
282 | 0 | { |
283 | 0 | goto exit; |
284 | 0 | } |
285 | 0 | } |
286 | 0 | } |
287 | 0 | if (!noptargs) { |
288 | 0 | goto skip_optional_kwonly; |
289 | 0 | } |
290 | 0 | if (args[2]) { |
291 | 0 | flags = PyLong_AsInt(args[2]); |
292 | 0 | if (flags == -1 && PyErr_Occurred()) { |
293 | 0 | goto exit; |
294 | 0 | } |
295 | 0 | if (!--noptargs) { |
296 | 0 | goto skip_optional_kwonly; |
297 | 0 | } |
298 | 0 | } |
299 | 0 | if (args[3]) { |
300 | 0 | if (!dir_fd_converter(args[3], &dir_fd)) { |
301 | 0 | goto exit; |
302 | 0 | } |
303 | 0 | if (!--noptargs) { |
304 | 0 | goto skip_optional_kwonly; |
305 | 0 | } |
306 | 0 | } |
307 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
308 | 0 | if (follow_symlinks < 0) { |
309 | 0 | goto exit; |
310 | 0 | } |
311 | 0 | skip_optional_kwonly: |
312 | 0 | return_value = os_statx_impl(module, &path, mask, flags, dir_fd, follow_symlinks); |
313 | |
|
314 | 0 | exit: |
315 | | /* Cleanup for path */ |
316 | 0 | path_cleanup(&path); |
317 | |
|
318 | 0 | return return_value; |
319 | 0 | } |
320 | | |
321 | | #endif /* defined(HAVE_STATX) */ |
322 | | |
323 | | PyDoc_STRVAR(os_access__doc__, |
324 | | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
325 | | " follow_symlinks=True)\n" |
326 | | "--\n" |
327 | | "\n" |
328 | | "Use the real uid/gid to test for access to a path.\n" |
329 | | "\n" |
330 | | " path\n" |
331 | | " Path to be tested; can be string, bytes, or a path-like object.\n" |
332 | | " mode\n" |
333 | | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
334 | | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
335 | | " dir_fd\n" |
336 | | " If not None, it should be a file descriptor open to a directory,\n" |
337 | | " and path should be relative; path will then be relative to that\n" |
338 | | " directory.\n" |
339 | | " effective_ids\n" |
340 | | " If True, access will use the effective uid/gid instead of\n" |
341 | | " the real uid/gid.\n" |
342 | | " follow_symlinks\n" |
343 | | " If False, and the last element of the path is a symbolic link,\n" |
344 | | " access will examine the symbolic link itself instead of the file\n" |
345 | | " the link points to.\n" |
346 | | "\n" |
347 | | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
348 | | " on your platform. If they are unavailable, using them will raise a\n" |
349 | | " NotImplementedError.\n" |
350 | | "\n" |
351 | | "Note that most operations will use the effective uid/gid, therefore this\n" |
352 | | " routine can be used in a suid/sgid environment to test if the invoking\n" |
353 | | " user has the specified access to the path."); |
354 | | |
355 | | #define OS_ACCESS_METHODDEF \ |
356 | | {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__}, |
357 | | |
358 | | static int |
359 | | os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
360 | | int effective_ids, int follow_symlinks); |
361 | | |
362 | | static PyObject * |
363 | | os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
364 | 0 | { |
365 | 0 | PyObject *return_value = NULL; |
366 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
367 | |
|
368 | 0 | #define NUM_KEYWORDS 5 |
369 | 0 | static struct { |
370 | 0 | PyGC_Head _this_is_not_used; |
371 | 0 | PyObject_VAR_HEAD |
372 | 0 | Py_hash_t ob_hash; |
373 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
374 | 0 | } _kwtuple = { |
375 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
376 | 0 | .ob_hash = -1, |
377 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), }, |
378 | 0 | }; |
379 | 0 | #undef NUM_KEYWORDS |
380 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
381 | |
|
382 | | #else // !Py_BUILD_CORE |
383 | | # define KWTUPLE NULL |
384 | | #endif // !Py_BUILD_CORE |
385 | |
|
386 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; |
387 | 0 | static _PyArg_Parser _parser = { |
388 | 0 | .keywords = _keywords, |
389 | 0 | .fname = "access", |
390 | 0 | .kwtuple = KWTUPLE, |
391 | 0 | }; |
392 | 0 | #undef KWTUPLE |
393 | 0 | PyObject *argsbuf[5]; |
394 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
395 | 0 | path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0); |
396 | 0 | int mode; |
397 | 0 | int dir_fd = DEFAULT_DIR_FD; |
398 | 0 | int effective_ids = 0; |
399 | 0 | int follow_symlinks = 1; |
400 | 0 | int _return_value; |
401 | |
|
402 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
403 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
404 | 0 | if (!args) { |
405 | 0 | goto exit; |
406 | 0 | } |
407 | 0 | if (!path_converter(args[0], &path)) { |
408 | 0 | goto exit; |
409 | 0 | } |
410 | 0 | mode = PyLong_AsInt(args[1]); |
411 | 0 | if (mode == -1 && PyErr_Occurred()) { |
412 | 0 | goto exit; |
413 | 0 | } |
414 | 0 | if (!noptargs) { |
415 | 0 | goto skip_optional_kwonly; |
416 | 0 | } |
417 | 0 | if (args[2]) { |
418 | 0 | if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
419 | 0 | goto exit; |
420 | 0 | } |
421 | 0 | if (!--noptargs) { |
422 | 0 | goto skip_optional_kwonly; |
423 | 0 | } |
424 | 0 | } |
425 | 0 | if (args[3]) { |
426 | 0 | effective_ids = PyObject_IsTrue(args[3]); |
427 | 0 | if (effective_ids < 0) { |
428 | 0 | goto exit; |
429 | 0 | } |
430 | 0 | if (!--noptargs) { |
431 | 0 | goto skip_optional_kwonly; |
432 | 0 | } |
433 | 0 | } |
434 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
435 | 0 | if (follow_symlinks < 0) { |
436 | 0 | goto exit; |
437 | 0 | } |
438 | 0 | skip_optional_kwonly: |
439 | 0 | _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); |
440 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
441 | 0 | goto exit; |
442 | 0 | } |
443 | 0 | return_value = PyBool_FromLong((long)_return_value); |
444 | |
|
445 | 0 | exit: |
446 | | /* Cleanup for path */ |
447 | 0 | path_cleanup(&path); |
448 | |
|
449 | 0 | return return_value; |
450 | 0 | } |
451 | | |
452 | | #if defined(HAVE_TTYNAME_R) |
453 | | |
454 | | PyDoc_STRVAR(os_ttyname__doc__, |
455 | | "ttyname($module, fd, /)\n" |
456 | | "--\n" |
457 | | "\n" |
458 | | "Return the name of the terminal device connected to \'fd\'.\n" |
459 | | "\n" |
460 | | " fd\n" |
461 | | " Integer file descriptor handle."); |
462 | | |
463 | | #define OS_TTYNAME_METHODDEF \ |
464 | | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
465 | | |
466 | | static PyObject * |
467 | | os_ttyname_impl(PyObject *module, int fd); |
468 | | |
469 | | static PyObject * |
470 | | os_ttyname(PyObject *module, PyObject *arg) |
471 | 0 | { |
472 | 0 | PyObject *return_value = NULL; |
473 | 0 | int fd; |
474 | |
|
475 | 0 | fd = PyLong_AsInt(arg); |
476 | 0 | if (fd == -1 && PyErr_Occurred()) { |
477 | 0 | goto exit; |
478 | 0 | } |
479 | 0 | return_value = os_ttyname_impl(module, fd); |
480 | |
|
481 | 0 | exit: |
482 | 0 | return return_value; |
483 | 0 | } |
484 | | |
485 | | #endif /* defined(HAVE_TTYNAME_R) */ |
486 | | |
487 | | #if defined(HAVE_CTERMID) |
488 | | |
489 | | PyDoc_STRVAR(os_ctermid__doc__, |
490 | | "ctermid($module, /)\n" |
491 | | "--\n" |
492 | | "\n" |
493 | | "Return the name of the controlling terminal for this process."); |
494 | | |
495 | | #define OS_CTERMID_METHODDEF \ |
496 | | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
497 | | |
498 | | static PyObject * |
499 | | os_ctermid_impl(PyObject *module); |
500 | | |
501 | | static PyObject * |
502 | | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
503 | 0 | { |
504 | 0 | return os_ctermid_impl(module); |
505 | 0 | } |
506 | | |
507 | | #endif /* defined(HAVE_CTERMID) */ |
508 | | |
509 | | PyDoc_STRVAR(os_chdir__doc__, |
510 | | "chdir($module, /, path)\n" |
511 | | "--\n" |
512 | | "\n" |
513 | | "Change the current working directory to the specified path.\n" |
514 | | "\n" |
515 | | "path may always be specified as a string.\n" |
516 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
517 | | "If this functionality is unavailable, using it raises an exception."); |
518 | | |
519 | | #define OS_CHDIR_METHODDEF \ |
520 | | {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__}, |
521 | | |
522 | | static PyObject * |
523 | | os_chdir_impl(PyObject *module, path_t *path); |
524 | | |
525 | | static PyObject * |
526 | | os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
527 | 0 | { |
528 | 0 | PyObject *return_value = NULL; |
529 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
530 | |
|
531 | 0 | #define NUM_KEYWORDS 1 |
532 | 0 | static struct { |
533 | 0 | PyGC_Head _this_is_not_used; |
534 | 0 | PyObject_VAR_HEAD |
535 | 0 | Py_hash_t ob_hash; |
536 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
537 | 0 | } _kwtuple = { |
538 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
539 | 0 | .ob_hash = -1, |
540 | 0 | .ob_item = { &_Py_ID(path), }, |
541 | 0 | }; |
542 | 0 | #undef NUM_KEYWORDS |
543 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
544 | |
|
545 | | #else // !Py_BUILD_CORE |
546 | | # define KWTUPLE NULL |
547 | | #endif // !Py_BUILD_CORE |
548 | |
|
549 | 0 | static const char * const _keywords[] = {"path", NULL}; |
550 | 0 | static _PyArg_Parser _parser = { |
551 | 0 | .keywords = _keywords, |
552 | 0 | .fname = "chdir", |
553 | 0 | .kwtuple = KWTUPLE, |
554 | 0 | }; |
555 | 0 | #undef KWTUPLE |
556 | 0 | PyObject *argsbuf[1]; |
557 | 0 | path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR); |
558 | |
|
559 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
560 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
561 | 0 | if (!args) { |
562 | 0 | goto exit; |
563 | 0 | } |
564 | 0 | if (!path_converter(args[0], &path)) { |
565 | 0 | goto exit; |
566 | 0 | } |
567 | 0 | return_value = os_chdir_impl(module, &path); |
568 | |
|
569 | 0 | exit: |
570 | | /* Cleanup for path */ |
571 | 0 | path_cleanup(&path); |
572 | |
|
573 | 0 | return return_value; |
574 | 0 | } |
575 | | |
576 | | #if defined(HAVE_FCHDIR) |
577 | | |
578 | | PyDoc_STRVAR(os_fchdir__doc__, |
579 | | "fchdir($module, /, fd)\n" |
580 | | "--\n" |
581 | | "\n" |
582 | | "Change to the directory of the given file descriptor.\n" |
583 | | "\n" |
584 | | "fd must be opened on a directory, not a file.\n" |
585 | | "Equivalent to os.chdir(fd)."); |
586 | | |
587 | | #define OS_FCHDIR_METHODDEF \ |
588 | | {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__}, |
589 | | |
590 | | static PyObject * |
591 | | os_fchdir_impl(PyObject *module, int fd); |
592 | | |
593 | | static PyObject * |
594 | | os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
595 | 0 | { |
596 | 0 | PyObject *return_value = NULL; |
597 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
598 | |
|
599 | 0 | #define NUM_KEYWORDS 1 |
600 | 0 | static struct { |
601 | 0 | PyGC_Head _this_is_not_used; |
602 | 0 | PyObject_VAR_HEAD |
603 | 0 | Py_hash_t ob_hash; |
604 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
605 | 0 | } _kwtuple = { |
606 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
607 | 0 | .ob_hash = -1, |
608 | 0 | .ob_item = { &_Py_ID(fd), }, |
609 | 0 | }; |
610 | 0 | #undef NUM_KEYWORDS |
611 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
612 | |
|
613 | | #else // !Py_BUILD_CORE |
614 | | # define KWTUPLE NULL |
615 | | #endif // !Py_BUILD_CORE |
616 | |
|
617 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
618 | 0 | static _PyArg_Parser _parser = { |
619 | 0 | .keywords = _keywords, |
620 | 0 | .fname = "fchdir", |
621 | 0 | .kwtuple = KWTUPLE, |
622 | 0 | }; |
623 | 0 | #undef KWTUPLE |
624 | 0 | PyObject *argsbuf[1]; |
625 | 0 | int fd; |
626 | |
|
627 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
628 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
629 | 0 | if (!args) { |
630 | 0 | goto exit; |
631 | 0 | } |
632 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
633 | 0 | if (fd < 0) { |
634 | 0 | goto exit; |
635 | 0 | } |
636 | 0 | return_value = os_fchdir_impl(module, fd); |
637 | |
|
638 | 0 | exit: |
639 | 0 | return return_value; |
640 | 0 | } |
641 | | |
642 | | #endif /* defined(HAVE_FCHDIR) */ |
643 | | |
644 | | PyDoc_STRVAR(os_chmod__doc__, |
645 | | "chmod($module, /, path, mode, *, dir_fd=None,\n" |
646 | | " follow_symlinks=(os.name != \'nt\'))\n" |
647 | | "--\n" |
648 | | "\n" |
649 | | "Change the access permissions of a file.\n" |
650 | | "\n" |
651 | | " path\n" |
652 | | " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n" |
653 | | " On some platforms, path may also be specified as an open file descriptor.\n" |
654 | | " If this functionality is unavailable, using it raises an exception.\n" |
655 | | " mode\n" |
656 | | " Operating-system mode bitfield.\n" |
657 | | " Be careful when using number literals for *mode*. The conventional UNIX notation for\n" |
658 | | " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n" |
659 | | " Python.\n" |
660 | | " dir_fd\n" |
661 | | " If not None, it should be a file descriptor open to a directory,\n" |
662 | | " and path should be relative; path will then be relative to that\n" |
663 | | " directory.\n" |
664 | | " follow_symlinks\n" |
665 | | " If False, and the last element of the path is a symbolic link,\n" |
666 | | " chmod will modify the symbolic link itself instead of the file\n" |
667 | | " the link points to.\n" |
668 | | "\n" |
669 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
670 | | " an open file descriptor.\n" |
671 | | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
672 | | " If they are unavailable, using them will raise a NotImplementedError."); |
673 | | |
674 | | #define OS_CHMOD_METHODDEF \ |
675 | | {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__}, |
676 | | |
677 | | static PyObject * |
678 | | os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
679 | | int follow_symlinks); |
680 | | |
681 | | static PyObject * |
682 | | os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
683 | 0 | { |
684 | 0 | PyObject *return_value = NULL; |
685 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
686 | |
|
687 | 0 | #define NUM_KEYWORDS 4 |
688 | 0 | static struct { |
689 | 0 | PyGC_Head _this_is_not_used; |
690 | 0 | PyObject_VAR_HEAD |
691 | 0 | Py_hash_t ob_hash; |
692 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
693 | 0 | } _kwtuple = { |
694 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
695 | 0 | .ob_hash = -1, |
696 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
697 | 0 | }; |
698 | 0 | #undef NUM_KEYWORDS |
699 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
700 | |
|
701 | | #else // !Py_BUILD_CORE |
702 | | # define KWTUPLE NULL |
703 | | #endif // !Py_BUILD_CORE |
704 | |
|
705 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; |
706 | 0 | static _PyArg_Parser _parser = { |
707 | 0 | .keywords = _keywords, |
708 | 0 | .fname = "chmod", |
709 | 0 | .kwtuple = KWTUPLE, |
710 | 0 | }; |
711 | 0 | #undef KWTUPLE |
712 | 0 | PyObject *argsbuf[4]; |
713 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
714 | 0 | path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD); |
715 | 0 | int mode; |
716 | 0 | int dir_fd = DEFAULT_DIR_FD; |
717 | 0 | int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS; |
718 | |
|
719 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
720 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
721 | 0 | if (!args) { |
722 | 0 | goto exit; |
723 | 0 | } |
724 | 0 | if (!path_converter(args[0], &path)) { |
725 | 0 | goto exit; |
726 | 0 | } |
727 | 0 | mode = PyLong_AsInt(args[1]); |
728 | 0 | if (mode == -1 && PyErr_Occurred()) { |
729 | 0 | goto exit; |
730 | 0 | } |
731 | 0 | if (!noptargs) { |
732 | 0 | goto skip_optional_kwonly; |
733 | 0 | } |
734 | 0 | if (args[2]) { |
735 | 0 | if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
736 | 0 | goto exit; |
737 | 0 | } |
738 | 0 | if (!--noptargs) { |
739 | 0 | goto skip_optional_kwonly; |
740 | 0 | } |
741 | 0 | } |
742 | 0 | follow_symlinks = PyObject_IsTrue(args[3]); |
743 | 0 | if (follow_symlinks < 0) { |
744 | 0 | goto exit; |
745 | 0 | } |
746 | 0 | skip_optional_kwonly: |
747 | 0 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
748 | |
|
749 | 0 | exit: |
750 | | /* Cleanup for path */ |
751 | 0 | path_cleanup(&path); |
752 | |
|
753 | 0 | return return_value; |
754 | 0 | } |
755 | | |
756 | | #if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) |
757 | | |
758 | | PyDoc_STRVAR(os_fchmod__doc__, |
759 | | "fchmod($module, /, fd, mode)\n" |
760 | | "--\n" |
761 | | "\n" |
762 | | "Change the access permissions of the file given by file descriptor fd.\n" |
763 | | "\n" |
764 | | " fd\n" |
765 | | " The file descriptor of the file to be modified.\n" |
766 | | " mode\n" |
767 | | " Operating-system mode bitfield.\n" |
768 | | " Be careful when using number literals for *mode*. The conventional UNIX notation for\n" |
769 | | " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n" |
770 | | " Python.\n" |
771 | | "\n" |
772 | | "Equivalent to os.chmod(fd, mode)."); |
773 | | |
774 | | #define OS_FCHMOD_METHODDEF \ |
775 | | {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__}, |
776 | | |
777 | | static PyObject * |
778 | | os_fchmod_impl(PyObject *module, int fd, int mode); |
779 | | |
780 | | static PyObject * |
781 | | os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
782 | 0 | { |
783 | 0 | PyObject *return_value = NULL; |
784 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
785 | |
|
786 | 0 | #define NUM_KEYWORDS 2 |
787 | 0 | static struct { |
788 | 0 | PyGC_Head _this_is_not_used; |
789 | 0 | PyObject_VAR_HEAD |
790 | 0 | Py_hash_t ob_hash; |
791 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
792 | 0 | } _kwtuple = { |
793 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
794 | 0 | .ob_hash = -1, |
795 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(mode), }, |
796 | 0 | }; |
797 | 0 | #undef NUM_KEYWORDS |
798 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
799 | |
|
800 | | #else // !Py_BUILD_CORE |
801 | | # define KWTUPLE NULL |
802 | | #endif // !Py_BUILD_CORE |
803 | |
|
804 | 0 | static const char * const _keywords[] = {"fd", "mode", NULL}; |
805 | 0 | static _PyArg_Parser _parser = { |
806 | 0 | .keywords = _keywords, |
807 | 0 | .fname = "fchmod", |
808 | 0 | .kwtuple = KWTUPLE, |
809 | 0 | }; |
810 | 0 | #undef KWTUPLE |
811 | 0 | PyObject *argsbuf[2]; |
812 | 0 | int fd; |
813 | 0 | int mode; |
814 | |
|
815 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
816 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
817 | 0 | if (!args) { |
818 | 0 | goto exit; |
819 | 0 | } |
820 | 0 | fd = PyLong_AsInt(args[0]); |
821 | 0 | if (fd == -1 && PyErr_Occurred()) { |
822 | 0 | goto exit; |
823 | 0 | } |
824 | 0 | mode = PyLong_AsInt(args[1]); |
825 | 0 | if (mode == -1 && PyErr_Occurred()) { |
826 | 0 | goto exit; |
827 | 0 | } |
828 | 0 | return_value = os_fchmod_impl(module, fd, mode); |
829 | |
|
830 | 0 | exit: |
831 | 0 | return return_value; |
832 | 0 | } |
833 | | |
834 | | #endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */ |
835 | | |
836 | | #if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) |
837 | | |
838 | | PyDoc_STRVAR(os_lchmod__doc__, |
839 | | "lchmod($module, /, path, mode)\n" |
840 | | "--\n" |
841 | | "\n" |
842 | | "Change the access permissions of a file, without following symbolic links.\n" |
843 | | "\n" |
844 | | "If path is a symlink, this affects the link itself rather than the target.\n" |
845 | | "Equivalent to chmod(path, mode, follow_symlinks=False).\""); |
846 | | |
847 | | #define OS_LCHMOD_METHODDEF \ |
848 | | {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__}, |
849 | | |
850 | | static PyObject * |
851 | | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
852 | | |
853 | | static PyObject * |
854 | | os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
855 | | { |
856 | | PyObject *return_value = NULL; |
857 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
858 | | |
859 | | #define NUM_KEYWORDS 2 |
860 | | static struct { |
861 | | PyGC_Head _this_is_not_used; |
862 | | PyObject_VAR_HEAD |
863 | | Py_hash_t ob_hash; |
864 | | PyObject *ob_item[NUM_KEYWORDS]; |
865 | | } _kwtuple = { |
866 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
867 | | .ob_hash = -1, |
868 | | .ob_item = { &_Py_ID(path), &_Py_ID(mode), }, |
869 | | }; |
870 | | #undef NUM_KEYWORDS |
871 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
872 | | |
873 | | #else // !Py_BUILD_CORE |
874 | | # define KWTUPLE NULL |
875 | | #endif // !Py_BUILD_CORE |
876 | | |
877 | | static const char * const _keywords[] = {"path", "mode", NULL}; |
878 | | static _PyArg_Parser _parser = { |
879 | | .keywords = _keywords, |
880 | | .fname = "lchmod", |
881 | | .kwtuple = KWTUPLE, |
882 | | }; |
883 | | #undef KWTUPLE |
884 | | PyObject *argsbuf[2]; |
885 | | path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0); |
886 | | int mode; |
887 | | |
888 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
889 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
890 | | if (!args) { |
891 | | goto exit; |
892 | | } |
893 | | if (!path_converter(args[0], &path)) { |
894 | | goto exit; |
895 | | } |
896 | | mode = PyLong_AsInt(args[1]); |
897 | | if (mode == -1 && PyErr_Occurred()) { |
898 | | goto exit; |
899 | | } |
900 | | return_value = os_lchmod_impl(module, &path, mode); |
901 | | |
902 | | exit: |
903 | | /* Cleanup for path */ |
904 | | path_cleanup(&path); |
905 | | |
906 | | return return_value; |
907 | | } |
908 | | |
909 | | #endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */ |
910 | | |
911 | | #if defined(HAVE_CHFLAGS) |
912 | | |
913 | | PyDoc_STRVAR(os_chflags__doc__, |
914 | | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
915 | | "--\n" |
916 | | "\n" |
917 | | "Set file flags.\n" |
918 | | "\n" |
919 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
920 | | " link, chflags will change flags on the symbolic link itself instead of the\n" |
921 | | " file the link points to.\n" |
922 | | "follow_symlinks may not be implemented on your platform. If it is\n" |
923 | | "unavailable, using it will raise a NotImplementedError."); |
924 | | |
925 | | #define OS_CHFLAGS_METHODDEF \ |
926 | | {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__}, |
927 | | |
928 | | static PyObject * |
929 | | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
930 | | int follow_symlinks); |
931 | | |
932 | | static PyObject * |
933 | | os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
934 | | { |
935 | | PyObject *return_value = NULL; |
936 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
937 | | |
938 | | #define NUM_KEYWORDS 3 |
939 | | static struct { |
940 | | PyGC_Head _this_is_not_used; |
941 | | PyObject_VAR_HEAD |
942 | | Py_hash_t ob_hash; |
943 | | PyObject *ob_item[NUM_KEYWORDS]; |
944 | | } _kwtuple = { |
945 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
946 | | .ob_hash = -1, |
947 | | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
948 | | }; |
949 | | #undef NUM_KEYWORDS |
950 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
951 | | |
952 | | #else // !Py_BUILD_CORE |
953 | | # define KWTUPLE NULL |
954 | | #endif // !Py_BUILD_CORE |
955 | | |
956 | | static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL}; |
957 | | static _PyArg_Parser _parser = { |
958 | | .keywords = _keywords, |
959 | | .fname = "chflags", |
960 | | .kwtuple = KWTUPLE, |
961 | | }; |
962 | | #undef KWTUPLE |
963 | | PyObject *argsbuf[3]; |
964 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
965 | | path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0); |
966 | | unsigned long flags; |
967 | | int follow_symlinks = 1; |
968 | | |
969 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
970 | | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
971 | | if (!args) { |
972 | | goto exit; |
973 | | } |
974 | | if (!path_converter(args[0], &path)) { |
975 | | goto exit; |
976 | | } |
977 | | if (!PyIndex_Check(args[1])) { |
978 | | _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]); |
979 | | goto exit; |
980 | | } |
981 | | { |
982 | | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long), |
983 | | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
984 | | Py_ASNATIVEBYTES_ALLOW_INDEX | |
985 | | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
986 | | if (_bytes < 0) { |
987 | | goto exit; |
988 | | } |
989 | | if ((size_t)_bytes > sizeof(unsigned long)) { |
990 | | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
991 | | "integer value out of range", 1) < 0) |
992 | | { |
993 | | goto exit; |
994 | | } |
995 | | } |
996 | | } |
997 | | if (!noptargs) { |
998 | | goto skip_optional_pos; |
999 | | } |
1000 | | follow_symlinks = PyObject_IsTrue(args[2]); |
1001 | | if (follow_symlinks < 0) { |
1002 | | goto exit; |
1003 | | } |
1004 | | skip_optional_pos: |
1005 | | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
1006 | | |
1007 | | exit: |
1008 | | /* Cleanup for path */ |
1009 | | path_cleanup(&path); |
1010 | | |
1011 | | return return_value; |
1012 | | } |
1013 | | |
1014 | | #endif /* defined(HAVE_CHFLAGS) */ |
1015 | | |
1016 | | #if defined(HAVE_LCHFLAGS) |
1017 | | |
1018 | | PyDoc_STRVAR(os_lchflags__doc__, |
1019 | | "lchflags($module, /, path, flags)\n" |
1020 | | "--\n" |
1021 | | "\n" |
1022 | | "Set file flags.\n" |
1023 | | "\n" |
1024 | | "This function will not follow symbolic links.\n" |
1025 | | "Equivalent to chflags(path, flags, follow_symlinks=False)."); |
1026 | | |
1027 | | #define OS_LCHFLAGS_METHODDEF \ |
1028 | | {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__}, |
1029 | | |
1030 | | static PyObject * |
1031 | | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
1032 | | |
1033 | | static PyObject * |
1034 | | os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1035 | | { |
1036 | | PyObject *return_value = NULL; |
1037 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1038 | | |
1039 | | #define NUM_KEYWORDS 2 |
1040 | | static struct { |
1041 | | PyGC_Head _this_is_not_used; |
1042 | | PyObject_VAR_HEAD |
1043 | | Py_hash_t ob_hash; |
1044 | | PyObject *ob_item[NUM_KEYWORDS]; |
1045 | | } _kwtuple = { |
1046 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1047 | | .ob_hash = -1, |
1048 | | .ob_item = { &_Py_ID(path), &_Py_ID(flags), }, |
1049 | | }; |
1050 | | #undef NUM_KEYWORDS |
1051 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1052 | | |
1053 | | #else // !Py_BUILD_CORE |
1054 | | # define KWTUPLE NULL |
1055 | | #endif // !Py_BUILD_CORE |
1056 | | |
1057 | | static const char * const _keywords[] = {"path", "flags", NULL}; |
1058 | | static _PyArg_Parser _parser = { |
1059 | | .keywords = _keywords, |
1060 | | .fname = "lchflags", |
1061 | | .kwtuple = KWTUPLE, |
1062 | | }; |
1063 | | #undef KWTUPLE |
1064 | | PyObject *argsbuf[2]; |
1065 | | path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0); |
1066 | | unsigned long flags; |
1067 | | |
1068 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1069 | | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1070 | | if (!args) { |
1071 | | goto exit; |
1072 | | } |
1073 | | if (!path_converter(args[0], &path)) { |
1074 | | goto exit; |
1075 | | } |
1076 | | if (!PyIndex_Check(args[1])) { |
1077 | | _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]); |
1078 | | goto exit; |
1079 | | } |
1080 | | { |
1081 | | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned long), |
1082 | | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
1083 | | Py_ASNATIVEBYTES_ALLOW_INDEX | |
1084 | | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
1085 | | if (_bytes < 0) { |
1086 | | goto exit; |
1087 | | } |
1088 | | if ((size_t)_bytes > sizeof(unsigned long)) { |
1089 | | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
1090 | | "integer value out of range", 1) < 0) |
1091 | | { |
1092 | | goto exit; |
1093 | | } |
1094 | | } |
1095 | | } |
1096 | | return_value = os_lchflags_impl(module, &path, flags); |
1097 | | |
1098 | | exit: |
1099 | | /* Cleanup for path */ |
1100 | | path_cleanup(&path); |
1101 | | |
1102 | | return return_value; |
1103 | | } |
1104 | | |
1105 | | #endif /* defined(HAVE_LCHFLAGS) */ |
1106 | | |
1107 | | #if defined(HAVE_CHROOT) |
1108 | | |
1109 | | PyDoc_STRVAR(os_chroot__doc__, |
1110 | | "chroot($module, /, path)\n" |
1111 | | "--\n" |
1112 | | "\n" |
1113 | | "Change root directory to path."); |
1114 | | |
1115 | | #define OS_CHROOT_METHODDEF \ |
1116 | | {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__}, |
1117 | | |
1118 | | static PyObject * |
1119 | | os_chroot_impl(PyObject *module, path_t *path); |
1120 | | |
1121 | | static PyObject * |
1122 | | os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1123 | 0 | { |
1124 | 0 | PyObject *return_value = NULL; |
1125 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1126 | |
|
1127 | 0 | #define NUM_KEYWORDS 1 |
1128 | 0 | static struct { |
1129 | 0 | PyGC_Head _this_is_not_used; |
1130 | 0 | PyObject_VAR_HEAD |
1131 | 0 | Py_hash_t ob_hash; |
1132 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1133 | 0 | } _kwtuple = { |
1134 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1135 | 0 | .ob_hash = -1, |
1136 | 0 | .ob_item = { &_Py_ID(path), }, |
1137 | 0 | }; |
1138 | 0 | #undef NUM_KEYWORDS |
1139 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1140 | |
|
1141 | | #else // !Py_BUILD_CORE |
1142 | | # define KWTUPLE NULL |
1143 | | #endif // !Py_BUILD_CORE |
1144 | |
|
1145 | 0 | static const char * const _keywords[] = {"path", NULL}; |
1146 | 0 | static _PyArg_Parser _parser = { |
1147 | 0 | .keywords = _keywords, |
1148 | 0 | .fname = "chroot", |
1149 | 0 | .kwtuple = KWTUPLE, |
1150 | 0 | }; |
1151 | 0 | #undef KWTUPLE |
1152 | 0 | PyObject *argsbuf[1]; |
1153 | 0 | path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0); |
1154 | |
|
1155 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1156 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1157 | 0 | if (!args) { |
1158 | 0 | goto exit; |
1159 | 0 | } |
1160 | 0 | if (!path_converter(args[0], &path)) { |
1161 | 0 | goto exit; |
1162 | 0 | } |
1163 | 0 | return_value = os_chroot_impl(module, &path); |
1164 | |
|
1165 | 0 | exit: |
1166 | | /* Cleanup for path */ |
1167 | 0 | path_cleanup(&path); |
1168 | |
|
1169 | 0 | return return_value; |
1170 | 0 | } |
1171 | | |
1172 | | #endif /* defined(HAVE_CHROOT) */ |
1173 | | |
1174 | | #if defined(HAVE_FSYNC) |
1175 | | |
1176 | | PyDoc_STRVAR(os_fsync__doc__, |
1177 | | "fsync($module, /, fd)\n" |
1178 | | "--\n" |
1179 | | "\n" |
1180 | | "Force write of fd to disk."); |
1181 | | |
1182 | | #define OS_FSYNC_METHODDEF \ |
1183 | | {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__}, |
1184 | | |
1185 | | static PyObject * |
1186 | | os_fsync_impl(PyObject *module, int fd); |
1187 | | |
1188 | | static PyObject * |
1189 | | os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1190 | 0 | { |
1191 | 0 | PyObject *return_value = NULL; |
1192 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1193 | |
|
1194 | 0 | #define NUM_KEYWORDS 1 |
1195 | 0 | static struct { |
1196 | 0 | PyGC_Head _this_is_not_used; |
1197 | 0 | PyObject_VAR_HEAD |
1198 | 0 | Py_hash_t ob_hash; |
1199 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1200 | 0 | } _kwtuple = { |
1201 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1202 | 0 | .ob_hash = -1, |
1203 | 0 | .ob_item = { &_Py_ID(fd), }, |
1204 | 0 | }; |
1205 | 0 | #undef NUM_KEYWORDS |
1206 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1207 | |
|
1208 | | #else // !Py_BUILD_CORE |
1209 | | # define KWTUPLE NULL |
1210 | | #endif // !Py_BUILD_CORE |
1211 | |
|
1212 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1213 | 0 | static _PyArg_Parser _parser = { |
1214 | 0 | .keywords = _keywords, |
1215 | 0 | .fname = "fsync", |
1216 | 0 | .kwtuple = KWTUPLE, |
1217 | 0 | }; |
1218 | 0 | #undef KWTUPLE |
1219 | 0 | PyObject *argsbuf[1]; |
1220 | 0 | int fd; |
1221 | |
|
1222 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1223 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1224 | 0 | if (!args) { |
1225 | 0 | goto exit; |
1226 | 0 | } |
1227 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1228 | 0 | if (fd < 0) { |
1229 | 0 | goto exit; |
1230 | 0 | } |
1231 | 0 | return_value = os_fsync_impl(module, fd); |
1232 | |
|
1233 | 0 | exit: |
1234 | 0 | return return_value; |
1235 | 0 | } |
1236 | | |
1237 | | #endif /* defined(HAVE_FSYNC) */ |
1238 | | |
1239 | | #if defined(HAVE_SYNC) |
1240 | | |
1241 | | PyDoc_STRVAR(os_sync__doc__, |
1242 | | "sync($module, /)\n" |
1243 | | "--\n" |
1244 | | "\n" |
1245 | | "Force write of everything to disk."); |
1246 | | |
1247 | | #define OS_SYNC_METHODDEF \ |
1248 | | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
1249 | | |
1250 | | static PyObject * |
1251 | | os_sync_impl(PyObject *module); |
1252 | | |
1253 | | static PyObject * |
1254 | | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1255 | 0 | { |
1256 | 0 | return os_sync_impl(module); |
1257 | 0 | } |
1258 | | |
1259 | | #endif /* defined(HAVE_SYNC) */ |
1260 | | |
1261 | | #if defined(HAVE_FDATASYNC) |
1262 | | |
1263 | | PyDoc_STRVAR(os_fdatasync__doc__, |
1264 | | "fdatasync($module, /, fd)\n" |
1265 | | "--\n" |
1266 | | "\n" |
1267 | | "Force write of fd to disk without forcing update of metadata."); |
1268 | | |
1269 | | #define OS_FDATASYNC_METHODDEF \ |
1270 | | {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__}, |
1271 | | |
1272 | | static PyObject * |
1273 | | os_fdatasync_impl(PyObject *module, int fd); |
1274 | | |
1275 | | static PyObject * |
1276 | | os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1277 | 0 | { |
1278 | 0 | PyObject *return_value = NULL; |
1279 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1280 | |
|
1281 | 0 | #define NUM_KEYWORDS 1 |
1282 | 0 | static struct { |
1283 | 0 | PyGC_Head _this_is_not_used; |
1284 | 0 | PyObject_VAR_HEAD |
1285 | 0 | Py_hash_t ob_hash; |
1286 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1287 | 0 | } _kwtuple = { |
1288 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1289 | 0 | .ob_hash = -1, |
1290 | 0 | .ob_item = { &_Py_ID(fd), }, |
1291 | 0 | }; |
1292 | 0 | #undef NUM_KEYWORDS |
1293 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1294 | |
|
1295 | | #else // !Py_BUILD_CORE |
1296 | | # define KWTUPLE NULL |
1297 | | #endif // !Py_BUILD_CORE |
1298 | |
|
1299 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
1300 | 0 | static _PyArg_Parser _parser = { |
1301 | 0 | .keywords = _keywords, |
1302 | 0 | .fname = "fdatasync", |
1303 | 0 | .kwtuple = KWTUPLE, |
1304 | 0 | }; |
1305 | 0 | #undef KWTUPLE |
1306 | 0 | PyObject *argsbuf[1]; |
1307 | 0 | int fd; |
1308 | |
|
1309 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1310 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1311 | 0 | if (!args) { |
1312 | 0 | goto exit; |
1313 | 0 | } |
1314 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
1315 | 0 | if (fd < 0) { |
1316 | 0 | goto exit; |
1317 | 0 | } |
1318 | 0 | return_value = os_fdatasync_impl(module, fd); |
1319 | |
|
1320 | 0 | exit: |
1321 | 0 | return return_value; |
1322 | 0 | } |
1323 | | |
1324 | | #endif /* defined(HAVE_FDATASYNC) */ |
1325 | | |
1326 | | #if defined(HAVE_CHOWN) |
1327 | | |
1328 | | PyDoc_STRVAR(os_chown__doc__, |
1329 | | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
1330 | | "--\n" |
1331 | | "\n" |
1332 | | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
1333 | | "\n" |
1334 | | " path\n" |
1335 | | " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n" |
1336 | | " dir_fd\n" |
1337 | | " If not None, it should be a file descriptor open to a directory,\n" |
1338 | | " and path should be relative; path will then be relative to that\n" |
1339 | | " directory.\n" |
1340 | | " follow_symlinks\n" |
1341 | | " If False, and the last element of the path is a symbolic link,\n" |
1342 | | " stat will examine the symbolic link itself instead of the file\n" |
1343 | | " the link points to.\n" |
1344 | | "\n" |
1345 | | "path may always be specified as a string.\n" |
1346 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
1347 | | " If this functionality is unavailable, using it raises an exception.\n" |
1348 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1349 | | " and path should be relative; path will then be relative to that directory.\n" |
1350 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
1351 | | " link, chown will modify the symbolic link itself instead of the file the\n" |
1352 | | " link points to.\n" |
1353 | | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
1354 | | " an open file descriptor.\n" |
1355 | | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
1356 | | " If they are unavailable, using them will raise a NotImplementedError."); |
1357 | | |
1358 | | #define OS_CHOWN_METHODDEF \ |
1359 | | {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__}, |
1360 | | |
1361 | | static PyObject * |
1362 | | os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid, |
1363 | | int dir_fd, int follow_symlinks); |
1364 | | |
1365 | | static PyObject * |
1366 | | os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1367 | 0 | { |
1368 | 0 | PyObject *return_value = NULL; |
1369 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1370 | |
|
1371 | 0 | #define NUM_KEYWORDS 5 |
1372 | 0 | static struct { |
1373 | 0 | PyGC_Head _this_is_not_used; |
1374 | 0 | PyObject_VAR_HEAD |
1375 | 0 | Py_hash_t ob_hash; |
1376 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1377 | 0 | } _kwtuple = { |
1378 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1379 | 0 | .ob_hash = -1, |
1380 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
1381 | 0 | }; |
1382 | 0 | #undef NUM_KEYWORDS |
1383 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1384 | |
|
1385 | | #else // !Py_BUILD_CORE |
1386 | | # define KWTUPLE NULL |
1387 | | #endif // !Py_BUILD_CORE |
1388 | |
|
1389 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; |
1390 | 0 | static _PyArg_Parser _parser = { |
1391 | 0 | .keywords = _keywords, |
1392 | 0 | .fname = "chown", |
1393 | 0 | .kwtuple = KWTUPLE, |
1394 | 0 | }; |
1395 | 0 | #undef KWTUPLE |
1396 | 0 | PyObject *argsbuf[5]; |
1397 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
1398 | 0 | path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN); |
1399 | 0 | uid_t uid; |
1400 | 0 | gid_t gid; |
1401 | 0 | int dir_fd = DEFAULT_DIR_FD; |
1402 | 0 | int follow_symlinks = 1; |
1403 | |
|
1404 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1405 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1406 | 0 | if (!args) { |
1407 | 0 | goto exit; |
1408 | 0 | } |
1409 | 0 | if (!path_converter(args[0], &path)) { |
1410 | 0 | goto exit; |
1411 | 0 | } |
1412 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1413 | 0 | goto exit; |
1414 | 0 | } |
1415 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1416 | 0 | goto exit; |
1417 | 0 | } |
1418 | 0 | if (!noptargs) { |
1419 | 0 | goto skip_optional_kwonly; |
1420 | 0 | } |
1421 | 0 | if (args[3]) { |
1422 | 0 | if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
1423 | 0 | goto exit; |
1424 | 0 | } |
1425 | 0 | if (!--noptargs) { |
1426 | 0 | goto skip_optional_kwonly; |
1427 | 0 | } |
1428 | 0 | } |
1429 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1430 | 0 | if (follow_symlinks < 0) { |
1431 | 0 | goto exit; |
1432 | 0 | } |
1433 | 0 | skip_optional_kwonly: |
1434 | 0 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
1435 | |
|
1436 | 0 | exit: |
1437 | | /* Cleanup for path */ |
1438 | 0 | path_cleanup(&path); |
1439 | |
|
1440 | 0 | return return_value; |
1441 | 0 | } |
1442 | | |
1443 | | #endif /* defined(HAVE_CHOWN) */ |
1444 | | |
1445 | | #if defined(HAVE_FCHOWN) |
1446 | | |
1447 | | PyDoc_STRVAR(os_fchown__doc__, |
1448 | | "fchown($module, /, fd, uid, gid)\n" |
1449 | | "--\n" |
1450 | | "\n" |
1451 | | "Change the owner and group id of the file specified by file descriptor.\n" |
1452 | | "\n" |
1453 | | "Equivalent to os.chown(fd, uid, gid)."); |
1454 | | |
1455 | | #define OS_FCHOWN_METHODDEF \ |
1456 | | {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__}, |
1457 | | |
1458 | | static PyObject * |
1459 | | os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid); |
1460 | | |
1461 | | static PyObject * |
1462 | | os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1463 | 0 | { |
1464 | 0 | PyObject *return_value = NULL; |
1465 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1466 | |
|
1467 | 0 | #define NUM_KEYWORDS 3 |
1468 | 0 | static struct { |
1469 | 0 | PyGC_Head _this_is_not_used; |
1470 | 0 | PyObject_VAR_HEAD |
1471 | 0 | Py_hash_t ob_hash; |
1472 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1473 | 0 | } _kwtuple = { |
1474 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1475 | 0 | .ob_hash = -1, |
1476 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), }, |
1477 | 0 | }; |
1478 | 0 | #undef NUM_KEYWORDS |
1479 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1480 | |
|
1481 | | #else // !Py_BUILD_CORE |
1482 | | # define KWTUPLE NULL |
1483 | | #endif // !Py_BUILD_CORE |
1484 | |
|
1485 | 0 | static const char * const _keywords[] = {"fd", "uid", "gid", NULL}; |
1486 | 0 | static _PyArg_Parser _parser = { |
1487 | 0 | .keywords = _keywords, |
1488 | 0 | .fname = "fchown", |
1489 | 0 | .kwtuple = KWTUPLE, |
1490 | 0 | }; |
1491 | 0 | #undef KWTUPLE |
1492 | 0 | PyObject *argsbuf[3]; |
1493 | 0 | int fd; |
1494 | 0 | uid_t uid; |
1495 | 0 | gid_t gid; |
1496 | |
|
1497 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1498 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1499 | 0 | if (!args) { |
1500 | 0 | goto exit; |
1501 | 0 | } |
1502 | 0 | fd = PyLong_AsInt(args[0]); |
1503 | 0 | if (fd == -1 && PyErr_Occurred()) { |
1504 | 0 | goto exit; |
1505 | 0 | } |
1506 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1507 | 0 | goto exit; |
1508 | 0 | } |
1509 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1510 | 0 | goto exit; |
1511 | 0 | } |
1512 | 0 | return_value = os_fchown_impl(module, fd, uid, gid); |
1513 | |
|
1514 | 0 | exit: |
1515 | 0 | return return_value; |
1516 | 0 | } |
1517 | | |
1518 | | #endif /* defined(HAVE_FCHOWN) */ |
1519 | | |
1520 | | #if defined(HAVE_LCHOWN) |
1521 | | |
1522 | | PyDoc_STRVAR(os_lchown__doc__, |
1523 | | "lchown($module, /, path, uid, gid)\n" |
1524 | | "--\n" |
1525 | | "\n" |
1526 | | "Change the owner and group id of path to the numeric uid and gid.\n" |
1527 | | "\n" |
1528 | | "This function will not follow symbolic links.\n" |
1529 | | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); |
1530 | | |
1531 | | #define OS_LCHOWN_METHODDEF \ |
1532 | | {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__}, |
1533 | | |
1534 | | static PyObject * |
1535 | | os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid); |
1536 | | |
1537 | | static PyObject * |
1538 | | os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1539 | 0 | { |
1540 | 0 | PyObject *return_value = NULL; |
1541 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1542 | |
|
1543 | 0 | #define NUM_KEYWORDS 3 |
1544 | 0 | static struct { |
1545 | 0 | PyGC_Head _this_is_not_used; |
1546 | 0 | PyObject_VAR_HEAD |
1547 | 0 | Py_hash_t ob_hash; |
1548 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1549 | 0 | } _kwtuple = { |
1550 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1551 | 0 | .ob_hash = -1, |
1552 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), }, |
1553 | 0 | }; |
1554 | 0 | #undef NUM_KEYWORDS |
1555 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1556 | |
|
1557 | | #else // !Py_BUILD_CORE |
1558 | | # define KWTUPLE NULL |
1559 | | #endif // !Py_BUILD_CORE |
1560 | |
|
1561 | 0 | static const char * const _keywords[] = {"path", "uid", "gid", NULL}; |
1562 | 0 | static _PyArg_Parser _parser = { |
1563 | 0 | .keywords = _keywords, |
1564 | 0 | .fname = "lchown", |
1565 | 0 | .kwtuple = KWTUPLE, |
1566 | 0 | }; |
1567 | 0 | #undef KWTUPLE |
1568 | 0 | PyObject *argsbuf[3]; |
1569 | 0 | path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0); |
1570 | 0 | uid_t uid; |
1571 | 0 | gid_t gid; |
1572 | |
|
1573 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1574 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1575 | 0 | if (!args) { |
1576 | 0 | goto exit; |
1577 | 0 | } |
1578 | 0 | if (!path_converter(args[0], &path)) { |
1579 | 0 | goto exit; |
1580 | 0 | } |
1581 | 0 | if (!_Py_Uid_Converter(args[1], &uid)) { |
1582 | 0 | goto exit; |
1583 | 0 | } |
1584 | 0 | if (!_Py_Gid_Converter(args[2], &gid)) { |
1585 | 0 | goto exit; |
1586 | 0 | } |
1587 | 0 | return_value = os_lchown_impl(module, &path, uid, gid); |
1588 | |
|
1589 | 0 | exit: |
1590 | | /* Cleanup for path */ |
1591 | 0 | path_cleanup(&path); |
1592 | |
|
1593 | 0 | return return_value; |
1594 | 0 | } |
1595 | | |
1596 | | #endif /* defined(HAVE_LCHOWN) */ |
1597 | | |
1598 | | PyDoc_STRVAR(os_getcwd__doc__, |
1599 | | "getcwd($module, /)\n" |
1600 | | "--\n" |
1601 | | "\n" |
1602 | | "Return a unicode string representing the current working directory."); |
1603 | | |
1604 | | #define OS_GETCWD_METHODDEF \ |
1605 | | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
1606 | | |
1607 | | static PyObject * |
1608 | | os_getcwd_impl(PyObject *module); |
1609 | | |
1610 | | static PyObject * |
1611 | | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1612 | 0 | { |
1613 | 0 | return os_getcwd_impl(module); |
1614 | 0 | } |
1615 | | |
1616 | | PyDoc_STRVAR(os_getcwdb__doc__, |
1617 | | "getcwdb($module, /)\n" |
1618 | | "--\n" |
1619 | | "\n" |
1620 | | "Return a bytes string representing the current working directory."); |
1621 | | |
1622 | | #define OS_GETCWDB_METHODDEF \ |
1623 | | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
1624 | | |
1625 | | static PyObject * |
1626 | | os_getcwdb_impl(PyObject *module); |
1627 | | |
1628 | | static PyObject * |
1629 | | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1630 | 0 | { |
1631 | 0 | return os_getcwdb_impl(module); |
1632 | 0 | } |
1633 | | |
1634 | | #if defined(HAVE_LINK) |
1635 | | |
1636 | | PyDoc_STRVAR(os_link__doc__, |
1637 | | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
1638 | | " follow_symlinks=(os.name != \'nt\'))\n" |
1639 | | "--\n" |
1640 | | "\n" |
1641 | | "Create a hard link to a file.\n" |
1642 | | "\n" |
1643 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
1644 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
1645 | | " should be relative; the path will then be relative to that directory.\n" |
1646 | | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
1647 | | " link, link will create a link to the symbolic link itself instead of the\n" |
1648 | | " file the link points to.\n" |
1649 | | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
1650 | | " platform. If they are unavailable, using them will raise a\n" |
1651 | | " NotImplementedError."); |
1652 | | |
1653 | | #define OS_LINK_METHODDEF \ |
1654 | | {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__}, |
1655 | | |
1656 | | static PyObject * |
1657 | | os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
1658 | | int dst_dir_fd, int follow_symlinks); |
1659 | | |
1660 | | static PyObject * |
1661 | | os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1662 | 0 | { |
1663 | 0 | PyObject *return_value = NULL; |
1664 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1665 | |
|
1666 | 0 | #define NUM_KEYWORDS 5 |
1667 | 0 | static struct { |
1668 | 0 | PyGC_Head _this_is_not_used; |
1669 | 0 | PyObject_VAR_HEAD |
1670 | 0 | Py_hash_t ob_hash; |
1671 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
1672 | 0 | } _kwtuple = { |
1673 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1674 | 0 | .ob_hash = -1, |
1675 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), }, |
1676 | 0 | }; |
1677 | 0 | #undef NUM_KEYWORDS |
1678 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1679 | |
|
1680 | | #else // !Py_BUILD_CORE |
1681 | | # define KWTUPLE NULL |
1682 | | #endif // !Py_BUILD_CORE |
1683 | |
|
1684 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; |
1685 | 0 | static _PyArg_Parser _parser = { |
1686 | 0 | .keywords = _keywords, |
1687 | 0 | .fname = "link", |
1688 | 0 | .kwtuple = KWTUPLE, |
1689 | 0 | }; |
1690 | 0 | #undef KWTUPLE |
1691 | 0 | PyObject *argsbuf[5]; |
1692 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1693 | 0 | path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0); |
1694 | 0 | path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0); |
1695 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
1696 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
1697 | 0 | int follow_symlinks = -1; |
1698 | |
|
1699 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1700 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1701 | 0 | if (!args) { |
1702 | 0 | goto exit; |
1703 | 0 | } |
1704 | 0 | if (!path_converter(args[0], &src)) { |
1705 | 0 | goto exit; |
1706 | 0 | } |
1707 | 0 | if (!path_converter(args[1], &dst)) { |
1708 | 0 | goto exit; |
1709 | 0 | } |
1710 | 0 | if (!noptargs) { |
1711 | 0 | goto skip_optional_kwonly; |
1712 | 0 | } |
1713 | 0 | if (args[2]) { |
1714 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
1715 | 0 | goto exit; |
1716 | 0 | } |
1717 | 0 | if (!--noptargs) { |
1718 | 0 | goto skip_optional_kwonly; |
1719 | 0 | } |
1720 | 0 | } |
1721 | 0 | if (args[3]) { |
1722 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
1723 | 0 | goto exit; |
1724 | 0 | } |
1725 | 0 | if (!--noptargs) { |
1726 | 0 | goto skip_optional_kwonly; |
1727 | 0 | } |
1728 | 0 | } |
1729 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
1730 | 0 | if (follow_symlinks < 0) { |
1731 | 0 | goto exit; |
1732 | 0 | } |
1733 | 0 | skip_optional_kwonly: |
1734 | 0 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
1735 | |
|
1736 | 0 | exit: |
1737 | | /* Cleanup for src */ |
1738 | 0 | path_cleanup(&src); |
1739 | | /* Cleanup for dst */ |
1740 | 0 | path_cleanup(&dst); |
1741 | |
|
1742 | 0 | return return_value; |
1743 | 0 | } |
1744 | | |
1745 | | #endif /* defined(HAVE_LINK) */ |
1746 | | |
1747 | | PyDoc_STRVAR(os_listdir__doc__, |
1748 | | "listdir($module, /, path=None)\n" |
1749 | | "--\n" |
1750 | | "\n" |
1751 | | "Return a list containing the names of the files in the directory.\n" |
1752 | | "\n" |
1753 | | "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n" |
1754 | | " the filenames returned will also be bytes; in all other circumstances\n" |
1755 | | " the filenames returned will be str.\n" |
1756 | | "If path is None, uses the path=\'.\'.\n" |
1757 | | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
1758 | | " the file descriptor must refer to a directory.\n" |
1759 | | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
1760 | | "\n" |
1761 | | "The list is in arbitrary order. It does not include the special\n" |
1762 | | "entries \'.\' and \'..\' even if they are present in the directory."); |
1763 | | |
1764 | | #define OS_LISTDIR_METHODDEF \ |
1765 | | {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__}, |
1766 | | |
1767 | | static PyObject * |
1768 | | os_listdir_impl(PyObject *module, path_t *path); |
1769 | | |
1770 | | static PyObject * |
1771 | | os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1772 | 120 | { |
1773 | 120 | PyObject *return_value = NULL; |
1774 | 120 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1775 | | |
1776 | 120 | #define NUM_KEYWORDS 1 |
1777 | 120 | static struct { |
1778 | 120 | PyGC_Head _this_is_not_used; |
1779 | 120 | PyObject_VAR_HEAD |
1780 | 120 | Py_hash_t ob_hash; |
1781 | 120 | PyObject *ob_item[NUM_KEYWORDS]; |
1782 | 120 | } _kwtuple = { |
1783 | 120 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1784 | 120 | .ob_hash = -1, |
1785 | 120 | .ob_item = { &_Py_ID(path), }, |
1786 | 120 | }; |
1787 | 120 | #undef NUM_KEYWORDS |
1788 | 120 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1789 | | |
1790 | | #else // !Py_BUILD_CORE |
1791 | | # define KWTUPLE NULL |
1792 | | #endif // !Py_BUILD_CORE |
1793 | | |
1794 | 120 | static const char * const _keywords[] = {"path", NULL}; |
1795 | 120 | static _PyArg_Parser _parser = { |
1796 | 120 | .keywords = _keywords, |
1797 | 120 | .fname = "listdir", |
1798 | 120 | .kwtuple = KWTUPLE, |
1799 | 120 | }; |
1800 | 120 | #undef KWTUPLE |
1801 | 120 | PyObject *argsbuf[1]; |
1802 | 120 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1803 | 120 | path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
1804 | | |
1805 | 120 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1806 | 120 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1807 | 120 | if (!args) { |
1808 | 0 | goto exit; |
1809 | 0 | } |
1810 | 120 | if (!noptargs) { |
1811 | 0 | goto skip_optional_pos; |
1812 | 0 | } |
1813 | 120 | if (!path_converter(args[0], &path)) { |
1814 | 0 | goto exit; |
1815 | 0 | } |
1816 | 120 | skip_optional_pos: |
1817 | 120 | return_value = os_listdir_impl(module, &path); |
1818 | | |
1819 | 120 | exit: |
1820 | | /* Cleanup for path */ |
1821 | 120 | path_cleanup(&path); |
1822 | | |
1823 | 120 | return return_value; |
1824 | 120 | } |
1825 | | |
1826 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1827 | | |
1828 | | PyDoc_STRVAR(os_listdrives__doc__, |
1829 | | "listdrives($module, /)\n" |
1830 | | "--\n" |
1831 | | "\n" |
1832 | | "Return a list containing the names of drives in the system.\n" |
1833 | | "\n" |
1834 | | "A drive name typically looks like \'C:\\\\\'."); |
1835 | | |
1836 | | #define OS_LISTDRIVES_METHODDEF \ |
1837 | | {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__}, |
1838 | | |
1839 | | static PyObject * |
1840 | | os_listdrives_impl(PyObject *module); |
1841 | | |
1842 | | static PyObject * |
1843 | | os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1844 | | { |
1845 | | return os_listdrives_impl(module); |
1846 | | } |
1847 | | |
1848 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1849 | | |
1850 | | #if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
1851 | | |
1852 | | PyDoc_STRVAR(os_listvolumes__doc__, |
1853 | | "listvolumes($module, /)\n" |
1854 | | "--\n" |
1855 | | "\n" |
1856 | | "Return a list containing the volumes in the system.\n" |
1857 | | "\n" |
1858 | | "Volumes are typically represented as a GUID path."); |
1859 | | |
1860 | | #define OS_LISTVOLUMES_METHODDEF \ |
1861 | | {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__}, |
1862 | | |
1863 | | static PyObject * |
1864 | | os_listvolumes_impl(PyObject *module); |
1865 | | |
1866 | | static PyObject * |
1867 | | os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1868 | | { |
1869 | | return os_listvolumes_impl(module); |
1870 | | } |
1871 | | |
1872 | | #endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
1873 | | |
1874 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) |
1875 | | |
1876 | | PyDoc_STRVAR(os_listmounts__doc__, |
1877 | | "listmounts($module, /, volume)\n" |
1878 | | "--\n" |
1879 | | "\n" |
1880 | | "Return a list containing mount points for a particular volume.\n" |
1881 | | "\n" |
1882 | | "\'volume\' should be a GUID path as returned from os.listvolumes."); |
1883 | | |
1884 | | #define OS_LISTMOUNTS_METHODDEF \ |
1885 | | {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__}, |
1886 | | |
1887 | | static PyObject * |
1888 | | os_listmounts_impl(PyObject *module, path_t *volume); |
1889 | | |
1890 | | static PyObject * |
1891 | | os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1892 | | { |
1893 | | PyObject *return_value = NULL; |
1894 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1895 | | |
1896 | | #define NUM_KEYWORDS 1 |
1897 | | static struct { |
1898 | | PyGC_Head _this_is_not_used; |
1899 | | PyObject_VAR_HEAD |
1900 | | Py_hash_t ob_hash; |
1901 | | PyObject *ob_item[NUM_KEYWORDS]; |
1902 | | } _kwtuple = { |
1903 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1904 | | .ob_hash = -1, |
1905 | | .ob_item = { &_Py_ID(volume), }, |
1906 | | }; |
1907 | | #undef NUM_KEYWORDS |
1908 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1909 | | |
1910 | | #else // !Py_BUILD_CORE |
1911 | | # define KWTUPLE NULL |
1912 | | #endif // !Py_BUILD_CORE |
1913 | | |
1914 | | static const char * const _keywords[] = {"volume", NULL}; |
1915 | | static _PyArg_Parser _parser = { |
1916 | | .keywords = _keywords, |
1917 | | .fname = "listmounts", |
1918 | | .kwtuple = KWTUPLE, |
1919 | | }; |
1920 | | #undef KWTUPLE |
1921 | | PyObject *argsbuf[1]; |
1922 | | path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0); |
1923 | | |
1924 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1925 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1926 | | if (!args) { |
1927 | | goto exit; |
1928 | | } |
1929 | | if (!path_converter(args[0], &volume)) { |
1930 | | goto exit; |
1931 | | } |
1932 | | return_value = os_listmounts_impl(module, &volume); |
1933 | | |
1934 | | exit: |
1935 | | /* Cleanup for volume */ |
1936 | | path_cleanup(&volume); |
1937 | | |
1938 | | return return_value; |
1939 | | } |
1940 | | |
1941 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ |
1942 | | |
1943 | | #if defined(MS_WINDOWS) |
1944 | | |
1945 | | PyDoc_STRVAR(os__path_isdevdrive__doc__, |
1946 | | "_path_isdevdrive($module, /, path)\n" |
1947 | | "--\n" |
1948 | | "\n" |
1949 | | "Determines whether the specified path is on a Windows Dev Drive."); |
1950 | | |
1951 | | #define OS__PATH_ISDEVDRIVE_METHODDEF \ |
1952 | | {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__}, |
1953 | | |
1954 | | static PyObject * |
1955 | | os__path_isdevdrive_impl(PyObject *module, path_t *path); |
1956 | | |
1957 | | static PyObject * |
1958 | | os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1959 | | { |
1960 | | PyObject *return_value = NULL; |
1961 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
1962 | | |
1963 | | #define NUM_KEYWORDS 1 |
1964 | | static struct { |
1965 | | PyGC_Head _this_is_not_used; |
1966 | | PyObject_VAR_HEAD |
1967 | | Py_hash_t ob_hash; |
1968 | | PyObject *ob_item[NUM_KEYWORDS]; |
1969 | | } _kwtuple = { |
1970 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
1971 | | .ob_hash = -1, |
1972 | | .ob_item = { &_Py_ID(path), }, |
1973 | | }; |
1974 | | #undef NUM_KEYWORDS |
1975 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
1976 | | |
1977 | | #else // !Py_BUILD_CORE |
1978 | | # define KWTUPLE NULL |
1979 | | #endif // !Py_BUILD_CORE |
1980 | | |
1981 | | static const char * const _keywords[] = {"path", NULL}; |
1982 | | static _PyArg_Parser _parser = { |
1983 | | .keywords = _keywords, |
1984 | | .fname = "_path_isdevdrive", |
1985 | | .kwtuple = KWTUPLE, |
1986 | | }; |
1987 | | #undef KWTUPLE |
1988 | | PyObject *argsbuf[1]; |
1989 | | path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0); |
1990 | | |
1991 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
1992 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
1993 | | if (!args) { |
1994 | | goto exit; |
1995 | | } |
1996 | | if (!path_converter(args[0], &path)) { |
1997 | | goto exit; |
1998 | | } |
1999 | | return_value = os__path_isdevdrive_impl(module, &path); |
2000 | | |
2001 | | exit: |
2002 | | /* Cleanup for path */ |
2003 | | path_cleanup(&path); |
2004 | | |
2005 | | return return_value; |
2006 | | } |
2007 | | |
2008 | | #endif /* defined(MS_WINDOWS) */ |
2009 | | |
2010 | | #if defined(MS_WINDOWS) |
2011 | | |
2012 | | PyDoc_STRVAR(os__getfullpathname__doc__, |
2013 | | "_getfullpathname($module, path, /)\n" |
2014 | | "--\n" |
2015 | | "\n"); |
2016 | | |
2017 | | #define OS__GETFULLPATHNAME_METHODDEF \ |
2018 | | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
2019 | | |
2020 | | static PyObject * |
2021 | | os__getfullpathname_impl(PyObject *module, path_t *path); |
2022 | | |
2023 | | static PyObject * |
2024 | | os__getfullpathname(PyObject *module, PyObject *arg) |
2025 | | { |
2026 | | PyObject *return_value = NULL; |
2027 | | path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0); |
2028 | | |
2029 | | if (!path_converter(arg, &path)) { |
2030 | | goto exit; |
2031 | | } |
2032 | | return_value = os__getfullpathname_impl(module, &path); |
2033 | | |
2034 | | exit: |
2035 | | /* Cleanup for path */ |
2036 | | path_cleanup(&path); |
2037 | | |
2038 | | return return_value; |
2039 | | } |
2040 | | |
2041 | | #endif /* defined(MS_WINDOWS) */ |
2042 | | |
2043 | | #if defined(MS_WINDOWS) |
2044 | | |
2045 | | PyDoc_STRVAR(os__getfinalpathname__doc__, |
2046 | | "_getfinalpathname($module, path, /)\n" |
2047 | | "--\n" |
2048 | | "\n" |
2049 | | "A helper function for samepath on windows."); |
2050 | | |
2051 | | #define OS__GETFINALPATHNAME_METHODDEF \ |
2052 | | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
2053 | | |
2054 | | static PyObject * |
2055 | | os__getfinalpathname_impl(PyObject *module, path_t *path); |
2056 | | |
2057 | | static PyObject * |
2058 | | os__getfinalpathname(PyObject *module, PyObject *arg) |
2059 | | { |
2060 | | PyObject *return_value = NULL; |
2061 | | path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0); |
2062 | | |
2063 | | if (!path_converter(arg, &path)) { |
2064 | | goto exit; |
2065 | | } |
2066 | | return_value = os__getfinalpathname_impl(module, &path); |
2067 | | |
2068 | | exit: |
2069 | | /* Cleanup for path */ |
2070 | | path_cleanup(&path); |
2071 | | |
2072 | | return return_value; |
2073 | | } |
2074 | | |
2075 | | #endif /* defined(MS_WINDOWS) */ |
2076 | | |
2077 | | #if defined(MS_WINDOWS) |
2078 | | |
2079 | | PyDoc_STRVAR(os__findfirstfile__doc__, |
2080 | | "_findfirstfile($module, path, /)\n" |
2081 | | "--\n" |
2082 | | "\n" |
2083 | | "A function to get the real file name without accessing the file in Windows."); |
2084 | | |
2085 | | #define OS__FINDFIRSTFILE_METHODDEF \ |
2086 | | {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__}, |
2087 | | |
2088 | | static PyObject * |
2089 | | os__findfirstfile_impl(PyObject *module, path_t *path); |
2090 | | |
2091 | | static PyObject * |
2092 | | os__findfirstfile(PyObject *module, PyObject *arg) |
2093 | | { |
2094 | | PyObject *return_value = NULL; |
2095 | | path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0); |
2096 | | |
2097 | | if (!path_converter(arg, &path)) { |
2098 | | goto exit; |
2099 | | } |
2100 | | return_value = os__findfirstfile_impl(module, &path); |
2101 | | |
2102 | | exit: |
2103 | | /* Cleanup for path */ |
2104 | | path_cleanup(&path); |
2105 | | |
2106 | | return return_value; |
2107 | | } |
2108 | | |
2109 | | #endif /* defined(MS_WINDOWS) */ |
2110 | | |
2111 | | #if defined(MS_WINDOWS) |
2112 | | |
2113 | | PyDoc_STRVAR(os__getvolumepathname__doc__, |
2114 | | "_getvolumepathname($module, /, path)\n" |
2115 | | "--\n" |
2116 | | "\n" |
2117 | | "A helper function for ismount on Win32."); |
2118 | | |
2119 | | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
2120 | | {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__}, |
2121 | | |
2122 | | static PyObject * |
2123 | | os__getvolumepathname_impl(PyObject *module, path_t *path); |
2124 | | |
2125 | | static PyObject * |
2126 | | os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2127 | | { |
2128 | | PyObject *return_value = NULL; |
2129 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2130 | | |
2131 | | #define NUM_KEYWORDS 1 |
2132 | | static struct { |
2133 | | PyGC_Head _this_is_not_used; |
2134 | | PyObject_VAR_HEAD |
2135 | | Py_hash_t ob_hash; |
2136 | | PyObject *ob_item[NUM_KEYWORDS]; |
2137 | | } _kwtuple = { |
2138 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2139 | | .ob_hash = -1, |
2140 | | .ob_item = { &_Py_ID(path), }, |
2141 | | }; |
2142 | | #undef NUM_KEYWORDS |
2143 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2144 | | |
2145 | | #else // !Py_BUILD_CORE |
2146 | | # define KWTUPLE NULL |
2147 | | #endif // !Py_BUILD_CORE |
2148 | | |
2149 | | static const char * const _keywords[] = {"path", NULL}; |
2150 | | static _PyArg_Parser _parser = { |
2151 | | .keywords = _keywords, |
2152 | | .fname = "_getvolumepathname", |
2153 | | .kwtuple = KWTUPLE, |
2154 | | }; |
2155 | | #undef KWTUPLE |
2156 | | PyObject *argsbuf[1]; |
2157 | | path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0); |
2158 | | |
2159 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2160 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2161 | | if (!args) { |
2162 | | goto exit; |
2163 | | } |
2164 | | if (!path_converter(args[0], &path)) { |
2165 | | goto exit; |
2166 | | } |
2167 | | return_value = os__getvolumepathname_impl(module, &path); |
2168 | | |
2169 | | exit: |
2170 | | /* Cleanup for path */ |
2171 | | path_cleanup(&path); |
2172 | | |
2173 | | return return_value; |
2174 | | } |
2175 | | |
2176 | | #endif /* defined(MS_WINDOWS) */ |
2177 | | |
2178 | | #if defined(MS_WINDOWS) |
2179 | | |
2180 | | PyDoc_STRVAR(os__path_splitroot__doc__, |
2181 | | "_path_splitroot($module, path, /)\n" |
2182 | | "--\n" |
2183 | | "\n" |
2184 | | "Removes everything after the root on Win32."); |
2185 | | |
2186 | | #define OS__PATH_SPLITROOT_METHODDEF \ |
2187 | | {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__}, |
2188 | | |
2189 | | static PyObject * |
2190 | | os__path_splitroot_impl(PyObject *module, path_t *path); |
2191 | | |
2192 | | static PyObject * |
2193 | | os__path_splitroot(PyObject *module, PyObject *arg) |
2194 | | { |
2195 | | PyObject *return_value = NULL; |
2196 | | path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0); |
2197 | | |
2198 | | if (!path_converter(arg, &path)) { |
2199 | | goto exit; |
2200 | | } |
2201 | | return_value = os__path_splitroot_impl(module, &path); |
2202 | | |
2203 | | exit: |
2204 | | /* Cleanup for path */ |
2205 | | path_cleanup(&path); |
2206 | | |
2207 | | return return_value; |
2208 | | } |
2209 | | |
2210 | | #endif /* defined(MS_WINDOWS) */ |
2211 | | |
2212 | | #if defined(MS_WINDOWS) |
2213 | | |
2214 | | PyDoc_STRVAR(os__path_exists__doc__, |
2215 | | "_path_exists($module, /, path)\n" |
2216 | | "--\n" |
2217 | | "\n" |
2218 | | "Test whether a path exists. Returns False for broken symbolic links."); |
2219 | | |
2220 | | #define OS__PATH_EXISTS_METHODDEF \ |
2221 | | {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__}, |
2222 | | |
2223 | | static int |
2224 | | os__path_exists_impl(PyObject *module, path_t *path); |
2225 | | |
2226 | | static PyObject * |
2227 | | os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2228 | | { |
2229 | | PyObject *return_value = NULL; |
2230 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2231 | | |
2232 | | #define NUM_KEYWORDS 1 |
2233 | | static struct { |
2234 | | PyGC_Head _this_is_not_used; |
2235 | | PyObject_VAR_HEAD |
2236 | | Py_hash_t ob_hash; |
2237 | | PyObject *ob_item[NUM_KEYWORDS]; |
2238 | | } _kwtuple = { |
2239 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2240 | | .ob_hash = -1, |
2241 | | .ob_item = { &_Py_ID(path), }, |
2242 | | }; |
2243 | | #undef NUM_KEYWORDS |
2244 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2245 | | |
2246 | | #else // !Py_BUILD_CORE |
2247 | | # define KWTUPLE NULL |
2248 | | #endif // !Py_BUILD_CORE |
2249 | | |
2250 | | static const char * const _keywords[] = {"path", NULL}; |
2251 | | static _PyArg_Parser _parser = { |
2252 | | .keywords = _keywords, |
2253 | | .fname = "_path_exists", |
2254 | | .kwtuple = KWTUPLE, |
2255 | | }; |
2256 | | #undef KWTUPLE |
2257 | | PyObject *argsbuf[1]; |
2258 | | path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1); |
2259 | | int _return_value; |
2260 | | |
2261 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2262 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2263 | | if (!args) { |
2264 | | goto exit; |
2265 | | } |
2266 | | if (!path_converter(args[0], &path)) { |
2267 | | goto exit; |
2268 | | } |
2269 | | _return_value = os__path_exists_impl(module, &path); |
2270 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2271 | | goto exit; |
2272 | | } |
2273 | | return_value = PyBool_FromLong((long)_return_value); |
2274 | | |
2275 | | exit: |
2276 | | /* Cleanup for path */ |
2277 | | path_cleanup(&path); |
2278 | | |
2279 | | return return_value; |
2280 | | } |
2281 | | |
2282 | | #endif /* defined(MS_WINDOWS) */ |
2283 | | |
2284 | | #if defined(MS_WINDOWS) |
2285 | | |
2286 | | PyDoc_STRVAR(os__path_lexists__doc__, |
2287 | | "_path_lexists($module, /, path)\n" |
2288 | | "--\n" |
2289 | | "\n" |
2290 | | "Test whether a path exists. Returns True for broken symbolic links."); |
2291 | | |
2292 | | #define OS__PATH_LEXISTS_METHODDEF \ |
2293 | | {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__}, |
2294 | | |
2295 | | static int |
2296 | | os__path_lexists_impl(PyObject *module, path_t *path); |
2297 | | |
2298 | | static PyObject * |
2299 | | os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2300 | | { |
2301 | | PyObject *return_value = NULL; |
2302 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2303 | | |
2304 | | #define NUM_KEYWORDS 1 |
2305 | | static struct { |
2306 | | PyGC_Head _this_is_not_used; |
2307 | | PyObject_VAR_HEAD |
2308 | | Py_hash_t ob_hash; |
2309 | | PyObject *ob_item[NUM_KEYWORDS]; |
2310 | | } _kwtuple = { |
2311 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2312 | | .ob_hash = -1, |
2313 | | .ob_item = { &_Py_ID(path), }, |
2314 | | }; |
2315 | | #undef NUM_KEYWORDS |
2316 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2317 | | |
2318 | | #else // !Py_BUILD_CORE |
2319 | | # define KWTUPLE NULL |
2320 | | #endif // !Py_BUILD_CORE |
2321 | | |
2322 | | static const char * const _keywords[] = {"path", NULL}; |
2323 | | static _PyArg_Parser _parser = { |
2324 | | .keywords = _keywords, |
2325 | | .fname = "_path_lexists", |
2326 | | .kwtuple = KWTUPLE, |
2327 | | }; |
2328 | | #undef KWTUPLE |
2329 | | PyObject *argsbuf[1]; |
2330 | | path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1); |
2331 | | int _return_value; |
2332 | | |
2333 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2334 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2335 | | if (!args) { |
2336 | | goto exit; |
2337 | | } |
2338 | | if (!path_converter(args[0], &path)) { |
2339 | | goto exit; |
2340 | | } |
2341 | | _return_value = os__path_lexists_impl(module, &path); |
2342 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2343 | | goto exit; |
2344 | | } |
2345 | | return_value = PyBool_FromLong((long)_return_value); |
2346 | | |
2347 | | exit: |
2348 | | /* Cleanup for path */ |
2349 | | path_cleanup(&path); |
2350 | | |
2351 | | return return_value; |
2352 | | } |
2353 | | |
2354 | | #endif /* defined(MS_WINDOWS) */ |
2355 | | |
2356 | | #if defined(MS_WINDOWS) |
2357 | | |
2358 | | PyDoc_STRVAR(os__path_isdir__doc__, |
2359 | | "_path_isdir($module, path, /)\n" |
2360 | | "--\n" |
2361 | | "\n" |
2362 | | "Return true if the pathname refers to an existing directory."); |
2363 | | |
2364 | | #define OS__PATH_ISDIR_METHODDEF \ |
2365 | | {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__}, |
2366 | | |
2367 | | static int |
2368 | | os__path_isdir_impl(PyObject *module, path_t *path); |
2369 | | |
2370 | | static PyObject * |
2371 | | os__path_isdir(PyObject *module, PyObject *arg) |
2372 | | { |
2373 | | PyObject *return_value = NULL; |
2374 | | path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1); |
2375 | | int _return_value; |
2376 | | |
2377 | | if (!path_converter(arg, &path)) { |
2378 | | goto exit; |
2379 | | } |
2380 | | _return_value = os__path_isdir_impl(module, &path); |
2381 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2382 | | goto exit; |
2383 | | } |
2384 | | return_value = PyBool_FromLong((long)_return_value); |
2385 | | |
2386 | | exit: |
2387 | | /* Cleanup for path */ |
2388 | | path_cleanup(&path); |
2389 | | |
2390 | | return return_value; |
2391 | | } |
2392 | | |
2393 | | #endif /* defined(MS_WINDOWS) */ |
2394 | | |
2395 | | #if defined(MS_WINDOWS) |
2396 | | |
2397 | | PyDoc_STRVAR(os__path_isfile__doc__, |
2398 | | "_path_isfile($module, /, path)\n" |
2399 | | "--\n" |
2400 | | "\n" |
2401 | | "Test whether a path is a regular file"); |
2402 | | |
2403 | | #define OS__PATH_ISFILE_METHODDEF \ |
2404 | | {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__}, |
2405 | | |
2406 | | static int |
2407 | | os__path_isfile_impl(PyObject *module, path_t *path); |
2408 | | |
2409 | | static PyObject * |
2410 | | os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2411 | | { |
2412 | | PyObject *return_value = NULL; |
2413 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2414 | | |
2415 | | #define NUM_KEYWORDS 1 |
2416 | | static struct { |
2417 | | PyGC_Head _this_is_not_used; |
2418 | | PyObject_VAR_HEAD |
2419 | | Py_hash_t ob_hash; |
2420 | | PyObject *ob_item[NUM_KEYWORDS]; |
2421 | | } _kwtuple = { |
2422 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2423 | | .ob_hash = -1, |
2424 | | .ob_item = { &_Py_ID(path), }, |
2425 | | }; |
2426 | | #undef NUM_KEYWORDS |
2427 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2428 | | |
2429 | | #else // !Py_BUILD_CORE |
2430 | | # define KWTUPLE NULL |
2431 | | #endif // !Py_BUILD_CORE |
2432 | | |
2433 | | static const char * const _keywords[] = {"path", NULL}; |
2434 | | static _PyArg_Parser _parser = { |
2435 | | .keywords = _keywords, |
2436 | | .fname = "_path_isfile", |
2437 | | .kwtuple = KWTUPLE, |
2438 | | }; |
2439 | | #undef KWTUPLE |
2440 | | PyObject *argsbuf[1]; |
2441 | | path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1); |
2442 | | int _return_value; |
2443 | | |
2444 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2445 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2446 | | if (!args) { |
2447 | | goto exit; |
2448 | | } |
2449 | | if (!path_converter(args[0], &path)) { |
2450 | | goto exit; |
2451 | | } |
2452 | | _return_value = os__path_isfile_impl(module, &path); |
2453 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2454 | | goto exit; |
2455 | | } |
2456 | | return_value = PyBool_FromLong((long)_return_value); |
2457 | | |
2458 | | exit: |
2459 | | /* Cleanup for path */ |
2460 | | path_cleanup(&path); |
2461 | | |
2462 | | return return_value; |
2463 | | } |
2464 | | |
2465 | | #endif /* defined(MS_WINDOWS) */ |
2466 | | |
2467 | | #if defined(MS_WINDOWS) |
2468 | | |
2469 | | PyDoc_STRVAR(os__path_islink__doc__, |
2470 | | "_path_islink($module, /, path)\n" |
2471 | | "--\n" |
2472 | | "\n" |
2473 | | "Test whether a path is a symbolic link"); |
2474 | | |
2475 | | #define OS__PATH_ISLINK_METHODDEF \ |
2476 | | {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__}, |
2477 | | |
2478 | | static int |
2479 | | os__path_islink_impl(PyObject *module, path_t *path); |
2480 | | |
2481 | | static PyObject * |
2482 | | os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2483 | | { |
2484 | | PyObject *return_value = NULL; |
2485 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2486 | | |
2487 | | #define NUM_KEYWORDS 1 |
2488 | | static struct { |
2489 | | PyGC_Head _this_is_not_used; |
2490 | | PyObject_VAR_HEAD |
2491 | | Py_hash_t ob_hash; |
2492 | | PyObject *ob_item[NUM_KEYWORDS]; |
2493 | | } _kwtuple = { |
2494 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2495 | | .ob_hash = -1, |
2496 | | .ob_item = { &_Py_ID(path), }, |
2497 | | }; |
2498 | | #undef NUM_KEYWORDS |
2499 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2500 | | |
2501 | | #else // !Py_BUILD_CORE |
2502 | | # define KWTUPLE NULL |
2503 | | #endif // !Py_BUILD_CORE |
2504 | | |
2505 | | static const char * const _keywords[] = {"path", NULL}; |
2506 | | static _PyArg_Parser _parser = { |
2507 | | .keywords = _keywords, |
2508 | | .fname = "_path_islink", |
2509 | | .kwtuple = KWTUPLE, |
2510 | | }; |
2511 | | #undef KWTUPLE |
2512 | | PyObject *argsbuf[1]; |
2513 | | path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1); |
2514 | | int _return_value; |
2515 | | |
2516 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2517 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2518 | | if (!args) { |
2519 | | goto exit; |
2520 | | } |
2521 | | if (!path_converter(args[0], &path)) { |
2522 | | goto exit; |
2523 | | } |
2524 | | _return_value = os__path_islink_impl(module, &path); |
2525 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2526 | | goto exit; |
2527 | | } |
2528 | | return_value = PyBool_FromLong((long)_return_value); |
2529 | | |
2530 | | exit: |
2531 | | /* Cleanup for path */ |
2532 | | path_cleanup(&path); |
2533 | | |
2534 | | return return_value; |
2535 | | } |
2536 | | |
2537 | | #endif /* defined(MS_WINDOWS) */ |
2538 | | |
2539 | | #if defined(MS_WINDOWS) |
2540 | | |
2541 | | PyDoc_STRVAR(os__path_isjunction__doc__, |
2542 | | "_path_isjunction($module, /, path)\n" |
2543 | | "--\n" |
2544 | | "\n" |
2545 | | "Test whether a path is a junction"); |
2546 | | |
2547 | | #define OS__PATH_ISJUNCTION_METHODDEF \ |
2548 | | {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__}, |
2549 | | |
2550 | | static int |
2551 | | os__path_isjunction_impl(PyObject *module, path_t *path); |
2552 | | |
2553 | | static PyObject * |
2554 | | os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2555 | | { |
2556 | | PyObject *return_value = NULL; |
2557 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2558 | | |
2559 | | #define NUM_KEYWORDS 1 |
2560 | | static struct { |
2561 | | PyGC_Head _this_is_not_used; |
2562 | | PyObject_VAR_HEAD |
2563 | | Py_hash_t ob_hash; |
2564 | | PyObject *ob_item[NUM_KEYWORDS]; |
2565 | | } _kwtuple = { |
2566 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2567 | | .ob_hash = -1, |
2568 | | .ob_item = { &_Py_ID(path), }, |
2569 | | }; |
2570 | | #undef NUM_KEYWORDS |
2571 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2572 | | |
2573 | | #else // !Py_BUILD_CORE |
2574 | | # define KWTUPLE NULL |
2575 | | #endif // !Py_BUILD_CORE |
2576 | | |
2577 | | static const char * const _keywords[] = {"path", NULL}; |
2578 | | static _PyArg_Parser _parser = { |
2579 | | .keywords = _keywords, |
2580 | | .fname = "_path_isjunction", |
2581 | | .kwtuple = KWTUPLE, |
2582 | | }; |
2583 | | #undef KWTUPLE |
2584 | | PyObject *argsbuf[1]; |
2585 | | path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1); |
2586 | | int _return_value; |
2587 | | |
2588 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2589 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2590 | | if (!args) { |
2591 | | goto exit; |
2592 | | } |
2593 | | if (!path_converter(args[0], &path)) { |
2594 | | goto exit; |
2595 | | } |
2596 | | _return_value = os__path_isjunction_impl(module, &path); |
2597 | | if ((_return_value == -1) && PyErr_Occurred()) { |
2598 | | goto exit; |
2599 | | } |
2600 | | return_value = PyBool_FromLong((long)_return_value); |
2601 | | |
2602 | | exit: |
2603 | | /* Cleanup for path */ |
2604 | | path_cleanup(&path); |
2605 | | |
2606 | | return return_value; |
2607 | | } |
2608 | | |
2609 | | #endif /* defined(MS_WINDOWS) */ |
2610 | | |
2611 | | PyDoc_STRVAR(os__path_splitroot_ex__doc__, |
2612 | | "_path_splitroot_ex($module, path, /)\n" |
2613 | | "--\n" |
2614 | | "\n" |
2615 | | "Split a pathname into drive, root and tail.\n" |
2616 | | "\n" |
2617 | | "The tail contains anything after the root."); |
2618 | | |
2619 | | #define OS__PATH_SPLITROOT_EX_METHODDEF \ |
2620 | | {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__}, |
2621 | | |
2622 | | static PyObject * |
2623 | | os__path_splitroot_ex_impl(PyObject *module, path_t *path); |
2624 | | |
2625 | | static PyObject * |
2626 | | os__path_splitroot_ex(PyObject *module, PyObject *arg) |
2627 | 0 | { |
2628 | 0 | PyObject *return_value = NULL; |
2629 | 0 | path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0); |
2630 | |
|
2631 | 0 | if (!path_converter(arg, &path)) { |
2632 | 0 | goto exit; |
2633 | 0 | } |
2634 | 0 | return_value = os__path_splitroot_ex_impl(module, &path); |
2635 | |
|
2636 | 0 | exit: |
2637 | | /* Cleanup for path */ |
2638 | 0 | path_cleanup(&path); |
2639 | |
|
2640 | 0 | return return_value; |
2641 | 0 | } |
2642 | | |
2643 | | PyDoc_STRVAR(os__path_normpath__doc__, |
2644 | | "_path_normpath($module, /, path)\n" |
2645 | | "--\n" |
2646 | | "\n" |
2647 | | "Normalize path, eliminating double slashes, etc."); |
2648 | | |
2649 | | #define OS__PATH_NORMPATH_METHODDEF \ |
2650 | | {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__}, |
2651 | | |
2652 | | static PyObject * |
2653 | | os__path_normpath_impl(PyObject *module, path_t *path); |
2654 | | |
2655 | | static PyObject * |
2656 | | os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2657 | 80 | { |
2658 | 80 | PyObject *return_value = NULL; |
2659 | 80 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2660 | | |
2661 | 80 | #define NUM_KEYWORDS 1 |
2662 | 80 | static struct { |
2663 | 80 | PyGC_Head _this_is_not_used; |
2664 | 80 | PyObject_VAR_HEAD |
2665 | 80 | Py_hash_t ob_hash; |
2666 | 80 | PyObject *ob_item[NUM_KEYWORDS]; |
2667 | 80 | } _kwtuple = { |
2668 | 80 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2669 | 80 | .ob_hash = -1, |
2670 | 80 | .ob_item = { &_Py_ID(path), }, |
2671 | 80 | }; |
2672 | 80 | #undef NUM_KEYWORDS |
2673 | 80 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2674 | | |
2675 | | #else // !Py_BUILD_CORE |
2676 | | # define KWTUPLE NULL |
2677 | | #endif // !Py_BUILD_CORE |
2678 | | |
2679 | 80 | static const char * const _keywords[] = {"path", NULL}; |
2680 | 80 | static _PyArg_Parser _parser = { |
2681 | 80 | .keywords = _keywords, |
2682 | 80 | .fname = "_path_normpath", |
2683 | 80 | .kwtuple = KWTUPLE, |
2684 | 80 | }; |
2685 | 80 | #undef KWTUPLE |
2686 | 80 | PyObject *argsbuf[1]; |
2687 | 80 | path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0); |
2688 | | |
2689 | 80 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2690 | 80 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2691 | 80 | if (!args) { |
2692 | 0 | goto exit; |
2693 | 0 | } |
2694 | 80 | if (!path_converter(args[0], &path)) { |
2695 | 0 | goto exit; |
2696 | 0 | } |
2697 | 80 | return_value = os__path_normpath_impl(module, &path); |
2698 | | |
2699 | 80 | exit: |
2700 | | /* Cleanup for path */ |
2701 | 80 | path_cleanup(&path); |
2702 | | |
2703 | 80 | return return_value; |
2704 | 80 | } |
2705 | | |
2706 | | PyDoc_STRVAR(os_mkdir__doc__, |
2707 | | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
2708 | | "--\n" |
2709 | | "\n" |
2710 | | "Create a directory.\n" |
2711 | | "\n" |
2712 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
2713 | | " and path should be relative; path will then be relative to that directory.\n" |
2714 | | "dir_fd may not be implemented on your platform.\n" |
2715 | | " If it is unavailable, using it will raise a NotImplementedError.\n" |
2716 | | "\n" |
2717 | | "The mode argument is ignored on Windows. Where it is used, the current umask\n" |
2718 | | "value is first masked out."); |
2719 | | |
2720 | | #define OS_MKDIR_METHODDEF \ |
2721 | | {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
2722 | | |
2723 | | static PyObject * |
2724 | | os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
2725 | | |
2726 | | static PyObject * |
2727 | | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2728 | 0 | { |
2729 | 0 | PyObject *return_value = NULL; |
2730 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2731 | |
|
2732 | 0 | #define NUM_KEYWORDS 3 |
2733 | 0 | static struct { |
2734 | 0 | PyGC_Head _this_is_not_used; |
2735 | 0 | PyObject_VAR_HEAD |
2736 | 0 | Py_hash_t ob_hash; |
2737 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2738 | 0 | } _kwtuple = { |
2739 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2740 | 0 | .ob_hash = -1, |
2741 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
2742 | 0 | }; |
2743 | 0 | #undef NUM_KEYWORDS |
2744 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2745 | |
|
2746 | | #else // !Py_BUILD_CORE |
2747 | | # define KWTUPLE NULL |
2748 | | #endif // !Py_BUILD_CORE |
2749 | |
|
2750 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
2751 | 0 | static _PyArg_Parser _parser = { |
2752 | 0 | .keywords = _keywords, |
2753 | 0 | .fname = "mkdir", |
2754 | 0 | .kwtuple = KWTUPLE, |
2755 | 0 | }; |
2756 | 0 | #undef KWTUPLE |
2757 | 0 | PyObject *argsbuf[3]; |
2758 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
2759 | 0 | path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0); |
2760 | 0 | int mode = 511; |
2761 | 0 | int dir_fd = DEFAULT_DIR_FD; |
2762 | |
|
2763 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2764 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2765 | 0 | if (!args) { |
2766 | 0 | goto exit; |
2767 | 0 | } |
2768 | 0 | if (!path_converter(args[0], &path)) { |
2769 | 0 | goto exit; |
2770 | 0 | } |
2771 | 0 | if (!noptargs) { |
2772 | 0 | goto skip_optional_pos; |
2773 | 0 | } |
2774 | 0 | if (args[1]) { |
2775 | 0 | mode = PyLong_AsInt(args[1]); |
2776 | 0 | if (mode == -1 && PyErr_Occurred()) { |
2777 | 0 | goto exit; |
2778 | 0 | } |
2779 | 0 | if (!--noptargs) { |
2780 | 0 | goto skip_optional_pos; |
2781 | 0 | } |
2782 | 0 | } |
2783 | 0 | skip_optional_pos: |
2784 | 0 | if (!noptargs) { |
2785 | 0 | goto skip_optional_kwonly; |
2786 | 0 | } |
2787 | 0 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
2788 | 0 | goto exit; |
2789 | 0 | } |
2790 | 0 | skip_optional_kwonly: |
2791 | 0 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
2792 | |
|
2793 | 0 | exit: |
2794 | | /* Cleanup for path */ |
2795 | 0 | path_cleanup(&path); |
2796 | |
|
2797 | 0 | return return_value; |
2798 | 0 | } |
2799 | | |
2800 | | #if defined(HAVE_NICE) |
2801 | | |
2802 | | PyDoc_STRVAR(os_nice__doc__, |
2803 | | "nice($module, increment, /)\n" |
2804 | | "--\n" |
2805 | | "\n" |
2806 | | "Add increment to the priority of process and return the new priority."); |
2807 | | |
2808 | | #define OS_NICE_METHODDEF \ |
2809 | | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
2810 | | |
2811 | | static PyObject * |
2812 | | os_nice_impl(PyObject *module, int increment); |
2813 | | |
2814 | | static PyObject * |
2815 | | os_nice(PyObject *module, PyObject *arg) |
2816 | 0 | { |
2817 | 0 | PyObject *return_value = NULL; |
2818 | 0 | int increment; |
2819 | |
|
2820 | 0 | increment = PyLong_AsInt(arg); |
2821 | 0 | if (increment == -1 && PyErr_Occurred()) { |
2822 | 0 | goto exit; |
2823 | 0 | } |
2824 | 0 | return_value = os_nice_impl(module, increment); |
2825 | |
|
2826 | 0 | exit: |
2827 | 0 | return return_value; |
2828 | 0 | } |
2829 | | |
2830 | | #endif /* defined(HAVE_NICE) */ |
2831 | | |
2832 | | #if defined(HAVE_GETPRIORITY) |
2833 | | |
2834 | | PyDoc_STRVAR(os_getpriority__doc__, |
2835 | | "getpriority($module, /, which, who)\n" |
2836 | | "--\n" |
2837 | | "\n" |
2838 | | "Return program scheduling priority."); |
2839 | | |
2840 | | #define OS_GETPRIORITY_METHODDEF \ |
2841 | | {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
2842 | | |
2843 | | static PyObject * |
2844 | | os_getpriority_impl(PyObject *module, int which, int who); |
2845 | | |
2846 | | static PyObject * |
2847 | | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2848 | 0 | { |
2849 | 0 | PyObject *return_value = NULL; |
2850 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2851 | |
|
2852 | 0 | #define NUM_KEYWORDS 2 |
2853 | 0 | static struct { |
2854 | 0 | PyGC_Head _this_is_not_used; |
2855 | 0 | PyObject_VAR_HEAD |
2856 | 0 | Py_hash_t ob_hash; |
2857 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2858 | 0 | } _kwtuple = { |
2859 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2860 | 0 | .ob_hash = -1, |
2861 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), }, |
2862 | 0 | }; |
2863 | 0 | #undef NUM_KEYWORDS |
2864 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2865 | |
|
2866 | | #else // !Py_BUILD_CORE |
2867 | | # define KWTUPLE NULL |
2868 | | #endif // !Py_BUILD_CORE |
2869 | |
|
2870 | 0 | static const char * const _keywords[] = {"which", "who", NULL}; |
2871 | 0 | static _PyArg_Parser _parser = { |
2872 | 0 | .keywords = _keywords, |
2873 | 0 | .fname = "getpriority", |
2874 | 0 | .kwtuple = KWTUPLE, |
2875 | 0 | }; |
2876 | 0 | #undef KWTUPLE |
2877 | 0 | PyObject *argsbuf[2]; |
2878 | 0 | int which; |
2879 | 0 | int who; |
2880 | |
|
2881 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2882 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2883 | 0 | if (!args) { |
2884 | 0 | goto exit; |
2885 | 0 | } |
2886 | 0 | which = PyLong_AsInt(args[0]); |
2887 | 0 | if (which == -1 && PyErr_Occurred()) { |
2888 | 0 | goto exit; |
2889 | 0 | } |
2890 | 0 | who = PyLong_AsInt(args[1]); |
2891 | 0 | if (who == -1 && PyErr_Occurred()) { |
2892 | 0 | goto exit; |
2893 | 0 | } |
2894 | 0 | return_value = os_getpriority_impl(module, which, who); |
2895 | |
|
2896 | 0 | exit: |
2897 | 0 | return return_value; |
2898 | 0 | } |
2899 | | |
2900 | | #endif /* defined(HAVE_GETPRIORITY) */ |
2901 | | |
2902 | | #if defined(HAVE_SETPRIORITY) |
2903 | | |
2904 | | PyDoc_STRVAR(os_setpriority__doc__, |
2905 | | "setpriority($module, /, which, who, priority)\n" |
2906 | | "--\n" |
2907 | | "\n" |
2908 | | "Set program scheduling priority."); |
2909 | | |
2910 | | #define OS_SETPRIORITY_METHODDEF \ |
2911 | | {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
2912 | | |
2913 | | static PyObject * |
2914 | | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
2915 | | |
2916 | | static PyObject * |
2917 | | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2918 | 0 | { |
2919 | 0 | PyObject *return_value = NULL; |
2920 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
2921 | |
|
2922 | 0 | #define NUM_KEYWORDS 3 |
2923 | 0 | static struct { |
2924 | 0 | PyGC_Head _this_is_not_used; |
2925 | 0 | PyObject_VAR_HEAD |
2926 | 0 | Py_hash_t ob_hash; |
2927 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
2928 | 0 | } _kwtuple = { |
2929 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
2930 | 0 | .ob_hash = -1, |
2931 | 0 | .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), }, |
2932 | 0 | }; |
2933 | 0 | #undef NUM_KEYWORDS |
2934 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
2935 | |
|
2936 | | #else // !Py_BUILD_CORE |
2937 | | # define KWTUPLE NULL |
2938 | | #endif // !Py_BUILD_CORE |
2939 | |
|
2940 | 0 | static const char * const _keywords[] = {"which", "who", "priority", NULL}; |
2941 | 0 | static _PyArg_Parser _parser = { |
2942 | 0 | .keywords = _keywords, |
2943 | 0 | .fname = "setpriority", |
2944 | 0 | .kwtuple = KWTUPLE, |
2945 | 0 | }; |
2946 | 0 | #undef KWTUPLE |
2947 | 0 | PyObject *argsbuf[3]; |
2948 | 0 | int which; |
2949 | 0 | int who; |
2950 | 0 | int priority; |
2951 | |
|
2952 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
2953 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
2954 | 0 | if (!args) { |
2955 | 0 | goto exit; |
2956 | 0 | } |
2957 | 0 | which = PyLong_AsInt(args[0]); |
2958 | 0 | if (which == -1 && PyErr_Occurred()) { |
2959 | 0 | goto exit; |
2960 | 0 | } |
2961 | 0 | who = PyLong_AsInt(args[1]); |
2962 | 0 | if (who == -1 && PyErr_Occurred()) { |
2963 | 0 | goto exit; |
2964 | 0 | } |
2965 | 0 | priority = PyLong_AsInt(args[2]); |
2966 | 0 | if (priority == -1 && PyErr_Occurred()) { |
2967 | 0 | goto exit; |
2968 | 0 | } |
2969 | 0 | return_value = os_setpriority_impl(module, which, who, priority); |
2970 | |
|
2971 | 0 | exit: |
2972 | 0 | return return_value; |
2973 | 0 | } |
2974 | | |
2975 | | #endif /* defined(HAVE_SETPRIORITY) */ |
2976 | | |
2977 | | PyDoc_STRVAR(os_rename__doc__, |
2978 | | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
2979 | | "--\n" |
2980 | | "\n" |
2981 | | "Rename a file or directory.\n" |
2982 | | "\n" |
2983 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
2984 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
2985 | | " should be relative; the path will then be relative to that directory.\n" |
2986 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
2987 | | " If they are unavailable, using them will raise a NotImplementedError."); |
2988 | | |
2989 | | #define OS_RENAME_METHODDEF \ |
2990 | | {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
2991 | | |
2992 | | static PyObject * |
2993 | | os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
2994 | | int dst_dir_fd); |
2995 | | |
2996 | | static PyObject * |
2997 | | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2998 | 0 | { |
2999 | 0 | PyObject *return_value = NULL; |
3000 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3001 | |
|
3002 | 0 | #define NUM_KEYWORDS 4 |
3003 | 0 | static struct { |
3004 | 0 | PyGC_Head _this_is_not_used; |
3005 | 0 | PyObject_VAR_HEAD |
3006 | 0 | Py_hash_t ob_hash; |
3007 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3008 | 0 | } _kwtuple = { |
3009 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3010 | 0 | .ob_hash = -1, |
3011 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
3012 | 0 | }; |
3013 | 0 | #undef NUM_KEYWORDS |
3014 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3015 | |
|
3016 | | #else // !Py_BUILD_CORE |
3017 | | # define KWTUPLE NULL |
3018 | | #endif // !Py_BUILD_CORE |
3019 | |
|
3020 | 0 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
3021 | 0 | static _PyArg_Parser _parser = { |
3022 | 0 | .keywords = _keywords, |
3023 | 0 | .fname = "rename", |
3024 | 0 | .kwtuple = KWTUPLE, |
3025 | 0 | }; |
3026 | 0 | #undef KWTUPLE |
3027 | 0 | PyObject *argsbuf[4]; |
3028 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
3029 | 0 | path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0); |
3030 | 0 | path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0); |
3031 | 0 | int src_dir_fd = DEFAULT_DIR_FD; |
3032 | 0 | int dst_dir_fd = DEFAULT_DIR_FD; |
3033 | |
|
3034 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3035 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3036 | 0 | if (!args) { |
3037 | 0 | goto exit; |
3038 | 0 | } |
3039 | 0 | if (!path_converter(args[0], &src)) { |
3040 | 0 | goto exit; |
3041 | 0 | } |
3042 | 0 | if (!path_converter(args[1], &dst)) { |
3043 | 0 | goto exit; |
3044 | 0 | } |
3045 | 0 | if (!noptargs) { |
3046 | 0 | goto skip_optional_kwonly; |
3047 | 0 | } |
3048 | 0 | if (args[2]) { |
3049 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3050 | 0 | goto exit; |
3051 | 0 | } |
3052 | 0 | if (!--noptargs) { |
3053 | 0 | goto skip_optional_kwonly; |
3054 | 0 | } |
3055 | 0 | } |
3056 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3057 | 0 | goto exit; |
3058 | 0 | } |
3059 | 0 | skip_optional_kwonly: |
3060 | 0 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3061 | |
|
3062 | 0 | exit: |
3063 | | /* Cleanup for src */ |
3064 | 0 | path_cleanup(&src); |
3065 | | /* Cleanup for dst */ |
3066 | 0 | path_cleanup(&dst); |
3067 | |
|
3068 | 0 | return return_value; |
3069 | 0 | } |
3070 | | |
3071 | | PyDoc_STRVAR(os_replace__doc__, |
3072 | | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
3073 | | "--\n" |
3074 | | "\n" |
3075 | | "Rename a file or directory, overwriting the destination.\n" |
3076 | | "\n" |
3077 | | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
3078 | | " descriptor open to a directory, and the respective path string (src or dst)\n" |
3079 | | " should be relative; the path will then be relative to that directory.\n" |
3080 | | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
3081 | | " If they are unavailable, using them will raise a NotImplementedError."); |
3082 | | |
3083 | | #define OS_REPLACE_METHODDEF \ |
3084 | | {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
3085 | | |
3086 | | static PyObject * |
3087 | | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
3088 | | int dst_dir_fd); |
3089 | | |
3090 | | static PyObject * |
3091 | | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3092 | 241 | { |
3093 | 241 | PyObject *return_value = NULL; |
3094 | 241 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3095 | | |
3096 | 241 | #define NUM_KEYWORDS 4 |
3097 | 241 | static struct { |
3098 | 241 | PyGC_Head _this_is_not_used; |
3099 | 241 | PyObject_VAR_HEAD |
3100 | 241 | Py_hash_t ob_hash; |
3101 | 241 | PyObject *ob_item[NUM_KEYWORDS]; |
3102 | 241 | } _kwtuple = { |
3103 | 241 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3104 | 241 | .ob_hash = -1, |
3105 | 241 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), }, |
3106 | 241 | }; |
3107 | 241 | #undef NUM_KEYWORDS |
3108 | 241 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3109 | | |
3110 | | #else // !Py_BUILD_CORE |
3111 | | # define KWTUPLE NULL |
3112 | | #endif // !Py_BUILD_CORE |
3113 | | |
3114 | 241 | static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; |
3115 | 241 | static _PyArg_Parser _parser = { |
3116 | 241 | .keywords = _keywords, |
3117 | 241 | .fname = "replace", |
3118 | 241 | .kwtuple = KWTUPLE, |
3119 | 241 | }; |
3120 | 241 | #undef KWTUPLE |
3121 | 241 | PyObject *argsbuf[4]; |
3122 | 241 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
3123 | 241 | path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0); |
3124 | 241 | path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0); |
3125 | 241 | int src_dir_fd = DEFAULT_DIR_FD; |
3126 | 241 | int dst_dir_fd = DEFAULT_DIR_FD; |
3127 | | |
3128 | 241 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3129 | 241 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3130 | 241 | if (!args) { |
3131 | 0 | goto exit; |
3132 | 0 | } |
3133 | 241 | if (!path_converter(args[0], &src)) { |
3134 | 0 | goto exit; |
3135 | 0 | } |
3136 | 241 | if (!path_converter(args[1], &dst)) { |
3137 | 0 | goto exit; |
3138 | 0 | } |
3139 | 241 | if (!noptargs) { |
3140 | 241 | goto skip_optional_kwonly; |
3141 | 241 | } |
3142 | 0 | if (args[2]) { |
3143 | 0 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
3144 | 0 | goto exit; |
3145 | 0 | } |
3146 | 0 | if (!--noptargs) { |
3147 | 0 | goto skip_optional_kwonly; |
3148 | 0 | } |
3149 | 0 | } |
3150 | 0 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
3151 | 0 | goto exit; |
3152 | 0 | } |
3153 | 241 | skip_optional_kwonly: |
3154 | 241 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
3155 | | |
3156 | 241 | exit: |
3157 | | /* Cleanup for src */ |
3158 | 241 | path_cleanup(&src); |
3159 | | /* Cleanup for dst */ |
3160 | 241 | path_cleanup(&dst); |
3161 | | |
3162 | 241 | return return_value; |
3163 | 241 | } |
3164 | | |
3165 | | PyDoc_STRVAR(os_rmdir__doc__, |
3166 | | "rmdir($module, /, path, *, dir_fd=None)\n" |
3167 | | "--\n" |
3168 | | "\n" |
3169 | | "Remove a directory.\n" |
3170 | | "\n" |
3171 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3172 | | " and path should be relative; path will then be relative to that directory.\n" |
3173 | | "dir_fd may not be implemented on your platform.\n" |
3174 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3175 | | |
3176 | | #define OS_RMDIR_METHODDEF \ |
3177 | | {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
3178 | | |
3179 | | static PyObject * |
3180 | | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
3181 | | |
3182 | | static PyObject * |
3183 | | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3184 | 0 | { |
3185 | 0 | PyObject *return_value = NULL; |
3186 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3187 | |
|
3188 | 0 | #define NUM_KEYWORDS 2 |
3189 | 0 | static struct { |
3190 | 0 | PyGC_Head _this_is_not_used; |
3191 | 0 | PyObject_VAR_HEAD |
3192 | 0 | Py_hash_t ob_hash; |
3193 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3194 | 0 | } _kwtuple = { |
3195 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3196 | 0 | .ob_hash = -1, |
3197 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3198 | 0 | }; |
3199 | 0 | #undef NUM_KEYWORDS |
3200 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3201 | |
|
3202 | | #else // !Py_BUILD_CORE |
3203 | | # define KWTUPLE NULL |
3204 | | #endif // !Py_BUILD_CORE |
3205 | |
|
3206 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3207 | 0 | static _PyArg_Parser _parser = { |
3208 | 0 | .keywords = _keywords, |
3209 | 0 | .fname = "rmdir", |
3210 | 0 | .kwtuple = KWTUPLE, |
3211 | 0 | }; |
3212 | 0 | #undef KWTUPLE |
3213 | 0 | PyObject *argsbuf[2]; |
3214 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3215 | 0 | path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0); |
3216 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3217 | |
|
3218 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3219 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3220 | 0 | if (!args) { |
3221 | 0 | goto exit; |
3222 | 0 | } |
3223 | 0 | if (!path_converter(args[0], &path)) { |
3224 | 0 | goto exit; |
3225 | 0 | } |
3226 | 0 | if (!noptargs) { |
3227 | 0 | goto skip_optional_kwonly; |
3228 | 0 | } |
3229 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3230 | 0 | goto exit; |
3231 | 0 | } |
3232 | 0 | skip_optional_kwonly: |
3233 | 0 | return_value = os_rmdir_impl(module, &path, dir_fd); |
3234 | |
|
3235 | 0 | exit: |
3236 | | /* Cleanup for path */ |
3237 | 0 | path_cleanup(&path); |
3238 | |
|
3239 | 0 | return return_value; |
3240 | 0 | } |
3241 | | |
3242 | | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
3243 | | |
3244 | | PyDoc_STRVAR(os_system__doc__, |
3245 | | "system($module, /, command)\n" |
3246 | | "--\n" |
3247 | | "\n" |
3248 | | "Execute the command in a subshell."); |
3249 | | |
3250 | | #define OS_SYSTEM_METHODDEF \ |
3251 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3252 | | |
3253 | | static long |
3254 | | os_system_impl(PyObject *module, const wchar_t *command); |
3255 | | |
3256 | | static PyObject * |
3257 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3258 | | { |
3259 | | PyObject *return_value = NULL; |
3260 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3261 | | |
3262 | | #define NUM_KEYWORDS 1 |
3263 | | static struct { |
3264 | | PyGC_Head _this_is_not_used; |
3265 | | PyObject_VAR_HEAD |
3266 | | Py_hash_t ob_hash; |
3267 | | PyObject *ob_item[NUM_KEYWORDS]; |
3268 | | } _kwtuple = { |
3269 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3270 | | .ob_hash = -1, |
3271 | | .ob_item = { &_Py_ID(command), }, |
3272 | | }; |
3273 | | #undef NUM_KEYWORDS |
3274 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3275 | | |
3276 | | #else // !Py_BUILD_CORE |
3277 | | # define KWTUPLE NULL |
3278 | | #endif // !Py_BUILD_CORE |
3279 | | |
3280 | | static const char * const _keywords[] = {"command", NULL}; |
3281 | | static _PyArg_Parser _parser = { |
3282 | | .keywords = _keywords, |
3283 | | .fname = "system", |
3284 | | .kwtuple = KWTUPLE, |
3285 | | }; |
3286 | | #undef KWTUPLE |
3287 | | PyObject *argsbuf[1]; |
3288 | | const wchar_t *command = NULL; |
3289 | | long _return_value; |
3290 | | |
3291 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3292 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3293 | | if (!args) { |
3294 | | goto exit; |
3295 | | } |
3296 | | if (!PyUnicode_Check(args[0])) { |
3297 | | _PyArg_BadArgument("system", "argument 'command'", "str", args[0]); |
3298 | | goto exit; |
3299 | | } |
3300 | | command = PyUnicode_AsWideCharString(args[0], NULL); |
3301 | | if (command == NULL) { |
3302 | | goto exit; |
3303 | | } |
3304 | | _return_value = os_system_impl(module, command); |
3305 | | if ((_return_value == -1) && PyErr_Occurred()) { |
3306 | | goto exit; |
3307 | | } |
3308 | | return_value = PyLong_FromLong(_return_value); |
3309 | | |
3310 | | exit: |
3311 | | /* Cleanup for command */ |
3312 | | PyMem_Free((void *)command); |
3313 | | |
3314 | | return return_value; |
3315 | | } |
3316 | | |
3317 | | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
3318 | | |
3319 | | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
3320 | | |
3321 | | PyDoc_STRVAR(os_system__doc__, |
3322 | | "system($module, /, command)\n" |
3323 | | "--\n" |
3324 | | "\n" |
3325 | | "Execute the command in a subshell."); |
3326 | | |
3327 | | #define OS_SYSTEM_METHODDEF \ |
3328 | | {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
3329 | | |
3330 | | static long |
3331 | | os_system_impl(PyObject *module, PyObject *command); |
3332 | | |
3333 | | static PyObject * |
3334 | | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3335 | 0 | { |
3336 | 0 | PyObject *return_value = NULL; |
3337 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3338 | |
|
3339 | 0 | #define NUM_KEYWORDS 1 |
3340 | 0 | static struct { |
3341 | 0 | PyGC_Head _this_is_not_used; |
3342 | 0 | PyObject_VAR_HEAD |
3343 | 0 | Py_hash_t ob_hash; |
3344 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3345 | 0 | } _kwtuple = { |
3346 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3347 | 0 | .ob_hash = -1, |
3348 | 0 | .ob_item = { &_Py_ID(command), }, |
3349 | 0 | }; |
3350 | 0 | #undef NUM_KEYWORDS |
3351 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3352 | |
|
3353 | | #else // !Py_BUILD_CORE |
3354 | | # define KWTUPLE NULL |
3355 | | #endif // !Py_BUILD_CORE |
3356 | |
|
3357 | 0 | static const char * const _keywords[] = {"command", NULL}; |
3358 | 0 | static _PyArg_Parser _parser = { |
3359 | 0 | .keywords = _keywords, |
3360 | 0 | .fname = "system", |
3361 | 0 | .kwtuple = KWTUPLE, |
3362 | 0 | }; |
3363 | 0 | #undef KWTUPLE |
3364 | 0 | PyObject *argsbuf[1]; |
3365 | 0 | PyObject *command = NULL; |
3366 | 0 | long _return_value; |
3367 | |
|
3368 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3369 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3370 | 0 | if (!args) { |
3371 | 0 | goto exit; |
3372 | 0 | } |
3373 | 0 | if (!PyUnicode_FSConverter(args[0], &command)) { |
3374 | 0 | goto exit; |
3375 | 0 | } |
3376 | 0 | _return_value = os_system_impl(module, command); |
3377 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
3378 | 0 | goto exit; |
3379 | 0 | } |
3380 | 0 | return_value = PyLong_FromLong(_return_value); |
3381 | |
|
3382 | 0 | exit: |
3383 | | /* Cleanup for command */ |
3384 | 0 | Py_XDECREF(command); |
3385 | |
|
3386 | 0 | return return_value; |
3387 | 0 | } |
3388 | | |
3389 | | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
3390 | | |
3391 | | #if defined(HAVE_UMASK) |
3392 | | |
3393 | | PyDoc_STRVAR(os_umask__doc__, |
3394 | | "umask($module, mask, /)\n" |
3395 | | "--\n" |
3396 | | "\n" |
3397 | | "Set the current numeric umask and return the previous umask."); |
3398 | | |
3399 | | #define OS_UMASK_METHODDEF \ |
3400 | | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
3401 | | |
3402 | | static PyObject * |
3403 | | os_umask_impl(PyObject *module, int mask); |
3404 | | |
3405 | | static PyObject * |
3406 | | os_umask(PyObject *module, PyObject *arg) |
3407 | 0 | { |
3408 | 0 | PyObject *return_value = NULL; |
3409 | 0 | int mask; |
3410 | |
|
3411 | 0 | mask = PyLong_AsInt(arg); |
3412 | 0 | if (mask == -1 && PyErr_Occurred()) { |
3413 | 0 | goto exit; |
3414 | 0 | } |
3415 | 0 | return_value = os_umask_impl(module, mask); |
3416 | |
|
3417 | 0 | exit: |
3418 | 0 | return return_value; |
3419 | 0 | } |
3420 | | |
3421 | | #endif /* defined(HAVE_UMASK) */ |
3422 | | |
3423 | | PyDoc_STRVAR(os_unlink__doc__, |
3424 | | "unlink($module, /, path, *, dir_fd=None)\n" |
3425 | | "--\n" |
3426 | | "\n" |
3427 | | "Remove a file (same as remove()).\n" |
3428 | | "\n" |
3429 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3430 | | " and path should be relative; path will then be relative to that directory.\n" |
3431 | | "dir_fd may not be implemented on your platform.\n" |
3432 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3433 | | |
3434 | | #define OS_UNLINK_METHODDEF \ |
3435 | | {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
3436 | | |
3437 | | static PyObject * |
3438 | | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
3439 | | |
3440 | | static PyObject * |
3441 | | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3442 | 0 | { |
3443 | 0 | PyObject *return_value = NULL; |
3444 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3445 | |
|
3446 | 0 | #define NUM_KEYWORDS 2 |
3447 | 0 | static struct { |
3448 | 0 | PyGC_Head _this_is_not_used; |
3449 | 0 | PyObject_VAR_HEAD |
3450 | 0 | Py_hash_t ob_hash; |
3451 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3452 | 0 | } _kwtuple = { |
3453 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3454 | 0 | .ob_hash = -1, |
3455 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3456 | 0 | }; |
3457 | 0 | #undef NUM_KEYWORDS |
3458 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3459 | |
|
3460 | | #else // !Py_BUILD_CORE |
3461 | | # define KWTUPLE NULL |
3462 | | #endif // !Py_BUILD_CORE |
3463 | |
|
3464 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3465 | 0 | static _PyArg_Parser _parser = { |
3466 | 0 | .keywords = _keywords, |
3467 | 0 | .fname = "unlink", |
3468 | 0 | .kwtuple = KWTUPLE, |
3469 | 0 | }; |
3470 | 0 | #undef KWTUPLE |
3471 | 0 | PyObject *argsbuf[2]; |
3472 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3473 | 0 | path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0); |
3474 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3475 | |
|
3476 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3477 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3478 | 0 | if (!args) { |
3479 | 0 | goto exit; |
3480 | 0 | } |
3481 | 0 | if (!path_converter(args[0], &path)) { |
3482 | 0 | goto exit; |
3483 | 0 | } |
3484 | 0 | if (!noptargs) { |
3485 | 0 | goto skip_optional_kwonly; |
3486 | 0 | } |
3487 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3488 | 0 | goto exit; |
3489 | 0 | } |
3490 | 0 | skip_optional_kwonly: |
3491 | 0 | return_value = os_unlink_impl(module, &path, dir_fd); |
3492 | |
|
3493 | 0 | exit: |
3494 | | /* Cleanup for path */ |
3495 | 0 | path_cleanup(&path); |
3496 | |
|
3497 | 0 | return return_value; |
3498 | 0 | } |
3499 | | |
3500 | | PyDoc_STRVAR(os_remove__doc__, |
3501 | | "remove($module, /, path, *, dir_fd=None)\n" |
3502 | | "--\n" |
3503 | | "\n" |
3504 | | "Remove a file (same as unlink()).\n" |
3505 | | "\n" |
3506 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3507 | | " and path should be relative; path will then be relative to that directory.\n" |
3508 | | "dir_fd may not be implemented on your platform.\n" |
3509 | | " If it is unavailable, using it will raise a NotImplementedError."); |
3510 | | |
3511 | | #define OS_REMOVE_METHODDEF \ |
3512 | | {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
3513 | | |
3514 | | static PyObject * |
3515 | | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
3516 | | |
3517 | | static PyObject * |
3518 | | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3519 | 0 | { |
3520 | 0 | PyObject *return_value = NULL; |
3521 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3522 | |
|
3523 | 0 | #define NUM_KEYWORDS 2 |
3524 | 0 | static struct { |
3525 | 0 | PyGC_Head _this_is_not_used; |
3526 | 0 | PyObject_VAR_HEAD |
3527 | 0 | Py_hash_t ob_hash; |
3528 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3529 | 0 | } _kwtuple = { |
3530 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3531 | 0 | .ob_hash = -1, |
3532 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
3533 | 0 | }; |
3534 | 0 | #undef NUM_KEYWORDS |
3535 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3536 | |
|
3537 | | #else // !Py_BUILD_CORE |
3538 | | # define KWTUPLE NULL |
3539 | | #endif // !Py_BUILD_CORE |
3540 | |
|
3541 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
3542 | 0 | static _PyArg_Parser _parser = { |
3543 | 0 | .keywords = _keywords, |
3544 | 0 | .fname = "remove", |
3545 | 0 | .kwtuple = KWTUPLE, |
3546 | 0 | }; |
3547 | 0 | #undef KWTUPLE |
3548 | 0 | PyObject *argsbuf[2]; |
3549 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3550 | 0 | path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0); |
3551 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3552 | |
|
3553 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3554 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3555 | 0 | if (!args) { |
3556 | 0 | goto exit; |
3557 | 0 | } |
3558 | 0 | if (!path_converter(args[0], &path)) { |
3559 | 0 | goto exit; |
3560 | 0 | } |
3561 | 0 | if (!noptargs) { |
3562 | 0 | goto skip_optional_kwonly; |
3563 | 0 | } |
3564 | 0 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
3565 | 0 | goto exit; |
3566 | 0 | } |
3567 | 0 | skip_optional_kwonly: |
3568 | 0 | return_value = os_remove_impl(module, &path, dir_fd); |
3569 | |
|
3570 | 0 | exit: |
3571 | | /* Cleanup for path */ |
3572 | 0 | path_cleanup(&path); |
3573 | |
|
3574 | 0 | return return_value; |
3575 | 0 | } |
3576 | | |
3577 | | #if defined(HAVE_UNAME) |
3578 | | |
3579 | | PyDoc_STRVAR(os_uname__doc__, |
3580 | | "uname($module, /)\n" |
3581 | | "--\n" |
3582 | | "\n" |
3583 | | "Return an object identifying the current operating system.\n" |
3584 | | "\n" |
3585 | | "The object behaves like a named tuple with the following fields:\n" |
3586 | | " (sysname, nodename, release, version, machine)"); |
3587 | | |
3588 | | #define OS_UNAME_METHODDEF \ |
3589 | | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
3590 | | |
3591 | | static PyObject * |
3592 | | os_uname_impl(PyObject *module); |
3593 | | |
3594 | | static PyObject * |
3595 | | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3596 | 0 | { |
3597 | 0 | return os_uname_impl(module); |
3598 | 0 | } |
3599 | | |
3600 | | #endif /* defined(HAVE_UNAME) */ |
3601 | | |
3602 | | PyDoc_STRVAR(os_utime__doc__, |
3603 | | "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n" |
3604 | | " dir_fd=None, follow_symlinks=True)\n" |
3605 | | "--\n" |
3606 | | "\n" |
3607 | | "Set the access and modified time of path.\n" |
3608 | | "\n" |
3609 | | "path may always be specified as a string.\n" |
3610 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
3611 | | " If this functionality is unavailable, using it raises an exception.\n" |
3612 | | "\n" |
3613 | | "If times is not None, it must be a tuple (atime, mtime);\n" |
3614 | | " atime and mtime should be expressed as float seconds since the epoch.\n" |
3615 | | "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n" |
3616 | | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
3617 | | " since the epoch.\n" |
3618 | | "If times is None and ns is unspecified, utime uses the current time.\n" |
3619 | | "Specifying tuples for both times and ns is an error.\n" |
3620 | | "\n" |
3621 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
3622 | | " and path should be relative; path will then be relative to that directory.\n" |
3623 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
3624 | | " link, utime will modify the symbolic link itself instead of the file the\n" |
3625 | | " link points to.\n" |
3626 | | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
3627 | | " as an open file descriptor.\n" |
3628 | | "dir_fd and follow_symlinks may not be available on your platform.\n" |
3629 | | " If they are unavailable, using them will raise a NotImplementedError."); |
3630 | | |
3631 | | #define OS_UTIME_METHODDEF \ |
3632 | | {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
3633 | | |
3634 | | static PyObject * |
3635 | | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
3636 | | int dir_fd, int follow_symlinks); |
3637 | | |
3638 | | static PyObject * |
3639 | | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3640 | 0 | { |
3641 | 0 | PyObject *return_value = NULL; |
3642 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3643 | |
|
3644 | 0 | #define NUM_KEYWORDS 5 |
3645 | 0 | static struct { |
3646 | 0 | PyGC_Head _this_is_not_used; |
3647 | 0 | PyObject_VAR_HEAD |
3648 | 0 | Py_hash_t ob_hash; |
3649 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3650 | 0 | } _kwtuple = { |
3651 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3652 | 0 | .ob_hash = -1, |
3653 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), }, |
3654 | 0 | }; |
3655 | 0 | #undef NUM_KEYWORDS |
3656 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3657 | |
|
3658 | | #else // !Py_BUILD_CORE |
3659 | | # define KWTUPLE NULL |
3660 | | #endif // !Py_BUILD_CORE |
3661 | |
|
3662 | 0 | static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; |
3663 | 0 | static _PyArg_Parser _parser = { |
3664 | 0 | .keywords = _keywords, |
3665 | 0 | .fname = "utime", |
3666 | 0 | .kwtuple = KWTUPLE, |
3667 | 0 | }; |
3668 | 0 | #undef KWTUPLE |
3669 | 0 | PyObject *argsbuf[5]; |
3670 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
3671 | 0 | path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD); |
3672 | 0 | PyObject *times = Py_None; |
3673 | 0 | PyObject *ns = NULL; |
3674 | 0 | int dir_fd = DEFAULT_DIR_FD; |
3675 | 0 | int follow_symlinks = 1; |
3676 | |
|
3677 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3678 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3679 | 0 | if (!args) { |
3680 | 0 | goto exit; |
3681 | 0 | } |
3682 | 0 | if (!path_converter(args[0], &path)) { |
3683 | 0 | goto exit; |
3684 | 0 | } |
3685 | 0 | if (!noptargs) { |
3686 | 0 | goto skip_optional_pos; |
3687 | 0 | } |
3688 | 0 | if (args[1]) { |
3689 | 0 | times = args[1]; |
3690 | 0 | if (!--noptargs) { |
3691 | 0 | goto skip_optional_pos; |
3692 | 0 | } |
3693 | 0 | } |
3694 | 0 | skip_optional_pos: |
3695 | 0 | if (!noptargs) { |
3696 | 0 | goto skip_optional_kwonly; |
3697 | 0 | } |
3698 | 0 | if (args[2]) { |
3699 | 0 | ns = args[2]; |
3700 | 0 | if (!--noptargs) { |
3701 | 0 | goto skip_optional_kwonly; |
3702 | 0 | } |
3703 | 0 | } |
3704 | 0 | if (args[3]) { |
3705 | 0 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
3706 | 0 | goto exit; |
3707 | 0 | } |
3708 | 0 | if (!--noptargs) { |
3709 | 0 | goto skip_optional_kwonly; |
3710 | 0 | } |
3711 | 0 | } |
3712 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
3713 | 0 | if (follow_symlinks < 0) { |
3714 | 0 | goto exit; |
3715 | 0 | } |
3716 | 0 | skip_optional_kwonly: |
3717 | 0 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
3718 | |
|
3719 | 0 | exit: |
3720 | | /* Cleanup for path */ |
3721 | 0 | path_cleanup(&path); |
3722 | |
|
3723 | 0 | return return_value; |
3724 | 0 | } |
3725 | | |
3726 | | PyDoc_STRVAR(os__exit__doc__, |
3727 | | "_exit($module, /, status)\n" |
3728 | | "--\n" |
3729 | | "\n" |
3730 | | "Exit to the system with specified status, without normal exit processing."); |
3731 | | |
3732 | | #define OS__EXIT_METHODDEF \ |
3733 | | {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
3734 | | |
3735 | | static PyObject * |
3736 | | os__exit_impl(PyObject *module, int status); |
3737 | | |
3738 | | static PyObject * |
3739 | | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3740 | 0 | { |
3741 | 0 | PyObject *return_value = NULL; |
3742 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3743 | |
|
3744 | 0 | #define NUM_KEYWORDS 1 |
3745 | 0 | static struct { |
3746 | 0 | PyGC_Head _this_is_not_used; |
3747 | 0 | PyObject_VAR_HEAD |
3748 | 0 | Py_hash_t ob_hash; |
3749 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3750 | 0 | } _kwtuple = { |
3751 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3752 | 0 | .ob_hash = -1, |
3753 | 0 | .ob_item = { &_Py_ID(status), }, |
3754 | 0 | }; |
3755 | 0 | #undef NUM_KEYWORDS |
3756 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3757 | |
|
3758 | | #else // !Py_BUILD_CORE |
3759 | | # define KWTUPLE NULL |
3760 | | #endif // !Py_BUILD_CORE |
3761 | |
|
3762 | 0 | static const char * const _keywords[] = {"status", NULL}; |
3763 | 0 | static _PyArg_Parser _parser = { |
3764 | 0 | .keywords = _keywords, |
3765 | 0 | .fname = "_exit", |
3766 | 0 | .kwtuple = KWTUPLE, |
3767 | 0 | }; |
3768 | 0 | #undef KWTUPLE |
3769 | 0 | PyObject *argsbuf[1]; |
3770 | 0 | int status; |
3771 | |
|
3772 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3773 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3774 | 0 | if (!args) { |
3775 | 0 | goto exit; |
3776 | 0 | } |
3777 | 0 | status = PyLong_AsInt(args[0]); |
3778 | 0 | if (status == -1 && PyErr_Occurred()) { |
3779 | 0 | goto exit; |
3780 | 0 | } |
3781 | 0 | return_value = os__exit_impl(module, status); |
3782 | |
|
3783 | 0 | exit: |
3784 | 0 | return return_value; |
3785 | 0 | } |
3786 | | |
3787 | | #if defined(HAVE_EXECV) |
3788 | | |
3789 | | PyDoc_STRVAR(os_execv__doc__, |
3790 | | "execv($module, path, argv, /)\n" |
3791 | | "--\n" |
3792 | | "\n" |
3793 | | "Execute an executable path with arguments, replacing current process.\n" |
3794 | | "\n" |
3795 | | " path\n" |
3796 | | " Path of executable file.\n" |
3797 | | " argv\n" |
3798 | | " Tuple or list of strings."); |
3799 | | |
3800 | | #define OS_EXECV_METHODDEF \ |
3801 | | {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__}, |
3802 | | |
3803 | | static PyObject * |
3804 | | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
3805 | | |
3806 | | static PyObject * |
3807 | | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3808 | 0 | { |
3809 | 0 | PyObject *return_value = NULL; |
3810 | 0 | path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0); |
3811 | 0 | PyObject *argv; |
3812 | |
|
3813 | 0 | if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { |
3814 | 0 | goto exit; |
3815 | 0 | } |
3816 | 0 | if (!path_converter(args[0], &path)) { |
3817 | 0 | goto exit; |
3818 | 0 | } |
3819 | 0 | argv = args[1]; |
3820 | 0 | return_value = os_execv_impl(module, &path, argv); |
3821 | |
|
3822 | 0 | exit: |
3823 | | /* Cleanup for path */ |
3824 | 0 | path_cleanup(&path); |
3825 | |
|
3826 | 0 | return return_value; |
3827 | 0 | } |
3828 | | |
3829 | | #endif /* defined(HAVE_EXECV) */ |
3830 | | |
3831 | | #if defined(HAVE_EXECV) |
3832 | | |
3833 | | PyDoc_STRVAR(os_execve__doc__, |
3834 | | "execve($module, /, path, argv, env)\n" |
3835 | | "--\n" |
3836 | | "\n" |
3837 | | "Execute an executable path with arguments, replacing current process.\n" |
3838 | | "\n" |
3839 | | " path\n" |
3840 | | " Path of executable file.\n" |
3841 | | " argv\n" |
3842 | | " Tuple or list of strings.\n" |
3843 | | " env\n" |
3844 | | " Dictionary of strings mapping to strings."); |
3845 | | |
3846 | | #define OS_EXECVE_METHODDEF \ |
3847 | | {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
3848 | | |
3849 | | static PyObject * |
3850 | | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
3851 | | |
3852 | | static PyObject * |
3853 | | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3854 | 0 | { |
3855 | 0 | PyObject *return_value = NULL; |
3856 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3857 | |
|
3858 | 0 | #define NUM_KEYWORDS 3 |
3859 | 0 | static struct { |
3860 | 0 | PyGC_Head _this_is_not_used; |
3861 | 0 | PyObject_VAR_HEAD |
3862 | 0 | Py_hash_t ob_hash; |
3863 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3864 | 0 | } _kwtuple = { |
3865 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3866 | 0 | .ob_hash = -1, |
3867 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), }, |
3868 | 0 | }; |
3869 | 0 | #undef NUM_KEYWORDS |
3870 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3871 | |
|
3872 | | #else // !Py_BUILD_CORE |
3873 | | # define KWTUPLE NULL |
3874 | | #endif // !Py_BUILD_CORE |
3875 | |
|
3876 | 0 | static const char * const _keywords[] = {"path", "argv", "env", NULL}; |
3877 | 0 | static _PyArg_Parser _parser = { |
3878 | 0 | .keywords = _keywords, |
3879 | 0 | .fname = "execve", |
3880 | 0 | .kwtuple = KWTUPLE, |
3881 | 0 | }; |
3882 | 0 | #undef KWTUPLE |
3883 | 0 | PyObject *argsbuf[3]; |
3884 | 0 | path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE); |
3885 | 0 | PyObject *argv; |
3886 | 0 | PyObject *env; |
3887 | |
|
3888 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3889 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3890 | 0 | if (!args) { |
3891 | 0 | goto exit; |
3892 | 0 | } |
3893 | 0 | if (!path_converter(args[0], &path)) { |
3894 | 0 | goto exit; |
3895 | 0 | } |
3896 | 0 | argv = args[1]; |
3897 | 0 | env = args[2]; |
3898 | 0 | return_value = os_execve_impl(module, &path, argv, env); |
3899 | |
|
3900 | 0 | exit: |
3901 | | /* Cleanup for path */ |
3902 | 0 | path_cleanup(&path); |
3903 | |
|
3904 | 0 | return return_value; |
3905 | 0 | } |
3906 | | |
3907 | | #endif /* defined(HAVE_EXECV) */ |
3908 | | |
3909 | | #if defined(HAVE_POSIX_SPAWN) |
3910 | | |
3911 | | PyDoc_STRVAR(os_posix_spawn__doc__, |
3912 | | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
3913 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
3914 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
3915 | | "--\n" |
3916 | | "\n" |
3917 | | "Execute the program specified by path in a new process.\n" |
3918 | | "\n" |
3919 | | " path\n" |
3920 | | " Path of executable file.\n" |
3921 | | " argv\n" |
3922 | | " Tuple or list of strings.\n" |
3923 | | " env\n" |
3924 | | " Dictionary of strings mapping to strings.\n" |
3925 | | " file_actions\n" |
3926 | | " A sequence of file action tuples.\n" |
3927 | | " setpgroup\n" |
3928 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
3929 | | " resetids\n" |
3930 | | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
3931 | | " setsid\n" |
3932 | | " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
3933 | | " setsigmask\n" |
3934 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
3935 | | " setsigdef\n" |
3936 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
3937 | | " scheduler\n" |
3938 | | " A tuple with the scheduler policy (optional) and parameters."); |
3939 | | |
3940 | | #define OS_POSIX_SPAWN_METHODDEF \ |
3941 | | {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
3942 | | |
3943 | | static PyObject * |
3944 | | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
3945 | | PyObject *env, PyObject *file_actions, |
3946 | | PyObject *setpgroup, int resetids, int setsid, |
3947 | | PyObject *setsigmask, PyObject *setsigdef, |
3948 | | PyObject *scheduler); |
3949 | | |
3950 | | static PyObject * |
3951 | | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3952 | 0 | { |
3953 | 0 | PyObject *return_value = NULL; |
3954 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
3955 | |
|
3956 | 0 | #define NUM_KEYWORDS 7 |
3957 | 0 | static struct { |
3958 | 0 | PyGC_Head _this_is_not_used; |
3959 | 0 | PyObject_VAR_HEAD |
3960 | 0 | Py_hash_t ob_hash; |
3961 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
3962 | 0 | } _kwtuple = { |
3963 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
3964 | 0 | .ob_hash = -1, |
3965 | 0 | .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), }, |
3966 | 0 | }; |
3967 | 0 | #undef NUM_KEYWORDS |
3968 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
3969 | |
|
3970 | | #else // !Py_BUILD_CORE |
3971 | | # define KWTUPLE NULL |
3972 | | #endif // !Py_BUILD_CORE |
3973 | |
|
3974 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
3975 | 0 | static _PyArg_Parser _parser = { |
3976 | 0 | .keywords = _keywords, |
3977 | 0 | .fname = "posix_spawn", |
3978 | 0 | .kwtuple = KWTUPLE, |
3979 | 0 | }; |
3980 | 0 | #undef KWTUPLE |
3981 | 0 | PyObject *argsbuf[10]; |
3982 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
3983 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0); |
3984 | 0 | PyObject *argv; |
3985 | 0 | PyObject *env; |
3986 | 0 | PyObject *file_actions = NULL; |
3987 | 0 | PyObject *setpgroup = NULL; |
3988 | 0 | int resetids = 0; |
3989 | 0 | int setsid = 0; |
3990 | 0 | PyObject *setsigmask = NULL; |
3991 | 0 | PyObject *setsigdef = NULL; |
3992 | 0 | PyObject *scheduler = NULL; |
3993 | |
|
3994 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
3995 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
3996 | 0 | if (!args) { |
3997 | 0 | goto exit; |
3998 | 0 | } |
3999 | 0 | if (!path_converter(args[0], &path)) { |
4000 | 0 | goto exit; |
4001 | 0 | } |
4002 | 0 | argv = args[1]; |
4003 | 0 | env = args[2]; |
4004 | 0 | if (!noptargs) { |
4005 | 0 | goto skip_optional_kwonly; |
4006 | 0 | } |
4007 | 0 | if (args[3]) { |
4008 | 0 | file_actions = args[3]; |
4009 | 0 | if (!--noptargs) { |
4010 | 0 | goto skip_optional_kwonly; |
4011 | 0 | } |
4012 | 0 | } |
4013 | 0 | if (args[4]) { |
4014 | 0 | setpgroup = args[4]; |
4015 | 0 | if (!--noptargs) { |
4016 | 0 | goto skip_optional_kwonly; |
4017 | 0 | } |
4018 | 0 | } |
4019 | 0 | if (args[5]) { |
4020 | 0 | resetids = PyObject_IsTrue(args[5]); |
4021 | 0 | if (resetids < 0) { |
4022 | 0 | goto exit; |
4023 | 0 | } |
4024 | 0 | if (!--noptargs) { |
4025 | 0 | goto skip_optional_kwonly; |
4026 | 0 | } |
4027 | 0 | } |
4028 | 0 | if (args[6]) { |
4029 | 0 | setsid = PyObject_IsTrue(args[6]); |
4030 | 0 | if (setsid < 0) { |
4031 | 0 | goto exit; |
4032 | 0 | } |
4033 | 0 | if (!--noptargs) { |
4034 | 0 | goto skip_optional_kwonly; |
4035 | 0 | } |
4036 | 0 | } |
4037 | 0 | if (args[7]) { |
4038 | 0 | setsigmask = args[7]; |
4039 | 0 | if (!--noptargs) { |
4040 | 0 | goto skip_optional_kwonly; |
4041 | 0 | } |
4042 | 0 | } |
4043 | 0 | if (args[8]) { |
4044 | 0 | setsigdef = args[8]; |
4045 | 0 | if (!--noptargs) { |
4046 | 0 | goto skip_optional_kwonly; |
4047 | 0 | } |
4048 | 0 | } |
4049 | 0 | scheduler = args[9]; |
4050 | 0 | skip_optional_kwonly: |
4051 | 0 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4052 | |
|
4053 | 0 | exit: |
4054 | | /* Cleanup for path */ |
4055 | 0 | path_cleanup(&path); |
4056 | |
|
4057 | 0 | return return_value; |
4058 | 0 | } |
4059 | | |
4060 | | #endif /* defined(HAVE_POSIX_SPAWN) */ |
4061 | | |
4062 | | #if defined(HAVE_POSIX_SPAWNP) |
4063 | | |
4064 | | PyDoc_STRVAR(os_posix_spawnp__doc__, |
4065 | | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
4066 | | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
4067 | | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
4068 | | "--\n" |
4069 | | "\n" |
4070 | | "Execute the program specified by path in a new process.\n" |
4071 | | "\n" |
4072 | | " path\n" |
4073 | | " Path of executable file.\n" |
4074 | | " argv\n" |
4075 | | " Tuple or list of strings.\n" |
4076 | | " env\n" |
4077 | | " Dictionary of strings mapping to strings.\n" |
4078 | | " file_actions\n" |
4079 | | " A sequence of file action tuples.\n" |
4080 | | " setpgroup\n" |
4081 | | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
4082 | | " resetids\n" |
4083 | | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
4084 | | " setsid\n" |
4085 | | " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
4086 | | " setsigmask\n" |
4087 | | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
4088 | | " setsigdef\n" |
4089 | | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
4090 | | " scheduler\n" |
4091 | | " A tuple with the scheduler policy (optional) and parameters."); |
4092 | | |
4093 | | #define OS_POSIX_SPAWNP_METHODDEF \ |
4094 | | {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
4095 | | |
4096 | | static PyObject * |
4097 | | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
4098 | | PyObject *env, PyObject *file_actions, |
4099 | | PyObject *setpgroup, int resetids, int setsid, |
4100 | | PyObject *setsigmask, PyObject *setsigdef, |
4101 | | PyObject *scheduler); |
4102 | | |
4103 | | static PyObject * |
4104 | | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4105 | 0 | { |
4106 | 0 | PyObject *return_value = NULL; |
4107 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4108 | |
|
4109 | 0 | #define NUM_KEYWORDS 7 |
4110 | 0 | static struct { |
4111 | 0 | PyGC_Head _this_is_not_used; |
4112 | 0 | PyObject_VAR_HEAD |
4113 | 0 | Py_hash_t ob_hash; |
4114 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4115 | 0 | } _kwtuple = { |
4116 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4117 | 0 | .ob_hash = -1, |
4118 | 0 | .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), }, |
4119 | 0 | }; |
4120 | 0 | #undef NUM_KEYWORDS |
4121 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4122 | |
|
4123 | | #else // !Py_BUILD_CORE |
4124 | | # define KWTUPLE NULL |
4125 | | #endif // !Py_BUILD_CORE |
4126 | |
|
4127 | 0 | static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL}; |
4128 | 0 | static _PyArg_Parser _parser = { |
4129 | 0 | .keywords = _keywords, |
4130 | 0 | .fname = "posix_spawnp", |
4131 | 0 | .kwtuple = KWTUPLE, |
4132 | 0 | }; |
4133 | 0 | #undef KWTUPLE |
4134 | 0 | PyObject *argsbuf[10]; |
4135 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
4136 | 0 | path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0); |
4137 | 0 | PyObject *argv; |
4138 | 0 | PyObject *env; |
4139 | 0 | PyObject *file_actions = NULL; |
4140 | 0 | PyObject *setpgroup = NULL; |
4141 | 0 | int resetids = 0; |
4142 | 0 | int setsid = 0; |
4143 | 0 | PyObject *setsigmask = NULL; |
4144 | 0 | PyObject *setsigdef = NULL; |
4145 | 0 | PyObject *scheduler = NULL; |
4146 | |
|
4147 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4148 | 0 | /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4149 | 0 | if (!args) { |
4150 | 0 | goto exit; |
4151 | 0 | } |
4152 | 0 | if (!path_converter(args[0], &path)) { |
4153 | 0 | goto exit; |
4154 | 0 | } |
4155 | 0 | argv = args[1]; |
4156 | 0 | env = args[2]; |
4157 | 0 | if (!noptargs) { |
4158 | 0 | goto skip_optional_kwonly; |
4159 | 0 | } |
4160 | 0 | if (args[3]) { |
4161 | 0 | file_actions = args[3]; |
4162 | 0 | if (!--noptargs) { |
4163 | 0 | goto skip_optional_kwonly; |
4164 | 0 | } |
4165 | 0 | } |
4166 | 0 | if (args[4]) { |
4167 | 0 | setpgroup = args[4]; |
4168 | 0 | if (!--noptargs) { |
4169 | 0 | goto skip_optional_kwonly; |
4170 | 0 | } |
4171 | 0 | } |
4172 | 0 | if (args[5]) { |
4173 | 0 | resetids = PyObject_IsTrue(args[5]); |
4174 | 0 | if (resetids < 0) { |
4175 | 0 | goto exit; |
4176 | 0 | } |
4177 | 0 | if (!--noptargs) { |
4178 | 0 | goto skip_optional_kwonly; |
4179 | 0 | } |
4180 | 0 | } |
4181 | 0 | if (args[6]) { |
4182 | 0 | setsid = PyObject_IsTrue(args[6]); |
4183 | 0 | if (setsid < 0) { |
4184 | 0 | goto exit; |
4185 | 0 | } |
4186 | 0 | if (!--noptargs) { |
4187 | 0 | goto skip_optional_kwonly; |
4188 | 0 | } |
4189 | 0 | } |
4190 | 0 | if (args[7]) { |
4191 | 0 | setsigmask = args[7]; |
4192 | 0 | if (!--noptargs) { |
4193 | 0 | goto skip_optional_kwonly; |
4194 | 0 | } |
4195 | 0 | } |
4196 | 0 | if (args[8]) { |
4197 | 0 | setsigdef = args[8]; |
4198 | 0 | if (!--noptargs) { |
4199 | 0 | goto skip_optional_kwonly; |
4200 | 0 | } |
4201 | 0 | } |
4202 | 0 | scheduler = args[9]; |
4203 | 0 | skip_optional_kwonly: |
4204 | 0 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
4205 | |
|
4206 | 0 | exit: |
4207 | | /* Cleanup for path */ |
4208 | 0 | path_cleanup(&path); |
4209 | |
|
4210 | 0 | return return_value; |
4211 | 0 | } |
4212 | | |
4213 | | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
4214 | | |
4215 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4216 | | |
4217 | | PyDoc_STRVAR(os_spawnv__doc__, |
4218 | | "spawnv($module, mode, path, argv, /)\n" |
4219 | | "--\n" |
4220 | | "\n" |
4221 | | "Execute the program specified by path in a new process.\n" |
4222 | | "\n" |
4223 | | " mode\n" |
4224 | | " Mode of process creation.\n" |
4225 | | " path\n" |
4226 | | " Path of executable file.\n" |
4227 | | " argv\n" |
4228 | | " Tuple or list of strings."); |
4229 | | |
4230 | | #define OS_SPAWNV_METHODDEF \ |
4231 | | {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__}, |
4232 | | |
4233 | | static PyObject * |
4234 | | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
4235 | | |
4236 | | static PyObject * |
4237 | | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4238 | | { |
4239 | | PyObject *return_value = NULL; |
4240 | | int mode; |
4241 | | path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0); |
4242 | | PyObject *argv; |
4243 | | |
4244 | | if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { |
4245 | | goto exit; |
4246 | | } |
4247 | | mode = PyLong_AsInt(args[0]); |
4248 | | if (mode == -1 && PyErr_Occurred()) { |
4249 | | goto exit; |
4250 | | } |
4251 | | if (!path_converter(args[1], &path)) { |
4252 | | goto exit; |
4253 | | } |
4254 | | argv = args[2]; |
4255 | | return_value = os_spawnv_impl(module, mode, &path, argv); |
4256 | | |
4257 | | exit: |
4258 | | /* Cleanup for path */ |
4259 | | path_cleanup(&path); |
4260 | | |
4261 | | return return_value; |
4262 | | } |
4263 | | |
4264 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4265 | | |
4266 | | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
4267 | | |
4268 | | PyDoc_STRVAR(os_spawnve__doc__, |
4269 | | "spawnve($module, mode, path, argv, env, /)\n" |
4270 | | "--\n" |
4271 | | "\n" |
4272 | | "Execute the program specified by path in a new process.\n" |
4273 | | "\n" |
4274 | | " mode\n" |
4275 | | " Mode of process creation.\n" |
4276 | | " path\n" |
4277 | | " Path of executable file.\n" |
4278 | | " argv\n" |
4279 | | " Tuple or list of strings.\n" |
4280 | | " env\n" |
4281 | | " Dictionary of strings mapping to strings."); |
4282 | | |
4283 | | #define OS_SPAWNVE_METHODDEF \ |
4284 | | {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__}, |
4285 | | |
4286 | | static PyObject * |
4287 | | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
4288 | | PyObject *env); |
4289 | | |
4290 | | static PyObject * |
4291 | | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4292 | | { |
4293 | | PyObject *return_value = NULL; |
4294 | | int mode; |
4295 | | path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0); |
4296 | | PyObject *argv; |
4297 | | PyObject *env; |
4298 | | |
4299 | | if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { |
4300 | | goto exit; |
4301 | | } |
4302 | | mode = PyLong_AsInt(args[0]); |
4303 | | if (mode == -1 && PyErr_Occurred()) { |
4304 | | goto exit; |
4305 | | } |
4306 | | if (!path_converter(args[1], &path)) { |
4307 | | goto exit; |
4308 | | } |
4309 | | argv = args[2]; |
4310 | | env = args[3]; |
4311 | | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
4312 | | |
4313 | | exit: |
4314 | | /* Cleanup for path */ |
4315 | | path_cleanup(&path); |
4316 | | |
4317 | | return return_value; |
4318 | | } |
4319 | | |
4320 | | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
4321 | | |
4322 | | #if defined(HAVE_FORK) |
4323 | | |
4324 | | PyDoc_STRVAR(os_register_at_fork__doc__, |
4325 | | "register_at_fork($module, /, *, before=<unrepresentable>,\n" |
4326 | | " after_in_child=<unrepresentable>,\n" |
4327 | | " after_in_parent=<unrepresentable>)\n" |
4328 | | "--\n" |
4329 | | "\n" |
4330 | | "Register callables to be called when forking a new process.\n" |
4331 | | "\n" |
4332 | | " before\n" |
4333 | | " A callable to be called in the parent before the fork() syscall.\n" |
4334 | | " after_in_child\n" |
4335 | | " A callable to be called in the child after fork().\n" |
4336 | | " after_in_parent\n" |
4337 | | " A callable to be called in the parent after fork().\n" |
4338 | | "\n" |
4339 | | "\'before\' callbacks are called in reverse order.\n" |
4340 | | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order."); |
4341 | | |
4342 | | #define OS_REGISTER_AT_FORK_METHODDEF \ |
4343 | | {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
4344 | | |
4345 | | static PyObject * |
4346 | | os_register_at_fork_impl(PyObject *module, PyObject *before, |
4347 | | PyObject *after_in_child, PyObject *after_in_parent); |
4348 | | |
4349 | | static PyObject * |
4350 | | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4351 | 2 | { |
4352 | 2 | PyObject *return_value = NULL; |
4353 | 2 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4354 | | |
4355 | 2 | #define NUM_KEYWORDS 3 |
4356 | 2 | static struct { |
4357 | 2 | PyGC_Head _this_is_not_used; |
4358 | 2 | PyObject_VAR_HEAD |
4359 | 2 | Py_hash_t ob_hash; |
4360 | 2 | PyObject *ob_item[NUM_KEYWORDS]; |
4361 | 2 | } _kwtuple = { |
4362 | 2 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4363 | 2 | .ob_hash = -1, |
4364 | 2 | .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), }, |
4365 | 2 | }; |
4366 | 2 | #undef NUM_KEYWORDS |
4367 | 2 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4368 | | |
4369 | | #else // !Py_BUILD_CORE |
4370 | | # define KWTUPLE NULL |
4371 | | #endif // !Py_BUILD_CORE |
4372 | | |
4373 | 2 | static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL}; |
4374 | 2 | static _PyArg_Parser _parser = { |
4375 | 2 | .keywords = _keywords, |
4376 | 2 | .fname = "register_at_fork", |
4377 | 2 | .kwtuple = KWTUPLE, |
4378 | 2 | }; |
4379 | 2 | #undef KWTUPLE |
4380 | 2 | PyObject *argsbuf[3]; |
4381 | 2 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
4382 | 2 | PyObject *before = NULL; |
4383 | 2 | PyObject *after_in_child = NULL; |
4384 | 2 | PyObject *after_in_parent = NULL; |
4385 | | |
4386 | 2 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4387 | 2 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4388 | 2 | if (!args) { |
4389 | 0 | goto exit; |
4390 | 0 | } |
4391 | 2 | if (!noptargs) { |
4392 | 0 | goto skip_optional_kwonly; |
4393 | 0 | } |
4394 | 2 | if (args[0]) { |
4395 | 0 | before = args[0]; |
4396 | 0 | if (!--noptargs) { |
4397 | 0 | goto skip_optional_kwonly; |
4398 | 0 | } |
4399 | 0 | } |
4400 | 2 | if (args[1]) { |
4401 | 2 | after_in_child = args[1]; |
4402 | 2 | if (!--noptargs) { |
4403 | 2 | goto skip_optional_kwonly; |
4404 | 2 | } |
4405 | 2 | } |
4406 | 0 | after_in_parent = args[2]; |
4407 | 2 | skip_optional_kwonly: |
4408 | 2 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
4409 | | |
4410 | 2 | exit: |
4411 | 2 | return return_value; |
4412 | 2 | } |
4413 | | |
4414 | | #endif /* defined(HAVE_FORK) */ |
4415 | | |
4416 | | #if defined(HAVE_FORK1) |
4417 | | |
4418 | | PyDoc_STRVAR(os_fork1__doc__, |
4419 | | "fork1($module, /)\n" |
4420 | | "--\n" |
4421 | | "\n" |
4422 | | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
4423 | | "\n" |
4424 | | "Return 0 to child process and PID of child to parent process."); |
4425 | | |
4426 | | #define OS_FORK1_METHODDEF \ |
4427 | | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
4428 | | |
4429 | | static PyObject * |
4430 | | os_fork1_impl(PyObject *module); |
4431 | | |
4432 | | static PyObject * |
4433 | | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4434 | | { |
4435 | | return os_fork1_impl(module); |
4436 | | } |
4437 | | |
4438 | | #endif /* defined(HAVE_FORK1) */ |
4439 | | |
4440 | | #if defined(HAVE_FORK) |
4441 | | |
4442 | | PyDoc_STRVAR(os_fork__doc__, |
4443 | | "fork($module, /)\n" |
4444 | | "--\n" |
4445 | | "\n" |
4446 | | "Fork a child process.\n" |
4447 | | "\n" |
4448 | | "Return 0 to child process and PID of child to parent process."); |
4449 | | |
4450 | | #define OS_FORK_METHODDEF \ |
4451 | | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
4452 | | |
4453 | | static PyObject * |
4454 | | os_fork_impl(PyObject *module); |
4455 | | |
4456 | | static PyObject * |
4457 | | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4458 | 0 | { |
4459 | 0 | return os_fork_impl(module); |
4460 | 0 | } |
4461 | | |
4462 | | #endif /* defined(HAVE_FORK) */ |
4463 | | |
4464 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4465 | | |
4466 | | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
4467 | | "sched_get_priority_max($module, /, policy)\n" |
4468 | | "--\n" |
4469 | | "\n" |
4470 | | "Get the maximum scheduling priority for policy."); |
4471 | | |
4472 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
4473 | | {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
4474 | | |
4475 | | static PyObject * |
4476 | | os_sched_get_priority_max_impl(PyObject *module, int policy); |
4477 | | |
4478 | | static PyObject * |
4479 | | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4480 | 0 | { |
4481 | 0 | PyObject *return_value = NULL; |
4482 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4483 | |
|
4484 | 0 | #define NUM_KEYWORDS 1 |
4485 | 0 | static struct { |
4486 | 0 | PyGC_Head _this_is_not_used; |
4487 | 0 | PyObject_VAR_HEAD |
4488 | 0 | Py_hash_t ob_hash; |
4489 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4490 | 0 | } _kwtuple = { |
4491 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4492 | 0 | .ob_hash = -1, |
4493 | 0 | .ob_item = { &_Py_ID(policy), }, |
4494 | 0 | }; |
4495 | 0 | #undef NUM_KEYWORDS |
4496 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4497 | |
|
4498 | | #else // !Py_BUILD_CORE |
4499 | | # define KWTUPLE NULL |
4500 | | #endif // !Py_BUILD_CORE |
4501 | |
|
4502 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4503 | 0 | static _PyArg_Parser _parser = { |
4504 | 0 | .keywords = _keywords, |
4505 | 0 | .fname = "sched_get_priority_max", |
4506 | 0 | .kwtuple = KWTUPLE, |
4507 | 0 | }; |
4508 | 0 | #undef KWTUPLE |
4509 | 0 | PyObject *argsbuf[1]; |
4510 | 0 | int policy; |
4511 | |
|
4512 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4513 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4514 | 0 | if (!args) { |
4515 | 0 | goto exit; |
4516 | 0 | } |
4517 | 0 | policy = PyLong_AsInt(args[0]); |
4518 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4519 | 0 | goto exit; |
4520 | 0 | } |
4521 | 0 | return_value = os_sched_get_priority_max_impl(module, policy); |
4522 | |
|
4523 | 0 | exit: |
4524 | 0 | return return_value; |
4525 | 0 | } |
4526 | | |
4527 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4528 | | |
4529 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
4530 | | |
4531 | | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
4532 | | "sched_get_priority_min($module, /, policy)\n" |
4533 | | "--\n" |
4534 | | "\n" |
4535 | | "Get the minimum scheduling priority for policy."); |
4536 | | |
4537 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
4538 | | {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
4539 | | |
4540 | | static PyObject * |
4541 | | os_sched_get_priority_min_impl(PyObject *module, int policy); |
4542 | | |
4543 | | static PyObject * |
4544 | | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4545 | 0 | { |
4546 | 0 | PyObject *return_value = NULL; |
4547 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4548 | |
|
4549 | 0 | #define NUM_KEYWORDS 1 |
4550 | 0 | static struct { |
4551 | 0 | PyGC_Head _this_is_not_used; |
4552 | 0 | PyObject_VAR_HEAD |
4553 | 0 | Py_hash_t ob_hash; |
4554 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4555 | 0 | } _kwtuple = { |
4556 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4557 | 0 | .ob_hash = -1, |
4558 | 0 | .ob_item = { &_Py_ID(policy), }, |
4559 | 0 | }; |
4560 | 0 | #undef NUM_KEYWORDS |
4561 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4562 | |
|
4563 | | #else // !Py_BUILD_CORE |
4564 | | # define KWTUPLE NULL |
4565 | | #endif // !Py_BUILD_CORE |
4566 | |
|
4567 | 0 | static const char * const _keywords[] = {"policy", NULL}; |
4568 | 0 | static _PyArg_Parser _parser = { |
4569 | 0 | .keywords = _keywords, |
4570 | 0 | .fname = "sched_get_priority_min", |
4571 | 0 | .kwtuple = KWTUPLE, |
4572 | 0 | }; |
4573 | 0 | #undef KWTUPLE |
4574 | 0 | PyObject *argsbuf[1]; |
4575 | 0 | int policy; |
4576 | |
|
4577 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
4578 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4579 | 0 | if (!args) { |
4580 | 0 | goto exit; |
4581 | 0 | } |
4582 | 0 | policy = PyLong_AsInt(args[0]); |
4583 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4584 | 0 | goto exit; |
4585 | 0 | } |
4586 | 0 | return_value = os_sched_get_priority_min_impl(module, policy); |
4587 | |
|
4588 | 0 | exit: |
4589 | 0 | return return_value; |
4590 | 0 | } |
4591 | | |
4592 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
4593 | | |
4594 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4595 | | |
4596 | | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
4597 | | "sched_getscheduler($module, pid, /)\n" |
4598 | | "--\n" |
4599 | | "\n" |
4600 | | "Get the scheduling policy for the process identified by pid.\n" |
4601 | | "\n" |
4602 | | "Passing 0 for pid returns the scheduling policy for the calling process."); |
4603 | | |
4604 | | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
4605 | | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
4606 | | |
4607 | | static PyObject * |
4608 | | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
4609 | | |
4610 | | static PyObject * |
4611 | | os_sched_getscheduler(PyObject *module, PyObject *arg) |
4612 | 0 | { |
4613 | 0 | PyObject *return_value = NULL; |
4614 | 0 | pid_t pid; |
4615 | |
|
4616 | 0 | pid = PyLong_AsPid(arg); |
4617 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4618 | 0 | goto exit; |
4619 | 0 | } |
4620 | 0 | return_value = os_sched_getscheduler_impl(module, pid); |
4621 | |
|
4622 | 0 | exit: |
4623 | 0 | return return_value; |
4624 | 0 | } |
4625 | | |
4626 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4627 | | |
4628 | | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
4629 | | |
4630 | | PyDoc_STRVAR(os_sched_param__doc__, |
4631 | | "sched_param(sched_priority)\n" |
4632 | | "--\n" |
4633 | | "\n" |
4634 | | "Currently has only one field: sched_priority\n" |
4635 | | "\n" |
4636 | | " sched_priority\n" |
4637 | | " A scheduling parameter."); |
4638 | | |
4639 | | static PyObject * |
4640 | | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
4641 | | |
4642 | | static PyObject * |
4643 | | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
4644 | 0 | { |
4645 | 0 | PyObject *return_value = NULL; |
4646 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
4647 | |
|
4648 | 0 | #define NUM_KEYWORDS 1 |
4649 | 0 | static struct { |
4650 | 0 | PyGC_Head _this_is_not_used; |
4651 | 0 | PyObject_VAR_HEAD |
4652 | 0 | Py_hash_t ob_hash; |
4653 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
4654 | 0 | } _kwtuple = { |
4655 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
4656 | 0 | .ob_hash = -1, |
4657 | 0 | .ob_item = { &_Py_ID(sched_priority), }, |
4658 | 0 | }; |
4659 | 0 | #undef NUM_KEYWORDS |
4660 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
4661 | |
|
4662 | | #else // !Py_BUILD_CORE |
4663 | | # define KWTUPLE NULL |
4664 | | #endif // !Py_BUILD_CORE |
4665 | |
|
4666 | 0 | static const char * const _keywords[] = {"sched_priority", NULL}; |
4667 | 0 | static _PyArg_Parser _parser = { |
4668 | 0 | .keywords = _keywords, |
4669 | 0 | .fname = "sched_param", |
4670 | 0 | .kwtuple = KWTUPLE, |
4671 | 0 | }; |
4672 | 0 | #undef KWTUPLE |
4673 | 0 | PyObject *argsbuf[1]; |
4674 | 0 | PyObject * const *fastargs; |
4675 | 0 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
4676 | 0 | PyObject *sched_priority; |
4677 | |
|
4678 | 0 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
4679 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
4680 | 0 | if (!fastargs) { |
4681 | 0 | goto exit; |
4682 | 0 | } |
4683 | 0 | sched_priority = fastargs[0]; |
4684 | 0 | return_value = os_sched_param_impl(type, sched_priority); |
4685 | |
|
4686 | 0 | exit: |
4687 | 0 | return return_value; |
4688 | 0 | } |
4689 | | |
4690 | | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
4691 | | |
4692 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
4693 | | |
4694 | | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
4695 | | "sched_setscheduler($module, pid, policy, param, /)\n" |
4696 | | "--\n" |
4697 | | "\n" |
4698 | | "Set the scheduling policy for the process identified by pid.\n" |
4699 | | "\n" |
4700 | | "If pid is 0, the calling process is changed.\n" |
4701 | | "param is an instance of sched_param."); |
4702 | | |
4703 | | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
4704 | | {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__}, |
4705 | | |
4706 | | static PyObject * |
4707 | | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
4708 | | PyObject *param_obj); |
4709 | | |
4710 | | static PyObject * |
4711 | | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4712 | 0 | { |
4713 | 0 | PyObject *return_value = NULL; |
4714 | 0 | pid_t pid; |
4715 | 0 | int policy; |
4716 | 0 | PyObject *param_obj; |
4717 | |
|
4718 | 0 | if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) { |
4719 | 0 | goto exit; |
4720 | 0 | } |
4721 | 0 | pid = PyLong_AsPid(args[0]); |
4722 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4723 | 0 | goto exit; |
4724 | 0 | } |
4725 | 0 | policy = PyLong_AsInt(args[1]); |
4726 | 0 | if (policy == -1 && PyErr_Occurred()) { |
4727 | 0 | goto exit; |
4728 | 0 | } |
4729 | 0 | param_obj = args[2]; |
4730 | 0 | return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj); |
4731 | |
|
4732 | 0 | exit: |
4733 | 0 | return return_value; |
4734 | 0 | } |
4735 | | |
4736 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
4737 | | |
4738 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4739 | | |
4740 | | PyDoc_STRVAR(os_sched_getparam__doc__, |
4741 | | "sched_getparam($module, pid, /)\n" |
4742 | | "--\n" |
4743 | | "\n" |
4744 | | "Returns scheduling parameters for the process identified by pid.\n" |
4745 | | "\n" |
4746 | | "If pid is 0, returns parameters for the calling process.\n" |
4747 | | "Return value is an instance of sched_param."); |
4748 | | |
4749 | | #define OS_SCHED_GETPARAM_METHODDEF \ |
4750 | | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
4751 | | |
4752 | | static PyObject * |
4753 | | os_sched_getparam_impl(PyObject *module, pid_t pid); |
4754 | | |
4755 | | static PyObject * |
4756 | | os_sched_getparam(PyObject *module, PyObject *arg) |
4757 | 0 | { |
4758 | 0 | PyObject *return_value = NULL; |
4759 | 0 | pid_t pid; |
4760 | |
|
4761 | 0 | pid = PyLong_AsPid(arg); |
4762 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4763 | 0 | goto exit; |
4764 | 0 | } |
4765 | 0 | return_value = os_sched_getparam_impl(module, pid); |
4766 | |
|
4767 | 0 | exit: |
4768 | 0 | return return_value; |
4769 | 0 | } |
4770 | | |
4771 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4772 | | |
4773 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
4774 | | |
4775 | | PyDoc_STRVAR(os_sched_setparam__doc__, |
4776 | | "sched_setparam($module, pid, param, /)\n" |
4777 | | "--\n" |
4778 | | "\n" |
4779 | | "Set scheduling parameters for the process identified by pid.\n" |
4780 | | "\n" |
4781 | | "If pid is 0, sets parameters for the calling process.\n" |
4782 | | "param should be an instance of sched_param."); |
4783 | | |
4784 | | #define OS_SCHED_SETPARAM_METHODDEF \ |
4785 | | {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__}, |
4786 | | |
4787 | | static PyObject * |
4788 | | os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj); |
4789 | | |
4790 | | static PyObject * |
4791 | | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4792 | 0 | { |
4793 | 0 | PyObject *return_value = NULL; |
4794 | 0 | pid_t pid; |
4795 | 0 | PyObject *param_obj; |
4796 | |
|
4797 | 0 | if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) { |
4798 | 0 | goto exit; |
4799 | 0 | } |
4800 | 0 | pid = PyLong_AsPid(args[0]); |
4801 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4802 | 0 | goto exit; |
4803 | 0 | } |
4804 | 0 | param_obj = args[1]; |
4805 | 0 | return_value = os_sched_setparam_impl(module, pid, param_obj); |
4806 | |
|
4807 | 0 | exit: |
4808 | 0 | return return_value; |
4809 | 0 | } |
4810 | | |
4811 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
4812 | | |
4813 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
4814 | | |
4815 | | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
4816 | | "sched_rr_get_interval($module, pid, /)\n" |
4817 | | "--\n" |
4818 | | "\n" |
4819 | | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
4820 | | "\n" |
4821 | | "Value returned is a float."); |
4822 | | |
4823 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
4824 | | {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__}, |
4825 | | |
4826 | | static double |
4827 | | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
4828 | | |
4829 | | static PyObject * |
4830 | | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
4831 | 0 | { |
4832 | 0 | PyObject *return_value = NULL; |
4833 | 0 | pid_t pid; |
4834 | 0 | double _return_value; |
4835 | |
|
4836 | 0 | pid = PyLong_AsPid(arg); |
4837 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4838 | 0 | goto exit; |
4839 | 0 | } |
4840 | 0 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
4841 | 0 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
4842 | 0 | goto exit; |
4843 | 0 | } |
4844 | 0 | return_value = PyFloat_FromDouble(_return_value); |
4845 | |
|
4846 | 0 | exit: |
4847 | 0 | return return_value; |
4848 | 0 | } |
4849 | | |
4850 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
4851 | | |
4852 | | #if defined(HAVE_SCHED_H) |
4853 | | |
4854 | | PyDoc_STRVAR(os_sched_yield__doc__, |
4855 | | "sched_yield($module, /)\n" |
4856 | | "--\n" |
4857 | | "\n" |
4858 | | "Voluntarily relinquish the CPU."); |
4859 | | |
4860 | | #define OS_SCHED_YIELD_METHODDEF \ |
4861 | | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
4862 | | |
4863 | | static PyObject * |
4864 | | os_sched_yield_impl(PyObject *module); |
4865 | | |
4866 | | static PyObject * |
4867 | | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4868 | 0 | { |
4869 | 0 | return os_sched_yield_impl(module); |
4870 | 0 | } |
4871 | | |
4872 | | #endif /* defined(HAVE_SCHED_H) */ |
4873 | | |
4874 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4875 | | |
4876 | | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
4877 | | "sched_setaffinity($module, pid, mask, /)\n" |
4878 | | "--\n" |
4879 | | "\n" |
4880 | | "Set the CPU affinity of the process identified by pid to mask.\n" |
4881 | | "\n" |
4882 | | "mask should be an iterable of integers identifying CPUs."); |
4883 | | |
4884 | | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
4885 | | {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__}, |
4886 | | |
4887 | | static PyObject * |
4888 | | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
4889 | | |
4890 | | static PyObject * |
4891 | | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4892 | 0 | { |
4893 | 0 | PyObject *return_value = NULL; |
4894 | 0 | pid_t pid; |
4895 | 0 | PyObject *mask; |
4896 | |
|
4897 | 0 | if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) { |
4898 | 0 | goto exit; |
4899 | 0 | } |
4900 | 0 | pid = PyLong_AsPid(args[0]); |
4901 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4902 | 0 | goto exit; |
4903 | 0 | } |
4904 | 0 | mask = args[1]; |
4905 | 0 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
4906 | |
|
4907 | 0 | exit: |
4908 | 0 | return return_value; |
4909 | 0 | } |
4910 | | |
4911 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4912 | | |
4913 | | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
4914 | | |
4915 | | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
4916 | | "sched_getaffinity($module, pid, /)\n" |
4917 | | "--\n" |
4918 | | "\n" |
4919 | | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
4920 | | "\n" |
4921 | | "The affinity is returned as a set of CPU identifiers."); |
4922 | | |
4923 | | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
4924 | | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
4925 | | |
4926 | | static PyObject * |
4927 | | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
4928 | | |
4929 | | static PyObject * |
4930 | | os_sched_getaffinity(PyObject *module, PyObject *arg) |
4931 | 0 | { |
4932 | 0 | PyObject *return_value = NULL; |
4933 | 0 | pid_t pid; |
4934 | |
|
4935 | 0 | pid = PyLong_AsPid(arg); |
4936 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
4937 | 0 | goto exit; |
4938 | 0 | } |
4939 | 0 | return_value = os_sched_getaffinity_impl(module, pid); |
4940 | |
|
4941 | 0 | exit: |
4942 | 0 | return return_value; |
4943 | 0 | } |
4944 | | |
4945 | | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
4946 | | |
4947 | | #if defined(HAVE_POSIX_OPENPT) |
4948 | | |
4949 | | PyDoc_STRVAR(os_posix_openpt__doc__, |
4950 | | "posix_openpt($module, oflag, /)\n" |
4951 | | "--\n" |
4952 | | "\n" |
4953 | | "Open and return a file descriptor for a master pseudo-terminal device.\n" |
4954 | | "\n" |
4955 | | "Performs a posix_openpt() C function call. The oflag argument is used to\n" |
4956 | | "set file status flags and file access modes as specified in the manual page\n" |
4957 | | "of posix_openpt() of your system."); |
4958 | | |
4959 | | #define OS_POSIX_OPENPT_METHODDEF \ |
4960 | | {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__}, |
4961 | | |
4962 | | static int |
4963 | | os_posix_openpt_impl(PyObject *module, int oflag); |
4964 | | |
4965 | | static PyObject * |
4966 | | os_posix_openpt(PyObject *module, PyObject *arg) |
4967 | 0 | { |
4968 | 0 | PyObject *return_value = NULL; |
4969 | 0 | int oflag; |
4970 | 0 | int _return_value; |
4971 | |
|
4972 | 0 | oflag = PyLong_AsInt(arg); |
4973 | 0 | if (oflag == -1 && PyErr_Occurred()) { |
4974 | 0 | goto exit; |
4975 | 0 | } |
4976 | 0 | _return_value = os_posix_openpt_impl(module, oflag); |
4977 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
4978 | 0 | goto exit; |
4979 | 0 | } |
4980 | 0 | return_value = PyLong_FromLong((long)_return_value); |
4981 | |
|
4982 | 0 | exit: |
4983 | 0 | return return_value; |
4984 | 0 | } |
4985 | | |
4986 | | #endif /* defined(HAVE_POSIX_OPENPT) */ |
4987 | | |
4988 | | #if defined(HAVE_GRANTPT) |
4989 | | |
4990 | | PyDoc_STRVAR(os_grantpt__doc__, |
4991 | | "grantpt($module, fd, /)\n" |
4992 | | "--\n" |
4993 | | "\n" |
4994 | | "Grant access to the slave pseudo-terminal device.\n" |
4995 | | "\n" |
4996 | | " fd\n" |
4997 | | " File descriptor of a master pseudo-terminal device.\n" |
4998 | | "\n" |
4999 | | "Performs a grantpt() C function call."); |
5000 | | |
5001 | | #define OS_GRANTPT_METHODDEF \ |
5002 | | {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__}, |
5003 | | |
5004 | | static PyObject * |
5005 | | os_grantpt_impl(PyObject *module, int fd); |
5006 | | |
5007 | | static PyObject * |
5008 | | os_grantpt(PyObject *module, PyObject *arg) |
5009 | 0 | { |
5010 | 0 | PyObject *return_value = NULL; |
5011 | 0 | int fd; |
5012 | |
|
5013 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5014 | 0 | if (fd < 0) { |
5015 | 0 | goto exit; |
5016 | 0 | } |
5017 | 0 | return_value = os_grantpt_impl(module, fd); |
5018 | |
|
5019 | 0 | exit: |
5020 | 0 | return return_value; |
5021 | 0 | } |
5022 | | |
5023 | | #endif /* defined(HAVE_GRANTPT) */ |
5024 | | |
5025 | | #if defined(HAVE_UNLOCKPT) |
5026 | | |
5027 | | PyDoc_STRVAR(os_unlockpt__doc__, |
5028 | | "unlockpt($module, fd, /)\n" |
5029 | | "--\n" |
5030 | | "\n" |
5031 | | "Unlock a pseudo-terminal master/slave pair.\n" |
5032 | | "\n" |
5033 | | " fd\n" |
5034 | | " File descriptor of a master pseudo-terminal device.\n" |
5035 | | "\n" |
5036 | | "Performs an unlockpt() C function call."); |
5037 | | |
5038 | | #define OS_UNLOCKPT_METHODDEF \ |
5039 | | {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__}, |
5040 | | |
5041 | | static PyObject * |
5042 | | os_unlockpt_impl(PyObject *module, int fd); |
5043 | | |
5044 | | static PyObject * |
5045 | | os_unlockpt(PyObject *module, PyObject *arg) |
5046 | 0 | { |
5047 | 0 | PyObject *return_value = NULL; |
5048 | 0 | int fd; |
5049 | |
|
5050 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5051 | 0 | if (fd < 0) { |
5052 | 0 | goto exit; |
5053 | 0 | } |
5054 | 0 | return_value = os_unlockpt_impl(module, fd); |
5055 | |
|
5056 | 0 | exit: |
5057 | 0 | return return_value; |
5058 | 0 | } |
5059 | | |
5060 | | #endif /* defined(HAVE_UNLOCKPT) */ |
5061 | | |
5062 | | #if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) |
5063 | | |
5064 | | PyDoc_STRVAR(os_ptsname__doc__, |
5065 | | "ptsname($module, fd, /)\n" |
5066 | | "--\n" |
5067 | | "\n" |
5068 | | "Return the name of the slave pseudo-terminal device.\n" |
5069 | | "\n" |
5070 | | " fd\n" |
5071 | | " File descriptor of a master pseudo-terminal device.\n" |
5072 | | "\n" |
5073 | | "If the ptsname_r() C function is available, it is called;\n" |
5074 | | "otherwise, performs a ptsname() C function call."); |
5075 | | |
5076 | | #define OS_PTSNAME_METHODDEF \ |
5077 | | {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__}, |
5078 | | |
5079 | | static PyObject * |
5080 | | os_ptsname_impl(PyObject *module, int fd); |
5081 | | |
5082 | | static PyObject * |
5083 | | os_ptsname(PyObject *module, PyObject *arg) |
5084 | 0 | { |
5085 | 0 | PyObject *return_value = NULL; |
5086 | 0 | int fd; |
5087 | |
|
5088 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5089 | 0 | if (fd < 0) { |
5090 | 0 | goto exit; |
5091 | 0 | } |
5092 | 0 | return_value = os_ptsname_impl(module, fd); |
5093 | |
|
5094 | 0 | exit: |
5095 | 0 | return return_value; |
5096 | 0 | } |
5097 | | |
5098 | | #endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */ |
5099 | | |
5100 | | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
5101 | | |
5102 | | PyDoc_STRVAR(os_openpty__doc__, |
5103 | | "openpty($module, /)\n" |
5104 | | "--\n" |
5105 | | "\n" |
5106 | | "Open a pseudo-terminal.\n" |
5107 | | "\n" |
5108 | | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
5109 | | "for both the master and slave ends."); |
5110 | | |
5111 | | #define OS_OPENPTY_METHODDEF \ |
5112 | | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
5113 | | |
5114 | | static PyObject * |
5115 | | os_openpty_impl(PyObject *module); |
5116 | | |
5117 | | static PyObject * |
5118 | | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5119 | 0 | { |
5120 | 0 | return os_openpty_impl(module); |
5121 | 0 | } |
5122 | | |
5123 | | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
5124 | | |
5125 | | #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) |
5126 | | |
5127 | | PyDoc_STRVAR(os_login_tty__doc__, |
5128 | | "login_tty($module, fd, /)\n" |
5129 | | "--\n" |
5130 | | "\n" |
5131 | | "Prepare the tty of which fd is a file descriptor for a new login session.\n" |
5132 | | "\n" |
5133 | | "Make the calling process a session leader; make the tty the\n" |
5134 | | "controlling tty, the stdin, the stdout, and the stderr of the\n" |
5135 | | "calling process; close fd."); |
5136 | | |
5137 | | #define OS_LOGIN_TTY_METHODDEF \ |
5138 | | {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, |
5139 | | |
5140 | | static PyObject * |
5141 | | os_login_tty_impl(PyObject *module, int fd); |
5142 | | |
5143 | | static PyObject * |
5144 | | os_login_tty(PyObject *module, PyObject *arg) |
5145 | 0 | { |
5146 | 0 | PyObject *return_value = NULL; |
5147 | 0 | int fd; |
5148 | |
|
5149 | 0 | fd = PyObject_AsFileDescriptor(arg); |
5150 | 0 | if (fd < 0) { |
5151 | 0 | goto exit; |
5152 | 0 | } |
5153 | 0 | return_value = os_login_tty_impl(module, fd); |
5154 | |
|
5155 | 0 | exit: |
5156 | 0 | return return_value; |
5157 | 0 | } |
5158 | | |
5159 | | #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ |
5160 | | |
5161 | | #if defined(HAVE_FORKPTY) |
5162 | | |
5163 | | PyDoc_STRVAR(os_forkpty__doc__, |
5164 | | "forkpty($module, /)\n" |
5165 | | "--\n" |
5166 | | "\n" |
5167 | | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
5168 | | "\n" |
5169 | | "Returns a tuple of (pid, master_fd).\n" |
5170 | | "Like fork(), return pid of 0 to the child process,\n" |
5171 | | "and pid of child to the parent process.\n" |
5172 | | "To both, return fd of newly opened pseudo-terminal.\n" |
5173 | | "The master_fd is non-inheritable."); |
5174 | | |
5175 | | #define OS_FORKPTY_METHODDEF \ |
5176 | | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
5177 | | |
5178 | | static PyObject * |
5179 | | os_forkpty_impl(PyObject *module); |
5180 | | |
5181 | | static PyObject * |
5182 | | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5183 | 0 | { |
5184 | 0 | return os_forkpty_impl(module); |
5185 | 0 | } |
5186 | | |
5187 | | #endif /* defined(HAVE_FORKPTY) */ |
5188 | | |
5189 | | #if defined(HAVE_GETEGID) |
5190 | | |
5191 | | PyDoc_STRVAR(os_getegid__doc__, |
5192 | | "getegid($module, /)\n" |
5193 | | "--\n" |
5194 | | "\n" |
5195 | | "Return the current process\'s effective group id."); |
5196 | | |
5197 | | #define OS_GETEGID_METHODDEF \ |
5198 | | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
5199 | | |
5200 | | static PyObject * |
5201 | | os_getegid_impl(PyObject *module); |
5202 | | |
5203 | | static PyObject * |
5204 | | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5205 | 16 | { |
5206 | 16 | return os_getegid_impl(module); |
5207 | 16 | } |
5208 | | |
5209 | | #endif /* defined(HAVE_GETEGID) */ |
5210 | | |
5211 | | #if defined(HAVE_GETEUID) |
5212 | | |
5213 | | PyDoc_STRVAR(os_geteuid__doc__, |
5214 | | "geteuid($module, /)\n" |
5215 | | "--\n" |
5216 | | "\n" |
5217 | | "Return the current process\'s effective user id."); |
5218 | | |
5219 | | #define OS_GETEUID_METHODDEF \ |
5220 | | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
5221 | | |
5222 | | static PyObject * |
5223 | | os_geteuid_impl(PyObject *module); |
5224 | | |
5225 | | static PyObject * |
5226 | | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5227 | 16 | { |
5228 | 16 | return os_geteuid_impl(module); |
5229 | 16 | } |
5230 | | |
5231 | | #endif /* defined(HAVE_GETEUID) */ |
5232 | | |
5233 | | #if defined(HAVE_GETGID) |
5234 | | |
5235 | | PyDoc_STRVAR(os_getgid__doc__, |
5236 | | "getgid($module, /)\n" |
5237 | | "--\n" |
5238 | | "\n" |
5239 | | "Return the current process\'s group id."); |
5240 | | |
5241 | | #define OS_GETGID_METHODDEF \ |
5242 | | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
5243 | | |
5244 | | static PyObject * |
5245 | | os_getgid_impl(PyObject *module); |
5246 | | |
5247 | | static PyObject * |
5248 | | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5249 | 16 | { |
5250 | 16 | return os_getgid_impl(module); |
5251 | 16 | } |
5252 | | |
5253 | | #endif /* defined(HAVE_GETGID) */ |
5254 | | |
5255 | | #if defined(HAVE_GETPID) |
5256 | | |
5257 | | PyDoc_STRVAR(os_getpid__doc__, |
5258 | | "getpid($module, /)\n" |
5259 | | "--\n" |
5260 | | "\n" |
5261 | | "Return the current process id."); |
5262 | | |
5263 | | #define OS_GETPID_METHODDEF \ |
5264 | | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
5265 | | |
5266 | | static PyObject * |
5267 | | os_getpid_impl(PyObject *module); |
5268 | | |
5269 | | static PyObject * |
5270 | | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5271 | 0 | { |
5272 | 0 | return os_getpid_impl(module); |
5273 | 0 | } |
5274 | | |
5275 | | #endif /* defined(HAVE_GETPID) */ |
5276 | | |
5277 | | #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__) |
5278 | | |
5279 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5280 | | "getgrouplist($module, user, group, /)\n" |
5281 | | "--\n" |
5282 | | "\n" |
5283 | | "Returns a list of groups to which a user belongs.\n" |
5284 | | "\n" |
5285 | | " user\n" |
5286 | | " username to lookup\n" |
5287 | | " group\n" |
5288 | | " base group id of the user"); |
5289 | | |
5290 | | #define OS_GETGROUPLIST_METHODDEF \ |
5291 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5292 | | |
5293 | | static PyObject * |
5294 | | os_getgrouplist_impl(PyObject *module, const char *user, int basegid); |
5295 | | |
5296 | | static PyObject * |
5297 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5298 | | { |
5299 | | PyObject *return_value = NULL; |
5300 | | const char *user; |
5301 | | int basegid; |
5302 | | |
5303 | | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5304 | | goto exit; |
5305 | | } |
5306 | | if (!PyUnicode_Check(args[0])) { |
5307 | | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5308 | | goto exit; |
5309 | | } |
5310 | | Py_ssize_t user_length; |
5311 | | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5312 | | if (user == NULL) { |
5313 | | goto exit; |
5314 | | } |
5315 | | if (strlen(user) != (size_t)user_length) { |
5316 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5317 | | goto exit; |
5318 | | } |
5319 | | basegid = PyLong_AsInt(args[1]); |
5320 | | if (basegid == -1 && PyErr_Occurred()) { |
5321 | | goto exit; |
5322 | | } |
5323 | | return_value = os_getgrouplist_impl(module, user, basegid); |
5324 | | |
5325 | | exit: |
5326 | | return return_value; |
5327 | | } |
5328 | | |
5329 | | #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */ |
5330 | | |
5331 | | #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) |
5332 | | |
5333 | | PyDoc_STRVAR(os_getgrouplist__doc__, |
5334 | | "getgrouplist($module, user, group, /)\n" |
5335 | | "--\n" |
5336 | | "\n" |
5337 | | "Returns a list of groups to which a user belongs.\n" |
5338 | | "\n" |
5339 | | " user\n" |
5340 | | " username to lookup\n" |
5341 | | " group\n" |
5342 | | " base group id of the user"); |
5343 | | |
5344 | | #define OS_GETGROUPLIST_METHODDEF \ |
5345 | | {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__}, |
5346 | | |
5347 | | static PyObject * |
5348 | | os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid); |
5349 | | |
5350 | | static PyObject * |
5351 | | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5352 | 0 | { |
5353 | 0 | PyObject *return_value = NULL; |
5354 | 0 | const char *user; |
5355 | 0 | gid_t basegid; |
5356 | |
|
5357 | 0 | if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) { |
5358 | 0 | goto exit; |
5359 | 0 | } |
5360 | 0 | if (!PyUnicode_Check(args[0])) { |
5361 | 0 | _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); |
5362 | 0 | goto exit; |
5363 | 0 | } |
5364 | 0 | Py_ssize_t user_length; |
5365 | 0 | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
5366 | 0 | if (user == NULL) { |
5367 | 0 | goto exit; |
5368 | 0 | } |
5369 | 0 | if (strlen(user) != (size_t)user_length) { |
5370 | 0 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
5371 | 0 | goto exit; |
5372 | 0 | } |
5373 | 0 | if (!_Py_Gid_Converter(args[1], &basegid)) { |
5374 | 0 | goto exit; |
5375 | 0 | } |
5376 | 0 | return_value = os_getgrouplist_impl(module, user, basegid); |
5377 | |
|
5378 | 0 | exit: |
5379 | 0 | return return_value; |
5380 | 0 | } |
5381 | | |
5382 | | #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */ |
5383 | | |
5384 | | #if defined(HAVE_GETGROUPS) |
5385 | | |
5386 | | PyDoc_STRVAR(os_getgroups__doc__, |
5387 | | "getgroups($module, /)\n" |
5388 | | "--\n" |
5389 | | "\n" |
5390 | | "Return list of supplemental group IDs for the process."); |
5391 | | |
5392 | | #define OS_GETGROUPS_METHODDEF \ |
5393 | | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
5394 | | |
5395 | | static PyObject * |
5396 | | os_getgroups_impl(PyObject *module); |
5397 | | |
5398 | | static PyObject * |
5399 | | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5400 | 0 | { |
5401 | 0 | return os_getgroups_impl(module); |
5402 | 0 | } |
5403 | | |
5404 | | #endif /* defined(HAVE_GETGROUPS) */ |
5405 | | |
5406 | | #if defined(HAVE_INITGROUPS) && defined(__APPLE__) |
5407 | | |
5408 | | PyDoc_STRVAR(os_initgroups__doc__, |
5409 | | "initgroups($module, username, gid, /)\n" |
5410 | | "--\n" |
5411 | | "\n" |
5412 | | "Initialize the group access list.\n" |
5413 | | "\n" |
5414 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5415 | | "the groups of which the specified username is a member, plus the specified\n" |
5416 | | "group id."); |
5417 | | |
5418 | | #define OS_INITGROUPS_METHODDEF \ |
5419 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5420 | | |
5421 | | static PyObject * |
5422 | | os_initgroups_impl(PyObject *module, PyObject *oname, int gid); |
5423 | | |
5424 | | static PyObject * |
5425 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5426 | | { |
5427 | | PyObject *return_value = NULL; |
5428 | | PyObject *oname = NULL; |
5429 | | int gid; |
5430 | | |
5431 | | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5432 | | goto exit; |
5433 | | } |
5434 | | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5435 | | goto exit; |
5436 | | } |
5437 | | gid = PyLong_AsInt(args[1]); |
5438 | | if (gid == -1 && PyErr_Occurred()) { |
5439 | | goto exit; |
5440 | | } |
5441 | | return_value = os_initgroups_impl(module, oname, gid); |
5442 | | |
5443 | | exit: |
5444 | | /* Cleanup for oname */ |
5445 | | Py_XDECREF(oname); |
5446 | | |
5447 | | return return_value; |
5448 | | } |
5449 | | |
5450 | | #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */ |
5451 | | |
5452 | | #if defined(HAVE_INITGROUPS) && !defined(__APPLE__) |
5453 | | |
5454 | | PyDoc_STRVAR(os_initgroups__doc__, |
5455 | | "initgroups($module, username, gid, /)\n" |
5456 | | "--\n" |
5457 | | "\n" |
5458 | | "Initialize the group access list.\n" |
5459 | | "\n" |
5460 | | "Call the system initgroups() to initialize the group access list with all of\n" |
5461 | | "the groups of which the specified username is a member, plus the specified\n" |
5462 | | "group id."); |
5463 | | |
5464 | | #define OS_INITGROUPS_METHODDEF \ |
5465 | | {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__}, |
5466 | | |
5467 | | static PyObject * |
5468 | | os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid); |
5469 | | |
5470 | | static PyObject * |
5471 | | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5472 | 0 | { |
5473 | 0 | PyObject *return_value = NULL; |
5474 | 0 | PyObject *oname = NULL; |
5475 | 0 | gid_t gid; |
5476 | |
|
5477 | 0 | if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) { |
5478 | 0 | goto exit; |
5479 | 0 | } |
5480 | 0 | if (!PyUnicode_FSConverter(args[0], &oname)) { |
5481 | 0 | goto exit; |
5482 | 0 | } |
5483 | 0 | if (!_Py_Gid_Converter(args[1], &gid)) { |
5484 | 0 | goto exit; |
5485 | 0 | } |
5486 | 0 | return_value = os_initgroups_impl(module, oname, gid); |
5487 | |
|
5488 | 0 | exit: |
5489 | | /* Cleanup for oname */ |
5490 | 0 | Py_XDECREF(oname); |
5491 | |
|
5492 | 0 | return return_value; |
5493 | 0 | } |
5494 | | |
5495 | | #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */ |
5496 | | |
5497 | | #if defined(HAVE_GETPGID) |
5498 | | |
5499 | | PyDoc_STRVAR(os_getpgid__doc__, |
5500 | | "getpgid($module, /, pid)\n" |
5501 | | "--\n" |
5502 | | "\n" |
5503 | | "Call the system call getpgid(), and return the result."); |
5504 | | |
5505 | | #define OS_GETPGID_METHODDEF \ |
5506 | | {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
5507 | | |
5508 | | static PyObject * |
5509 | | os_getpgid_impl(PyObject *module, pid_t pid); |
5510 | | |
5511 | | static PyObject * |
5512 | | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5513 | 0 | { |
5514 | 0 | PyObject *return_value = NULL; |
5515 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
5516 | |
|
5517 | 0 | #define NUM_KEYWORDS 1 |
5518 | 0 | static struct { |
5519 | 0 | PyGC_Head _this_is_not_used; |
5520 | 0 | PyObject_VAR_HEAD |
5521 | 0 | Py_hash_t ob_hash; |
5522 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
5523 | 0 | } _kwtuple = { |
5524 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
5525 | 0 | .ob_hash = -1, |
5526 | 0 | .ob_item = { &_Py_ID(pid), }, |
5527 | 0 | }; |
5528 | 0 | #undef NUM_KEYWORDS |
5529 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
5530 | |
|
5531 | | #else // !Py_BUILD_CORE |
5532 | | # define KWTUPLE NULL |
5533 | | #endif // !Py_BUILD_CORE |
5534 | |
|
5535 | 0 | static const char * const _keywords[] = {"pid", NULL}; |
5536 | 0 | static _PyArg_Parser _parser = { |
5537 | 0 | .keywords = _keywords, |
5538 | 0 | .fname = "getpgid", |
5539 | 0 | .kwtuple = KWTUPLE, |
5540 | 0 | }; |
5541 | 0 | #undef KWTUPLE |
5542 | 0 | PyObject *argsbuf[1]; |
5543 | 0 | pid_t pid; |
5544 | |
|
5545 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
5546 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
5547 | 0 | if (!args) { |
5548 | 0 | goto exit; |
5549 | 0 | } |
5550 | 0 | pid = PyLong_AsPid(args[0]); |
5551 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5552 | 0 | goto exit; |
5553 | 0 | } |
5554 | 0 | return_value = os_getpgid_impl(module, pid); |
5555 | |
|
5556 | 0 | exit: |
5557 | 0 | return return_value; |
5558 | 0 | } |
5559 | | |
5560 | | #endif /* defined(HAVE_GETPGID) */ |
5561 | | |
5562 | | #if defined(HAVE_GETPGRP) |
5563 | | |
5564 | | PyDoc_STRVAR(os_getpgrp__doc__, |
5565 | | "getpgrp($module, /)\n" |
5566 | | "--\n" |
5567 | | "\n" |
5568 | | "Return the current process group id."); |
5569 | | |
5570 | | #define OS_GETPGRP_METHODDEF \ |
5571 | | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
5572 | | |
5573 | | static PyObject * |
5574 | | os_getpgrp_impl(PyObject *module); |
5575 | | |
5576 | | static PyObject * |
5577 | | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5578 | 0 | { |
5579 | 0 | return os_getpgrp_impl(module); |
5580 | 0 | } |
5581 | | |
5582 | | #endif /* defined(HAVE_GETPGRP) */ |
5583 | | |
5584 | | #if defined(HAVE_SETPGRP) |
5585 | | |
5586 | | PyDoc_STRVAR(os_setpgrp__doc__, |
5587 | | "setpgrp($module, /)\n" |
5588 | | "--\n" |
5589 | | "\n" |
5590 | | "Make the current process the leader of its process group."); |
5591 | | |
5592 | | #define OS_SETPGRP_METHODDEF \ |
5593 | | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
5594 | | |
5595 | | static PyObject * |
5596 | | os_setpgrp_impl(PyObject *module); |
5597 | | |
5598 | | static PyObject * |
5599 | | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5600 | 0 | { |
5601 | 0 | return os_setpgrp_impl(module); |
5602 | 0 | } |
5603 | | |
5604 | | #endif /* defined(HAVE_SETPGRP) */ |
5605 | | |
5606 | | #if defined(HAVE_GETPPID) |
5607 | | |
5608 | | PyDoc_STRVAR(os_getppid__doc__, |
5609 | | "getppid($module, /)\n" |
5610 | | "--\n" |
5611 | | "\n" |
5612 | | "Return the parent\'s process id.\n" |
5613 | | "\n" |
5614 | | "If the parent process has already exited, Windows machines will still\n" |
5615 | | "return its id; others systems will return the id of the \'init\' process (1)."); |
5616 | | |
5617 | | #define OS_GETPPID_METHODDEF \ |
5618 | | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
5619 | | |
5620 | | static PyObject * |
5621 | | os_getppid_impl(PyObject *module); |
5622 | | |
5623 | | static PyObject * |
5624 | | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5625 | 0 | { |
5626 | 0 | return os_getppid_impl(module); |
5627 | 0 | } |
5628 | | |
5629 | | #endif /* defined(HAVE_GETPPID) */ |
5630 | | |
5631 | | #if defined(HAVE_GETLOGIN) |
5632 | | |
5633 | | PyDoc_STRVAR(os_getlogin__doc__, |
5634 | | "getlogin($module, /)\n" |
5635 | | "--\n" |
5636 | | "\n" |
5637 | | "Return the actual login name."); |
5638 | | |
5639 | | #define OS_GETLOGIN_METHODDEF \ |
5640 | | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
5641 | | |
5642 | | static PyObject * |
5643 | | os_getlogin_impl(PyObject *module); |
5644 | | |
5645 | | static PyObject * |
5646 | | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5647 | 0 | { |
5648 | 0 | return os_getlogin_impl(module); |
5649 | 0 | } |
5650 | | |
5651 | | #endif /* defined(HAVE_GETLOGIN) */ |
5652 | | |
5653 | | #if defined(HAVE_GETUID) |
5654 | | |
5655 | | PyDoc_STRVAR(os_getuid__doc__, |
5656 | | "getuid($module, /)\n" |
5657 | | "--\n" |
5658 | | "\n" |
5659 | | "Return the current process\'s user id."); |
5660 | | |
5661 | | #define OS_GETUID_METHODDEF \ |
5662 | | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
5663 | | |
5664 | | static PyObject * |
5665 | | os_getuid_impl(PyObject *module); |
5666 | | |
5667 | | static PyObject * |
5668 | | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5669 | 16 | { |
5670 | 16 | return os_getuid_impl(module); |
5671 | 16 | } |
5672 | | |
5673 | | #endif /* defined(HAVE_GETUID) */ |
5674 | | |
5675 | | #if defined(HAVE_KILL) |
5676 | | |
5677 | | PyDoc_STRVAR(os_kill__doc__, |
5678 | | "kill($module, pid, signal, /)\n" |
5679 | | "--\n" |
5680 | | "\n" |
5681 | | "Kill a process with a signal."); |
5682 | | |
5683 | | #define OS_KILL_METHODDEF \ |
5684 | | {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__}, |
5685 | | |
5686 | | static PyObject * |
5687 | | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
5688 | | |
5689 | | static PyObject * |
5690 | | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5691 | 0 | { |
5692 | 0 | PyObject *return_value = NULL; |
5693 | 0 | pid_t pid; |
5694 | 0 | Py_ssize_t signal; |
5695 | |
|
5696 | 0 | if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) { |
5697 | 0 | goto exit; |
5698 | 0 | } |
5699 | 0 | pid = PyLong_AsPid(args[0]); |
5700 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
5701 | 0 | goto exit; |
5702 | 0 | } |
5703 | 0 | { |
5704 | 0 | Py_ssize_t ival = -1; |
5705 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
5706 | 0 | if (iobj != NULL) { |
5707 | 0 | ival = PyLong_AsSsize_t(iobj); |
5708 | 0 | Py_DECREF(iobj); |
5709 | 0 | } |
5710 | 0 | if (ival == -1 && PyErr_Occurred()) { |
5711 | 0 | goto exit; |
5712 | 0 | } |
5713 | 0 | signal = ival; |
5714 | 0 | } |
5715 | 0 | return_value = os_kill_impl(module, pid, signal); |
5716 | |
|
5717 | 0 | exit: |
5718 | 0 | return return_value; |
5719 | 0 | } |
5720 | | |
5721 | | #endif /* defined(HAVE_KILL) */ |
5722 | | |
5723 | | #if defined(HAVE_KILLPG) |
5724 | | |
5725 | | PyDoc_STRVAR(os_killpg__doc__, |
5726 | | "killpg($module, pgid, signal, /)\n" |
5727 | | "--\n" |
5728 | | "\n" |
5729 | | "Kill a process group with a signal."); |
5730 | | |
5731 | | #define OS_KILLPG_METHODDEF \ |
5732 | | {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__}, |
5733 | | |
5734 | | static PyObject * |
5735 | | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
5736 | | |
5737 | | static PyObject * |
5738 | | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5739 | 0 | { |
5740 | 0 | PyObject *return_value = NULL; |
5741 | 0 | pid_t pgid; |
5742 | 0 | int signal; |
5743 | |
|
5744 | 0 | if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) { |
5745 | 0 | goto exit; |
5746 | 0 | } |
5747 | 0 | pgid = PyLong_AsPid(args[0]); |
5748 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
5749 | 0 | goto exit; |
5750 | 0 | } |
5751 | 0 | signal = PyLong_AsInt(args[1]); |
5752 | 0 | if (signal == -1 && PyErr_Occurred()) { |
5753 | 0 | goto exit; |
5754 | 0 | } |
5755 | 0 | return_value = os_killpg_impl(module, pgid, signal); |
5756 | |
|
5757 | 0 | exit: |
5758 | 0 | return return_value; |
5759 | 0 | } |
5760 | | |
5761 | | #endif /* defined(HAVE_KILLPG) */ |
5762 | | |
5763 | | #if defined(HAVE_PLOCK) |
5764 | | |
5765 | | PyDoc_STRVAR(os_plock__doc__, |
5766 | | "plock($module, op, /)\n" |
5767 | | "--\n" |
5768 | | "\n" |
5769 | | "Lock program segments into memory.\");"); |
5770 | | |
5771 | | #define OS_PLOCK_METHODDEF \ |
5772 | | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
5773 | | |
5774 | | static PyObject * |
5775 | | os_plock_impl(PyObject *module, int op); |
5776 | | |
5777 | | static PyObject * |
5778 | | os_plock(PyObject *module, PyObject *arg) |
5779 | | { |
5780 | | PyObject *return_value = NULL; |
5781 | | int op; |
5782 | | |
5783 | | op = PyLong_AsInt(arg); |
5784 | | if (op == -1 && PyErr_Occurred()) { |
5785 | | goto exit; |
5786 | | } |
5787 | | return_value = os_plock_impl(module, op); |
5788 | | |
5789 | | exit: |
5790 | | return return_value; |
5791 | | } |
5792 | | |
5793 | | #endif /* defined(HAVE_PLOCK) */ |
5794 | | |
5795 | | #if defined(HAVE_SETUID) |
5796 | | |
5797 | | PyDoc_STRVAR(os_setuid__doc__, |
5798 | | "setuid($module, uid, /)\n" |
5799 | | "--\n" |
5800 | | "\n" |
5801 | | "Set the current process\'s user id."); |
5802 | | |
5803 | | #define OS_SETUID_METHODDEF \ |
5804 | | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
5805 | | |
5806 | | static PyObject * |
5807 | | os_setuid_impl(PyObject *module, uid_t uid); |
5808 | | |
5809 | | static PyObject * |
5810 | | os_setuid(PyObject *module, PyObject *arg) |
5811 | 0 | { |
5812 | 0 | PyObject *return_value = NULL; |
5813 | 0 | uid_t uid; |
5814 | |
|
5815 | 0 | if (!_Py_Uid_Converter(arg, &uid)) { |
5816 | 0 | goto exit; |
5817 | 0 | } |
5818 | 0 | return_value = os_setuid_impl(module, uid); |
5819 | |
|
5820 | 0 | exit: |
5821 | 0 | return return_value; |
5822 | 0 | } |
5823 | | |
5824 | | #endif /* defined(HAVE_SETUID) */ |
5825 | | |
5826 | | #if defined(HAVE_SETEUID) |
5827 | | |
5828 | | PyDoc_STRVAR(os_seteuid__doc__, |
5829 | | "seteuid($module, euid, /)\n" |
5830 | | "--\n" |
5831 | | "\n" |
5832 | | "Set the current process\'s effective user id."); |
5833 | | |
5834 | | #define OS_SETEUID_METHODDEF \ |
5835 | | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
5836 | | |
5837 | | static PyObject * |
5838 | | os_seteuid_impl(PyObject *module, uid_t euid); |
5839 | | |
5840 | | static PyObject * |
5841 | | os_seteuid(PyObject *module, PyObject *arg) |
5842 | 0 | { |
5843 | 0 | PyObject *return_value = NULL; |
5844 | 0 | uid_t euid; |
5845 | |
|
5846 | 0 | if (!_Py_Uid_Converter(arg, &euid)) { |
5847 | 0 | goto exit; |
5848 | 0 | } |
5849 | 0 | return_value = os_seteuid_impl(module, euid); |
5850 | |
|
5851 | 0 | exit: |
5852 | 0 | return return_value; |
5853 | 0 | } |
5854 | | |
5855 | | #endif /* defined(HAVE_SETEUID) */ |
5856 | | |
5857 | | #if defined(HAVE_SETEGID) |
5858 | | |
5859 | | PyDoc_STRVAR(os_setegid__doc__, |
5860 | | "setegid($module, egid, /)\n" |
5861 | | "--\n" |
5862 | | "\n" |
5863 | | "Set the current process\'s effective group id."); |
5864 | | |
5865 | | #define OS_SETEGID_METHODDEF \ |
5866 | | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
5867 | | |
5868 | | static PyObject * |
5869 | | os_setegid_impl(PyObject *module, gid_t egid); |
5870 | | |
5871 | | static PyObject * |
5872 | | os_setegid(PyObject *module, PyObject *arg) |
5873 | 0 | { |
5874 | 0 | PyObject *return_value = NULL; |
5875 | 0 | gid_t egid; |
5876 | |
|
5877 | 0 | if (!_Py_Gid_Converter(arg, &egid)) { |
5878 | 0 | goto exit; |
5879 | 0 | } |
5880 | 0 | return_value = os_setegid_impl(module, egid); |
5881 | |
|
5882 | 0 | exit: |
5883 | 0 | return return_value; |
5884 | 0 | } |
5885 | | |
5886 | | #endif /* defined(HAVE_SETEGID) */ |
5887 | | |
5888 | | #if defined(HAVE_SETREUID) |
5889 | | |
5890 | | PyDoc_STRVAR(os_setreuid__doc__, |
5891 | | "setreuid($module, ruid, euid, /)\n" |
5892 | | "--\n" |
5893 | | "\n" |
5894 | | "Set the current process\'s real and effective user ids."); |
5895 | | |
5896 | | #define OS_SETREUID_METHODDEF \ |
5897 | | {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__}, |
5898 | | |
5899 | | static PyObject * |
5900 | | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
5901 | | |
5902 | | static PyObject * |
5903 | | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5904 | 0 | { |
5905 | 0 | PyObject *return_value = NULL; |
5906 | 0 | uid_t ruid; |
5907 | 0 | uid_t euid; |
5908 | |
|
5909 | 0 | if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { |
5910 | 0 | goto exit; |
5911 | 0 | } |
5912 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
5913 | 0 | goto exit; |
5914 | 0 | } |
5915 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
5916 | 0 | goto exit; |
5917 | 0 | } |
5918 | 0 | return_value = os_setreuid_impl(module, ruid, euid); |
5919 | |
|
5920 | 0 | exit: |
5921 | 0 | return return_value; |
5922 | 0 | } |
5923 | | |
5924 | | #endif /* defined(HAVE_SETREUID) */ |
5925 | | |
5926 | | #if defined(HAVE_SETREGID) |
5927 | | |
5928 | | PyDoc_STRVAR(os_setregid__doc__, |
5929 | | "setregid($module, rgid, egid, /)\n" |
5930 | | "--\n" |
5931 | | "\n" |
5932 | | "Set the current process\'s real and effective group ids."); |
5933 | | |
5934 | | #define OS_SETREGID_METHODDEF \ |
5935 | | {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__}, |
5936 | | |
5937 | | static PyObject * |
5938 | | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
5939 | | |
5940 | | static PyObject * |
5941 | | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5942 | 0 | { |
5943 | 0 | PyObject *return_value = NULL; |
5944 | 0 | gid_t rgid; |
5945 | 0 | gid_t egid; |
5946 | |
|
5947 | 0 | if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { |
5948 | 0 | goto exit; |
5949 | 0 | } |
5950 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
5951 | 0 | goto exit; |
5952 | 0 | } |
5953 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
5954 | 0 | goto exit; |
5955 | 0 | } |
5956 | 0 | return_value = os_setregid_impl(module, rgid, egid); |
5957 | |
|
5958 | 0 | exit: |
5959 | 0 | return return_value; |
5960 | 0 | } |
5961 | | |
5962 | | #endif /* defined(HAVE_SETREGID) */ |
5963 | | |
5964 | | #if defined(HAVE_SETGID) |
5965 | | |
5966 | | PyDoc_STRVAR(os_setgid__doc__, |
5967 | | "setgid($module, gid, /)\n" |
5968 | | "--\n" |
5969 | | "\n" |
5970 | | "Set the current process\'s group id."); |
5971 | | |
5972 | | #define OS_SETGID_METHODDEF \ |
5973 | | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
5974 | | |
5975 | | static PyObject * |
5976 | | os_setgid_impl(PyObject *module, gid_t gid); |
5977 | | |
5978 | | static PyObject * |
5979 | | os_setgid(PyObject *module, PyObject *arg) |
5980 | 0 | { |
5981 | 0 | PyObject *return_value = NULL; |
5982 | 0 | gid_t gid; |
5983 | |
|
5984 | 0 | if (!_Py_Gid_Converter(arg, &gid)) { |
5985 | 0 | goto exit; |
5986 | 0 | } |
5987 | 0 | return_value = os_setgid_impl(module, gid); |
5988 | |
|
5989 | 0 | exit: |
5990 | 0 | return return_value; |
5991 | 0 | } |
5992 | | |
5993 | | #endif /* defined(HAVE_SETGID) */ |
5994 | | |
5995 | | #if defined(HAVE_SETGROUPS) |
5996 | | |
5997 | | PyDoc_STRVAR(os_setgroups__doc__, |
5998 | | "setgroups($module, groups, /)\n" |
5999 | | "--\n" |
6000 | | "\n" |
6001 | | "Set the groups of the current process to list."); |
6002 | | |
6003 | | #define OS_SETGROUPS_METHODDEF \ |
6004 | | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
6005 | | |
6006 | | #endif /* defined(HAVE_SETGROUPS) */ |
6007 | | |
6008 | | #if defined(HAVE_WAIT3) |
6009 | | |
6010 | | PyDoc_STRVAR(os_wait3__doc__, |
6011 | | "wait3($module, /, options)\n" |
6012 | | "--\n" |
6013 | | "\n" |
6014 | | "Wait for completion of a child process.\n" |
6015 | | "\n" |
6016 | | "Returns a tuple of information about the child process:\n" |
6017 | | " (pid, status, rusage)"); |
6018 | | |
6019 | | #define OS_WAIT3_METHODDEF \ |
6020 | | {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__}, |
6021 | | |
6022 | | static PyObject * |
6023 | | os_wait3_impl(PyObject *module, int options); |
6024 | | |
6025 | | static PyObject * |
6026 | | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6027 | 0 | { |
6028 | 0 | PyObject *return_value = NULL; |
6029 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6030 | |
|
6031 | 0 | #define NUM_KEYWORDS 1 |
6032 | 0 | static struct { |
6033 | 0 | PyGC_Head _this_is_not_used; |
6034 | 0 | PyObject_VAR_HEAD |
6035 | 0 | Py_hash_t ob_hash; |
6036 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6037 | 0 | } _kwtuple = { |
6038 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6039 | 0 | .ob_hash = -1, |
6040 | 0 | .ob_item = { &_Py_ID(options), }, |
6041 | 0 | }; |
6042 | 0 | #undef NUM_KEYWORDS |
6043 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6044 | |
|
6045 | | #else // !Py_BUILD_CORE |
6046 | | # define KWTUPLE NULL |
6047 | | #endif // !Py_BUILD_CORE |
6048 | |
|
6049 | 0 | static const char * const _keywords[] = {"options", NULL}; |
6050 | 0 | static _PyArg_Parser _parser = { |
6051 | 0 | .keywords = _keywords, |
6052 | 0 | .fname = "wait3", |
6053 | 0 | .kwtuple = KWTUPLE, |
6054 | 0 | }; |
6055 | 0 | #undef KWTUPLE |
6056 | 0 | PyObject *argsbuf[1]; |
6057 | 0 | int options; |
6058 | |
|
6059 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6060 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6061 | 0 | if (!args) { |
6062 | 0 | goto exit; |
6063 | 0 | } |
6064 | 0 | options = PyLong_AsInt(args[0]); |
6065 | 0 | if (options == -1 && PyErr_Occurred()) { |
6066 | 0 | goto exit; |
6067 | 0 | } |
6068 | 0 | return_value = os_wait3_impl(module, options); |
6069 | |
|
6070 | 0 | exit: |
6071 | 0 | return return_value; |
6072 | 0 | } |
6073 | | |
6074 | | #endif /* defined(HAVE_WAIT3) */ |
6075 | | |
6076 | | #if defined(HAVE_WAIT4) |
6077 | | |
6078 | | PyDoc_STRVAR(os_wait4__doc__, |
6079 | | "wait4($module, /, pid, options)\n" |
6080 | | "--\n" |
6081 | | "\n" |
6082 | | "Wait for completion of a specific child process.\n" |
6083 | | "\n" |
6084 | | "Returns a tuple of information about the child process:\n" |
6085 | | " (pid, status, rusage)"); |
6086 | | |
6087 | | #define OS_WAIT4_METHODDEF \ |
6088 | | {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
6089 | | |
6090 | | static PyObject * |
6091 | | os_wait4_impl(PyObject *module, pid_t pid, int options); |
6092 | | |
6093 | | static PyObject * |
6094 | | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6095 | 0 | { |
6096 | 0 | PyObject *return_value = NULL; |
6097 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6098 | |
|
6099 | 0 | #define NUM_KEYWORDS 2 |
6100 | 0 | static struct { |
6101 | 0 | PyGC_Head _this_is_not_used; |
6102 | 0 | PyObject_VAR_HEAD |
6103 | 0 | Py_hash_t ob_hash; |
6104 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6105 | 0 | } _kwtuple = { |
6106 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6107 | 0 | .ob_hash = -1, |
6108 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(options), }, |
6109 | 0 | }; |
6110 | 0 | #undef NUM_KEYWORDS |
6111 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6112 | |
|
6113 | | #else // !Py_BUILD_CORE |
6114 | | # define KWTUPLE NULL |
6115 | | #endif // !Py_BUILD_CORE |
6116 | |
|
6117 | 0 | static const char * const _keywords[] = {"pid", "options", NULL}; |
6118 | 0 | static _PyArg_Parser _parser = { |
6119 | 0 | .keywords = _keywords, |
6120 | 0 | .fname = "wait4", |
6121 | 0 | .kwtuple = KWTUPLE, |
6122 | 0 | }; |
6123 | 0 | #undef KWTUPLE |
6124 | 0 | PyObject *argsbuf[2]; |
6125 | 0 | pid_t pid; |
6126 | 0 | int options; |
6127 | |
|
6128 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6129 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6130 | 0 | if (!args) { |
6131 | 0 | goto exit; |
6132 | 0 | } |
6133 | 0 | pid = PyLong_AsPid(args[0]); |
6134 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6135 | 0 | goto exit; |
6136 | 0 | } |
6137 | 0 | options = PyLong_AsInt(args[1]); |
6138 | 0 | if (options == -1 && PyErr_Occurred()) { |
6139 | 0 | goto exit; |
6140 | 0 | } |
6141 | 0 | return_value = os_wait4_impl(module, pid, options); |
6142 | |
|
6143 | 0 | exit: |
6144 | 0 | return return_value; |
6145 | 0 | } |
6146 | | |
6147 | | #endif /* defined(HAVE_WAIT4) */ |
6148 | | |
6149 | | #if defined(HAVE_WAITID) |
6150 | | |
6151 | | PyDoc_STRVAR(os_waitid__doc__, |
6152 | | "waitid($module, idtype, id, options, /)\n" |
6153 | | "--\n" |
6154 | | "\n" |
6155 | | "Returns the result of waiting for a process or processes.\n" |
6156 | | "\n" |
6157 | | " idtype\n" |
6158 | | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
6159 | | " id\n" |
6160 | | " The id to wait on.\n" |
6161 | | " options\n" |
6162 | | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
6163 | | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
6164 | | "\n" |
6165 | | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
6166 | | "no children in a waitable state."); |
6167 | | |
6168 | | #define OS_WAITID_METHODDEF \ |
6169 | | {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__}, |
6170 | | |
6171 | | static PyObject * |
6172 | | os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options); |
6173 | | |
6174 | | static PyObject * |
6175 | | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6176 | 0 | { |
6177 | 0 | PyObject *return_value = NULL; |
6178 | 0 | idtype_t idtype; |
6179 | 0 | id_t id; |
6180 | 0 | int options; |
6181 | |
|
6182 | 0 | if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) { |
6183 | 0 | goto exit; |
6184 | 0 | } |
6185 | 0 | if (!idtype_t_converter(args[0], &idtype)) { |
6186 | 0 | goto exit; |
6187 | 0 | } |
6188 | 0 | id = (id_t)PyLong_AsPid(args[1]); |
6189 | 0 | if (id == (id_t)(-1) && PyErr_Occurred()) { |
6190 | 0 | goto exit; |
6191 | 0 | } |
6192 | 0 | options = PyLong_AsInt(args[2]); |
6193 | 0 | if (options == -1 && PyErr_Occurred()) { |
6194 | 0 | goto exit; |
6195 | 0 | } |
6196 | 0 | return_value = os_waitid_impl(module, idtype, id, options); |
6197 | |
|
6198 | 0 | exit: |
6199 | 0 | return return_value; |
6200 | 0 | } |
6201 | | |
6202 | | #endif /* defined(HAVE_WAITID) */ |
6203 | | |
6204 | | #if defined(HAVE_WAITPID) |
6205 | | |
6206 | | PyDoc_STRVAR(os_waitpid__doc__, |
6207 | | "waitpid($module, pid, options, /)\n" |
6208 | | "--\n" |
6209 | | "\n" |
6210 | | "Wait for completion of a given child process.\n" |
6211 | | "\n" |
6212 | | "Returns a tuple of information regarding the child process:\n" |
6213 | | " (pid, status)\n" |
6214 | | "\n" |
6215 | | "The options argument is ignored on Windows."); |
6216 | | |
6217 | | #define OS_WAITPID_METHODDEF \ |
6218 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6219 | | |
6220 | | static PyObject * |
6221 | | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
6222 | | |
6223 | | static PyObject * |
6224 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6225 | 0 | { |
6226 | 0 | PyObject *return_value = NULL; |
6227 | 0 | pid_t pid; |
6228 | 0 | int options; |
6229 | |
|
6230 | 0 | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6231 | 0 | goto exit; |
6232 | 0 | } |
6233 | 0 | pid = PyLong_AsPid(args[0]); |
6234 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6235 | 0 | goto exit; |
6236 | 0 | } |
6237 | 0 | options = PyLong_AsInt(args[1]); |
6238 | 0 | if (options == -1 && PyErr_Occurred()) { |
6239 | 0 | goto exit; |
6240 | 0 | } |
6241 | 0 | return_value = os_waitpid_impl(module, pid, options); |
6242 | |
|
6243 | 0 | exit: |
6244 | 0 | return return_value; |
6245 | 0 | } |
6246 | | |
6247 | | #endif /* defined(HAVE_WAITPID) */ |
6248 | | |
6249 | | #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) |
6250 | | |
6251 | | PyDoc_STRVAR(os_waitpid__doc__, |
6252 | | "waitpid($module, pid, options, /)\n" |
6253 | | "--\n" |
6254 | | "\n" |
6255 | | "Wait for completion of a given process.\n" |
6256 | | "\n" |
6257 | | "Returns a tuple of information regarding the process:\n" |
6258 | | " (pid, status << 8)\n" |
6259 | | "\n" |
6260 | | "The options argument is ignored on Windows."); |
6261 | | |
6262 | | #define OS_WAITPID_METHODDEF \ |
6263 | | {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__}, |
6264 | | |
6265 | | static PyObject * |
6266 | | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
6267 | | |
6268 | | static PyObject * |
6269 | | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6270 | | { |
6271 | | PyObject *return_value = NULL; |
6272 | | intptr_t pid; |
6273 | | int options; |
6274 | | |
6275 | | if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) { |
6276 | | goto exit; |
6277 | | } |
6278 | | pid = (intptr_t)PyLong_AsVoidPtr(args[0]); |
6279 | | if (!pid && PyErr_Occurred()) { |
6280 | | goto exit; |
6281 | | } |
6282 | | options = PyLong_AsInt(args[1]); |
6283 | | if (options == -1 && PyErr_Occurred()) { |
6284 | | goto exit; |
6285 | | } |
6286 | | return_value = os_waitpid_impl(module, pid, options); |
6287 | | |
6288 | | exit: |
6289 | | return return_value; |
6290 | | } |
6291 | | |
6292 | | #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */ |
6293 | | |
6294 | | #if defined(HAVE_WAIT) |
6295 | | |
6296 | | PyDoc_STRVAR(os_wait__doc__, |
6297 | | "wait($module, /)\n" |
6298 | | "--\n" |
6299 | | "\n" |
6300 | | "Wait for completion of a child process.\n" |
6301 | | "\n" |
6302 | | "Returns a tuple of information about the child process:\n" |
6303 | | " (pid, status)"); |
6304 | | |
6305 | | #define OS_WAIT_METHODDEF \ |
6306 | | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
6307 | | |
6308 | | static PyObject * |
6309 | | os_wait_impl(PyObject *module); |
6310 | | |
6311 | | static PyObject * |
6312 | | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6313 | 0 | { |
6314 | 0 | return os_wait_impl(module); |
6315 | 0 | } |
6316 | | |
6317 | | #endif /* defined(HAVE_WAIT) */ |
6318 | | |
6319 | | #if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) |
6320 | | |
6321 | | PyDoc_STRVAR(os_pidfd_open__doc__, |
6322 | | "pidfd_open($module, /, pid, flags=0)\n" |
6323 | | "--\n" |
6324 | | "\n" |
6325 | | "Return a file descriptor referring to the process *pid*.\n" |
6326 | | "\n" |
6327 | | "The descriptor can be used to perform process management without races and\n" |
6328 | | "signals."); |
6329 | | |
6330 | | #define OS_PIDFD_OPEN_METHODDEF \ |
6331 | | {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__}, |
6332 | | |
6333 | | static PyObject * |
6334 | | os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags); |
6335 | | |
6336 | | static PyObject * |
6337 | | os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6338 | 0 | { |
6339 | 0 | PyObject *return_value = NULL; |
6340 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6341 | |
|
6342 | 0 | #define NUM_KEYWORDS 2 |
6343 | 0 | static struct { |
6344 | 0 | PyGC_Head _this_is_not_used; |
6345 | 0 | PyObject_VAR_HEAD |
6346 | 0 | Py_hash_t ob_hash; |
6347 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6348 | 0 | } _kwtuple = { |
6349 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6350 | 0 | .ob_hash = -1, |
6351 | 0 | .ob_item = { &_Py_ID(pid), &_Py_ID(flags), }, |
6352 | 0 | }; |
6353 | 0 | #undef NUM_KEYWORDS |
6354 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6355 | |
|
6356 | | #else // !Py_BUILD_CORE |
6357 | | # define KWTUPLE NULL |
6358 | | #endif // !Py_BUILD_CORE |
6359 | |
|
6360 | 0 | static const char * const _keywords[] = {"pid", "flags", NULL}; |
6361 | 0 | static _PyArg_Parser _parser = { |
6362 | 0 | .keywords = _keywords, |
6363 | 0 | .fname = "pidfd_open", |
6364 | 0 | .kwtuple = KWTUPLE, |
6365 | 0 | }; |
6366 | 0 | #undef KWTUPLE |
6367 | 0 | PyObject *argsbuf[2]; |
6368 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6369 | 0 | pid_t pid; |
6370 | 0 | unsigned int flags = 0; |
6371 | |
|
6372 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6373 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6374 | 0 | if (!args) { |
6375 | 0 | goto exit; |
6376 | 0 | } |
6377 | 0 | pid = PyLong_AsPid(args[0]); |
6378 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
6379 | 0 | goto exit; |
6380 | 0 | } |
6381 | 0 | if (!noptargs) { |
6382 | 0 | goto skip_optional_pos; |
6383 | 0 | } |
6384 | 0 | if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) { |
6385 | 0 | goto exit; |
6386 | 0 | } |
6387 | 0 | skip_optional_pos: |
6388 | 0 | return_value = os_pidfd_open_impl(module, pid, flags); |
6389 | |
|
6390 | 0 | exit: |
6391 | 0 | return return_value; |
6392 | 0 | } |
6393 | | |
6394 | | #endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */ |
6395 | | |
6396 | | #if defined(HAVE_SETNS) |
6397 | | |
6398 | | PyDoc_STRVAR(os_setns__doc__, |
6399 | | "setns($module, /, fd, nstype=0)\n" |
6400 | | "--\n" |
6401 | | "\n" |
6402 | | "Move the calling thread into different namespaces.\n" |
6403 | | "\n" |
6404 | | " fd\n" |
6405 | | " A file descriptor to a namespace.\n" |
6406 | | " nstype\n" |
6407 | | " Type of namespace."); |
6408 | | |
6409 | | #define OS_SETNS_METHODDEF \ |
6410 | | {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__}, |
6411 | | |
6412 | | static PyObject * |
6413 | | os_setns_impl(PyObject *module, int fd, int nstype); |
6414 | | |
6415 | | static PyObject * |
6416 | | os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6417 | 0 | { |
6418 | 0 | PyObject *return_value = NULL; |
6419 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6420 | |
|
6421 | 0 | #define NUM_KEYWORDS 2 |
6422 | 0 | static struct { |
6423 | 0 | PyGC_Head _this_is_not_used; |
6424 | 0 | PyObject_VAR_HEAD |
6425 | 0 | Py_hash_t ob_hash; |
6426 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6427 | 0 | } _kwtuple = { |
6428 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6429 | 0 | .ob_hash = -1, |
6430 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), }, |
6431 | 0 | }; |
6432 | 0 | #undef NUM_KEYWORDS |
6433 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6434 | |
|
6435 | | #else // !Py_BUILD_CORE |
6436 | | # define KWTUPLE NULL |
6437 | | #endif // !Py_BUILD_CORE |
6438 | |
|
6439 | 0 | static const char * const _keywords[] = {"fd", "nstype", NULL}; |
6440 | 0 | static _PyArg_Parser _parser = { |
6441 | 0 | .keywords = _keywords, |
6442 | 0 | .fname = "setns", |
6443 | 0 | .kwtuple = KWTUPLE, |
6444 | 0 | }; |
6445 | 0 | #undef KWTUPLE |
6446 | 0 | PyObject *argsbuf[2]; |
6447 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6448 | 0 | int fd; |
6449 | 0 | int nstype = 0; |
6450 | |
|
6451 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6452 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6453 | 0 | if (!args) { |
6454 | 0 | goto exit; |
6455 | 0 | } |
6456 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6457 | 0 | if (fd < 0) { |
6458 | 0 | goto exit; |
6459 | 0 | } |
6460 | 0 | if (!noptargs) { |
6461 | 0 | goto skip_optional_pos; |
6462 | 0 | } |
6463 | 0 | nstype = PyLong_AsInt(args[1]); |
6464 | 0 | if (nstype == -1 && PyErr_Occurred()) { |
6465 | 0 | goto exit; |
6466 | 0 | } |
6467 | 0 | skip_optional_pos: |
6468 | 0 | return_value = os_setns_impl(module, fd, nstype); |
6469 | |
|
6470 | 0 | exit: |
6471 | 0 | return return_value; |
6472 | 0 | } |
6473 | | |
6474 | | #endif /* defined(HAVE_SETNS) */ |
6475 | | |
6476 | | #if defined(HAVE_UNSHARE) |
6477 | | |
6478 | | PyDoc_STRVAR(os_unshare__doc__, |
6479 | | "unshare($module, /, flags)\n" |
6480 | | "--\n" |
6481 | | "\n" |
6482 | | "Disassociate parts of a process (or thread) execution context.\n" |
6483 | | "\n" |
6484 | | " flags\n" |
6485 | | " Namespaces to be unshared."); |
6486 | | |
6487 | | #define OS_UNSHARE_METHODDEF \ |
6488 | | {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__}, |
6489 | | |
6490 | | static PyObject * |
6491 | | os_unshare_impl(PyObject *module, int flags); |
6492 | | |
6493 | | static PyObject * |
6494 | | os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6495 | 0 | { |
6496 | 0 | PyObject *return_value = NULL; |
6497 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6498 | |
|
6499 | 0 | #define NUM_KEYWORDS 1 |
6500 | 0 | static struct { |
6501 | 0 | PyGC_Head _this_is_not_used; |
6502 | 0 | PyObject_VAR_HEAD |
6503 | 0 | Py_hash_t ob_hash; |
6504 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6505 | 0 | } _kwtuple = { |
6506 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6507 | 0 | .ob_hash = -1, |
6508 | 0 | .ob_item = { &_Py_ID(flags), }, |
6509 | 0 | }; |
6510 | 0 | #undef NUM_KEYWORDS |
6511 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6512 | |
|
6513 | | #else // !Py_BUILD_CORE |
6514 | | # define KWTUPLE NULL |
6515 | | #endif // !Py_BUILD_CORE |
6516 | |
|
6517 | 0 | static const char * const _keywords[] = {"flags", NULL}; |
6518 | 0 | static _PyArg_Parser _parser = { |
6519 | 0 | .keywords = _keywords, |
6520 | 0 | .fname = "unshare", |
6521 | 0 | .kwtuple = KWTUPLE, |
6522 | 0 | }; |
6523 | 0 | #undef KWTUPLE |
6524 | 0 | PyObject *argsbuf[1]; |
6525 | 0 | int flags; |
6526 | |
|
6527 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6528 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6529 | 0 | if (!args) { |
6530 | 0 | goto exit; |
6531 | 0 | } |
6532 | 0 | flags = PyLong_AsInt(args[0]); |
6533 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6534 | 0 | goto exit; |
6535 | 0 | } |
6536 | 0 | return_value = os_unshare_impl(module, flags); |
6537 | |
|
6538 | 0 | exit: |
6539 | 0 | return return_value; |
6540 | 0 | } |
6541 | | |
6542 | | #endif /* defined(HAVE_UNSHARE) */ |
6543 | | |
6544 | | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
6545 | | |
6546 | | PyDoc_STRVAR(os_readlink__doc__, |
6547 | | "readlink($module, /, path, *, dir_fd=None)\n" |
6548 | | "--\n" |
6549 | | "\n" |
6550 | | "Return a string representing the path to which the symbolic link points.\n" |
6551 | | "\n" |
6552 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6553 | | "and path should be relative; path will then be relative to that directory.\n" |
6554 | | "\n" |
6555 | | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
6556 | | "using it will raise a NotImplementedError."); |
6557 | | |
6558 | | #define OS_READLINK_METHODDEF \ |
6559 | | {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
6560 | | |
6561 | | static PyObject * |
6562 | | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
6563 | | |
6564 | | static PyObject * |
6565 | | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6566 | 0 | { |
6567 | 0 | PyObject *return_value = NULL; |
6568 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6569 | |
|
6570 | 0 | #define NUM_KEYWORDS 2 |
6571 | 0 | static struct { |
6572 | 0 | PyGC_Head _this_is_not_used; |
6573 | 0 | PyObject_VAR_HEAD |
6574 | 0 | Py_hash_t ob_hash; |
6575 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6576 | 0 | } _kwtuple = { |
6577 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6578 | 0 | .ob_hash = -1, |
6579 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), }, |
6580 | 0 | }; |
6581 | 0 | #undef NUM_KEYWORDS |
6582 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6583 | |
|
6584 | | #else // !Py_BUILD_CORE |
6585 | | # define KWTUPLE NULL |
6586 | | #endif // !Py_BUILD_CORE |
6587 | |
|
6588 | 0 | static const char * const _keywords[] = {"path", "dir_fd", NULL}; |
6589 | 0 | static _PyArg_Parser _parser = { |
6590 | 0 | .keywords = _keywords, |
6591 | 0 | .fname = "readlink", |
6592 | 0 | .kwtuple = KWTUPLE, |
6593 | 0 | }; |
6594 | 0 | #undef KWTUPLE |
6595 | 0 | PyObject *argsbuf[2]; |
6596 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6597 | 0 | path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0); |
6598 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6599 | |
|
6600 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6601 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6602 | 0 | if (!args) { |
6603 | 0 | goto exit; |
6604 | 0 | } |
6605 | 0 | if (!path_converter(args[0], &path)) { |
6606 | 0 | goto exit; |
6607 | 0 | } |
6608 | 0 | if (!noptargs) { |
6609 | 0 | goto skip_optional_kwonly; |
6610 | 0 | } |
6611 | 0 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
6612 | 0 | goto exit; |
6613 | 0 | } |
6614 | 0 | skip_optional_kwonly: |
6615 | 0 | return_value = os_readlink_impl(module, &path, dir_fd); |
6616 | |
|
6617 | 0 | exit: |
6618 | | /* Cleanup for path */ |
6619 | 0 | path_cleanup(&path); |
6620 | |
|
6621 | 0 | return return_value; |
6622 | 0 | } |
6623 | | |
6624 | | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
6625 | | |
6626 | | #if defined(HAVE_SYMLINK) |
6627 | | |
6628 | | PyDoc_STRVAR(os_symlink__doc__, |
6629 | | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
6630 | | "--\n" |
6631 | | "\n" |
6632 | | "Create a symbolic link pointing to src named dst.\n" |
6633 | | "\n" |
6634 | | "target_is_directory is required on Windows if the target is to be\n" |
6635 | | " interpreted as a directory. (On Windows, symlink requires\n" |
6636 | | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
6637 | | " target_is_directory is ignored on non-Windows platforms.\n" |
6638 | | "\n" |
6639 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
6640 | | " and path should be relative; path will then be relative to that directory.\n" |
6641 | | "dir_fd may not be implemented on your platform.\n" |
6642 | | " If it is unavailable, using it will raise a NotImplementedError."); |
6643 | | |
6644 | | #define OS_SYMLINK_METHODDEF \ |
6645 | | {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
6646 | | |
6647 | | static PyObject * |
6648 | | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
6649 | | int target_is_directory, int dir_fd); |
6650 | | |
6651 | | static PyObject * |
6652 | | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6653 | 0 | { |
6654 | 0 | PyObject *return_value = NULL; |
6655 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6656 | |
|
6657 | 0 | #define NUM_KEYWORDS 4 |
6658 | 0 | static struct { |
6659 | 0 | PyGC_Head _this_is_not_used; |
6660 | 0 | PyObject_VAR_HEAD |
6661 | 0 | Py_hash_t ob_hash; |
6662 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6663 | 0 | } _kwtuple = { |
6664 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6665 | 0 | .ob_hash = -1, |
6666 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), }, |
6667 | 0 | }; |
6668 | 0 | #undef NUM_KEYWORDS |
6669 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6670 | |
|
6671 | | #else // !Py_BUILD_CORE |
6672 | | # define KWTUPLE NULL |
6673 | | #endif // !Py_BUILD_CORE |
6674 | |
|
6675 | 0 | static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; |
6676 | 0 | static _PyArg_Parser _parser = { |
6677 | 0 | .keywords = _keywords, |
6678 | 0 | .fname = "symlink", |
6679 | 0 | .kwtuple = KWTUPLE, |
6680 | 0 | }; |
6681 | 0 | #undef KWTUPLE |
6682 | 0 | PyObject *argsbuf[4]; |
6683 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
6684 | 0 | path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0); |
6685 | 0 | path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0); |
6686 | 0 | int target_is_directory = 0; |
6687 | 0 | int dir_fd = DEFAULT_DIR_FD; |
6688 | |
|
6689 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6690 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6691 | 0 | if (!args) { |
6692 | 0 | goto exit; |
6693 | 0 | } |
6694 | 0 | if (!path_converter(args[0], &src)) { |
6695 | 0 | goto exit; |
6696 | 0 | } |
6697 | 0 | if (!path_converter(args[1], &dst)) { |
6698 | 0 | goto exit; |
6699 | 0 | } |
6700 | 0 | if (!noptargs) { |
6701 | 0 | goto skip_optional_pos; |
6702 | 0 | } |
6703 | 0 | if (args[2]) { |
6704 | 0 | target_is_directory = PyObject_IsTrue(args[2]); |
6705 | 0 | if (target_is_directory < 0) { |
6706 | 0 | goto exit; |
6707 | 0 | } |
6708 | 0 | if (!--noptargs) { |
6709 | 0 | goto skip_optional_pos; |
6710 | 0 | } |
6711 | 0 | } |
6712 | 0 | skip_optional_pos: |
6713 | 0 | if (!noptargs) { |
6714 | 0 | goto skip_optional_kwonly; |
6715 | 0 | } |
6716 | 0 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
6717 | 0 | goto exit; |
6718 | 0 | } |
6719 | 0 | skip_optional_kwonly: |
6720 | 0 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
6721 | |
|
6722 | 0 | exit: |
6723 | | /* Cleanup for src */ |
6724 | 0 | path_cleanup(&src); |
6725 | | /* Cleanup for dst */ |
6726 | 0 | path_cleanup(&dst); |
6727 | |
|
6728 | 0 | return return_value; |
6729 | 0 | } |
6730 | | |
6731 | | #endif /* defined(HAVE_SYMLINK) */ |
6732 | | |
6733 | | PyDoc_STRVAR(os_times__doc__, |
6734 | | "times($module, /)\n" |
6735 | | "--\n" |
6736 | | "\n" |
6737 | | "Return a collection containing process timing information.\n" |
6738 | | "\n" |
6739 | | "The object returned behaves like a named tuple with these fields:\n" |
6740 | | " (utime, stime, cutime, cstime, elapsed_time)\n" |
6741 | | "All fields are floating-point numbers."); |
6742 | | |
6743 | | #define OS_TIMES_METHODDEF \ |
6744 | | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
6745 | | |
6746 | | static PyObject * |
6747 | | os_times_impl(PyObject *module); |
6748 | | |
6749 | | static PyObject * |
6750 | | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
6751 | 0 | { |
6752 | 0 | return os_times_impl(module); |
6753 | 0 | } |
6754 | | |
6755 | | #if defined(HAVE_TIMERFD_CREATE) |
6756 | | |
6757 | | PyDoc_STRVAR(os_timerfd_create__doc__, |
6758 | | "timerfd_create($module, clockid, /, *, flags=0)\n" |
6759 | | "--\n" |
6760 | | "\n" |
6761 | | "Create and return a timer file descriptor.\n" |
6762 | | "\n" |
6763 | | " clockid\n" |
6764 | | " A valid clock ID constant as timer file descriptor.\n" |
6765 | | "\n" |
6766 | | " time.CLOCK_REALTIME\n" |
6767 | | " time.CLOCK_MONOTONIC\n" |
6768 | | " time.CLOCK_BOOTTIME\n" |
6769 | | " flags\n" |
6770 | | " 0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n" |
6771 | | "\n" |
6772 | | " os.TFD_NONBLOCK\n" |
6773 | | " If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n" |
6774 | | " If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n" |
6775 | | "\n" |
6776 | | " os.TFD_CLOEXEC\n" |
6777 | | " If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag"); |
6778 | | |
6779 | | #define OS_TIMERFD_CREATE_METHODDEF \ |
6780 | | {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__}, |
6781 | | |
6782 | | static PyObject * |
6783 | | os_timerfd_create_impl(PyObject *module, int clockid, int flags); |
6784 | | |
6785 | | static PyObject * |
6786 | | os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6787 | 0 | { |
6788 | 0 | PyObject *return_value = NULL; |
6789 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6790 | |
|
6791 | 0 | #define NUM_KEYWORDS 1 |
6792 | 0 | static struct { |
6793 | 0 | PyGC_Head _this_is_not_used; |
6794 | 0 | PyObject_VAR_HEAD |
6795 | 0 | Py_hash_t ob_hash; |
6796 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6797 | 0 | } _kwtuple = { |
6798 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6799 | 0 | .ob_hash = -1, |
6800 | 0 | .ob_item = { &_Py_ID(flags), }, |
6801 | 0 | }; |
6802 | 0 | #undef NUM_KEYWORDS |
6803 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6804 | |
|
6805 | | #else // !Py_BUILD_CORE |
6806 | | # define KWTUPLE NULL |
6807 | | #endif // !Py_BUILD_CORE |
6808 | |
|
6809 | 0 | static const char * const _keywords[] = {"", "flags", NULL}; |
6810 | 0 | static _PyArg_Parser _parser = { |
6811 | 0 | .keywords = _keywords, |
6812 | 0 | .fname = "timerfd_create", |
6813 | 0 | .kwtuple = KWTUPLE, |
6814 | 0 | }; |
6815 | 0 | #undef KWTUPLE |
6816 | 0 | PyObject *argsbuf[2]; |
6817 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6818 | 0 | int clockid; |
6819 | 0 | int flags = 0; |
6820 | |
|
6821 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6822 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6823 | 0 | if (!args) { |
6824 | 0 | goto exit; |
6825 | 0 | } |
6826 | 0 | clockid = PyLong_AsInt(args[0]); |
6827 | 0 | if (clockid == -1 && PyErr_Occurred()) { |
6828 | 0 | goto exit; |
6829 | 0 | } |
6830 | 0 | if (!noptargs) { |
6831 | 0 | goto skip_optional_kwonly; |
6832 | 0 | } |
6833 | 0 | flags = PyLong_AsInt(args[1]); |
6834 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6835 | 0 | goto exit; |
6836 | 0 | } |
6837 | 0 | skip_optional_kwonly: |
6838 | 0 | return_value = os_timerfd_create_impl(module, clockid, flags); |
6839 | |
|
6840 | 0 | exit: |
6841 | 0 | return return_value; |
6842 | 0 | } |
6843 | | |
6844 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6845 | | |
6846 | | #if defined(HAVE_TIMERFD_CREATE) |
6847 | | |
6848 | | PyDoc_STRVAR(os_timerfd_settime__doc__, |
6849 | | "timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n" |
6850 | | "--\n" |
6851 | | "\n" |
6852 | | "Alter a timer file descriptor\'s internal timer in seconds.\n" |
6853 | | "\n" |
6854 | | " fd\n" |
6855 | | " A timer file descriptor.\n" |
6856 | | " flags\n" |
6857 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6858 | | " initial\n" |
6859 | | " The initial expiration time, in seconds.\n" |
6860 | | " interval\n" |
6861 | | " The timer\'s interval, in seconds."); |
6862 | | |
6863 | | #define OS_TIMERFD_SETTIME_METHODDEF \ |
6864 | | {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__}, |
6865 | | |
6866 | | static PyObject * |
6867 | | os_timerfd_settime_impl(PyObject *module, int fd, int flags, |
6868 | | double initial_double, double interval_double); |
6869 | | |
6870 | | static PyObject * |
6871 | | os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6872 | 0 | { |
6873 | 0 | PyObject *return_value = NULL; |
6874 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6875 | |
|
6876 | 0 | #define NUM_KEYWORDS 3 |
6877 | 0 | static struct { |
6878 | 0 | PyGC_Head _this_is_not_used; |
6879 | 0 | PyObject_VAR_HEAD |
6880 | 0 | Py_hash_t ob_hash; |
6881 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6882 | 0 | } _kwtuple = { |
6883 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
6884 | 0 | .ob_hash = -1, |
6885 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
6886 | 0 | }; |
6887 | 0 | #undef NUM_KEYWORDS |
6888 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
6889 | |
|
6890 | | #else // !Py_BUILD_CORE |
6891 | | # define KWTUPLE NULL |
6892 | | #endif // !Py_BUILD_CORE |
6893 | |
|
6894 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
6895 | 0 | static _PyArg_Parser _parser = { |
6896 | 0 | .keywords = _keywords, |
6897 | 0 | .fname = "timerfd_settime", |
6898 | 0 | .kwtuple = KWTUPLE, |
6899 | 0 | }; |
6900 | 0 | #undef KWTUPLE |
6901 | 0 | PyObject *argsbuf[4]; |
6902 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
6903 | 0 | int fd; |
6904 | 0 | int flags = 0; |
6905 | 0 | double initial_double = 0.0; |
6906 | 0 | double interval_double = 0.0; |
6907 | |
|
6908 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
6909 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
6910 | 0 | if (!args) { |
6911 | 0 | goto exit; |
6912 | 0 | } |
6913 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
6914 | 0 | if (fd < 0) { |
6915 | 0 | goto exit; |
6916 | 0 | } |
6917 | 0 | if (!noptargs) { |
6918 | 0 | goto skip_optional_kwonly; |
6919 | 0 | } |
6920 | 0 | if (args[1]) { |
6921 | 0 | flags = PyLong_AsInt(args[1]); |
6922 | 0 | if (flags == -1 && PyErr_Occurred()) { |
6923 | 0 | goto exit; |
6924 | 0 | } |
6925 | 0 | if (!--noptargs) { |
6926 | 0 | goto skip_optional_kwonly; |
6927 | 0 | } |
6928 | 0 | } |
6929 | 0 | if (args[2]) { |
6930 | 0 | if (PyFloat_CheckExact(args[2])) { |
6931 | 0 | initial_double = PyFloat_AS_DOUBLE(args[2]); |
6932 | 0 | } |
6933 | 0 | else |
6934 | 0 | { |
6935 | 0 | initial_double = PyFloat_AsDouble(args[2]); |
6936 | 0 | if (initial_double == -1.0 && PyErr_Occurred()) { |
6937 | 0 | goto exit; |
6938 | 0 | } |
6939 | 0 | } |
6940 | 0 | if (!--noptargs) { |
6941 | 0 | goto skip_optional_kwonly; |
6942 | 0 | } |
6943 | 0 | } |
6944 | 0 | if (PyFloat_CheckExact(args[3])) { |
6945 | 0 | interval_double = PyFloat_AS_DOUBLE(args[3]); |
6946 | 0 | } |
6947 | 0 | else |
6948 | 0 | { |
6949 | 0 | interval_double = PyFloat_AsDouble(args[3]); |
6950 | 0 | if (interval_double == -1.0 && PyErr_Occurred()) { |
6951 | 0 | goto exit; |
6952 | 0 | } |
6953 | 0 | } |
6954 | 0 | skip_optional_kwonly: |
6955 | 0 | return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double); |
6956 | |
|
6957 | 0 | exit: |
6958 | 0 | return return_value; |
6959 | 0 | } |
6960 | | |
6961 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
6962 | | |
6963 | | #if defined(HAVE_TIMERFD_CREATE) |
6964 | | |
6965 | | PyDoc_STRVAR(os_timerfd_settime_ns__doc__, |
6966 | | "timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n" |
6967 | | "--\n" |
6968 | | "\n" |
6969 | | "Alter a timer file descriptor\'s internal timer in nanoseconds.\n" |
6970 | | "\n" |
6971 | | " fd\n" |
6972 | | " A timer file descriptor.\n" |
6973 | | " flags\n" |
6974 | | " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n" |
6975 | | " initial\n" |
6976 | | " initial expiration timing in seconds.\n" |
6977 | | " interval\n" |
6978 | | " interval for the timer in seconds."); |
6979 | | |
6980 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF \ |
6981 | | {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__}, |
6982 | | |
6983 | | static PyObject * |
6984 | | os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags, |
6985 | | long long initial, long long interval); |
6986 | | |
6987 | | static PyObject * |
6988 | | os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6989 | 0 | { |
6990 | 0 | PyObject *return_value = NULL; |
6991 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6992 | |
|
6993 | 0 | #define NUM_KEYWORDS 3 |
6994 | 0 | static struct { |
6995 | 0 | PyGC_Head _this_is_not_used; |
6996 | 0 | PyObject_VAR_HEAD |
6997 | 0 | Py_hash_t ob_hash; |
6998 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
6999 | 0 | } _kwtuple = { |
7000 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7001 | 0 | .ob_hash = -1, |
7002 | 0 | .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), }, |
7003 | 0 | }; |
7004 | 0 | #undef NUM_KEYWORDS |
7005 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7006 | |
|
7007 | | #else // !Py_BUILD_CORE |
7008 | | # define KWTUPLE NULL |
7009 | | #endif // !Py_BUILD_CORE |
7010 | |
|
7011 | 0 | static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL}; |
7012 | 0 | static _PyArg_Parser _parser = { |
7013 | 0 | .keywords = _keywords, |
7014 | 0 | .fname = "timerfd_settime_ns", |
7015 | 0 | .kwtuple = KWTUPLE, |
7016 | 0 | }; |
7017 | 0 | #undef KWTUPLE |
7018 | 0 | PyObject *argsbuf[4]; |
7019 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
7020 | 0 | int fd; |
7021 | 0 | int flags = 0; |
7022 | 0 | long long initial = 0; |
7023 | 0 | long long interval = 0; |
7024 | |
|
7025 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7026 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7027 | 0 | if (!args) { |
7028 | 0 | goto exit; |
7029 | 0 | } |
7030 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
7031 | 0 | if (fd < 0) { |
7032 | 0 | goto exit; |
7033 | 0 | } |
7034 | 0 | if (!noptargs) { |
7035 | 0 | goto skip_optional_kwonly; |
7036 | 0 | } |
7037 | 0 | if (args[1]) { |
7038 | 0 | flags = PyLong_AsInt(args[1]); |
7039 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7040 | 0 | goto exit; |
7041 | 0 | } |
7042 | 0 | if (!--noptargs) { |
7043 | 0 | goto skip_optional_kwonly; |
7044 | 0 | } |
7045 | 0 | } |
7046 | 0 | if (args[2]) { |
7047 | 0 | initial = PyLong_AsLongLong(args[2]); |
7048 | 0 | if (initial == -1 && PyErr_Occurred()) { |
7049 | 0 | goto exit; |
7050 | 0 | } |
7051 | 0 | if (!--noptargs) { |
7052 | 0 | goto skip_optional_kwonly; |
7053 | 0 | } |
7054 | 0 | } |
7055 | 0 | interval = PyLong_AsLongLong(args[3]); |
7056 | 0 | if (interval == -1 && PyErr_Occurred()) { |
7057 | 0 | goto exit; |
7058 | 0 | } |
7059 | 0 | skip_optional_kwonly: |
7060 | 0 | return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval); |
7061 | |
|
7062 | 0 | exit: |
7063 | 0 | return return_value; |
7064 | 0 | } |
7065 | | |
7066 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7067 | | |
7068 | | #if defined(HAVE_TIMERFD_CREATE) |
7069 | | |
7070 | | PyDoc_STRVAR(os_timerfd_gettime__doc__, |
7071 | | "timerfd_gettime($module, fd, /)\n" |
7072 | | "--\n" |
7073 | | "\n" |
7074 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n" |
7075 | | "\n" |
7076 | | " fd\n" |
7077 | | " A timer file descriptor."); |
7078 | | |
7079 | | #define OS_TIMERFD_GETTIME_METHODDEF \ |
7080 | | {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__}, |
7081 | | |
7082 | | static PyObject * |
7083 | | os_timerfd_gettime_impl(PyObject *module, int fd); |
7084 | | |
7085 | | static PyObject * |
7086 | | os_timerfd_gettime(PyObject *module, PyObject *arg) |
7087 | 0 | { |
7088 | 0 | PyObject *return_value = NULL; |
7089 | 0 | int fd; |
7090 | |
|
7091 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7092 | 0 | if (fd < 0) { |
7093 | 0 | goto exit; |
7094 | 0 | } |
7095 | 0 | return_value = os_timerfd_gettime_impl(module, fd); |
7096 | |
|
7097 | 0 | exit: |
7098 | 0 | return return_value; |
7099 | 0 | } |
7100 | | |
7101 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7102 | | |
7103 | | #if defined(HAVE_TIMERFD_CREATE) |
7104 | | |
7105 | | PyDoc_STRVAR(os_timerfd_gettime_ns__doc__, |
7106 | | "timerfd_gettime_ns($module, fd, /)\n" |
7107 | | "--\n" |
7108 | | "\n" |
7109 | | "Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n" |
7110 | | "\n" |
7111 | | " fd\n" |
7112 | | " A timer file descriptor."); |
7113 | | |
7114 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF \ |
7115 | | {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__}, |
7116 | | |
7117 | | static PyObject * |
7118 | | os_timerfd_gettime_ns_impl(PyObject *module, int fd); |
7119 | | |
7120 | | static PyObject * |
7121 | | os_timerfd_gettime_ns(PyObject *module, PyObject *arg) |
7122 | 0 | { |
7123 | 0 | PyObject *return_value = NULL; |
7124 | 0 | int fd; |
7125 | |
|
7126 | 0 | fd = PyObject_AsFileDescriptor(arg); |
7127 | 0 | if (fd < 0) { |
7128 | 0 | goto exit; |
7129 | 0 | } |
7130 | 0 | return_value = os_timerfd_gettime_ns_impl(module, fd); |
7131 | |
|
7132 | 0 | exit: |
7133 | 0 | return return_value; |
7134 | 0 | } |
7135 | | |
7136 | | #endif /* defined(HAVE_TIMERFD_CREATE) */ |
7137 | | |
7138 | | #if defined(HAVE_GETSID) |
7139 | | |
7140 | | PyDoc_STRVAR(os_getsid__doc__, |
7141 | | "getsid($module, pid, /)\n" |
7142 | | "--\n" |
7143 | | "\n" |
7144 | | "Call the system call getsid(pid) and return the result."); |
7145 | | |
7146 | | #define OS_GETSID_METHODDEF \ |
7147 | | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
7148 | | |
7149 | | static PyObject * |
7150 | | os_getsid_impl(PyObject *module, pid_t pid); |
7151 | | |
7152 | | static PyObject * |
7153 | | os_getsid(PyObject *module, PyObject *arg) |
7154 | 0 | { |
7155 | 0 | PyObject *return_value = NULL; |
7156 | 0 | pid_t pid; |
7157 | |
|
7158 | 0 | pid = PyLong_AsPid(arg); |
7159 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7160 | 0 | goto exit; |
7161 | 0 | } |
7162 | 0 | return_value = os_getsid_impl(module, pid); |
7163 | |
|
7164 | 0 | exit: |
7165 | 0 | return return_value; |
7166 | 0 | } |
7167 | | |
7168 | | #endif /* defined(HAVE_GETSID) */ |
7169 | | |
7170 | | #if defined(HAVE_SETSID) |
7171 | | |
7172 | | PyDoc_STRVAR(os_setsid__doc__, |
7173 | | "setsid($module, /)\n" |
7174 | | "--\n" |
7175 | | "\n" |
7176 | | "Call the system call setsid()."); |
7177 | | |
7178 | | #define OS_SETSID_METHODDEF \ |
7179 | | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
7180 | | |
7181 | | static PyObject * |
7182 | | os_setsid_impl(PyObject *module); |
7183 | | |
7184 | | static PyObject * |
7185 | | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7186 | 0 | { |
7187 | 0 | return os_setsid_impl(module); |
7188 | 0 | } |
7189 | | |
7190 | | #endif /* defined(HAVE_SETSID) */ |
7191 | | |
7192 | | #if defined(HAVE_SETPGID) |
7193 | | |
7194 | | PyDoc_STRVAR(os_setpgid__doc__, |
7195 | | "setpgid($module, pid, pgrp, /)\n" |
7196 | | "--\n" |
7197 | | "\n" |
7198 | | "Call the system call setpgid(pid, pgrp)."); |
7199 | | |
7200 | | #define OS_SETPGID_METHODDEF \ |
7201 | | {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__}, |
7202 | | |
7203 | | static PyObject * |
7204 | | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
7205 | | |
7206 | | static PyObject * |
7207 | | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7208 | 0 | { |
7209 | 0 | PyObject *return_value = NULL; |
7210 | 0 | pid_t pid; |
7211 | 0 | pid_t pgrp; |
7212 | |
|
7213 | 0 | if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) { |
7214 | 0 | goto exit; |
7215 | 0 | } |
7216 | 0 | pid = PyLong_AsPid(args[0]); |
7217 | 0 | if (pid == (pid_t)(-1) && PyErr_Occurred()) { |
7218 | 0 | goto exit; |
7219 | 0 | } |
7220 | 0 | pgrp = PyLong_AsPid(args[1]); |
7221 | 0 | if (pgrp == (pid_t)(-1) && PyErr_Occurred()) { |
7222 | 0 | goto exit; |
7223 | 0 | } |
7224 | 0 | return_value = os_setpgid_impl(module, pid, pgrp); |
7225 | |
|
7226 | 0 | exit: |
7227 | 0 | return return_value; |
7228 | 0 | } |
7229 | | |
7230 | | #endif /* defined(HAVE_SETPGID) */ |
7231 | | |
7232 | | #if defined(HAVE_TCGETPGRP) |
7233 | | |
7234 | | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
7235 | | "tcgetpgrp($module, fd, /)\n" |
7236 | | "--\n" |
7237 | | "\n" |
7238 | | "Return the process group associated with the terminal specified by fd."); |
7239 | | |
7240 | | #define OS_TCGETPGRP_METHODDEF \ |
7241 | | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
7242 | | |
7243 | | static PyObject * |
7244 | | os_tcgetpgrp_impl(PyObject *module, int fd); |
7245 | | |
7246 | | static PyObject * |
7247 | | os_tcgetpgrp(PyObject *module, PyObject *arg) |
7248 | 0 | { |
7249 | 0 | PyObject *return_value = NULL; |
7250 | 0 | int fd; |
7251 | |
|
7252 | 0 | fd = PyLong_AsInt(arg); |
7253 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7254 | 0 | goto exit; |
7255 | 0 | } |
7256 | 0 | return_value = os_tcgetpgrp_impl(module, fd); |
7257 | |
|
7258 | 0 | exit: |
7259 | 0 | return return_value; |
7260 | 0 | } |
7261 | | |
7262 | | #endif /* defined(HAVE_TCGETPGRP) */ |
7263 | | |
7264 | | #if defined(HAVE_TCSETPGRP) |
7265 | | |
7266 | | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
7267 | | "tcsetpgrp($module, fd, pgid, /)\n" |
7268 | | "--\n" |
7269 | | "\n" |
7270 | | "Set the process group associated with the terminal specified by fd."); |
7271 | | |
7272 | | #define OS_TCSETPGRP_METHODDEF \ |
7273 | | {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__}, |
7274 | | |
7275 | | static PyObject * |
7276 | | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
7277 | | |
7278 | | static PyObject * |
7279 | | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7280 | 0 | { |
7281 | 0 | PyObject *return_value = NULL; |
7282 | 0 | int fd; |
7283 | 0 | pid_t pgid; |
7284 | |
|
7285 | 0 | if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) { |
7286 | 0 | goto exit; |
7287 | 0 | } |
7288 | 0 | fd = PyLong_AsInt(args[0]); |
7289 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7290 | 0 | goto exit; |
7291 | 0 | } |
7292 | 0 | pgid = PyLong_AsPid(args[1]); |
7293 | 0 | if (pgid == (pid_t)(-1) && PyErr_Occurred()) { |
7294 | 0 | goto exit; |
7295 | 0 | } |
7296 | 0 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
7297 | |
|
7298 | 0 | exit: |
7299 | 0 | return return_value; |
7300 | 0 | } |
7301 | | |
7302 | | #endif /* defined(HAVE_TCSETPGRP) */ |
7303 | | |
7304 | | PyDoc_STRVAR(os_open__doc__, |
7305 | | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
7306 | | "--\n" |
7307 | | "\n" |
7308 | | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
7309 | | "\n" |
7310 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
7311 | | " and path should be relative; path will then be relative to that directory.\n" |
7312 | | "dir_fd may not be implemented on your platform.\n" |
7313 | | " If it is unavailable, using it will raise a NotImplementedError."); |
7314 | | |
7315 | | #define OS_OPEN_METHODDEF \ |
7316 | | {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
7317 | | |
7318 | | static int |
7319 | | os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd); |
7320 | | |
7321 | | static PyObject * |
7322 | | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7323 | 241 | { |
7324 | 241 | PyObject *return_value = NULL; |
7325 | 241 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7326 | | |
7327 | 241 | #define NUM_KEYWORDS 4 |
7328 | 241 | static struct { |
7329 | 241 | PyGC_Head _this_is_not_used; |
7330 | 241 | PyObject_VAR_HEAD |
7331 | 241 | Py_hash_t ob_hash; |
7332 | 241 | PyObject *ob_item[NUM_KEYWORDS]; |
7333 | 241 | } _kwtuple = { |
7334 | 241 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7335 | 241 | .ob_hash = -1, |
7336 | 241 | .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
7337 | 241 | }; |
7338 | 241 | #undef NUM_KEYWORDS |
7339 | 241 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7340 | | |
7341 | | #else // !Py_BUILD_CORE |
7342 | | # define KWTUPLE NULL |
7343 | | #endif // !Py_BUILD_CORE |
7344 | | |
7345 | 241 | static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; |
7346 | 241 | static _PyArg_Parser _parser = { |
7347 | 241 | .keywords = _keywords, |
7348 | 241 | .fname = "open", |
7349 | 241 | .kwtuple = KWTUPLE, |
7350 | 241 | }; |
7351 | 241 | #undef KWTUPLE |
7352 | 241 | PyObject *argsbuf[4]; |
7353 | 241 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7354 | 241 | path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0); |
7355 | 241 | int flags; |
7356 | 241 | int mode = 511; |
7357 | 241 | int dir_fd = DEFAULT_DIR_FD; |
7358 | 241 | int _return_value; |
7359 | | |
7360 | 241 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7361 | 241 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7362 | 241 | if (!args) { |
7363 | 0 | goto exit; |
7364 | 0 | } |
7365 | 241 | if (!path_converter(args[0], &path)) { |
7366 | 0 | goto exit; |
7367 | 0 | } |
7368 | 241 | flags = PyLong_AsInt(args[1]); |
7369 | 241 | if (flags == -1 && PyErr_Occurred()) { |
7370 | 0 | goto exit; |
7371 | 0 | } |
7372 | 241 | if (!noptargs) { |
7373 | 0 | goto skip_optional_pos; |
7374 | 0 | } |
7375 | 241 | if (args[2]) { |
7376 | 241 | mode = PyLong_AsInt(args[2]); |
7377 | 241 | if (mode == -1 && PyErr_Occurred()) { |
7378 | 0 | goto exit; |
7379 | 0 | } |
7380 | 241 | if (!--noptargs) { |
7381 | 241 | goto skip_optional_pos; |
7382 | 241 | } |
7383 | 241 | } |
7384 | 241 | skip_optional_pos: |
7385 | 241 | if (!noptargs) { |
7386 | 241 | goto skip_optional_kwonly; |
7387 | 241 | } |
7388 | 0 | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
7389 | 0 | goto exit; |
7390 | 0 | } |
7391 | 241 | skip_optional_kwonly: |
7392 | 241 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
7393 | 241 | if ((_return_value == -1) && PyErr_Occurred()) { |
7394 | 0 | goto exit; |
7395 | 0 | } |
7396 | 241 | return_value = PyLong_FromLong((long)_return_value); |
7397 | | |
7398 | 241 | exit: |
7399 | | /* Cleanup for path */ |
7400 | 241 | path_cleanup(&path); |
7401 | | |
7402 | 241 | return return_value; |
7403 | 241 | } |
7404 | | |
7405 | | PyDoc_STRVAR(os_close__doc__, |
7406 | | "close($module, /, fd)\n" |
7407 | | "--\n" |
7408 | | "\n" |
7409 | | "Close a file descriptor."); |
7410 | | |
7411 | | #define OS_CLOSE_METHODDEF \ |
7412 | | {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
7413 | | |
7414 | | static PyObject * |
7415 | | os_close_impl(PyObject *module, int fd); |
7416 | | |
7417 | | static PyObject * |
7418 | | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7419 | 0 | { |
7420 | 0 | PyObject *return_value = NULL; |
7421 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7422 | |
|
7423 | 0 | #define NUM_KEYWORDS 1 |
7424 | 0 | static struct { |
7425 | 0 | PyGC_Head _this_is_not_used; |
7426 | 0 | PyObject_VAR_HEAD |
7427 | 0 | Py_hash_t ob_hash; |
7428 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7429 | 0 | } _kwtuple = { |
7430 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7431 | 0 | .ob_hash = -1, |
7432 | 0 | .ob_item = { &_Py_ID(fd), }, |
7433 | 0 | }; |
7434 | 0 | #undef NUM_KEYWORDS |
7435 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7436 | |
|
7437 | | #else // !Py_BUILD_CORE |
7438 | | # define KWTUPLE NULL |
7439 | | #endif // !Py_BUILD_CORE |
7440 | |
|
7441 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
7442 | 0 | static _PyArg_Parser _parser = { |
7443 | 0 | .keywords = _keywords, |
7444 | 0 | .fname = "close", |
7445 | 0 | .kwtuple = KWTUPLE, |
7446 | 0 | }; |
7447 | 0 | #undef KWTUPLE |
7448 | 0 | PyObject *argsbuf[1]; |
7449 | 0 | int fd; |
7450 | |
|
7451 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7452 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7453 | 0 | if (!args) { |
7454 | 0 | goto exit; |
7455 | 0 | } |
7456 | 0 | fd = PyLong_AsInt(args[0]); |
7457 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7458 | 0 | goto exit; |
7459 | 0 | } |
7460 | 0 | return_value = os_close_impl(module, fd); |
7461 | |
|
7462 | 0 | exit: |
7463 | 0 | return return_value; |
7464 | 0 | } |
7465 | | |
7466 | | PyDoc_STRVAR(os_closerange__doc__, |
7467 | | "closerange($module, fd_low, fd_high, /)\n" |
7468 | | "--\n" |
7469 | | "\n" |
7470 | | "Closes all file descriptors in [fd_low, fd_high), ignoring errors."); |
7471 | | |
7472 | | #define OS_CLOSERANGE_METHODDEF \ |
7473 | | {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__}, |
7474 | | |
7475 | | static PyObject * |
7476 | | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
7477 | | |
7478 | | static PyObject * |
7479 | | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7480 | 0 | { |
7481 | 0 | PyObject *return_value = NULL; |
7482 | 0 | int fd_low; |
7483 | 0 | int fd_high; |
7484 | |
|
7485 | 0 | if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { |
7486 | 0 | goto exit; |
7487 | 0 | } |
7488 | 0 | fd_low = PyLong_AsInt(args[0]); |
7489 | 0 | if (fd_low == -1 && PyErr_Occurred()) { |
7490 | 0 | goto exit; |
7491 | 0 | } |
7492 | 0 | fd_high = PyLong_AsInt(args[1]); |
7493 | 0 | if (fd_high == -1 && PyErr_Occurred()) { |
7494 | 0 | goto exit; |
7495 | 0 | } |
7496 | 0 | return_value = os_closerange_impl(module, fd_low, fd_high); |
7497 | |
|
7498 | 0 | exit: |
7499 | 0 | return return_value; |
7500 | 0 | } |
7501 | | |
7502 | | PyDoc_STRVAR(os_dup__doc__, |
7503 | | "dup($module, fd, /)\n" |
7504 | | "--\n" |
7505 | | "\n" |
7506 | | "Return a duplicate of a file descriptor."); |
7507 | | |
7508 | | #define OS_DUP_METHODDEF \ |
7509 | | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
7510 | | |
7511 | | static int |
7512 | | os_dup_impl(PyObject *module, int fd); |
7513 | | |
7514 | | static PyObject * |
7515 | | os_dup(PyObject *module, PyObject *arg) |
7516 | 0 | { |
7517 | 0 | PyObject *return_value = NULL; |
7518 | 0 | int fd; |
7519 | 0 | int _return_value; |
7520 | |
|
7521 | 0 | fd = PyLong_AsInt(arg); |
7522 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7523 | 0 | goto exit; |
7524 | 0 | } |
7525 | 0 | _return_value = os_dup_impl(module, fd); |
7526 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7527 | 0 | goto exit; |
7528 | 0 | } |
7529 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7530 | |
|
7531 | 0 | exit: |
7532 | 0 | return return_value; |
7533 | 0 | } |
7534 | | |
7535 | | #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) |
7536 | | |
7537 | | PyDoc_STRVAR(os_dup2__doc__, |
7538 | | "dup2($module, /, fd, fd2, inheritable=True)\n" |
7539 | | "--\n" |
7540 | | "\n" |
7541 | | "Duplicate file descriptor."); |
7542 | | |
7543 | | #define OS_DUP2_METHODDEF \ |
7544 | | {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
7545 | | |
7546 | | static int |
7547 | | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
7548 | | |
7549 | | static PyObject * |
7550 | | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7551 | 0 | { |
7552 | 0 | PyObject *return_value = NULL; |
7553 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
7554 | |
|
7555 | 0 | #define NUM_KEYWORDS 3 |
7556 | 0 | static struct { |
7557 | 0 | PyGC_Head _this_is_not_used; |
7558 | 0 | PyObject_VAR_HEAD |
7559 | 0 | Py_hash_t ob_hash; |
7560 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
7561 | 0 | } _kwtuple = { |
7562 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
7563 | 0 | .ob_hash = -1, |
7564 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), }, |
7565 | 0 | }; |
7566 | 0 | #undef NUM_KEYWORDS |
7567 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
7568 | |
|
7569 | | #else // !Py_BUILD_CORE |
7570 | | # define KWTUPLE NULL |
7571 | | #endif // !Py_BUILD_CORE |
7572 | |
|
7573 | 0 | static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL}; |
7574 | 0 | static _PyArg_Parser _parser = { |
7575 | 0 | .keywords = _keywords, |
7576 | 0 | .fname = "dup2", |
7577 | 0 | .kwtuple = KWTUPLE, |
7578 | 0 | }; |
7579 | 0 | #undef KWTUPLE |
7580 | 0 | PyObject *argsbuf[3]; |
7581 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7582 | 0 | int fd; |
7583 | 0 | int fd2; |
7584 | 0 | int inheritable = 1; |
7585 | 0 | int _return_value; |
7586 | |
|
7587 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
7588 | 0 | /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
7589 | 0 | if (!args) { |
7590 | 0 | goto exit; |
7591 | 0 | } |
7592 | 0 | fd = PyLong_AsInt(args[0]); |
7593 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7594 | 0 | goto exit; |
7595 | 0 | } |
7596 | 0 | fd2 = PyLong_AsInt(args[1]); |
7597 | 0 | if (fd2 == -1 && PyErr_Occurred()) { |
7598 | 0 | goto exit; |
7599 | 0 | } |
7600 | 0 | if (!noptargs) { |
7601 | 0 | goto skip_optional_pos; |
7602 | 0 | } |
7603 | 0 | inheritable = PyObject_IsTrue(args[2]); |
7604 | 0 | if (inheritable < 0) { |
7605 | 0 | goto exit; |
7606 | 0 | } |
7607 | 0 | skip_optional_pos: |
7608 | 0 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
7609 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7610 | 0 | goto exit; |
7611 | 0 | } |
7612 | 0 | return_value = PyLong_FromLong((long)_return_value); |
7613 | |
|
7614 | 0 | exit: |
7615 | 0 | return return_value; |
7616 | 0 | } |
7617 | | |
7618 | | #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */ |
7619 | | |
7620 | | #if defined(HAVE_LOCKF) |
7621 | | |
7622 | | PyDoc_STRVAR(os_lockf__doc__, |
7623 | | "lockf($module, fd, command, length, /)\n" |
7624 | | "--\n" |
7625 | | "\n" |
7626 | | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
7627 | | "\n" |
7628 | | " fd\n" |
7629 | | " An open file descriptor.\n" |
7630 | | " command\n" |
7631 | | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
7632 | | " length\n" |
7633 | | " The number of bytes to lock, starting at the current position."); |
7634 | | |
7635 | | #define OS_LOCKF_METHODDEF \ |
7636 | | {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__}, |
7637 | | |
7638 | | static PyObject * |
7639 | | os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length); |
7640 | | |
7641 | | static PyObject * |
7642 | | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7643 | 0 | { |
7644 | 0 | PyObject *return_value = NULL; |
7645 | 0 | int fd; |
7646 | 0 | int command; |
7647 | 0 | Py_off_t length; |
7648 | |
|
7649 | 0 | if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { |
7650 | 0 | goto exit; |
7651 | 0 | } |
7652 | 0 | fd = PyLong_AsInt(args[0]); |
7653 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7654 | 0 | goto exit; |
7655 | 0 | } |
7656 | 0 | command = PyLong_AsInt(args[1]); |
7657 | 0 | if (command == -1 && PyErr_Occurred()) { |
7658 | 0 | goto exit; |
7659 | 0 | } |
7660 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
7661 | 0 | goto exit; |
7662 | 0 | } |
7663 | 0 | return_value = os_lockf_impl(module, fd, command, length); |
7664 | |
|
7665 | 0 | exit: |
7666 | 0 | return return_value; |
7667 | 0 | } |
7668 | | |
7669 | | #endif /* defined(HAVE_LOCKF) */ |
7670 | | |
7671 | | PyDoc_STRVAR(os_lseek__doc__, |
7672 | | "lseek($module, fd, position, whence, /)\n" |
7673 | | "--\n" |
7674 | | "\n" |
7675 | | "Set the position of a file descriptor. Return the new position.\n" |
7676 | | "\n" |
7677 | | " fd\n" |
7678 | | " An open file descriptor, as returned by os.open().\n" |
7679 | | " position\n" |
7680 | | " Position, interpreted relative to \'whence\'.\n" |
7681 | | " whence\n" |
7682 | | " The relative position to seek from. Valid values are:\n" |
7683 | | " - SEEK_SET: seek from the start of the file.\n" |
7684 | | " - SEEK_CUR: seek from the current file position.\n" |
7685 | | " - SEEK_END: seek from the end of the file.\n" |
7686 | | "\n" |
7687 | | "The return value is the number of bytes relative to the beginning of the file."); |
7688 | | |
7689 | | #define OS_LSEEK_METHODDEF \ |
7690 | | {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__}, |
7691 | | |
7692 | | static Py_off_t |
7693 | | os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how); |
7694 | | |
7695 | | static PyObject * |
7696 | | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7697 | 0 | { |
7698 | 0 | PyObject *return_value = NULL; |
7699 | 0 | int fd; |
7700 | 0 | Py_off_t position; |
7701 | 0 | int how; |
7702 | 0 | Py_off_t _return_value; |
7703 | |
|
7704 | 0 | if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { |
7705 | 0 | goto exit; |
7706 | 0 | } |
7707 | 0 | fd = PyLong_AsInt(args[0]); |
7708 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7709 | 0 | goto exit; |
7710 | 0 | } |
7711 | 0 | if (!Py_off_t_converter(args[1], &position)) { |
7712 | 0 | goto exit; |
7713 | 0 | } |
7714 | 0 | how = PyLong_AsInt(args[2]); |
7715 | 0 | if (how == -1 && PyErr_Occurred()) { |
7716 | 0 | goto exit; |
7717 | 0 | } |
7718 | 0 | _return_value = os_lseek_impl(module, fd, position, how); |
7719 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7720 | 0 | goto exit; |
7721 | 0 | } |
7722 | 0 | return_value = PyLong_FromPy_off_t(_return_value); |
7723 | |
|
7724 | 0 | exit: |
7725 | 0 | return return_value; |
7726 | 0 | } |
7727 | | |
7728 | | PyDoc_STRVAR(os_read__doc__, |
7729 | | "read($module, fd, length, /)\n" |
7730 | | "--\n" |
7731 | | "\n" |
7732 | | "Read from a file descriptor. Returns a bytes object."); |
7733 | | |
7734 | | #define OS_READ_METHODDEF \ |
7735 | | {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__}, |
7736 | | |
7737 | | static PyObject * |
7738 | | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
7739 | | |
7740 | | static PyObject * |
7741 | | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7742 | 0 | { |
7743 | 0 | PyObject *return_value = NULL; |
7744 | 0 | int fd; |
7745 | 0 | Py_ssize_t length; |
7746 | |
|
7747 | 0 | if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { |
7748 | 0 | goto exit; |
7749 | 0 | } |
7750 | 0 | fd = PyLong_AsInt(args[0]); |
7751 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7752 | 0 | goto exit; |
7753 | 0 | } |
7754 | 0 | { |
7755 | 0 | Py_ssize_t ival = -1; |
7756 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7757 | 0 | if (iobj != NULL) { |
7758 | 0 | ival = PyLong_AsSsize_t(iobj); |
7759 | 0 | Py_DECREF(iobj); |
7760 | 0 | } |
7761 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7762 | 0 | goto exit; |
7763 | 0 | } |
7764 | 0 | length = ival; |
7765 | 0 | } |
7766 | 0 | return_value = os_read_impl(module, fd, length); |
7767 | |
|
7768 | 0 | exit: |
7769 | 0 | return return_value; |
7770 | 0 | } |
7771 | | |
7772 | | PyDoc_STRVAR(os_readinto__doc__, |
7773 | | "readinto($module, fd, buffer, /)\n" |
7774 | | "--\n" |
7775 | | "\n" |
7776 | | "Read into a buffer object from a file descriptor.\n" |
7777 | | "\n" |
7778 | | "The buffer should be mutable and bytes-like. On success, returns the number of\n" |
7779 | | "bytes read. Less bytes may be read than the size of the buffer. The underlying\n" |
7780 | | "system call will be retried when interrupted by a signal, unless the signal\n" |
7781 | | "handler raises an exception. Other errors will not be retried and an error will\n" |
7782 | | "be raised.\n" |
7783 | | "\n" |
7784 | | "Returns 0 if *fd* is at end of file or if the provided *buffer* has length 0\n" |
7785 | | "(which can be used to check for errors without reading data). Never returns\n" |
7786 | | "negative."); |
7787 | | |
7788 | | #define OS_READINTO_METHODDEF \ |
7789 | | {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__}, |
7790 | | |
7791 | | static Py_ssize_t |
7792 | | os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer); |
7793 | | |
7794 | | static PyObject * |
7795 | | os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7796 | 0 | { |
7797 | 0 | PyObject *return_value = NULL; |
7798 | 0 | int fd; |
7799 | 0 | Py_buffer buffer = {NULL, NULL}; |
7800 | 0 | Py_ssize_t _return_value; |
7801 | |
|
7802 | 0 | if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) { |
7803 | 0 | goto exit; |
7804 | 0 | } |
7805 | 0 | fd = PyLong_AsInt(args[0]); |
7806 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7807 | 0 | goto exit; |
7808 | 0 | } |
7809 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) { |
7810 | 0 | _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]); |
7811 | 0 | goto exit; |
7812 | 0 | } |
7813 | 0 | _return_value = os_readinto_impl(module, fd, &buffer); |
7814 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7815 | 0 | goto exit; |
7816 | 0 | } |
7817 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7818 | |
|
7819 | 0 | exit: |
7820 | | /* Cleanup for buffer */ |
7821 | 0 | if (buffer.obj) { |
7822 | 0 | PyBuffer_Release(&buffer); |
7823 | 0 | } |
7824 | |
|
7825 | 0 | return return_value; |
7826 | 0 | } |
7827 | | |
7828 | | #if defined(HAVE_READV) |
7829 | | |
7830 | | PyDoc_STRVAR(os_readv__doc__, |
7831 | | "readv($module, fd, buffers, /)\n" |
7832 | | "--\n" |
7833 | | "\n" |
7834 | | "Read from a file descriptor fd into an iterable of buffers.\n" |
7835 | | "\n" |
7836 | | "The buffers should be mutable buffers accepting bytes.\n" |
7837 | | "readv will transfer data into each buffer until it is full\n" |
7838 | | "and then move on to the next buffer in the sequence to hold\n" |
7839 | | "the rest of the data.\n" |
7840 | | "\n" |
7841 | | "readv returns the total number of bytes read,\n" |
7842 | | "which may be less than the total capacity of all the buffers."); |
7843 | | |
7844 | | #define OS_READV_METHODDEF \ |
7845 | | {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__}, |
7846 | | |
7847 | | static Py_ssize_t |
7848 | | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
7849 | | |
7850 | | static PyObject * |
7851 | | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7852 | 0 | { |
7853 | 0 | PyObject *return_value = NULL; |
7854 | 0 | int fd; |
7855 | 0 | PyObject *buffers; |
7856 | 0 | Py_ssize_t _return_value; |
7857 | |
|
7858 | 0 | if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { |
7859 | 0 | goto exit; |
7860 | 0 | } |
7861 | 0 | fd = PyLong_AsInt(args[0]); |
7862 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7863 | 0 | goto exit; |
7864 | 0 | } |
7865 | 0 | buffers = args[1]; |
7866 | 0 | _return_value = os_readv_impl(module, fd, buffers); |
7867 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7868 | 0 | goto exit; |
7869 | 0 | } |
7870 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7871 | |
|
7872 | 0 | exit: |
7873 | 0 | return return_value; |
7874 | 0 | } |
7875 | | |
7876 | | #endif /* defined(HAVE_READV) */ |
7877 | | |
7878 | | #if defined(HAVE_PREAD) |
7879 | | |
7880 | | PyDoc_STRVAR(os_pread__doc__, |
7881 | | "pread($module, fd, length, offset, /)\n" |
7882 | | "--\n" |
7883 | | "\n" |
7884 | | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
7885 | | "\n" |
7886 | | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
7887 | | "the beginning of the file. The file offset remains unchanged."); |
7888 | | |
7889 | | #define OS_PREAD_METHODDEF \ |
7890 | | {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__}, |
7891 | | |
7892 | | static PyObject * |
7893 | | os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset); |
7894 | | |
7895 | | static PyObject * |
7896 | | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7897 | 0 | { |
7898 | 0 | PyObject *return_value = NULL; |
7899 | 0 | int fd; |
7900 | 0 | Py_ssize_t length; |
7901 | 0 | Py_off_t offset; |
7902 | |
|
7903 | 0 | if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { |
7904 | 0 | goto exit; |
7905 | 0 | } |
7906 | 0 | fd = PyLong_AsInt(args[0]); |
7907 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7908 | 0 | goto exit; |
7909 | 0 | } |
7910 | 0 | { |
7911 | 0 | Py_ssize_t ival = -1; |
7912 | 0 | PyObject *iobj = _PyNumber_Index(args[1]); |
7913 | 0 | if (iobj != NULL) { |
7914 | 0 | ival = PyLong_AsSsize_t(iobj); |
7915 | 0 | Py_DECREF(iobj); |
7916 | 0 | } |
7917 | 0 | if (ival == -1 && PyErr_Occurred()) { |
7918 | 0 | goto exit; |
7919 | 0 | } |
7920 | 0 | length = ival; |
7921 | 0 | } |
7922 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7923 | 0 | goto exit; |
7924 | 0 | } |
7925 | 0 | return_value = os_pread_impl(module, fd, length, offset); |
7926 | |
|
7927 | 0 | exit: |
7928 | 0 | return return_value; |
7929 | 0 | } |
7930 | | |
7931 | | #endif /* defined(HAVE_PREAD) */ |
7932 | | |
7933 | | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
7934 | | |
7935 | | PyDoc_STRVAR(os_preadv__doc__, |
7936 | | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
7937 | | "--\n" |
7938 | | "\n" |
7939 | | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
7940 | | "\n" |
7941 | | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
7942 | | "transfer data into each buffer until it is full and then move on to the next\n" |
7943 | | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
7944 | | "specifies the file offset at which the input operation is to be performed. It\n" |
7945 | | "will return the total number of bytes read (which can be less than the total\n" |
7946 | | "capacity of all the objects).\n" |
7947 | | "\n" |
7948 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
7949 | | "\n" |
7950 | | "- RWF_HIPRI\n" |
7951 | | "- RWF_NOWAIT\n" |
7952 | | "- RWF_DONTCACHE\n" |
7953 | | "\n" |
7954 | | "Using non-zero flags requires Linux 4.6 or newer."); |
7955 | | |
7956 | | #define OS_PREADV_METHODDEF \ |
7957 | | {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__}, |
7958 | | |
7959 | | static Py_ssize_t |
7960 | | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
7961 | | int flags); |
7962 | | |
7963 | | static PyObject * |
7964 | | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7965 | 0 | { |
7966 | 0 | PyObject *return_value = NULL; |
7967 | 0 | int fd; |
7968 | 0 | PyObject *buffers; |
7969 | 0 | Py_off_t offset; |
7970 | 0 | int flags = 0; |
7971 | 0 | Py_ssize_t _return_value; |
7972 | |
|
7973 | 0 | if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { |
7974 | 0 | goto exit; |
7975 | 0 | } |
7976 | 0 | fd = PyLong_AsInt(args[0]); |
7977 | 0 | if (fd == -1 && PyErr_Occurred()) { |
7978 | 0 | goto exit; |
7979 | 0 | } |
7980 | 0 | buffers = args[1]; |
7981 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
7982 | 0 | goto exit; |
7983 | 0 | } |
7984 | 0 | if (nargs < 4) { |
7985 | 0 | goto skip_optional; |
7986 | 0 | } |
7987 | 0 | flags = PyLong_AsInt(args[3]); |
7988 | 0 | if (flags == -1 && PyErr_Occurred()) { |
7989 | 0 | goto exit; |
7990 | 0 | } |
7991 | 0 | skip_optional: |
7992 | 0 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
7993 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
7994 | 0 | goto exit; |
7995 | 0 | } |
7996 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
7997 | |
|
7998 | 0 | exit: |
7999 | 0 | return return_value; |
8000 | 0 | } |
8001 | | |
8002 | | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
8003 | | |
8004 | | PyDoc_STRVAR(os_write__doc__, |
8005 | | "write($module, fd, data, /)\n" |
8006 | | "--\n" |
8007 | | "\n" |
8008 | | "Write a bytes object to a file descriptor."); |
8009 | | |
8010 | | #define OS_WRITE_METHODDEF \ |
8011 | | {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__}, |
8012 | | |
8013 | | static Py_ssize_t |
8014 | | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
8015 | | |
8016 | | static PyObject * |
8017 | | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8018 | 0 | { |
8019 | 0 | PyObject *return_value = NULL; |
8020 | 0 | int fd; |
8021 | 0 | Py_buffer data = {NULL, NULL}; |
8022 | 0 | Py_ssize_t _return_value; |
8023 | |
|
8024 | 0 | if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { |
8025 | 0 | goto exit; |
8026 | 0 | } |
8027 | 0 | fd = PyLong_AsInt(args[0]); |
8028 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8029 | 0 | goto exit; |
8030 | 0 | } |
8031 | 0 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
8032 | 0 | goto exit; |
8033 | 0 | } |
8034 | 0 | _return_value = os_write_impl(module, fd, &data); |
8035 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8036 | 0 | goto exit; |
8037 | 0 | } |
8038 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8039 | |
|
8040 | 0 | exit: |
8041 | | /* Cleanup for data */ |
8042 | 0 | if (data.obj) { |
8043 | 0 | PyBuffer_Release(&data); |
8044 | 0 | } |
8045 | |
|
8046 | 0 | return return_value; |
8047 | 0 | } |
8048 | | |
8049 | | #if defined(HAVE_SENDFILE) && defined(__APPLE__) |
8050 | | |
8051 | | PyDoc_STRVAR(os_sendfile__doc__, |
8052 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8053 | | " trailers=(), flags=0)\n" |
8054 | | "--\n" |
8055 | | "\n" |
8056 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8057 | | |
8058 | | #define OS_SENDFILE_METHODDEF \ |
8059 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8060 | | |
8061 | | static PyObject * |
8062 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8063 | | Py_off_t sbytes, PyObject *headers, PyObject *trailers, |
8064 | | int flags); |
8065 | | |
8066 | | static PyObject * |
8067 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8068 | | { |
8069 | | PyObject *return_value = NULL; |
8070 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8071 | | |
8072 | | #define NUM_KEYWORDS 7 |
8073 | | static struct { |
8074 | | PyGC_Head _this_is_not_used; |
8075 | | PyObject_VAR_HEAD |
8076 | | Py_hash_t ob_hash; |
8077 | | PyObject *ob_item[NUM_KEYWORDS]; |
8078 | | } _kwtuple = { |
8079 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8080 | | .ob_hash = -1, |
8081 | | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), }, |
8082 | | }; |
8083 | | #undef NUM_KEYWORDS |
8084 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8085 | | |
8086 | | #else // !Py_BUILD_CORE |
8087 | | # define KWTUPLE NULL |
8088 | | #endif // !Py_BUILD_CORE |
8089 | | |
8090 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8091 | | static _PyArg_Parser _parser = { |
8092 | | .keywords = _keywords, |
8093 | | .fname = "sendfile", |
8094 | | .kwtuple = KWTUPLE, |
8095 | | }; |
8096 | | #undef KWTUPLE |
8097 | | PyObject *argsbuf[7]; |
8098 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8099 | | int out_fd; |
8100 | | int in_fd; |
8101 | | Py_off_t offset; |
8102 | | Py_off_t sbytes; |
8103 | | PyObject *headers = NULL; |
8104 | | PyObject *trailers = NULL; |
8105 | | int flags = 0; |
8106 | | |
8107 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8108 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8109 | | if (!args) { |
8110 | | goto exit; |
8111 | | } |
8112 | | out_fd = PyLong_AsInt(args[0]); |
8113 | | if (out_fd == -1 && PyErr_Occurred()) { |
8114 | | goto exit; |
8115 | | } |
8116 | | in_fd = PyLong_AsInt(args[1]); |
8117 | | if (in_fd == -1 && PyErr_Occurred()) { |
8118 | | goto exit; |
8119 | | } |
8120 | | if (!Py_off_t_converter(args[2], &offset)) { |
8121 | | goto exit; |
8122 | | } |
8123 | | if (!Py_off_t_converter(args[3], &sbytes)) { |
8124 | | goto exit; |
8125 | | } |
8126 | | if (!noptargs) { |
8127 | | goto skip_optional_pos; |
8128 | | } |
8129 | | if (args[4]) { |
8130 | | headers = args[4]; |
8131 | | if (!--noptargs) { |
8132 | | goto skip_optional_pos; |
8133 | | } |
8134 | | } |
8135 | | if (args[5]) { |
8136 | | trailers = args[5]; |
8137 | | if (!--noptargs) { |
8138 | | goto skip_optional_pos; |
8139 | | } |
8140 | | } |
8141 | | flags = PyLong_AsInt(args[6]); |
8142 | | if (flags == -1 && PyErr_Occurred()) { |
8143 | | goto exit; |
8144 | | } |
8145 | | skip_optional_pos: |
8146 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags); |
8147 | | |
8148 | | exit: |
8149 | | return return_value; |
8150 | | } |
8151 | | |
8152 | | #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */ |
8153 | | |
8154 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) |
8155 | | |
8156 | | PyDoc_STRVAR(os_sendfile__doc__, |
8157 | | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
8158 | | " trailers=(), flags=0)\n" |
8159 | | "--\n" |
8160 | | "\n" |
8161 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8162 | | |
8163 | | #define OS_SENDFILE_METHODDEF \ |
8164 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8165 | | |
8166 | | static PyObject * |
8167 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
8168 | | Py_ssize_t count, PyObject *headers, PyObject *trailers, |
8169 | | int flags); |
8170 | | |
8171 | | static PyObject * |
8172 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8173 | | { |
8174 | | PyObject *return_value = NULL; |
8175 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8176 | | |
8177 | | #define NUM_KEYWORDS 7 |
8178 | | static struct { |
8179 | | PyGC_Head _this_is_not_used; |
8180 | | PyObject_VAR_HEAD |
8181 | | Py_hash_t ob_hash; |
8182 | | PyObject *ob_item[NUM_KEYWORDS]; |
8183 | | } _kwtuple = { |
8184 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8185 | | .ob_hash = -1, |
8186 | | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), }, |
8187 | | }; |
8188 | | #undef NUM_KEYWORDS |
8189 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8190 | | |
8191 | | #else // !Py_BUILD_CORE |
8192 | | # define KWTUPLE NULL |
8193 | | #endif // !Py_BUILD_CORE |
8194 | | |
8195 | | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL}; |
8196 | | static _PyArg_Parser _parser = { |
8197 | | .keywords = _keywords, |
8198 | | .fname = "sendfile", |
8199 | | .kwtuple = KWTUPLE, |
8200 | | }; |
8201 | | #undef KWTUPLE |
8202 | | PyObject *argsbuf[7]; |
8203 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
8204 | | int out_fd; |
8205 | | int in_fd; |
8206 | | Py_off_t offset; |
8207 | | Py_ssize_t count; |
8208 | | PyObject *headers = NULL; |
8209 | | PyObject *trailers = NULL; |
8210 | | int flags = 0; |
8211 | | |
8212 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8213 | | /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8214 | | if (!args) { |
8215 | | goto exit; |
8216 | | } |
8217 | | out_fd = PyLong_AsInt(args[0]); |
8218 | | if (out_fd == -1 && PyErr_Occurred()) { |
8219 | | goto exit; |
8220 | | } |
8221 | | in_fd = PyLong_AsInt(args[1]); |
8222 | | if (in_fd == -1 && PyErr_Occurred()) { |
8223 | | goto exit; |
8224 | | } |
8225 | | if (!Py_off_t_converter(args[2], &offset)) { |
8226 | | goto exit; |
8227 | | } |
8228 | | { |
8229 | | Py_ssize_t ival = -1; |
8230 | | PyObject *iobj = _PyNumber_Index(args[3]); |
8231 | | if (iobj != NULL) { |
8232 | | ival = PyLong_AsSsize_t(iobj); |
8233 | | Py_DECREF(iobj); |
8234 | | } |
8235 | | if (ival == -1 && PyErr_Occurred()) { |
8236 | | goto exit; |
8237 | | } |
8238 | | count = ival; |
8239 | | if (count < 0) { |
8240 | | PyErr_SetString(PyExc_ValueError, |
8241 | | "count cannot be negative"); |
8242 | | goto exit; |
8243 | | } |
8244 | | } |
8245 | | if (!noptargs) { |
8246 | | goto skip_optional_pos; |
8247 | | } |
8248 | | if (args[4]) { |
8249 | | headers = args[4]; |
8250 | | if (!--noptargs) { |
8251 | | goto skip_optional_pos; |
8252 | | } |
8253 | | } |
8254 | | if (args[5]) { |
8255 | | trailers = args[5]; |
8256 | | if (!--noptargs) { |
8257 | | goto skip_optional_pos; |
8258 | | } |
8259 | | } |
8260 | | flags = PyLong_AsInt(args[6]); |
8261 | | if (flags == -1 && PyErr_Occurred()) { |
8262 | | goto exit; |
8263 | | } |
8264 | | skip_optional_pos: |
8265 | | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags); |
8266 | | |
8267 | | exit: |
8268 | | return return_value; |
8269 | | } |
8270 | | |
8271 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8272 | | |
8273 | | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) |
8274 | | |
8275 | | PyDoc_STRVAR(os_sendfile__doc__, |
8276 | | "sendfile($module, /, out_fd, in_fd, offset, count)\n" |
8277 | | "--\n" |
8278 | | "\n" |
8279 | | "Copy count bytes from file descriptor in_fd to file descriptor out_fd."); |
8280 | | |
8281 | | #define OS_SENDFILE_METHODDEF \ |
8282 | | {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
8283 | | |
8284 | | static PyObject * |
8285 | | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj, |
8286 | | Py_ssize_t count); |
8287 | | |
8288 | | static PyObject * |
8289 | | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8290 | 0 | { |
8291 | 0 | PyObject *return_value = NULL; |
8292 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8293 | |
|
8294 | 0 | #define NUM_KEYWORDS 4 |
8295 | 0 | static struct { |
8296 | 0 | PyGC_Head _this_is_not_used; |
8297 | 0 | PyObject_VAR_HEAD |
8298 | 0 | Py_hash_t ob_hash; |
8299 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8300 | 0 | } _kwtuple = { |
8301 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8302 | 0 | .ob_hash = -1, |
8303 | 0 | .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), }, |
8304 | 0 | }; |
8305 | 0 | #undef NUM_KEYWORDS |
8306 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8307 | |
|
8308 | | #else // !Py_BUILD_CORE |
8309 | | # define KWTUPLE NULL |
8310 | | #endif // !Py_BUILD_CORE |
8311 | |
|
8312 | 0 | static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL}; |
8313 | 0 | static _PyArg_Parser _parser = { |
8314 | 0 | .keywords = _keywords, |
8315 | 0 | .fname = "sendfile", |
8316 | 0 | .kwtuple = KWTUPLE, |
8317 | 0 | }; |
8318 | 0 | #undef KWTUPLE |
8319 | 0 | PyObject *argsbuf[4]; |
8320 | 0 | int out_fd; |
8321 | 0 | int in_fd; |
8322 | 0 | PyObject *offobj; |
8323 | 0 | Py_ssize_t count; |
8324 | |
|
8325 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8326 | 0 | /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8327 | 0 | if (!args) { |
8328 | 0 | goto exit; |
8329 | 0 | } |
8330 | 0 | out_fd = PyLong_AsInt(args[0]); |
8331 | 0 | if (out_fd == -1 && PyErr_Occurred()) { |
8332 | 0 | goto exit; |
8333 | 0 | } |
8334 | 0 | in_fd = PyLong_AsInt(args[1]); |
8335 | 0 | if (in_fd == -1 && PyErr_Occurred()) { |
8336 | 0 | goto exit; |
8337 | 0 | } |
8338 | 0 | offobj = args[2]; |
8339 | 0 | { |
8340 | 0 | Py_ssize_t ival = -1; |
8341 | 0 | PyObject *iobj = _PyNumber_Index(args[3]); |
8342 | 0 | if (iobj != NULL) { |
8343 | 0 | ival = PyLong_AsSsize_t(iobj); |
8344 | 0 | Py_DECREF(iobj); |
8345 | 0 | } |
8346 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8347 | 0 | goto exit; |
8348 | 0 | } |
8349 | 0 | count = ival; |
8350 | 0 | if (count < 0) { |
8351 | 0 | PyErr_SetString(PyExc_ValueError, |
8352 | 0 | "count cannot be negative"); |
8353 | 0 | goto exit; |
8354 | 0 | } |
8355 | 0 | } |
8356 | 0 | return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); |
8357 | |
|
8358 | 0 | exit: |
8359 | 0 | return return_value; |
8360 | 0 | } |
8361 | | |
8362 | | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */ |
8363 | | |
8364 | | #if defined(__APPLE__) |
8365 | | |
8366 | | PyDoc_STRVAR(os__fcopyfile__doc__, |
8367 | | "_fcopyfile($module, in_fd, out_fd, flags, /)\n" |
8368 | | "--\n" |
8369 | | "\n" |
8370 | | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); |
8371 | | |
8372 | | #define OS__FCOPYFILE_METHODDEF \ |
8373 | | {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__}, |
8374 | | |
8375 | | static PyObject * |
8376 | | os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags); |
8377 | | |
8378 | | static PyObject * |
8379 | | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8380 | | { |
8381 | | PyObject *return_value = NULL; |
8382 | | int in_fd; |
8383 | | int out_fd; |
8384 | | int flags; |
8385 | | |
8386 | | if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { |
8387 | | goto exit; |
8388 | | } |
8389 | | in_fd = PyLong_AsInt(args[0]); |
8390 | | if (in_fd == -1 && PyErr_Occurred()) { |
8391 | | goto exit; |
8392 | | } |
8393 | | out_fd = PyLong_AsInt(args[1]); |
8394 | | if (out_fd == -1 && PyErr_Occurred()) { |
8395 | | goto exit; |
8396 | | } |
8397 | | flags = PyLong_AsInt(args[2]); |
8398 | | if (flags == -1 && PyErr_Occurred()) { |
8399 | | goto exit; |
8400 | | } |
8401 | | return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags); |
8402 | | |
8403 | | exit: |
8404 | | return return_value; |
8405 | | } |
8406 | | |
8407 | | #endif /* defined(__APPLE__) */ |
8408 | | |
8409 | | PyDoc_STRVAR(os_fstat__doc__, |
8410 | | "fstat($module, /, fd)\n" |
8411 | | "--\n" |
8412 | | "\n" |
8413 | | "Perform a stat system call on the given file descriptor.\n" |
8414 | | "\n" |
8415 | | "Like stat(), but for an open file descriptor.\n" |
8416 | | "Equivalent to os.stat(fd)."); |
8417 | | |
8418 | | #define OS_FSTAT_METHODDEF \ |
8419 | | {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
8420 | | |
8421 | | static PyObject * |
8422 | | os_fstat_impl(PyObject *module, int fd); |
8423 | | |
8424 | | static PyObject * |
8425 | | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8426 | 0 | { |
8427 | 0 | PyObject *return_value = NULL; |
8428 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8429 | |
|
8430 | 0 | #define NUM_KEYWORDS 1 |
8431 | 0 | static struct { |
8432 | 0 | PyGC_Head _this_is_not_used; |
8433 | 0 | PyObject_VAR_HEAD |
8434 | 0 | Py_hash_t ob_hash; |
8435 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8436 | 0 | } _kwtuple = { |
8437 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8438 | 0 | .ob_hash = -1, |
8439 | 0 | .ob_item = { &_Py_ID(fd), }, |
8440 | 0 | }; |
8441 | 0 | #undef NUM_KEYWORDS |
8442 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8443 | |
|
8444 | | #else // !Py_BUILD_CORE |
8445 | | # define KWTUPLE NULL |
8446 | | #endif // !Py_BUILD_CORE |
8447 | |
|
8448 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
8449 | 0 | static _PyArg_Parser _parser = { |
8450 | 0 | .keywords = _keywords, |
8451 | 0 | .fname = "fstat", |
8452 | 0 | .kwtuple = KWTUPLE, |
8453 | 0 | }; |
8454 | 0 | #undef KWTUPLE |
8455 | 0 | PyObject *argsbuf[1]; |
8456 | 0 | int fd; |
8457 | |
|
8458 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8459 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8460 | 0 | if (!args) { |
8461 | 0 | goto exit; |
8462 | 0 | } |
8463 | 0 | fd = PyLong_AsInt(args[0]); |
8464 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8465 | 0 | goto exit; |
8466 | 0 | } |
8467 | 0 | return_value = os_fstat_impl(module, fd); |
8468 | |
|
8469 | 0 | exit: |
8470 | 0 | return return_value; |
8471 | 0 | } |
8472 | | |
8473 | | PyDoc_STRVAR(os_isatty__doc__, |
8474 | | "isatty($module, fd, /)\n" |
8475 | | "--\n" |
8476 | | "\n" |
8477 | | "Return True if the fd is connected to a terminal.\n" |
8478 | | "\n" |
8479 | | "Return True if the file descriptor is an open file descriptor\n" |
8480 | | "connected to the slave end of a terminal."); |
8481 | | |
8482 | | #define OS_ISATTY_METHODDEF \ |
8483 | | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
8484 | | |
8485 | | static int |
8486 | | os_isatty_impl(PyObject *module, int fd); |
8487 | | |
8488 | | static PyObject * |
8489 | | os_isatty(PyObject *module, PyObject *arg) |
8490 | 0 | { |
8491 | 0 | PyObject *return_value = NULL; |
8492 | 0 | int fd; |
8493 | 0 | int _return_value; |
8494 | |
|
8495 | 0 | fd = PyLong_AsInt(arg); |
8496 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8497 | 0 | goto exit; |
8498 | 0 | } |
8499 | 0 | _return_value = os_isatty_impl(module, fd); |
8500 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8501 | 0 | goto exit; |
8502 | 0 | } |
8503 | 0 | return_value = PyBool_FromLong((long)_return_value); |
8504 | |
|
8505 | 0 | exit: |
8506 | 0 | return return_value; |
8507 | 0 | } |
8508 | | |
8509 | | #if defined(HAVE_PIPE) |
8510 | | |
8511 | | PyDoc_STRVAR(os_pipe__doc__, |
8512 | | "pipe($module, /)\n" |
8513 | | "--\n" |
8514 | | "\n" |
8515 | | "Create a pipe.\n" |
8516 | | "\n" |
8517 | | "Returns a tuple of two file descriptors:\n" |
8518 | | " (read_fd, write_fd)"); |
8519 | | |
8520 | | #define OS_PIPE_METHODDEF \ |
8521 | | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
8522 | | |
8523 | | static PyObject * |
8524 | | os_pipe_impl(PyObject *module); |
8525 | | |
8526 | | static PyObject * |
8527 | | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
8528 | 0 | { |
8529 | 0 | return os_pipe_impl(module); |
8530 | 0 | } |
8531 | | |
8532 | | #endif /* defined(HAVE_PIPE) */ |
8533 | | |
8534 | | #if defined(HAVE_PIPE2) |
8535 | | |
8536 | | PyDoc_STRVAR(os_pipe2__doc__, |
8537 | | "pipe2($module, flags, /)\n" |
8538 | | "--\n" |
8539 | | "\n" |
8540 | | "Create a pipe with flags set atomically.\n" |
8541 | | "\n" |
8542 | | "Returns a tuple of two file descriptors:\n" |
8543 | | " (read_fd, write_fd)\n" |
8544 | | "\n" |
8545 | | "flags can be constructed by ORing together one or more of these values:\n" |
8546 | | "O_NONBLOCK, O_CLOEXEC."); |
8547 | | |
8548 | | #define OS_PIPE2_METHODDEF \ |
8549 | | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
8550 | | |
8551 | | static PyObject * |
8552 | | os_pipe2_impl(PyObject *module, int flags); |
8553 | | |
8554 | | static PyObject * |
8555 | | os_pipe2(PyObject *module, PyObject *arg) |
8556 | 0 | { |
8557 | 0 | PyObject *return_value = NULL; |
8558 | 0 | int flags; |
8559 | |
|
8560 | 0 | flags = PyLong_AsInt(arg); |
8561 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8562 | 0 | goto exit; |
8563 | 0 | } |
8564 | 0 | return_value = os_pipe2_impl(module, flags); |
8565 | |
|
8566 | 0 | exit: |
8567 | 0 | return return_value; |
8568 | 0 | } |
8569 | | |
8570 | | #endif /* defined(HAVE_PIPE2) */ |
8571 | | |
8572 | | #if defined(HAVE_WRITEV) |
8573 | | |
8574 | | PyDoc_STRVAR(os_writev__doc__, |
8575 | | "writev($module, fd, buffers, /)\n" |
8576 | | "--\n" |
8577 | | "\n" |
8578 | | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
8579 | | "\n" |
8580 | | "Returns the total number of bytes written.\n" |
8581 | | "buffers must be a sequence of bytes-like objects."); |
8582 | | |
8583 | | #define OS_WRITEV_METHODDEF \ |
8584 | | {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__}, |
8585 | | |
8586 | | static Py_ssize_t |
8587 | | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
8588 | | |
8589 | | static PyObject * |
8590 | | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8591 | 0 | { |
8592 | 0 | PyObject *return_value = NULL; |
8593 | 0 | int fd; |
8594 | 0 | PyObject *buffers; |
8595 | 0 | Py_ssize_t _return_value; |
8596 | |
|
8597 | 0 | if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { |
8598 | 0 | goto exit; |
8599 | 0 | } |
8600 | 0 | fd = PyLong_AsInt(args[0]); |
8601 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8602 | 0 | goto exit; |
8603 | 0 | } |
8604 | 0 | buffers = args[1]; |
8605 | 0 | _return_value = os_writev_impl(module, fd, buffers); |
8606 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8607 | 0 | goto exit; |
8608 | 0 | } |
8609 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8610 | |
|
8611 | 0 | exit: |
8612 | 0 | return return_value; |
8613 | 0 | } |
8614 | | |
8615 | | #endif /* defined(HAVE_WRITEV) */ |
8616 | | |
8617 | | #if defined(HAVE_PWRITE) |
8618 | | |
8619 | | PyDoc_STRVAR(os_pwrite__doc__, |
8620 | | "pwrite($module, fd, buffer, offset, /)\n" |
8621 | | "--\n" |
8622 | | "\n" |
8623 | | "Write bytes to a file descriptor starting at a particular offset.\n" |
8624 | | "\n" |
8625 | | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
8626 | | "the file. Returns the number of bytes written. Does not change the\n" |
8627 | | "current file offset."); |
8628 | | |
8629 | | #define OS_PWRITE_METHODDEF \ |
8630 | | {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__}, |
8631 | | |
8632 | | static Py_ssize_t |
8633 | | os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset); |
8634 | | |
8635 | | static PyObject * |
8636 | | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8637 | 0 | { |
8638 | 0 | PyObject *return_value = NULL; |
8639 | 0 | int fd; |
8640 | 0 | Py_buffer buffer = {NULL, NULL}; |
8641 | 0 | Py_off_t offset; |
8642 | 0 | Py_ssize_t _return_value; |
8643 | |
|
8644 | 0 | if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { |
8645 | 0 | goto exit; |
8646 | 0 | } |
8647 | 0 | fd = PyLong_AsInt(args[0]); |
8648 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8649 | 0 | goto exit; |
8650 | 0 | } |
8651 | 0 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
8652 | 0 | goto exit; |
8653 | 0 | } |
8654 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8655 | 0 | goto exit; |
8656 | 0 | } |
8657 | 0 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
8658 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8659 | 0 | goto exit; |
8660 | 0 | } |
8661 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8662 | |
|
8663 | 0 | exit: |
8664 | | /* Cleanup for buffer */ |
8665 | 0 | if (buffer.obj) { |
8666 | 0 | PyBuffer_Release(&buffer); |
8667 | 0 | } |
8668 | |
|
8669 | 0 | return return_value; |
8670 | 0 | } |
8671 | | |
8672 | | #endif /* defined(HAVE_PWRITE) */ |
8673 | | |
8674 | | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
8675 | | |
8676 | | PyDoc_STRVAR(os_pwritev__doc__, |
8677 | | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
8678 | | "--\n" |
8679 | | "\n" |
8680 | | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
8681 | | "\n" |
8682 | | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
8683 | | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
8684 | | "buffer is written before proceeding to second, and so on. The operating system may\n" |
8685 | | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
8686 | | "This function writes the contents of each object to the file descriptor and returns\n" |
8687 | | "the total number of bytes written.\n" |
8688 | | "\n" |
8689 | | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
8690 | | "\n" |
8691 | | "- RWF_DSYNC\n" |
8692 | | "- RWF_SYNC\n" |
8693 | | "- RWF_APPEND\n" |
8694 | | "- RWF_DONTCACHE\n" |
8695 | | "\n" |
8696 | | "Using non-zero flags requires Linux 4.7 or newer."); |
8697 | | |
8698 | | #define OS_PWRITEV_METHODDEF \ |
8699 | | {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__}, |
8700 | | |
8701 | | static Py_ssize_t |
8702 | | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
8703 | | int flags); |
8704 | | |
8705 | | static PyObject * |
8706 | | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8707 | 0 | { |
8708 | 0 | PyObject *return_value = NULL; |
8709 | 0 | int fd; |
8710 | 0 | PyObject *buffers; |
8711 | 0 | Py_off_t offset; |
8712 | 0 | int flags = 0; |
8713 | 0 | Py_ssize_t _return_value; |
8714 | |
|
8715 | 0 | if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { |
8716 | 0 | goto exit; |
8717 | 0 | } |
8718 | 0 | fd = PyLong_AsInt(args[0]); |
8719 | 0 | if (fd == -1 && PyErr_Occurred()) { |
8720 | 0 | goto exit; |
8721 | 0 | } |
8722 | 0 | buffers = args[1]; |
8723 | 0 | if (!Py_off_t_converter(args[2], &offset)) { |
8724 | 0 | goto exit; |
8725 | 0 | } |
8726 | 0 | if (nargs < 4) { |
8727 | 0 | goto skip_optional; |
8728 | 0 | } |
8729 | 0 | flags = PyLong_AsInt(args[3]); |
8730 | 0 | if (flags == -1 && PyErr_Occurred()) { |
8731 | 0 | goto exit; |
8732 | 0 | } |
8733 | 0 | skip_optional: |
8734 | 0 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
8735 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
8736 | 0 | goto exit; |
8737 | 0 | } |
8738 | 0 | return_value = PyLong_FromSsize_t(_return_value); |
8739 | |
|
8740 | 0 | exit: |
8741 | 0 | return return_value; |
8742 | 0 | } |
8743 | | |
8744 | | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
8745 | | |
8746 | | #if defined(HAVE_COPY_FILE_RANGE) |
8747 | | |
8748 | | PyDoc_STRVAR(os_copy_file_range__doc__, |
8749 | | "copy_file_range($module, /, src, dst, count, offset_src=None,\n" |
8750 | | " offset_dst=None)\n" |
8751 | | "--\n" |
8752 | | "\n" |
8753 | | "Copy count bytes from one file descriptor to another.\n" |
8754 | | "\n" |
8755 | | " src\n" |
8756 | | " Source file descriptor.\n" |
8757 | | " dst\n" |
8758 | | " Destination file descriptor.\n" |
8759 | | " count\n" |
8760 | | " Number of bytes to copy.\n" |
8761 | | " offset_src\n" |
8762 | | " Starting offset in src.\n" |
8763 | | " offset_dst\n" |
8764 | | " Starting offset in dst.\n" |
8765 | | "\n" |
8766 | | "If offset_src is None, then src is read from the current position;\n" |
8767 | | "respectively for offset_dst."); |
8768 | | |
8769 | | #define OS_COPY_FILE_RANGE_METHODDEF \ |
8770 | | {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__}, |
8771 | | |
8772 | | static PyObject * |
8773 | | os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8774 | | PyObject *offset_src, PyObject *offset_dst); |
8775 | | |
8776 | | static PyObject * |
8777 | | os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8778 | 0 | { |
8779 | 0 | PyObject *return_value = NULL; |
8780 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8781 | |
|
8782 | 0 | #define NUM_KEYWORDS 5 |
8783 | 0 | static struct { |
8784 | 0 | PyGC_Head _this_is_not_used; |
8785 | 0 | PyObject_VAR_HEAD |
8786 | 0 | Py_hash_t ob_hash; |
8787 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8788 | 0 | } _kwtuple = { |
8789 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8790 | 0 | .ob_hash = -1, |
8791 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), }, |
8792 | 0 | }; |
8793 | 0 | #undef NUM_KEYWORDS |
8794 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8795 | |
|
8796 | | #else // !Py_BUILD_CORE |
8797 | | # define KWTUPLE NULL |
8798 | | #endif // !Py_BUILD_CORE |
8799 | |
|
8800 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL}; |
8801 | 0 | static _PyArg_Parser _parser = { |
8802 | 0 | .keywords = _keywords, |
8803 | 0 | .fname = "copy_file_range", |
8804 | 0 | .kwtuple = KWTUPLE, |
8805 | 0 | }; |
8806 | 0 | #undef KWTUPLE |
8807 | 0 | PyObject *argsbuf[5]; |
8808 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8809 | 0 | int src; |
8810 | 0 | int dst; |
8811 | 0 | Py_ssize_t count; |
8812 | 0 | PyObject *offset_src = Py_None; |
8813 | 0 | PyObject *offset_dst = Py_None; |
8814 | |
|
8815 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8816 | 0 | /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8817 | 0 | if (!args) { |
8818 | 0 | goto exit; |
8819 | 0 | } |
8820 | 0 | src = PyLong_AsInt(args[0]); |
8821 | 0 | if (src == -1 && PyErr_Occurred()) { |
8822 | 0 | goto exit; |
8823 | 0 | } |
8824 | 0 | dst = PyLong_AsInt(args[1]); |
8825 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8826 | 0 | goto exit; |
8827 | 0 | } |
8828 | 0 | { |
8829 | 0 | Py_ssize_t ival = -1; |
8830 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8831 | 0 | if (iobj != NULL) { |
8832 | 0 | ival = PyLong_AsSsize_t(iobj); |
8833 | 0 | Py_DECREF(iobj); |
8834 | 0 | } |
8835 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8836 | 0 | goto exit; |
8837 | 0 | } |
8838 | 0 | count = ival; |
8839 | 0 | if (count < 0) { |
8840 | 0 | PyErr_SetString(PyExc_ValueError, |
8841 | 0 | "count cannot be negative"); |
8842 | 0 | goto exit; |
8843 | 0 | } |
8844 | 0 | } |
8845 | 0 | if (!noptargs) { |
8846 | 0 | goto skip_optional_pos; |
8847 | 0 | } |
8848 | 0 | if (args[3]) { |
8849 | 0 | offset_src = args[3]; |
8850 | 0 | if (!--noptargs) { |
8851 | 0 | goto skip_optional_pos; |
8852 | 0 | } |
8853 | 0 | } |
8854 | 0 | offset_dst = args[4]; |
8855 | 0 | skip_optional_pos: |
8856 | 0 | return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst); |
8857 | |
|
8858 | 0 | exit: |
8859 | 0 | return return_value; |
8860 | 0 | } |
8861 | | |
8862 | | #endif /* defined(HAVE_COPY_FILE_RANGE) */ |
8863 | | |
8864 | | #if ((defined(HAVE_SPLICE) && !defined(_AIX))) |
8865 | | |
8866 | | PyDoc_STRVAR(os_splice__doc__, |
8867 | | "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n" |
8868 | | " flags=0)\n" |
8869 | | "--\n" |
8870 | | "\n" |
8871 | | "Transfer count bytes from one pipe to a descriptor or vice versa.\n" |
8872 | | "\n" |
8873 | | " src\n" |
8874 | | " Source file descriptor.\n" |
8875 | | " dst\n" |
8876 | | " Destination file descriptor.\n" |
8877 | | " count\n" |
8878 | | " Number of bytes to copy.\n" |
8879 | | " offset_src\n" |
8880 | | " Starting offset in src.\n" |
8881 | | " offset_dst\n" |
8882 | | " Starting offset in dst.\n" |
8883 | | " flags\n" |
8884 | | " Flags to modify the semantics of the call.\n" |
8885 | | "\n" |
8886 | | "If offset_src is None, then src is read from the current position;\n" |
8887 | | "respectively for offset_dst. The offset associated to the file\n" |
8888 | | "descriptor that refers to a pipe must be None."); |
8889 | | |
8890 | | #define OS_SPLICE_METHODDEF \ |
8891 | | {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__}, |
8892 | | |
8893 | | static PyObject * |
8894 | | os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
8895 | | PyObject *offset_src, PyObject *offset_dst, |
8896 | | unsigned int flags); |
8897 | | |
8898 | | static PyObject * |
8899 | | os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8900 | 0 | { |
8901 | 0 | PyObject *return_value = NULL; |
8902 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
8903 | |
|
8904 | 0 | #define NUM_KEYWORDS 6 |
8905 | 0 | static struct { |
8906 | 0 | PyGC_Head _this_is_not_used; |
8907 | 0 | PyObject_VAR_HEAD |
8908 | 0 | Py_hash_t ob_hash; |
8909 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
8910 | 0 | } _kwtuple = { |
8911 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
8912 | 0 | .ob_hash = -1, |
8913 | 0 | .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), }, |
8914 | 0 | }; |
8915 | 0 | #undef NUM_KEYWORDS |
8916 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
8917 | |
|
8918 | | #else // !Py_BUILD_CORE |
8919 | | # define KWTUPLE NULL |
8920 | | #endif // !Py_BUILD_CORE |
8921 | |
|
8922 | 0 | static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL}; |
8923 | 0 | static _PyArg_Parser _parser = { |
8924 | 0 | .keywords = _keywords, |
8925 | 0 | .fname = "splice", |
8926 | 0 | .kwtuple = KWTUPLE, |
8927 | 0 | }; |
8928 | 0 | #undef KWTUPLE |
8929 | 0 | PyObject *argsbuf[6]; |
8930 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
8931 | 0 | int src; |
8932 | 0 | int dst; |
8933 | 0 | Py_ssize_t count; |
8934 | 0 | PyObject *offset_src = Py_None; |
8935 | 0 | PyObject *offset_dst = Py_None; |
8936 | 0 | unsigned int flags = 0; |
8937 | |
|
8938 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
8939 | 0 | /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
8940 | 0 | if (!args) { |
8941 | 0 | goto exit; |
8942 | 0 | } |
8943 | 0 | src = PyLong_AsInt(args[0]); |
8944 | 0 | if (src == -1 && PyErr_Occurred()) { |
8945 | 0 | goto exit; |
8946 | 0 | } |
8947 | 0 | dst = PyLong_AsInt(args[1]); |
8948 | 0 | if (dst == -1 && PyErr_Occurred()) { |
8949 | 0 | goto exit; |
8950 | 0 | } |
8951 | 0 | { |
8952 | 0 | Py_ssize_t ival = -1; |
8953 | 0 | PyObject *iobj = _PyNumber_Index(args[2]); |
8954 | 0 | if (iobj != NULL) { |
8955 | 0 | ival = PyLong_AsSsize_t(iobj); |
8956 | 0 | Py_DECREF(iobj); |
8957 | 0 | } |
8958 | 0 | if (ival == -1 && PyErr_Occurred()) { |
8959 | 0 | goto exit; |
8960 | 0 | } |
8961 | 0 | count = ival; |
8962 | 0 | if (count < 0) { |
8963 | 0 | PyErr_SetString(PyExc_ValueError, |
8964 | 0 | "count cannot be negative"); |
8965 | 0 | goto exit; |
8966 | 0 | } |
8967 | 0 | } |
8968 | 0 | if (!noptargs) { |
8969 | 0 | goto skip_optional_pos; |
8970 | 0 | } |
8971 | 0 | if (args[3]) { |
8972 | 0 | offset_src = args[3]; |
8973 | 0 | if (!--noptargs) { |
8974 | 0 | goto skip_optional_pos; |
8975 | 0 | } |
8976 | 0 | } |
8977 | 0 | if (args[4]) { |
8978 | 0 | offset_dst = args[4]; |
8979 | 0 | if (!--noptargs) { |
8980 | 0 | goto skip_optional_pos; |
8981 | 0 | } |
8982 | 0 | } |
8983 | 0 | if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) { |
8984 | 0 | goto exit; |
8985 | 0 | } |
8986 | 0 | skip_optional_pos: |
8987 | 0 | return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags); |
8988 | |
|
8989 | 0 | exit: |
8990 | 0 | return return_value; |
8991 | 0 | } |
8992 | | |
8993 | | #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */ |
8994 | | |
8995 | | #if defined(HAVE_MKFIFO) |
8996 | | |
8997 | | PyDoc_STRVAR(os_mkfifo__doc__, |
8998 | | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
8999 | | "--\n" |
9000 | | "\n" |
9001 | | "Create a \"fifo\" (a POSIX named pipe).\n" |
9002 | | "\n" |
9003 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
9004 | | " and path should be relative; path will then be relative to that directory.\n" |
9005 | | "dir_fd may not be implemented on your platform.\n" |
9006 | | " If it is unavailable, using it will raise a NotImplementedError."); |
9007 | | |
9008 | | #define OS_MKFIFO_METHODDEF \ |
9009 | | {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
9010 | | |
9011 | | static PyObject * |
9012 | | os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
9013 | | |
9014 | | static PyObject * |
9015 | | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9016 | 0 | { |
9017 | 0 | PyObject *return_value = NULL; |
9018 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9019 | |
|
9020 | 0 | #define NUM_KEYWORDS 3 |
9021 | 0 | static struct { |
9022 | 0 | PyGC_Head _this_is_not_used; |
9023 | 0 | PyObject_VAR_HEAD |
9024 | 0 | Py_hash_t ob_hash; |
9025 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9026 | 0 | } _kwtuple = { |
9027 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9028 | 0 | .ob_hash = -1, |
9029 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), }, |
9030 | 0 | }; |
9031 | 0 | #undef NUM_KEYWORDS |
9032 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9033 | |
|
9034 | | #else // !Py_BUILD_CORE |
9035 | | # define KWTUPLE NULL |
9036 | | #endif // !Py_BUILD_CORE |
9037 | |
|
9038 | 0 | static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL}; |
9039 | 0 | static _PyArg_Parser _parser = { |
9040 | 0 | .keywords = _keywords, |
9041 | 0 | .fname = "mkfifo", |
9042 | 0 | .kwtuple = KWTUPLE, |
9043 | 0 | }; |
9044 | 0 | #undef KWTUPLE |
9045 | 0 | PyObject *argsbuf[3]; |
9046 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
9047 | 0 | path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0); |
9048 | 0 | int mode = 438; |
9049 | 0 | int dir_fd = DEFAULT_DIR_FD; |
9050 | |
|
9051 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9052 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9053 | 0 | if (!args) { |
9054 | 0 | goto exit; |
9055 | 0 | } |
9056 | 0 | if (!path_converter(args[0], &path)) { |
9057 | 0 | goto exit; |
9058 | 0 | } |
9059 | 0 | if (!noptargs) { |
9060 | 0 | goto skip_optional_pos; |
9061 | 0 | } |
9062 | 0 | if (args[1]) { |
9063 | 0 | mode = PyLong_AsInt(args[1]); |
9064 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9065 | 0 | goto exit; |
9066 | 0 | } |
9067 | 0 | if (!--noptargs) { |
9068 | 0 | goto skip_optional_pos; |
9069 | 0 | } |
9070 | 0 | } |
9071 | 0 | skip_optional_pos: |
9072 | 0 | if (!noptargs) { |
9073 | 0 | goto skip_optional_kwonly; |
9074 | 0 | } |
9075 | 0 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
9076 | 0 | goto exit; |
9077 | 0 | } |
9078 | 0 | skip_optional_kwonly: |
9079 | 0 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
9080 | |
|
9081 | 0 | exit: |
9082 | | /* Cleanup for path */ |
9083 | 0 | path_cleanup(&path); |
9084 | |
|
9085 | 0 | return return_value; |
9086 | 0 | } |
9087 | | |
9088 | | #endif /* defined(HAVE_MKFIFO) */ |
9089 | | |
9090 | | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
9091 | | |
9092 | | PyDoc_STRVAR(os_mknod__doc__, |
9093 | | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
9094 | | "--\n" |
9095 | | "\n" |
9096 | | "Create a node in the file system.\n" |
9097 | | "\n" |
9098 | | "Create a node in the file system (file, device special file or named pipe)\n" |
9099 | | "at path. mode specifies both the permissions to use and the\n" |
9100 | | "type of node to be created, being combined (bitwise OR) with one of\n" |
9101 | | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
9102 | | "device defines the newly created device special file (probably using\n" |
9103 | | "os.makedev()). Otherwise device is ignored.\n" |
9104 | | "\n" |
9105 | | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
9106 | | " and path should be relative; path will then be relative to that directory.\n" |
9107 | | "dir_fd may not be implemented on your platform.\n" |
9108 | | " If it is unavailable, using it will raise a NotImplementedError."); |
9109 | | |
9110 | | #define OS_MKNOD_METHODDEF \ |
9111 | | {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
9112 | | |
9113 | | static PyObject * |
9114 | | os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, |
9115 | | int dir_fd); |
9116 | | |
9117 | | static PyObject * |
9118 | | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9119 | 0 | { |
9120 | 0 | PyObject *return_value = NULL; |
9121 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9122 | |
|
9123 | 0 | #define NUM_KEYWORDS 4 |
9124 | 0 | static struct { |
9125 | 0 | PyGC_Head _this_is_not_used; |
9126 | 0 | PyObject_VAR_HEAD |
9127 | 0 | Py_hash_t ob_hash; |
9128 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9129 | 0 | } _kwtuple = { |
9130 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9131 | 0 | .ob_hash = -1, |
9132 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), }, |
9133 | 0 | }; |
9134 | 0 | #undef NUM_KEYWORDS |
9135 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9136 | |
|
9137 | | #else // !Py_BUILD_CORE |
9138 | | # define KWTUPLE NULL |
9139 | | #endif // !Py_BUILD_CORE |
9140 | |
|
9141 | 0 | static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL}; |
9142 | 0 | static _PyArg_Parser _parser = { |
9143 | 0 | .keywords = _keywords, |
9144 | 0 | .fname = "mknod", |
9145 | 0 | .kwtuple = KWTUPLE, |
9146 | 0 | }; |
9147 | 0 | #undef KWTUPLE |
9148 | 0 | PyObject *argsbuf[4]; |
9149 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
9150 | 0 | path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0); |
9151 | 0 | int mode = 384; |
9152 | 0 | dev_t device = 0; |
9153 | 0 | int dir_fd = DEFAULT_DIR_FD; |
9154 | |
|
9155 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9156 | 0 | /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9157 | 0 | if (!args) { |
9158 | 0 | goto exit; |
9159 | 0 | } |
9160 | 0 | if (!path_converter(args[0], &path)) { |
9161 | 0 | goto exit; |
9162 | 0 | } |
9163 | 0 | if (!noptargs) { |
9164 | 0 | goto skip_optional_pos; |
9165 | 0 | } |
9166 | 0 | if (args[1]) { |
9167 | 0 | mode = PyLong_AsInt(args[1]); |
9168 | 0 | if (mode == -1 && PyErr_Occurred()) { |
9169 | 0 | goto exit; |
9170 | 0 | } |
9171 | 0 | if (!--noptargs) { |
9172 | 0 | goto skip_optional_pos; |
9173 | 0 | } |
9174 | 0 | } |
9175 | 0 | if (args[2]) { |
9176 | 0 | if (!_Py_Dev_Converter(args[2], &device)) { |
9177 | 0 | goto exit; |
9178 | 0 | } |
9179 | 0 | if (!--noptargs) { |
9180 | 0 | goto skip_optional_pos; |
9181 | 0 | } |
9182 | 0 | } |
9183 | 0 | skip_optional_pos: |
9184 | 0 | if (!noptargs) { |
9185 | 0 | goto skip_optional_kwonly; |
9186 | 0 | } |
9187 | 0 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
9188 | 0 | goto exit; |
9189 | 0 | } |
9190 | 0 | skip_optional_kwonly: |
9191 | 0 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
9192 | |
|
9193 | 0 | exit: |
9194 | | /* Cleanup for path */ |
9195 | 0 | path_cleanup(&path); |
9196 | |
|
9197 | 0 | return return_value; |
9198 | 0 | } |
9199 | | |
9200 | | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
9201 | | |
9202 | | #if defined(HAVE_DEVICE_MACROS) |
9203 | | |
9204 | | PyDoc_STRVAR(os_major__doc__, |
9205 | | "major($module, device, /)\n" |
9206 | | "--\n" |
9207 | | "\n" |
9208 | | "Extracts a device major number from a raw device number."); |
9209 | | |
9210 | | #define OS_MAJOR_METHODDEF \ |
9211 | | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
9212 | | |
9213 | | static PyObject * |
9214 | | os_major_impl(PyObject *module, dev_t device); |
9215 | | |
9216 | | static PyObject * |
9217 | | os_major(PyObject *module, PyObject *arg) |
9218 | 0 | { |
9219 | 0 | PyObject *return_value = NULL; |
9220 | 0 | dev_t device; |
9221 | |
|
9222 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9223 | 0 | goto exit; |
9224 | 0 | } |
9225 | 0 | return_value = os_major_impl(module, device); |
9226 | |
|
9227 | 0 | exit: |
9228 | 0 | return return_value; |
9229 | 0 | } |
9230 | | |
9231 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9232 | | |
9233 | | #if defined(HAVE_DEVICE_MACROS) |
9234 | | |
9235 | | PyDoc_STRVAR(os_minor__doc__, |
9236 | | "minor($module, device, /)\n" |
9237 | | "--\n" |
9238 | | "\n" |
9239 | | "Extracts a device minor number from a raw device number."); |
9240 | | |
9241 | | #define OS_MINOR_METHODDEF \ |
9242 | | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
9243 | | |
9244 | | static PyObject * |
9245 | | os_minor_impl(PyObject *module, dev_t device); |
9246 | | |
9247 | | static PyObject * |
9248 | | os_minor(PyObject *module, PyObject *arg) |
9249 | 0 | { |
9250 | 0 | PyObject *return_value = NULL; |
9251 | 0 | dev_t device; |
9252 | |
|
9253 | 0 | if (!_Py_Dev_Converter(arg, &device)) { |
9254 | 0 | goto exit; |
9255 | 0 | } |
9256 | 0 | return_value = os_minor_impl(module, device); |
9257 | |
|
9258 | 0 | exit: |
9259 | 0 | return return_value; |
9260 | 0 | } |
9261 | | |
9262 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9263 | | |
9264 | | #if defined(HAVE_DEVICE_MACROS) |
9265 | | |
9266 | | PyDoc_STRVAR(os_makedev__doc__, |
9267 | | "makedev($module, major, minor, /)\n" |
9268 | | "--\n" |
9269 | | "\n" |
9270 | | "Composes a raw device number from the major and minor device numbers."); |
9271 | | |
9272 | | #define OS_MAKEDEV_METHODDEF \ |
9273 | | {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__}, |
9274 | | |
9275 | | static dev_t |
9276 | | os_makedev_impl(PyObject *module, dev_t major, dev_t minor); |
9277 | | |
9278 | | static PyObject * |
9279 | | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9280 | 0 | { |
9281 | 0 | PyObject *return_value = NULL; |
9282 | 0 | dev_t major; |
9283 | 0 | dev_t minor; |
9284 | 0 | dev_t _return_value; |
9285 | |
|
9286 | 0 | if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { |
9287 | 0 | goto exit; |
9288 | 0 | } |
9289 | 0 | if (!_Py_Dev_Converter(args[0], &major)) { |
9290 | 0 | goto exit; |
9291 | 0 | } |
9292 | 0 | if (!_Py_Dev_Converter(args[1], &minor)) { |
9293 | 0 | goto exit; |
9294 | 0 | } |
9295 | 0 | _return_value = os_makedev_impl(module, major, minor); |
9296 | 0 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
9297 | 0 | goto exit; |
9298 | 0 | } |
9299 | 0 | return_value = _PyLong_FromDev(_return_value); |
9300 | |
|
9301 | 0 | exit: |
9302 | 0 | return return_value; |
9303 | 0 | } |
9304 | | |
9305 | | #endif /* defined(HAVE_DEVICE_MACROS) */ |
9306 | | |
9307 | | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
9308 | | |
9309 | | PyDoc_STRVAR(os_ftruncate__doc__, |
9310 | | "ftruncate($module, fd, length, /)\n" |
9311 | | "--\n" |
9312 | | "\n" |
9313 | | "Truncate a file, specified by file descriptor, to a specific length."); |
9314 | | |
9315 | | #define OS_FTRUNCATE_METHODDEF \ |
9316 | | {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__}, |
9317 | | |
9318 | | static PyObject * |
9319 | | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
9320 | | |
9321 | | static PyObject * |
9322 | | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9323 | 0 | { |
9324 | 0 | PyObject *return_value = NULL; |
9325 | 0 | int fd; |
9326 | 0 | Py_off_t length; |
9327 | |
|
9328 | 0 | if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { |
9329 | 0 | goto exit; |
9330 | 0 | } |
9331 | 0 | fd = PyLong_AsInt(args[0]); |
9332 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9333 | 0 | goto exit; |
9334 | 0 | } |
9335 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9336 | 0 | goto exit; |
9337 | 0 | } |
9338 | 0 | return_value = os_ftruncate_impl(module, fd, length); |
9339 | |
|
9340 | 0 | exit: |
9341 | 0 | return return_value; |
9342 | 0 | } |
9343 | | |
9344 | | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
9345 | | |
9346 | | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
9347 | | |
9348 | | PyDoc_STRVAR(os_truncate__doc__, |
9349 | | "truncate($module, /, path, length)\n" |
9350 | | "--\n" |
9351 | | "\n" |
9352 | | "Truncate a file, specified by path, to a specific length.\n" |
9353 | | "\n" |
9354 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
9355 | | " If this functionality is unavailable, using it raises an exception."); |
9356 | | |
9357 | | #define OS_TRUNCATE_METHODDEF \ |
9358 | | {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
9359 | | |
9360 | | static PyObject * |
9361 | | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
9362 | | |
9363 | | static PyObject * |
9364 | | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9365 | 0 | { |
9366 | 0 | PyObject *return_value = NULL; |
9367 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9368 | |
|
9369 | 0 | #define NUM_KEYWORDS 2 |
9370 | 0 | static struct { |
9371 | 0 | PyGC_Head _this_is_not_used; |
9372 | 0 | PyObject_VAR_HEAD |
9373 | 0 | Py_hash_t ob_hash; |
9374 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9375 | 0 | } _kwtuple = { |
9376 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9377 | 0 | .ob_hash = -1, |
9378 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(length), }, |
9379 | 0 | }; |
9380 | 0 | #undef NUM_KEYWORDS |
9381 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9382 | |
|
9383 | | #else // !Py_BUILD_CORE |
9384 | | # define KWTUPLE NULL |
9385 | | #endif // !Py_BUILD_CORE |
9386 | |
|
9387 | 0 | static const char * const _keywords[] = {"path", "length", NULL}; |
9388 | 0 | static _PyArg_Parser _parser = { |
9389 | 0 | .keywords = _keywords, |
9390 | 0 | .fname = "truncate", |
9391 | 0 | .kwtuple = KWTUPLE, |
9392 | 0 | }; |
9393 | 0 | #undef KWTUPLE |
9394 | 0 | PyObject *argsbuf[2]; |
9395 | 0 | path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE); |
9396 | 0 | Py_off_t length; |
9397 | |
|
9398 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9399 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9400 | 0 | if (!args) { |
9401 | 0 | goto exit; |
9402 | 0 | } |
9403 | 0 | if (!path_converter(args[0], &path)) { |
9404 | 0 | goto exit; |
9405 | 0 | } |
9406 | 0 | if (!Py_off_t_converter(args[1], &length)) { |
9407 | 0 | goto exit; |
9408 | 0 | } |
9409 | 0 | return_value = os_truncate_impl(module, &path, length); |
9410 | |
|
9411 | 0 | exit: |
9412 | | /* Cleanup for path */ |
9413 | 0 | path_cleanup(&path); |
9414 | |
|
9415 | 0 | return return_value; |
9416 | 0 | } |
9417 | | |
9418 | | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
9419 | | |
9420 | | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) |
9421 | | |
9422 | | PyDoc_STRVAR(os_posix_fallocate__doc__, |
9423 | | "posix_fallocate($module, fd, offset, length, /)\n" |
9424 | | "--\n" |
9425 | | "\n" |
9426 | | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
9427 | | "\n" |
9428 | | "Ensure that the file specified by fd encompasses a range of bytes\n" |
9429 | | "starting at offset bytes from the beginning and continuing for length bytes."); |
9430 | | |
9431 | | #define OS_POSIX_FALLOCATE_METHODDEF \ |
9432 | | {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__}, |
9433 | | |
9434 | | static PyObject * |
9435 | | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
9436 | | Py_off_t length); |
9437 | | |
9438 | | static PyObject * |
9439 | | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9440 | 0 | { |
9441 | 0 | PyObject *return_value = NULL; |
9442 | 0 | int fd; |
9443 | 0 | Py_off_t offset; |
9444 | 0 | Py_off_t length; |
9445 | |
|
9446 | 0 | if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { |
9447 | 0 | goto exit; |
9448 | 0 | } |
9449 | 0 | fd = PyLong_AsInt(args[0]); |
9450 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9451 | 0 | goto exit; |
9452 | 0 | } |
9453 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9454 | 0 | goto exit; |
9455 | 0 | } |
9456 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9457 | 0 | goto exit; |
9458 | 0 | } |
9459 | 0 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
9460 | |
|
9461 | 0 | exit: |
9462 | 0 | return return_value; |
9463 | 0 | } |
9464 | | |
9465 | | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */ |
9466 | | |
9467 | | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
9468 | | |
9469 | | PyDoc_STRVAR(os_posix_fadvise__doc__, |
9470 | | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
9471 | | "--\n" |
9472 | | "\n" |
9473 | | "Announce an intention to access data in a specific pattern.\n" |
9474 | | "\n" |
9475 | | "Announce an intention to access data in a specific pattern, thus allowing\n" |
9476 | | "the kernel to make optimizations.\n" |
9477 | | "The advice applies to the region of the file specified by fd starting at\n" |
9478 | | "offset and continuing for length bytes.\n" |
9479 | | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
9480 | | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
9481 | | "POSIX_FADV_DONTNEED."); |
9482 | | |
9483 | | #define OS_POSIX_FADVISE_METHODDEF \ |
9484 | | {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__}, |
9485 | | |
9486 | | static PyObject * |
9487 | | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
9488 | | Py_off_t length, int advice); |
9489 | | |
9490 | | static PyObject * |
9491 | | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9492 | 0 | { |
9493 | 0 | PyObject *return_value = NULL; |
9494 | 0 | int fd; |
9495 | 0 | Py_off_t offset; |
9496 | 0 | Py_off_t length; |
9497 | 0 | int advice; |
9498 | |
|
9499 | 0 | if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { |
9500 | 0 | goto exit; |
9501 | 0 | } |
9502 | 0 | fd = PyLong_AsInt(args[0]); |
9503 | 0 | if (fd == -1 && PyErr_Occurred()) { |
9504 | 0 | goto exit; |
9505 | 0 | } |
9506 | 0 | if (!Py_off_t_converter(args[1], &offset)) { |
9507 | 0 | goto exit; |
9508 | 0 | } |
9509 | 0 | if (!Py_off_t_converter(args[2], &length)) { |
9510 | 0 | goto exit; |
9511 | 0 | } |
9512 | 0 | advice = PyLong_AsInt(args[3]); |
9513 | 0 | if (advice == -1 && PyErr_Occurred()) { |
9514 | 0 | goto exit; |
9515 | 0 | } |
9516 | 0 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
9517 | |
|
9518 | 0 | exit: |
9519 | 0 | return return_value; |
9520 | 0 | } |
9521 | | |
9522 | | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
9523 | | |
9524 | | #if defined(MS_WINDOWS) |
9525 | | |
9526 | | PyDoc_STRVAR(os_putenv__doc__, |
9527 | | "putenv($module, name, value, /)\n" |
9528 | | "--\n" |
9529 | | "\n" |
9530 | | "Change or add an environment variable."); |
9531 | | |
9532 | | #define OS_PUTENV_METHODDEF \ |
9533 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9534 | | |
9535 | | static PyObject * |
9536 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9537 | | |
9538 | | static PyObject * |
9539 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9540 | | { |
9541 | | PyObject *return_value = NULL; |
9542 | | PyObject *name; |
9543 | | PyObject *value; |
9544 | | |
9545 | | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9546 | | goto exit; |
9547 | | } |
9548 | | if (!PyUnicode_Check(args[0])) { |
9549 | | _PyArg_BadArgument("putenv", "argument 1", "str", args[0]); |
9550 | | goto exit; |
9551 | | } |
9552 | | name = args[0]; |
9553 | | if (!PyUnicode_Check(args[1])) { |
9554 | | _PyArg_BadArgument("putenv", "argument 2", "str", args[1]); |
9555 | | goto exit; |
9556 | | } |
9557 | | value = args[1]; |
9558 | | return_value = os_putenv_impl(module, name, value); |
9559 | | |
9560 | | exit: |
9561 | | return return_value; |
9562 | | } |
9563 | | |
9564 | | #endif /* defined(MS_WINDOWS) */ |
9565 | | |
9566 | | #if !defined(MS_WINDOWS) |
9567 | | |
9568 | | PyDoc_STRVAR(os_putenv__doc__, |
9569 | | "putenv($module, name, value, /)\n" |
9570 | | "--\n" |
9571 | | "\n" |
9572 | | "Change or add an environment variable."); |
9573 | | |
9574 | | #define OS_PUTENV_METHODDEF \ |
9575 | | {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__}, |
9576 | | |
9577 | | static PyObject * |
9578 | | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
9579 | | |
9580 | | static PyObject * |
9581 | | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
9582 | 0 | { |
9583 | 0 | PyObject *return_value = NULL; |
9584 | 0 | PyObject *name = NULL; |
9585 | 0 | PyObject *value = NULL; |
9586 | |
|
9587 | 0 | if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { |
9588 | 0 | goto exit; |
9589 | 0 | } |
9590 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
9591 | 0 | goto exit; |
9592 | 0 | } |
9593 | 0 | if (!PyUnicode_FSConverter(args[1], &value)) { |
9594 | 0 | goto exit; |
9595 | 0 | } |
9596 | 0 | return_value = os_putenv_impl(module, name, value); |
9597 | |
|
9598 | 0 | exit: |
9599 | | /* Cleanup for name */ |
9600 | 0 | Py_XDECREF(name); |
9601 | | /* Cleanup for value */ |
9602 | 0 | Py_XDECREF(value); |
9603 | |
|
9604 | 0 | return return_value; |
9605 | 0 | } |
9606 | | |
9607 | | #endif /* !defined(MS_WINDOWS) */ |
9608 | | |
9609 | | #if defined(MS_WINDOWS) |
9610 | | |
9611 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9612 | | "unsetenv($module, name, /)\n" |
9613 | | "--\n" |
9614 | | "\n" |
9615 | | "Delete an environment variable."); |
9616 | | |
9617 | | #define OS_UNSETENV_METHODDEF \ |
9618 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9619 | | |
9620 | | static PyObject * |
9621 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9622 | | |
9623 | | static PyObject * |
9624 | | os_unsetenv(PyObject *module, PyObject *arg) |
9625 | | { |
9626 | | PyObject *return_value = NULL; |
9627 | | PyObject *name; |
9628 | | |
9629 | | if (!PyUnicode_Check(arg)) { |
9630 | | _PyArg_BadArgument("unsetenv", "argument", "str", arg); |
9631 | | goto exit; |
9632 | | } |
9633 | | name = arg; |
9634 | | return_value = os_unsetenv_impl(module, name); |
9635 | | |
9636 | | exit: |
9637 | | return return_value; |
9638 | | } |
9639 | | |
9640 | | #endif /* defined(MS_WINDOWS) */ |
9641 | | |
9642 | | #if !defined(MS_WINDOWS) |
9643 | | |
9644 | | PyDoc_STRVAR(os_unsetenv__doc__, |
9645 | | "unsetenv($module, name, /)\n" |
9646 | | "--\n" |
9647 | | "\n" |
9648 | | "Delete an environment variable."); |
9649 | | |
9650 | | #define OS_UNSETENV_METHODDEF \ |
9651 | | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
9652 | | |
9653 | | static PyObject * |
9654 | | os_unsetenv_impl(PyObject *module, PyObject *name); |
9655 | | |
9656 | | static PyObject * |
9657 | | os_unsetenv(PyObject *module, PyObject *arg) |
9658 | 0 | { |
9659 | 0 | PyObject *return_value = NULL; |
9660 | 0 | PyObject *name = NULL; |
9661 | |
|
9662 | 0 | if (!PyUnicode_FSConverter(arg, &name)) { |
9663 | 0 | goto exit; |
9664 | 0 | } |
9665 | 0 | return_value = os_unsetenv_impl(module, name); |
9666 | |
|
9667 | 0 | exit: |
9668 | | /* Cleanup for name */ |
9669 | 0 | Py_XDECREF(name); |
9670 | |
|
9671 | 0 | return return_value; |
9672 | 0 | } |
9673 | | |
9674 | | #endif /* !defined(MS_WINDOWS) */ |
9675 | | |
9676 | | #if defined(HAVE_CLEARENV) |
9677 | | |
9678 | | PyDoc_STRVAR(os__clearenv__doc__, |
9679 | | "_clearenv($module, /)\n" |
9680 | | "--\n" |
9681 | | "\n"); |
9682 | | |
9683 | | #define OS__CLEARENV_METHODDEF \ |
9684 | | {"_clearenv", (PyCFunction)os__clearenv, METH_NOARGS, os__clearenv__doc__}, |
9685 | | |
9686 | | static PyObject * |
9687 | | os__clearenv_impl(PyObject *module); |
9688 | | |
9689 | | static PyObject * |
9690 | | os__clearenv(PyObject *module, PyObject *Py_UNUSED(ignored)) |
9691 | 0 | { |
9692 | 0 | return os__clearenv_impl(module); |
9693 | 0 | } |
9694 | | |
9695 | | #endif /* defined(HAVE_CLEARENV) */ |
9696 | | |
9697 | | PyDoc_STRVAR(os_strerror__doc__, |
9698 | | "strerror($module, code, /)\n" |
9699 | | "--\n" |
9700 | | "\n" |
9701 | | "Translate an error code to a message string."); |
9702 | | |
9703 | | #define OS_STRERROR_METHODDEF \ |
9704 | | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
9705 | | |
9706 | | static PyObject * |
9707 | | os_strerror_impl(PyObject *module, int code); |
9708 | | |
9709 | | static PyObject * |
9710 | | os_strerror(PyObject *module, PyObject *arg) |
9711 | 0 | { |
9712 | 0 | PyObject *return_value = NULL; |
9713 | 0 | int code; |
9714 | |
|
9715 | 0 | code = PyLong_AsInt(arg); |
9716 | 0 | if (code == -1 && PyErr_Occurred()) { |
9717 | 0 | goto exit; |
9718 | 0 | } |
9719 | 0 | return_value = os_strerror_impl(module, code); |
9720 | |
|
9721 | 0 | exit: |
9722 | 0 | return return_value; |
9723 | 0 | } |
9724 | | |
9725 | | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
9726 | | |
9727 | | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
9728 | | "WCOREDUMP($module, status, /)\n" |
9729 | | "--\n" |
9730 | | "\n" |
9731 | | "Return True if the process returning status was dumped to a core file."); |
9732 | | |
9733 | | #define OS_WCOREDUMP_METHODDEF \ |
9734 | | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
9735 | | |
9736 | | static int |
9737 | | os_WCOREDUMP_impl(PyObject *module, int status); |
9738 | | |
9739 | | static PyObject * |
9740 | | os_WCOREDUMP(PyObject *module, PyObject *arg) |
9741 | 0 | { |
9742 | 0 | PyObject *return_value = NULL; |
9743 | 0 | int status; |
9744 | 0 | int _return_value; |
9745 | |
|
9746 | 0 | status = PyLong_AsInt(arg); |
9747 | 0 | if (status == -1 && PyErr_Occurred()) { |
9748 | 0 | goto exit; |
9749 | 0 | } |
9750 | 0 | _return_value = os_WCOREDUMP_impl(module, status); |
9751 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9752 | 0 | goto exit; |
9753 | 0 | } |
9754 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9755 | |
|
9756 | 0 | exit: |
9757 | 0 | return return_value; |
9758 | 0 | } |
9759 | | |
9760 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
9761 | | |
9762 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
9763 | | |
9764 | | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
9765 | | "WIFCONTINUED($module, /, status)\n" |
9766 | | "--\n" |
9767 | | "\n" |
9768 | | "Return True if a particular process was continued from a job control stop.\n" |
9769 | | "\n" |
9770 | | "Return True if the process returning status was continued from a\n" |
9771 | | "job control stop."); |
9772 | | |
9773 | | #define OS_WIFCONTINUED_METHODDEF \ |
9774 | | {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
9775 | | |
9776 | | static int |
9777 | | os_WIFCONTINUED_impl(PyObject *module, int status); |
9778 | | |
9779 | | static PyObject * |
9780 | | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9781 | 0 | { |
9782 | 0 | PyObject *return_value = NULL; |
9783 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9784 | |
|
9785 | 0 | #define NUM_KEYWORDS 1 |
9786 | 0 | static struct { |
9787 | 0 | PyGC_Head _this_is_not_used; |
9788 | 0 | PyObject_VAR_HEAD |
9789 | 0 | Py_hash_t ob_hash; |
9790 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9791 | 0 | } _kwtuple = { |
9792 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9793 | 0 | .ob_hash = -1, |
9794 | 0 | .ob_item = { &_Py_ID(status), }, |
9795 | 0 | }; |
9796 | 0 | #undef NUM_KEYWORDS |
9797 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9798 | |
|
9799 | | #else // !Py_BUILD_CORE |
9800 | | # define KWTUPLE NULL |
9801 | | #endif // !Py_BUILD_CORE |
9802 | |
|
9803 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9804 | 0 | static _PyArg_Parser _parser = { |
9805 | 0 | .keywords = _keywords, |
9806 | 0 | .fname = "WIFCONTINUED", |
9807 | 0 | .kwtuple = KWTUPLE, |
9808 | 0 | }; |
9809 | 0 | #undef KWTUPLE |
9810 | 0 | PyObject *argsbuf[1]; |
9811 | 0 | int status; |
9812 | 0 | int _return_value; |
9813 | |
|
9814 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9815 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9816 | 0 | if (!args) { |
9817 | 0 | goto exit; |
9818 | 0 | } |
9819 | 0 | status = PyLong_AsInt(args[0]); |
9820 | 0 | if (status == -1 && PyErr_Occurred()) { |
9821 | 0 | goto exit; |
9822 | 0 | } |
9823 | 0 | _return_value = os_WIFCONTINUED_impl(module, status); |
9824 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9825 | 0 | goto exit; |
9826 | 0 | } |
9827 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9828 | |
|
9829 | 0 | exit: |
9830 | 0 | return return_value; |
9831 | 0 | } |
9832 | | |
9833 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
9834 | | |
9835 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
9836 | | |
9837 | | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
9838 | | "WIFSTOPPED($module, /, status)\n" |
9839 | | "--\n" |
9840 | | "\n" |
9841 | | "Return True if the process returning status was stopped."); |
9842 | | |
9843 | | #define OS_WIFSTOPPED_METHODDEF \ |
9844 | | {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
9845 | | |
9846 | | static int |
9847 | | os_WIFSTOPPED_impl(PyObject *module, int status); |
9848 | | |
9849 | | static PyObject * |
9850 | | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9851 | 0 | { |
9852 | 0 | PyObject *return_value = NULL; |
9853 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9854 | |
|
9855 | 0 | #define NUM_KEYWORDS 1 |
9856 | 0 | static struct { |
9857 | 0 | PyGC_Head _this_is_not_used; |
9858 | 0 | PyObject_VAR_HEAD |
9859 | 0 | Py_hash_t ob_hash; |
9860 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9861 | 0 | } _kwtuple = { |
9862 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9863 | 0 | .ob_hash = -1, |
9864 | 0 | .ob_item = { &_Py_ID(status), }, |
9865 | 0 | }; |
9866 | 0 | #undef NUM_KEYWORDS |
9867 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9868 | |
|
9869 | | #else // !Py_BUILD_CORE |
9870 | | # define KWTUPLE NULL |
9871 | | #endif // !Py_BUILD_CORE |
9872 | |
|
9873 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9874 | 0 | static _PyArg_Parser _parser = { |
9875 | 0 | .keywords = _keywords, |
9876 | 0 | .fname = "WIFSTOPPED", |
9877 | 0 | .kwtuple = KWTUPLE, |
9878 | 0 | }; |
9879 | 0 | #undef KWTUPLE |
9880 | 0 | PyObject *argsbuf[1]; |
9881 | 0 | int status; |
9882 | 0 | int _return_value; |
9883 | |
|
9884 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9885 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9886 | 0 | if (!args) { |
9887 | 0 | goto exit; |
9888 | 0 | } |
9889 | 0 | status = PyLong_AsInt(args[0]); |
9890 | 0 | if (status == -1 && PyErr_Occurred()) { |
9891 | 0 | goto exit; |
9892 | 0 | } |
9893 | 0 | _return_value = os_WIFSTOPPED_impl(module, status); |
9894 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9895 | 0 | goto exit; |
9896 | 0 | } |
9897 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9898 | |
|
9899 | 0 | exit: |
9900 | 0 | return return_value; |
9901 | 0 | } |
9902 | | |
9903 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
9904 | | |
9905 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
9906 | | |
9907 | | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
9908 | | "WIFSIGNALED($module, /, status)\n" |
9909 | | "--\n" |
9910 | | "\n" |
9911 | | "Return True if the process returning status was terminated by a signal."); |
9912 | | |
9913 | | #define OS_WIFSIGNALED_METHODDEF \ |
9914 | | {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
9915 | | |
9916 | | static int |
9917 | | os_WIFSIGNALED_impl(PyObject *module, int status); |
9918 | | |
9919 | | static PyObject * |
9920 | | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9921 | 0 | { |
9922 | 0 | PyObject *return_value = NULL; |
9923 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9924 | |
|
9925 | 0 | #define NUM_KEYWORDS 1 |
9926 | 0 | static struct { |
9927 | 0 | PyGC_Head _this_is_not_used; |
9928 | 0 | PyObject_VAR_HEAD |
9929 | 0 | Py_hash_t ob_hash; |
9930 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
9931 | 0 | } _kwtuple = { |
9932 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
9933 | 0 | .ob_hash = -1, |
9934 | 0 | .ob_item = { &_Py_ID(status), }, |
9935 | 0 | }; |
9936 | 0 | #undef NUM_KEYWORDS |
9937 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
9938 | |
|
9939 | | #else // !Py_BUILD_CORE |
9940 | | # define KWTUPLE NULL |
9941 | | #endif // !Py_BUILD_CORE |
9942 | |
|
9943 | 0 | static const char * const _keywords[] = {"status", NULL}; |
9944 | 0 | static _PyArg_Parser _parser = { |
9945 | 0 | .keywords = _keywords, |
9946 | 0 | .fname = "WIFSIGNALED", |
9947 | 0 | .kwtuple = KWTUPLE, |
9948 | 0 | }; |
9949 | 0 | #undef KWTUPLE |
9950 | 0 | PyObject *argsbuf[1]; |
9951 | 0 | int status; |
9952 | 0 | int _return_value; |
9953 | |
|
9954 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
9955 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
9956 | 0 | if (!args) { |
9957 | 0 | goto exit; |
9958 | 0 | } |
9959 | 0 | status = PyLong_AsInt(args[0]); |
9960 | 0 | if (status == -1 && PyErr_Occurred()) { |
9961 | 0 | goto exit; |
9962 | 0 | } |
9963 | 0 | _return_value = os_WIFSIGNALED_impl(module, status); |
9964 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
9965 | 0 | goto exit; |
9966 | 0 | } |
9967 | 0 | return_value = PyBool_FromLong((long)_return_value); |
9968 | |
|
9969 | 0 | exit: |
9970 | 0 | return return_value; |
9971 | 0 | } |
9972 | | |
9973 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
9974 | | |
9975 | | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
9976 | | |
9977 | | PyDoc_STRVAR(os_WIFEXITED__doc__, |
9978 | | "WIFEXITED($module, /, status)\n" |
9979 | | "--\n" |
9980 | | "\n" |
9981 | | "Return True if the process returning status exited via the exit() system call."); |
9982 | | |
9983 | | #define OS_WIFEXITED_METHODDEF \ |
9984 | | {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
9985 | | |
9986 | | static int |
9987 | | os_WIFEXITED_impl(PyObject *module, int status); |
9988 | | |
9989 | | static PyObject * |
9990 | | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
9991 | 0 | { |
9992 | 0 | PyObject *return_value = NULL; |
9993 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
9994 | |
|
9995 | 0 | #define NUM_KEYWORDS 1 |
9996 | 0 | static struct { |
9997 | 0 | PyGC_Head _this_is_not_used; |
9998 | 0 | PyObject_VAR_HEAD |
9999 | 0 | Py_hash_t ob_hash; |
10000 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10001 | 0 | } _kwtuple = { |
10002 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10003 | 0 | .ob_hash = -1, |
10004 | 0 | .ob_item = { &_Py_ID(status), }, |
10005 | 0 | }; |
10006 | 0 | #undef NUM_KEYWORDS |
10007 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10008 | |
|
10009 | | #else // !Py_BUILD_CORE |
10010 | | # define KWTUPLE NULL |
10011 | | #endif // !Py_BUILD_CORE |
10012 | |
|
10013 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10014 | 0 | static _PyArg_Parser _parser = { |
10015 | 0 | .keywords = _keywords, |
10016 | 0 | .fname = "WIFEXITED", |
10017 | 0 | .kwtuple = KWTUPLE, |
10018 | 0 | }; |
10019 | 0 | #undef KWTUPLE |
10020 | 0 | PyObject *argsbuf[1]; |
10021 | 0 | int status; |
10022 | 0 | int _return_value; |
10023 | |
|
10024 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10025 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10026 | 0 | if (!args) { |
10027 | 0 | goto exit; |
10028 | 0 | } |
10029 | 0 | status = PyLong_AsInt(args[0]); |
10030 | 0 | if (status == -1 && PyErr_Occurred()) { |
10031 | 0 | goto exit; |
10032 | 0 | } |
10033 | 0 | _return_value = os_WIFEXITED_impl(module, status); |
10034 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10035 | 0 | goto exit; |
10036 | 0 | } |
10037 | 0 | return_value = PyBool_FromLong((long)_return_value); |
10038 | |
|
10039 | 0 | exit: |
10040 | 0 | return return_value; |
10041 | 0 | } |
10042 | | |
10043 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
10044 | | |
10045 | | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
10046 | | |
10047 | | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
10048 | | "WEXITSTATUS($module, /, status)\n" |
10049 | | "--\n" |
10050 | | "\n" |
10051 | | "Return the process return code from status."); |
10052 | | |
10053 | | #define OS_WEXITSTATUS_METHODDEF \ |
10054 | | {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
10055 | | |
10056 | | static int |
10057 | | os_WEXITSTATUS_impl(PyObject *module, int status); |
10058 | | |
10059 | | static PyObject * |
10060 | | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10061 | 0 | { |
10062 | 0 | PyObject *return_value = NULL; |
10063 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10064 | |
|
10065 | 0 | #define NUM_KEYWORDS 1 |
10066 | 0 | static struct { |
10067 | 0 | PyGC_Head _this_is_not_used; |
10068 | 0 | PyObject_VAR_HEAD |
10069 | 0 | Py_hash_t ob_hash; |
10070 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10071 | 0 | } _kwtuple = { |
10072 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10073 | 0 | .ob_hash = -1, |
10074 | 0 | .ob_item = { &_Py_ID(status), }, |
10075 | 0 | }; |
10076 | 0 | #undef NUM_KEYWORDS |
10077 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10078 | |
|
10079 | | #else // !Py_BUILD_CORE |
10080 | | # define KWTUPLE NULL |
10081 | | #endif // !Py_BUILD_CORE |
10082 | |
|
10083 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10084 | 0 | static _PyArg_Parser _parser = { |
10085 | 0 | .keywords = _keywords, |
10086 | 0 | .fname = "WEXITSTATUS", |
10087 | 0 | .kwtuple = KWTUPLE, |
10088 | 0 | }; |
10089 | 0 | #undef KWTUPLE |
10090 | 0 | PyObject *argsbuf[1]; |
10091 | 0 | int status; |
10092 | 0 | int _return_value; |
10093 | |
|
10094 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10095 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10096 | 0 | if (!args) { |
10097 | 0 | goto exit; |
10098 | 0 | } |
10099 | 0 | status = PyLong_AsInt(args[0]); |
10100 | 0 | if (status == -1 && PyErr_Occurred()) { |
10101 | 0 | goto exit; |
10102 | 0 | } |
10103 | 0 | _return_value = os_WEXITSTATUS_impl(module, status); |
10104 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10105 | 0 | goto exit; |
10106 | 0 | } |
10107 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10108 | |
|
10109 | 0 | exit: |
10110 | 0 | return return_value; |
10111 | 0 | } |
10112 | | |
10113 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
10114 | | |
10115 | | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
10116 | | |
10117 | | PyDoc_STRVAR(os_WTERMSIG__doc__, |
10118 | | "WTERMSIG($module, /, status)\n" |
10119 | | "--\n" |
10120 | | "\n" |
10121 | | "Return the signal that terminated the process that provided the status value."); |
10122 | | |
10123 | | #define OS_WTERMSIG_METHODDEF \ |
10124 | | {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
10125 | | |
10126 | | static int |
10127 | | os_WTERMSIG_impl(PyObject *module, int status); |
10128 | | |
10129 | | static PyObject * |
10130 | | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10131 | 0 | { |
10132 | 0 | PyObject *return_value = NULL; |
10133 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10134 | |
|
10135 | 0 | #define NUM_KEYWORDS 1 |
10136 | 0 | static struct { |
10137 | 0 | PyGC_Head _this_is_not_used; |
10138 | 0 | PyObject_VAR_HEAD |
10139 | 0 | Py_hash_t ob_hash; |
10140 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10141 | 0 | } _kwtuple = { |
10142 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10143 | 0 | .ob_hash = -1, |
10144 | 0 | .ob_item = { &_Py_ID(status), }, |
10145 | 0 | }; |
10146 | 0 | #undef NUM_KEYWORDS |
10147 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10148 | |
|
10149 | | #else // !Py_BUILD_CORE |
10150 | | # define KWTUPLE NULL |
10151 | | #endif // !Py_BUILD_CORE |
10152 | |
|
10153 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10154 | 0 | static _PyArg_Parser _parser = { |
10155 | 0 | .keywords = _keywords, |
10156 | 0 | .fname = "WTERMSIG", |
10157 | 0 | .kwtuple = KWTUPLE, |
10158 | 0 | }; |
10159 | 0 | #undef KWTUPLE |
10160 | 0 | PyObject *argsbuf[1]; |
10161 | 0 | int status; |
10162 | 0 | int _return_value; |
10163 | |
|
10164 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10165 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10166 | 0 | if (!args) { |
10167 | 0 | goto exit; |
10168 | 0 | } |
10169 | 0 | status = PyLong_AsInt(args[0]); |
10170 | 0 | if (status == -1 && PyErr_Occurred()) { |
10171 | 0 | goto exit; |
10172 | 0 | } |
10173 | 0 | _return_value = os_WTERMSIG_impl(module, status); |
10174 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10175 | 0 | goto exit; |
10176 | 0 | } |
10177 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10178 | |
|
10179 | 0 | exit: |
10180 | 0 | return return_value; |
10181 | 0 | } |
10182 | | |
10183 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
10184 | | |
10185 | | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
10186 | | |
10187 | | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
10188 | | "WSTOPSIG($module, /, status)\n" |
10189 | | "--\n" |
10190 | | "\n" |
10191 | | "Return the signal that stopped the process that provided the status value."); |
10192 | | |
10193 | | #define OS_WSTOPSIG_METHODDEF \ |
10194 | | {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
10195 | | |
10196 | | static int |
10197 | | os_WSTOPSIG_impl(PyObject *module, int status); |
10198 | | |
10199 | | static PyObject * |
10200 | | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10201 | 0 | { |
10202 | 0 | PyObject *return_value = NULL; |
10203 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10204 | |
|
10205 | 0 | #define NUM_KEYWORDS 1 |
10206 | 0 | static struct { |
10207 | 0 | PyGC_Head _this_is_not_used; |
10208 | 0 | PyObject_VAR_HEAD |
10209 | 0 | Py_hash_t ob_hash; |
10210 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10211 | 0 | } _kwtuple = { |
10212 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10213 | 0 | .ob_hash = -1, |
10214 | 0 | .ob_item = { &_Py_ID(status), }, |
10215 | 0 | }; |
10216 | 0 | #undef NUM_KEYWORDS |
10217 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10218 | |
|
10219 | | #else // !Py_BUILD_CORE |
10220 | | # define KWTUPLE NULL |
10221 | | #endif // !Py_BUILD_CORE |
10222 | |
|
10223 | 0 | static const char * const _keywords[] = {"status", NULL}; |
10224 | 0 | static _PyArg_Parser _parser = { |
10225 | 0 | .keywords = _keywords, |
10226 | 0 | .fname = "WSTOPSIG", |
10227 | 0 | .kwtuple = KWTUPLE, |
10228 | 0 | }; |
10229 | 0 | #undef KWTUPLE |
10230 | 0 | PyObject *argsbuf[1]; |
10231 | 0 | int status; |
10232 | 0 | int _return_value; |
10233 | |
|
10234 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10235 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10236 | 0 | if (!args) { |
10237 | 0 | goto exit; |
10238 | 0 | } |
10239 | 0 | status = PyLong_AsInt(args[0]); |
10240 | 0 | if (status == -1 && PyErr_Occurred()) { |
10241 | 0 | goto exit; |
10242 | 0 | } |
10243 | 0 | _return_value = os_WSTOPSIG_impl(module, status); |
10244 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10245 | 0 | goto exit; |
10246 | 0 | } |
10247 | 0 | return_value = PyLong_FromLong((long)_return_value); |
10248 | |
|
10249 | 0 | exit: |
10250 | 0 | return return_value; |
10251 | 0 | } |
10252 | | |
10253 | | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
10254 | | |
10255 | | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10256 | | |
10257 | | PyDoc_STRVAR(os_fstatvfs__doc__, |
10258 | | "fstatvfs($module, fd, /)\n" |
10259 | | "--\n" |
10260 | | "\n" |
10261 | | "Perform an fstatvfs system call on the given fd.\n" |
10262 | | "\n" |
10263 | | "Equivalent to statvfs(fd)."); |
10264 | | |
10265 | | #define OS_FSTATVFS_METHODDEF \ |
10266 | | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
10267 | | |
10268 | | static PyObject * |
10269 | | os_fstatvfs_impl(PyObject *module, int fd); |
10270 | | |
10271 | | static PyObject * |
10272 | | os_fstatvfs(PyObject *module, PyObject *arg) |
10273 | 0 | { |
10274 | 0 | PyObject *return_value = NULL; |
10275 | 0 | int fd; |
10276 | |
|
10277 | 0 | fd = PyLong_AsInt(arg); |
10278 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10279 | 0 | goto exit; |
10280 | 0 | } |
10281 | 0 | return_value = os_fstatvfs_impl(module, fd); |
10282 | |
|
10283 | 0 | exit: |
10284 | 0 | return return_value; |
10285 | 0 | } |
10286 | | |
10287 | | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10288 | | |
10289 | | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
10290 | | |
10291 | | PyDoc_STRVAR(os_statvfs__doc__, |
10292 | | "statvfs($module, /, path)\n" |
10293 | | "--\n" |
10294 | | "\n" |
10295 | | "Perform a statvfs system call on the given path.\n" |
10296 | | "\n" |
10297 | | "path may always be specified as a string.\n" |
10298 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10299 | | " If this functionality is unavailable, using it raises an exception."); |
10300 | | |
10301 | | #define OS_STATVFS_METHODDEF \ |
10302 | | {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
10303 | | |
10304 | | static PyObject * |
10305 | | os_statvfs_impl(PyObject *module, path_t *path); |
10306 | | |
10307 | | static PyObject * |
10308 | | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10309 | 0 | { |
10310 | 0 | PyObject *return_value = NULL; |
10311 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10312 | |
|
10313 | 0 | #define NUM_KEYWORDS 1 |
10314 | 0 | static struct { |
10315 | 0 | PyGC_Head _this_is_not_used; |
10316 | 0 | PyObject_VAR_HEAD |
10317 | 0 | Py_hash_t ob_hash; |
10318 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10319 | 0 | } _kwtuple = { |
10320 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10321 | 0 | .ob_hash = -1, |
10322 | 0 | .ob_item = { &_Py_ID(path), }, |
10323 | 0 | }; |
10324 | 0 | #undef NUM_KEYWORDS |
10325 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10326 | |
|
10327 | | #else // !Py_BUILD_CORE |
10328 | | # define KWTUPLE NULL |
10329 | | #endif // !Py_BUILD_CORE |
10330 | |
|
10331 | 0 | static const char * const _keywords[] = {"path", NULL}; |
10332 | 0 | static _PyArg_Parser _parser = { |
10333 | 0 | .keywords = _keywords, |
10334 | 0 | .fname = "statvfs", |
10335 | 0 | .kwtuple = KWTUPLE, |
10336 | 0 | }; |
10337 | 0 | #undef KWTUPLE |
10338 | 0 | PyObject *argsbuf[1]; |
10339 | 0 | path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS); |
10340 | |
|
10341 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10342 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10343 | 0 | if (!args) { |
10344 | 0 | goto exit; |
10345 | 0 | } |
10346 | 0 | if (!path_converter(args[0], &path)) { |
10347 | 0 | goto exit; |
10348 | 0 | } |
10349 | 0 | return_value = os_statvfs_impl(module, &path); |
10350 | |
|
10351 | 0 | exit: |
10352 | | /* Cleanup for path */ |
10353 | 0 | path_cleanup(&path); |
10354 | |
|
10355 | 0 | return return_value; |
10356 | 0 | } |
10357 | | |
10358 | | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
10359 | | |
10360 | | #if defined(MS_WINDOWS) |
10361 | | |
10362 | | PyDoc_STRVAR(os__getdiskusage__doc__, |
10363 | | "_getdiskusage($module, /, path)\n" |
10364 | | "--\n" |
10365 | | "\n" |
10366 | | "Return disk usage statistics about the given path as a (total, free) tuple."); |
10367 | | |
10368 | | #define OS__GETDISKUSAGE_METHODDEF \ |
10369 | | {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
10370 | | |
10371 | | static PyObject * |
10372 | | os__getdiskusage_impl(PyObject *module, path_t *path); |
10373 | | |
10374 | | static PyObject * |
10375 | | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10376 | | { |
10377 | | PyObject *return_value = NULL; |
10378 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10379 | | |
10380 | | #define NUM_KEYWORDS 1 |
10381 | | static struct { |
10382 | | PyGC_Head _this_is_not_used; |
10383 | | PyObject_VAR_HEAD |
10384 | | Py_hash_t ob_hash; |
10385 | | PyObject *ob_item[NUM_KEYWORDS]; |
10386 | | } _kwtuple = { |
10387 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10388 | | .ob_hash = -1, |
10389 | | .ob_item = { &_Py_ID(path), }, |
10390 | | }; |
10391 | | #undef NUM_KEYWORDS |
10392 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10393 | | |
10394 | | #else // !Py_BUILD_CORE |
10395 | | # define KWTUPLE NULL |
10396 | | #endif // !Py_BUILD_CORE |
10397 | | |
10398 | | static const char * const _keywords[] = {"path", NULL}; |
10399 | | static _PyArg_Parser _parser = { |
10400 | | .keywords = _keywords, |
10401 | | .fname = "_getdiskusage", |
10402 | | .kwtuple = KWTUPLE, |
10403 | | }; |
10404 | | #undef KWTUPLE |
10405 | | PyObject *argsbuf[1]; |
10406 | | path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0); |
10407 | | |
10408 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10409 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10410 | | if (!args) { |
10411 | | goto exit; |
10412 | | } |
10413 | | if (!path_converter(args[0], &path)) { |
10414 | | goto exit; |
10415 | | } |
10416 | | return_value = os__getdiskusage_impl(module, &path); |
10417 | | |
10418 | | exit: |
10419 | | /* Cleanup for path */ |
10420 | | path_cleanup(&path); |
10421 | | |
10422 | | return return_value; |
10423 | | } |
10424 | | |
10425 | | #endif /* defined(MS_WINDOWS) */ |
10426 | | |
10427 | | #if defined(HAVE_FPATHCONF) |
10428 | | |
10429 | | PyDoc_STRVAR(os_fpathconf__doc__, |
10430 | | "fpathconf($module, fd, name, /)\n" |
10431 | | "--\n" |
10432 | | "\n" |
10433 | | "Return the configuration limit name for the file descriptor fd.\n" |
10434 | | "\n" |
10435 | | "If there is no limit, return -1."); |
10436 | | |
10437 | | #define OS_FPATHCONF_METHODDEF \ |
10438 | | {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__}, |
10439 | | |
10440 | | static long |
10441 | | os_fpathconf_impl(PyObject *module, int fd, int name); |
10442 | | |
10443 | | static PyObject * |
10444 | | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10445 | 0 | { |
10446 | 0 | PyObject *return_value = NULL; |
10447 | 0 | int fd; |
10448 | 0 | int name; |
10449 | 0 | long _return_value; |
10450 | |
|
10451 | 0 | if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { |
10452 | 0 | goto exit; |
10453 | 0 | } |
10454 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
10455 | 0 | if (fd < 0) { |
10456 | 0 | goto exit; |
10457 | 0 | } |
10458 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10459 | 0 | goto exit; |
10460 | 0 | } |
10461 | 0 | _return_value = os_fpathconf_impl(module, fd, name); |
10462 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10463 | 0 | goto exit; |
10464 | 0 | } |
10465 | 0 | return_value = PyLong_FromLong(_return_value); |
10466 | |
|
10467 | 0 | exit: |
10468 | 0 | return return_value; |
10469 | 0 | } |
10470 | | |
10471 | | #endif /* defined(HAVE_FPATHCONF) */ |
10472 | | |
10473 | | #if defined(HAVE_PATHCONF) |
10474 | | |
10475 | | PyDoc_STRVAR(os_pathconf__doc__, |
10476 | | "pathconf($module, /, path, name)\n" |
10477 | | "--\n" |
10478 | | "\n" |
10479 | | "Return the configuration limit name for the file or directory path.\n" |
10480 | | "\n" |
10481 | | "If there is no limit, return -1.\n" |
10482 | | "On some platforms, path may also be specified as an open file descriptor.\n" |
10483 | | " If this functionality is unavailable, using it raises an exception."); |
10484 | | |
10485 | | #define OS_PATHCONF_METHODDEF \ |
10486 | | {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
10487 | | |
10488 | | static long |
10489 | | os_pathconf_impl(PyObject *module, path_t *path, int name); |
10490 | | |
10491 | | static PyObject * |
10492 | | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10493 | 0 | { |
10494 | 0 | PyObject *return_value = NULL; |
10495 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10496 | |
|
10497 | 0 | #define NUM_KEYWORDS 2 |
10498 | 0 | static struct { |
10499 | 0 | PyGC_Head _this_is_not_used; |
10500 | 0 | PyObject_VAR_HEAD |
10501 | 0 | Py_hash_t ob_hash; |
10502 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10503 | 0 | } _kwtuple = { |
10504 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10505 | 0 | .ob_hash = -1, |
10506 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(name), }, |
10507 | 0 | }; |
10508 | 0 | #undef NUM_KEYWORDS |
10509 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10510 | |
|
10511 | | #else // !Py_BUILD_CORE |
10512 | | # define KWTUPLE NULL |
10513 | | #endif // !Py_BUILD_CORE |
10514 | |
|
10515 | 0 | static const char * const _keywords[] = {"path", "name", NULL}; |
10516 | 0 | static _PyArg_Parser _parser = { |
10517 | 0 | .keywords = _keywords, |
10518 | 0 | .fname = "pathconf", |
10519 | 0 | .kwtuple = KWTUPLE, |
10520 | 0 | }; |
10521 | 0 | #undef KWTUPLE |
10522 | 0 | PyObject *argsbuf[2]; |
10523 | 0 | path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF); |
10524 | 0 | int name; |
10525 | 0 | long _return_value; |
10526 | |
|
10527 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10528 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10529 | 0 | if (!args) { |
10530 | 0 | goto exit; |
10531 | 0 | } |
10532 | 0 | if (!path_converter(args[0], &path)) { |
10533 | 0 | goto exit; |
10534 | 0 | } |
10535 | 0 | if (!conv_confname(module, args[1], &name, "pathconf_names")) { |
10536 | 0 | goto exit; |
10537 | 0 | } |
10538 | 0 | _return_value = os_pathconf_impl(module, &path, name); |
10539 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10540 | 0 | goto exit; |
10541 | 0 | } |
10542 | 0 | return_value = PyLong_FromLong(_return_value); |
10543 | |
|
10544 | 0 | exit: |
10545 | | /* Cleanup for path */ |
10546 | 0 | path_cleanup(&path); |
10547 | |
|
10548 | 0 | return return_value; |
10549 | 0 | } |
10550 | | |
10551 | | #endif /* defined(HAVE_PATHCONF) */ |
10552 | | |
10553 | | #if defined(HAVE_CONFSTR) |
10554 | | |
10555 | | PyDoc_STRVAR(os_confstr__doc__, |
10556 | | "confstr($module, name, /)\n" |
10557 | | "--\n" |
10558 | | "\n" |
10559 | | "Return a string-valued system configuration variable."); |
10560 | | |
10561 | | #define OS_CONFSTR_METHODDEF \ |
10562 | | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
10563 | | |
10564 | | static PyObject * |
10565 | | os_confstr_impl(PyObject *module, int name); |
10566 | | |
10567 | | static PyObject * |
10568 | | os_confstr(PyObject *module, PyObject *arg) |
10569 | 0 | { |
10570 | 0 | PyObject *return_value = NULL; |
10571 | 0 | int name; |
10572 | |
|
10573 | 0 | if (!conv_confname(module, arg, &name, "confstr_names")) { |
10574 | 0 | goto exit; |
10575 | 0 | } |
10576 | 0 | return_value = os_confstr_impl(module, name); |
10577 | |
|
10578 | 0 | exit: |
10579 | 0 | return return_value; |
10580 | 0 | } |
10581 | | |
10582 | | #endif /* defined(HAVE_CONFSTR) */ |
10583 | | |
10584 | | #if defined(HAVE_SYSCONF) |
10585 | | |
10586 | | PyDoc_STRVAR(os_sysconf__doc__, |
10587 | | "sysconf($module, name, /)\n" |
10588 | | "--\n" |
10589 | | "\n" |
10590 | | "Return an integer-valued system configuration variable."); |
10591 | | |
10592 | | #define OS_SYSCONF_METHODDEF \ |
10593 | | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
10594 | | |
10595 | | static long |
10596 | | os_sysconf_impl(PyObject *module, int name); |
10597 | | |
10598 | | static PyObject * |
10599 | | os_sysconf(PyObject *module, PyObject *arg) |
10600 | 0 | { |
10601 | 0 | PyObject *return_value = NULL; |
10602 | 0 | int name; |
10603 | 0 | long _return_value; |
10604 | |
|
10605 | 0 | if (!conv_confname(module, arg, &name, "sysconf_names")) { |
10606 | 0 | goto exit; |
10607 | 0 | } |
10608 | 0 | _return_value = os_sysconf_impl(module, name); |
10609 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
10610 | 0 | goto exit; |
10611 | 0 | } |
10612 | 0 | return_value = PyLong_FromLong(_return_value); |
10613 | |
|
10614 | 0 | exit: |
10615 | 0 | return return_value; |
10616 | 0 | } |
10617 | | |
10618 | | #endif /* defined(HAVE_SYSCONF) */ |
10619 | | |
10620 | | PyDoc_STRVAR(os_abort__doc__, |
10621 | | "abort($module, /)\n" |
10622 | | "--\n" |
10623 | | "\n" |
10624 | | "Abort the interpreter immediately.\n" |
10625 | | "\n" |
10626 | | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
10627 | | "on the hosting operating system. This function never returns."); |
10628 | | |
10629 | | #define OS_ABORT_METHODDEF \ |
10630 | | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
10631 | | |
10632 | | static PyObject * |
10633 | | os_abort_impl(PyObject *module); |
10634 | | |
10635 | | static PyObject * |
10636 | | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10637 | 0 | { |
10638 | 0 | return os_abort_impl(module); |
10639 | 0 | } |
10640 | | |
10641 | | #if defined(MS_WINDOWS) |
10642 | | |
10643 | | PyDoc_STRVAR(os_startfile__doc__, |
10644 | | "startfile($module, /, filepath, operation=<unrepresentable>,\n" |
10645 | | " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n" |
10646 | | "--\n" |
10647 | | "\n" |
10648 | | "Start a file with its associated application.\n" |
10649 | | "\n" |
10650 | | "When \"operation\" is not specified or \"open\", this acts like\n" |
10651 | | "double-clicking the file in Explorer, or giving the file name as an\n" |
10652 | | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
10653 | | "application (if any) its extension is associated.\n" |
10654 | | "When another \"operation\" is given, it specifies what should be done with\n" |
10655 | | "the file. A typical operation is \"print\".\n" |
10656 | | "\n" |
10657 | | "\"arguments\" is passed to the application, but should be omitted if the\n" |
10658 | | "file is a document.\n" |
10659 | | "\n" |
10660 | | "\"cwd\" is the working directory for the operation. If \"filepath\" is\n" |
10661 | | "relative, it will be resolved against this directory. This argument\n" |
10662 | | "should usually be an absolute path.\n" |
10663 | | "\n" |
10664 | | "\"show_cmd\" can be used to override the recommended visibility option.\n" |
10665 | | "See the Windows ShellExecute documentation for values.\n" |
10666 | | "\n" |
10667 | | "startfile returns as soon as the associated application is launched.\n" |
10668 | | "There is no option to wait for the application to close, and no way\n" |
10669 | | "to retrieve the application\'s exit status.\n" |
10670 | | "\n" |
10671 | | "The filepath is relative to the current directory. If you want to use\n" |
10672 | | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
10673 | | "the underlying Win32 ShellExecute function doesn\'t work if it is."); |
10674 | | |
10675 | | #define OS_STARTFILE_METHODDEF \ |
10676 | | {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
10677 | | |
10678 | | static PyObject * |
10679 | | os_startfile_impl(PyObject *module, path_t *filepath, |
10680 | | const wchar_t *operation, const wchar_t *arguments, |
10681 | | path_t *cwd, int show_cmd); |
10682 | | |
10683 | | static PyObject * |
10684 | | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10685 | | { |
10686 | | PyObject *return_value = NULL; |
10687 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10688 | | |
10689 | | #define NUM_KEYWORDS 5 |
10690 | | static struct { |
10691 | | PyGC_Head _this_is_not_used; |
10692 | | PyObject_VAR_HEAD |
10693 | | Py_hash_t ob_hash; |
10694 | | PyObject *ob_item[NUM_KEYWORDS]; |
10695 | | } _kwtuple = { |
10696 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10697 | | .ob_hash = -1, |
10698 | | .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), }, |
10699 | | }; |
10700 | | #undef NUM_KEYWORDS |
10701 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10702 | | |
10703 | | #else // !Py_BUILD_CORE |
10704 | | # define KWTUPLE NULL |
10705 | | #endif // !Py_BUILD_CORE |
10706 | | |
10707 | | static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL}; |
10708 | | static _PyArg_Parser _parser = { |
10709 | | .keywords = _keywords, |
10710 | | .fname = "startfile", |
10711 | | .kwtuple = KWTUPLE, |
10712 | | }; |
10713 | | #undef KWTUPLE |
10714 | | PyObject *argsbuf[5]; |
10715 | | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
10716 | | path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0); |
10717 | | const wchar_t *operation = NULL; |
10718 | | const wchar_t *arguments = NULL; |
10719 | | path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0); |
10720 | | int show_cmd = 1; |
10721 | | |
10722 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10723 | | /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10724 | | if (!args) { |
10725 | | goto exit; |
10726 | | } |
10727 | | if (!path_converter(args[0], &filepath)) { |
10728 | | goto exit; |
10729 | | } |
10730 | | if (!noptargs) { |
10731 | | goto skip_optional_pos; |
10732 | | } |
10733 | | if (args[1]) { |
10734 | | if (!PyUnicode_Check(args[1])) { |
10735 | | _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]); |
10736 | | goto exit; |
10737 | | } |
10738 | | operation = PyUnicode_AsWideCharString(args[1], NULL); |
10739 | | if (operation == NULL) { |
10740 | | goto exit; |
10741 | | } |
10742 | | if (!--noptargs) { |
10743 | | goto skip_optional_pos; |
10744 | | } |
10745 | | } |
10746 | | if (args[2]) { |
10747 | | if (!PyUnicode_Check(args[2])) { |
10748 | | _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]); |
10749 | | goto exit; |
10750 | | } |
10751 | | arguments = PyUnicode_AsWideCharString(args[2], NULL); |
10752 | | if (arguments == NULL) { |
10753 | | goto exit; |
10754 | | } |
10755 | | if (!--noptargs) { |
10756 | | goto skip_optional_pos; |
10757 | | } |
10758 | | } |
10759 | | if (args[3]) { |
10760 | | if (!path_converter(args[3], &cwd)) { |
10761 | | goto exit; |
10762 | | } |
10763 | | if (!--noptargs) { |
10764 | | goto skip_optional_pos; |
10765 | | } |
10766 | | } |
10767 | | show_cmd = PyLong_AsInt(args[4]); |
10768 | | if (show_cmd == -1 && PyErr_Occurred()) { |
10769 | | goto exit; |
10770 | | } |
10771 | | skip_optional_pos: |
10772 | | return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd); |
10773 | | |
10774 | | exit: |
10775 | | /* Cleanup for filepath */ |
10776 | | path_cleanup(&filepath); |
10777 | | /* Cleanup for operation */ |
10778 | | PyMem_Free((void *)operation); |
10779 | | /* Cleanup for arguments */ |
10780 | | PyMem_Free((void *)arguments); |
10781 | | /* Cleanup for cwd */ |
10782 | | path_cleanup(&cwd); |
10783 | | |
10784 | | return return_value; |
10785 | | } |
10786 | | |
10787 | | #endif /* defined(MS_WINDOWS) */ |
10788 | | |
10789 | | #if defined(HAVE_GETLOADAVG) |
10790 | | |
10791 | | PyDoc_STRVAR(os_getloadavg__doc__, |
10792 | | "getloadavg($module, /)\n" |
10793 | | "--\n" |
10794 | | "\n" |
10795 | | "Return average recent system load information.\n" |
10796 | | "\n" |
10797 | | "Return the number of processes in the system run queue averaged over\n" |
10798 | | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
10799 | | "Raises OSError if the load average was unobtainable."); |
10800 | | |
10801 | | #define OS_GETLOADAVG_METHODDEF \ |
10802 | | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
10803 | | |
10804 | | static PyObject * |
10805 | | os_getloadavg_impl(PyObject *module); |
10806 | | |
10807 | | static PyObject * |
10808 | | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10809 | 0 | { |
10810 | 0 | return os_getloadavg_impl(module); |
10811 | 0 | } |
10812 | | |
10813 | | #endif /* defined(HAVE_GETLOADAVG) */ |
10814 | | |
10815 | | PyDoc_STRVAR(os_device_encoding__doc__, |
10816 | | "device_encoding($module, /, fd)\n" |
10817 | | "--\n" |
10818 | | "\n" |
10819 | | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
10820 | | "\n" |
10821 | | "The file descriptor must be attached to a terminal.\n" |
10822 | | "If the device is not a terminal, return None."); |
10823 | | |
10824 | | #define OS_DEVICE_ENCODING_METHODDEF \ |
10825 | | {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
10826 | | |
10827 | | static PyObject * |
10828 | | os_device_encoding_impl(PyObject *module, int fd); |
10829 | | |
10830 | | static PyObject * |
10831 | | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
10832 | 0 | { |
10833 | 0 | PyObject *return_value = NULL; |
10834 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
10835 | |
|
10836 | 0 | #define NUM_KEYWORDS 1 |
10837 | 0 | static struct { |
10838 | 0 | PyGC_Head _this_is_not_used; |
10839 | 0 | PyObject_VAR_HEAD |
10840 | 0 | Py_hash_t ob_hash; |
10841 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
10842 | 0 | } _kwtuple = { |
10843 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
10844 | 0 | .ob_hash = -1, |
10845 | 0 | .ob_item = { &_Py_ID(fd), }, |
10846 | 0 | }; |
10847 | 0 | #undef NUM_KEYWORDS |
10848 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
10849 | |
|
10850 | | #else // !Py_BUILD_CORE |
10851 | | # define KWTUPLE NULL |
10852 | | #endif // !Py_BUILD_CORE |
10853 | |
|
10854 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
10855 | 0 | static _PyArg_Parser _parser = { |
10856 | 0 | .keywords = _keywords, |
10857 | 0 | .fname = "device_encoding", |
10858 | 0 | .kwtuple = KWTUPLE, |
10859 | 0 | }; |
10860 | 0 | #undef KWTUPLE |
10861 | 0 | PyObject *argsbuf[1]; |
10862 | 0 | int fd; |
10863 | |
|
10864 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
10865 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
10866 | 0 | if (!args) { |
10867 | 0 | goto exit; |
10868 | 0 | } |
10869 | 0 | fd = PyLong_AsInt(args[0]); |
10870 | 0 | if (fd == -1 && PyErr_Occurred()) { |
10871 | 0 | goto exit; |
10872 | 0 | } |
10873 | 0 | return_value = os_device_encoding_impl(module, fd); |
10874 | |
|
10875 | 0 | exit: |
10876 | 0 | return return_value; |
10877 | 0 | } |
10878 | | |
10879 | | #if defined(HAVE_SETRESUID) |
10880 | | |
10881 | | PyDoc_STRVAR(os_setresuid__doc__, |
10882 | | "setresuid($module, ruid, euid, suid, /)\n" |
10883 | | "--\n" |
10884 | | "\n" |
10885 | | "Set the current process\'s real, effective, and saved user ids."); |
10886 | | |
10887 | | #define OS_SETRESUID_METHODDEF \ |
10888 | | {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__}, |
10889 | | |
10890 | | static PyObject * |
10891 | | os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid); |
10892 | | |
10893 | | static PyObject * |
10894 | | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10895 | 0 | { |
10896 | 0 | PyObject *return_value = NULL; |
10897 | 0 | uid_t ruid; |
10898 | 0 | uid_t euid; |
10899 | 0 | uid_t suid; |
10900 | |
|
10901 | 0 | if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { |
10902 | 0 | goto exit; |
10903 | 0 | } |
10904 | 0 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
10905 | 0 | goto exit; |
10906 | 0 | } |
10907 | 0 | if (!_Py_Uid_Converter(args[1], &euid)) { |
10908 | 0 | goto exit; |
10909 | 0 | } |
10910 | 0 | if (!_Py_Uid_Converter(args[2], &suid)) { |
10911 | 0 | goto exit; |
10912 | 0 | } |
10913 | 0 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
10914 | |
|
10915 | 0 | exit: |
10916 | 0 | return return_value; |
10917 | 0 | } |
10918 | | |
10919 | | #endif /* defined(HAVE_SETRESUID) */ |
10920 | | |
10921 | | #if defined(HAVE_SETRESGID) |
10922 | | |
10923 | | PyDoc_STRVAR(os_setresgid__doc__, |
10924 | | "setresgid($module, rgid, egid, sgid, /)\n" |
10925 | | "--\n" |
10926 | | "\n" |
10927 | | "Set the current process\'s real, effective, and saved group ids."); |
10928 | | |
10929 | | #define OS_SETRESGID_METHODDEF \ |
10930 | | {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__}, |
10931 | | |
10932 | | static PyObject * |
10933 | | os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid); |
10934 | | |
10935 | | static PyObject * |
10936 | | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
10937 | 0 | { |
10938 | 0 | PyObject *return_value = NULL; |
10939 | 0 | gid_t rgid; |
10940 | 0 | gid_t egid; |
10941 | 0 | gid_t sgid; |
10942 | |
|
10943 | 0 | if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { |
10944 | 0 | goto exit; |
10945 | 0 | } |
10946 | 0 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
10947 | 0 | goto exit; |
10948 | 0 | } |
10949 | 0 | if (!_Py_Gid_Converter(args[1], &egid)) { |
10950 | 0 | goto exit; |
10951 | 0 | } |
10952 | 0 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
10953 | 0 | goto exit; |
10954 | 0 | } |
10955 | 0 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
10956 | |
|
10957 | 0 | exit: |
10958 | 0 | return return_value; |
10959 | 0 | } |
10960 | | |
10961 | | #endif /* defined(HAVE_SETRESGID) */ |
10962 | | |
10963 | | #if defined(HAVE_GETRESUID) |
10964 | | |
10965 | | PyDoc_STRVAR(os_getresuid__doc__, |
10966 | | "getresuid($module, /)\n" |
10967 | | "--\n" |
10968 | | "\n" |
10969 | | "Return a tuple of the current process\'s real, effective, and saved user ids."); |
10970 | | |
10971 | | #define OS_GETRESUID_METHODDEF \ |
10972 | | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
10973 | | |
10974 | | static PyObject * |
10975 | | os_getresuid_impl(PyObject *module); |
10976 | | |
10977 | | static PyObject * |
10978 | | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
10979 | 0 | { |
10980 | 0 | return os_getresuid_impl(module); |
10981 | 0 | } |
10982 | | |
10983 | | #endif /* defined(HAVE_GETRESUID) */ |
10984 | | |
10985 | | #if defined(HAVE_GETRESGID) |
10986 | | |
10987 | | PyDoc_STRVAR(os_getresgid__doc__, |
10988 | | "getresgid($module, /)\n" |
10989 | | "--\n" |
10990 | | "\n" |
10991 | | "Return a tuple of the current process\'s real, effective, and saved group ids."); |
10992 | | |
10993 | | #define OS_GETRESGID_METHODDEF \ |
10994 | | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
10995 | | |
10996 | | static PyObject * |
10997 | | os_getresgid_impl(PyObject *module); |
10998 | | |
10999 | | static PyObject * |
11000 | | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11001 | 0 | { |
11002 | 0 | return os_getresgid_impl(module); |
11003 | 0 | } |
11004 | | |
11005 | | #endif /* defined(HAVE_GETRESGID) */ |
11006 | | |
11007 | | #if defined(USE_XATTRS) |
11008 | | |
11009 | | PyDoc_STRVAR(os_getxattr__doc__, |
11010 | | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
11011 | | "--\n" |
11012 | | "\n" |
11013 | | "Return the value of extended attribute attribute on path.\n" |
11014 | | "\n" |
11015 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
11016 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11017 | | " link, getxattr will examine the symbolic link itself instead of the file\n" |
11018 | | " the link points to."); |
11019 | | |
11020 | | #define OS_GETXATTR_METHODDEF \ |
11021 | | {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
11022 | | |
11023 | | static PyObject * |
11024 | | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11025 | | int follow_symlinks); |
11026 | | |
11027 | | static PyObject * |
11028 | | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11029 | 0 | { |
11030 | 0 | PyObject *return_value = NULL; |
11031 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11032 | |
|
11033 | 0 | #define NUM_KEYWORDS 3 |
11034 | 0 | static struct { |
11035 | 0 | PyGC_Head _this_is_not_used; |
11036 | 0 | PyObject_VAR_HEAD |
11037 | 0 | Py_hash_t ob_hash; |
11038 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11039 | 0 | } _kwtuple = { |
11040 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11041 | 0 | .ob_hash = -1, |
11042 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
11043 | 0 | }; |
11044 | 0 | #undef NUM_KEYWORDS |
11045 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11046 | |
|
11047 | | #else // !Py_BUILD_CORE |
11048 | | # define KWTUPLE NULL |
11049 | | #endif // !Py_BUILD_CORE |
11050 | |
|
11051 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
11052 | 0 | static _PyArg_Parser _parser = { |
11053 | 0 | .keywords = _keywords, |
11054 | 0 | .fname = "getxattr", |
11055 | 0 | .kwtuple = KWTUPLE, |
11056 | 0 | }; |
11057 | 0 | #undef KWTUPLE |
11058 | 0 | PyObject *argsbuf[3]; |
11059 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
11060 | 0 | path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1); |
11061 | 0 | path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0); |
11062 | 0 | int follow_symlinks = 1; |
11063 | |
|
11064 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11065 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11066 | 0 | if (!args) { |
11067 | 0 | goto exit; |
11068 | 0 | } |
11069 | 0 | if (!path_converter(args[0], &path)) { |
11070 | 0 | goto exit; |
11071 | 0 | } |
11072 | 0 | if (!path_converter(args[1], &attribute)) { |
11073 | 0 | goto exit; |
11074 | 0 | } |
11075 | 0 | if (!noptargs) { |
11076 | 0 | goto skip_optional_kwonly; |
11077 | 0 | } |
11078 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11079 | 0 | if (follow_symlinks < 0) { |
11080 | 0 | goto exit; |
11081 | 0 | } |
11082 | 0 | skip_optional_kwonly: |
11083 | 0 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
11084 | |
|
11085 | 0 | exit: |
11086 | | /* Cleanup for path */ |
11087 | 0 | path_cleanup(&path); |
11088 | | /* Cleanup for attribute */ |
11089 | 0 | path_cleanup(&attribute); |
11090 | |
|
11091 | 0 | return return_value; |
11092 | 0 | } |
11093 | | |
11094 | | #endif /* defined(USE_XATTRS) */ |
11095 | | |
11096 | | #if defined(USE_XATTRS) |
11097 | | |
11098 | | PyDoc_STRVAR(os_setxattr__doc__, |
11099 | | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
11100 | | " follow_symlinks=True)\n" |
11101 | | "--\n" |
11102 | | "\n" |
11103 | | "Set extended attribute attribute on path to value.\n" |
11104 | | "\n" |
11105 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
11106 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11107 | | " link, setxattr will modify the symbolic link itself instead of the file\n" |
11108 | | " the link points to."); |
11109 | | |
11110 | | #define OS_SETXATTR_METHODDEF \ |
11111 | | {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
11112 | | |
11113 | | static PyObject * |
11114 | | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11115 | | Py_buffer *value, int flags, int follow_symlinks); |
11116 | | |
11117 | | static PyObject * |
11118 | | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11119 | 0 | { |
11120 | 0 | PyObject *return_value = NULL; |
11121 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11122 | |
|
11123 | 0 | #define NUM_KEYWORDS 5 |
11124 | 0 | static struct { |
11125 | 0 | PyGC_Head _this_is_not_used; |
11126 | 0 | PyObject_VAR_HEAD |
11127 | 0 | Py_hash_t ob_hash; |
11128 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11129 | 0 | } _kwtuple = { |
11130 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11131 | 0 | .ob_hash = -1, |
11132 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), }, |
11133 | 0 | }; |
11134 | 0 | #undef NUM_KEYWORDS |
11135 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11136 | |
|
11137 | | #else // !Py_BUILD_CORE |
11138 | | # define KWTUPLE NULL |
11139 | | #endif // !Py_BUILD_CORE |
11140 | |
|
11141 | 0 | static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; |
11142 | 0 | static _PyArg_Parser _parser = { |
11143 | 0 | .keywords = _keywords, |
11144 | 0 | .fname = "setxattr", |
11145 | 0 | .kwtuple = KWTUPLE, |
11146 | 0 | }; |
11147 | 0 | #undef KWTUPLE |
11148 | 0 | PyObject *argsbuf[5]; |
11149 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
11150 | 0 | path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1); |
11151 | 0 | path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0); |
11152 | 0 | Py_buffer value = {NULL, NULL}; |
11153 | 0 | int flags = 0; |
11154 | 0 | int follow_symlinks = 1; |
11155 | |
|
11156 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11157 | 0 | /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11158 | 0 | if (!args) { |
11159 | 0 | goto exit; |
11160 | 0 | } |
11161 | 0 | if (!path_converter(args[0], &path)) { |
11162 | 0 | goto exit; |
11163 | 0 | } |
11164 | 0 | if (!path_converter(args[1], &attribute)) { |
11165 | 0 | goto exit; |
11166 | 0 | } |
11167 | 0 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
11168 | 0 | goto exit; |
11169 | 0 | } |
11170 | 0 | if (!noptargs) { |
11171 | 0 | goto skip_optional_pos; |
11172 | 0 | } |
11173 | 0 | if (args[3]) { |
11174 | 0 | flags = PyLong_AsInt(args[3]); |
11175 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11176 | 0 | goto exit; |
11177 | 0 | } |
11178 | 0 | if (!--noptargs) { |
11179 | 0 | goto skip_optional_pos; |
11180 | 0 | } |
11181 | 0 | } |
11182 | 0 | skip_optional_pos: |
11183 | 0 | if (!noptargs) { |
11184 | 0 | goto skip_optional_kwonly; |
11185 | 0 | } |
11186 | 0 | follow_symlinks = PyObject_IsTrue(args[4]); |
11187 | 0 | if (follow_symlinks < 0) { |
11188 | 0 | goto exit; |
11189 | 0 | } |
11190 | 0 | skip_optional_kwonly: |
11191 | 0 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
11192 | |
|
11193 | 0 | exit: |
11194 | | /* Cleanup for path */ |
11195 | 0 | path_cleanup(&path); |
11196 | | /* Cleanup for attribute */ |
11197 | 0 | path_cleanup(&attribute); |
11198 | | /* Cleanup for value */ |
11199 | 0 | if (value.obj) { |
11200 | 0 | PyBuffer_Release(&value); |
11201 | 0 | } |
11202 | |
|
11203 | 0 | return return_value; |
11204 | 0 | } |
11205 | | |
11206 | | #endif /* defined(USE_XATTRS) */ |
11207 | | |
11208 | | #if defined(USE_XATTRS) |
11209 | | |
11210 | | PyDoc_STRVAR(os_removexattr__doc__, |
11211 | | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
11212 | | "--\n" |
11213 | | "\n" |
11214 | | "Remove extended attribute attribute on path.\n" |
11215 | | "\n" |
11216 | | "path may be either a string, a path-like object, or an open file descriptor.\n" |
11217 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11218 | | " link, removexattr will modify the symbolic link itself instead of the file\n" |
11219 | | " the link points to."); |
11220 | | |
11221 | | #define OS_REMOVEXATTR_METHODDEF \ |
11222 | | {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
11223 | | |
11224 | | static PyObject * |
11225 | | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
11226 | | int follow_symlinks); |
11227 | | |
11228 | | static PyObject * |
11229 | | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11230 | 0 | { |
11231 | 0 | PyObject *return_value = NULL; |
11232 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11233 | |
|
11234 | 0 | #define NUM_KEYWORDS 3 |
11235 | 0 | static struct { |
11236 | 0 | PyGC_Head _this_is_not_used; |
11237 | 0 | PyObject_VAR_HEAD |
11238 | 0 | Py_hash_t ob_hash; |
11239 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11240 | 0 | } _kwtuple = { |
11241 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11242 | 0 | .ob_hash = -1, |
11243 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), }, |
11244 | 0 | }; |
11245 | 0 | #undef NUM_KEYWORDS |
11246 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11247 | |
|
11248 | | #else // !Py_BUILD_CORE |
11249 | | # define KWTUPLE NULL |
11250 | | #endif // !Py_BUILD_CORE |
11251 | |
|
11252 | 0 | static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL}; |
11253 | 0 | static _PyArg_Parser _parser = { |
11254 | 0 | .keywords = _keywords, |
11255 | 0 | .fname = "removexattr", |
11256 | 0 | .kwtuple = KWTUPLE, |
11257 | 0 | }; |
11258 | 0 | #undef KWTUPLE |
11259 | 0 | PyObject *argsbuf[3]; |
11260 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
11261 | 0 | path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1); |
11262 | 0 | path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0); |
11263 | 0 | int follow_symlinks = 1; |
11264 | |
|
11265 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11266 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11267 | 0 | if (!args) { |
11268 | 0 | goto exit; |
11269 | 0 | } |
11270 | 0 | if (!path_converter(args[0], &path)) { |
11271 | 0 | goto exit; |
11272 | 0 | } |
11273 | 0 | if (!path_converter(args[1], &attribute)) { |
11274 | 0 | goto exit; |
11275 | 0 | } |
11276 | 0 | if (!noptargs) { |
11277 | 0 | goto skip_optional_kwonly; |
11278 | 0 | } |
11279 | 0 | follow_symlinks = PyObject_IsTrue(args[2]); |
11280 | 0 | if (follow_symlinks < 0) { |
11281 | 0 | goto exit; |
11282 | 0 | } |
11283 | 0 | skip_optional_kwonly: |
11284 | 0 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
11285 | |
|
11286 | 0 | exit: |
11287 | | /* Cleanup for path */ |
11288 | 0 | path_cleanup(&path); |
11289 | | /* Cleanup for attribute */ |
11290 | 0 | path_cleanup(&attribute); |
11291 | |
|
11292 | 0 | return return_value; |
11293 | 0 | } |
11294 | | |
11295 | | #endif /* defined(USE_XATTRS) */ |
11296 | | |
11297 | | #if defined(USE_XATTRS) |
11298 | | |
11299 | | PyDoc_STRVAR(os_listxattr__doc__, |
11300 | | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
11301 | | "--\n" |
11302 | | "\n" |
11303 | | "Return a list of extended attributes on path.\n" |
11304 | | "\n" |
11305 | | "path may be either None, a string, a path-like object, or an open file descriptor.\n" |
11306 | | "if path is None, listxattr will examine the current directory.\n" |
11307 | | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
11308 | | " link, listxattr will examine the symbolic link itself instead of the file\n" |
11309 | | " the link points to."); |
11310 | | |
11311 | | #define OS_LISTXATTR_METHODDEF \ |
11312 | | {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
11313 | | |
11314 | | static PyObject * |
11315 | | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
11316 | | |
11317 | | static PyObject * |
11318 | | os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11319 | 0 | { |
11320 | 0 | PyObject *return_value = NULL; |
11321 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11322 | |
|
11323 | 0 | #define NUM_KEYWORDS 2 |
11324 | 0 | static struct { |
11325 | 0 | PyGC_Head _this_is_not_used; |
11326 | 0 | PyObject_VAR_HEAD |
11327 | 0 | Py_hash_t ob_hash; |
11328 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11329 | 0 | } _kwtuple = { |
11330 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11331 | 0 | .ob_hash = -1, |
11332 | 0 | .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), }, |
11333 | 0 | }; |
11334 | 0 | #undef NUM_KEYWORDS |
11335 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11336 | |
|
11337 | | #else // !Py_BUILD_CORE |
11338 | | # define KWTUPLE NULL |
11339 | | #endif // !Py_BUILD_CORE |
11340 | |
|
11341 | 0 | static const char * const _keywords[] = {"path", "follow_symlinks", NULL}; |
11342 | 0 | static _PyArg_Parser _parser = { |
11343 | 0 | .keywords = _keywords, |
11344 | 0 | .fname = "listxattr", |
11345 | 0 | .kwtuple = KWTUPLE, |
11346 | 0 | }; |
11347 | 0 | #undef KWTUPLE |
11348 | 0 | PyObject *argsbuf[2]; |
11349 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
11350 | 0 | path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1); |
11351 | 0 | int follow_symlinks = 1; |
11352 | |
|
11353 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11354 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11355 | 0 | if (!args) { |
11356 | 0 | goto exit; |
11357 | 0 | } |
11358 | 0 | if (!noptargs) { |
11359 | 0 | goto skip_optional_pos; |
11360 | 0 | } |
11361 | 0 | if (args[0]) { |
11362 | 0 | if (!path_converter(args[0], &path)) { |
11363 | 0 | goto exit; |
11364 | 0 | } |
11365 | 0 | if (!--noptargs) { |
11366 | 0 | goto skip_optional_pos; |
11367 | 0 | } |
11368 | 0 | } |
11369 | 0 | skip_optional_pos: |
11370 | 0 | if (!noptargs) { |
11371 | 0 | goto skip_optional_kwonly; |
11372 | 0 | } |
11373 | 0 | follow_symlinks = PyObject_IsTrue(args[1]); |
11374 | 0 | if (follow_symlinks < 0) { |
11375 | 0 | goto exit; |
11376 | 0 | } |
11377 | 0 | skip_optional_kwonly: |
11378 | 0 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
11379 | |
|
11380 | 0 | exit: |
11381 | | /* Cleanup for path */ |
11382 | 0 | path_cleanup(&path); |
11383 | |
|
11384 | 0 | return return_value; |
11385 | 0 | } |
11386 | | |
11387 | | #endif /* defined(USE_XATTRS) */ |
11388 | | |
11389 | | PyDoc_STRVAR(os_urandom__doc__, |
11390 | | "urandom($module, size, /)\n" |
11391 | | "--\n" |
11392 | | "\n" |
11393 | | "Return a bytes object containing random bytes suitable for cryptographic use."); |
11394 | | |
11395 | | #define OS_URANDOM_METHODDEF \ |
11396 | | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
11397 | | |
11398 | | static PyObject * |
11399 | | os_urandom_impl(PyObject *module, Py_ssize_t size); |
11400 | | |
11401 | | static PyObject * |
11402 | | os_urandom(PyObject *module, PyObject *arg) |
11403 | 0 | { |
11404 | 0 | PyObject *return_value = NULL; |
11405 | 0 | Py_ssize_t size; |
11406 | |
|
11407 | 0 | { |
11408 | 0 | Py_ssize_t ival = -1; |
11409 | 0 | PyObject *iobj = _PyNumber_Index(arg); |
11410 | 0 | if (iobj != NULL) { |
11411 | 0 | ival = PyLong_AsSsize_t(iobj); |
11412 | 0 | Py_DECREF(iobj); |
11413 | 0 | } |
11414 | 0 | if (ival == -1 && PyErr_Occurred()) { |
11415 | 0 | goto exit; |
11416 | 0 | } |
11417 | 0 | size = ival; |
11418 | 0 | if (size < 0) { |
11419 | 0 | PyErr_SetString(PyExc_ValueError, |
11420 | 0 | "size cannot be negative"); |
11421 | 0 | goto exit; |
11422 | 0 | } |
11423 | 0 | } |
11424 | 0 | return_value = os_urandom_impl(module, size); |
11425 | |
|
11426 | 0 | exit: |
11427 | 0 | return return_value; |
11428 | 0 | } |
11429 | | |
11430 | | #if defined(HAVE_MEMFD_CREATE) |
11431 | | |
11432 | | PyDoc_STRVAR(os_memfd_create__doc__, |
11433 | | "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n" |
11434 | | "--\n" |
11435 | | "\n"); |
11436 | | |
11437 | | #define OS_MEMFD_CREATE_METHODDEF \ |
11438 | | {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__}, |
11439 | | |
11440 | | static PyObject * |
11441 | | os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags); |
11442 | | |
11443 | | static PyObject * |
11444 | | os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11445 | 0 | { |
11446 | 0 | PyObject *return_value = NULL; |
11447 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11448 | |
|
11449 | 0 | #define NUM_KEYWORDS 2 |
11450 | 0 | static struct { |
11451 | 0 | PyGC_Head _this_is_not_used; |
11452 | 0 | PyObject_VAR_HEAD |
11453 | 0 | Py_hash_t ob_hash; |
11454 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11455 | 0 | } _kwtuple = { |
11456 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11457 | 0 | .ob_hash = -1, |
11458 | 0 | .ob_item = { &_Py_ID(name), &_Py_ID(flags), }, |
11459 | 0 | }; |
11460 | 0 | #undef NUM_KEYWORDS |
11461 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11462 | |
|
11463 | | #else // !Py_BUILD_CORE |
11464 | | # define KWTUPLE NULL |
11465 | | #endif // !Py_BUILD_CORE |
11466 | |
|
11467 | 0 | static const char * const _keywords[] = {"name", "flags", NULL}; |
11468 | 0 | static _PyArg_Parser _parser = { |
11469 | 0 | .keywords = _keywords, |
11470 | 0 | .fname = "memfd_create", |
11471 | 0 | .kwtuple = KWTUPLE, |
11472 | 0 | }; |
11473 | 0 | #undef KWTUPLE |
11474 | 0 | PyObject *argsbuf[2]; |
11475 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11476 | 0 | PyObject *name = NULL; |
11477 | 0 | unsigned int flags = MFD_CLOEXEC; |
11478 | |
|
11479 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11480 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11481 | 0 | if (!args) { |
11482 | 0 | goto exit; |
11483 | 0 | } |
11484 | 0 | if (!PyUnicode_FSConverter(args[0], &name)) { |
11485 | 0 | goto exit; |
11486 | 0 | } |
11487 | 0 | if (!noptargs) { |
11488 | 0 | goto skip_optional_pos; |
11489 | 0 | } |
11490 | 0 | { |
11491 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[1], &flags, sizeof(unsigned int), |
11492 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
11493 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
11494 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
11495 | 0 | if (_bytes < 0) { |
11496 | 0 | goto exit; |
11497 | 0 | } |
11498 | 0 | if ((size_t)_bytes > sizeof(unsigned int)) { |
11499 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
11500 | 0 | "integer value out of range", 1) < 0) |
11501 | 0 | { |
11502 | 0 | goto exit; |
11503 | 0 | } |
11504 | 0 | } |
11505 | 0 | } |
11506 | 0 | skip_optional_pos: |
11507 | 0 | return_value = os_memfd_create_impl(module, name, flags); |
11508 | |
|
11509 | 0 | exit: |
11510 | | /* Cleanup for name */ |
11511 | 0 | Py_XDECREF(name); |
11512 | |
|
11513 | 0 | return return_value; |
11514 | 0 | } |
11515 | | |
11516 | | #endif /* defined(HAVE_MEMFD_CREATE) */ |
11517 | | |
11518 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11519 | | |
11520 | | PyDoc_STRVAR(os_eventfd__doc__, |
11521 | | "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n" |
11522 | | "--\n" |
11523 | | "\n" |
11524 | | "Creates and returns an event notification file descriptor."); |
11525 | | |
11526 | | #define OS_EVENTFD_METHODDEF \ |
11527 | | {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__}, |
11528 | | |
11529 | | static PyObject * |
11530 | | os_eventfd_impl(PyObject *module, unsigned int initval, int flags); |
11531 | | |
11532 | | static PyObject * |
11533 | | os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11534 | 0 | { |
11535 | 0 | PyObject *return_value = NULL; |
11536 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11537 | |
|
11538 | 0 | #define NUM_KEYWORDS 2 |
11539 | 0 | static struct { |
11540 | 0 | PyGC_Head _this_is_not_used; |
11541 | 0 | PyObject_VAR_HEAD |
11542 | 0 | Py_hash_t ob_hash; |
11543 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11544 | 0 | } _kwtuple = { |
11545 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11546 | 0 | .ob_hash = -1, |
11547 | 0 | .ob_item = { &_Py_ID(initval), &_Py_ID(flags), }, |
11548 | 0 | }; |
11549 | 0 | #undef NUM_KEYWORDS |
11550 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11551 | |
|
11552 | | #else // !Py_BUILD_CORE |
11553 | | # define KWTUPLE NULL |
11554 | | #endif // !Py_BUILD_CORE |
11555 | |
|
11556 | 0 | static const char * const _keywords[] = {"initval", "flags", NULL}; |
11557 | 0 | static _PyArg_Parser _parser = { |
11558 | 0 | .keywords = _keywords, |
11559 | 0 | .fname = "eventfd", |
11560 | 0 | .kwtuple = KWTUPLE, |
11561 | 0 | }; |
11562 | 0 | #undef KWTUPLE |
11563 | 0 | PyObject *argsbuf[2]; |
11564 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
11565 | 0 | unsigned int initval; |
11566 | 0 | int flags = EFD_CLOEXEC; |
11567 | |
|
11568 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11569 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11570 | 0 | if (!args) { |
11571 | 0 | goto exit; |
11572 | 0 | } |
11573 | 0 | if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) { |
11574 | 0 | goto exit; |
11575 | 0 | } |
11576 | 0 | if (!noptargs) { |
11577 | 0 | goto skip_optional_pos; |
11578 | 0 | } |
11579 | 0 | flags = PyLong_AsInt(args[1]); |
11580 | 0 | if (flags == -1 && PyErr_Occurred()) { |
11581 | 0 | goto exit; |
11582 | 0 | } |
11583 | 0 | skip_optional_pos: |
11584 | 0 | return_value = os_eventfd_impl(module, initval, flags); |
11585 | |
|
11586 | 0 | exit: |
11587 | 0 | return return_value; |
11588 | 0 | } |
11589 | | |
11590 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11591 | | |
11592 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11593 | | |
11594 | | PyDoc_STRVAR(os_eventfd_read__doc__, |
11595 | | "eventfd_read($module, /, fd)\n" |
11596 | | "--\n" |
11597 | | "\n" |
11598 | | "Read eventfd value"); |
11599 | | |
11600 | | #define OS_EVENTFD_READ_METHODDEF \ |
11601 | | {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__}, |
11602 | | |
11603 | | static PyObject * |
11604 | | os_eventfd_read_impl(PyObject *module, int fd); |
11605 | | |
11606 | | static PyObject * |
11607 | | os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11608 | 0 | { |
11609 | 0 | PyObject *return_value = NULL; |
11610 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11611 | |
|
11612 | 0 | #define NUM_KEYWORDS 1 |
11613 | 0 | static struct { |
11614 | 0 | PyGC_Head _this_is_not_used; |
11615 | 0 | PyObject_VAR_HEAD |
11616 | 0 | Py_hash_t ob_hash; |
11617 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11618 | 0 | } _kwtuple = { |
11619 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11620 | 0 | .ob_hash = -1, |
11621 | 0 | .ob_item = { &_Py_ID(fd), }, |
11622 | 0 | }; |
11623 | 0 | #undef NUM_KEYWORDS |
11624 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11625 | |
|
11626 | | #else // !Py_BUILD_CORE |
11627 | | # define KWTUPLE NULL |
11628 | | #endif // !Py_BUILD_CORE |
11629 | |
|
11630 | 0 | static const char * const _keywords[] = {"fd", NULL}; |
11631 | 0 | static _PyArg_Parser _parser = { |
11632 | 0 | .keywords = _keywords, |
11633 | 0 | .fname = "eventfd_read", |
11634 | 0 | .kwtuple = KWTUPLE, |
11635 | 0 | }; |
11636 | 0 | #undef KWTUPLE |
11637 | 0 | PyObject *argsbuf[1]; |
11638 | 0 | int fd; |
11639 | |
|
11640 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11641 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11642 | 0 | if (!args) { |
11643 | 0 | goto exit; |
11644 | 0 | } |
11645 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11646 | 0 | if (fd < 0) { |
11647 | 0 | goto exit; |
11648 | 0 | } |
11649 | 0 | return_value = os_eventfd_read_impl(module, fd); |
11650 | |
|
11651 | 0 | exit: |
11652 | 0 | return return_value; |
11653 | 0 | } |
11654 | | |
11655 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11656 | | |
11657 | | #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) |
11658 | | |
11659 | | PyDoc_STRVAR(os_eventfd_write__doc__, |
11660 | | "eventfd_write($module, /, fd, value)\n" |
11661 | | "--\n" |
11662 | | "\n" |
11663 | | "Write eventfd value."); |
11664 | | |
11665 | | #define OS_EVENTFD_WRITE_METHODDEF \ |
11666 | | {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__}, |
11667 | | |
11668 | | static PyObject * |
11669 | | os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value); |
11670 | | |
11671 | | static PyObject * |
11672 | | os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
11673 | 0 | { |
11674 | 0 | PyObject *return_value = NULL; |
11675 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
11676 | |
|
11677 | 0 | #define NUM_KEYWORDS 2 |
11678 | 0 | static struct { |
11679 | 0 | PyGC_Head _this_is_not_used; |
11680 | 0 | PyObject_VAR_HEAD |
11681 | 0 | Py_hash_t ob_hash; |
11682 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
11683 | 0 | } _kwtuple = { |
11684 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
11685 | 0 | .ob_hash = -1, |
11686 | 0 | .ob_item = { &_Py_ID(fd), &_Py_ID(value), }, |
11687 | 0 | }; |
11688 | 0 | #undef NUM_KEYWORDS |
11689 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
11690 | |
|
11691 | | #else // !Py_BUILD_CORE |
11692 | | # define KWTUPLE NULL |
11693 | | #endif // !Py_BUILD_CORE |
11694 | |
|
11695 | 0 | static const char * const _keywords[] = {"fd", "value", NULL}; |
11696 | 0 | static _PyArg_Parser _parser = { |
11697 | 0 | .keywords = _keywords, |
11698 | 0 | .fname = "eventfd_write", |
11699 | 0 | .kwtuple = KWTUPLE, |
11700 | 0 | }; |
11701 | 0 | #undef KWTUPLE |
11702 | 0 | PyObject *argsbuf[2]; |
11703 | 0 | int fd; |
11704 | 0 | unsigned long long value; |
11705 | |
|
11706 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
11707 | 0 | /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
11708 | 0 | if (!args) { |
11709 | 0 | goto exit; |
11710 | 0 | } |
11711 | 0 | fd = PyObject_AsFileDescriptor(args[0]); |
11712 | 0 | if (fd < 0) { |
11713 | 0 | goto exit; |
11714 | 0 | } |
11715 | 0 | if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) { |
11716 | 0 | goto exit; |
11717 | 0 | } |
11718 | 0 | return_value = os_eventfd_write_impl(module, fd, value); |
11719 | |
|
11720 | 0 | exit: |
11721 | 0 | return return_value; |
11722 | 0 | } |
11723 | | |
11724 | | #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */ |
11725 | | |
11726 | | #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) |
11727 | | |
11728 | | PyDoc_STRVAR(os_get_terminal_size__doc__, |
11729 | | "get_terminal_size($module, fd=<unrepresentable>, /)\n" |
11730 | | "--\n" |
11731 | | "\n" |
11732 | | "Return the size of the terminal window as (columns, lines).\n" |
11733 | | "\n" |
11734 | | "The optional argument fd (default standard output) specifies\n" |
11735 | | "which file descriptor should be queried.\n" |
11736 | | "\n" |
11737 | | "If the file descriptor is not connected to a terminal, an OSError\n" |
11738 | | "is thrown.\n" |
11739 | | "\n" |
11740 | | "This function will only be defined if an implementation is\n" |
11741 | | "available for this system.\n" |
11742 | | "\n" |
11743 | | "shutil.get_terminal_size is the high-level function which should\n" |
11744 | | "normally be used, os.get_terminal_size is the low-level implementation."); |
11745 | | |
11746 | | #define OS_GET_TERMINAL_SIZE_METHODDEF \ |
11747 | | {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__}, |
11748 | | |
11749 | | static PyObject * |
11750 | | os_get_terminal_size_impl(PyObject *module, int fd); |
11751 | | |
11752 | | static PyObject * |
11753 | | os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11754 | 0 | { |
11755 | 0 | PyObject *return_value = NULL; |
11756 | 0 | int fd = fileno(stdout); |
11757 | |
|
11758 | 0 | if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) { |
11759 | 0 | goto exit; |
11760 | 0 | } |
11761 | 0 | if (nargs < 1) { |
11762 | 0 | goto skip_optional; |
11763 | 0 | } |
11764 | 0 | fd = PyLong_AsInt(args[0]); |
11765 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11766 | 0 | goto exit; |
11767 | 0 | } |
11768 | 0 | skip_optional: |
11769 | 0 | return_value = os_get_terminal_size_impl(module, fd); |
11770 | |
|
11771 | 0 | exit: |
11772 | 0 | return return_value; |
11773 | 0 | } |
11774 | | |
11775 | | #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */ |
11776 | | |
11777 | | PyDoc_STRVAR(os_cpu_count__doc__, |
11778 | | "cpu_count($module, /)\n" |
11779 | | "--\n" |
11780 | | "\n" |
11781 | | "Return the number of logical CPUs in the system.\n" |
11782 | | "\n" |
11783 | | "Return None if indeterminable."); |
11784 | | |
11785 | | #define OS_CPU_COUNT_METHODDEF \ |
11786 | | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
11787 | | |
11788 | | static PyObject * |
11789 | | os_cpu_count_impl(PyObject *module); |
11790 | | |
11791 | | static PyObject * |
11792 | | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
11793 | 0 | { |
11794 | 0 | return os_cpu_count_impl(module); |
11795 | 0 | } |
11796 | | |
11797 | | PyDoc_STRVAR(os_get_inheritable__doc__, |
11798 | | "get_inheritable($module, fd, /)\n" |
11799 | | "--\n" |
11800 | | "\n" |
11801 | | "Get the close-on-exe flag of the specified file descriptor."); |
11802 | | |
11803 | | #define OS_GET_INHERITABLE_METHODDEF \ |
11804 | | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
11805 | | |
11806 | | static int |
11807 | | os_get_inheritable_impl(PyObject *module, int fd); |
11808 | | |
11809 | | static PyObject * |
11810 | | os_get_inheritable(PyObject *module, PyObject *arg) |
11811 | 0 | { |
11812 | 0 | PyObject *return_value = NULL; |
11813 | 0 | int fd; |
11814 | 0 | int _return_value; |
11815 | |
|
11816 | 0 | fd = PyLong_AsInt(arg); |
11817 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11818 | 0 | goto exit; |
11819 | 0 | } |
11820 | 0 | _return_value = os_get_inheritable_impl(module, fd); |
11821 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11822 | 0 | goto exit; |
11823 | 0 | } |
11824 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11825 | |
|
11826 | 0 | exit: |
11827 | 0 | return return_value; |
11828 | 0 | } |
11829 | | |
11830 | | PyDoc_STRVAR(os_set_inheritable__doc__, |
11831 | | "set_inheritable($module, fd, inheritable, /)\n" |
11832 | | "--\n" |
11833 | | "\n" |
11834 | | "Set the inheritable flag of the specified file descriptor."); |
11835 | | |
11836 | | #define OS_SET_INHERITABLE_METHODDEF \ |
11837 | | {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__}, |
11838 | | |
11839 | | static PyObject * |
11840 | | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
11841 | | |
11842 | | static PyObject * |
11843 | | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11844 | 0 | { |
11845 | 0 | PyObject *return_value = NULL; |
11846 | 0 | int fd; |
11847 | 0 | int inheritable; |
11848 | |
|
11849 | 0 | if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { |
11850 | 0 | goto exit; |
11851 | 0 | } |
11852 | 0 | fd = PyLong_AsInt(args[0]); |
11853 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11854 | 0 | goto exit; |
11855 | 0 | } |
11856 | 0 | inheritable = PyLong_AsInt(args[1]); |
11857 | 0 | if (inheritable == -1 && PyErr_Occurred()) { |
11858 | 0 | goto exit; |
11859 | 0 | } |
11860 | 0 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
11861 | |
|
11862 | 0 | exit: |
11863 | 0 | return return_value; |
11864 | 0 | } |
11865 | | |
11866 | | #if defined(MS_WINDOWS) |
11867 | | |
11868 | | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
11869 | | "get_handle_inheritable($module, handle, /)\n" |
11870 | | "--\n" |
11871 | | "\n" |
11872 | | "Get the close-on-exe flag of the specified file descriptor."); |
11873 | | |
11874 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
11875 | | {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__}, |
11876 | | |
11877 | | static int |
11878 | | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
11879 | | |
11880 | | static PyObject * |
11881 | | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
11882 | | { |
11883 | | PyObject *return_value = NULL; |
11884 | | intptr_t handle; |
11885 | | int _return_value; |
11886 | | |
11887 | | handle = (intptr_t)PyLong_AsVoidPtr(arg); |
11888 | | if (!handle && PyErr_Occurred()) { |
11889 | | goto exit; |
11890 | | } |
11891 | | _return_value = os_get_handle_inheritable_impl(module, handle); |
11892 | | if ((_return_value == -1) && PyErr_Occurred()) { |
11893 | | goto exit; |
11894 | | } |
11895 | | return_value = PyBool_FromLong((long)_return_value); |
11896 | | |
11897 | | exit: |
11898 | | return return_value; |
11899 | | } |
11900 | | |
11901 | | #endif /* defined(MS_WINDOWS) */ |
11902 | | |
11903 | | #if defined(MS_WINDOWS) |
11904 | | |
11905 | | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
11906 | | "set_handle_inheritable($module, handle, inheritable, /)\n" |
11907 | | "--\n" |
11908 | | "\n" |
11909 | | "Set the inheritable flag of the specified handle."); |
11910 | | |
11911 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
11912 | | {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__}, |
11913 | | |
11914 | | static PyObject * |
11915 | | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
11916 | | int inheritable); |
11917 | | |
11918 | | static PyObject * |
11919 | | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11920 | | { |
11921 | | PyObject *return_value = NULL; |
11922 | | intptr_t handle; |
11923 | | int inheritable; |
11924 | | |
11925 | | if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) { |
11926 | | goto exit; |
11927 | | } |
11928 | | handle = (intptr_t)PyLong_AsVoidPtr(args[0]); |
11929 | | if (!handle && PyErr_Occurred()) { |
11930 | | goto exit; |
11931 | | } |
11932 | | inheritable = PyObject_IsTrue(args[1]); |
11933 | | if (inheritable < 0) { |
11934 | | goto exit; |
11935 | | } |
11936 | | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
11937 | | |
11938 | | exit: |
11939 | | return return_value; |
11940 | | } |
11941 | | |
11942 | | #endif /* defined(MS_WINDOWS) */ |
11943 | | |
11944 | | PyDoc_STRVAR(os_get_blocking__doc__, |
11945 | | "get_blocking($module, fd, /)\n" |
11946 | | "--\n" |
11947 | | "\n" |
11948 | | "Get the blocking mode of the file descriptor.\n" |
11949 | | "\n" |
11950 | | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared."); |
11951 | | |
11952 | | #define OS_GET_BLOCKING_METHODDEF \ |
11953 | | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
11954 | | |
11955 | | static int |
11956 | | os_get_blocking_impl(PyObject *module, int fd); |
11957 | | |
11958 | | static PyObject * |
11959 | | os_get_blocking(PyObject *module, PyObject *arg) |
11960 | 0 | { |
11961 | 0 | PyObject *return_value = NULL; |
11962 | 0 | int fd; |
11963 | 0 | int _return_value; |
11964 | |
|
11965 | 0 | fd = PyLong_AsInt(arg); |
11966 | 0 | if (fd == -1 && PyErr_Occurred()) { |
11967 | 0 | goto exit; |
11968 | 0 | } |
11969 | 0 | _return_value = os_get_blocking_impl(module, fd); |
11970 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
11971 | 0 | goto exit; |
11972 | 0 | } |
11973 | 0 | return_value = PyBool_FromLong((long)_return_value); |
11974 | |
|
11975 | 0 | exit: |
11976 | 0 | return return_value; |
11977 | 0 | } |
11978 | | |
11979 | | PyDoc_STRVAR(os_set_blocking__doc__, |
11980 | | "set_blocking($module, fd, blocking, /)\n" |
11981 | | "--\n" |
11982 | | "\n" |
11983 | | "Set the blocking mode of the specified file descriptor.\n" |
11984 | | "\n" |
11985 | | "Set the O_NONBLOCK flag if blocking is False,\n" |
11986 | | "clear the O_NONBLOCK flag otherwise."); |
11987 | | |
11988 | | #define OS_SET_BLOCKING_METHODDEF \ |
11989 | | {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__}, |
11990 | | |
11991 | | static PyObject * |
11992 | | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
11993 | | |
11994 | | static PyObject * |
11995 | | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
11996 | 0 | { |
11997 | 0 | PyObject *return_value = NULL; |
11998 | 0 | int fd; |
11999 | 0 | int blocking; |
12000 | |
|
12001 | 0 | if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { |
12002 | 0 | goto exit; |
12003 | 0 | } |
12004 | 0 | fd = PyLong_AsInt(args[0]); |
12005 | 0 | if (fd == -1 && PyErr_Occurred()) { |
12006 | 0 | goto exit; |
12007 | 0 | } |
12008 | 0 | blocking = PyObject_IsTrue(args[1]); |
12009 | 0 | if (blocking < 0) { |
12010 | 0 | goto exit; |
12011 | 0 | } |
12012 | 0 | return_value = os_set_blocking_impl(module, fd, blocking); |
12013 | |
|
12014 | 0 | exit: |
12015 | 0 | return return_value; |
12016 | 0 | } |
12017 | | |
12018 | | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
12019 | | "is_symlink($self, /)\n" |
12020 | | "--\n" |
12021 | | "\n" |
12022 | | "Return True if the entry is a symbolic link; cached per entry."); |
12023 | | |
12024 | | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
12025 | | {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__}, |
12026 | | |
12027 | | static int |
12028 | | os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class); |
12029 | | |
12030 | | static PyObject * |
12031 | | os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12032 | 0 | { |
12033 | 0 | PyObject *return_value = NULL; |
12034 | 0 | int _return_value; |
12035 | |
|
12036 | 0 | if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
12037 | 0 | PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); |
12038 | 0 | goto exit; |
12039 | 0 | } |
12040 | 0 | _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class); |
12041 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12042 | 0 | goto exit; |
12043 | 0 | } |
12044 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12045 | |
|
12046 | 0 | exit: |
12047 | 0 | return return_value; |
12048 | 0 | } |
12049 | | |
12050 | | PyDoc_STRVAR(os_DirEntry_is_junction__doc__, |
12051 | | "is_junction($self, /)\n" |
12052 | | "--\n" |
12053 | | "\n" |
12054 | | "Return True if the entry is a junction; cached per entry."); |
12055 | | |
12056 | | #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \ |
12057 | | {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__}, |
12058 | | |
12059 | | static int |
12060 | | os_DirEntry_is_junction_impl(DirEntry *self); |
12061 | | |
12062 | | static PyObject * |
12063 | | os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12064 | 0 | { |
12065 | 0 | PyObject *return_value = NULL; |
12066 | 0 | int _return_value; |
12067 | |
|
12068 | 0 | _return_value = os_DirEntry_is_junction_impl((DirEntry *)self); |
12069 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12070 | 0 | goto exit; |
12071 | 0 | } |
12072 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12073 | |
|
12074 | 0 | exit: |
12075 | 0 | return return_value; |
12076 | 0 | } |
12077 | | |
12078 | | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
12079 | | "stat($self, /, *, follow_symlinks=True)\n" |
12080 | | "--\n" |
12081 | | "\n" |
12082 | | "Return stat_result object for the entry; cached per entry."); |
12083 | | |
12084 | | #define OS_DIRENTRY_STAT_METHODDEF \ |
12085 | | {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
12086 | | |
12087 | | static PyObject * |
12088 | | os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class, |
12089 | | int follow_symlinks); |
12090 | | |
12091 | | static PyObject * |
12092 | | os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12093 | 0 | { |
12094 | 0 | PyObject *return_value = NULL; |
12095 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12096 | |
|
12097 | 0 | #define NUM_KEYWORDS 1 |
12098 | 0 | static struct { |
12099 | 0 | PyGC_Head _this_is_not_used; |
12100 | 0 | PyObject_VAR_HEAD |
12101 | 0 | Py_hash_t ob_hash; |
12102 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12103 | 0 | } _kwtuple = { |
12104 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12105 | 0 | .ob_hash = -1, |
12106 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12107 | 0 | }; |
12108 | 0 | #undef NUM_KEYWORDS |
12109 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12110 | |
|
12111 | | #else // !Py_BUILD_CORE |
12112 | | # define KWTUPLE NULL |
12113 | | #endif // !Py_BUILD_CORE |
12114 | |
|
12115 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12116 | 0 | static _PyArg_Parser _parser = { |
12117 | 0 | .keywords = _keywords, |
12118 | 0 | .fname = "stat", |
12119 | 0 | .kwtuple = KWTUPLE, |
12120 | 0 | }; |
12121 | 0 | #undef KWTUPLE |
12122 | 0 | PyObject *argsbuf[1]; |
12123 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12124 | 0 | int follow_symlinks = 1; |
12125 | |
|
12126 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12127 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12128 | 0 | if (!args) { |
12129 | 0 | goto exit; |
12130 | 0 | } |
12131 | 0 | if (!noptargs) { |
12132 | 0 | goto skip_optional_kwonly; |
12133 | 0 | } |
12134 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12135 | 0 | if (follow_symlinks < 0) { |
12136 | 0 | goto exit; |
12137 | 0 | } |
12138 | 0 | skip_optional_kwonly: |
12139 | 0 | return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks); |
12140 | |
|
12141 | 0 | exit: |
12142 | 0 | return return_value; |
12143 | 0 | } |
12144 | | |
12145 | | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
12146 | | "is_dir($self, /, *, follow_symlinks=True)\n" |
12147 | | "--\n" |
12148 | | "\n" |
12149 | | "Return True if the entry is a directory; cached per entry."); |
12150 | | |
12151 | | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
12152 | | {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
12153 | | |
12154 | | static int |
12155 | | os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class, |
12156 | | int follow_symlinks); |
12157 | | |
12158 | | static PyObject * |
12159 | | os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12160 | 0 | { |
12161 | 0 | PyObject *return_value = NULL; |
12162 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12163 | |
|
12164 | 0 | #define NUM_KEYWORDS 1 |
12165 | 0 | static struct { |
12166 | 0 | PyGC_Head _this_is_not_used; |
12167 | 0 | PyObject_VAR_HEAD |
12168 | 0 | Py_hash_t ob_hash; |
12169 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12170 | 0 | } _kwtuple = { |
12171 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12172 | 0 | .ob_hash = -1, |
12173 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12174 | 0 | }; |
12175 | 0 | #undef NUM_KEYWORDS |
12176 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12177 | |
|
12178 | | #else // !Py_BUILD_CORE |
12179 | | # define KWTUPLE NULL |
12180 | | #endif // !Py_BUILD_CORE |
12181 | |
|
12182 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12183 | 0 | static _PyArg_Parser _parser = { |
12184 | 0 | .keywords = _keywords, |
12185 | 0 | .fname = "is_dir", |
12186 | 0 | .kwtuple = KWTUPLE, |
12187 | 0 | }; |
12188 | 0 | #undef KWTUPLE |
12189 | 0 | PyObject *argsbuf[1]; |
12190 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12191 | 0 | int follow_symlinks = 1; |
12192 | 0 | int _return_value; |
12193 | |
|
12194 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12195 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12196 | 0 | if (!args) { |
12197 | 0 | goto exit; |
12198 | 0 | } |
12199 | 0 | if (!noptargs) { |
12200 | 0 | goto skip_optional_kwonly; |
12201 | 0 | } |
12202 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12203 | 0 | if (follow_symlinks < 0) { |
12204 | 0 | goto exit; |
12205 | 0 | } |
12206 | 0 | skip_optional_kwonly: |
12207 | 0 | _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks); |
12208 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12209 | 0 | goto exit; |
12210 | 0 | } |
12211 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12212 | |
|
12213 | 0 | exit: |
12214 | 0 | return return_value; |
12215 | 0 | } |
12216 | | |
12217 | | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
12218 | | "is_file($self, /, *, follow_symlinks=True)\n" |
12219 | | "--\n" |
12220 | | "\n" |
12221 | | "Return True if the entry is a file; cached per entry."); |
12222 | | |
12223 | | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
12224 | | {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
12225 | | |
12226 | | static int |
12227 | | os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class, |
12228 | | int follow_symlinks); |
12229 | | |
12230 | | static PyObject * |
12231 | | os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12232 | 0 | { |
12233 | 0 | PyObject *return_value = NULL; |
12234 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12235 | |
|
12236 | 0 | #define NUM_KEYWORDS 1 |
12237 | 0 | static struct { |
12238 | 0 | PyGC_Head _this_is_not_used; |
12239 | 0 | PyObject_VAR_HEAD |
12240 | 0 | Py_hash_t ob_hash; |
12241 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12242 | 0 | } _kwtuple = { |
12243 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12244 | 0 | .ob_hash = -1, |
12245 | 0 | .ob_item = { &_Py_ID(follow_symlinks), }, |
12246 | 0 | }; |
12247 | 0 | #undef NUM_KEYWORDS |
12248 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12249 | |
|
12250 | | #else // !Py_BUILD_CORE |
12251 | | # define KWTUPLE NULL |
12252 | | #endif // !Py_BUILD_CORE |
12253 | |
|
12254 | 0 | static const char * const _keywords[] = {"follow_symlinks", NULL}; |
12255 | 0 | static _PyArg_Parser _parser = { |
12256 | 0 | .keywords = _keywords, |
12257 | 0 | .fname = "is_file", |
12258 | 0 | .kwtuple = KWTUPLE, |
12259 | 0 | }; |
12260 | 0 | #undef KWTUPLE |
12261 | 0 | PyObject *argsbuf[1]; |
12262 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12263 | 0 | int follow_symlinks = 1; |
12264 | 0 | int _return_value; |
12265 | |
|
12266 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12267 | 0 | /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12268 | 0 | if (!args) { |
12269 | 0 | goto exit; |
12270 | 0 | } |
12271 | 0 | if (!noptargs) { |
12272 | 0 | goto skip_optional_kwonly; |
12273 | 0 | } |
12274 | 0 | follow_symlinks = PyObject_IsTrue(args[0]); |
12275 | 0 | if (follow_symlinks < 0) { |
12276 | 0 | goto exit; |
12277 | 0 | } |
12278 | 0 | skip_optional_kwonly: |
12279 | 0 | _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks); |
12280 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
12281 | 0 | goto exit; |
12282 | 0 | } |
12283 | 0 | return_value = PyBool_FromLong((long)_return_value); |
12284 | |
|
12285 | 0 | exit: |
12286 | 0 | return return_value; |
12287 | 0 | } |
12288 | | |
12289 | | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
12290 | | "inode($self, /)\n" |
12291 | | "--\n" |
12292 | | "\n" |
12293 | | "Return inode of the entry; cached per entry."); |
12294 | | |
12295 | | #define OS_DIRENTRY_INODE_METHODDEF \ |
12296 | | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
12297 | | |
12298 | | static PyObject * |
12299 | | os_DirEntry_inode_impl(DirEntry *self); |
12300 | | |
12301 | | static PyObject * |
12302 | | os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12303 | 0 | { |
12304 | 0 | return os_DirEntry_inode_impl((DirEntry *)self); |
12305 | 0 | } |
12306 | | |
12307 | | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
12308 | | "__fspath__($self, /)\n" |
12309 | | "--\n" |
12310 | | "\n" |
12311 | | "Returns the path for the entry."); |
12312 | | |
12313 | | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
12314 | | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
12315 | | |
12316 | | static PyObject * |
12317 | | os_DirEntry___fspath___impl(DirEntry *self); |
12318 | | |
12319 | | static PyObject * |
12320 | | os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
12321 | 0 | { |
12322 | 0 | return os_DirEntry___fspath___impl((DirEntry *)self); |
12323 | 0 | } |
12324 | | |
12325 | | PyDoc_STRVAR(os_scandir__doc__, |
12326 | | "scandir($module, /, path=None)\n" |
12327 | | "--\n" |
12328 | | "\n" |
12329 | | "Return an iterator of DirEntry objects for given path.\n" |
12330 | | "\n" |
12331 | | "path can be specified as either str, bytes, or a path-like object. If path\n" |
12332 | | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
12333 | | "all other circumstances they will be str.\n" |
12334 | | "\n" |
12335 | | "If path is None, uses the path=\'.\'."); |
12336 | | |
12337 | | #define OS_SCANDIR_METHODDEF \ |
12338 | | {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
12339 | | |
12340 | | static PyObject * |
12341 | | os_scandir_impl(PyObject *module, path_t *path); |
12342 | | |
12343 | | static PyObject * |
12344 | | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12345 | 0 | { |
12346 | 0 | PyObject *return_value = NULL; |
12347 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12348 | |
|
12349 | 0 | #define NUM_KEYWORDS 1 |
12350 | 0 | static struct { |
12351 | 0 | PyGC_Head _this_is_not_used; |
12352 | 0 | PyObject_VAR_HEAD |
12353 | 0 | Py_hash_t ob_hash; |
12354 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12355 | 0 | } _kwtuple = { |
12356 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12357 | 0 | .ob_hash = -1, |
12358 | 0 | .ob_item = { &_Py_ID(path), }, |
12359 | 0 | }; |
12360 | 0 | #undef NUM_KEYWORDS |
12361 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12362 | |
|
12363 | | #else // !Py_BUILD_CORE |
12364 | | # define KWTUPLE NULL |
12365 | | #endif // !Py_BUILD_CORE |
12366 | |
|
12367 | 0 | static const char * const _keywords[] = {"path", NULL}; |
12368 | 0 | static _PyArg_Parser _parser = { |
12369 | 0 | .keywords = _keywords, |
12370 | 0 | .fname = "scandir", |
12371 | 0 | .kwtuple = KWTUPLE, |
12372 | 0 | }; |
12373 | 0 | #undef KWTUPLE |
12374 | 0 | PyObject *argsbuf[1]; |
12375 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
12376 | 0 | path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR); |
12377 | |
|
12378 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12379 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12380 | 0 | if (!args) { |
12381 | 0 | goto exit; |
12382 | 0 | } |
12383 | 0 | if (!noptargs) { |
12384 | 0 | goto skip_optional_pos; |
12385 | 0 | } |
12386 | 0 | if (!path_converter(args[0], &path)) { |
12387 | 0 | goto exit; |
12388 | 0 | } |
12389 | 0 | skip_optional_pos: |
12390 | 0 | return_value = os_scandir_impl(module, &path); |
12391 | |
|
12392 | 0 | exit: |
12393 | | /* Cleanup for path */ |
12394 | 0 | path_cleanup(&path); |
12395 | |
|
12396 | 0 | return return_value; |
12397 | 0 | } |
12398 | | |
12399 | | PyDoc_STRVAR(os_fspath__doc__, |
12400 | | "fspath($module, /, path)\n" |
12401 | | "--\n" |
12402 | | "\n" |
12403 | | "Return the file system path representation of the object.\n" |
12404 | | "\n" |
12405 | | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
12406 | | "object defines __fspath__(), then return the result of that method. All other\n" |
12407 | | "types raise a TypeError."); |
12408 | | |
12409 | | #define OS_FSPATH_METHODDEF \ |
12410 | | {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
12411 | | |
12412 | | static PyObject * |
12413 | | os_fspath_impl(PyObject *module, PyObject *path); |
12414 | | |
12415 | | static PyObject * |
12416 | | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12417 | 3.07k | { |
12418 | 3.07k | PyObject *return_value = NULL; |
12419 | 3.07k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12420 | | |
12421 | 3.07k | #define NUM_KEYWORDS 1 |
12422 | 3.07k | static struct { |
12423 | 3.07k | PyGC_Head _this_is_not_used; |
12424 | 3.07k | PyObject_VAR_HEAD |
12425 | 3.07k | Py_hash_t ob_hash; |
12426 | 3.07k | PyObject *ob_item[NUM_KEYWORDS]; |
12427 | 3.07k | } _kwtuple = { |
12428 | 3.07k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12429 | 3.07k | .ob_hash = -1, |
12430 | 3.07k | .ob_item = { &_Py_ID(path), }, |
12431 | 3.07k | }; |
12432 | 3.07k | #undef NUM_KEYWORDS |
12433 | 3.07k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12434 | | |
12435 | | #else // !Py_BUILD_CORE |
12436 | | # define KWTUPLE NULL |
12437 | | #endif // !Py_BUILD_CORE |
12438 | | |
12439 | 3.07k | static const char * const _keywords[] = {"path", NULL}; |
12440 | 3.07k | static _PyArg_Parser _parser = { |
12441 | 3.07k | .keywords = _keywords, |
12442 | 3.07k | .fname = "fspath", |
12443 | 3.07k | .kwtuple = KWTUPLE, |
12444 | 3.07k | }; |
12445 | 3.07k | #undef KWTUPLE |
12446 | 3.07k | PyObject *argsbuf[1]; |
12447 | 3.07k | PyObject *path; |
12448 | | |
12449 | 3.07k | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12450 | 3.07k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12451 | 3.07k | if (!args) { |
12452 | 0 | goto exit; |
12453 | 0 | } |
12454 | 3.07k | path = args[0]; |
12455 | 3.07k | return_value = os_fspath_impl(module, path); |
12456 | | |
12457 | 3.07k | exit: |
12458 | 3.07k | return return_value; |
12459 | 3.07k | } |
12460 | | |
12461 | | #if defined(HAVE_GETRANDOM_SYSCALL) |
12462 | | |
12463 | | PyDoc_STRVAR(os_getrandom__doc__, |
12464 | | "getrandom($module, /, size, flags=0)\n" |
12465 | | "--\n" |
12466 | | "\n" |
12467 | | "Obtain a series of random bytes."); |
12468 | | |
12469 | | #define OS_GETRANDOM_METHODDEF \ |
12470 | | {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
12471 | | |
12472 | | static PyObject * |
12473 | | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
12474 | | |
12475 | | static PyObject * |
12476 | | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12477 | 0 | { |
12478 | 0 | PyObject *return_value = NULL; |
12479 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12480 | |
|
12481 | 0 | #define NUM_KEYWORDS 2 |
12482 | 0 | static struct { |
12483 | 0 | PyGC_Head _this_is_not_used; |
12484 | 0 | PyObject_VAR_HEAD |
12485 | 0 | Py_hash_t ob_hash; |
12486 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12487 | 0 | } _kwtuple = { |
12488 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12489 | 0 | .ob_hash = -1, |
12490 | 0 | .ob_item = { &_Py_ID(size), &_Py_ID(flags), }, |
12491 | 0 | }; |
12492 | 0 | #undef NUM_KEYWORDS |
12493 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12494 | |
|
12495 | | #else // !Py_BUILD_CORE |
12496 | | # define KWTUPLE NULL |
12497 | | #endif // !Py_BUILD_CORE |
12498 | |
|
12499 | 0 | static const char * const _keywords[] = {"size", "flags", NULL}; |
12500 | 0 | static _PyArg_Parser _parser = { |
12501 | 0 | .keywords = _keywords, |
12502 | 0 | .fname = "getrandom", |
12503 | 0 | .kwtuple = KWTUPLE, |
12504 | 0 | }; |
12505 | 0 | #undef KWTUPLE |
12506 | 0 | PyObject *argsbuf[2]; |
12507 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
12508 | 0 | Py_ssize_t size; |
12509 | 0 | int flags = 0; |
12510 | |
|
12511 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12512 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12513 | 0 | if (!args) { |
12514 | 0 | goto exit; |
12515 | 0 | } |
12516 | 0 | { |
12517 | 0 | Py_ssize_t ival = -1; |
12518 | 0 | PyObject *iobj = _PyNumber_Index(args[0]); |
12519 | 0 | if (iobj != NULL) { |
12520 | 0 | ival = PyLong_AsSsize_t(iobj); |
12521 | 0 | Py_DECREF(iobj); |
12522 | 0 | } |
12523 | 0 | if (ival == -1 && PyErr_Occurred()) { |
12524 | 0 | goto exit; |
12525 | 0 | } |
12526 | 0 | size = ival; |
12527 | 0 | } |
12528 | 0 | if (!noptargs) { |
12529 | 0 | goto skip_optional_pos; |
12530 | 0 | } |
12531 | 0 | flags = PyLong_AsInt(args[1]); |
12532 | 0 | if (flags == -1 && PyErr_Occurred()) { |
12533 | 0 | goto exit; |
12534 | 0 | } |
12535 | 0 | skip_optional_pos: |
12536 | 0 | return_value = os_getrandom_impl(module, size, flags); |
12537 | |
|
12538 | 0 | exit: |
12539 | 0 | return return_value; |
12540 | 0 | } |
12541 | | |
12542 | | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
12543 | | |
12544 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12545 | | |
12546 | | PyDoc_STRVAR(os__add_dll_directory__doc__, |
12547 | | "_add_dll_directory($module, /, path)\n" |
12548 | | "--\n" |
12549 | | "\n" |
12550 | | "Add a path to the DLL search path.\n" |
12551 | | "\n" |
12552 | | "This search path is used when resolving dependencies for imported\n" |
12553 | | "extension modules (the module itself is resolved through sys.path),\n" |
12554 | | "and also by ctypes.\n" |
12555 | | "\n" |
12556 | | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
12557 | | "to remove this directory from the search path."); |
12558 | | |
12559 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
12560 | | {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
12561 | | |
12562 | | static PyObject * |
12563 | | os__add_dll_directory_impl(PyObject *module, path_t *path); |
12564 | | |
12565 | | static PyObject * |
12566 | | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12567 | | { |
12568 | | PyObject *return_value = NULL; |
12569 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12570 | | |
12571 | | #define NUM_KEYWORDS 1 |
12572 | | static struct { |
12573 | | PyGC_Head _this_is_not_used; |
12574 | | PyObject_VAR_HEAD |
12575 | | Py_hash_t ob_hash; |
12576 | | PyObject *ob_item[NUM_KEYWORDS]; |
12577 | | } _kwtuple = { |
12578 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12579 | | .ob_hash = -1, |
12580 | | .ob_item = { &_Py_ID(path), }, |
12581 | | }; |
12582 | | #undef NUM_KEYWORDS |
12583 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12584 | | |
12585 | | #else // !Py_BUILD_CORE |
12586 | | # define KWTUPLE NULL |
12587 | | #endif // !Py_BUILD_CORE |
12588 | | |
12589 | | static const char * const _keywords[] = {"path", NULL}; |
12590 | | static _PyArg_Parser _parser = { |
12591 | | .keywords = _keywords, |
12592 | | .fname = "_add_dll_directory", |
12593 | | .kwtuple = KWTUPLE, |
12594 | | }; |
12595 | | #undef KWTUPLE |
12596 | | PyObject *argsbuf[1]; |
12597 | | path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0); |
12598 | | |
12599 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12600 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12601 | | if (!args) { |
12602 | | goto exit; |
12603 | | } |
12604 | | if (!path_converter(args[0], &path)) { |
12605 | | goto exit; |
12606 | | } |
12607 | | return_value = os__add_dll_directory_impl(module, &path); |
12608 | | |
12609 | | exit: |
12610 | | /* Cleanup for path */ |
12611 | | path_cleanup(&path); |
12612 | | |
12613 | | return return_value; |
12614 | | } |
12615 | | |
12616 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12617 | | |
12618 | | #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) |
12619 | | |
12620 | | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
12621 | | "_remove_dll_directory($module, /, cookie)\n" |
12622 | | "--\n" |
12623 | | "\n" |
12624 | | "Removes a path from the DLL search path.\n" |
12625 | | "\n" |
12626 | | "The parameter is an opaque value that was returned from\n" |
12627 | | "os.add_dll_directory. You can only remove directories that you added\n" |
12628 | | "yourself."); |
12629 | | |
12630 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
12631 | | {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
12632 | | |
12633 | | static PyObject * |
12634 | | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
12635 | | |
12636 | | static PyObject * |
12637 | | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12638 | | { |
12639 | | PyObject *return_value = NULL; |
12640 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12641 | | |
12642 | | #define NUM_KEYWORDS 1 |
12643 | | static struct { |
12644 | | PyGC_Head _this_is_not_used; |
12645 | | PyObject_VAR_HEAD |
12646 | | Py_hash_t ob_hash; |
12647 | | PyObject *ob_item[NUM_KEYWORDS]; |
12648 | | } _kwtuple = { |
12649 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12650 | | .ob_hash = -1, |
12651 | | .ob_item = { &_Py_ID(cookie), }, |
12652 | | }; |
12653 | | #undef NUM_KEYWORDS |
12654 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12655 | | |
12656 | | #else // !Py_BUILD_CORE |
12657 | | # define KWTUPLE NULL |
12658 | | #endif // !Py_BUILD_CORE |
12659 | | |
12660 | | static const char * const _keywords[] = {"cookie", NULL}; |
12661 | | static _PyArg_Parser _parser = { |
12662 | | .keywords = _keywords, |
12663 | | .fname = "_remove_dll_directory", |
12664 | | .kwtuple = KWTUPLE, |
12665 | | }; |
12666 | | #undef KWTUPLE |
12667 | | PyObject *argsbuf[1]; |
12668 | | PyObject *cookie; |
12669 | | |
12670 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12671 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12672 | | if (!args) { |
12673 | | goto exit; |
12674 | | } |
12675 | | cookie = args[0]; |
12676 | | return_value = os__remove_dll_directory_impl(module, cookie); |
12677 | | |
12678 | | exit: |
12679 | | return return_value; |
12680 | | } |
12681 | | |
12682 | | #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ |
12683 | | |
12684 | | #if (defined(WIFEXITED) || defined(MS_WINDOWS)) |
12685 | | |
12686 | | PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__, |
12687 | | "waitstatus_to_exitcode($module, /, status)\n" |
12688 | | "--\n" |
12689 | | "\n" |
12690 | | "Convert a wait status to an exit code.\n" |
12691 | | "\n" |
12692 | | "On Unix:\n" |
12693 | | "\n" |
12694 | | "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n" |
12695 | | "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n" |
12696 | | "* Otherwise, raise a ValueError.\n" |
12697 | | "\n" |
12698 | | "On Windows, return status shifted right by 8 bits.\n" |
12699 | | "\n" |
12700 | | "On Unix, if the process is being traced or if waitpid() was called with\n" |
12701 | | "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n" |
12702 | | "This function must not be called if WIFSTOPPED(status) is true."); |
12703 | | |
12704 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \ |
12705 | | {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__}, |
12706 | | |
12707 | | static PyObject * |
12708 | | os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj); |
12709 | | |
12710 | | static PyObject * |
12711 | | os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12712 | 0 | { |
12713 | 0 | PyObject *return_value = NULL; |
12714 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12715 | |
|
12716 | 0 | #define NUM_KEYWORDS 1 |
12717 | 0 | static struct { |
12718 | 0 | PyGC_Head _this_is_not_used; |
12719 | 0 | PyObject_VAR_HEAD |
12720 | 0 | Py_hash_t ob_hash; |
12721 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
12722 | 0 | } _kwtuple = { |
12723 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12724 | 0 | .ob_hash = -1, |
12725 | 0 | .ob_item = { &_Py_ID(status), }, |
12726 | 0 | }; |
12727 | 0 | #undef NUM_KEYWORDS |
12728 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12729 | |
|
12730 | | #else // !Py_BUILD_CORE |
12731 | | # define KWTUPLE NULL |
12732 | | #endif // !Py_BUILD_CORE |
12733 | |
|
12734 | 0 | static const char * const _keywords[] = {"status", NULL}; |
12735 | 0 | static _PyArg_Parser _parser = { |
12736 | 0 | .keywords = _keywords, |
12737 | 0 | .fname = "waitstatus_to_exitcode", |
12738 | 0 | .kwtuple = KWTUPLE, |
12739 | 0 | }; |
12740 | 0 | #undef KWTUPLE |
12741 | 0 | PyObject *argsbuf[1]; |
12742 | 0 | PyObject *status_obj; |
12743 | |
|
12744 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12745 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12746 | 0 | if (!args) { |
12747 | 0 | goto exit; |
12748 | 0 | } |
12749 | 0 | status_obj = args[0]; |
12750 | 0 | return_value = os_waitstatus_to_exitcode_impl(module, status_obj); |
12751 | |
|
12752 | 0 | exit: |
12753 | 0 | return return_value; |
12754 | 0 | } |
12755 | | |
12756 | | #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */ |
12757 | | |
12758 | | #if defined(MS_WINDOWS) |
12759 | | |
12760 | | PyDoc_STRVAR(os__supports_virtual_terminal__doc__, |
12761 | | "_supports_virtual_terminal($module, /)\n" |
12762 | | "--\n" |
12763 | | "\n" |
12764 | | "Checks if virtual terminal is supported in windows"); |
12765 | | |
12766 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF \ |
12767 | | {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__}, |
12768 | | |
12769 | | static PyObject * |
12770 | | os__supports_virtual_terminal_impl(PyObject *module); |
12771 | | |
12772 | | static PyObject * |
12773 | | os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12774 | | { |
12775 | | return os__supports_virtual_terminal_impl(module); |
12776 | | } |
12777 | | |
12778 | | #endif /* defined(MS_WINDOWS) */ |
12779 | | |
12780 | | PyDoc_STRVAR(os__inputhook__doc__, |
12781 | | "_inputhook($module, /)\n" |
12782 | | "--\n" |
12783 | | "\n" |
12784 | | "Calls PyOS_InputHook dropping the GIL first"); |
12785 | | |
12786 | | #define OS__INPUTHOOK_METHODDEF \ |
12787 | | {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__}, |
12788 | | |
12789 | | static PyObject * |
12790 | | os__inputhook_impl(PyObject *module); |
12791 | | |
12792 | | static PyObject * |
12793 | | os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12794 | 0 | { |
12795 | 0 | return os__inputhook_impl(module); |
12796 | 0 | } |
12797 | | |
12798 | | PyDoc_STRVAR(os__is_inputhook_installed__doc__, |
12799 | | "_is_inputhook_installed($module, /)\n" |
12800 | | "--\n" |
12801 | | "\n" |
12802 | | "Checks if PyOS_InputHook is set"); |
12803 | | |
12804 | | #define OS__IS_INPUTHOOK_INSTALLED_METHODDEF \ |
12805 | | {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__}, |
12806 | | |
12807 | | static PyObject * |
12808 | | os__is_inputhook_installed_impl(PyObject *module); |
12809 | | |
12810 | | static PyObject * |
12811 | | os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12812 | 0 | { |
12813 | 0 | return os__is_inputhook_installed_impl(module); |
12814 | 0 | } |
12815 | | |
12816 | | PyDoc_STRVAR(os__create_environ__doc__, |
12817 | | "_create_environ($module, /)\n" |
12818 | | "--\n" |
12819 | | "\n" |
12820 | | "Create the environment dictionary."); |
12821 | | |
12822 | | #define OS__CREATE_ENVIRON_METHODDEF \ |
12823 | | {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__}, |
12824 | | |
12825 | | static PyObject * |
12826 | | os__create_environ_impl(PyObject *module); |
12827 | | |
12828 | | static PyObject * |
12829 | | os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12830 | 0 | { |
12831 | 0 | return os__create_environ_impl(module); |
12832 | 0 | } |
12833 | | |
12834 | | #if defined(__EMSCRIPTEN__) |
12835 | | |
12836 | | PyDoc_STRVAR(os__emscripten_debugger__doc__, |
12837 | | "_emscripten_debugger($module, /)\n" |
12838 | | "--\n" |
12839 | | "\n" |
12840 | | "Create a breakpoint for the JavaScript debugger. Emscripten only."); |
12841 | | |
12842 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF \ |
12843 | | {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__}, |
12844 | | |
12845 | | static PyObject * |
12846 | | os__emscripten_debugger_impl(PyObject *module); |
12847 | | |
12848 | | static PyObject * |
12849 | | os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored)) |
12850 | | { |
12851 | | return os__emscripten_debugger_impl(module); |
12852 | | } |
12853 | | |
12854 | | #endif /* defined(__EMSCRIPTEN__) */ |
12855 | | |
12856 | | #if defined(__EMSCRIPTEN__) |
12857 | | |
12858 | | PyDoc_STRVAR(os__emscripten_log__doc__, |
12859 | | "_emscripten_log($module, /, arg)\n" |
12860 | | "--\n" |
12861 | | "\n" |
12862 | | "Log something to the JS console. Emscripten only."); |
12863 | | |
12864 | | #define OS__EMSCRIPTEN_LOG_METHODDEF \ |
12865 | | {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__}, |
12866 | | |
12867 | | static PyObject * |
12868 | | os__emscripten_log_impl(PyObject *module, const char *arg); |
12869 | | |
12870 | | static PyObject * |
12871 | | os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
12872 | | { |
12873 | | PyObject *return_value = NULL; |
12874 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
12875 | | |
12876 | | #define NUM_KEYWORDS 1 |
12877 | | static struct { |
12878 | | PyGC_Head _this_is_not_used; |
12879 | | PyObject_VAR_HEAD |
12880 | | Py_hash_t ob_hash; |
12881 | | PyObject *ob_item[NUM_KEYWORDS]; |
12882 | | } _kwtuple = { |
12883 | | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
12884 | | .ob_hash = -1, |
12885 | | .ob_item = { &_Py_ID(arg), }, |
12886 | | }; |
12887 | | #undef NUM_KEYWORDS |
12888 | | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
12889 | | |
12890 | | #else // !Py_BUILD_CORE |
12891 | | # define KWTUPLE NULL |
12892 | | #endif // !Py_BUILD_CORE |
12893 | | |
12894 | | static const char * const _keywords[] = {"arg", NULL}; |
12895 | | static _PyArg_Parser _parser = { |
12896 | | .keywords = _keywords, |
12897 | | .fname = "_emscripten_log", |
12898 | | .kwtuple = KWTUPLE, |
12899 | | }; |
12900 | | #undef KWTUPLE |
12901 | | PyObject *argsbuf[1]; |
12902 | | const char *arg; |
12903 | | |
12904 | | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
12905 | | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
12906 | | if (!args) { |
12907 | | goto exit; |
12908 | | } |
12909 | | if (!PyUnicode_Check(args[0])) { |
12910 | | _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]); |
12911 | | goto exit; |
12912 | | } |
12913 | | Py_ssize_t arg_length; |
12914 | | arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length); |
12915 | | if (arg == NULL) { |
12916 | | goto exit; |
12917 | | } |
12918 | | if (strlen(arg) != (size_t)arg_length) { |
12919 | | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
12920 | | goto exit; |
12921 | | } |
12922 | | return_value = os__emscripten_log_impl(module, arg); |
12923 | | |
12924 | | exit: |
12925 | | return return_value; |
12926 | | } |
12927 | | |
12928 | | #endif /* defined(__EMSCRIPTEN__) */ |
12929 | | |
12930 | | #ifndef OS_STATX_METHODDEF |
12931 | | #define OS_STATX_METHODDEF |
12932 | | #endif /* !defined(OS_STATX_METHODDEF) */ |
12933 | | |
12934 | | #ifndef OS_TTYNAME_METHODDEF |
12935 | | #define OS_TTYNAME_METHODDEF |
12936 | | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
12937 | | |
12938 | | #ifndef OS_CTERMID_METHODDEF |
12939 | | #define OS_CTERMID_METHODDEF |
12940 | | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
12941 | | |
12942 | | #ifndef OS_FCHDIR_METHODDEF |
12943 | | #define OS_FCHDIR_METHODDEF |
12944 | | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
12945 | | |
12946 | | #ifndef OS_FCHMOD_METHODDEF |
12947 | | #define OS_FCHMOD_METHODDEF |
12948 | | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
12949 | | |
12950 | | #ifndef OS_LCHMOD_METHODDEF |
12951 | | #define OS_LCHMOD_METHODDEF |
12952 | | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
12953 | | |
12954 | | #ifndef OS_CHFLAGS_METHODDEF |
12955 | | #define OS_CHFLAGS_METHODDEF |
12956 | | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
12957 | | |
12958 | | #ifndef OS_LCHFLAGS_METHODDEF |
12959 | | #define OS_LCHFLAGS_METHODDEF |
12960 | | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
12961 | | |
12962 | | #ifndef OS_CHROOT_METHODDEF |
12963 | | #define OS_CHROOT_METHODDEF |
12964 | | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
12965 | | |
12966 | | #ifndef OS_FSYNC_METHODDEF |
12967 | | #define OS_FSYNC_METHODDEF |
12968 | | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
12969 | | |
12970 | | #ifndef OS_SYNC_METHODDEF |
12971 | | #define OS_SYNC_METHODDEF |
12972 | | #endif /* !defined(OS_SYNC_METHODDEF) */ |
12973 | | |
12974 | | #ifndef OS_FDATASYNC_METHODDEF |
12975 | | #define OS_FDATASYNC_METHODDEF |
12976 | | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
12977 | | |
12978 | | #ifndef OS_CHOWN_METHODDEF |
12979 | | #define OS_CHOWN_METHODDEF |
12980 | | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
12981 | | |
12982 | | #ifndef OS_FCHOWN_METHODDEF |
12983 | | #define OS_FCHOWN_METHODDEF |
12984 | | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
12985 | | |
12986 | | #ifndef OS_LCHOWN_METHODDEF |
12987 | | #define OS_LCHOWN_METHODDEF |
12988 | | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
12989 | | |
12990 | | #ifndef OS_LINK_METHODDEF |
12991 | | #define OS_LINK_METHODDEF |
12992 | | #endif /* !defined(OS_LINK_METHODDEF) */ |
12993 | | |
12994 | | #ifndef OS_LISTDRIVES_METHODDEF |
12995 | | #define OS_LISTDRIVES_METHODDEF |
12996 | | #endif /* !defined(OS_LISTDRIVES_METHODDEF) */ |
12997 | | |
12998 | | #ifndef OS_LISTVOLUMES_METHODDEF |
12999 | | #define OS_LISTVOLUMES_METHODDEF |
13000 | | #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */ |
13001 | | |
13002 | | #ifndef OS_LISTMOUNTS_METHODDEF |
13003 | | #define OS_LISTMOUNTS_METHODDEF |
13004 | | #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */ |
13005 | | |
13006 | | #ifndef OS__PATH_ISDEVDRIVE_METHODDEF |
13007 | | #define OS__PATH_ISDEVDRIVE_METHODDEF |
13008 | | #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */ |
13009 | | |
13010 | | #ifndef OS__GETFULLPATHNAME_METHODDEF |
13011 | | #define OS__GETFULLPATHNAME_METHODDEF |
13012 | | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
13013 | | |
13014 | | #ifndef OS__GETFINALPATHNAME_METHODDEF |
13015 | | #define OS__GETFINALPATHNAME_METHODDEF |
13016 | | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
13017 | | |
13018 | | #ifndef OS__FINDFIRSTFILE_METHODDEF |
13019 | | #define OS__FINDFIRSTFILE_METHODDEF |
13020 | | #endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */ |
13021 | | |
13022 | | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
13023 | | #define OS__GETVOLUMEPATHNAME_METHODDEF |
13024 | | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
13025 | | |
13026 | | #ifndef OS__PATH_SPLITROOT_METHODDEF |
13027 | | #define OS__PATH_SPLITROOT_METHODDEF |
13028 | | #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */ |
13029 | | |
13030 | | #ifndef OS__PATH_EXISTS_METHODDEF |
13031 | | #define OS__PATH_EXISTS_METHODDEF |
13032 | | #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */ |
13033 | | |
13034 | | #ifndef OS__PATH_LEXISTS_METHODDEF |
13035 | | #define OS__PATH_LEXISTS_METHODDEF |
13036 | | #endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */ |
13037 | | |
13038 | | #ifndef OS__PATH_ISDIR_METHODDEF |
13039 | | #define OS__PATH_ISDIR_METHODDEF |
13040 | | #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */ |
13041 | | |
13042 | | #ifndef OS__PATH_ISFILE_METHODDEF |
13043 | | #define OS__PATH_ISFILE_METHODDEF |
13044 | | #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */ |
13045 | | |
13046 | | #ifndef OS__PATH_ISLINK_METHODDEF |
13047 | | #define OS__PATH_ISLINK_METHODDEF |
13048 | | #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */ |
13049 | | |
13050 | | #ifndef OS__PATH_ISJUNCTION_METHODDEF |
13051 | | #define OS__PATH_ISJUNCTION_METHODDEF |
13052 | | #endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */ |
13053 | | |
13054 | | #ifndef OS_NICE_METHODDEF |
13055 | | #define OS_NICE_METHODDEF |
13056 | | #endif /* !defined(OS_NICE_METHODDEF) */ |
13057 | | |
13058 | | #ifndef OS_GETPRIORITY_METHODDEF |
13059 | | #define OS_GETPRIORITY_METHODDEF |
13060 | | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
13061 | | |
13062 | | #ifndef OS_SETPRIORITY_METHODDEF |
13063 | | #define OS_SETPRIORITY_METHODDEF |
13064 | | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
13065 | | |
13066 | | #ifndef OS_SYSTEM_METHODDEF |
13067 | | #define OS_SYSTEM_METHODDEF |
13068 | | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
13069 | | |
13070 | | #ifndef OS_UMASK_METHODDEF |
13071 | | #define OS_UMASK_METHODDEF |
13072 | | #endif /* !defined(OS_UMASK_METHODDEF) */ |
13073 | | |
13074 | | #ifndef OS_UNAME_METHODDEF |
13075 | | #define OS_UNAME_METHODDEF |
13076 | | #endif /* !defined(OS_UNAME_METHODDEF) */ |
13077 | | |
13078 | | #ifndef OS_EXECV_METHODDEF |
13079 | | #define OS_EXECV_METHODDEF |
13080 | | #endif /* !defined(OS_EXECV_METHODDEF) */ |
13081 | | |
13082 | | #ifndef OS_EXECVE_METHODDEF |
13083 | | #define OS_EXECVE_METHODDEF |
13084 | | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
13085 | | |
13086 | | #ifndef OS_POSIX_SPAWN_METHODDEF |
13087 | | #define OS_POSIX_SPAWN_METHODDEF |
13088 | | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
13089 | | |
13090 | | #ifndef OS_POSIX_SPAWNP_METHODDEF |
13091 | | #define OS_POSIX_SPAWNP_METHODDEF |
13092 | | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
13093 | | |
13094 | | #ifndef OS_SPAWNV_METHODDEF |
13095 | | #define OS_SPAWNV_METHODDEF |
13096 | | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
13097 | | |
13098 | | #ifndef OS_SPAWNVE_METHODDEF |
13099 | | #define OS_SPAWNVE_METHODDEF |
13100 | | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
13101 | | |
13102 | | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
13103 | | #define OS_REGISTER_AT_FORK_METHODDEF |
13104 | | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
13105 | | |
13106 | | #ifndef OS_FORK1_METHODDEF |
13107 | | #define OS_FORK1_METHODDEF |
13108 | | #endif /* !defined(OS_FORK1_METHODDEF) */ |
13109 | | |
13110 | | #ifndef OS_FORK_METHODDEF |
13111 | | #define OS_FORK_METHODDEF |
13112 | | #endif /* !defined(OS_FORK_METHODDEF) */ |
13113 | | |
13114 | | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
13115 | | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
13116 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
13117 | | |
13118 | | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
13119 | | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
13120 | | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
13121 | | |
13122 | | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
13123 | | #define OS_SCHED_GETSCHEDULER_METHODDEF |
13124 | | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
13125 | | |
13126 | | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
13127 | | #define OS_SCHED_SETSCHEDULER_METHODDEF |
13128 | | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
13129 | | |
13130 | | #ifndef OS_SCHED_GETPARAM_METHODDEF |
13131 | | #define OS_SCHED_GETPARAM_METHODDEF |
13132 | | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
13133 | | |
13134 | | #ifndef OS_SCHED_SETPARAM_METHODDEF |
13135 | | #define OS_SCHED_SETPARAM_METHODDEF |
13136 | | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
13137 | | |
13138 | | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
13139 | | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
13140 | | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
13141 | | |
13142 | | #ifndef OS_SCHED_YIELD_METHODDEF |
13143 | | #define OS_SCHED_YIELD_METHODDEF |
13144 | | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
13145 | | |
13146 | | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
13147 | | #define OS_SCHED_SETAFFINITY_METHODDEF |
13148 | | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
13149 | | |
13150 | | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
13151 | | #define OS_SCHED_GETAFFINITY_METHODDEF |
13152 | | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
13153 | | |
13154 | | #ifndef OS_POSIX_OPENPT_METHODDEF |
13155 | | #define OS_POSIX_OPENPT_METHODDEF |
13156 | | #endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */ |
13157 | | |
13158 | | #ifndef OS_GRANTPT_METHODDEF |
13159 | | #define OS_GRANTPT_METHODDEF |
13160 | | #endif /* !defined(OS_GRANTPT_METHODDEF) */ |
13161 | | |
13162 | | #ifndef OS_UNLOCKPT_METHODDEF |
13163 | | #define OS_UNLOCKPT_METHODDEF |
13164 | | #endif /* !defined(OS_UNLOCKPT_METHODDEF) */ |
13165 | | |
13166 | | #ifndef OS_PTSNAME_METHODDEF |
13167 | | #define OS_PTSNAME_METHODDEF |
13168 | | #endif /* !defined(OS_PTSNAME_METHODDEF) */ |
13169 | | |
13170 | | #ifndef OS_OPENPTY_METHODDEF |
13171 | | #define OS_OPENPTY_METHODDEF |
13172 | | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
13173 | | |
13174 | | #ifndef OS_LOGIN_TTY_METHODDEF |
13175 | | #define OS_LOGIN_TTY_METHODDEF |
13176 | | #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ |
13177 | | |
13178 | | #ifndef OS_FORKPTY_METHODDEF |
13179 | | #define OS_FORKPTY_METHODDEF |
13180 | | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
13181 | | |
13182 | | #ifndef OS_GETEGID_METHODDEF |
13183 | | #define OS_GETEGID_METHODDEF |
13184 | | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
13185 | | |
13186 | | #ifndef OS_GETEUID_METHODDEF |
13187 | | #define OS_GETEUID_METHODDEF |
13188 | | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
13189 | | |
13190 | | #ifndef OS_GETGID_METHODDEF |
13191 | | #define OS_GETGID_METHODDEF |
13192 | | #endif /* !defined(OS_GETGID_METHODDEF) */ |
13193 | | |
13194 | | #ifndef OS_GETPID_METHODDEF |
13195 | | #define OS_GETPID_METHODDEF |
13196 | | #endif /* !defined(OS_GETPID_METHODDEF) */ |
13197 | | |
13198 | | #ifndef OS_GETGROUPLIST_METHODDEF |
13199 | | #define OS_GETGROUPLIST_METHODDEF |
13200 | | #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */ |
13201 | | |
13202 | | #ifndef OS_GETGROUPS_METHODDEF |
13203 | | #define OS_GETGROUPS_METHODDEF |
13204 | | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
13205 | | |
13206 | | #ifndef OS_INITGROUPS_METHODDEF |
13207 | | #define OS_INITGROUPS_METHODDEF |
13208 | | #endif /* !defined(OS_INITGROUPS_METHODDEF) */ |
13209 | | |
13210 | | #ifndef OS_GETPGID_METHODDEF |
13211 | | #define OS_GETPGID_METHODDEF |
13212 | | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
13213 | | |
13214 | | #ifndef OS_GETPGRP_METHODDEF |
13215 | | #define OS_GETPGRP_METHODDEF |
13216 | | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
13217 | | |
13218 | | #ifndef OS_SETPGRP_METHODDEF |
13219 | | #define OS_SETPGRP_METHODDEF |
13220 | | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
13221 | | |
13222 | | #ifndef OS_GETPPID_METHODDEF |
13223 | | #define OS_GETPPID_METHODDEF |
13224 | | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
13225 | | |
13226 | | #ifndef OS_GETLOGIN_METHODDEF |
13227 | | #define OS_GETLOGIN_METHODDEF |
13228 | | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
13229 | | |
13230 | | #ifndef OS_GETUID_METHODDEF |
13231 | | #define OS_GETUID_METHODDEF |
13232 | | #endif /* !defined(OS_GETUID_METHODDEF) */ |
13233 | | |
13234 | | #ifndef OS_KILL_METHODDEF |
13235 | | #define OS_KILL_METHODDEF |
13236 | | #endif /* !defined(OS_KILL_METHODDEF) */ |
13237 | | |
13238 | | #ifndef OS_KILLPG_METHODDEF |
13239 | | #define OS_KILLPG_METHODDEF |
13240 | | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
13241 | | |
13242 | | #ifndef OS_PLOCK_METHODDEF |
13243 | | #define OS_PLOCK_METHODDEF |
13244 | | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
13245 | | |
13246 | | #ifndef OS_SETUID_METHODDEF |
13247 | | #define OS_SETUID_METHODDEF |
13248 | | #endif /* !defined(OS_SETUID_METHODDEF) */ |
13249 | | |
13250 | | #ifndef OS_SETEUID_METHODDEF |
13251 | | #define OS_SETEUID_METHODDEF |
13252 | | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
13253 | | |
13254 | | #ifndef OS_SETEGID_METHODDEF |
13255 | | #define OS_SETEGID_METHODDEF |
13256 | | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
13257 | | |
13258 | | #ifndef OS_SETREUID_METHODDEF |
13259 | | #define OS_SETREUID_METHODDEF |
13260 | | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
13261 | | |
13262 | | #ifndef OS_SETREGID_METHODDEF |
13263 | | #define OS_SETREGID_METHODDEF |
13264 | | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
13265 | | |
13266 | | #ifndef OS_SETGID_METHODDEF |
13267 | | #define OS_SETGID_METHODDEF |
13268 | | #endif /* !defined(OS_SETGID_METHODDEF) */ |
13269 | | |
13270 | | #ifndef OS_SETGROUPS_METHODDEF |
13271 | | #define OS_SETGROUPS_METHODDEF |
13272 | | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
13273 | | |
13274 | | #ifndef OS_WAIT3_METHODDEF |
13275 | | #define OS_WAIT3_METHODDEF |
13276 | | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
13277 | | |
13278 | | #ifndef OS_WAIT4_METHODDEF |
13279 | | #define OS_WAIT4_METHODDEF |
13280 | | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
13281 | | |
13282 | | #ifndef OS_WAITID_METHODDEF |
13283 | | #define OS_WAITID_METHODDEF |
13284 | | #endif /* !defined(OS_WAITID_METHODDEF) */ |
13285 | | |
13286 | | #ifndef OS_WAITPID_METHODDEF |
13287 | | #define OS_WAITPID_METHODDEF |
13288 | | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
13289 | | |
13290 | | #ifndef OS_WAIT_METHODDEF |
13291 | | #define OS_WAIT_METHODDEF |
13292 | | #endif /* !defined(OS_WAIT_METHODDEF) */ |
13293 | | |
13294 | | #ifndef OS_PIDFD_OPEN_METHODDEF |
13295 | | #define OS_PIDFD_OPEN_METHODDEF |
13296 | | #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */ |
13297 | | |
13298 | | #ifndef OS_SETNS_METHODDEF |
13299 | | #define OS_SETNS_METHODDEF |
13300 | | #endif /* !defined(OS_SETNS_METHODDEF) */ |
13301 | | |
13302 | | #ifndef OS_UNSHARE_METHODDEF |
13303 | | #define OS_UNSHARE_METHODDEF |
13304 | | #endif /* !defined(OS_UNSHARE_METHODDEF) */ |
13305 | | |
13306 | | #ifndef OS_READLINK_METHODDEF |
13307 | | #define OS_READLINK_METHODDEF |
13308 | | #endif /* !defined(OS_READLINK_METHODDEF) */ |
13309 | | |
13310 | | #ifndef OS_SYMLINK_METHODDEF |
13311 | | #define OS_SYMLINK_METHODDEF |
13312 | | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
13313 | | |
13314 | | #ifndef OS_TIMERFD_CREATE_METHODDEF |
13315 | | #define OS_TIMERFD_CREATE_METHODDEF |
13316 | | #endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */ |
13317 | | |
13318 | | #ifndef OS_TIMERFD_SETTIME_METHODDEF |
13319 | | #define OS_TIMERFD_SETTIME_METHODDEF |
13320 | | #endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */ |
13321 | | |
13322 | | #ifndef OS_TIMERFD_SETTIME_NS_METHODDEF |
13323 | | #define OS_TIMERFD_SETTIME_NS_METHODDEF |
13324 | | #endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */ |
13325 | | |
13326 | | #ifndef OS_TIMERFD_GETTIME_METHODDEF |
13327 | | #define OS_TIMERFD_GETTIME_METHODDEF |
13328 | | #endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */ |
13329 | | |
13330 | | #ifndef OS_TIMERFD_GETTIME_NS_METHODDEF |
13331 | | #define OS_TIMERFD_GETTIME_NS_METHODDEF |
13332 | | #endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */ |
13333 | | |
13334 | | #ifndef OS_GETSID_METHODDEF |
13335 | | #define OS_GETSID_METHODDEF |
13336 | | #endif /* !defined(OS_GETSID_METHODDEF) */ |
13337 | | |
13338 | | #ifndef OS_SETSID_METHODDEF |
13339 | | #define OS_SETSID_METHODDEF |
13340 | | #endif /* !defined(OS_SETSID_METHODDEF) */ |
13341 | | |
13342 | | #ifndef OS_SETPGID_METHODDEF |
13343 | | #define OS_SETPGID_METHODDEF |
13344 | | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
13345 | | |
13346 | | #ifndef OS_TCGETPGRP_METHODDEF |
13347 | | #define OS_TCGETPGRP_METHODDEF |
13348 | | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
13349 | | |
13350 | | #ifndef OS_TCSETPGRP_METHODDEF |
13351 | | #define OS_TCSETPGRP_METHODDEF |
13352 | | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
13353 | | |
13354 | | #ifndef OS_DUP2_METHODDEF |
13355 | | #define OS_DUP2_METHODDEF |
13356 | | #endif /* !defined(OS_DUP2_METHODDEF) */ |
13357 | | |
13358 | | #ifndef OS_LOCKF_METHODDEF |
13359 | | #define OS_LOCKF_METHODDEF |
13360 | | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
13361 | | |
13362 | | #ifndef OS_READV_METHODDEF |
13363 | | #define OS_READV_METHODDEF |
13364 | | #endif /* !defined(OS_READV_METHODDEF) */ |
13365 | | |
13366 | | #ifndef OS_PREAD_METHODDEF |
13367 | | #define OS_PREAD_METHODDEF |
13368 | | #endif /* !defined(OS_PREAD_METHODDEF) */ |
13369 | | |
13370 | | #ifndef OS_PREADV_METHODDEF |
13371 | | #define OS_PREADV_METHODDEF |
13372 | | #endif /* !defined(OS_PREADV_METHODDEF) */ |
13373 | | |
13374 | | #ifndef OS_SENDFILE_METHODDEF |
13375 | | #define OS_SENDFILE_METHODDEF |
13376 | | #endif /* !defined(OS_SENDFILE_METHODDEF) */ |
13377 | | |
13378 | | #ifndef OS__FCOPYFILE_METHODDEF |
13379 | | #define OS__FCOPYFILE_METHODDEF |
13380 | | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
13381 | | |
13382 | | #ifndef OS_PIPE_METHODDEF |
13383 | | #define OS_PIPE_METHODDEF |
13384 | | #endif /* !defined(OS_PIPE_METHODDEF) */ |
13385 | | |
13386 | | #ifndef OS_PIPE2_METHODDEF |
13387 | | #define OS_PIPE2_METHODDEF |
13388 | | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
13389 | | |
13390 | | #ifndef OS_WRITEV_METHODDEF |
13391 | | #define OS_WRITEV_METHODDEF |
13392 | | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
13393 | | |
13394 | | #ifndef OS_PWRITE_METHODDEF |
13395 | | #define OS_PWRITE_METHODDEF |
13396 | | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
13397 | | |
13398 | | #ifndef OS_PWRITEV_METHODDEF |
13399 | | #define OS_PWRITEV_METHODDEF |
13400 | | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
13401 | | |
13402 | | #ifndef OS_COPY_FILE_RANGE_METHODDEF |
13403 | | #define OS_COPY_FILE_RANGE_METHODDEF |
13404 | | #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */ |
13405 | | |
13406 | | #ifndef OS_SPLICE_METHODDEF |
13407 | | #define OS_SPLICE_METHODDEF |
13408 | | #endif /* !defined(OS_SPLICE_METHODDEF) */ |
13409 | | |
13410 | | #ifndef OS_MKFIFO_METHODDEF |
13411 | | #define OS_MKFIFO_METHODDEF |
13412 | | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
13413 | | |
13414 | | #ifndef OS_MKNOD_METHODDEF |
13415 | | #define OS_MKNOD_METHODDEF |
13416 | | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
13417 | | |
13418 | | #ifndef OS_MAJOR_METHODDEF |
13419 | | #define OS_MAJOR_METHODDEF |
13420 | | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
13421 | | |
13422 | | #ifndef OS_MINOR_METHODDEF |
13423 | | #define OS_MINOR_METHODDEF |
13424 | | #endif /* !defined(OS_MINOR_METHODDEF) */ |
13425 | | |
13426 | | #ifndef OS_MAKEDEV_METHODDEF |
13427 | | #define OS_MAKEDEV_METHODDEF |
13428 | | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
13429 | | |
13430 | | #ifndef OS_FTRUNCATE_METHODDEF |
13431 | | #define OS_FTRUNCATE_METHODDEF |
13432 | | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
13433 | | |
13434 | | #ifndef OS_TRUNCATE_METHODDEF |
13435 | | #define OS_TRUNCATE_METHODDEF |
13436 | | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
13437 | | |
13438 | | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
13439 | | #define OS_POSIX_FALLOCATE_METHODDEF |
13440 | | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
13441 | | |
13442 | | #ifndef OS_POSIX_FADVISE_METHODDEF |
13443 | | #define OS_POSIX_FADVISE_METHODDEF |
13444 | | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
13445 | | |
13446 | | #ifndef OS_PUTENV_METHODDEF |
13447 | | #define OS_PUTENV_METHODDEF |
13448 | | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
13449 | | |
13450 | | #ifndef OS_UNSETENV_METHODDEF |
13451 | | #define OS_UNSETENV_METHODDEF |
13452 | | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
13453 | | |
13454 | | #ifndef OS__CLEARENV_METHODDEF |
13455 | | #define OS__CLEARENV_METHODDEF |
13456 | | #endif /* !defined(OS__CLEARENV_METHODDEF) */ |
13457 | | |
13458 | | #ifndef OS_WCOREDUMP_METHODDEF |
13459 | | #define OS_WCOREDUMP_METHODDEF |
13460 | | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
13461 | | |
13462 | | #ifndef OS_WIFCONTINUED_METHODDEF |
13463 | | #define OS_WIFCONTINUED_METHODDEF |
13464 | | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
13465 | | |
13466 | | #ifndef OS_WIFSTOPPED_METHODDEF |
13467 | | #define OS_WIFSTOPPED_METHODDEF |
13468 | | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
13469 | | |
13470 | | #ifndef OS_WIFSIGNALED_METHODDEF |
13471 | | #define OS_WIFSIGNALED_METHODDEF |
13472 | | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
13473 | | |
13474 | | #ifndef OS_WIFEXITED_METHODDEF |
13475 | | #define OS_WIFEXITED_METHODDEF |
13476 | | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
13477 | | |
13478 | | #ifndef OS_WEXITSTATUS_METHODDEF |
13479 | | #define OS_WEXITSTATUS_METHODDEF |
13480 | | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
13481 | | |
13482 | | #ifndef OS_WTERMSIG_METHODDEF |
13483 | | #define OS_WTERMSIG_METHODDEF |
13484 | | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
13485 | | |
13486 | | #ifndef OS_WSTOPSIG_METHODDEF |
13487 | | #define OS_WSTOPSIG_METHODDEF |
13488 | | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
13489 | | |
13490 | | #ifndef OS_FSTATVFS_METHODDEF |
13491 | | #define OS_FSTATVFS_METHODDEF |
13492 | | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
13493 | | |
13494 | | #ifndef OS_STATVFS_METHODDEF |
13495 | | #define OS_STATVFS_METHODDEF |
13496 | | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
13497 | | |
13498 | | #ifndef OS__GETDISKUSAGE_METHODDEF |
13499 | | #define OS__GETDISKUSAGE_METHODDEF |
13500 | | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
13501 | | |
13502 | | #ifndef OS_FPATHCONF_METHODDEF |
13503 | | #define OS_FPATHCONF_METHODDEF |
13504 | | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
13505 | | |
13506 | | #ifndef OS_PATHCONF_METHODDEF |
13507 | | #define OS_PATHCONF_METHODDEF |
13508 | | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
13509 | | |
13510 | | #ifndef OS_CONFSTR_METHODDEF |
13511 | | #define OS_CONFSTR_METHODDEF |
13512 | | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
13513 | | |
13514 | | #ifndef OS_SYSCONF_METHODDEF |
13515 | | #define OS_SYSCONF_METHODDEF |
13516 | | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
13517 | | |
13518 | | #ifndef OS_STARTFILE_METHODDEF |
13519 | | #define OS_STARTFILE_METHODDEF |
13520 | | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
13521 | | |
13522 | | #ifndef OS_GETLOADAVG_METHODDEF |
13523 | | #define OS_GETLOADAVG_METHODDEF |
13524 | | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
13525 | | |
13526 | | #ifndef OS_SETRESUID_METHODDEF |
13527 | | #define OS_SETRESUID_METHODDEF |
13528 | | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
13529 | | |
13530 | | #ifndef OS_SETRESGID_METHODDEF |
13531 | | #define OS_SETRESGID_METHODDEF |
13532 | | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
13533 | | |
13534 | | #ifndef OS_GETRESUID_METHODDEF |
13535 | | #define OS_GETRESUID_METHODDEF |
13536 | | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
13537 | | |
13538 | | #ifndef OS_GETRESGID_METHODDEF |
13539 | | #define OS_GETRESGID_METHODDEF |
13540 | | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
13541 | | |
13542 | | #ifndef OS_GETXATTR_METHODDEF |
13543 | | #define OS_GETXATTR_METHODDEF |
13544 | | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
13545 | | |
13546 | | #ifndef OS_SETXATTR_METHODDEF |
13547 | | #define OS_SETXATTR_METHODDEF |
13548 | | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
13549 | | |
13550 | | #ifndef OS_REMOVEXATTR_METHODDEF |
13551 | | #define OS_REMOVEXATTR_METHODDEF |
13552 | | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
13553 | | |
13554 | | #ifndef OS_LISTXATTR_METHODDEF |
13555 | | #define OS_LISTXATTR_METHODDEF |
13556 | | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
13557 | | |
13558 | | #ifndef OS_MEMFD_CREATE_METHODDEF |
13559 | | #define OS_MEMFD_CREATE_METHODDEF |
13560 | | #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */ |
13561 | | |
13562 | | #ifndef OS_EVENTFD_METHODDEF |
13563 | | #define OS_EVENTFD_METHODDEF |
13564 | | #endif /* !defined(OS_EVENTFD_METHODDEF) */ |
13565 | | |
13566 | | #ifndef OS_EVENTFD_READ_METHODDEF |
13567 | | #define OS_EVENTFD_READ_METHODDEF |
13568 | | #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */ |
13569 | | |
13570 | | #ifndef OS_EVENTFD_WRITE_METHODDEF |
13571 | | #define OS_EVENTFD_WRITE_METHODDEF |
13572 | | #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */ |
13573 | | |
13574 | | #ifndef OS_GET_TERMINAL_SIZE_METHODDEF |
13575 | | #define OS_GET_TERMINAL_SIZE_METHODDEF |
13576 | | #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */ |
13577 | | |
13578 | | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
13579 | | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
13580 | | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
13581 | | |
13582 | | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
13583 | | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
13584 | | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
13585 | | |
13586 | | #ifndef OS_GETRANDOM_METHODDEF |
13587 | | #define OS_GETRANDOM_METHODDEF |
13588 | | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
13589 | | |
13590 | | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
13591 | | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
13592 | | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
13593 | | |
13594 | | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13595 | | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
13596 | | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
13597 | | |
13598 | | #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13599 | | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
13600 | | #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ |
13601 | | |
13602 | | #ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13603 | | #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF |
13604 | | #endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */ |
13605 | | |
13606 | | #ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13607 | | #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF |
13608 | | #endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */ |
13609 | | |
13610 | | #ifndef OS__EMSCRIPTEN_LOG_METHODDEF |
13611 | | #define OS__EMSCRIPTEN_LOG_METHODDEF |
13612 | | #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ |
13613 | | /*[clinic end generated code: output=82f60940338c70e4 input=a9049054013a1b77]*/ |