1 | /*[clinic input] |
2 | preserve |
3 | [clinic start generated code]*/ |
4 | |
5 | PyDoc_STRVAR(os_stat__doc__, |
6 | "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n" |
7 | "--\n" |
8 | "\n" |
9 | "Perform a stat system call on the given path.\n" |
10 | "\n" |
11 | " path\n" |
12 | " Path to be examined; can be string, bytes, a path-like object or\n" |
13 | " open-file-descriptor int.\n" |
14 | " dir_fd\n" |
15 | " If not None, it should be a file descriptor open to a directory,\n" |
16 | " and path should be a relative string; path will then be relative to\n" |
17 | " that directory.\n" |
18 | " follow_symlinks\n" |
19 | " If False, and the last element of the path is a symbolic link,\n" |
20 | " stat will examine the symbolic link itself instead of the file\n" |
21 | " the link points to.\n" |
22 | "\n" |
23 | "dir_fd and follow_symlinks may not be implemented\n" |
24 | " on your platform. If they are unavailable, using them will raise a\n" |
25 | " NotImplementedError.\n" |
26 | "\n" |
27 | "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n" |
28 | " an open file descriptor." ); |
29 | |
30 | #define OS_STAT_METHODDEF \ |
31 | {"stat", (PyCFunction)(void(*)(void))os_stat, METH_FASTCALL|METH_KEYWORDS, os_stat__doc__}, |
32 | |
33 | static PyObject * |
34 | os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks); |
35 | |
36 | static PyObject * |
37 | os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
38 | { |
39 | PyObject *return_value = NULL; |
40 | static const char * const _keywords[] = {"path" , "dir_fd" , "follow_symlinks" , NULL}; |
41 | static _PyArg_Parser _parser = {NULL, _keywords, "stat" , 0}; |
42 | PyObject *argsbuf[3]; |
43 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
44 | path_t path = PATH_T_INITIALIZE("stat" , "path" , 0, 1); |
45 | int dir_fd = DEFAULT_DIR_FD; |
46 | int follow_symlinks = 1; |
47 | |
48 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
49 | if (!args) { |
50 | goto exit; |
51 | } |
52 | if (!path_converter(args[0], &path)) { |
53 | goto exit; |
54 | } |
55 | if (!noptargs) { |
56 | goto skip_optional_kwonly; |
57 | } |
58 | if (args[1]) { |
59 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
60 | goto exit; |
61 | } |
62 | if (!--noptargs) { |
63 | goto skip_optional_kwonly; |
64 | } |
65 | } |
66 | follow_symlinks = PyObject_IsTrue(args[2]); |
67 | if (follow_symlinks < 0) { |
68 | goto exit; |
69 | } |
70 | skip_optional_kwonly: |
71 | return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); |
72 | |
73 | exit: |
74 | /* Cleanup for path */ |
75 | path_cleanup(&path); |
76 | |
77 | return return_value; |
78 | } |
79 | |
80 | PyDoc_STRVAR(os_lstat__doc__, |
81 | "lstat($module, /, path, *, dir_fd=None)\n" |
82 | "--\n" |
83 | "\n" |
84 | "Perform a stat system call on the given path, without following symbolic links.\n" |
85 | "\n" |
86 | "Like stat(), but do not follow symbolic links.\n" |
87 | "Equivalent to stat(path, follow_symlinks=False)." ); |
88 | |
89 | #define OS_LSTAT_METHODDEF \ |
90 | {"lstat", (PyCFunction)(void(*)(void))os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__}, |
91 | |
92 | static PyObject * |
93 | os_lstat_impl(PyObject *module, path_t *path, int dir_fd); |
94 | |
95 | static PyObject * |
96 | os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
97 | { |
98 | PyObject *return_value = NULL; |
99 | static const char * const _keywords[] = {"path" , "dir_fd" , NULL}; |
100 | static _PyArg_Parser _parser = {NULL, _keywords, "lstat" , 0}; |
101 | PyObject *argsbuf[2]; |
102 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
103 | path_t path = PATH_T_INITIALIZE("lstat" , "path" , 0, 0); |
104 | int dir_fd = DEFAULT_DIR_FD; |
105 | |
106 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
107 | if (!args) { |
108 | goto exit; |
109 | } |
110 | if (!path_converter(args[0], &path)) { |
111 | goto exit; |
112 | } |
113 | if (!noptargs) { |
114 | goto skip_optional_kwonly; |
115 | } |
116 | if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
117 | goto exit; |
118 | } |
119 | skip_optional_kwonly: |
120 | return_value = os_lstat_impl(module, &path, dir_fd); |
121 | |
122 | exit: |
123 | /* Cleanup for path */ |
124 | path_cleanup(&path); |
125 | |
126 | return return_value; |
127 | } |
128 | |
129 | PyDoc_STRVAR(os_access__doc__, |
130 | "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n" |
131 | " follow_symlinks=True)\n" |
132 | "--\n" |
133 | "\n" |
134 | "Use the real uid/gid to test for access to a path.\n" |
135 | "\n" |
136 | " path\n" |
137 | " Path to be tested; can be string, bytes, or a path-like object.\n" |
138 | " mode\n" |
139 | " Operating-system mode bitfield. Can be F_OK to test existence,\n" |
140 | " or the inclusive-OR of R_OK, W_OK, and X_OK.\n" |
141 | " dir_fd\n" |
142 | " If not None, it should be a file descriptor open to a directory,\n" |
143 | " and path should be relative; path will then be relative to that\n" |
144 | " directory.\n" |
145 | " effective_ids\n" |
146 | " If True, access will use the effective uid/gid instead of\n" |
147 | " the real uid/gid.\n" |
148 | " follow_symlinks\n" |
149 | " If False, and the last element of the path is a symbolic link,\n" |
150 | " access will examine the symbolic link itself instead of the file\n" |
151 | " the link points to.\n" |
152 | "\n" |
153 | "dir_fd, effective_ids, and follow_symlinks may not be implemented\n" |
154 | " on your platform. If they are unavailable, using them will raise a\n" |
155 | " NotImplementedError.\n" |
156 | "\n" |
157 | "Note that most operations will use the effective uid/gid, therefore this\n" |
158 | " routine can be used in a suid/sgid environment to test if the invoking user\n" |
159 | " has the specified access to the path." ); |
160 | |
161 | #define OS_ACCESS_METHODDEF \ |
162 | {"access", (PyCFunction)(void(*)(void))os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__}, |
163 | |
164 | static int |
165 | os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
166 | int effective_ids, int follow_symlinks); |
167 | |
168 | static PyObject * |
169 | os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
170 | { |
171 | PyObject *return_value = NULL; |
172 | static const char * const _keywords[] = {"path" , "mode" , "dir_fd" , "effective_ids" , "follow_symlinks" , NULL}; |
173 | static _PyArg_Parser _parser = {NULL, _keywords, "access" , 0}; |
174 | PyObject *argsbuf[5]; |
175 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
176 | path_t path = PATH_T_INITIALIZE("access" , "path" , 0, 0); |
177 | int mode; |
178 | int dir_fd = DEFAULT_DIR_FD; |
179 | int effective_ids = 0; |
180 | int follow_symlinks = 1; |
181 | int _return_value; |
182 | |
183 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
184 | if (!args) { |
185 | goto exit; |
186 | } |
187 | if (!path_converter(args[0], &path)) { |
188 | goto exit; |
189 | } |
190 | mode = _PyLong_AsInt(args[1]); |
191 | if (mode == -1 && PyErr_Occurred()) { |
192 | goto exit; |
193 | } |
194 | if (!noptargs) { |
195 | goto skip_optional_kwonly; |
196 | } |
197 | if (args[2]) { |
198 | if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
199 | goto exit; |
200 | } |
201 | if (!--noptargs) { |
202 | goto skip_optional_kwonly; |
203 | } |
204 | } |
205 | if (args[3]) { |
206 | effective_ids = PyObject_IsTrue(args[3]); |
207 | if (effective_ids < 0) { |
208 | goto exit; |
209 | } |
210 | if (!--noptargs) { |
211 | goto skip_optional_kwonly; |
212 | } |
213 | } |
214 | follow_symlinks = PyObject_IsTrue(args[4]); |
215 | if (follow_symlinks < 0) { |
216 | goto exit; |
217 | } |
218 | skip_optional_kwonly: |
219 | _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); |
220 | if ((_return_value == -1) && PyErr_Occurred()) { |
221 | goto exit; |
222 | } |
223 | return_value = PyBool_FromLong((long)_return_value); |
224 | |
225 | exit: |
226 | /* Cleanup for path */ |
227 | path_cleanup(&path); |
228 | |
229 | return return_value; |
230 | } |
231 | |
232 | #if defined(HAVE_TTYNAME) |
233 | |
234 | PyDoc_STRVAR(os_ttyname__doc__, |
235 | "ttyname($module, fd, /)\n" |
236 | "--\n" |
237 | "\n" |
238 | "Return the name of the terminal device connected to \'fd\'.\n" |
239 | "\n" |
240 | " fd\n" |
241 | " Integer file descriptor handle." ); |
242 | |
243 | #define OS_TTYNAME_METHODDEF \ |
244 | {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__}, |
245 | |
246 | static PyObject * |
247 | os_ttyname_impl(PyObject *module, int fd); |
248 | |
249 | static PyObject * |
250 | os_ttyname(PyObject *module, PyObject *arg) |
251 | { |
252 | PyObject *return_value = NULL; |
253 | int fd; |
254 | |
255 | fd = _PyLong_AsInt(arg); |
256 | if (fd == -1 && PyErr_Occurred()) { |
257 | goto exit; |
258 | } |
259 | return_value = os_ttyname_impl(module, fd); |
260 | |
261 | exit: |
262 | return return_value; |
263 | } |
264 | |
265 | #endif /* defined(HAVE_TTYNAME) */ |
266 | |
267 | #if defined(HAVE_CTERMID) |
268 | |
269 | PyDoc_STRVAR(os_ctermid__doc__, |
270 | "ctermid($module, /)\n" |
271 | "--\n" |
272 | "\n" |
273 | "Return the name of the controlling terminal for this process." ); |
274 | |
275 | #define OS_CTERMID_METHODDEF \ |
276 | {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, |
277 | |
278 | static PyObject * |
279 | os_ctermid_impl(PyObject *module); |
280 | |
281 | static PyObject * |
282 | os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
283 | { |
284 | return os_ctermid_impl(module); |
285 | } |
286 | |
287 | #endif /* defined(HAVE_CTERMID) */ |
288 | |
289 | PyDoc_STRVAR(os_chdir__doc__, |
290 | "chdir($module, /, path)\n" |
291 | "--\n" |
292 | "\n" |
293 | "Change the current working directory to the specified path.\n" |
294 | "\n" |
295 | "path may always be specified as a string.\n" |
296 | "On some platforms, path may also be specified as an open file descriptor.\n" |
297 | " If this functionality is unavailable, using it raises an exception." ); |
298 | |
299 | #define OS_CHDIR_METHODDEF \ |
300 | {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__}, |
301 | |
302 | static PyObject * |
303 | os_chdir_impl(PyObject *module, path_t *path); |
304 | |
305 | static PyObject * |
306 | os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
307 | { |
308 | PyObject *return_value = NULL; |
309 | static const char * const _keywords[] = {"path" , NULL}; |
310 | static _PyArg_Parser _parser = {NULL, _keywords, "chdir" , 0}; |
311 | PyObject *argsbuf[1]; |
312 | path_t path = PATH_T_INITIALIZE("chdir" , "path" , 0, PATH_HAVE_FCHDIR); |
313 | |
314 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
315 | if (!args) { |
316 | goto exit; |
317 | } |
318 | if (!path_converter(args[0], &path)) { |
319 | goto exit; |
320 | } |
321 | return_value = os_chdir_impl(module, &path); |
322 | |
323 | exit: |
324 | /* Cleanup for path */ |
325 | path_cleanup(&path); |
326 | |
327 | return return_value; |
328 | } |
329 | |
330 | #if defined(HAVE_FCHDIR) |
331 | |
332 | PyDoc_STRVAR(os_fchdir__doc__, |
333 | "fchdir($module, /, fd)\n" |
334 | "--\n" |
335 | "\n" |
336 | "Change to the directory of the given file descriptor.\n" |
337 | "\n" |
338 | "fd must be opened on a directory, not a file.\n" |
339 | "Equivalent to os.chdir(fd)." ); |
340 | |
341 | #define OS_FCHDIR_METHODDEF \ |
342 | {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__}, |
343 | |
344 | static PyObject * |
345 | os_fchdir_impl(PyObject *module, int fd); |
346 | |
347 | static PyObject * |
348 | os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
349 | { |
350 | PyObject *return_value = NULL; |
351 | static const char * const _keywords[] = {"fd" , NULL}; |
352 | static _PyArg_Parser _parser = {NULL, _keywords, "fchdir" , 0}; |
353 | PyObject *argsbuf[1]; |
354 | int fd; |
355 | |
356 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
357 | if (!args) { |
358 | goto exit; |
359 | } |
360 | if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
361 | goto exit; |
362 | } |
363 | return_value = os_fchdir_impl(module, fd); |
364 | |
365 | exit: |
366 | return return_value; |
367 | } |
368 | |
369 | #endif /* defined(HAVE_FCHDIR) */ |
370 | |
371 | PyDoc_STRVAR(os_chmod__doc__, |
372 | "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n" |
373 | "--\n" |
374 | "\n" |
375 | "Change the access permissions of a file.\n" |
376 | "\n" |
377 | " path\n" |
378 | " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n" |
379 | " On some platforms, path may also be specified as an open file descriptor.\n" |
380 | " If this functionality is unavailable, using it raises an exception.\n" |
381 | " mode\n" |
382 | " Operating-system mode bitfield.\n" |
383 | " dir_fd\n" |
384 | " If not None, it should be a file descriptor open to a directory,\n" |
385 | " and path should be relative; path will then be relative to that\n" |
386 | " directory.\n" |
387 | " follow_symlinks\n" |
388 | " If False, and the last element of the path is a symbolic link,\n" |
389 | " chmod will modify the symbolic link itself instead of the file\n" |
390 | " the link points to.\n" |
391 | "\n" |
392 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
393 | " an open file descriptor.\n" |
394 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
395 | " If they are unavailable, using them will raise a NotImplementedError." ); |
396 | |
397 | #define OS_CHMOD_METHODDEF \ |
398 | {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__}, |
399 | |
400 | static PyObject * |
401 | os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, |
402 | int follow_symlinks); |
403 | |
404 | static PyObject * |
405 | os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
406 | { |
407 | PyObject *return_value = NULL; |
408 | static const char * const _keywords[] = {"path" , "mode" , "dir_fd" , "follow_symlinks" , NULL}; |
409 | static _PyArg_Parser _parser = {NULL, _keywords, "chmod" , 0}; |
410 | PyObject *argsbuf[4]; |
411 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
412 | path_t path = PATH_T_INITIALIZE("chmod" , "path" , 0, PATH_HAVE_FCHMOD); |
413 | int mode; |
414 | int dir_fd = DEFAULT_DIR_FD; |
415 | int follow_symlinks = 1; |
416 | |
417 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
418 | if (!args) { |
419 | goto exit; |
420 | } |
421 | if (!path_converter(args[0], &path)) { |
422 | goto exit; |
423 | } |
424 | mode = _PyLong_AsInt(args[1]); |
425 | if (mode == -1 && PyErr_Occurred()) { |
426 | goto exit; |
427 | } |
428 | if (!noptargs) { |
429 | goto skip_optional_kwonly; |
430 | } |
431 | if (args[2]) { |
432 | if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
433 | goto exit; |
434 | } |
435 | if (!--noptargs) { |
436 | goto skip_optional_kwonly; |
437 | } |
438 | } |
439 | follow_symlinks = PyObject_IsTrue(args[3]); |
440 | if (follow_symlinks < 0) { |
441 | goto exit; |
442 | } |
443 | skip_optional_kwonly: |
444 | return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); |
445 | |
446 | exit: |
447 | /* Cleanup for path */ |
448 | path_cleanup(&path); |
449 | |
450 | return return_value; |
451 | } |
452 | |
453 | #if defined(HAVE_FCHMOD) |
454 | |
455 | PyDoc_STRVAR(os_fchmod__doc__, |
456 | "fchmod($module, /, fd, mode)\n" |
457 | "--\n" |
458 | "\n" |
459 | "Change the access permissions of the file given by file descriptor fd.\n" |
460 | "\n" |
461 | "Equivalent to os.chmod(fd, mode)." ); |
462 | |
463 | #define OS_FCHMOD_METHODDEF \ |
464 | {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__}, |
465 | |
466 | static PyObject * |
467 | os_fchmod_impl(PyObject *module, int fd, int mode); |
468 | |
469 | static PyObject * |
470 | os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
471 | { |
472 | PyObject *return_value = NULL; |
473 | static const char * const _keywords[] = {"fd" , "mode" , NULL}; |
474 | static _PyArg_Parser _parser = {NULL, _keywords, "fchmod" , 0}; |
475 | PyObject *argsbuf[2]; |
476 | int fd; |
477 | int mode; |
478 | |
479 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
480 | if (!args) { |
481 | goto exit; |
482 | } |
483 | fd = _PyLong_AsInt(args[0]); |
484 | if (fd == -1 && PyErr_Occurred()) { |
485 | goto exit; |
486 | } |
487 | mode = _PyLong_AsInt(args[1]); |
488 | if (mode == -1 && PyErr_Occurred()) { |
489 | goto exit; |
490 | } |
491 | return_value = os_fchmod_impl(module, fd, mode); |
492 | |
493 | exit: |
494 | return return_value; |
495 | } |
496 | |
497 | #endif /* defined(HAVE_FCHMOD) */ |
498 | |
499 | #if defined(HAVE_LCHMOD) |
500 | |
501 | PyDoc_STRVAR(os_lchmod__doc__, |
502 | "lchmod($module, /, path, mode)\n" |
503 | "--\n" |
504 | "\n" |
505 | "Change the access permissions of a file, without following symbolic links.\n" |
506 | "\n" |
507 | "If path is a symlink, this affects the link itself rather than the target.\n" |
508 | "Equivalent to chmod(path, mode, follow_symlinks=False).\"" ); |
509 | |
510 | #define OS_LCHMOD_METHODDEF \ |
511 | {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__}, |
512 | |
513 | static PyObject * |
514 | os_lchmod_impl(PyObject *module, path_t *path, int mode); |
515 | |
516 | static PyObject * |
517 | os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
518 | { |
519 | PyObject *return_value = NULL; |
520 | static const char * const _keywords[] = {"path" , "mode" , NULL}; |
521 | static _PyArg_Parser _parser = {NULL, _keywords, "lchmod" , 0}; |
522 | PyObject *argsbuf[2]; |
523 | path_t path = PATH_T_INITIALIZE("lchmod" , "path" , 0, 0); |
524 | int mode; |
525 | |
526 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
527 | if (!args) { |
528 | goto exit; |
529 | } |
530 | if (!path_converter(args[0], &path)) { |
531 | goto exit; |
532 | } |
533 | mode = _PyLong_AsInt(args[1]); |
534 | if (mode == -1 && PyErr_Occurred()) { |
535 | goto exit; |
536 | } |
537 | return_value = os_lchmod_impl(module, &path, mode); |
538 | |
539 | exit: |
540 | /* Cleanup for path */ |
541 | path_cleanup(&path); |
542 | |
543 | return return_value; |
544 | } |
545 | |
546 | #endif /* defined(HAVE_LCHMOD) */ |
547 | |
548 | #if defined(HAVE_CHFLAGS) |
549 | |
550 | PyDoc_STRVAR(os_chflags__doc__, |
551 | "chflags($module, /, path, flags, follow_symlinks=True)\n" |
552 | "--\n" |
553 | "\n" |
554 | "Set file flags.\n" |
555 | "\n" |
556 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
557 | " link, chflags will change flags on the symbolic link itself instead of the\n" |
558 | " file the link points to.\n" |
559 | "follow_symlinks may not be implemented on your platform. If it is\n" |
560 | "unavailable, using it will raise a NotImplementedError." ); |
561 | |
562 | #define OS_CHFLAGS_METHODDEF \ |
563 | {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__}, |
564 | |
565 | static PyObject * |
566 | os_chflags_impl(PyObject *module, path_t *path, unsigned long flags, |
567 | int follow_symlinks); |
568 | |
569 | static PyObject * |
570 | os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
571 | { |
572 | PyObject *return_value = NULL; |
573 | static const char * const _keywords[] = {"path" , "flags" , "follow_symlinks" , NULL}; |
574 | static _PyArg_Parser _parser = {NULL, _keywords, "chflags" , 0}; |
575 | PyObject *argsbuf[3]; |
576 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
577 | path_t path = PATH_T_INITIALIZE("chflags" , "path" , 0, 0); |
578 | unsigned long flags; |
579 | int follow_symlinks = 1; |
580 | |
581 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
582 | if (!args) { |
583 | goto exit; |
584 | } |
585 | if (!path_converter(args[0], &path)) { |
586 | goto exit; |
587 | } |
588 | if (!PyLong_Check(args[1])) { |
589 | _PyArg_BadArgument("chflags" , "argument 'flags'" , "int" , args[1]); |
590 | goto exit; |
591 | } |
592 | flags = PyLong_AsUnsignedLongMask(args[1]); |
593 | if (!noptargs) { |
594 | goto skip_optional_pos; |
595 | } |
596 | follow_symlinks = PyObject_IsTrue(args[2]); |
597 | if (follow_symlinks < 0) { |
598 | goto exit; |
599 | } |
600 | skip_optional_pos: |
601 | return_value = os_chflags_impl(module, &path, flags, follow_symlinks); |
602 | |
603 | exit: |
604 | /* Cleanup for path */ |
605 | path_cleanup(&path); |
606 | |
607 | return return_value; |
608 | } |
609 | |
610 | #endif /* defined(HAVE_CHFLAGS) */ |
611 | |
612 | #if defined(HAVE_LCHFLAGS) |
613 | |
614 | PyDoc_STRVAR(os_lchflags__doc__, |
615 | "lchflags($module, /, path, flags)\n" |
616 | "--\n" |
617 | "\n" |
618 | "Set file flags.\n" |
619 | "\n" |
620 | "This function will not follow symbolic links.\n" |
621 | "Equivalent to chflags(path, flags, follow_symlinks=False)." ); |
622 | |
623 | #define OS_LCHFLAGS_METHODDEF \ |
624 | {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__}, |
625 | |
626 | static PyObject * |
627 | os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags); |
628 | |
629 | static PyObject * |
630 | os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
631 | { |
632 | PyObject *return_value = NULL; |
633 | static const char * const _keywords[] = {"path" , "flags" , NULL}; |
634 | static _PyArg_Parser _parser = {NULL, _keywords, "lchflags" , 0}; |
635 | PyObject *argsbuf[2]; |
636 | path_t path = PATH_T_INITIALIZE("lchflags" , "path" , 0, 0); |
637 | unsigned long flags; |
638 | |
639 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
640 | if (!args) { |
641 | goto exit; |
642 | } |
643 | if (!path_converter(args[0], &path)) { |
644 | goto exit; |
645 | } |
646 | if (!PyLong_Check(args[1])) { |
647 | _PyArg_BadArgument("lchflags" , "argument 'flags'" , "int" , args[1]); |
648 | goto exit; |
649 | } |
650 | flags = PyLong_AsUnsignedLongMask(args[1]); |
651 | return_value = os_lchflags_impl(module, &path, flags); |
652 | |
653 | exit: |
654 | /* Cleanup for path */ |
655 | path_cleanup(&path); |
656 | |
657 | return return_value; |
658 | } |
659 | |
660 | #endif /* defined(HAVE_LCHFLAGS) */ |
661 | |
662 | #if defined(HAVE_CHROOT) |
663 | |
664 | PyDoc_STRVAR(os_chroot__doc__, |
665 | "chroot($module, /, path)\n" |
666 | "--\n" |
667 | "\n" |
668 | "Change root directory to path." ); |
669 | |
670 | #define OS_CHROOT_METHODDEF \ |
671 | {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__}, |
672 | |
673 | static PyObject * |
674 | os_chroot_impl(PyObject *module, path_t *path); |
675 | |
676 | static PyObject * |
677 | os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
678 | { |
679 | PyObject *return_value = NULL; |
680 | static const char * const _keywords[] = {"path" , NULL}; |
681 | static _PyArg_Parser _parser = {NULL, _keywords, "chroot" , 0}; |
682 | PyObject *argsbuf[1]; |
683 | path_t path = PATH_T_INITIALIZE("chroot" , "path" , 0, 0); |
684 | |
685 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
686 | if (!args) { |
687 | goto exit; |
688 | } |
689 | if (!path_converter(args[0], &path)) { |
690 | goto exit; |
691 | } |
692 | return_value = os_chroot_impl(module, &path); |
693 | |
694 | exit: |
695 | /* Cleanup for path */ |
696 | path_cleanup(&path); |
697 | |
698 | return return_value; |
699 | } |
700 | |
701 | #endif /* defined(HAVE_CHROOT) */ |
702 | |
703 | #if defined(HAVE_FSYNC) |
704 | |
705 | PyDoc_STRVAR(os_fsync__doc__, |
706 | "fsync($module, /, fd)\n" |
707 | "--\n" |
708 | "\n" |
709 | "Force write of fd to disk." ); |
710 | |
711 | #define OS_FSYNC_METHODDEF \ |
712 | {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__}, |
713 | |
714 | static PyObject * |
715 | os_fsync_impl(PyObject *module, int fd); |
716 | |
717 | static PyObject * |
718 | os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
719 | { |
720 | PyObject *return_value = NULL; |
721 | static const char * const _keywords[] = {"fd" , NULL}; |
722 | static _PyArg_Parser _parser = {NULL, _keywords, "fsync" , 0}; |
723 | PyObject *argsbuf[1]; |
724 | int fd; |
725 | |
726 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
727 | if (!args) { |
728 | goto exit; |
729 | } |
730 | if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
731 | goto exit; |
732 | } |
733 | return_value = os_fsync_impl(module, fd); |
734 | |
735 | exit: |
736 | return return_value; |
737 | } |
738 | |
739 | #endif /* defined(HAVE_FSYNC) */ |
740 | |
741 | #if defined(HAVE_SYNC) |
742 | |
743 | PyDoc_STRVAR(os_sync__doc__, |
744 | "sync($module, /)\n" |
745 | "--\n" |
746 | "\n" |
747 | "Force write of everything to disk." ); |
748 | |
749 | #define OS_SYNC_METHODDEF \ |
750 | {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, |
751 | |
752 | static PyObject * |
753 | os_sync_impl(PyObject *module); |
754 | |
755 | static PyObject * |
756 | os_sync(PyObject *module, PyObject *Py_UNUSED(ignored)) |
757 | { |
758 | return os_sync_impl(module); |
759 | } |
760 | |
761 | #endif /* defined(HAVE_SYNC) */ |
762 | |
763 | #if defined(HAVE_FDATASYNC) |
764 | |
765 | PyDoc_STRVAR(os_fdatasync__doc__, |
766 | "fdatasync($module, /, fd)\n" |
767 | "--\n" |
768 | "\n" |
769 | "Force write of fd to disk without forcing update of metadata." ); |
770 | |
771 | #define OS_FDATASYNC_METHODDEF \ |
772 | {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__}, |
773 | |
774 | static PyObject * |
775 | os_fdatasync_impl(PyObject *module, int fd); |
776 | |
777 | static PyObject * |
778 | os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
779 | { |
780 | PyObject *return_value = NULL; |
781 | static const char * const _keywords[] = {"fd" , NULL}; |
782 | static _PyArg_Parser _parser = {NULL, _keywords, "fdatasync" , 0}; |
783 | PyObject *argsbuf[1]; |
784 | int fd; |
785 | |
786 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
787 | if (!args) { |
788 | goto exit; |
789 | } |
790 | if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
791 | goto exit; |
792 | } |
793 | return_value = os_fdatasync_impl(module, fd); |
794 | |
795 | exit: |
796 | return return_value; |
797 | } |
798 | |
799 | #endif /* defined(HAVE_FDATASYNC) */ |
800 | |
801 | #if defined(HAVE_CHOWN) |
802 | |
803 | PyDoc_STRVAR(os_chown__doc__, |
804 | "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" |
805 | "--\n" |
806 | "\n" |
807 | "Change the owner and group id of path to the numeric uid and gid.\\\n" |
808 | "\n" |
809 | " path\n" |
810 | " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n" |
811 | " dir_fd\n" |
812 | " If not None, it should be a file descriptor open to a directory,\n" |
813 | " and path should be relative; path will then be relative to that\n" |
814 | " directory.\n" |
815 | " follow_symlinks\n" |
816 | " If False, and the last element of the path is a symbolic link,\n" |
817 | " stat will examine the symbolic link itself instead of the file\n" |
818 | " the link points to.\n" |
819 | "\n" |
820 | "path may always be specified as a string.\n" |
821 | "On some platforms, path may also be specified as an open file descriptor.\n" |
822 | " If this functionality is unavailable, using it raises an exception.\n" |
823 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
824 | " and path should be relative; path will then be relative to that directory.\n" |
825 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
826 | " link, chown will modify the symbolic link itself instead of the file the\n" |
827 | " link points to.\n" |
828 | "It is an error to use dir_fd or follow_symlinks when specifying path as\n" |
829 | " an open file descriptor.\n" |
830 | "dir_fd and follow_symlinks may not be implemented on your platform.\n" |
831 | " If they are unavailable, using them will raise a NotImplementedError." ); |
832 | |
833 | #define OS_CHOWN_METHODDEF \ |
834 | {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__}, |
835 | |
836 | static PyObject * |
837 | os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid, |
838 | int dir_fd, int follow_symlinks); |
839 | |
840 | static PyObject * |
841 | os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
842 | { |
843 | PyObject *return_value = NULL; |
844 | static const char * const _keywords[] = {"path" , "uid" , "gid" , "dir_fd" , "follow_symlinks" , NULL}; |
845 | static _PyArg_Parser _parser = {NULL, _keywords, "chown" , 0}; |
846 | PyObject *argsbuf[5]; |
847 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
848 | path_t path = PATH_T_INITIALIZE("chown" , "path" , 0, PATH_HAVE_FCHOWN); |
849 | uid_t uid; |
850 | gid_t gid; |
851 | int dir_fd = DEFAULT_DIR_FD; |
852 | int follow_symlinks = 1; |
853 | |
854 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
855 | if (!args) { |
856 | goto exit; |
857 | } |
858 | if (!path_converter(args[0], &path)) { |
859 | goto exit; |
860 | } |
861 | if (!_Py_Uid_Converter(args[1], &uid)) { |
862 | goto exit; |
863 | } |
864 | if (!_Py_Gid_Converter(args[2], &gid)) { |
865 | goto exit; |
866 | } |
867 | if (!noptargs) { |
868 | goto skip_optional_kwonly; |
869 | } |
870 | if (args[3]) { |
871 | if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
872 | goto exit; |
873 | } |
874 | if (!--noptargs) { |
875 | goto skip_optional_kwonly; |
876 | } |
877 | } |
878 | follow_symlinks = PyObject_IsTrue(args[4]); |
879 | if (follow_symlinks < 0) { |
880 | goto exit; |
881 | } |
882 | skip_optional_kwonly: |
883 | return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); |
884 | |
885 | exit: |
886 | /* Cleanup for path */ |
887 | path_cleanup(&path); |
888 | |
889 | return return_value; |
890 | } |
891 | |
892 | #endif /* defined(HAVE_CHOWN) */ |
893 | |
894 | #if defined(HAVE_FCHOWN) |
895 | |
896 | PyDoc_STRVAR(os_fchown__doc__, |
897 | "fchown($module, /, fd, uid, gid)\n" |
898 | "--\n" |
899 | "\n" |
900 | "Change the owner and group id of the file specified by file descriptor.\n" |
901 | "\n" |
902 | "Equivalent to os.chown(fd, uid, gid)." ); |
903 | |
904 | #define OS_FCHOWN_METHODDEF \ |
905 | {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__}, |
906 | |
907 | static PyObject * |
908 | os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid); |
909 | |
910 | static PyObject * |
911 | os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
912 | { |
913 | PyObject *return_value = NULL; |
914 | static const char * const _keywords[] = {"fd" , "uid" , "gid" , NULL}; |
915 | static _PyArg_Parser _parser = {NULL, _keywords, "fchown" , 0}; |
916 | PyObject *argsbuf[3]; |
917 | int fd; |
918 | uid_t uid; |
919 | gid_t gid; |
920 | |
921 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
922 | if (!args) { |
923 | goto exit; |
924 | } |
925 | fd = _PyLong_AsInt(args[0]); |
926 | if (fd == -1 && PyErr_Occurred()) { |
927 | goto exit; |
928 | } |
929 | if (!_Py_Uid_Converter(args[1], &uid)) { |
930 | goto exit; |
931 | } |
932 | if (!_Py_Gid_Converter(args[2], &gid)) { |
933 | goto exit; |
934 | } |
935 | return_value = os_fchown_impl(module, fd, uid, gid); |
936 | |
937 | exit: |
938 | return return_value; |
939 | } |
940 | |
941 | #endif /* defined(HAVE_FCHOWN) */ |
942 | |
943 | #if defined(HAVE_LCHOWN) |
944 | |
945 | PyDoc_STRVAR(os_lchown__doc__, |
946 | "lchown($module, /, path, uid, gid)\n" |
947 | "--\n" |
948 | "\n" |
949 | "Change the owner and group id of path to the numeric uid and gid.\n" |
950 | "\n" |
951 | "This function will not follow symbolic links.\n" |
952 | "Equivalent to os.chown(path, uid, gid, follow_symlinks=False)." ); |
953 | |
954 | #define OS_LCHOWN_METHODDEF \ |
955 | {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__}, |
956 | |
957 | static PyObject * |
958 | os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid); |
959 | |
960 | static PyObject * |
961 | os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
962 | { |
963 | PyObject *return_value = NULL; |
964 | static const char * const _keywords[] = {"path" , "uid" , "gid" , NULL}; |
965 | static _PyArg_Parser _parser = {NULL, _keywords, "lchown" , 0}; |
966 | PyObject *argsbuf[3]; |
967 | path_t path = PATH_T_INITIALIZE("lchown" , "path" , 0, 0); |
968 | uid_t uid; |
969 | gid_t gid; |
970 | |
971 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
972 | if (!args) { |
973 | goto exit; |
974 | } |
975 | if (!path_converter(args[0], &path)) { |
976 | goto exit; |
977 | } |
978 | if (!_Py_Uid_Converter(args[1], &uid)) { |
979 | goto exit; |
980 | } |
981 | if (!_Py_Gid_Converter(args[2], &gid)) { |
982 | goto exit; |
983 | } |
984 | return_value = os_lchown_impl(module, &path, uid, gid); |
985 | |
986 | exit: |
987 | /* Cleanup for path */ |
988 | path_cleanup(&path); |
989 | |
990 | return return_value; |
991 | } |
992 | |
993 | #endif /* defined(HAVE_LCHOWN) */ |
994 | |
995 | PyDoc_STRVAR(os_getcwd__doc__, |
996 | "getcwd($module, /)\n" |
997 | "--\n" |
998 | "\n" |
999 | "Return a unicode string representing the current working directory." ); |
1000 | |
1001 | #define OS_GETCWD_METHODDEF \ |
1002 | {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, |
1003 | |
1004 | static PyObject * |
1005 | os_getcwd_impl(PyObject *module); |
1006 | |
1007 | static PyObject * |
1008 | os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1009 | { |
1010 | return os_getcwd_impl(module); |
1011 | } |
1012 | |
1013 | PyDoc_STRVAR(os_getcwdb__doc__, |
1014 | "getcwdb($module, /)\n" |
1015 | "--\n" |
1016 | "\n" |
1017 | "Return a bytes string representing the current working directory." ); |
1018 | |
1019 | #define OS_GETCWDB_METHODDEF \ |
1020 | {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, |
1021 | |
1022 | static PyObject * |
1023 | os_getcwdb_impl(PyObject *module); |
1024 | |
1025 | static PyObject * |
1026 | os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1027 | { |
1028 | return os_getcwdb_impl(module); |
1029 | } |
1030 | |
1031 | #if defined(HAVE_LINK) |
1032 | |
1033 | PyDoc_STRVAR(os_link__doc__, |
1034 | "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" |
1035 | " follow_symlinks=True)\n" |
1036 | "--\n" |
1037 | "\n" |
1038 | "Create a hard link to a file.\n" |
1039 | "\n" |
1040 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
1041 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
1042 | " should be relative; the path will then be relative to that directory.\n" |
1043 | "If follow_symlinks is False, and the last element of src is a symbolic\n" |
1044 | " link, link will create a link to the symbolic link itself instead of the\n" |
1045 | " file the link points to.\n" |
1046 | "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" |
1047 | " platform. If they are unavailable, using them will raise a\n" |
1048 | " NotImplementedError." ); |
1049 | |
1050 | #define OS_LINK_METHODDEF \ |
1051 | {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__}, |
1052 | |
1053 | static PyObject * |
1054 | os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
1055 | int dst_dir_fd, int follow_symlinks); |
1056 | |
1057 | static PyObject * |
1058 | os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1059 | { |
1060 | PyObject *return_value = NULL; |
1061 | static const char * const _keywords[] = {"src" , "dst" , "src_dir_fd" , "dst_dir_fd" , "follow_symlinks" , NULL}; |
1062 | static _PyArg_Parser _parser = {NULL, _keywords, "link" , 0}; |
1063 | PyObject *argsbuf[5]; |
1064 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1065 | path_t src = PATH_T_INITIALIZE("link" , "src" , 0, 0); |
1066 | path_t dst = PATH_T_INITIALIZE("link" , "dst" , 0, 0); |
1067 | int src_dir_fd = DEFAULT_DIR_FD; |
1068 | int dst_dir_fd = DEFAULT_DIR_FD; |
1069 | int follow_symlinks = 1; |
1070 | |
1071 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
1072 | if (!args) { |
1073 | goto exit; |
1074 | } |
1075 | if (!path_converter(args[0], &src)) { |
1076 | goto exit; |
1077 | } |
1078 | if (!path_converter(args[1], &dst)) { |
1079 | goto exit; |
1080 | } |
1081 | if (!noptargs) { |
1082 | goto skip_optional_kwonly; |
1083 | } |
1084 | if (args[2]) { |
1085 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
1086 | goto exit; |
1087 | } |
1088 | if (!--noptargs) { |
1089 | goto skip_optional_kwonly; |
1090 | } |
1091 | } |
1092 | if (args[3]) { |
1093 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
1094 | goto exit; |
1095 | } |
1096 | if (!--noptargs) { |
1097 | goto skip_optional_kwonly; |
1098 | } |
1099 | } |
1100 | follow_symlinks = PyObject_IsTrue(args[4]); |
1101 | if (follow_symlinks < 0) { |
1102 | goto exit; |
1103 | } |
1104 | skip_optional_kwonly: |
1105 | return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); |
1106 | |
1107 | exit: |
1108 | /* Cleanup for src */ |
1109 | path_cleanup(&src); |
1110 | /* Cleanup for dst */ |
1111 | path_cleanup(&dst); |
1112 | |
1113 | return return_value; |
1114 | } |
1115 | |
1116 | #endif /* defined(HAVE_LINK) */ |
1117 | |
1118 | PyDoc_STRVAR(os_listdir__doc__, |
1119 | "listdir($module, /, path=None)\n" |
1120 | "--\n" |
1121 | "\n" |
1122 | "Return a list containing the names of the files in the directory.\n" |
1123 | "\n" |
1124 | "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n" |
1125 | " the filenames returned will also be bytes; in all other circumstances\n" |
1126 | " the filenames returned will be str.\n" |
1127 | "If path is None, uses the path=\'.\'.\n" |
1128 | "On some platforms, path may also be specified as an open file descriptor;\\\n" |
1129 | " the file descriptor must refer to a directory.\n" |
1130 | " If this functionality is unavailable, using it raises NotImplementedError.\n" |
1131 | "\n" |
1132 | "The list is in arbitrary order. It does not include the special\n" |
1133 | "entries \'.\' and \'..\' even if they are present in the directory." ); |
1134 | |
1135 | #define OS_LISTDIR_METHODDEF \ |
1136 | {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__}, |
1137 | |
1138 | static PyObject * |
1139 | os_listdir_impl(PyObject *module, path_t *path); |
1140 | |
1141 | static PyObject * |
1142 | os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1143 | { |
1144 | PyObject *return_value = NULL; |
1145 | static const char * const _keywords[] = {"path" , NULL}; |
1146 | static _PyArg_Parser _parser = {NULL, _keywords, "listdir" , 0}; |
1147 | PyObject *argsbuf[1]; |
1148 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
1149 | path_t path = PATH_T_INITIALIZE("listdir" , "path" , 1, PATH_HAVE_FDOPENDIR); |
1150 | |
1151 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
1152 | if (!args) { |
1153 | goto exit; |
1154 | } |
1155 | if (!noptargs) { |
1156 | goto skip_optional_pos; |
1157 | } |
1158 | if (!path_converter(args[0], &path)) { |
1159 | goto exit; |
1160 | } |
1161 | skip_optional_pos: |
1162 | return_value = os_listdir_impl(module, &path); |
1163 | |
1164 | exit: |
1165 | /* Cleanup for path */ |
1166 | path_cleanup(&path); |
1167 | |
1168 | return return_value; |
1169 | } |
1170 | |
1171 | #if defined(MS_WINDOWS) |
1172 | |
1173 | PyDoc_STRVAR(os__getfullpathname__doc__, |
1174 | "_getfullpathname($module, path, /)\n" |
1175 | "--\n" |
1176 | "\n" ); |
1177 | |
1178 | #define OS__GETFULLPATHNAME_METHODDEF \ |
1179 | {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__}, |
1180 | |
1181 | static PyObject * |
1182 | os__getfullpathname_impl(PyObject *module, path_t *path); |
1183 | |
1184 | static PyObject * |
1185 | os__getfullpathname(PyObject *module, PyObject *arg) |
1186 | { |
1187 | PyObject *return_value = NULL; |
1188 | path_t path = PATH_T_INITIALIZE("_getfullpathname" , "path" , 0, 0); |
1189 | |
1190 | if (!path_converter(arg, &path)) { |
1191 | goto exit; |
1192 | } |
1193 | return_value = os__getfullpathname_impl(module, &path); |
1194 | |
1195 | exit: |
1196 | /* Cleanup for path */ |
1197 | path_cleanup(&path); |
1198 | |
1199 | return return_value; |
1200 | } |
1201 | |
1202 | #endif /* defined(MS_WINDOWS) */ |
1203 | |
1204 | #if defined(MS_WINDOWS) |
1205 | |
1206 | PyDoc_STRVAR(os__getfinalpathname__doc__, |
1207 | "_getfinalpathname($module, path, /)\n" |
1208 | "--\n" |
1209 | "\n" |
1210 | "A helper function for samepath on windows." ); |
1211 | |
1212 | #define OS__GETFINALPATHNAME_METHODDEF \ |
1213 | {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__}, |
1214 | |
1215 | static PyObject * |
1216 | os__getfinalpathname_impl(PyObject *module, path_t *path); |
1217 | |
1218 | static PyObject * |
1219 | os__getfinalpathname(PyObject *module, PyObject *arg) |
1220 | { |
1221 | PyObject *return_value = NULL; |
1222 | path_t path = PATH_T_INITIALIZE("_getfinalpathname" , "path" , 0, 0); |
1223 | |
1224 | if (!path_converter(arg, &path)) { |
1225 | goto exit; |
1226 | } |
1227 | return_value = os__getfinalpathname_impl(module, &path); |
1228 | |
1229 | exit: |
1230 | /* Cleanup for path */ |
1231 | path_cleanup(&path); |
1232 | |
1233 | return return_value; |
1234 | } |
1235 | |
1236 | #endif /* defined(MS_WINDOWS) */ |
1237 | |
1238 | #if defined(MS_WINDOWS) |
1239 | |
1240 | PyDoc_STRVAR(os__getvolumepathname__doc__, |
1241 | "_getvolumepathname($module, /, path)\n" |
1242 | "--\n" |
1243 | "\n" |
1244 | "A helper function for ismount on Win32." ); |
1245 | |
1246 | #define OS__GETVOLUMEPATHNAME_METHODDEF \ |
1247 | {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__}, |
1248 | |
1249 | static PyObject * |
1250 | os__getvolumepathname_impl(PyObject *module, path_t *path); |
1251 | |
1252 | static PyObject * |
1253 | os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1254 | { |
1255 | PyObject *return_value = NULL; |
1256 | static const char * const _keywords[] = {"path" , NULL}; |
1257 | static _PyArg_Parser _parser = {NULL, _keywords, "_getvolumepathname" , 0}; |
1258 | PyObject *argsbuf[1]; |
1259 | path_t path = PATH_T_INITIALIZE("_getvolumepathname" , "path" , 0, 0); |
1260 | |
1261 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
1262 | if (!args) { |
1263 | goto exit; |
1264 | } |
1265 | if (!path_converter(args[0], &path)) { |
1266 | goto exit; |
1267 | } |
1268 | return_value = os__getvolumepathname_impl(module, &path); |
1269 | |
1270 | exit: |
1271 | /* Cleanup for path */ |
1272 | path_cleanup(&path); |
1273 | |
1274 | return return_value; |
1275 | } |
1276 | |
1277 | #endif /* defined(MS_WINDOWS) */ |
1278 | |
1279 | #if defined(MS_WINDOWS) |
1280 | |
1281 | PyDoc_STRVAR(os__path_splitroot__doc__, |
1282 | "_path_splitroot($module, /, path)\n" |
1283 | "--\n" |
1284 | "\n" |
1285 | "Removes everything after the root on Win32." ); |
1286 | |
1287 | #define OS__PATH_SPLITROOT_METHODDEF \ |
1288 | {"_path_splitroot", (PyCFunction)(void(*)(void))os__path_splitroot, METH_FASTCALL|METH_KEYWORDS, os__path_splitroot__doc__}, |
1289 | |
1290 | static PyObject * |
1291 | os__path_splitroot_impl(PyObject *module, path_t *path); |
1292 | |
1293 | static PyObject * |
1294 | os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1295 | { |
1296 | PyObject *return_value = NULL; |
1297 | static const char * const _keywords[] = {"path" , NULL}; |
1298 | static _PyArg_Parser _parser = {NULL, _keywords, "_path_splitroot" , 0}; |
1299 | PyObject *argsbuf[1]; |
1300 | path_t path = PATH_T_INITIALIZE("_path_splitroot" , "path" , 0, 0); |
1301 | |
1302 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
1303 | if (!args) { |
1304 | goto exit; |
1305 | } |
1306 | if (!path_converter(args[0], &path)) { |
1307 | goto exit; |
1308 | } |
1309 | return_value = os__path_splitroot_impl(module, &path); |
1310 | |
1311 | exit: |
1312 | /* Cleanup for path */ |
1313 | path_cleanup(&path); |
1314 | |
1315 | return return_value; |
1316 | } |
1317 | |
1318 | #endif /* defined(MS_WINDOWS) */ |
1319 | |
1320 | PyDoc_STRVAR(os_mkdir__doc__, |
1321 | "mkdir($module, /, path, mode=511, *, dir_fd=None)\n" |
1322 | "--\n" |
1323 | "\n" |
1324 | "Create a directory.\n" |
1325 | "\n" |
1326 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1327 | " and path should be relative; path will then be relative to that directory.\n" |
1328 | "dir_fd may not be implemented on your platform.\n" |
1329 | " If it is unavailable, using it will raise a NotImplementedError.\n" |
1330 | "\n" |
1331 | "The mode argument is ignored on Windows." ); |
1332 | |
1333 | #define OS_MKDIR_METHODDEF \ |
1334 | {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__}, |
1335 | |
1336 | static PyObject * |
1337 | os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
1338 | |
1339 | static PyObject * |
1340 | os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1341 | { |
1342 | PyObject *return_value = NULL; |
1343 | static const char * const _keywords[] = {"path" , "mode" , "dir_fd" , NULL}; |
1344 | static _PyArg_Parser _parser = {NULL, _keywords, "mkdir" , 0}; |
1345 | PyObject *argsbuf[3]; |
1346 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
1347 | path_t path = PATH_T_INITIALIZE("mkdir" , "path" , 0, 0); |
1348 | int mode = 511; |
1349 | int dir_fd = DEFAULT_DIR_FD; |
1350 | |
1351 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
1352 | if (!args) { |
1353 | goto exit; |
1354 | } |
1355 | if (!path_converter(args[0], &path)) { |
1356 | goto exit; |
1357 | } |
1358 | if (!noptargs) { |
1359 | goto skip_optional_pos; |
1360 | } |
1361 | if (args[1]) { |
1362 | mode = _PyLong_AsInt(args[1]); |
1363 | if (mode == -1 && PyErr_Occurred()) { |
1364 | goto exit; |
1365 | } |
1366 | if (!--noptargs) { |
1367 | goto skip_optional_pos; |
1368 | } |
1369 | } |
1370 | skip_optional_pos: |
1371 | if (!noptargs) { |
1372 | goto skip_optional_kwonly; |
1373 | } |
1374 | if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
1375 | goto exit; |
1376 | } |
1377 | skip_optional_kwonly: |
1378 | return_value = os_mkdir_impl(module, &path, mode, dir_fd); |
1379 | |
1380 | exit: |
1381 | /* Cleanup for path */ |
1382 | path_cleanup(&path); |
1383 | |
1384 | return return_value; |
1385 | } |
1386 | |
1387 | #if defined(HAVE_NICE) |
1388 | |
1389 | PyDoc_STRVAR(os_nice__doc__, |
1390 | "nice($module, increment, /)\n" |
1391 | "--\n" |
1392 | "\n" |
1393 | "Add increment to the priority of process and return the new priority." ); |
1394 | |
1395 | #define OS_NICE_METHODDEF \ |
1396 | {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__}, |
1397 | |
1398 | static PyObject * |
1399 | os_nice_impl(PyObject *module, int increment); |
1400 | |
1401 | static PyObject * |
1402 | os_nice(PyObject *module, PyObject *arg) |
1403 | { |
1404 | PyObject *return_value = NULL; |
1405 | int increment; |
1406 | |
1407 | increment = _PyLong_AsInt(arg); |
1408 | if (increment == -1 && PyErr_Occurred()) { |
1409 | goto exit; |
1410 | } |
1411 | return_value = os_nice_impl(module, increment); |
1412 | |
1413 | exit: |
1414 | return return_value; |
1415 | } |
1416 | |
1417 | #endif /* defined(HAVE_NICE) */ |
1418 | |
1419 | #if defined(HAVE_GETPRIORITY) |
1420 | |
1421 | PyDoc_STRVAR(os_getpriority__doc__, |
1422 | "getpriority($module, /, which, who)\n" |
1423 | "--\n" |
1424 | "\n" |
1425 | "Return program scheduling priority." ); |
1426 | |
1427 | #define OS_GETPRIORITY_METHODDEF \ |
1428 | {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__}, |
1429 | |
1430 | static PyObject * |
1431 | os_getpriority_impl(PyObject *module, int which, int who); |
1432 | |
1433 | static PyObject * |
1434 | os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1435 | { |
1436 | PyObject *return_value = NULL; |
1437 | static const char * const _keywords[] = {"which" , "who" , NULL}; |
1438 | static _PyArg_Parser _parser = {NULL, _keywords, "getpriority" , 0}; |
1439 | PyObject *argsbuf[2]; |
1440 | int which; |
1441 | int who; |
1442 | |
1443 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
1444 | if (!args) { |
1445 | goto exit; |
1446 | } |
1447 | which = _PyLong_AsInt(args[0]); |
1448 | if (which == -1 && PyErr_Occurred()) { |
1449 | goto exit; |
1450 | } |
1451 | who = _PyLong_AsInt(args[1]); |
1452 | if (who == -1 && PyErr_Occurred()) { |
1453 | goto exit; |
1454 | } |
1455 | return_value = os_getpriority_impl(module, which, who); |
1456 | |
1457 | exit: |
1458 | return return_value; |
1459 | } |
1460 | |
1461 | #endif /* defined(HAVE_GETPRIORITY) */ |
1462 | |
1463 | #if defined(HAVE_SETPRIORITY) |
1464 | |
1465 | PyDoc_STRVAR(os_setpriority__doc__, |
1466 | "setpriority($module, /, which, who, priority)\n" |
1467 | "--\n" |
1468 | "\n" |
1469 | "Set program scheduling priority." ); |
1470 | |
1471 | #define OS_SETPRIORITY_METHODDEF \ |
1472 | {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__}, |
1473 | |
1474 | static PyObject * |
1475 | os_setpriority_impl(PyObject *module, int which, int who, int priority); |
1476 | |
1477 | static PyObject * |
1478 | os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1479 | { |
1480 | PyObject *return_value = NULL; |
1481 | static const char * const _keywords[] = {"which" , "who" , "priority" , NULL}; |
1482 | static _PyArg_Parser _parser = {NULL, _keywords, "setpriority" , 0}; |
1483 | PyObject *argsbuf[3]; |
1484 | int which; |
1485 | int who; |
1486 | int priority; |
1487 | |
1488 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
1489 | if (!args) { |
1490 | goto exit; |
1491 | } |
1492 | which = _PyLong_AsInt(args[0]); |
1493 | if (which == -1 && PyErr_Occurred()) { |
1494 | goto exit; |
1495 | } |
1496 | who = _PyLong_AsInt(args[1]); |
1497 | if (who == -1 && PyErr_Occurred()) { |
1498 | goto exit; |
1499 | } |
1500 | priority = _PyLong_AsInt(args[2]); |
1501 | if (priority == -1 && PyErr_Occurred()) { |
1502 | goto exit; |
1503 | } |
1504 | return_value = os_setpriority_impl(module, which, who, priority); |
1505 | |
1506 | exit: |
1507 | return return_value; |
1508 | } |
1509 | |
1510 | #endif /* defined(HAVE_SETPRIORITY) */ |
1511 | |
1512 | PyDoc_STRVAR(os_rename__doc__, |
1513 | "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
1514 | "--\n" |
1515 | "\n" |
1516 | "Rename a file or directory.\n" |
1517 | "\n" |
1518 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
1519 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
1520 | " should be relative; the path will then be relative to that directory.\n" |
1521 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
1522 | " If they are unavailable, using them will raise a NotImplementedError." ); |
1523 | |
1524 | #define OS_RENAME_METHODDEF \ |
1525 | {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__}, |
1526 | |
1527 | static PyObject * |
1528 | os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
1529 | int dst_dir_fd); |
1530 | |
1531 | static PyObject * |
1532 | os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1533 | { |
1534 | PyObject *return_value = NULL; |
1535 | static const char * const _keywords[] = {"src" , "dst" , "src_dir_fd" , "dst_dir_fd" , NULL}; |
1536 | static _PyArg_Parser _parser = {NULL, _keywords, "rename" , 0}; |
1537 | PyObject *argsbuf[4]; |
1538 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1539 | path_t src = PATH_T_INITIALIZE("rename" , "src" , 0, 0); |
1540 | path_t dst = PATH_T_INITIALIZE("rename" , "dst" , 0, 0); |
1541 | int src_dir_fd = DEFAULT_DIR_FD; |
1542 | int dst_dir_fd = DEFAULT_DIR_FD; |
1543 | |
1544 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
1545 | if (!args) { |
1546 | goto exit; |
1547 | } |
1548 | if (!path_converter(args[0], &src)) { |
1549 | goto exit; |
1550 | } |
1551 | if (!path_converter(args[1], &dst)) { |
1552 | goto exit; |
1553 | } |
1554 | if (!noptargs) { |
1555 | goto skip_optional_kwonly; |
1556 | } |
1557 | if (args[2]) { |
1558 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
1559 | goto exit; |
1560 | } |
1561 | if (!--noptargs) { |
1562 | goto skip_optional_kwonly; |
1563 | } |
1564 | } |
1565 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
1566 | goto exit; |
1567 | } |
1568 | skip_optional_kwonly: |
1569 | return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
1570 | |
1571 | exit: |
1572 | /* Cleanup for src */ |
1573 | path_cleanup(&src); |
1574 | /* Cleanup for dst */ |
1575 | path_cleanup(&dst); |
1576 | |
1577 | return return_value; |
1578 | } |
1579 | |
1580 | PyDoc_STRVAR(os_replace__doc__, |
1581 | "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" |
1582 | "--\n" |
1583 | "\n" |
1584 | "Rename a file or directory, overwriting the destination.\n" |
1585 | "\n" |
1586 | "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" |
1587 | " descriptor open to a directory, and the respective path string (src or dst)\n" |
1588 | " should be relative; the path will then be relative to that directory.\n" |
1589 | "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" |
1590 | " If they are unavailable, using them will raise a NotImplementedError." ); |
1591 | |
1592 | #define OS_REPLACE_METHODDEF \ |
1593 | {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__}, |
1594 | |
1595 | static PyObject * |
1596 | os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd, |
1597 | int dst_dir_fd); |
1598 | |
1599 | static PyObject * |
1600 | os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1601 | { |
1602 | PyObject *return_value = NULL; |
1603 | static const char * const _keywords[] = {"src" , "dst" , "src_dir_fd" , "dst_dir_fd" , NULL}; |
1604 | static _PyArg_Parser _parser = {NULL, _keywords, "replace" , 0}; |
1605 | PyObject *argsbuf[4]; |
1606 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
1607 | path_t src = PATH_T_INITIALIZE("replace" , "src" , 0, 0); |
1608 | path_t dst = PATH_T_INITIALIZE("replace" , "dst" , 0, 0); |
1609 | int src_dir_fd = DEFAULT_DIR_FD; |
1610 | int dst_dir_fd = DEFAULT_DIR_FD; |
1611 | |
1612 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
1613 | if (!args) { |
1614 | goto exit; |
1615 | } |
1616 | if (!path_converter(args[0], &src)) { |
1617 | goto exit; |
1618 | } |
1619 | if (!path_converter(args[1], &dst)) { |
1620 | goto exit; |
1621 | } |
1622 | if (!noptargs) { |
1623 | goto skip_optional_kwonly; |
1624 | } |
1625 | if (args[2]) { |
1626 | if (!dir_fd_converter(args[2], &src_dir_fd)) { |
1627 | goto exit; |
1628 | } |
1629 | if (!--noptargs) { |
1630 | goto skip_optional_kwonly; |
1631 | } |
1632 | } |
1633 | if (!dir_fd_converter(args[3], &dst_dir_fd)) { |
1634 | goto exit; |
1635 | } |
1636 | skip_optional_kwonly: |
1637 | return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); |
1638 | |
1639 | exit: |
1640 | /* Cleanup for src */ |
1641 | path_cleanup(&src); |
1642 | /* Cleanup for dst */ |
1643 | path_cleanup(&dst); |
1644 | |
1645 | return return_value; |
1646 | } |
1647 | |
1648 | PyDoc_STRVAR(os_rmdir__doc__, |
1649 | "rmdir($module, /, path, *, dir_fd=None)\n" |
1650 | "--\n" |
1651 | "\n" |
1652 | "Remove a directory.\n" |
1653 | "\n" |
1654 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1655 | " and path should be relative; path will then be relative to that directory.\n" |
1656 | "dir_fd may not be implemented on your platform.\n" |
1657 | " If it is unavailable, using it will raise a NotImplementedError." ); |
1658 | |
1659 | #define OS_RMDIR_METHODDEF \ |
1660 | {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__}, |
1661 | |
1662 | static PyObject * |
1663 | os_rmdir_impl(PyObject *module, path_t *path, int dir_fd); |
1664 | |
1665 | static PyObject * |
1666 | os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1667 | { |
1668 | PyObject *return_value = NULL; |
1669 | static const char * const _keywords[] = {"path" , "dir_fd" , NULL}; |
1670 | static _PyArg_Parser _parser = {NULL, _keywords, "rmdir" , 0}; |
1671 | PyObject *argsbuf[2]; |
1672 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
1673 | path_t path = PATH_T_INITIALIZE("rmdir" , "path" , 0, 0); |
1674 | int dir_fd = DEFAULT_DIR_FD; |
1675 | |
1676 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
1677 | if (!args) { |
1678 | goto exit; |
1679 | } |
1680 | if (!path_converter(args[0], &path)) { |
1681 | goto exit; |
1682 | } |
1683 | if (!noptargs) { |
1684 | goto skip_optional_kwonly; |
1685 | } |
1686 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
1687 | goto exit; |
1688 | } |
1689 | skip_optional_kwonly: |
1690 | return_value = os_rmdir_impl(module, &path, dir_fd); |
1691 | |
1692 | exit: |
1693 | /* Cleanup for path */ |
1694 | path_cleanup(&path); |
1695 | |
1696 | return return_value; |
1697 | } |
1698 | |
1699 | #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS) |
1700 | |
1701 | PyDoc_STRVAR(os_system__doc__, |
1702 | "system($module, /, command)\n" |
1703 | "--\n" |
1704 | "\n" |
1705 | "Execute the command in a subshell." ); |
1706 | |
1707 | #define OS_SYSTEM_METHODDEF \ |
1708 | {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
1709 | |
1710 | static long |
1711 | os_system_impl(PyObject *module, const Py_UNICODE *command); |
1712 | |
1713 | static PyObject * |
1714 | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1715 | { |
1716 | PyObject *return_value = NULL; |
1717 | static const char * const _keywords[] = {"command" , NULL}; |
1718 | static _PyArg_Parser _parser = {NULL, _keywords, "system" , 0}; |
1719 | PyObject *argsbuf[1]; |
1720 | const Py_UNICODE *command; |
1721 | long _return_value; |
1722 | |
1723 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
1724 | if (!args) { |
1725 | goto exit; |
1726 | } |
1727 | if (!PyUnicode_Check(args[0])) { |
1728 | _PyArg_BadArgument("system" , "argument 'command'" , "str" , args[0]); |
1729 | goto exit; |
1730 | } |
1731 | #if USE_UNICODE_WCHAR_CACHE |
1732 | command = _PyUnicode_AsUnicode(args[0]); |
1733 | #else /* USE_UNICODE_WCHAR_CACHE */ |
1734 | command = PyUnicode_AsWideCharString(args[0], NULL); |
1735 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
1736 | if (command == NULL) { |
1737 | goto exit; |
1738 | } |
1739 | _return_value = os_system_impl(module, command); |
1740 | if ((_return_value == -1) && PyErr_Occurred()) { |
1741 | goto exit; |
1742 | } |
1743 | return_value = PyLong_FromLong(_return_value); |
1744 | |
1745 | exit: |
1746 | /* Cleanup for command */ |
1747 | #if !USE_UNICODE_WCHAR_CACHE |
1748 | PyMem_Free((void *)command); |
1749 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
1750 | |
1751 | return return_value; |
1752 | } |
1753 | |
1754 | #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */ |
1755 | |
1756 | #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) |
1757 | |
1758 | PyDoc_STRVAR(os_system__doc__, |
1759 | "system($module, /, command)\n" |
1760 | "--\n" |
1761 | "\n" |
1762 | "Execute the command in a subshell." ); |
1763 | |
1764 | #define OS_SYSTEM_METHODDEF \ |
1765 | {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__}, |
1766 | |
1767 | static long |
1768 | os_system_impl(PyObject *module, PyObject *command); |
1769 | |
1770 | static PyObject * |
1771 | os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1772 | { |
1773 | PyObject *return_value = NULL; |
1774 | static const char * const _keywords[] = {"command" , NULL}; |
1775 | static _PyArg_Parser _parser = {NULL, _keywords, "system" , 0}; |
1776 | PyObject *argsbuf[1]; |
1777 | PyObject *command = NULL; |
1778 | long _return_value; |
1779 | |
1780 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
1781 | if (!args) { |
1782 | goto exit; |
1783 | } |
1784 | if (!PyUnicode_FSConverter(args[0], &command)) { |
1785 | goto exit; |
1786 | } |
1787 | _return_value = os_system_impl(module, command); |
1788 | if ((_return_value == -1) && PyErr_Occurred()) { |
1789 | goto exit; |
1790 | } |
1791 | return_value = PyLong_FromLong(_return_value); |
1792 | |
1793 | exit: |
1794 | /* Cleanup for command */ |
1795 | Py_XDECREF(command); |
1796 | |
1797 | return return_value; |
1798 | } |
1799 | |
1800 | #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ |
1801 | |
1802 | PyDoc_STRVAR(os_umask__doc__, |
1803 | "umask($module, mask, /)\n" |
1804 | "--\n" |
1805 | "\n" |
1806 | "Set the current numeric umask and return the previous umask." ); |
1807 | |
1808 | #define OS_UMASK_METHODDEF \ |
1809 | {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__}, |
1810 | |
1811 | static PyObject * |
1812 | os_umask_impl(PyObject *module, int mask); |
1813 | |
1814 | static PyObject * |
1815 | os_umask(PyObject *module, PyObject *arg) |
1816 | { |
1817 | PyObject *return_value = NULL; |
1818 | int mask; |
1819 | |
1820 | mask = _PyLong_AsInt(arg); |
1821 | if (mask == -1 && PyErr_Occurred()) { |
1822 | goto exit; |
1823 | } |
1824 | return_value = os_umask_impl(module, mask); |
1825 | |
1826 | exit: |
1827 | return return_value; |
1828 | } |
1829 | |
1830 | PyDoc_STRVAR(os_unlink__doc__, |
1831 | "unlink($module, /, path, *, dir_fd=None)\n" |
1832 | "--\n" |
1833 | "\n" |
1834 | "Remove a file (same as remove()).\n" |
1835 | "\n" |
1836 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1837 | " and path should be relative; path will then be relative to that directory.\n" |
1838 | "dir_fd may not be implemented on your platform.\n" |
1839 | " If it is unavailable, using it will raise a NotImplementedError." ); |
1840 | |
1841 | #define OS_UNLINK_METHODDEF \ |
1842 | {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__}, |
1843 | |
1844 | static PyObject * |
1845 | os_unlink_impl(PyObject *module, path_t *path, int dir_fd); |
1846 | |
1847 | static PyObject * |
1848 | os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1849 | { |
1850 | PyObject *return_value = NULL; |
1851 | static const char * const _keywords[] = {"path" , "dir_fd" , NULL}; |
1852 | static _PyArg_Parser _parser = {NULL, _keywords, "unlink" , 0}; |
1853 | PyObject *argsbuf[2]; |
1854 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
1855 | path_t path = PATH_T_INITIALIZE("unlink" , "path" , 0, 0); |
1856 | int dir_fd = DEFAULT_DIR_FD; |
1857 | |
1858 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
1859 | if (!args) { |
1860 | goto exit; |
1861 | } |
1862 | if (!path_converter(args[0], &path)) { |
1863 | goto exit; |
1864 | } |
1865 | if (!noptargs) { |
1866 | goto skip_optional_kwonly; |
1867 | } |
1868 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
1869 | goto exit; |
1870 | } |
1871 | skip_optional_kwonly: |
1872 | return_value = os_unlink_impl(module, &path, dir_fd); |
1873 | |
1874 | exit: |
1875 | /* Cleanup for path */ |
1876 | path_cleanup(&path); |
1877 | |
1878 | return return_value; |
1879 | } |
1880 | |
1881 | PyDoc_STRVAR(os_remove__doc__, |
1882 | "remove($module, /, path, *, dir_fd=None)\n" |
1883 | "--\n" |
1884 | "\n" |
1885 | "Remove a file (same as unlink()).\n" |
1886 | "\n" |
1887 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1888 | " and path should be relative; path will then be relative to that directory.\n" |
1889 | "dir_fd may not be implemented on your platform.\n" |
1890 | " If it is unavailable, using it will raise a NotImplementedError." ); |
1891 | |
1892 | #define OS_REMOVE_METHODDEF \ |
1893 | {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__}, |
1894 | |
1895 | static PyObject * |
1896 | os_remove_impl(PyObject *module, path_t *path, int dir_fd); |
1897 | |
1898 | static PyObject * |
1899 | os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1900 | { |
1901 | PyObject *return_value = NULL; |
1902 | static const char * const _keywords[] = {"path" , "dir_fd" , NULL}; |
1903 | static _PyArg_Parser _parser = {NULL, _keywords, "remove" , 0}; |
1904 | PyObject *argsbuf[2]; |
1905 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
1906 | path_t path = PATH_T_INITIALIZE("remove" , "path" , 0, 0); |
1907 | int dir_fd = DEFAULT_DIR_FD; |
1908 | |
1909 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
1910 | if (!args) { |
1911 | goto exit; |
1912 | } |
1913 | if (!path_converter(args[0], &path)) { |
1914 | goto exit; |
1915 | } |
1916 | if (!noptargs) { |
1917 | goto skip_optional_kwonly; |
1918 | } |
1919 | if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
1920 | goto exit; |
1921 | } |
1922 | skip_optional_kwonly: |
1923 | return_value = os_remove_impl(module, &path, dir_fd); |
1924 | |
1925 | exit: |
1926 | /* Cleanup for path */ |
1927 | path_cleanup(&path); |
1928 | |
1929 | return return_value; |
1930 | } |
1931 | |
1932 | #if defined(HAVE_UNAME) |
1933 | |
1934 | PyDoc_STRVAR(os_uname__doc__, |
1935 | "uname($module, /)\n" |
1936 | "--\n" |
1937 | "\n" |
1938 | "Return an object identifying the current operating system.\n" |
1939 | "\n" |
1940 | "The object behaves like a named tuple with the following fields:\n" |
1941 | " (sysname, nodename, release, version, machine)" ); |
1942 | |
1943 | #define OS_UNAME_METHODDEF \ |
1944 | {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, |
1945 | |
1946 | static PyObject * |
1947 | os_uname_impl(PyObject *module); |
1948 | |
1949 | static PyObject * |
1950 | os_uname(PyObject *module, PyObject *Py_UNUSED(ignored)) |
1951 | { |
1952 | return os_uname_impl(module); |
1953 | } |
1954 | |
1955 | #endif /* defined(HAVE_UNAME) */ |
1956 | |
1957 | PyDoc_STRVAR(os_utime__doc__, |
1958 | "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n" |
1959 | " dir_fd=None, follow_symlinks=True)\n" |
1960 | "--\n" |
1961 | "\n" |
1962 | "Set the access and modified time of path.\n" |
1963 | "\n" |
1964 | "path may always be specified as a string.\n" |
1965 | "On some platforms, path may also be specified as an open file descriptor.\n" |
1966 | " If this functionality is unavailable, using it raises an exception.\n" |
1967 | "\n" |
1968 | "If times is not None, it must be a tuple (atime, mtime);\n" |
1969 | " atime and mtime should be expressed as float seconds since the epoch.\n" |
1970 | "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n" |
1971 | " atime_ns and mtime_ns should be expressed as integer nanoseconds\n" |
1972 | " since the epoch.\n" |
1973 | "If times is None and ns is unspecified, utime uses the current time.\n" |
1974 | "Specifying tuples for both times and ns is an error.\n" |
1975 | "\n" |
1976 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
1977 | " and path should be relative; path will then be relative to that directory.\n" |
1978 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
1979 | " link, utime will modify the symbolic link itself instead of the file the\n" |
1980 | " link points to.\n" |
1981 | "It is an error to use dir_fd or follow_symlinks when specifying path\n" |
1982 | " as an open file descriptor.\n" |
1983 | "dir_fd and follow_symlinks may not be available on your platform.\n" |
1984 | " If they are unavailable, using them will raise a NotImplementedError." ); |
1985 | |
1986 | #define OS_UTIME_METHODDEF \ |
1987 | {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__}, |
1988 | |
1989 | static PyObject * |
1990 | os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns, |
1991 | int dir_fd, int follow_symlinks); |
1992 | |
1993 | static PyObject * |
1994 | os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
1995 | { |
1996 | PyObject *return_value = NULL; |
1997 | static const char * const _keywords[] = {"path" , "times" , "ns" , "dir_fd" , "follow_symlinks" , NULL}; |
1998 | static _PyArg_Parser _parser = {NULL, _keywords, "utime" , 0}; |
1999 | PyObject *argsbuf[5]; |
2000 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
2001 | path_t path = PATH_T_INITIALIZE("utime" , "path" , 0, PATH_UTIME_HAVE_FD); |
2002 | PyObject *times = Py_None; |
2003 | PyObject *ns = NULL; |
2004 | int dir_fd = DEFAULT_DIR_FD; |
2005 | int follow_symlinks = 1; |
2006 | |
2007 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
2008 | if (!args) { |
2009 | goto exit; |
2010 | } |
2011 | if (!path_converter(args[0], &path)) { |
2012 | goto exit; |
2013 | } |
2014 | if (!noptargs) { |
2015 | goto skip_optional_pos; |
2016 | } |
2017 | if (args[1]) { |
2018 | times = args[1]; |
2019 | if (!--noptargs) { |
2020 | goto skip_optional_pos; |
2021 | } |
2022 | } |
2023 | skip_optional_pos: |
2024 | if (!noptargs) { |
2025 | goto skip_optional_kwonly; |
2026 | } |
2027 | if (args[2]) { |
2028 | ns = args[2]; |
2029 | if (!--noptargs) { |
2030 | goto skip_optional_kwonly; |
2031 | } |
2032 | } |
2033 | if (args[3]) { |
2034 | if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
2035 | goto exit; |
2036 | } |
2037 | if (!--noptargs) { |
2038 | goto skip_optional_kwonly; |
2039 | } |
2040 | } |
2041 | follow_symlinks = PyObject_IsTrue(args[4]); |
2042 | if (follow_symlinks < 0) { |
2043 | goto exit; |
2044 | } |
2045 | skip_optional_kwonly: |
2046 | return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); |
2047 | |
2048 | exit: |
2049 | /* Cleanup for path */ |
2050 | path_cleanup(&path); |
2051 | |
2052 | return return_value; |
2053 | } |
2054 | |
2055 | PyDoc_STRVAR(os__exit__doc__, |
2056 | "_exit($module, /, status)\n" |
2057 | "--\n" |
2058 | "\n" |
2059 | "Exit to the system with specified status, without normal exit processing." ); |
2060 | |
2061 | #define OS__EXIT_METHODDEF \ |
2062 | {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__}, |
2063 | |
2064 | static PyObject * |
2065 | os__exit_impl(PyObject *module, int status); |
2066 | |
2067 | static PyObject * |
2068 | os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2069 | { |
2070 | PyObject *return_value = NULL; |
2071 | static const char * const _keywords[] = {"status" , NULL}; |
2072 | static _PyArg_Parser _parser = {NULL, _keywords, "_exit" , 0}; |
2073 | PyObject *argsbuf[1]; |
2074 | int status; |
2075 | |
2076 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
2077 | if (!args) { |
2078 | goto exit; |
2079 | } |
2080 | status = _PyLong_AsInt(args[0]); |
2081 | if (status == -1 && PyErr_Occurred()) { |
2082 | goto exit; |
2083 | } |
2084 | return_value = os__exit_impl(module, status); |
2085 | |
2086 | exit: |
2087 | return return_value; |
2088 | } |
2089 | |
2090 | #if defined(HAVE_EXECV) |
2091 | |
2092 | PyDoc_STRVAR(os_execv__doc__, |
2093 | "execv($module, path, argv, /)\n" |
2094 | "--\n" |
2095 | "\n" |
2096 | "Execute an executable path with arguments, replacing current process.\n" |
2097 | "\n" |
2098 | " path\n" |
2099 | " Path of executable file.\n" |
2100 | " argv\n" |
2101 | " Tuple or list of strings." ); |
2102 | |
2103 | #define OS_EXECV_METHODDEF \ |
2104 | {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__}, |
2105 | |
2106 | static PyObject * |
2107 | os_execv_impl(PyObject *module, path_t *path, PyObject *argv); |
2108 | |
2109 | static PyObject * |
2110 | os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2111 | { |
2112 | PyObject *return_value = NULL; |
2113 | path_t path = PATH_T_INITIALIZE("execv" , "path" , 0, 0); |
2114 | PyObject *argv; |
2115 | |
2116 | if (!_PyArg_CheckPositional("execv" , nargs, 2, 2)) { |
2117 | goto exit; |
2118 | } |
2119 | if (!path_converter(args[0], &path)) { |
2120 | goto exit; |
2121 | } |
2122 | argv = args[1]; |
2123 | return_value = os_execv_impl(module, &path, argv); |
2124 | |
2125 | exit: |
2126 | /* Cleanup for path */ |
2127 | path_cleanup(&path); |
2128 | |
2129 | return return_value; |
2130 | } |
2131 | |
2132 | #endif /* defined(HAVE_EXECV) */ |
2133 | |
2134 | #if defined(HAVE_EXECV) |
2135 | |
2136 | PyDoc_STRVAR(os_execve__doc__, |
2137 | "execve($module, /, path, argv, env)\n" |
2138 | "--\n" |
2139 | "\n" |
2140 | "Execute an executable path with arguments, replacing current process.\n" |
2141 | "\n" |
2142 | " path\n" |
2143 | " Path of executable file.\n" |
2144 | " argv\n" |
2145 | " Tuple or list of strings.\n" |
2146 | " env\n" |
2147 | " Dictionary of strings mapping to strings." ); |
2148 | |
2149 | #define OS_EXECVE_METHODDEF \ |
2150 | {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__}, |
2151 | |
2152 | static PyObject * |
2153 | os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env); |
2154 | |
2155 | static PyObject * |
2156 | os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2157 | { |
2158 | PyObject *return_value = NULL; |
2159 | static const char * const _keywords[] = {"path" , "argv" , "env" , NULL}; |
2160 | static _PyArg_Parser _parser = {NULL, _keywords, "execve" , 0}; |
2161 | PyObject *argsbuf[3]; |
2162 | path_t path = PATH_T_INITIALIZE("execve" , "path" , 0, PATH_HAVE_FEXECVE); |
2163 | PyObject *argv; |
2164 | PyObject *env; |
2165 | |
2166 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
2167 | if (!args) { |
2168 | goto exit; |
2169 | } |
2170 | if (!path_converter(args[0], &path)) { |
2171 | goto exit; |
2172 | } |
2173 | argv = args[1]; |
2174 | env = args[2]; |
2175 | return_value = os_execve_impl(module, &path, argv, env); |
2176 | |
2177 | exit: |
2178 | /* Cleanup for path */ |
2179 | path_cleanup(&path); |
2180 | |
2181 | return return_value; |
2182 | } |
2183 | |
2184 | #endif /* defined(HAVE_EXECV) */ |
2185 | |
2186 | #if defined(HAVE_POSIX_SPAWN) |
2187 | |
2188 | PyDoc_STRVAR(os_posix_spawn__doc__, |
2189 | "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n" |
2190 | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
2191 | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
2192 | "--\n" |
2193 | "\n" |
2194 | "Execute the program specified by path in a new process.\n" |
2195 | "\n" |
2196 | " path\n" |
2197 | " Path of executable file.\n" |
2198 | " argv\n" |
2199 | " Tuple or list of strings.\n" |
2200 | " env\n" |
2201 | " Dictionary of strings mapping to strings.\n" |
2202 | " file_actions\n" |
2203 | " A sequence of file action tuples.\n" |
2204 | " setpgroup\n" |
2205 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
2206 | " resetids\n" |
2207 | " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n" |
2208 | " setsid\n" |
2209 | " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
2210 | " setsigmask\n" |
2211 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
2212 | " setsigdef\n" |
2213 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
2214 | " scheduler\n" |
2215 | " A tuple with the scheduler policy (optional) and parameters." ); |
2216 | |
2217 | #define OS_POSIX_SPAWN_METHODDEF \ |
2218 | {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__}, |
2219 | |
2220 | static PyObject * |
2221 | os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv, |
2222 | PyObject *env, PyObject *file_actions, |
2223 | PyObject *setpgroup, int resetids, int setsid, |
2224 | PyObject *setsigmask, PyObject *setsigdef, |
2225 | PyObject *scheduler); |
2226 | |
2227 | static PyObject * |
2228 | os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2229 | { |
2230 | PyObject *return_value = NULL; |
2231 | static const char * const _keywords[] = {"" , "" , "" , "file_actions" , "setpgroup" , "resetids" , "setsid" , "setsigmask" , "setsigdef" , "scheduler" , NULL}; |
2232 | static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawn" , 0}; |
2233 | PyObject *argsbuf[10]; |
2234 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
2235 | path_t path = PATH_T_INITIALIZE("posix_spawn" , "path" , 0, 0); |
2236 | PyObject *argv; |
2237 | PyObject *env; |
2238 | PyObject *file_actions = NULL; |
2239 | PyObject *setpgroup = NULL; |
2240 | int resetids = 0; |
2241 | int setsid = 0; |
2242 | PyObject *setsigmask = NULL; |
2243 | PyObject *setsigdef = NULL; |
2244 | PyObject *scheduler = NULL; |
2245 | |
2246 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
2247 | if (!args) { |
2248 | goto exit; |
2249 | } |
2250 | if (!path_converter(args[0], &path)) { |
2251 | goto exit; |
2252 | } |
2253 | argv = args[1]; |
2254 | env = args[2]; |
2255 | if (!noptargs) { |
2256 | goto skip_optional_kwonly; |
2257 | } |
2258 | if (args[3]) { |
2259 | file_actions = args[3]; |
2260 | if (!--noptargs) { |
2261 | goto skip_optional_kwonly; |
2262 | } |
2263 | } |
2264 | if (args[4]) { |
2265 | setpgroup = args[4]; |
2266 | if (!--noptargs) { |
2267 | goto skip_optional_kwonly; |
2268 | } |
2269 | } |
2270 | if (args[5]) { |
2271 | resetids = _PyLong_AsInt(args[5]); |
2272 | if (resetids == -1 && PyErr_Occurred()) { |
2273 | goto exit; |
2274 | } |
2275 | if (!--noptargs) { |
2276 | goto skip_optional_kwonly; |
2277 | } |
2278 | } |
2279 | if (args[6]) { |
2280 | setsid = _PyLong_AsInt(args[6]); |
2281 | if (setsid == -1 && PyErr_Occurred()) { |
2282 | goto exit; |
2283 | } |
2284 | if (!--noptargs) { |
2285 | goto skip_optional_kwonly; |
2286 | } |
2287 | } |
2288 | if (args[7]) { |
2289 | setsigmask = args[7]; |
2290 | if (!--noptargs) { |
2291 | goto skip_optional_kwonly; |
2292 | } |
2293 | } |
2294 | if (args[8]) { |
2295 | setsigdef = args[8]; |
2296 | if (!--noptargs) { |
2297 | goto skip_optional_kwonly; |
2298 | } |
2299 | } |
2300 | scheduler = args[9]; |
2301 | skip_optional_kwonly: |
2302 | return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
2303 | |
2304 | exit: |
2305 | /* Cleanup for path */ |
2306 | path_cleanup(&path); |
2307 | |
2308 | return return_value; |
2309 | } |
2310 | |
2311 | #endif /* defined(HAVE_POSIX_SPAWN) */ |
2312 | |
2313 | #if defined(HAVE_POSIX_SPAWNP) |
2314 | |
2315 | PyDoc_STRVAR(os_posix_spawnp__doc__, |
2316 | "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n" |
2317 | " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n" |
2318 | " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n" |
2319 | "--\n" |
2320 | "\n" |
2321 | "Execute the program specified by path in a new process.\n" |
2322 | "\n" |
2323 | " path\n" |
2324 | " Path of executable file.\n" |
2325 | " argv\n" |
2326 | " Tuple or list of strings.\n" |
2327 | " env\n" |
2328 | " Dictionary of strings mapping to strings.\n" |
2329 | " file_actions\n" |
2330 | " A sequence of file action tuples.\n" |
2331 | " setpgroup\n" |
2332 | " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n" |
2333 | " resetids\n" |
2334 | " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n" |
2335 | " setsid\n" |
2336 | " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n" |
2337 | " setsigmask\n" |
2338 | " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n" |
2339 | " setsigdef\n" |
2340 | " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n" |
2341 | " scheduler\n" |
2342 | " A tuple with the scheduler policy (optional) and parameters." ); |
2343 | |
2344 | #define OS_POSIX_SPAWNP_METHODDEF \ |
2345 | {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__}, |
2346 | |
2347 | static PyObject * |
2348 | os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv, |
2349 | PyObject *env, PyObject *file_actions, |
2350 | PyObject *setpgroup, int resetids, int setsid, |
2351 | PyObject *setsigmask, PyObject *setsigdef, |
2352 | PyObject *scheduler); |
2353 | |
2354 | static PyObject * |
2355 | os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2356 | { |
2357 | PyObject *return_value = NULL; |
2358 | static const char * const _keywords[] = {"" , "" , "" , "file_actions" , "setpgroup" , "resetids" , "setsid" , "setsigmask" , "setsigdef" , "scheduler" , NULL}; |
2359 | static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawnp" , 0}; |
2360 | PyObject *argsbuf[10]; |
2361 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
2362 | path_t path = PATH_T_INITIALIZE("posix_spawnp" , "path" , 0, 0); |
2363 | PyObject *argv; |
2364 | PyObject *env; |
2365 | PyObject *file_actions = NULL; |
2366 | PyObject *setpgroup = NULL; |
2367 | int resetids = 0; |
2368 | int setsid = 0; |
2369 | PyObject *setsigmask = NULL; |
2370 | PyObject *setsigdef = NULL; |
2371 | PyObject *scheduler = NULL; |
2372 | |
2373 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); |
2374 | if (!args) { |
2375 | goto exit; |
2376 | } |
2377 | if (!path_converter(args[0], &path)) { |
2378 | goto exit; |
2379 | } |
2380 | argv = args[1]; |
2381 | env = args[2]; |
2382 | if (!noptargs) { |
2383 | goto skip_optional_kwonly; |
2384 | } |
2385 | if (args[3]) { |
2386 | file_actions = args[3]; |
2387 | if (!--noptargs) { |
2388 | goto skip_optional_kwonly; |
2389 | } |
2390 | } |
2391 | if (args[4]) { |
2392 | setpgroup = args[4]; |
2393 | if (!--noptargs) { |
2394 | goto skip_optional_kwonly; |
2395 | } |
2396 | } |
2397 | if (args[5]) { |
2398 | resetids = _PyLong_AsInt(args[5]); |
2399 | if (resetids == -1 && PyErr_Occurred()) { |
2400 | goto exit; |
2401 | } |
2402 | if (!--noptargs) { |
2403 | goto skip_optional_kwonly; |
2404 | } |
2405 | } |
2406 | if (args[6]) { |
2407 | setsid = _PyLong_AsInt(args[6]); |
2408 | if (setsid == -1 && PyErr_Occurred()) { |
2409 | goto exit; |
2410 | } |
2411 | if (!--noptargs) { |
2412 | goto skip_optional_kwonly; |
2413 | } |
2414 | } |
2415 | if (args[7]) { |
2416 | setsigmask = args[7]; |
2417 | if (!--noptargs) { |
2418 | goto skip_optional_kwonly; |
2419 | } |
2420 | } |
2421 | if (args[8]) { |
2422 | setsigdef = args[8]; |
2423 | if (!--noptargs) { |
2424 | goto skip_optional_kwonly; |
2425 | } |
2426 | } |
2427 | scheduler = args[9]; |
2428 | skip_optional_kwonly: |
2429 | return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler); |
2430 | |
2431 | exit: |
2432 | /* Cleanup for path */ |
2433 | path_cleanup(&path); |
2434 | |
2435 | return return_value; |
2436 | } |
2437 | |
2438 | #endif /* defined(HAVE_POSIX_SPAWNP) */ |
2439 | |
2440 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
2441 | |
2442 | PyDoc_STRVAR(os_spawnv__doc__, |
2443 | "spawnv($module, mode, path, argv, /)\n" |
2444 | "--\n" |
2445 | "\n" |
2446 | "Execute the program specified by path in a new process.\n" |
2447 | "\n" |
2448 | " mode\n" |
2449 | " Mode of process creation.\n" |
2450 | " path\n" |
2451 | " Path of executable file.\n" |
2452 | " argv\n" |
2453 | " Tuple or list of strings." ); |
2454 | |
2455 | #define OS_SPAWNV_METHODDEF \ |
2456 | {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__}, |
2457 | |
2458 | static PyObject * |
2459 | os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv); |
2460 | |
2461 | static PyObject * |
2462 | os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2463 | { |
2464 | PyObject *return_value = NULL; |
2465 | int mode; |
2466 | path_t path = PATH_T_INITIALIZE("spawnv" , "path" , 0, 0); |
2467 | PyObject *argv; |
2468 | |
2469 | if (!_PyArg_CheckPositional("spawnv" , nargs, 3, 3)) { |
2470 | goto exit; |
2471 | } |
2472 | mode = _PyLong_AsInt(args[0]); |
2473 | if (mode == -1 && PyErr_Occurred()) { |
2474 | goto exit; |
2475 | } |
2476 | if (!path_converter(args[1], &path)) { |
2477 | goto exit; |
2478 | } |
2479 | argv = args[2]; |
2480 | return_value = os_spawnv_impl(module, mode, &path, argv); |
2481 | |
2482 | exit: |
2483 | /* Cleanup for path */ |
2484 | path_cleanup(&path); |
2485 | |
2486 | return return_value; |
2487 | } |
2488 | |
2489 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
2490 | |
2491 | #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) |
2492 | |
2493 | PyDoc_STRVAR(os_spawnve__doc__, |
2494 | "spawnve($module, mode, path, argv, env, /)\n" |
2495 | "--\n" |
2496 | "\n" |
2497 | "Execute the program specified by path in a new process.\n" |
2498 | "\n" |
2499 | " mode\n" |
2500 | " Mode of process creation.\n" |
2501 | " path\n" |
2502 | " Path of executable file.\n" |
2503 | " argv\n" |
2504 | " Tuple or list of strings.\n" |
2505 | " env\n" |
2506 | " Dictionary of strings mapping to strings." ); |
2507 | |
2508 | #define OS_SPAWNVE_METHODDEF \ |
2509 | {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__}, |
2510 | |
2511 | static PyObject * |
2512 | os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv, |
2513 | PyObject *env); |
2514 | |
2515 | static PyObject * |
2516 | os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2517 | { |
2518 | PyObject *return_value = NULL; |
2519 | int mode; |
2520 | path_t path = PATH_T_INITIALIZE("spawnve" , "path" , 0, 0); |
2521 | PyObject *argv; |
2522 | PyObject *env; |
2523 | |
2524 | if (!_PyArg_CheckPositional("spawnve" , nargs, 4, 4)) { |
2525 | goto exit; |
2526 | } |
2527 | mode = _PyLong_AsInt(args[0]); |
2528 | if (mode == -1 && PyErr_Occurred()) { |
2529 | goto exit; |
2530 | } |
2531 | if (!path_converter(args[1], &path)) { |
2532 | goto exit; |
2533 | } |
2534 | argv = args[2]; |
2535 | env = args[3]; |
2536 | return_value = os_spawnve_impl(module, mode, &path, argv, env); |
2537 | |
2538 | exit: |
2539 | /* Cleanup for path */ |
2540 | path_cleanup(&path); |
2541 | |
2542 | return return_value; |
2543 | } |
2544 | |
2545 | #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */ |
2546 | |
2547 | #if defined(HAVE_FORK) |
2548 | |
2549 | PyDoc_STRVAR(os_register_at_fork__doc__, |
2550 | "register_at_fork($module, /, *, before=<unrepresentable>,\n" |
2551 | " after_in_child=<unrepresentable>,\n" |
2552 | " after_in_parent=<unrepresentable>)\n" |
2553 | "--\n" |
2554 | "\n" |
2555 | "Register callables to be called when forking a new process.\n" |
2556 | "\n" |
2557 | " before\n" |
2558 | " A callable to be called in the parent before the fork() syscall.\n" |
2559 | " after_in_child\n" |
2560 | " A callable to be called in the child after fork().\n" |
2561 | " after_in_parent\n" |
2562 | " A callable to be called in the parent after fork().\n" |
2563 | "\n" |
2564 | "\'before\' callbacks are called in reverse order.\n" |
2565 | "\'after_in_child\' and \'after_in_parent\' callbacks are called in order." ); |
2566 | |
2567 | #define OS_REGISTER_AT_FORK_METHODDEF \ |
2568 | {"register_at_fork", (PyCFunction)(void(*)(void))os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__}, |
2569 | |
2570 | static PyObject * |
2571 | os_register_at_fork_impl(PyObject *module, PyObject *before, |
2572 | PyObject *after_in_child, PyObject *after_in_parent); |
2573 | |
2574 | static PyObject * |
2575 | os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2576 | { |
2577 | PyObject *return_value = NULL; |
2578 | static const char * const _keywords[] = {"before" , "after_in_child" , "after_in_parent" , NULL}; |
2579 | static _PyArg_Parser _parser = {NULL, _keywords, "register_at_fork" , 0}; |
2580 | PyObject *argsbuf[3]; |
2581 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
2582 | PyObject *before = NULL; |
2583 | PyObject *after_in_child = NULL; |
2584 | PyObject *after_in_parent = NULL; |
2585 | |
2586 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
2587 | if (!args) { |
2588 | goto exit; |
2589 | } |
2590 | if (!noptargs) { |
2591 | goto skip_optional_kwonly; |
2592 | } |
2593 | if (args[0]) { |
2594 | before = args[0]; |
2595 | if (!--noptargs) { |
2596 | goto skip_optional_kwonly; |
2597 | } |
2598 | } |
2599 | if (args[1]) { |
2600 | after_in_child = args[1]; |
2601 | if (!--noptargs) { |
2602 | goto skip_optional_kwonly; |
2603 | } |
2604 | } |
2605 | after_in_parent = args[2]; |
2606 | skip_optional_kwonly: |
2607 | return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent); |
2608 | |
2609 | exit: |
2610 | return return_value; |
2611 | } |
2612 | |
2613 | #endif /* defined(HAVE_FORK) */ |
2614 | |
2615 | #if defined(HAVE_FORK1) |
2616 | |
2617 | PyDoc_STRVAR(os_fork1__doc__, |
2618 | "fork1($module, /)\n" |
2619 | "--\n" |
2620 | "\n" |
2621 | "Fork a child process with a single multiplexed (i.e., not bound) thread.\n" |
2622 | "\n" |
2623 | "Return 0 to child process and PID of child to parent process." ); |
2624 | |
2625 | #define OS_FORK1_METHODDEF \ |
2626 | {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, |
2627 | |
2628 | static PyObject * |
2629 | os_fork1_impl(PyObject *module); |
2630 | |
2631 | static PyObject * |
2632 | os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored)) |
2633 | { |
2634 | return os_fork1_impl(module); |
2635 | } |
2636 | |
2637 | #endif /* defined(HAVE_FORK1) */ |
2638 | |
2639 | #if defined(HAVE_FORK) |
2640 | |
2641 | PyDoc_STRVAR(os_fork__doc__, |
2642 | "fork($module, /)\n" |
2643 | "--\n" |
2644 | "\n" |
2645 | "Fork a child process.\n" |
2646 | "\n" |
2647 | "Return 0 to child process and PID of child to parent process." ); |
2648 | |
2649 | #define OS_FORK_METHODDEF \ |
2650 | {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, |
2651 | |
2652 | static PyObject * |
2653 | os_fork_impl(PyObject *module); |
2654 | |
2655 | static PyObject * |
2656 | os_fork(PyObject *module, PyObject *Py_UNUSED(ignored)) |
2657 | { |
2658 | return os_fork_impl(module); |
2659 | } |
2660 | |
2661 | #endif /* defined(HAVE_FORK) */ |
2662 | |
2663 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
2664 | |
2665 | PyDoc_STRVAR(os_sched_get_priority_max__doc__, |
2666 | "sched_get_priority_max($module, /, policy)\n" |
2667 | "--\n" |
2668 | "\n" |
2669 | "Get the maximum scheduling priority for policy." ); |
2670 | |
2671 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ |
2672 | {"sched_get_priority_max", (PyCFunction)(void(*)(void))os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__}, |
2673 | |
2674 | static PyObject * |
2675 | os_sched_get_priority_max_impl(PyObject *module, int policy); |
2676 | |
2677 | static PyObject * |
2678 | os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2679 | { |
2680 | PyObject *return_value = NULL; |
2681 | static const char * const _keywords[] = {"policy" , NULL}; |
2682 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_max" , 0}; |
2683 | PyObject *argsbuf[1]; |
2684 | int policy; |
2685 | |
2686 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
2687 | if (!args) { |
2688 | goto exit; |
2689 | } |
2690 | policy = _PyLong_AsInt(args[0]); |
2691 | if (policy == -1 && PyErr_Occurred()) { |
2692 | goto exit; |
2693 | } |
2694 | return_value = os_sched_get_priority_max_impl(module, policy); |
2695 | |
2696 | exit: |
2697 | return return_value; |
2698 | } |
2699 | |
2700 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
2701 | |
2702 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) |
2703 | |
2704 | PyDoc_STRVAR(os_sched_get_priority_min__doc__, |
2705 | "sched_get_priority_min($module, /, policy)\n" |
2706 | "--\n" |
2707 | "\n" |
2708 | "Get the minimum scheduling priority for policy." ); |
2709 | |
2710 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ |
2711 | {"sched_get_priority_min", (PyCFunction)(void(*)(void))os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__}, |
2712 | |
2713 | static PyObject * |
2714 | os_sched_get_priority_min_impl(PyObject *module, int policy); |
2715 | |
2716 | static PyObject * |
2717 | os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
2718 | { |
2719 | PyObject *return_value = NULL; |
2720 | static const char * const _keywords[] = {"policy" , NULL}; |
2721 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_min" , 0}; |
2722 | PyObject *argsbuf[1]; |
2723 | int policy; |
2724 | |
2725 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
2726 | if (!args) { |
2727 | goto exit; |
2728 | } |
2729 | policy = _PyLong_AsInt(args[0]); |
2730 | if (policy == -1 && PyErr_Occurred()) { |
2731 | goto exit; |
2732 | } |
2733 | return_value = os_sched_get_priority_min_impl(module, policy); |
2734 | |
2735 | exit: |
2736 | return return_value; |
2737 | } |
2738 | |
2739 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */ |
2740 | |
2741 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
2742 | |
2743 | PyDoc_STRVAR(os_sched_getscheduler__doc__, |
2744 | "sched_getscheduler($module, pid, /)\n" |
2745 | "--\n" |
2746 | "\n" |
2747 | "Get the scheduling policy for the process identified by pid.\n" |
2748 | "\n" |
2749 | "Passing 0 for pid returns the scheduling policy for the calling process." ); |
2750 | |
2751 | #define OS_SCHED_GETSCHEDULER_METHODDEF \ |
2752 | {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__}, |
2753 | |
2754 | static PyObject * |
2755 | os_sched_getscheduler_impl(PyObject *module, pid_t pid); |
2756 | |
2757 | static PyObject * |
2758 | os_sched_getscheduler(PyObject *module, PyObject *arg) |
2759 | { |
2760 | PyObject *return_value = NULL; |
2761 | pid_t pid; |
2762 | |
2763 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler" , &pid)) { |
2764 | goto exit; |
2765 | } |
2766 | return_value = os_sched_getscheduler_impl(module, pid); |
2767 | |
2768 | exit: |
2769 | return return_value; |
2770 | } |
2771 | |
2772 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
2773 | |
2774 | #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) |
2775 | |
2776 | PyDoc_STRVAR(os_sched_param__doc__, |
2777 | "sched_param(sched_priority)\n" |
2778 | "--\n" |
2779 | "\n" |
2780 | "Currently has only one field: sched_priority\n" |
2781 | "\n" |
2782 | " sched_priority\n" |
2783 | " A scheduling parameter." ); |
2784 | |
2785 | static PyObject * |
2786 | os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); |
2787 | |
2788 | static PyObject * |
2789 | os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
2790 | { |
2791 | PyObject *return_value = NULL; |
2792 | static const char * const _keywords[] = {"sched_priority" , NULL}; |
2793 | static _PyArg_Parser _parser = {NULL, _keywords, "sched_param" , 0}; |
2794 | PyObject *argsbuf[1]; |
2795 | PyObject * const *fastargs; |
2796 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
2797 | PyObject *sched_priority; |
2798 | |
2799 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); |
2800 | if (!fastargs) { |
2801 | goto exit; |
2802 | } |
2803 | sched_priority = fastargs[0]; |
2804 | return_value = os_sched_param_impl(type, sched_priority); |
2805 | |
2806 | exit: |
2807 | return return_value; |
2808 | } |
2809 | |
2810 | #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */ |
2811 | |
2812 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) |
2813 | |
2814 | PyDoc_STRVAR(os_sched_setscheduler__doc__, |
2815 | "sched_setscheduler($module, pid, policy, param, /)\n" |
2816 | "--\n" |
2817 | "\n" |
2818 | "Set the scheduling policy for the process identified by pid.\n" |
2819 | "\n" |
2820 | "If pid is 0, the calling process is changed.\n" |
2821 | "param is an instance of sched_param." ); |
2822 | |
2823 | #define OS_SCHED_SETSCHEDULER_METHODDEF \ |
2824 | {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__}, |
2825 | |
2826 | static PyObject * |
2827 | os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy, |
2828 | PyObject *param_obj); |
2829 | |
2830 | static PyObject * |
2831 | os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2832 | { |
2833 | PyObject *return_value = NULL; |
2834 | pid_t pid; |
2835 | int policy; |
2836 | PyObject *param_obj; |
2837 | |
2838 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO:sched_setscheduler" , |
2839 | &pid, &policy, ¶m_obj)) { |
2840 | goto exit; |
2841 | } |
2842 | return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj); |
2843 | |
2844 | exit: |
2845 | return return_value; |
2846 | } |
2847 | |
2848 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */ |
2849 | |
2850 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
2851 | |
2852 | PyDoc_STRVAR(os_sched_getparam__doc__, |
2853 | "sched_getparam($module, pid, /)\n" |
2854 | "--\n" |
2855 | "\n" |
2856 | "Returns scheduling parameters for the process identified by pid.\n" |
2857 | "\n" |
2858 | "If pid is 0, returns parameters for the calling process.\n" |
2859 | "Return value is an instance of sched_param." ); |
2860 | |
2861 | #define OS_SCHED_GETPARAM_METHODDEF \ |
2862 | {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__}, |
2863 | |
2864 | static PyObject * |
2865 | os_sched_getparam_impl(PyObject *module, pid_t pid); |
2866 | |
2867 | static PyObject * |
2868 | os_sched_getparam(PyObject *module, PyObject *arg) |
2869 | { |
2870 | PyObject *return_value = NULL; |
2871 | pid_t pid; |
2872 | |
2873 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam" , &pid)) { |
2874 | goto exit; |
2875 | } |
2876 | return_value = os_sched_getparam_impl(module, pid); |
2877 | |
2878 | exit: |
2879 | return return_value; |
2880 | } |
2881 | |
2882 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
2883 | |
2884 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) |
2885 | |
2886 | PyDoc_STRVAR(os_sched_setparam__doc__, |
2887 | "sched_setparam($module, pid, param, /)\n" |
2888 | "--\n" |
2889 | "\n" |
2890 | "Set scheduling parameters for the process identified by pid.\n" |
2891 | "\n" |
2892 | "If pid is 0, sets parameters for the calling process.\n" |
2893 | "param should be an instance of sched_param." ); |
2894 | |
2895 | #define OS_SCHED_SETPARAM_METHODDEF \ |
2896 | {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__}, |
2897 | |
2898 | static PyObject * |
2899 | os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj); |
2900 | |
2901 | static PyObject * |
2902 | os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2903 | { |
2904 | PyObject *return_value = NULL; |
2905 | pid_t pid; |
2906 | PyObject *param_obj; |
2907 | |
2908 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setparam" , |
2909 | &pid, ¶m_obj)) { |
2910 | goto exit; |
2911 | } |
2912 | return_value = os_sched_setparam_impl(module, pid, param_obj); |
2913 | |
2914 | exit: |
2915 | return return_value; |
2916 | } |
2917 | |
2918 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */ |
2919 | |
2920 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) |
2921 | |
2922 | PyDoc_STRVAR(os_sched_rr_get_interval__doc__, |
2923 | "sched_rr_get_interval($module, pid, /)\n" |
2924 | "--\n" |
2925 | "\n" |
2926 | "Return the round-robin quantum for the process identified by pid, in seconds.\n" |
2927 | "\n" |
2928 | "Value returned is a float." ); |
2929 | |
2930 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ |
2931 | {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__}, |
2932 | |
2933 | static double |
2934 | os_sched_rr_get_interval_impl(PyObject *module, pid_t pid); |
2935 | |
2936 | static PyObject * |
2937 | os_sched_rr_get_interval(PyObject *module, PyObject *arg) |
2938 | { |
2939 | PyObject *return_value = NULL; |
2940 | pid_t pid; |
2941 | double _return_value; |
2942 | |
2943 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval" , &pid)) { |
2944 | goto exit; |
2945 | } |
2946 | _return_value = os_sched_rr_get_interval_impl(module, pid); |
2947 | if ((_return_value == -1.0) && PyErr_Occurred()) { |
2948 | goto exit; |
2949 | } |
2950 | return_value = PyFloat_FromDouble(_return_value); |
2951 | |
2952 | exit: |
2953 | return return_value; |
2954 | } |
2955 | |
2956 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */ |
2957 | |
2958 | #if defined(HAVE_SCHED_H) |
2959 | |
2960 | PyDoc_STRVAR(os_sched_yield__doc__, |
2961 | "sched_yield($module, /)\n" |
2962 | "--\n" |
2963 | "\n" |
2964 | "Voluntarily relinquish the CPU." ); |
2965 | |
2966 | #define OS_SCHED_YIELD_METHODDEF \ |
2967 | {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, |
2968 | |
2969 | static PyObject * |
2970 | os_sched_yield_impl(PyObject *module); |
2971 | |
2972 | static PyObject * |
2973 | os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored)) |
2974 | { |
2975 | return os_sched_yield_impl(module); |
2976 | } |
2977 | |
2978 | #endif /* defined(HAVE_SCHED_H) */ |
2979 | |
2980 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
2981 | |
2982 | PyDoc_STRVAR(os_sched_setaffinity__doc__, |
2983 | "sched_setaffinity($module, pid, mask, /)\n" |
2984 | "--\n" |
2985 | "\n" |
2986 | "Set the CPU affinity of the process identified by pid to mask.\n" |
2987 | "\n" |
2988 | "mask should be an iterable of integers identifying CPUs." ); |
2989 | |
2990 | #define OS_SCHED_SETAFFINITY_METHODDEF \ |
2991 | {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__}, |
2992 | |
2993 | static PyObject * |
2994 | os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask); |
2995 | |
2996 | static PyObject * |
2997 | os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
2998 | { |
2999 | PyObject *return_value = NULL; |
3000 | pid_t pid; |
3001 | PyObject *mask; |
3002 | |
3003 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity" , |
3004 | &pid, &mask)) { |
3005 | goto exit; |
3006 | } |
3007 | return_value = os_sched_setaffinity_impl(module, pid, mask); |
3008 | |
3009 | exit: |
3010 | return return_value; |
3011 | } |
3012 | |
3013 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
3014 | |
3015 | #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) |
3016 | |
3017 | PyDoc_STRVAR(os_sched_getaffinity__doc__, |
3018 | "sched_getaffinity($module, pid, /)\n" |
3019 | "--\n" |
3020 | "\n" |
3021 | "Return the affinity of the process identified by pid (or the current process if zero).\n" |
3022 | "\n" |
3023 | "The affinity is returned as a set of CPU identifiers." ); |
3024 | |
3025 | #define OS_SCHED_GETAFFINITY_METHODDEF \ |
3026 | {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__}, |
3027 | |
3028 | static PyObject * |
3029 | os_sched_getaffinity_impl(PyObject *module, pid_t pid); |
3030 | |
3031 | static PyObject * |
3032 | os_sched_getaffinity(PyObject *module, PyObject *arg) |
3033 | { |
3034 | PyObject *return_value = NULL; |
3035 | pid_t pid; |
3036 | |
3037 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity" , &pid)) { |
3038 | goto exit; |
3039 | } |
3040 | return_value = os_sched_getaffinity_impl(module, pid); |
3041 | |
3042 | exit: |
3043 | return return_value; |
3044 | } |
3045 | |
3046 | #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */ |
3047 | |
3048 | #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) |
3049 | |
3050 | PyDoc_STRVAR(os_openpty__doc__, |
3051 | "openpty($module, /)\n" |
3052 | "--\n" |
3053 | "\n" |
3054 | "Open a pseudo-terminal.\n" |
3055 | "\n" |
3056 | "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" |
3057 | "for both the master and slave ends." ); |
3058 | |
3059 | #define OS_OPENPTY_METHODDEF \ |
3060 | {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, |
3061 | |
3062 | static PyObject * |
3063 | os_openpty_impl(PyObject *module); |
3064 | |
3065 | static PyObject * |
3066 | os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3067 | { |
3068 | return os_openpty_impl(module); |
3069 | } |
3070 | |
3071 | #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ |
3072 | |
3073 | #if defined(HAVE_FORKPTY) |
3074 | |
3075 | PyDoc_STRVAR(os_forkpty__doc__, |
3076 | "forkpty($module, /)\n" |
3077 | "--\n" |
3078 | "\n" |
3079 | "Fork a new process with a new pseudo-terminal as controlling tty.\n" |
3080 | "\n" |
3081 | "Returns a tuple of (pid, master_fd).\n" |
3082 | "Like fork(), return pid of 0 to the child process,\n" |
3083 | "and pid of child to the parent process.\n" |
3084 | "To both, return fd of newly opened pseudo-terminal." ); |
3085 | |
3086 | #define OS_FORKPTY_METHODDEF \ |
3087 | {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, |
3088 | |
3089 | static PyObject * |
3090 | os_forkpty_impl(PyObject *module); |
3091 | |
3092 | static PyObject * |
3093 | os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3094 | { |
3095 | return os_forkpty_impl(module); |
3096 | } |
3097 | |
3098 | #endif /* defined(HAVE_FORKPTY) */ |
3099 | |
3100 | #if defined(HAVE_GETEGID) |
3101 | |
3102 | PyDoc_STRVAR(os_getegid__doc__, |
3103 | "getegid($module, /)\n" |
3104 | "--\n" |
3105 | "\n" |
3106 | "Return the current process\'s effective group id." ); |
3107 | |
3108 | #define OS_GETEGID_METHODDEF \ |
3109 | {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, |
3110 | |
3111 | static PyObject * |
3112 | os_getegid_impl(PyObject *module); |
3113 | |
3114 | static PyObject * |
3115 | os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3116 | { |
3117 | return os_getegid_impl(module); |
3118 | } |
3119 | |
3120 | #endif /* defined(HAVE_GETEGID) */ |
3121 | |
3122 | #if defined(HAVE_GETEUID) |
3123 | |
3124 | PyDoc_STRVAR(os_geteuid__doc__, |
3125 | "geteuid($module, /)\n" |
3126 | "--\n" |
3127 | "\n" |
3128 | "Return the current process\'s effective user id." ); |
3129 | |
3130 | #define OS_GETEUID_METHODDEF \ |
3131 | {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, |
3132 | |
3133 | static PyObject * |
3134 | os_geteuid_impl(PyObject *module); |
3135 | |
3136 | static PyObject * |
3137 | os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3138 | { |
3139 | return os_geteuid_impl(module); |
3140 | } |
3141 | |
3142 | #endif /* defined(HAVE_GETEUID) */ |
3143 | |
3144 | #if defined(HAVE_GETGID) |
3145 | |
3146 | PyDoc_STRVAR(os_getgid__doc__, |
3147 | "getgid($module, /)\n" |
3148 | "--\n" |
3149 | "\n" |
3150 | "Return the current process\'s group id." ); |
3151 | |
3152 | #define OS_GETGID_METHODDEF \ |
3153 | {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, |
3154 | |
3155 | static PyObject * |
3156 | os_getgid_impl(PyObject *module); |
3157 | |
3158 | static PyObject * |
3159 | os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3160 | { |
3161 | return os_getgid_impl(module); |
3162 | } |
3163 | |
3164 | #endif /* defined(HAVE_GETGID) */ |
3165 | |
3166 | #if defined(HAVE_GETPID) |
3167 | |
3168 | PyDoc_STRVAR(os_getpid__doc__, |
3169 | "getpid($module, /)\n" |
3170 | "--\n" |
3171 | "\n" |
3172 | "Return the current process id." ); |
3173 | |
3174 | #define OS_GETPID_METHODDEF \ |
3175 | {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, |
3176 | |
3177 | static PyObject * |
3178 | os_getpid_impl(PyObject *module); |
3179 | |
3180 | static PyObject * |
3181 | os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3182 | { |
3183 | return os_getpid_impl(module); |
3184 | } |
3185 | |
3186 | #endif /* defined(HAVE_GETPID) */ |
3187 | |
3188 | #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__) |
3189 | |
3190 | PyDoc_STRVAR(os_getgrouplist__doc__, |
3191 | "getgrouplist($module, user, group, /)\n" |
3192 | "--\n" |
3193 | "\n" |
3194 | "Returns a list of groups to which a user belongs.\n" |
3195 | "\n" |
3196 | " user\n" |
3197 | " username to lookup\n" |
3198 | " group\n" |
3199 | " base group id of the user" ); |
3200 | |
3201 | #define OS_GETGROUPLIST_METHODDEF \ |
3202 | {"getgrouplist", (PyCFunction)(void(*)(void))os_getgrouplist, METH_FASTCALL, os_getgrouplist__doc__}, |
3203 | |
3204 | static PyObject * |
3205 | os_getgrouplist_impl(PyObject *module, const char *user, int basegid); |
3206 | |
3207 | static PyObject * |
3208 | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3209 | { |
3210 | PyObject *return_value = NULL; |
3211 | const char *user; |
3212 | int basegid; |
3213 | |
3214 | if (!_PyArg_CheckPositional("getgrouplist" , nargs, 2, 2)) { |
3215 | goto exit; |
3216 | } |
3217 | if (!PyUnicode_Check(args[0])) { |
3218 | _PyArg_BadArgument("getgrouplist" , "argument 1" , "str" , args[0]); |
3219 | goto exit; |
3220 | } |
3221 | Py_ssize_t user_length; |
3222 | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
3223 | if (user == NULL) { |
3224 | goto exit; |
3225 | } |
3226 | if (strlen(user) != (size_t)user_length) { |
3227 | PyErr_SetString(PyExc_ValueError, "embedded null character" ); |
3228 | goto exit; |
3229 | } |
3230 | basegid = _PyLong_AsInt(args[1]); |
3231 | if (basegid == -1 && PyErr_Occurred()) { |
3232 | goto exit; |
3233 | } |
3234 | return_value = os_getgrouplist_impl(module, user, basegid); |
3235 | |
3236 | exit: |
3237 | return return_value; |
3238 | } |
3239 | |
3240 | #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */ |
3241 | |
3242 | #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) |
3243 | |
3244 | PyDoc_STRVAR(os_getgrouplist__doc__, |
3245 | "getgrouplist($module, user, group, /)\n" |
3246 | "--\n" |
3247 | "\n" |
3248 | "Returns a list of groups to which a user belongs.\n" |
3249 | "\n" |
3250 | " user\n" |
3251 | " username to lookup\n" |
3252 | " group\n" |
3253 | " base group id of the user" ); |
3254 | |
3255 | #define OS_GETGROUPLIST_METHODDEF \ |
3256 | {"getgrouplist", (PyCFunction)(void(*)(void))os_getgrouplist, METH_FASTCALL, os_getgrouplist__doc__}, |
3257 | |
3258 | static PyObject * |
3259 | os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid); |
3260 | |
3261 | static PyObject * |
3262 | os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3263 | { |
3264 | PyObject *return_value = NULL; |
3265 | const char *user; |
3266 | gid_t basegid; |
3267 | |
3268 | if (!_PyArg_CheckPositional("getgrouplist" , nargs, 2, 2)) { |
3269 | goto exit; |
3270 | } |
3271 | if (!PyUnicode_Check(args[0])) { |
3272 | _PyArg_BadArgument("getgrouplist" , "argument 1" , "str" , args[0]); |
3273 | goto exit; |
3274 | } |
3275 | Py_ssize_t user_length; |
3276 | user = PyUnicode_AsUTF8AndSize(args[0], &user_length); |
3277 | if (user == NULL) { |
3278 | goto exit; |
3279 | } |
3280 | if (strlen(user) != (size_t)user_length) { |
3281 | PyErr_SetString(PyExc_ValueError, "embedded null character" ); |
3282 | goto exit; |
3283 | } |
3284 | if (!_Py_Gid_Converter(args[1], &basegid)) { |
3285 | goto exit; |
3286 | } |
3287 | return_value = os_getgrouplist_impl(module, user, basegid); |
3288 | |
3289 | exit: |
3290 | return return_value; |
3291 | } |
3292 | |
3293 | #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */ |
3294 | |
3295 | #if defined(HAVE_GETGROUPS) |
3296 | |
3297 | PyDoc_STRVAR(os_getgroups__doc__, |
3298 | "getgroups($module, /)\n" |
3299 | "--\n" |
3300 | "\n" |
3301 | "Return list of supplemental group IDs for the process." ); |
3302 | |
3303 | #define OS_GETGROUPS_METHODDEF \ |
3304 | {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, |
3305 | |
3306 | static PyObject * |
3307 | os_getgroups_impl(PyObject *module); |
3308 | |
3309 | static PyObject * |
3310 | os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3311 | { |
3312 | return os_getgroups_impl(module); |
3313 | } |
3314 | |
3315 | #endif /* defined(HAVE_GETGROUPS) */ |
3316 | |
3317 | #if defined(HAVE_INITGROUPS) && defined(__APPLE__) |
3318 | |
3319 | PyDoc_STRVAR(os_initgroups__doc__, |
3320 | "initgroups($module, username, gid, /)\n" |
3321 | "--\n" |
3322 | "\n" |
3323 | "Initialize the group access list.\n" |
3324 | "\n" |
3325 | "Call the system initgroups() to initialize the group access list with all of\n" |
3326 | "the groups of which the specified username is a member, plus the specified\n" |
3327 | "group id." ); |
3328 | |
3329 | #define OS_INITGROUPS_METHODDEF \ |
3330 | {"initgroups", (PyCFunction)(void(*)(void))os_initgroups, METH_FASTCALL, os_initgroups__doc__}, |
3331 | |
3332 | static PyObject * |
3333 | os_initgroups_impl(PyObject *module, PyObject *oname, int gid); |
3334 | |
3335 | static PyObject * |
3336 | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3337 | { |
3338 | PyObject *return_value = NULL; |
3339 | PyObject *oname = NULL; |
3340 | int gid; |
3341 | |
3342 | if (!_PyArg_CheckPositional("initgroups" , nargs, 2, 2)) { |
3343 | goto exit; |
3344 | } |
3345 | if (!PyUnicode_FSConverter(args[0], &oname)) { |
3346 | goto exit; |
3347 | } |
3348 | gid = _PyLong_AsInt(args[1]); |
3349 | if (gid == -1 && PyErr_Occurred()) { |
3350 | goto exit; |
3351 | } |
3352 | return_value = os_initgroups_impl(module, oname, gid); |
3353 | |
3354 | exit: |
3355 | /* Cleanup for oname */ |
3356 | Py_XDECREF(oname); |
3357 | |
3358 | return return_value; |
3359 | } |
3360 | |
3361 | #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */ |
3362 | |
3363 | #if defined(HAVE_INITGROUPS) && !defined(__APPLE__) |
3364 | |
3365 | PyDoc_STRVAR(os_initgroups__doc__, |
3366 | "initgroups($module, username, gid, /)\n" |
3367 | "--\n" |
3368 | "\n" |
3369 | "Initialize the group access list.\n" |
3370 | "\n" |
3371 | "Call the system initgroups() to initialize the group access list with all of\n" |
3372 | "the groups of which the specified username is a member, plus the specified\n" |
3373 | "group id." ); |
3374 | |
3375 | #define OS_INITGROUPS_METHODDEF \ |
3376 | {"initgroups", (PyCFunction)(void(*)(void))os_initgroups, METH_FASTCALL, os_initgroups__doc__}, |
3377 | |
3378 | static PyObject * |
3379 | os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid); |
3380 | |
3381 | static PyObject * |
3382 | os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3383 | { |
3384 | PyObject *return_value = NULL; |
3385 | PyObject *oname = NULL; |
3386 | gid_t gid; |
3387 | |
3388 | if (!_PyArg_CheckPositional("initgroups" , nargs, 2, 2)) { |
3389 | goto exit; |
3390 | } |
3391 | if (!PyUnicode_FSConverter(args[0], &oname)) { |
3392 | goto exit; |
3393 | } |
3394 | if (!_Py_Gid_Converter(args[1], &gid)) { |
3395 | goto exit; |
3396 | } |
3397 | return_value = os_initgroups_impl(module, oname, gid); |
3398 | |
3399 | exit: |
3400 | /* Cleanup for oname */ |
3401 | Py_XDECREF(oname); |
3402 | |
3403 | return return_value; |
3404 | } |
3405 | |
3406 | #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */ |
3407 | |
3408 | #if defined(HAVE_GETPGID) |
3409 | |
3410 | PyDoc_STRVAR(os_getpgid__doc__, |
3411 | "getpgid($module, /, pid)\n" |
3412 | "--\n" |
3413 | "\n" |
3414 | "Call the system call getpgid(), and return the result." ); |
3415 | |
3416 | #define OS_GETPGID_METHODDEF \ |
3417 | {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__}, |
3418 | |
3419 | static PyObject * |
3420 | os_getpgid_impl(PyObject *module, pid_t pid); |
3421 | |
3422 | static PyObject * |
3423 | os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3424 | { |
3425 | PyObject *return_value = NULL; |
3426 | static const char * const _keywords[] = {"pid" , NULL}; |
3427 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid" , _keywords, 0}; |
3428 | pid_t pid; |
3429 | |
3430 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
3431 | &pid)) { |
3432 | goto exit; |
3433 | } |
3434 | return_value = os_getpgid_impl(module, pid); |
3435 | |
3436 | exit: |
3437 | return return_value; |
3438 | } |
3439 | |
3440 | #endif /* defined(HAVE_GETPGID) */ |
3441 | |
3442 | #if defined(HAVE_GETPGRP) |
3443 | |
3444 | PyDoc_STRVAR(os_getpgrp__doc__, |
3445 | "getpgrp($module, /)\n" |
3446 | "--\n" |
3447 | "\n" |
3448 | "Return the current process group id." ); |
3449 | |
3450 | #define OS_GETPGRP_METHODDEF \ |
3451 | {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, |
3452 | |
3453 | static PyObject * |
3454 | os_getpgrp_impl(PyObject *module); |
3455 | |
3456 | static PyObject * |
3457 | os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3458 | { |
3459 | return os_getpgrp_impl(module); |
3460 | } |
3461 | |
3462 | #endif /* defined(HAVE_GETPGRP) */ |
3463 | |
3464 | #if defined(HAVE_SETPGRP) |
3465 | |
3466 | PyDoc_STRVAR(os_setpgrp__doc__, |
3467 | "setpgrp($module, /)\n" |
3468 | "--\n" |
3469 | "\n" |
3470 | "Make the current process the leader of its process group." ); |
3471 | |
3472 | #define OS_SETPGRP_METHODDEF \ |
3473 | {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, |
3474 | |
3475 | static PyObject * |
3476 | os_setpgrp_impl(PyObject *module); |
3477 | |
3478 | static PyObject * |
3479 | os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3480 | { |
3481 | return os_setpgrp_impl(module); |
3482 | } |
3483 | |
3484 | #endif /* defined(HAVE_SETPGRP) */ |
3485 | |
3486 | #if defined(HAVE_GETPPID) |
3487 | |
3488 | PyDoc_STRVAR(os_getppid__doc__, |
3489 | "getppid($module, /)\n" |
3490 | "--\n" |
3491 | "\n" |
3492 | "Return the parent\'s process id.\n" |
3493 | "\n" |
3494 | "If the parent process has already exited, Windows machines will still\n" |
3495 | "return its id; others systems will return the id of the \'init\' process (1)." ); |
3496 | |
3497 | #define OS_GETPPID_METHODDEF \ |
3498 | {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, |
3499 | |
3500 | static PyObject * |
3501 | os_getppid_impl(PyObject *module); |
3502 | |
3503 | static PyObject * |
3504 | os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3505 | { |
3506 | return os_getppid_impl(module); |
3507 | } |
3508 | |
3509 | #endif /* defined(HAVE_GETPPID) */ |
3510 | |
3511 | #if defined(HAVE_GETLOGIN) |
3512 | |
3513 | PyDoc_STRVAR(os_getlogin__doc__, |
3514 | "getlogin($module, /)\n" |
3515 | "--\n" |
3516 | "\n" |
3517 | "Return the actual login name." ); |
3518 | |
3519 | #define OS_GETLOGIN_METHODDEF \ |
3520 | {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, |
3521 | |
3522 | static PyObject * |
3523 | os_getlogin_impl(PyObject *module); |
3524 | |
3525 | static PyObject * |
3526 | os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3527 | { |
3528 | return os_getlogin_impl(module); |
3529 | } |
3530 | |
3531 | #endif /* defined(HAVE_GETLOGIN) */ |
3532 | |
3533 | #if defined(HAVE_GETUID) |
3534 | |
3535 | PyDoc_STRVAR(os_getuid__doc__, |
3536 | "getuid($module, /)\n" |
3537 | "--\n" |
3538 | "\n" |
3539 | "Return the current process\'s user id." ); |
3540 | |
3541 | #define OS_GETUID_METHODDEF \ |
3542 | {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, |
3543 | |
3544 | static PyObject * |
3545 | os_getuid_impl(PyObject *module); |
3546 | |
3547 | static PyObject * |
3548 | os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
3549 | { |
3550 | return os_getuid_impl(module); |
3551 | } |
3552 | |
3553 | #endif /* defined(HAVE_GETUID) */ |
3554 | |
3555 | #if defined(HAVE_KILL) |
3556 | |
3557 | PyDoc_STRVAR(os_kill__doc__, |
3558 | "kill($module, pid, signal, /)\n" |
3559 | "--\n" |
3560 | "\n" |
3561 | "Kill a process with a signal." ); |
3562 | |
3563 | #define OS_KILL_METHODDEF \ |
3564 | {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__}, |
3565 | |
3566 | static PyObject * |
3567 | os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal); |
3568 | |
3569 | static PyObject * |
3570 | os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3571 | { |
3572 | PyObject *return_value = NULL; |
3573 | pid_t pid; |
3574 | Py_ssize_t signal; |
3575 | |
3576 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill" , |
3577 | &pid, &signal)) { |
3578 | goto exit; |
3579 | } |
3580 | return_value = os_kill_impl(module, pid, signal); |
3581 | |
3582 | exit: |
3583 | return return_value; |
3584 | } |
3585 | |
3586 | #endif /* defined(HAVE_KILL) */ |
3587 | |
3588 | #if defined(HAVE_KILLPG) |
3589 | |
3590 | PyDoc_STRVAR(os_killpg__doc__, |
3591 | "killpg($module, pgid, signal, /)\n" |
3592 | "--\n" |
3593 | "\n" |
3594 | "Kill a process group with a signal." ); |
3595 | |
3596 | #define OS_KILLPG_METHODDEF \ |
3597 | {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__}, |
3598 | |
3599 | static PyObject * |
3600 | os_killpg_impl(PyObject *module, pid_t pgid, int signal); |
3601 | |
3602 | static PyObject * |
3603 | os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3604 | { |
3605 | PyObject *return_value = NULL; |
3606 | pid_t pgid; |
3607 | int signal; |
3608 | |
3609 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg" , |
3610 | &pgid, &signal)) { |
3611 | goto exit; |
3612 | } |
3613 | return_value = os_killpg_impl(module, pgid, signal); |
3614 | |
3615 | exit: |
3616 | return return_value; |
3617 | } |
3618 | |
3619 | #endif /* defined(HAVE_KILLPG) */ |
3620 | |
3621 | #if defined(HAVE_PLOCK) |
3622 | |
3623 | PyDoc_STRVAR(os_plock__doc__, |
3624 | "plock($module, op, /)\n" |
3625 | "--\n" |
3626 | "\n" |
3627 | "Lock program segments into memory.\");" ); |
3628 | |
3629 | #define OS_PLOCK_METHODDEF \ |
3630 | {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__}, |
3631 | |
3632 | static PyObject * |
3633 | os_plock_impl(PyObject *module, int op); |
3634 | |
3635 | static PyObject * |
3636 | os_plock(PyObject *module, PyObject *arg) |
3637 | { |
3638 | PyObject *return_value = NULL; |
3639 | int op; |
3640 | |
3641 | op = _PyLong_AsInt(arg); |
3642 | if (op == -1 && PyErr_Occurred()) { |
3643 | goto exit; |
3644 | } |
3645 | return_value = os_plock_impl(module, op); |
3646 | |
3647 | exit: |
3648 | return return_value; |
3649 | } |
3650 | |
3651 | #endif /* defined(HAVE_PLOCK) */ |
3652 | |
3653 | #if defined(HAVE_SETUID) |
3654 | |
3655 | PyDoc_STRVAR(os_setuid__doc__, |
3656 | "setuid($module, uid, /)\n" |
3657 | "--\n" |
3658 | "\n" |
3659 | "Set the current process\'s user id." ); |
3660 | |
3661 | #define OS_SETUID_METHODDEF \ |
3662 | {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__}, |
3663 | |
3664 | static PyObject * |
3665 | os_setuid_impl(PyObject *module, uid_t uid); |
3666 | |
3667 | static PyObject * |
3668 | os_setuid(PyObject *module, PyObject *arg) |
3669 | { |
3670 | PyObject *return_value = NULL; |
3671 | uid_t uid; |
3672 | |
3673 | if (!_Py_Uid_Converter(arg, &uid)) { |
3674 | goto exit; |
3675 | } |
3676 | return_value = os_setuid_impl(module, uid); |
3677 | |
3678 | exit: |
3679 | return return_value; |
3680 | } |
3681 | |
3682 | #endif /* defined(HAVE_SETUID) */ |
3683 | |
3684 | #if defined(HAVE_SETEUID) |
3685 | |
3686 | PyDoc_STRVAR(os_seteuid__doc__, |
3687 | "seteuid($module, euid, /)\n" |
3688 | "--\n" |
3689 | "\n" |
3690 | "Set the current process\'s effective user id." ); |
3691 | |
3692 | #define OS_SETEUID_METHODDEF \ |
3693 | {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__}, |
3694 | |
3695 | static PyObject * |
3696 | os_seteuid_impl(PyObject *module, uid_t euid); |
3697 | |
3698 | static PyObject * |
3699 | os_seteuid(PyObject *module, PyObject *arg) |
3700 | { |
3701 | PyObject *return_value = NULL; |
3702 | uid_t euid; |
3703 | |
3704 | if (!_Py_Uid_Converter(arg, &euid)) { |
3705 | goto exit; |
3706 | } |
3707 | return_value = os_seteuid_impl(module, euid); |
3708 | |
3709 | exit: |
3710 | return return_value; |
3711 | } |
3712 | |
3713 | #endif /* defined(HAVE_SETEUID) */ |
3714 | |
3715 | #if defined(HAVE_SETEGID) |
3716 | |
3717 | PyDoc_STRVAR(os_setegid__doc__, |
3718 | "setegid($module, egid, /)\n" |
3719 | "--\n" |
3720 | "\n" |
3721 | "Set the current process\'s effective group id." ); |
3722 | |
3723 | #define OS_SETEGID_METHODDEF \ |
3724 | {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__}, |
3725 | |
3726 | static PyObject * |
3727 | os_setegid_impl(PyObject *module, gid_t egid); |
3728 | |
3729 | static PyObject * |
3730 | os_setegid(PyObject *module, PyObject *arg) |
3731 | { |
3732 | PyObject *return_value = NULL; |
3733 | gid_t egid; |
3734 | |
3735 | if (!_Py_Gid_Converter(arg, &egid)) { |
3736 | goto exit; |
3737 | } |
3738 | return_value = os_setegid_impl(module, egid); |
3739 | |
3740 | exit: |
3741 | return return_value; |
3742 | } |
3743 | |
3744 | #endif /* defined(HAVE_SETEGID) */ |
3745 | |
3746 | #if defined(HAVE_SETREUID) |
3747 | |
3748 | PyDoc_STRVAR(os_setreuid__doc__, |
3749 | "setreuid($module, ruid, euid, /)\n" |
3750 | "--\n" |
3751 | "\n" |
3752 | "Set the current process\'s real and effective user ids." ); |
3753 | |
3754 | #define OS_SETREUID_METHODDEF \ |
3755 | {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__}, |
3756 | |
3757 | static PyObject * |
3758 | os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid); |
3759 | |
3760 | static PyObject * |
3761 | os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3762 | { |
3763 | PyObject *return_value = NULL; |
3764 | uid_t ruid; |
3765 | uid_t euid; |
3766 | |
3767 | if (!_PyArg_CheckPositional("setreuid" , nargs, 2, 2)) { |
3768 | goto exit; |
3769 | } |
3770 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
3771 | goto exit; |
3772 | } |
3773 | if (!_Py_Uid_Converter(args[1], &euid)) { |
3774 | goto exit; |
3775 | } |
3776 | return_value = os_setreuid_impl(module, ruid, euid); |
3777 | |
3778 | exit: |
3779 | return return_value; |
3780 | } |
3781 | |
3782 | #endif /* defined(HAVE_SETREUID) */ |
3783 | |
3784 | #if defined(HAVE_SETREGID) |
3785 | |
3786 | PyDoc_STRVAR(os_setregid__doc__, |
3787 | "setregid($module, rgid, egid, /)\n" |
3788 | "--\n" |
3789 | "\n" |
3790 | "Set the current process\'s real and effective group ids." ); |
3791 | |
3792 | #define OS_SETREGID_METHODDEF \ |
3793 | {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__}, |
3794 | |
3795 | static PyObject * |
3796 | os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid); |
3797 | |
3798 | static PyObject * |
3799 | os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3800 | { |
3801 | PyObject *return_value = NULL; |
3802 | gid_t rgid; |
3803 | gid_t egid; |
3804 | |
3805 | if (!_PyArg_CheckPositional("setregid" , nargs, 2, 2)) { |
3806 | goto exit; |
3807 | } |
3808 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
3809 | goto exit; |
3810 | } |
3811 | if (!_Py_Gid_Converter(args[1], &egid)) { |
3812 | goto exit; |
3813 | } |
3814 | return_value = os_setregid_impl(module, rgid, egid); |
3815 | |
3816 | exit: |
3817 | return return_value; |
3818 | } |
3819 | |
3820 | #endif /* defined(HAVE_SETREGID) */ |
3821 | |
3822 | #if defined(HAVE_SETGID) |
3823 | |
3824 | PyDoc_STRVAR(os_setgid__doc__, |
3825 | "setgid($module, gid, /)\n" |
3826 | "--\n" |
3827 | "\n" |
3828 | "Set the current process\'s group id." ); |
3829 | |
3830 | #define OS_SETGID_METHODDEF \ |
3831 | {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__}, |
3832 | |
3833 | static PyObject * |
3834 | os_setgid_impl(PyObject *module, gid_t gid); |
3835 | |
3836 | static PyObject * |
3837 | os_setgid(PyObject *module, PyObject *arg) |
3838 | { |
3839 | PyObject *return_value = NULL; |
3840 | gid_t gid; |
3841 | |
3842 | if (!_Py_Gid_Converter(arg, &gid)) { |
3843 | goto exit; |
3844 | } |
3845 | return_value = os_setgid_impl(module, gid); |
3846 | |
3847 | exit: |
3848 | return return_value; |
3849 | } |
3850 | |
3851 | #endif /* defined(HAVE_SETGID) */ |
3852 | |
3853 | #if defined(HAVE_SETGROUPS) |
3854 | |
3855 | PyDoc_STRVAR(os_setgroups__doc__, |
3856 | "setgroups($module, groups, /)\n" |
3857 | "--\n" |
3858 | "\n" |
3859 | "Set the groups of the current process to list." ); |
3860 | |
3861 | #define OS_SETGROUPS_METHODDEF \ |
3862 | {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, |
3863 | |
3864 | #endif /* defined(HAVE_SETGROUPS) */ |
3865 | |
3866 | #if defined(HAVE_WAIT3) |
3867 | |
3868 | PyDoc_STRVAR(os_wait3__doc__, |
3869 | "wait3($module, /, options)\n" |
3870 | "--\n" |
3871 | "\n" |
3872 | "Wait for completion of a child process.\n" |
3873 | "\n" |
3874 | "Returns a tuple of information about the child process:\n" |
3875 | " (pid, status, rusage)" ); |
3876 | |
3877 | #define OS_WAIT3_METHODDEF \ |
3878 | {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__}, |
3879 | |
3880 | static PyObject * |
3881 | os_wait3_impl(PyObject *module, int options); |
3882 | |
3883 | static PyObject * |
3884 | os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3885 | { |
3886 | PyObject *return_value = NULL; |
3887 | static const char * const _keywords[] = {"options" , NULL}; |
3888 | static _PyArg_Parser _parser = {NULL, _keywords, "wait3" , 0}; |
3889 | PyObject *argsbuf[1]; |
3890 | int options; |
3891 | |
3892 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
3893 | if (!args) { |
3894 | goto exit; |
3895 | } |
3896 | options = _PyLong_AsInt(args[0]); |
3897 | if (options == -1 && PyErr_Occurred()) { |
3898 | goto exit; |
3899 | } |
3900 | return_value = os_wait3_impl(module, options); |
3901 | |
3902 | exit: |
3903 | return return_value; |
3904 | } |
3905 | |
3906 | #endif /* defined(HAVE_WAIT3) */ |
3907 | |
3908 | #if defined(HAVE_WAIT4) |
3909 | |
3910 | PyDoc_STRVAR(os_wait4__doc__, |
3911 | "wait4($module, /, pid, options)\n" |
3912 | "--\n" |
3913 | "\n" |
3914 | "Wait for completion of a specific child process.\n" |
3915 | "\n" |
3916 | "Returns a tuple of information about the child process:\n" |
3917 | " (pid, status, rusage)" ); |
3918 | |
3919 | #define OS_WAIT4_METHODDEF \ |
3920 | {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__}, |
3921 | |
3922 | static PyObject * |
3923 | os_wait4_impl(PyObject *module, pid_t pid, int options); |
3924 | |
3925 | static PyObject * |
3926 | os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
3927 | { |
3928 | PyObject *return_value = NULL; |
3929 | static const char * const _keywords[] = {"pid" , "options" , NULL}; |
3930 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4" , _keywords, 0}; |
3931 | pid_t pid; |
3932 | int options; |
3933 | |
3934 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
3935 | &pid, &options)) { |
3936 | goto exit; |
3937 | } |
3938 | return_value = os_wait4_impl(module, pid, options); |
3939 | |
3940 | exit: |
3941 | return return_value; |
3942 | } |
3943 | |
3944 | #endif /* defined(HAVE_WAIT4) */ |
3945 | |
3946 | #if (defined(HAVE_WAITID) && !defined(__APPLE__)) |
3947 | |
3948 | PyDoc_STRVAR(os_waitid__doc__, |
3949 | "waitid($module, idtype, id, options, /)\n" |
3950 | "--\n" |
3951 | "\n" |
3952 | "Returns the result of waiting for a process or processes.\n" |
3953 | "\n" |
3954 | " idtype\n" |
3955 | " Must be one of be P_PID, P_PGID or P_ALL.\n" |
3956 | " id\n" |
3957 | " The id to wait on.\n" |
3958 | " options\n" |
3959 | " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" |
3960 | " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" |
3961 | "\n" |
3962 | "Returns either waitid_result or None if WNOHANG is specified and there are\n" |
3963 | "no children in a waitable state." ); |
3964 | |
3965 | #define OS_WAITID_METHODDEF \ |
3966 | {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__}, |
3967 | |
3968 | static PyObject * |
3969 | os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options); |
3970 | |
3971 | static PyObject * |
3972 | os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
3973 | { |
3974 | PyObject *return_value = NULL; |
3975 | idtype_t idtype; |
3976 | id_t id; |
3977 | int options; |
3978 | |
3979 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid" , |
3980 | &idtype, &id, &options)) { |
3981 | goto exit; |
3982 | } |
3983 | return_value = os_waitid_impl(module, idtype, id, options); |
3984 | |
3985 | exit: |
3986 | return return_value; |
3987 | } |
3988 | |
3989 | #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */ |
3990 | |
3991 | #if defined(HAVE_WAITPID) |
3992 | |
3993 | PyDoc_STRVAR(os_waitpid__doc__, |
3994 | "waitpid($module, pid, options, /)\n" |
3995 | "--\n" |
3996 | "\n" |
3997 | "Wait for completion of a given child process.\n" |
3998 | "\n" |
3999 | "Returns a tuple of information regarding the child process:\n" |
4000 | " (pid, status)\n" |
4001 | "\n" |
4002 | "The options argument is ignored on Windows." ); |
4003 | |
4004 | #define OS_WAITPID_METHODDEF \ |
4005 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
4006 | |
4007 | static PyObject * |
4008 | os_waitpid_impl(PyObject *module, pid_t pid, int options); |
4009 | |
4010 | static PyObject * |
4011 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4012 | { |
4013 | PyObject *return_value = NULL; |
4014 | pid_t pid; |
4015 | int options; |
4016 | |
4017 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid" , |
4018 | &pid, &options)) { |
4019 | goto exit; |
4020 | } |
4021 | return_value = os_waitpid_impl(module, pid, options); |
4022 | |
4023 | exit: |
4024 | return return_value; |
4025 | } |
4026 | |
4027 | #endif /* defined(HAVE_WAITPID) */ |
4028 | |
4029 | #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) |
4030 | |
4031 | PyDoc_STRVAR(os_waitpid__doc__, |
4032 | "waitpid($module, pid, options, /)\n" |
4033 | "--\n" |
4034 | "\n" |
4035 | "Wait for completion of a given process.\n" |
4036 | "\n" |
4037 | "Returns a tuple of information regarding the process:\n" |
4038 | " (pid, status << 8)\n" |
4039 | "\n" |
4040 | "The options argument is ignored on Windows." ); |
4041 | |
4042 | #define OS_WAITPID_METHODDEF \ |
4043 | {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__}, |
4044 | |
4045 | static PyObject * |
4046 | os_waitpid_impl(PyObject *module, intptr_t pid, int options); |
4047 | |
4048 | static PyObject * |
4049 | os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4050 | { |
4051 | PyObject *return_value = NULL; |
4052 | intptr_t pid; |
4053 | int options; |
4054 | |
4055 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid" , |
4056 | &pid, &options)) { |
4057 | goto exit; |
4058 | } |
4059 | return_value = os_waitpid_impl(module, pid, options); |
4060 | |
4061 | exit: |
4062 | return return_value; |
4063 | } |
4064 | |
4065 | #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */ |
4066 | |
4067 | #if defined(HAVE_WAIT) |
4068 | |
4069 | PyDoc_STRVAR(os_wait__doc__, |
4070 | "wait($module, /)\n" |
4071 | "--\n" |
4072 | "\n" |
4073 | "Wait for completion of a child process.\n" |
4074 | "\n" |
4075 | "Returns a tuple of information about the child process:\n" |
4076 | " (pid, status)" ); |
4077 | |
4078 | #define OS_WAIT_METHODDEF \ |
4079 | {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, |
4080 | |
4081 | static PyObject * |
4082 | os_wait_impl(PyObject *module); |
4083 | |
4084 | static PyObject * |
4085 | os_wait(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4086 | { |
4087 | return os_wait_impl(module); |
4088 | } |
4089 | |
4090 | #endif /* defined(HAVE_WAIT) */ |
4091 | |
4092 | #if (defined(__linux__) && defined(__NR_pidfd_open)) |
4093 | |
4094 | PyDoc_STRVAR(os_pidfd_open__doc__, |
4095 | "pidfd_open($module, /, pid, flags=0)\n" |
4096 | "--\n" |
4097 | "\n" |
4098 | "Return a file descriptor referring to the process *pid*.\n" |
4099 | "\n" |
4100 | "The descriptor can be used to perform process management without races and\n" |
4101 | "signals." ); |
4102 | |
4103 | #define OS_PIDFD_OPEN_METHODDEF \ |
4104 | {"pidfd_open", (PyCFunction)(void(*)(void))os_pidfd_open, METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__}, |
4105 | |
4106 | static PyObject * |
4107 | os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags); |
4108 | |
4109 | static PyObject * |
4110 | os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4111 | { |
4112 | PyObject *return_value = NULL; |
4113 | static const char * const _keywords[] = {"pid" , "flags" , NULL}; |
4114 | static _PyArg_Parser _parser = {"" _Py_PARSE_PID "|O&:pidfd_open" , _keywords, 0}; |
4115 | pid_t pid; |
4116 | unsigned int flags = 0; |
4117 | |
4118 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
4119 | &pid, _PyLong_UnsignedInt_Converter, &flags)) { |
4120 | goto exit; |
4121 | } |
4122 | return_value = os_pidfd_open_impl(module, pid, flags); |
4123 | |
4124 | exit: |
4125 | return return_value; |
4126 | } |
4127 | |
4128 | #endif /* (defined(__linux__) && defined(__NR_pidfd_open)) */ |
4129 | |
4130 | #if (defined(HAVE_READLINK) || defined(MS_WINDOWS)) |
4131 | |
4132 | PyDoc_STRVAR(os_readlink__doc__, |
4133 | "readlink($module, /, path, *, dir_fd=None)\n" |
4134 | "--\n" |
4135 | "\n" |
4136 | "Return a string representing the path to which the symbolic link points.\n" |
4137 | "\n" |
4138 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
4139 | "and path should be relative; path will then be relative to that directory.\n" |
4140 | "\n" |
4141 | "dir_fd may not be implemented on your platform. If it is unavailable,\n" |
4142 | "using it will raise a NotImplementedError." ); |
4143 | |
4144 | #define OS_READLINK_METHODDEF \ |
4145 | {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__}, |
4146 | |
4147 | static PyObject * |
4148 | os_readlink_impl(PyObject *module, path_t *path, int dir_fd); |
4149 | |
4150 | static PyObject * |
4151 | os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4152 | { |
4153 | PyObject *return_value = NULL; |
4154 | static const char * const _keywords[] = {"path" , "dir_fd" , NULL}; |
4155 | static _PyArg_Parser _parser = {NULL, _keywords, "readlink" , 0}; |
4156 | PyObject *argsbuf[2]; |
4157 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
4158 | path_t path = PATH_T_INITIALIZE("readlink" , "path" , 0, 0); |
4159 | int dir_fd = DEFAULT_DIR_FD; |
4160 | |
4161 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
4162 | if (!args) { |
4163 | goto exit; |
4164 | } |
4165 | if (!path_converter(args[0], &path)) { |
4166 | goto exit; |
4167 | } |
4168 | if (!noptargs) { |
4169 | goto skip_optional_kwonly; |
4170 | } |
4171 | if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) { |
4172 | goto exit; |
4173 | } |
4174 | skip_optional_kwonly: |
4175 | return_value = os_readlink_impl(module, &path, dir_fd); |
4176 | |
4177 | exit: |
4178 | /* Cleanup for path */ |
4179 | path_cleanup(&path); |
4180 | |
4181 | return return_value; |
4182 | } |
4183 | |
4184 | #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */ |
4185 | |
4186 | #if defined(HAVE_SYMLINK) |
4187 | |
4188 | PyDoc_STRVAR(os_symlink__doc__, |
4189 | "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" |
4190 | "--\n" |
4191 | "\n" |
4192 | "Create a symbolic link pointing to src named dst.\n" |
4193 | "\n" |
4194 | "target_is_directory is required on Windows if the target is to be\n" |
4195 | " interpreted as a directory. (On Windows, symlink requires\n" |
4196 | " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" |
4197 | " target_is_directory is ignored on non-Windows platforms.\n" |
4198 | "\n" |
4199 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
4200 | " and path should be relative; path will then be relative to that directory.\n" |
4201 | "dir_fd may not be implemented on your platform.\n" |
4202 | " If it is unavailable, using it will raise a NotImplementedError." ); |
4203 | |
4204 | #define OS_SYMLINK_METHODDEF \ |
4205 | {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__}, |
4206 | |
4207 | static PyObject * |
4208 | os_symlink_impl(PyObject *module, path_t *src, path_t *dst, |
4209 | int target_is_directory, int dir_fd); |
4210 | |
4211 | static PyObject * |
4212 | os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4213 | { |
4214 | PyObject *return_value = NULL; |
4215 | static const char * const _keywords[] = {"src" , "dst" , "target_is_directory" , "dir_fd" , NULL}; |
4216 | static _PyArg_Parser _parser = {NULL, _keywords, "symlink" , 0}; |
4217 | PyObject *argsbuf[4]; |
4218 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
4219 | path_t src = PATH_T_INITIALIZE("symlink" , "src" , 0, 0); |
4220 | path_t dst = PATH_T_INITIALIZE("symlink" , "dst" , 0, 0); |
4221 | int target_is_directory = 0; |
4222 | int dir_fd = DEFAULT_DIR_FD; |
4223 | |
4224 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
4225 | if (!args) { |
4226 | goto exit; |
4227 | } |
4228 | if (!path_converter(args[0], &src)) { |
4229 | goto exit; |
4230 | } |
4231 | if (!path_converter(args[1], &dst)) { |
4232 | goto exit; |
4233 | } |
4234 | if (!noptargs) { |
4235 | goto skip_optional_pos; |
4236 | } |
4237 | if (args[2]) { |
4238 | target_is_directory = PyObject_IsTrue(args[2]); |
4239 | if (target_is_directory < 0) { |
4240 | goto exit; |
4241 | } |
4242 | if (!--noptargs) { |
4243 | goto skip_optional_pos; |
4244 | } |
4245 | } |
4246 | skip_optional_pos: |
4247 | if (!noptargs) { |
4248 | goto skip_optional_kwonly; |
4249 | } |
4250 | if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
4251 | goto exit; |
4252 | } |
4253 | skip_optional_kwonly: |
4254 | return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); |
4255 | |
4256 | exit: |
4257 | /* Cleanup for src */ |
4258 | path_cleanup(&src); |
4259 | /* Cleanup for dst */ |
4260 | path_cleanup(&dst); |
4261 | |
4262 | return return_value; |
4263 | } |
4264 | |
4265 | #endif /* defined(HAVE_SYMLINK) */ |
4266 | |
4267 | #if defined(HAVE_TIMES) |
4268 | |
4269 | PyDoc_STRVAR(os_times__doc__, |
4270 | "times($module, /)\n" |
4271 | "--\n" |
4272 | "\n" |
4273 | "Return a collection containing process timing information.\n" |
4274 | "\n" |
4275 | "The object returned behaves like a named tuple with these fields:\n" |
4276 | " (utime, stime, cutime, cstime, elapsed_time)\n" |
4277 | "All fields are floating point numbers." ); |
4278 | |
4279 | #define OS_TIMES_METHODDEF \ |
4280 | {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, |
4281 | |
4282 | static PyObject * |
4283 | os_times_impl(PyObject *module); |
4284 | |
4285 | static PyObject * |
4286 | os_times(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4287 | { |
4288 | return os_times_impl(module); |
4289 | } |
4290 | |
4291 | #endif /* defined(HAVE_TIMES) */ |
4292 | |
4293 | #if defined(HAVE_GETSID) |
4294 | |
4295 | PyDoc_STRVAR(os_getsid__doc__, |
4296 | "getsid($module, pid, /)\n" |
4297 | "--\n" |
4298 | "\n" |
4299 | "Call the system call getsid(pid) and return the result." ); |
4300 | |
4301 | #define OS_GETSID_METHODDEF \ |
4302 | {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__}, |
4303 | |
4304 | static PyObject * |
4305 | os_getsid_impl(PyObject *module, pid_t pid); |
4306 | |
4307 | static PyObject * |
4308 | os_getsid(PyObject *module, PyObject *arg) |
4309 | { |
4310 | PyObject *return_value = NULL; |
4311 | pid_t pid; |
4312 | |
4313 | if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid" , &pid)) { |
4314 | goto exit; |
4315 | } |
4316 | return_value = os_getsid_impl(module, pid); |
4317 | |
4318 | exit: |
4319 | return return_value; |
4320 | } |
4321 | |
4322 | #endif /* defined(HAVE_GETSID) */ |
4323 | |
4324 | #if defined(HAVE_SETSID) |
4325 | |
4326 | PyDoc_STRVAR(os_setsid__doc__, |
4327 | "setsid($module, /)\n" |
4328 | "--\n" |
4329 | "\n" |
4330 | "Call the system call setsid()." ); |
4331 | |
4332 | #define OS_SETSID_METHODDEF \ |
4333 | {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, |
4334 | |
4335 | static PyObject * |
4336 | os_setsid_impl(PyObject *module); |
4337 | |
4338 | static PyObject * |
4339 | os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
4340 | { |
4341 | return os_setsid_impl(module); |
4342 | } |
4343 | |
4344 | #endif /* defined(HAVE_SETSID) */ |
4345 | |
4346 | #if defined(HAVE_SETPGID) |
4347 | |
4348 | PyDoc_STRVAR(os_setpgid__doc__, |
4349 | "setpgid($module, pid, pgrp, /)\n" |
4350 | "--\n" |
4351 | "\n" |
4352 | "Call the system call setpgid(pid, pgrp)." ); |
4353 | |
4354 | #define OS_SETPGID_METHODDEF \ |
4355 | {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__}, |
4356 | |
4357 | static PyObject * |
4358 | os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp); |
4359 | |
4360 | static PyObject * |
4361 | os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4362 | { |
4363 | PyObject *return_value = NULL; |
4364 | pid_t pid; |
4365 | pid_t pgrp; |
4366 | |
4367 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid" , |
4368 | &pid, &pgrp)) { |
4369 | goto exit; |
4370 | } |
4371 | return_value = os_setpgid_impl(module, pid, pgrp); |
4372 | |
4373 | exit: |
4374 | return return_value; |
4375 | } |
4376 | |
4377 | #endif /* defined(HAVE_SETPGID) */ |
4378 | |
4379 | #if defined(HAVE_TCGETPGRP) |
4380 | |
4381 | PyDoc_STRVAR(os_tcgetpgrp__doc__, |
4382 | "tcgetpgrp($module, fd, /)\n" |
4383 | "--\n" |
4384 | "\n" |
4385 | "Return the process group associated with the terminal specified by fd." ); |
4386 | |
4387 | #define OS_TCGETPGRP_METHODDEF \ |
4388 | {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__}, |
4389 | |
4390 | static PyObject * |
4391 | os_tcgetpgrp_impl(PyObject *module, int fd); |
4392 | |
4393 | static PyObject * |
4394 | os_tcgetpgrp(PyObject *module, PyObject *arg) |
4395 | { |
4396 | PyObject *return_value = NULL; |
4397 | int fd; |
4398 | |
4399 | fd = _PyLong_AsInt(arg); |
4400 | if (fd == -1 && PyErr_Occurred()) { |
4401 | goto exit; |
4402 | } |
4403 | return_value = os_tcgetpgrp_impl(module, fd); |
4404 | |
4405 | exit: |
4406 | return return_value; |
4407 | } |
4408 | |
4409 | #endif /* defined(HAVE_TCGETPGRP) */ |
4410 | |
4411 | #if defined(HAVE_TCSETPGRP) |
4412 | |
4413 | PyDoc_STRVAR(os_tcsetpgrp__doc__, |
4414 | "tcsetpgrp($module, fd, pgid, /)\n" |
4415 | "--\n" |
4416 | "\n" |
4417 | "Set the process group associated with the terminal specified by fd." ); |
4418 | |
4419 | #define OS_TCSETPGRP_METHODDEF \ |
4420 | {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__}, |
4421 | |
4422 | static PyObject * |
4423 | os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid); |
4424 | |
4425 | static PyObject * |
4426 | os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4427 | { |
4428 | PyObject *return_value = NULL; |
4429 | int fd; |
4430 | pid_t pgid; |
4431 | |
4432 | if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp" , |
4433 | &fd, &pgid)) { |
4434 | goto exit; |
4435 | } |
4436 | return_value = os_tcsetpgrp_impl(module, fd, pgid); |
4437 | |
4438 | exit: |
4439 | return return_value; |
4440 | } |
4441 | |
4442 | #endif /* defined(HAVE_TCSETPGRP) */ |
4443 | |
4444 | PyDoc_STRVAR(os_open__doc__, |
4445 | "open($module, /, path, flags, mode=511, *, dir_fd=None)\n" |
4446 | "--\n" |
4447 | "\n" |
4448 | "Open a file for low level IO. Returns a file descriptor (integer).\n" |
4449 | "\n" |
4450 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
4451 | " and path should be relative; path will then be relative to that directory.\n" |
4452 | "dir_fd may not be implemented on your platform.\n" |
4453 | " If it is unavailable, using it will raise a NotImplementedError." ); |
4454 | |
4455 | #define OS_OPEN_METHODDEF \ |
4456 | {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__}, |
4457 | |
4458 | static int |
4459 | os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd); |
4460 | |
4461 | static PyObject * |
4462 | os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4463 | { |
4464 | PyObject *return_value = NULL; |
4465 | static const char * const _keywords[] = {"path" , "flags" , "mode" , "dir_fd" , NULL}; |
4466 | static _PyArg_Parser _parser = {NULL, _keywords, "open" , 0}; |
4467 | PyObject *argsbuf[4]; |
4468 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
4469 | path_t path = PATH_T_INITIALIZE("open" , "path" , 0, 0); |
4470 | int flags; |
4471 | int mode = 511; |
4472 | int dir_fd = DEFAULT_DIR_FD; |
4473 | int _return_value; |
4474 | |
4475 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
4476 | if (!args) { |
4477 | goto exit; |
4478 | } |
4479 | if (!path_converter(args[0], &path)) { |
4480 | goto exit; |
4481 | } |
4482 | flags = _PyLong_AsInt(args[1]); |
4483 | if (flags == -1 && PyErr_Occurred()) { |
4484 | goto exit; |
4485 | } |
4486 | if (!noptargs) { |
4487 | goto skip_optional_pos; |
4488 | } |
4489 | if (args[2]) { |
4490 | mode = _PyLong_AsInt(args[2]); |
4491 | if (mode == -1 && PyErr_Occurred()) { |
4492 | goto exit; |
4493 | } |
4494 | if (!--noptargs) { |
4495 | goto skip_optional_pos; |
4496 | } |
4497 | } |
4498 | skip_optional_pos: |
4499 | if (!noptargs) { |
4500 | goto skip_optional_kwonly; |
4501 | } |
4502 | if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
4503 | goto exit; |
4504 | } |
4505 | skip_optional_kwonly: |
4506 | _return_value = os_open_impl(module, &path, flags, mode, dir_fd); |
4507 | if ((_return_value == -1) && PyErr_Occurred()) { |
4508 | goto exit; |
4509 | } |
4510 | return_value = PyLong_FromLong((long)_return_value); |
4511 | |
4512 | exit: |
4513 | /* Cleanup for path */ |
4514 | path_cleanup(&path); |
4515 | |
4516 | return return_value; |
4517 | } |
4518 | |
4519 | PyDoc_STRVAR(os_close__doc__, |
4520 | "close($module, /, fd)\n" |
4521 | "--\n" |
4522 | "\n" |
4523 | "Close a file descriptor." ); |
4524 | |
4525 | #define OS_CLOSE_METHODDEF \ |
4526 | {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__}, |
4527 | |
4528 | static PyObject * |
4529 | os_close_impl(PyObject *module, int fd); |
4530 | |
4531 | static PyObject * |
4532 | os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4533 | { |
4534 | PyObject *return_value = NULL; |
4535 | static const char * const _keywords[] = {"fd" , NULL}; |
4536 | static _PyArg_Parser _parser = {NULL, _keywords, "close" , 0}; |
4537 | PyObject *argsbuf[1]; |
4538 | int fd; |
4539 | |
4540 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
4541 | if (!args) { |
4542 | goto exit; |
4543 | } |
4544 | fd = _PyLong_AsInt(args[0]); |
4545 | if (fd == -1 && PyErr_Occurred()) { |
4546 | goto exit; |
4547 | } |
4548 | return_value = os_close_impl(module, fd); |
4549 | |
4550 | exit: |
4551 | return return_value; |
4552 | } |
4553 | |
4554 | PyDoc_STRVAR(os_closerange__doc__, |
4555 | "closerange($module, fd_low, fd_high, /)\n" |
4556 | "--\n" |
4557 | "\n" |
4558 | "Closes all file descriptors in [fd_low, fd_high), ignoring errors." ); |
4559 | |
4560 | #define OS_CLOSERANGE_METHODDEF \ |
4561 | {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__}, |
4562 | |
4563 | static PyObject * |
4564 | os_closerange_impl(PyObject *module, int fd_low, int fd_high); |
4565 | |
4566 | static PyObject * |
4567 | os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4568 | { |
4569 | PyObject *return_value = NULL; |
4570 | int fd_low; |
4571 | int fd_high; |
4572 | |
4573 | if (!_PyArg_CheckPositional("closerange" , nargs, 2, 2)) { |
4574 | goto exit; |
4575 | } |
4576 | fd_low = _PyLong_AsInt(args[0]); |
4577 | if (fd_low == -1 && PyErr_Occurred()) { |
4578 | goto exit; |
4579 | } |
4580 | fd_high = _PyLong_AsInt(args[1]); |
4581 | if (fd_high == -1 && PyErr_Occurred()) { |
4582 | goto exit; |
4583 | } |
4584 | return_value = os_closerange_impl(module, fd_low, fd_high); |
4585 | |
4586 | exit: |
4587 | return return_value; |
4588 | } |
4589 | |
4590 | PyDoc_STRVAR(os_dup__doc__, |
4591 | "dup($module, fd, /)\n" |
4592 | "--\n" |
4593 | "\n" |
4594 | "Return a duplicate of a file descriptor." ); |
4595 | |
4596 | #define OS_DUP_METHODDEF \ |
4597 | {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__}, |
4598 | |
4599 | static int |
4600 | os_dup_impl(PyObject *module, int fd); |
4601 | |
4602 | static PyObject * |
4603 | os_dup(PyObject *module, PyObject *arg) |
4604 | { |
4605 | PyObject *return_value = NULL; |
4606 | int fd; |
4607 | int _return_value; |
4608 | |
4609 | fd = _PyLong_AsInt(arg); |
4610 | if (fd == -1 && PyErr_Occurred()) { |
4611 | goto exit; |
4612 | } |
4613 | _return_value = os_dup_impl(module, fd); |
4614 | if ((_return_value == -1) && PyErr_Occurred()) { |
4615 | goto exit; |
4616 | } |
4617 | return_value = PyLong_FromLong((long)_return_value); |
4618 | |
4619 | exit: |
4620 | return return_value; |
4621 | } |
4622 | |
4623 | PyDoc_STRVAR(os_dup2__doc__, |
4624 | "dup2($module, /, fd, fd2, inheritable=True)\n" |
4625 | "--\n" |
4626 | "\n" |
4627 | "Duplicate file descriptor." ); |
4628 | |
4629 | #define OS_DUP2_METHODDEF \ |
4630 | {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__}, |
4631 | |
4632 | static int |
4633 | os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable); |
4634 | |
4635 | static PyObject * |
4636 | os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
4637 | { |
4638 | PyObject *return_value = NULL; |
4639 | static const char * const _keywords[] = {"fd" , "fd2" , "inheritable" , NULL}; |
4640 | static _PyArg_Parser _parser = {NULL, _keywords, "dup2" , 0}; |
4641 | PyObject *argsbuf[3]; |
4642 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
4643 | int fd; |
4644 | int fd2; |
4645 | int inheritable = 1; |
4646 | int _return_value; |
4647 | |
4648 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf); |
4649 | if (!args) { |
4650 | goto exit; |
4651 | } |
4652 | fd = _PyLong_AsInt(args[0]); |
4653 | if (fd == -1 && PyErr_Occurred()) { |
4654 | goto exit; |
4655 | } |
4656 | fd2 = _PyLong_AsInt(args[1]); |
4657 | if (fd2 == -1 && PyErr_Occurred()) { |
4658 | goto exit; |
4659 | } |
4660 | if (!noptargs) { |
4661 | goto skip_optional_pos; |
4662 | } |
4663 | inheritable = PyObject_IsTrue(args[2]); |
4664 | if (inheritable < 0) { |
4665 | goto exit; |
4666 | } |
4667 | skip_optional_pos: |
4668 | _return_value = os_dup2_impl(module, fd, fd2, inheritable); |
4669 | if ((_return_value == -1) && PyErr_Occurred()) { |
4670 | goto exit; |
4671 | } |
4672 | return_value = PyLong_FromLong((long)_return_value); |
4673 | |
4674 | exit: |
4675 | return return_value; |
4676 | } |
4677 | |
4678 | #if defined(HAVE_LOCKF) |
4679 | |
4680 | PyDoc_STRVAR(os_lockf__doc__, |
4681 | "lockf($module, fd, command, length, /)\n" |
4682 | "--\n" |
4683 | "\n" |
4684 | "Apply, test or remove a POSIX lock on an open file descriptor.\n" |
4685 | "\n" |
4686 | " fd\n" |
4687 | " An open file descriptor.\n" |
4688 | " command\n" |
4689 | " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" |
4690 | " length\n" |
4691 | " The number of bytes to lock, starting at the current position." ); |
4692 | |
4693 | #define OS_LOCKF_METHODDEF \ |
4694 | {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__}, |
4695 | |
4696 | static PyObject * |
4697 | os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length); |
4698 | |
4699 | static PyObject * |
4700 | os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4701 | { |
4702 | PyObject *return_value = NULL; |
4703 | int fd; |
4704 | int command; |
4705 | Py_off_t length; |
4706 | |
4707 | if (!_PyArg_CheckPositional("lockf" , nargs, 3, 3)) { |
4708 | goto exit; |
4709 | } |
4710 | fd = _PyLong_AsInt(args[0]); |
4711 | if (fd == -1 && PyErr_Occurred()) { |
4712 | goto exit; |
4713 | } |
4714 | command = _PyLong_AsInt(args[1]); |
4715 | if (command == -1 && PyErr_Occurred()) { |
4716 | goto exit; |
4717 | } |
4718 | if (!Py_off_t_converter(args[2], &length)) { |
4719 | goto exit; |
4720 | } |
4721 | return_value = os_lockf_impl(module, fd, command, length); |
4722 | |
4723 | exit: |
4724 | return return_value; |
4725 | } |
4726 | |
4727 | #endif /* defined(HAVE_LOCKF) */ |
4728 | |
4729 | PyDoc_STRVAR(os_lseek__doc__, |
4730 | "lseek($module, fd, position, how, /)\n" |
4731 | "--\n" |
4732 | "\n" |
4733 | "Set the position of a file descriptor. Return the new position.\n" |
4734 | "\n" |
4735 | "Return the new cursor position in number of bytes\n" |
4736 | "relative to the beginning of the file." ); |
4737 | |
4738 | #define OS_LSEEK_METHODDEF \ |
4739 | {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__}, |
4740 | |
4741 | static Py_off_t |
4742 | os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how); |
4743 | |
4744 | static PyObject * |
4745 | os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4746 | { |
4747 | PyObject *return_value = NULL; |
4748 | int fd; |
4749 | Py_off_t position; |
4750 | int how; |
4751 | Py_off_t _return_value; |
4752 | |
4753 | if (!_PyArg_CheckPositional("lseek" , nargs, 3, 3)) { |
4754 | goto exit; |
4755 | } |
4756 | fd = _PyLong_AsInt(args[0]); |
4757 | if (fd == -1 && PyErr_Occurred()) { |
4758 | goto exit; |
4759 | } |
4760 | if (!Py_off_t_converter(args[1], &position)) { |
4761 | goto exit; |
4762 | } |
4763 | how = _PyLong_AsInt(args[2]); |
4764 | if (how == -1 && PyErr_Occurred()) { |
4765 | goto exit; |
4766 | } |
4767 | _return_value = os_lseek_impl(module, fd, position, how); |
4768 | if ((_return_value == -1) && PyErr_Occurred()) { |
4769 | goto exit; |
4770 | } |
4771 | return_value = PyLong_FromPy_off_t(_return_value); |
4772 | |
4773 | exit: |
4774 | return return_value; |
4775 | } |
4776 | |
4777 | PyDoc_STRVAR(os_read__doc__, |
4778 | "read($module, fd, length, /)\n" |
4779 | "--\n" |
4780 | "\n" |
4781 | "Read from a file descriptor. Returns a bytes object." ); |
4782 | |
4783 | #define OS_READ_METHODDEF \ |
4784 | {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__}, |
4785 | |
4786 | static PyObject * |
4787 | os_read_impl(PyObject *module, int fd, Py_ssize_t length); |
4788 | |
4789 | static PyObject * |
4790 | os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4791 | { |
4792 | PyObject *return_value = NULL; |
4793 | int fd; |
4794 | Py_ssize_t length; |
4795 | |
4796 | if (!_PyArg_CheckPositional("read" , nargs, 2, 2)) { |
4797 | goto exit; |
4798 | } |
4799 | fd = _PyLong_AsInt(args[0]); |
4800 | if (fd == -1 && PyErr_Occurred()) { |
4801 | goto exit; |
4802 | } |
4803 | { |
4804 | Py_ssize_t ival = -1; |
4805 | PyObject *iobj = _PyNumber_Index(args[1]); |
4806 | if (iobj != NULL) { |
4807 | ival = PyLong_AsSsize_t(iobj); |
4808 | Py_DECREF(iobj); |
4809 | } |
4810 | if (ival == -1 && PyErr_Occurred()) { |
4811 | goto exit; |
4812 | } |
4813 | length = ival; |
4814 | } |
4815 | return_value = os_read_impl(module, fd, length); |
4816 | |
4817 | exit: |
4818 | return return_value; |
4819 | } |
4820 | |
4821 | #if defined(HAVE_READV) |
4822 | |
4823 | PyDoc_STRVAR(os_readv__doc__, |
4824 | "readv($module, fd, buffers, /)\n" |
4825 | "--\n" |
4826 | "\n" |
4827 | "Read from a file descriptor fd into an iterable of buffers.\n" |
4828 | "\n" |
4829 | "The buffers should be mutable buffers accepting bytes.\n" |
4830 | "readv will transfer data into each buffer until it is full\n" |
4831 | "and then move on to the next buffer in the sequence to hold\n" |
4832 | "the rest of the data.\n" |
4833 | "\n" |
4834 | "readv returns the total number of bytes read,\n" |
4835 | "which may be less than the total capacity of all the buffers." ); |
4836 | |
4837 | #define OS_READV_METHODDEF \ |
4838 | {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__}, |
4839 | |
4840 | static Py_ssize_t |
4841 | os_readv_impl(PyObject *module, int fd, PyObject *buffers); |
4842 | |
4843 | static PyObject * |
4844 | os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4845 | { |
4846 | PyObject *return_value = NULL; |
4847 | int fd; |
4848 | PyObject *buffers; |
4849 | Py_ssize_t _return_value; |
4850 | |
4851 | if (!_PyArg_CheckPositional("readv" , nargs, 2, 2)) { |
4852 | goto exit; |
4853 | } |
4854 | fd = _PyLong_AsInt(args[0]); |
4855 | if (fd == -1 && PyErr_Occurred()) { |
4856 | goto exit; |
4857 | } |
4858 | buffers = args[1]; |
4859 | _return_value = os_readv_impl(module, fd, buffers); |
4860 | if ((_return_value == -1) && PyErr_Occurred()) { |
4861 | goto exit; |
4862 | } |
4863 | return_value = PyLong_FromSsize_t(_return_value); |
4864 | |
4865 | exit: |
4866 | return return_value; |
4867 | } |
4868 | |
4869 | #endif /* defined(HAVE_READV) */ |
4870 | |
4871 | #if defined(HAVE_PREAD) |
4872 | |
4873 | PyDoc_STRVAR(os_pread__doc__, |
4874 | "pread($module, fd, length, offset, /)\n" |
4875 | "--\n" |
4876 | "\n" |
4877 | "Read a number of bytes from a file descriptor starting at a particular offset.\n" |
4878 | "\n" |
4879 | "Read length bytes from file descriptor fd, starting at offset bytes from\n" |
4880 | "the beginning of the file. The file offset remains unchanged." ); |
4881 | |
4882 | #define OS_PREAD_METHODDEF \ |
4883 | {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__}, |
4884 | |
4885 | static PyObject * |
4886 | os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset); |
4887 | |
4888 | static PyObject * |
4889 | os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4890 | { |
4891 | PyObject *return_value = NULL; |
4892 | int fd; |
4893 | Py_ssize_t length; |
4894 | Py_off_t offset; |
4895 | |
4896 | if (!_PyArg_CheckPositional("pread" , nargs, 3, 3)) { |
4897 | goto exit; |
4898 | } |
4899 | fd = _PyLong_AsInt(args[0]); |
4900 | if (fd == -1 && PyErr_Occurred()) { |
4901 | goto exit; |
4902 | } |
4903 | { |
4904 | Py_ssize_t ival = -1; |
4905 | PyObject *iobj = _PyNumber_Index(args[1]); |
4906 | if (iobj != NULL) { |
4907 | ival = PyLong_AsSsize_t(iobj); |
4908 | Py_DECREF(iobj); |
4909 | } |
4910 | if (ival == -1 && PyErr_Occurred()) { |
4911 | goto exit; |
4912 | } |
4913 | length = ival; |
4914 | } |
4915 | if (!Py_off_t_converter(args[2], &offset)) { |
4916 | goto exit; |
4917 | } |
4918 | return_value = os_pread_impl(module, fd, length, offset); |
4919 | |
4920 | exit: |
4921 | return return_value; |
4922 | } |
4923 | |
4924 | #endif /* defined(HAVE_PREAD) */ |
4925 | |
4926 | #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) |
4927 | |
4928 | PyDoc_STRVAR(os_preadv__doc__, |
4929 | "preadv($module, fd, buffers, offset, flags=0, /)\n" |
4930 | "--\n" |
4931 | "\n" |
4932 | "Reads from a file descriptor into a number of mutable bytes-like objects.\n" |
4933 | "\n" |
4934 | "Combines the functionality of readv() and pread(). As readv(), it will\n" |
4935 | "transfer data into each buffer until it is full and then move on to the next\n" |
4936 | "buffer in the sequence to hold the rest of the data. Its fourth argument,\n" |
4937 | "specifies the file offset at which the input operation is to be performed. It\n" |
4938 | "will return the total number of bytes read (which can be less than the total\n" |
4939 | "capacity of all the objects).\n" |
4940 | "\n" |
4941 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
4942 | "\n" |
4943 | "- RWF_HIPRI\n" |
4944 | "- RWF_NOWAIT\n" |
4945 | "\n" |
4946 | "Using non-zero flags requires Linux 4.6 or newer." ); |
4947 | |
4948 | #define OS_PREADV_METHODDEF \ |
4949 | {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__}, |
4950 | |
4951 | static Py_ssize_t |
4952 | os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
4953 | int flags); |
4954 | |
4955 | static PyObject * |
4956 | os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
4957 | { |
4958 | PyObject *return_value = NULL; |
4959 | int fd; |
4960 | PyObject *buffers; |
4961 | Py_off_t offset; |
4962 | int flags = 0; |
4963 | Py_ssize_t _return_value; |
4964 | |
4965 | if (!_PyArg_CheckPositional("preadv" , nargs, 3, 4)) { |
4966 | goto exit; |
4967 | } |
4968 | fd = _PyLong_AsInt(args[0]); |
4969 | if (fd == -1 && PyErr_Occurred()) { |
4970 | goto exit; |
4971 | } |
4972 | buffers = args[1]; |
4973 | if (!Py_off_t_converter(args[2], &offset)) { |
4974 | goto exit; |
4975 | } |
4976 | if (nargs < 4) { |
4977 | goto skip_optional; |
4978 | } |
4979 | flags = _PyLong_AsInt(args[3]); |
4980 | if (flags == -1 && PyErr_Occurred()) { |
4981 | goto exit; |
4982 | } |
4983 | skip_optional: |
4984 | _return_value = os_preadv_impl(module, fd, buffers, offset, flags); |
4985 | if ((_return_value == -1) && PyErr_Occurred()) { |
4986 | goto exit; |
4987 | } |
4988 | return_value = PyLong_FromSsize_t(_return_value); |
4989 | |
4990 | exit: |
4991 | return return_value; |
4992 | } |
4993 | |
4994 | #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */ |
4995 | |
4996 | PyDoc_STRVAR(os_write__doc__, |
4997 | "write($module, fd, data, /)\n" |
4998 | "--\n" |
4999 | "\n" |
5000 | "Write a bytes object to a file descriptor." ); |
5001 | |
5002 | #define OS_WRITE_METHODDEF \ |
5003 | {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__}, |
5004 | |
5005 | static Py_ssize_t |
5006 | os_write_impl(PyObject *module, int fd, Py_buffer *data); |
5007 | |
5008 | static PyObject * |
5009 | os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5010 | { |
5011 | PyObject *return_value = NULL; |
5012 | int fd; |
5013 | Py_buffer data = {NULL, NULL}; |
5014 | Py_ssize_t _return_value; |
5015 | |
5016 | if (!_PyArg_CheckPositional("write" , nargs, 2, 2)) { |
5017 | goto exit; |
5018 | } |
5019 | fd = _PyLong_AsInt(args[0]); |
5020 | if (fd == -1 && PyErr_Occurred()) { |
5021 | goto exit; |
5022 | } |
5023 | if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { |
5024 | goto exit; |
5025 | } |
5026 | if (!PyBuffer_IsContiguous(&data, 'C')) { |
5027 | _PyArg_BadArgument("write" , "argument 2" , "contiguous buffer" , args[1]); |
5028 | goto exit; |
5029 | } |
5030 | _return_value = os_write_impl(module, fd, &data); |
5031 | if ((_return_value == -1) && PyErr_Occurred()) { |
5032 | goto exit; |
5033 | } |
5034 | return_value = PyLong_FromSsize_t(_return_value); |
5035 | |
5036 | exit: |
5037 | /* Cleanup for data */ |
5038 | if (data.obj) { |
5039 | PyBuffer_Release(&data); |
5040 | } |
5041 | |
5042 | return return_value; |
5043 | } |
5044 | |
5045 | #if defined(HAVE_SENDFILE) && defined(__APPLE__) |
5046 | |
5047 | PyDoc_STRVAR(os_sendfile__doc__, |
5048 | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
5049 | " trailers=(), flags=0)\n" |
5050 | "--\n" |
5051 | "\n" |
5052 | "Copy count bytes from file descriptor in_fd to file descriptor out_fd." ); |
5053 | |
5054 | #define OS_SENDFILE_METHODDEF \ |
5055 | {"sendfile", (PyCFunction)(void(*)(void))os_sendfile, METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
5056 | |
5057 | static PyObject * |
5058 | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
5059 | Py_off_t sbytes, PyObject *headers, PyObject *trailers, |
5060 | int flags); |
5061 | |
5062 | static PyObject * |
5063 | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5064 | { |
5065 | PyObject *return_value = NULL; |
5066 | static const char * const _keywords[] = {"out_fd" , "in_fd" , "offset" , "count" , "headers" , "trailers" , "flags" , NULL}; |
5067 | static _PyArg_Parser _parser = {NULL, _keywords, "sendfile" , 0}; |
5068 | PyObject *argsbuf[7]; |
5069 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
5070 | int out_fd; |
5071 | int in_fd; |
5072 | Py_off_t offset; |
5073 | Py_off_t sbytes; |
5074 | PyObject *headers = NULL; |
5075 | PyObject *trailers = NULL; |
5076 | int flags = 0; |
5077 | |
5078 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf); |
5079 | if (!args) { |
5080 | goto exit; |
5081 | } |
5082 | out_fd = _PyLong_AsInt(args[0]); |
5083 | if (out_fd == -1 && PyErr_Occurred()) { |
5084 | goto exit; |
5085 | } |
5086 | in_fd = _PyLong_AsInt(args[1]); |
5087 | if (in_fd == -1 && PyErr_Occurred()) { |
5088 | goto exit; |
5089 | } |
5090 | if (!Py_off_t_converter(args[2], &offset)) { |
5091 | goto exit; |
5092 | } |
5093 | if (!Py_off_t_converter(args[3], &sbytes)) { |
5094 | goto exit; |
5095 | } |
5096 | if (!noptargs) { |
5097 | goto skip_optional_pos; |
5098 | } |
5099 | if (args[4]) { |
5100 | headers = args[4]; |
5101 | if (!--noptargs) { |
5102 | goto skip_optional_pos; |
5103 | } |
5104 | } |
5105 | if (args[5]) { |
5106 | trailers = args[5]; |
5107 | if (!--noptargs) { |
5108 | goto skip_optional_pos; |
5109 | } |
5110 | } |
5111 | flags = _PyLong_AsInt(args[6]); |
5112 | if (flags == -1 && PyErr_Occurred()) { |
5113 | goto exit; |
5114 | } |
5115 | skip_optional_pos: |
5116 | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags); |
5117 | |
5118 | exit: |
5119 | return return_value; |
5120 | } |
5121 | |
5122 | #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */ |
5123 | |
5124 | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) |
5125 | |
5126 | PyDoc_STRVAR(os_sendfile__doc__, |
5127 | "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n" |
5128 | " trailers=(), flags=0)\n" |
5129 | "--\n" |
5130 | "\n" |
5131 | "Copy count bytes from file descriptor in_fd to file descriptor out_fd." ); |
5132 | |
5133 | #define OS_SENDFILE_METHODDEF \ |
5134 | {"sendfile", (PyCFunction)(void(*)(void))os_sendfile, METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
5135 | |
5136 | static PyObject * |
5137 | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset, |
5138 | Py_ssize_t count, PyObject *headers, PyObject *trailers, |
5139 | int flags); |
5140 | |
5141 | static PyObject * |
5142 | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5143 | { |
5144 | PyObject *return_value = NULL; |
5145 | static const char * const _keywords[] = {"out_fd" , "in_fd" , "offset" , "count" , "headers" , "trailers" , "flags" , NULL}; |
5146 | static _PyArg_Parser _parser = {NULL, _keywords, "sendfile" , 0}; |
5147 | PyObject *argsbuf[7]; |
5148 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4; |
5149 | int out_fd; |
5150 | int in_fd; |
5151 | Py_off_t offset; |
5152 | Py_ssize_t count; |
5153 | PyObject *headers = NULL; |
5154 | PyObject *trailers = NULL; |
5155 | int flags = 0; |
5156 | |
5157 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf); |
5158 | if (!args) { |
5159 | goto exit; |
5160 | } |
5161 | out_fd = _PyLong_AsInt(args[0]); |
5162 | if (out_fd == -1 && PyErr_Occurred()) { |
5163 | goto exit; |
5164 | } |
5165 | in_fd = _PyLong_AsInt(args[1]); |
5166 | if (in_fd == -1 && PyErr_Occurred()) { |
5167 | goto exit; |
5168 | } |
5169 | if (!Py_off_t_converter(args[2], &offset)) { |
5170 | goto exit; |
5171 | } |
5172 | { |
5173 | Py_ssize_t ival = -1; |
5174 | PyObject *iobj = _PyNumber_Index(args[3]); |
5175 | if (iobj != NULL) { |
5176 | ival = PyLong_AsSsize_t(iobj); |
5177 | Py_DECREF(iobj); |
5178 | } |
5179 | if (ival == -1 && PyErr_Occurred()) { |
5180 | goto exit; |
5181 | } |
5182 | count = ival; |
5183 | } |
5184 | if (!noptargs) { |
5185 | goto skip_optional_pos; |
5186 | } |
5187 | if (args[4]) { |
5188 | headers = args[4]; |
5189 | if (!--noptargs) { |
5190 | goto skip_optional_pos; |
5191 | } |
5192 | } |
5193 | if (args[5]) { |
5194 | trailers = args[5]; |
5195 | if (!--noptargs) { |
5196 | goto skip_optional_pos; |
5197 | } |
5198 | } |
5199 | flags = _PyLong_AsInt(args[6]); |
5200 | if (flags == -1 && PyErr_Occurred()) { |
5201 | goto exit; |
5202 | } |
5203 | skip_optional_pos: |
5204 | return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags); |
5205 | |
5206 | exit: |
5207 | return return_value; |
5208 | } |
5209 | |
5210 | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */ |
5211 | |
5212 | #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) |
5213 | |
5214 | PyDoc_STRVAR(os_sendfile__doc__, |
5215 | "sendfile($module, /, out_fd, in_fd, offset, count)\n" |
5216 | "--\n" |
5217 | "\n" |
5218 | "Copy count bytes from file descriptor in_fd to file descriptor out_fd." ); |
5219 | |
5220 | #define OS_SENDFILE_METHODDEF \ |
5221 | {"sendfile", (PyCFunction)(void(*)(void))os_sendfile, METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__}, |
5222 | |
5223 | static PyObject * |
5224 | os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj, |
5225 | Py_ssize_t count); |
5226 | |
5227 | static PyObject * |
5228 | os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5229 | { |
5230 | PyObject *return_value = NULL; |
5231 | static const char * const _keywords[] = {"out_fd" , "in_fd" , "offset" , "count" , NULL}; |
5232 | static _PyArg_Parser _parser = {NULL, _keywords, "sendfile" , 0}; |
5233 | PyObject *argsbuf[4]; |
5234 | int out_fd; |
5235 | int in_fd; |
5236 | PyObject *offobj; |
5237 | Py_ssize_t count; |
5238 | |
5239 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf); |
5240 | if (!args) { |
5241 | goto exit; |
5242 | } |
5243 | out_fd = _PyLong_AsInt(args[0]); |
5244 | if (out_fd == -1 && PyErr_Occurred()) { |
5245 | goto exit; |
5246 | } |
5247 | in_fd = _PyLong_AsInt(args[1]); |
5248 | if (in_fd == -1 && PyErr_Occurred()) { |
5249 | goto exit; |
5250 | } |
5251 | offobj = args[2]; |
5252 | { |
5253 | Py_ssize_t ival = -1; |
5254 | PyObject *iobj = _PyNumber_Index(args[3]); |
5255 | if (iobj != NULL) { |
5256 | ival = PyLong_AsSsize_t(iobj); |
5257 | Py_DECREF(iobj); |
5258 | } |
5259 | if (ival == -1 && PyErr_Occurred()) { |
5260 | goto exit; |
5261 | } |
5262 | count = ival; |
5263 | } |
5264 | return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count); |
5265 | |
5266 | exit: |
5267 | return return_value; |
5268 | } |
5269 | |
5270 | #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */ |
5271 | |
5272 | #if defined(__APPLE__) |
5273 | |
5274 | PyDoc_STRVAR(os__fcopyfile__doc__, |
5275 | "_fcopyfile($module, in_fd, out_fd, flags, /)\n" |
5276 | "--\n" |
5277 | "\n" |
5278 | "Efficiently copy content or metadata of 2 regular file descriptors (macOS)." ); |
5279 | |
5280 | #define OS__FCOPYFILE_METHODDEF \ |
5281 | {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__}, |
5282 | |
5283 | static PyObject * |
5284 | os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags); |
5285 | |
5286 | static PyObject * |
5287 | os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5288 | { |
5289 | PyObject *return_value = NULL; |
5290 | int in_fd; |
5291 | int out_fd; |
5292 | int flags; |
5293 | |
5294 | if (!_PyArg_CheckPositional("_fcopyfile" , nargs, 3, 3)) { |
5295 | goto exit; |
5296 | } |
5297 | in_fd = _PyLong_AsInt(args[0]); |
5298 | if (in_fd == -1 && PyErr_Occurred()) { |
5299 | goto exit; |
5300 | } |
5301 | out_fd = _PyLong_AsInt(args[1]); |
5302 | if (out_fd == -1 && PyErr_Occurred()) { |
5303 | goto exit; |
5304 | } |
5305 | flags = _PyLong_AsInt(args[2]); |
5306 | if (flags == -1 && PyErr_Occurred()) { |
5307 | goto exit; |
5308 | } |
5309 | return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags); |
5310 | |
5311 | exit: |
5312 | return return_value; |
5313 | } |
5314 | |
5315 | #endif /* defined(__APPLE__) */ |
5316 | |
5317 | PyDoc_STRVAR(os_fstat__doc__, |
5318 | "fstat($module, /, fd)\n" |
5319 | "--\n" |
5320 | "\n" |
5321 | "Perform a stat system call on the given file descriptor.\n" |
5322 | "\n" |
5323 | "Like stat(), but for an open file descriptor.\n" |
5324 | "Equivalent to os.stat(fd)." ); |
5325 | |
5326 | #define OS_FSTAT_METHODDEF \ |
5327 | {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__}, |
5328 | |
5329 | static PyObject * |
5330 | os_fstat_impl(PyObject *module, int fd); |
5331 | |
5332 | static PyObject * |
5333 | os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5334 | { |
5335 | PyObject *return_value = NULL; |
5336 | static const char * const _keywords[] = {"fd" , NULL}; |
5337 | static _PyArg_Parser _parser = {NULL, _keywords, "fstat" , 0}; |
5338 | PyObject *argsbuf[1]; |
5339 | int fd; |
5340 | |
5341 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
5342 | if (!args) { |
5343 | goto exit; |
5344 | } |
5345 | fd = _PyLong_AsInt(args[0]); |
5346 | if (fd == -1 && PyErr_Occurred()) { |
5347 | goto exit; |
5348 | } |
5349 | return_value = os_fstat_impl(module, fd); |
5350 | |
5351 | exit: |
5352 | return return_value; |
5353 | } |
5354 | |
5355 | PyDoc_STRVAR(os_isatty__doc__, |
5356 | "isatty($module, fd, /)\n" |
5357 | "--\n" |
5358 | "\n" |
5359 | "Return True if the fd is connected to a terminal.\n" |
5360 | "\n" |
5361 | "Return True if the file descriptor is an open file descriptor\n" |
5362 | "connected to the slave end of a terminal." ); |
5363 | |
5364 | #define OS_ISATTY_METHODDEF \ |
5365 | {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, |
5366 | |
5367 | static int |
5368 | os_isatty_impl(PyObject *module, int fd); |
5369 | |
5370 | static PyObject * |
5371 | os_isatty(PyObject *module, PyObject *arg) |
5372 | { |
5373 | PyObject *return_value = NULL; |
5374 | int fd; |
5375 | int _return_value; |
5376 | |
5377 | fd = _PyLong_AsInt(arg); |
5378 | if (fd == -1 && PyErr_Occurred()) { |
5379 | goto exit; |
5380 | } |
5381 | _return_value = os_isatty_impl(module, fd); |
5382 | if ((_return_value == -1) && PyErr_Occurred()) { |
5383 | goto exit; |
5384 | } |
5385 | return_value = PyBool_FromLong((long)_return_value); |
5386 | |
5387 | exit: |
5388 | return return_value; |
5389 | } |
5390 | |
5391 | #if defined(HAVE_PIPE) |
5392 | |
5393 | PyDoc_STRVAR(os_pipe__doc__, |
5394 | "pipe($module, /)\n" |
5395 | "--\n" |
5396 | "\n" |
5397 | "Create a pipe.\n" |
5398 | "\n" |
5399 | "Returns a tuple of two file descriptors:\n" |
5400 | " (read_fd, write_fd)" ); |
5401 | |
5402 | #define OS_PIPE_METHODDEF \ |
5403 | {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, |
5404 | |
5405 | static PyObject * |
5406 | os_pipe_impl(PyObject *module); |
5407 | |
5408 | static PyObject * |
5409 | os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored)) |
5410 | { |
5411 | return os_pipe_impl(module); |
5412 | } |
5413 | |
5414 | #endif /* defined(HAVE_PIPE) */ |
5415 | |
5416 | #if defined(HAVE_PIPE2) |
5417 | |
5418 | PyDoc_STRVAR(os_pipe2__doc__, |
5419 | "pipe2($module, flags, /)\n" |
5420 | "--\n" |
5421 | "\n" |
5422 | "Create a pipe with flags set atomically.\n" |
5423 | "\n" |
5424 | "Returns a tuple of two file descriptors:\n" |
5425 | " (read_fd, write_fd)\n" |
5426 | "\n" |
5427 | "flags can be constructed by ORing together one or more of these values:\n" |
5428 | "O_NONBLOCK, O_CLOEXEC." ); |
5429 | |
5430 | #define OS_PIPE2_METHODDEF \ |
5431 | {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__}, |
5432 | |
5433 | static PyObject * |
5434 | os_pipe2_impl(PyObject *module, int flags); |
5435 | |
5436 | static PyObject * |
5437 | os_pipe2(PyObject *module, PyObject *arg) |
5438 | { |
5439 | PyObject *return_value = NULL; |
5440 | int flags; |
5441 | |
5442 | flags = _PyLong_AsInt(arg); |
5443 | if (flags == -1 && PyErr_Occurred()) { |
5444 | goto exit; |
5445 | } |
5446 | return_value = os_pipe2_impl(module, flags); |
5447 | |
5448 | exit: |
5449 | return return_value; |
5450 | } |
5451 | |
5452 | #endif /* defined(HAVE_PIPE2) */ |
5453 | |
5454 | #if defined(HAVE_WRITEV) |
5455 | |
5456 | PyDoc_STRVAR(os_writev__doc__, |
5457 | "writev($module, fd, buffers, /)\n" |
5458 | "--\n" |
5459 | "\n" |
5460 | "Iterate over buffers, and write the contents of each to a file descriptor.\n" |
5461 | "\n" |
5462 | "Returns the total number of bytes written.\n" |
5463 | "buffers must be a sequence of bytes-like objects." ); |
5464 | |
5465 | #define OS_WRITEV_METHODDEF \ |
5466 | {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__}, |
5467 | |
5468 | static Py_ssize_t |
5469 | os_writev_impl(PyObject *module, int fd, PyObject *buffers); |
5470 | |
5471 | static PyObject * |
5472 | os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5473 | { |
5474 | PyObject *return_value = NULL; |
5475 | int fd; |
5476 | PyObject *buffers; |
5477 | Py_ssize_t _return_value; |
5478 | |
5479 | if (!_PyArg_CheckPositional("writev" , nargs, 2, 2)) { |
5480 | goto exit; |
5481 | } |
5482 | fd = _PyLong_AsInt(args[0]); |
5483 | if (fd == -1 && PyErr_Occurred()) { |
5484 | goto exit; |
5485 | } |
5486 | buffers = args[1]; |
5487 | _return_value = os_writev_impl(module, fd, buffers); |
5488 | if ((_return_value == -1) && PyErr_Occurred()) { |
5489 | goto exit; |
5490 | } |
5491 | return_value = PyLong_FromSsize_t(_return_value); |
5492 | |
5493 | exit: |
5494 | return return_value; |
5495 | } |
5496 | |
5497 | #endif /* defined(HAVE_WRITEV) */ |
5498 | |
5499 | #if defined(HAVE_PWRITE) |
5500 | |
5501 | PyDoc_STRVAR(os_pwrite__doc__, |
5502 | "pwrite($module, fd, buffer, offset, /)\n" |
5503 | "--\n" |
5504 | "\n" |
5505 | "Write bytes to a file descriptor starting at a particular offset.\n" |
5506 | "\n" |
5507 | "Write buffer to fd, starting at offset bytes from the beginning of\n" |
5508 | "the file. Returns the number of bytes writte. Does not change the\n" |
5509 | "current file offset." ); |
5510 | |
5511 | #define OS_PWRITE_METHODDEF \ |
5512 | {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__}, |
5513 | |
5514 | static Py_ssize_t |
5515 | os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset); |
5516 | |
5517 | static PyObject * |
5518 | os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5519 | { |
5520 | PyObject *return_value = NULL; |
5521 | int fd; |
5522 | Py_buffer buffer = {NULL, NULL}; |
5523 | Py_off_t offset; |
5524 | Py_ssize_t _return_value; |
5525 | |
5526 | if (!_PyArg_CheckPositional("pwrite" , nargs, 3, 3)) { |
5527 | goto exit; |
5528 | } |
5529 | fd = _PyLong_AsInt(args[0]); |
5530 | if (fd == -1 && PyErr_Occurred()) { |
5531 | goto exit; |
5532 | } |
5533 | if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { |
5534 | goto exit; |
5535 | } |
5536 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
5537 | _PyArg_BadArgument("pwrite" , "argument 2" , "contiguous buffer" , args[1]); |
5538 | goto exit; |
5539 | } |
5540 | if (!Py_off_t_converter(args[2], &offset)) { |
5541 | goto exit; |
5542 | } |
5543 | _return_value = os_pwrite_impl(module, fd, &buffer, offset); |
5544 | if ((_return_value == -1) && PyErr_Occurred()) { |
5545 | goto exit; |
5546 | } |
5547 | return_value = PyLong_FromSsize_t(_return_value); |
5548 | |
5549 | exit: |
5550 | /* Cleanup for buffer */ |
5551 | if (buffer.obj) { |
5552 | PyBuffer_Release(&buffer); |
5553 | } |
5554 | |
5555 | return return_value; |
5556 | } |
5557 | |
5558 | #endif /* defined(HAVE_PWRITE) */ |
5559 | |
5560 | #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) |
5561 | |
5562 | PyDoc_STRVAR(os_pwritev__doc__, |
5563 | "pwritev($module, fd, buffers, offset, flags=0, /)\n" |
5564 | "--\n" |
5565 | "\n" |
5566 | "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n" |
5567 | "\n" |
5568 | "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n" |
5569 | "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n" |
5570 | "buffer is written before proceeding to second, and so on. The operating system may\n" |
5571 | "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n" |
5572 | "This function writes the contents of each object to the file descriptor and returns\n" |
5573 | "the total number of bytes written.\n" |
5574 | "\n" |
5575 | "The flags argument contains a bitwise OR of zero or more of the following flags:\n" |
5576 | "\n" |
5577 | "- RWF_DSYNC\n" |
5578 | "- RWF_SYNC\n" |
5579 | "- RWF_APPEND\n" |
5580 | "\n" |
5581 | "Using non-zero flags requires Linux 4.7 or newer." ); |
5582 | |
5583 | #define OS_PWRITEV_METHODDEF \ |
5584 | {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__}, |
5585 | |
5586 | static Py_ssize_t |
5587 | os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, |
5588 | int flags); |
5589 | |
5590 | static PyObject * |
5591 | os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
5592 | { |
5593 | PyObject *return_value = NULL; |
5594 | int fd; |
5595 | PyObject *buffers; |
5596 | Py_off_t offset; |
5597 | int flags = 0; |
5598 | Py_ssize_t _return_value; |
5599 | |
5600 | if (!_PyArg_CheckPositional("pwritev" , nargs, 3, 4)) { |
5601 | goto exit; |
5602 | } |
5603 | fd = _PyLong_AsInt(args[0]); |
5604 | if (fd == -1 && PyErr_Occurred()) { |
5605 | goto exit; |
5606 | } |
5607 | buffers = args[1]; |
5608 | if (!Py_off_t_converter(args[2], &offset)) { |
5609 | goto exit; |
5610 | } |
5611 | if (nargs < 4) { |
5612 | goto skip_optional; |
5613 | } |
5614 | flags = _PyLong_AsInt(args[3]); |
5615 | if (flags == -1 && PyErr_Occurred()) { |
5616 | goto exit; |
5617 | } |
5618 | skip_optional: |
5619 | _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); |
5620 | if ((_return_value == -1) && PyErr_Occurred()) { |
5621 | goto exit; |
5622 | } |
5623 | return_value = PyLong_FromSsize_t(_return_value); |
5624 | |
5625 | exit: |
5626 | return return_value; |
5627 | } |
5628 | |
5629 | #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */ |
5630 | |
5631 | #if defined(HAVE_COPY_FILE_RANGE) |
5632 | |
5633 | PyDoc_STRVAR(os_copy_file_range__doc__, |
5634 | "copy_file_range($module, /, src, dst, count, offset_src=None,\n" |
5635 | " offset_dst=None)\n" |
5636 | "--\n" |
5637 | "\n" |
5638 | "Copy count bytes from one file descriptor to another.\n" |
5639 | "\n" |
5640 | " src\n" |
5641 | " Source file descriptor.\n" |
5642 | " dst\n" |
5643 | " Destination file descriptor.\n" |
5644 | " count\n" |
5645 | " Number of bytes to copy.\n" |
5646 | " offset_src\n" |
5647 | " Starting offset in src.\n" |
5648 | " offset_dst\n" |
5649 | " Starting offset in dst.\n" |
5650 | "\n" |
5651 | "If offset_src is None, then src is read from the current position;\n" |
5652 | "respectively for offset_dst." ); |
5653 | |
5654 | #define OS_COPY_FILE_RANGE_METHODDEF \ |
5655 | {"copy_file_range", (PyCFunction)(void(*)(void))os_copy_file_range, METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__}, |
5656 | |
5657 | static PyObject * |
5658 | os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
5659 | PyObject *offset_src, PyObject *offset_dst); |
5660 | |
5661 | static PyObject * |
5662 | os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5663 | { |
5664 | PyObject *return_value = NULL; |
5665 | static const char * const _keywords[] = {"src" , "dst" , "count" , "offset_src" , "offset_dst" , NULL}; |
5666 | static _PyArg_Parser _parser = {NULL, _keywords, "copy_file_range" , 0}; |
5667 | PyObject *argsbuf[5]; |
5668 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
5669 | int src; |
5670 | int dst; |
5671 | Py_ssize_t count; |
5672 | PyObject *offset_src = Py_None; |
5673 | PyObject *offset_dst = Py_None; |
5674 | |
5675 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 5, 0, argsbuf); |
5676 | if (!args) { |
5677 | goto exit; |
5678 | } |
5679 | src = _PyLong_AsInt(args[0]); |
5680 | if (src == -1 && PyErr_Occurred()) { |
5681 | goto exit; |
5682 | } |
5683 | dst = _PyLong_AsInt(args[1]); |
5684 | if (dst == -1 && PyErr_Occurred()) { |
5685 | goto exit; |
5686 | } |
5687 | { |
5688 | Py_ssize_t ival = -1; |
5689 | PyObject *iobj = _PyNumber_Index(args[2]); |
5690 | if (iobj != NULL) { |
5691 | ival = PyLong_AsSsize_t(iobj); |
5692 | Py_DECREF(iobj); |
5693 | } |
5694 | if (ival == -1 && PyErr_Occurred()) { |
5695 | goto exit; |
5696 | } |
5697 | count = ival; |
5698 | } |
5699 | if (!noptargs) { |
5700 | goto skip_optional_pos; |
5701 | } |
5702 | if (args[3]) { |
5703 | offset_src = args[3]; |
5704 | if (!--noptargs) { |
5705 | goto skip_optional_pos; |
5706 | } |
5707 | } |
5708 | offset_dst = args[4]; |
5709 | skip_optional_pos: |
5710 | return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst); |
5711 | |
5712 | exit: |
5713 | return return_value; |
5714 | } |
5715 | |
5716 | #endif /* defined(HAVE_COPY_FILE_RANGE) */ |
5717 | |
5718 | #if ((defined(HAVE_SPLICE) && !defined(_AIX))) |
5719 | |
5720 | PyDoc_STRVAR(os_splice__doc__, |
5721 | "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n" |
5722 | " flags=0)\n" |
5723 | "--\n" |
5724 | "\n" |
5725 | "Transfer count bytes from one pipe to a descriptor or vice versa.\n" |
5726 | "\n" |
5727 | " src\n" |
5728 | " Source file descriptor.\n" |
5729 | " dst\n" |
5730 | " Destination file descriptor.\n" |
5731 | " count\n" |
5732 | " Number of bytes to copy.\n" |
5733 | " offset_src\n" |
5734 | " Starting offset in src.\n" |
5735 | " offset_dst\n" |
5736 | " Starting offset in dst.\n" |
5737 | " flags\n" |
5738 | " Flags to modify the semantics of the call.\n" |
5739 | "\n" |
5740 | "If offset_src is None, then src is read from the current position;\n" |
5741 | "respectively for offset_dst. The offset associated to the file\n" |
5742 | "descriptor that refers to a pipe must be None." ); |
5743 | |
5744 | #define OS_SPLICE_METHODDEF \ |
5745 | {"splice", (PyCFunction)(void(*)(void))os_splice, METH_FASTCALL|METH_KEYWORDS, os_splice__doc__}, |
5746 | |
5747 | static PyObject * |
5748 | os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count, |
5749 | PyObject *offset_src, PyObject *offset_dst, |
5750 | unsigned int flags); |
5751 | |
5752 | static PyObject * |
5753 | os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5754 | { |
5755 | PyObject *return_value = NULL; |
5756 | static const char * const _keywords[] = {"src" , "dst" , "count" , "offset_src" , "offset_dst" , "flags" , NULL}; |
5757 | static _PyArg_Parser _parser = {NULL, _keywords, "splice" , 0}; |
5758 | PyObject *argsbuf[6]; |
5759 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
5760 | int src; |
5761 | int dst; |
5762 | Py_ssize_t count; |
5763 | PyObject *offset_src = Py_None; |
5764 | PyObject *offset_dst = Py_None; |
5765 | unsigned int flags = 0; |
5766 | |
5767 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf); |
5768 | if (!args) { |
5769 | goto exit; |
5770 | } |
5771 | src = _PyLong_AsInt(args[0]); |
5772 | if (src == -1 && PyErr_Occurred()) { |
5773 | goto exit; |
5774 | } |
5775 | dst = _PyLong_AsInt(args[1]); |
5776 | if (dst == -1 && PyErr_Occurred()) { |
5777 | goto exit; |
5778 | } |
5779 | { |
5780 | Py_ssize_t ival = -1; |
5781 | PyObject *iobj = _PyNumber_Index(args[2]); |
5782 | if (iobj != NULL) { |
5783 | ival = PyLong_AsSsize_t(iobj); |
5784 | Py_DECREF(iobj); |
5785 | } |
5786 | if (ival == -1 && PyErr_Occurred()) { |
5787 | goto exit; |
5788 | } |
5789 | count = ival; |
5790 | } |
5791 | if (!noptargs) { |
5792 | goto skip_optional_pos; |
5793 | } |
5794 | if (args[3]) { |
5795 | offset_src = args[3]; |
5796 | if (!--noptargs) { |
5797 | goto skip_optional_pos; |
5798 | } |
5799 | } |
5800 | if (args[4]) { |
5801 | offset_dst = args[4]; |
5802 | if (!--noptargs) { |
5803 | goto skip_optional_pos; |
5804 | } |
5805 | } |
5806 | if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) { |
5807 | goto exit; |
5808 | } |
5809 | skip_optional_pos: |
5810 | return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags); |
5811 | |
5812 | exit: |
5813 | return return_value; |
5814 | } |
5815 | |
5816 | #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */ |
5817 | |
5818 | #if defined(HAVE_MKFIFO) |
5819 | |
5820 | PyDoc_STRVAR(os_mkfifo__doc__, |
5821 | "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" |
5822 | "--\n" |
5823 | "\n" |
5824 | "Create a \"fifo\" (a POSIX named pipe).\n" |
5825 | "\n" |
5826 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
5827 | " and path should be relative; path will then be relative to that directory.\n" |
5828 | "dir_fd may not be implemented on your platform.\n" |
5829 | " If it is unavailable, using it will raise a NotImplementedError." ); |
5830 | |
5831 | #define OS_MKFIFO_METHODDEF \ |
5832 | {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__}, |
5833 | |
5834 | static PyObject * |
5835 | os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd); |
5836 | |
5837 | static PyObject * |
5838 | os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5839 | { |
5840 | PyObject *return_value = NULL; |
5841 | static const char * const _keywords[] = {"path" , "mode" , "dir_fd" , NULL}; |
5842 | static _PyArg_Parser _parser = {NULL, _keywords, "mkfifo" , 0}; |
5843 | PyObject *argsbuf[3]; |
5844 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
5845 | path_t path = PATH_T_INITIALIZE("mkfifo" , "path" , 0, 0); |
5846 | int mode = 438; |
5847 | int dir_fd = DEFAULT_DIR_FD; |
5848 | |
5849 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
5850 | if (!args) { |
5851 | goto exit; |
5852 | } |
5853 | if (!path_converter(args[0], &path)) { |
5854 | goto exit; |
5855 | } |
5856 | if (!noptargs) { |
5857 | goto skip_optional_pos; |
5858 | } |
5859 | if (args[1]) { |
5860 | mode = _PyLong_AsInt(args[1]); |
5861 | if (mode == -1 && PyErr_Occurred()) { |
5862 | goto exit; |
5863 | } |
5864 | if (!--noptargs) { |
5865 | goto skip_optional_pos; |
5866 | } |
5867 | } |
5868 | skip_optional_pos: |
5869 | if (!noptargs) { |
5870 | goto skip_optional_kwonly; |
5871 | } |
5872 | if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) { |
5873 | goto exit; |
5874 | } |
5875 | skip_optional_kwonly: |
5876 | return_value = os_mkfifo_impl(module, &path, mode, dir_fd); |
5877 | |
5878 | exit: |
5879 | /* Cleanup for path */ |
5880 | path_cleanup(&path); |
5881 | |
5882 | return return_value; |
5883 | } |
5884 | |
5885 | #endif /* defined(HAVE_MKFIFO) */ |
5886 | |
5887 | #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) |
5888 | |
5889 | PyDoc_STRVAR(os_mknod__doc__, |
5890 | "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" |
5891 | "--\n" |
5892 | "\n" |
5893 | "Create a node in the file system.\n" |
5894 | "\n" |
5895 | "Create a node in the file system (file, device special file or named pipe)\n" |
5896 | "at path. mode specifies both the permissions to use and the\n" |
5897 | "type of node to be created, being combined (bitwise OR) with one of\n" |
5898 | "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" |
5899 | "device defines the newly created device special file (probably using\n" |
5900 | "os.makedev()). Otherwise device is ignored.\n" |
5901 | "\n" |
5902 | "If dir_fd is not None, it should be a file descriptor open to a directory,\n" |
5903 | " and path should be relative; path will then be relative to that directory.\n" |
5904 | "dir_fd may not be implemented on your platform.\n" |
5905 | " If it is unavailable, using it will raise a NotImplementedError." ); |
5906 | |
5907 | #define OS_MKNOD_METHODDEF \ |
5908 | {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__}, |
5909 | |
5910 | static PyObject * |
5911 | os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device, |
5912 | int dir_fd); |
5913 | |
5914 | static PyObject * |
5915 | os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
5916 | { |
5917 | PyObject *return_value = NULL; |
5918 | static const char * const _keywords[] = {"path" , "mode" , "device" , "dir_fd" , NULL}; |
5919 | static _PyArg_Parser _parser = {NULL, _keywords, "mknod" , 0}; |
5920 | PyObject *argsbuf[4]; |
5921 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
5922 | path_t path = PATH_T_INITIALIZE("mknod" , "path" , 0, 0); |
5923 | int mode = 384; |
5924 | dev_t device = 0; |
5925 | int dir_fd = DEFAULT_DIR_FD; |
5926 | |
5927 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf); |
5928 | if (!args) { |
5929 | goto exit; |
5930 | } |
5931 | if (!path_converter(args[0], &path)) { |
5932 | goto exit; |
5933 | } |
5934 | if (!noptargs) { |
5935 | goto skip_optional_pos; |
5936 | } |
5937 | if (args[1]) { |
5938 | mode = _PyLong_AsInt(args[1]); |
5939 | if (mode == -1 && PyErr_Occurred()) { |
5940 | goto exit; |
5941 | } |
5942 | if (!--noptargs) { |
5943 | goto skip_optional_pos; |
5944 | } |
5945 | } |
5946 | if (args[2]) { |
5947 | if (!_Py_Dev_Converter(args[2], &device)) { |
5948 | goto exit; |
5949 | } |
5950 | if (!--noptargs) { |
5951 | goto skip_optional_pos; |
5952 | } |
5953 | } |
5954 | skip_optional_pos: |
5955 | if (!noptargs) { |
5956 | goto skip_optional_kwonly; |
5957 | } |
5958 | if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) { |
5959 | goto exit; |
5960 | } |
5961 | skip_optional_kwonly: |
5962 | return_value = os_mknod_impl(module, &path, mode, device, dir_fd); |
5963 | |
5964 | exit: |
5965 | /* Cleanup for path */ |
5966 | path_cleanup(&path); |
5967 | |
5968 | return return_value; |
5969 | } |
5970 | |
5971 | #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */ |
5972 | |
5973 | #if defined(HAVE_DEVICE_MACROS) |
5974 | |
5975 | PyDoc_STRVAR(os_major__doc__, |
5976 | "major($module, device, /)\n" |
5977 | "--\n" |
5978 | "\n" |
5979 | "Extracts a device major number from a raw device number." ); |
5980 | |
5981 | #define OS_MAJOR_METHODDEF \ |
5982 | {"major", (PyCFunction)os_major, METH_O, os_major__doc__}, |
5983 | |
5984 | static unsigned int |
5985 | os_major_impl(PyObject *module, dev_t device); |
5986 | |
5987 | static PyObject * |
5988 | os_major(PyObject *module, PyObject *arg) |
5989 | { |
5990 | PyObject *return_value = NULL; |
5991 | dev_t device; |
5992 | unsigned int _return_value; |
5993 | |
5994 | if (!_Py_Dev_Converter(arg, &device)) { |
5995 | goto exit; |
5996 | } |
5997 | _return_value = os_major_impl(module, device); |
5998 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
5999 | goto exit; |
6000 | } |
6001 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
6002 | |
6003 | exit: |
6004 | return return_value; |
6005 | } |
6006 | |
6007 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
6008 | |
6009 | #if defined(HAVE_DEVICE_MACROS) |
6010 | |
6011 | PyDoc_STRVAR(os_minor__doc__, |
6012 | "minor($module, device, /)\n" |
6013 | "--\n" |
6014 | "\n" |
6015 | "Extracts a device minor number from a raw device number." ); |
6016 | |
6017 | #define OS_MINOR_METHODDEF \ |
6018 | {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__}, |
6019 | |
6020 | static unsigned int |
6021 | os_minor_impl(PyObject *module, dev_t device); |
6022 | |
6023 | static PyObject * |
6024 | os_minor(PyObject *module, PyObject *arg) |
6025 | { |
6026 | PyObject *return_value = NULL; |
6027 | dev_t device; |
6028 | unsigned int _return_value; |
6029 | |
6030 | if (!_Py_Dev_Converter(arg, &device)) { |
6031 | goto exit; |
6032 | } |
6033 | _return_value = os_minor_impl(module, device); |
6034 | if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { |
6035 | goto exit; |
6036 | } |
6037 | return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); |
6038 | |
6039 | exit: |
6040 | return return_value; |
6041 | } |
6042 | |
6043 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
6044 | |
6045 | #if defined(HAVE_DEVICE_MACROS) |
6046 | |
6047 | PyDoc_STRVAR(os_makedev__doc__, |
6048 | "makedev($module, major, minor, /)\n" |
6049 | "--\n" |
6050 | "\n" |
6051 | "Composes a raw device number from the major and minor device numbers." ); |
6052 | |
6053 | #define OS_MAKEDEV_METHODDEF \ |
6054 | {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__}, |
6055 | |
6056 | static dev_t |
6057 | os_makedev_impl(PyObject *module, int major, int minor); |
6058 | |
6059 | static PyObject * |
6060 | os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6061 | { |
6062 | PyObject *return_value = NULL; |
6063 | int major; |
6064 | int minor; |
6065 | dev_t _return_value; |
6066 | |
6067 | if (!_PyArg_CheckPositional("makedev" , nargs, 2, 2)) { |
6068 | goto exit; |
6069 | } |
6070 | major = _PyLong_AsInt(args[0]); |
6071 | if (major == -1 && PyErr_Occurred()) { |
6072 | goto exit; |
6073 | } |
6074 | minor = _PyLong_AsInt(args[1]); |
6075 | if (minor == -1 && PyErr_Occurred()) { |
6076 | goto exit; |
6077 | } |
6078 | _return_value = os_makedev_impl(module, major, minor); |
6079 | if ((_return_value == (dev_t)-1) && PyErr_Occurred()) { |
6080 | goto exit; |
6081 | } |
6082 | return_value = _PyLong_FromDev(_return_value); |
6083 | |
6084 | exit: |
6085 | return return_value; |
6086 | } |
6087 | |
6088 | #endif /* defined(HAVE_DEVICE_MACROS) */ |
6089 | |
6090 | #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS) |
6091 | |
6092 | PyDoc_STRVAR(os_ftruncate__doc__, |
6093 | "ftruncate($module, fd, length, /)\n" |
6094 | "--\n" |
6095 | "\n" |
6096 | "Truncate a file, specified by file descriptor, to a specific length." ); |
6097 | |
6098 | #define OS_FTRUNCATE_METHODDEF \ |
6099 | {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__}, |
6100 | |
6101 | static PyObject * |
6102 | os_ftruncate_impl(PyObject *module, int fd, Py_off_t length); |
6103 | |
6104 | static PyObject * |
6105 | os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6106 | { |
6107 | PyObject *return_value = NULL; |
6108 | int fd; |
6109 | Py_off_t length; |
6110 | |
6111 | if (!_PyArg_CheckPositional("ftruncate" , nargs, 2, 2)) { |
6112 | goto exit; |
6113 | } |
6114 | fd = _PyLong_AsInt(args[0]); |
6115 | if (fd == -1 && PyErr_Occurred()) { |
6116 | goto exit; |
6117 | } |
6118 | if (!Py_off_t_converter(args[1], &length)) { |
6119 | goto exit; |
6120 | } |
6121 | return_value = os_ftruncate_impl(module, fd, length); |
6122 | |
6123 | exit: |
6124 | return return_value; |
6125 | } |
6126 | |
6127 | #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */ |
6128 | |
6129 | #if (defined HAVE_TRUNCATE || defined MS_WINDOWS) |
6130 | |
6131 | PyDoc_STRVAR(os_truncate__doc__, |
6132 | "truncate($module, /, path, length)\n" |
6133 | "--\n" |
6134 | "\n" |
6135 | "Truncate a file, specified by path, to a specific length.\n" |
6136 | "\n" |
6137 | "On some platforms, path may also be specified as an open file descriptor.\n" |
6138 | " If this functionality is unavailable, using it raises an exception." ); |
6139 | |
6140 | #define OS_TRUNCATE_METHODDEF \ |
6141 | {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__}, |
6142 | |
6143 | static PyObject * |
6144 | os_truncate_impl(PyObject *module, path_t *path, Py_off_t length); |
6145 | |
6146 | static PyObject * |
6147 | os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6148 | { |
6149 | PyObject *return_value = NULL; |
6150 | static const char * const _keywords[] = {"path" , "length" , NULL}; |
6151 | static _PyArg_Parser _parser = {NULL, _keywords, "truncate" , 0}; |
6152 | PyObject *argsbuf[2]; |
6153 | path_t path = PATH_T_INITIALIZE("truncate" , "path" , 0, PATH_HAVE_FTRUNCATE); |
6154 | Py_off_t length; |
6155 | |
6156 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
6157 | if (!args) { |
6158 | goto exit; |
6159 | } |
6160 | if (!path_converter(args[0], &path)) { |
6161 | goto exit; |
6162 | } |
6163 | if (!Py_off_t_converter(args[1], &length)) { |
6164 | goto exit; |
6165 | } |
6166 | return_value = os_truncate_impl(module, &path, length); |
6167 | |
6168 | exit: |
6169 | /* Cleanup for path */ |
6170 | path_cleanup(&path); |
6171 | |
6172 | return return_value; |
6173 | } |
6174 | |
6175 | #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */ |
6176 | |
6177 | #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) |
6178 | |
6179 | PyDoc_STRVAR(os_posix_fallocate__doc__, |
6180 | "posix_fallocate($module, fd, offset, length, /)\n" |
6181 | "--\n" |
6182 | "\n" |
6183 | "Ensure a file has allocated at least a particular number of bytes on disk.\n" |
6184 | "\n" |
6185 | "Ensure that the file specified by fd encompasses a range of bytes\n" |
6186 | "starting at offset bytes from the beginning and continuing for length bytes." ); |
6187 | |
6188 | #define OS_POSIX_FALLOCATE_METHODDEF \ |
6189 | {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__}, |
6190 | |
6191 | static PyObject * |
6192 | os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset, |
6193 | Py_off_t length); |
6194 | |
6195 | static PyObject * |
6196 | os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6197 | { |
6198 | PyObject *return_value = NULL; |
6199 | int fd; |
6200 | Py_off_t offset; |
6201 | Py_off_t length; |
6202 | |
6203 | if (!_PyArg_CheckPositional("posix_fallocate" , nargs, 3, 3)) { |
6204 | goto exit; |
6205 | } |
6206 | fd = _PyLong_AsInt(args[0]); |
6207 | if (fd == -1 && PyErr_Occurred()) { |
6208 | goto exit; |
6209 | } |
6210 | if (!Py_off_t_converter(args[1], &offset)) { |
6211 | goto exit; |
6212 | } |
6213 | if (!Py_off_t_converter(args[2], &length)) { |
6214 | goto exit; |
6215 | } |
6216 | return_value = os_posix_fallocate_impl(module, fd, offset, length); |
6217 | |
6218 | exit: |
6219 | return return_value; |
6220 | } |
6221 | |
6222 | #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
6223 | |
6224 | #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) |
6225 | |
6226 | PyDoc_STRVAR(os_posix_fadvise__doc__, |
6227 | "posix_fadvise($module, fd, offset, length, advice, /)\n" |
6228 | "--\n" |
6229 | "\n" |
6230 | "Announce an intention to access data in a specific pattern.\n" |
6231 | "\n" |
6232 | "Announce an intention to access data in a specific pattern, thus allowing\n" |
6233 | "the kernel to make optimizations.\n" |
6234 | "The advice applies to the region of the file specified by fd starting at\n" |
6235 | "offset and continuing for length bytes.\n" |
6236 | "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" |
6237 | "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" |
6238 | "POSIX_FADV_DONTNEED." ); |
6239 | |
6240 | #define OS_POSIX_FADVISE_METHODDEF \ |
6241 | {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__}, |
6242 | |
6243 | static PyObject * |
6244 | os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset, |
6245 | Py_off_t length, int advice); |
6246 | |
6247 | static PyObject * |
6248 | os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6249 | { |
6250 | PyObject *return_value = NULL; |
6251 | int fd; |
6252 | Py_off_t offset; |
6253 | Py_off_t length; |
6254 | int advice; |
6255 | |
6256 | if (!_PyArg_CheckPositional("posix_fadvise" , nargs, 4, 4)) { |
6257 | goto exit; |
6258 | } |
6259 | fd = _PyLong_AsInt(args[0]); |
6260 | if (fd == -1 && PyErr_Occurred()) { |
6261 | goto exit; |
6262 | } |
6263 | if (!Py_off_t_converter(args[1], &offset)) { |
6264 | goto exit; |
6265 | } |
6266 | if (!Py_off_t_converter(args[2], &length)) { |
6267 | goto exit; |
6268 | } |
6269 | advice = _PyLong_AsInt(args[3]); |
6270 | if (advice == -1 && PyErr_Occurred()) { |
6271 | goto exit; |
6272 | } |
6273 | return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); |
6274 | |
6275 | exit: |
6276 | return return_value; |
6277 | } |
6278 | |
6279 | #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */ |
6280 | |
6281 | #if defined(MS_WINDOWS) |
6282 | |
6283 | PyDoc_STRVAR(os_putenv__doc__, |
6284 | "putenv($module, name, value, /)\n" |
6285 | "--\n" |
6286 | "\n" |
6287 | "Change or add an environment variable." ); |
6288 | |
6289 | #define OS_PUTENV_METHODDEF \ |
6290 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
6291 | |
6292 | static PyObject * |
6293 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
6294 | |
6295 | static PyObject * |
6296 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6297 | { |
6298 | PyObject *return_value = NULL; |
6299 | PyObject *name; |
6300 | PyObject *value; |
6301 | |
6302 | if (!_PyArg_CheckPositional("putenv" , nargs, 2, 2)) { |
6303 | goto exit; |
6304 | } |
6305 | if (!PyUnicode_Check(args[0])) { |
6306 | _PyArg_BadArgument("putenv" , "argument 1" , "str" , args[0]); |
6307 | goto exit; |
6308 | } |
6309 | if (PyUnicode_READY(args[0]) == -1) { |
6310 | goto exit; |
6311 | } |
6312 | name = args[0]; |
6313 | if (!PyUnicode_Check(args[1])) { |
6314 | _PyArg_BadArgument("putenv" , "argument 2" , "str" , args[1]); |
6315 | goto exit; |
6316 | } |
6317 | if (PyUnicode_READY(args[1]) == -1) { |
6318 | goto exit; |
6319 | } |
6320 | value = args[1]; |
6321 | return_value = os_putenv_impl(module, name, value); |
6322 | |
6323 | exit: |
6324 | return return_value; |
6325 | } |
6326 | |
6327 | #endif /* defined(MS_WINDOWS) */ |
6328 | |
6329 | #if !defined(MS_WINDOWS) |
6330 | |
6331 | PyDoc_STRVAR(os_putenv__doc__, |
6332 | "putenv($module, name, value, /)\n" |
6333 | "--\n" |
6334 | "\n" |
6335 | "Change or add an environment variable." ); |
6336 | |
6337 | #define OS_PUTENV_METHODDEF \ |
6338 | {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__}, |
6339 | |
6340 | static PyObject * |
6341 | os_putenv_impl(PyObject *module, PyObject *name, PyObject *value); |
6342 | |
6343 | static PyObject * |
6344 | os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6345 | { |
6346 | PyObject *return_value = NULL; |
6347 | PyObject *name = NULL; |
6348 | PyObject *value = NULL; |
6349 | |
6350 | if (!_PyArg_CheckPositional("putenv" , nargs, 2, 2)) { |
6351 | goto exit; |
6352 | } |
6353 | if (!PyUnicode_FSConverter(args[0], &name)) { |
6354 | goto exit; |
6355 | } |
6356 | if (!PyUnicode_FSConverter(args[1], &value)) { |
6357 | goto exit; |
6358 | } |
6359 | return_value = os_putenv_impl(module, name, value); |
6360 | |
6361 | exit: |
6362 | /* Cleanup for name */ |
6363 | Py_XDECREF(name); |
6364 | /* Cleanup for value */ |
6365 | Py_XDECREF(value); |
6366 | |
6367 | return return_value; |
6368 | } |
6369 | |
6370 | #endif /* !defined(MS_WINDOWS) */ |
6371 | |
6372 | #if defined(MS_WINDOWS) |
6373 | |
6374 | PyDoc_STRVAR(os_unsetenv__doc__, |
6375 | "unsetenv($module, name, /)\n" |
6376 | "--\n" |
6377 | "\n" |
6378 | "Delete an environment variable." ); |
6379 | |
6380 | #define OS_UNSETENV_METHODDEF \ |
6381 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
6382 | |
6383 | static PyObject * |
6384 | os_unsetenv_impl(PyObject *module, PyObject *name); |
6385 | |
6386 | static PyObject * |
6387 | os_unsetenv(PyObject *module, PyObject *arg) |
6388 | { |
6389 | PyObject *return_value = NULL; |
6390 | PyObject *name; |
6391 | |
6392 | if (!PyUnicode_Check(arg)) { |
6393 | _PyArg_BadArgument("unsetenv" , "argument" , "str" , arg); |
6394 | goto exit; |
6395 | } |
6396 | if (PyUnicode_READY(arg) == -1) { |
6397 | goto exit; |
6398 | } |
6399 | name = arg; |
6400 | return_value = os_unsetenv_impl(module, name); |
6401 | |
6402 | exit: |
6403 | return return_value; |
6404 | } |
6405 | |
6406 | #endif /* defined(MS_WINDOWS) */ |
6407 | |
6408 | #if !defined(MS_WINDOWS) |
6409 | |
6410 | PyDoc_STRVAR(os_unsetenv__doc__, |
6411 | "unsetenv($module, name, /)\n" |
6412 | "--\n" |
6413 | "\n" |
6414 | "Delete an environment variable." ); |
6415 | |
6416 | #define OS_UNSETENV_METHODDEF \ |
6417 | {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__}, |
6418 | |
6419 | static PyObject * |
6420 | os_unsetenv_impl(PyObject *module, PyObject *name); |
6421 | |
6422 | static PyObject * |
6423 | os_unsetenv(PyObject *module, PyObject *arg) |
6424 | { |
6425 | PyObject *return_value = NULL; |
6426 | PyObject *name = NULL; |
6427 | |
6428 | if (!PyUnicode_FSConverter(arg, &name)) { |
6429 | goto exit; |
6430 | } |
6431 | return_value = os_unsetenv_impl(module, name); |
6432 | |
6433 | exit: |
6434 | /* Cleanup for name */ |
6435 | Py_XDECREF(name); |
6436 | |
6437 | return return_value; |
6438 | } |
6439 | |
6440 | #endif /* !defined(MS_WINDOWS) */ |
6441 | |
6442 | PyDoc_STRVAR(os_strerror__doc__, |
6443 | "strerror($module, code, /)\n" |
6444 | "--\n" |
6445 | "\n" |
6446 | "Translate an error code to a message string." ); |
6447 | |
6448 | #define OS_STRERROR_METHODDEF \ |
6449 | {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__}, |
6450 | |
6451 | static PyObject * |
6452 | os_strerror_impl(PyObject *module, int code); |
6453 | |
6454 | static PyObject * |
6455 | os_strerror(PyObject *module, PyObject *arg) |
6456 | { |
6457 | PyObject *return_value = NULL; |
6458 | int code; |
6459 | |
6460 | code = _PyLong_AsInt(arg); |
6461 | if (code == -1 && PyErr_Occurred()) { |
6462 | goto exit; |
6463 | } |
6464 | return_value = os_strerror_impl(module, code); |
6465 | |
6466 | exit: |
6467 | return return_value; |
6468 | } |
6469 | |
6470 | #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) |
6471 | |
6472 | PyDoc_STRVAR(os_WCOREDUMP__doc__, |
6473 | "WCOREDUMP($module, status, /)\n" |
6474 | "--\n" |
6475 | "\n" |
6476 | "Return True if the process returning status was dumped to a core file." ); |
6477 | |
6478 | #define OS_WCOREDUMP_METHODDEF \ |
6479 | {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__}, |
6480 | |
6481 | static int |
6482 | os_WCOREDUMP_impl(PyObject *module, int status); |
6483 | |
6484 | static PyObject * |
6485 | os_WCOREDUMP(PyObject *module, PyObject *arg) |
6486 | { |
6487 | PyObject *return_value = NULL; |
6488 | int status; |
6489 | int _return_value; |
6490 | |
6491 | status = _PyLong_AsInt(arg); |
6492 | if (status == -1 && PyErr_Occurred()) { |
6493 | goto exit; |
6494 | } |
6495 | _return_value = os_WCOREDUMP_impl(module, status); |
6496 | if ((_return_value == -1) && PyErr_Occurred()) { |
6497 | goto exit; |
6498 | } |
6499 | return_value = PyBool_FromLong((long)_return_value); |
6500 | |
6501 | exit: |
6502 | return return_value; |
6503 | } |
6504 | |
6505 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */ |
6506 | |
6507 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) |
6508 | |
6509 | PyDoc_STRVAR(os_WIFCONTINUED__doc__, |
6510 | "WIFCONTINUED($module, /, status)\n" |
6511 | "--\n" |
6512 | "\n" |
6513 | "Return True if a particular process was continued from a job control stop.\n" |
6514 | "\n" |
6515 | "Return True if the process returning status was continued from a\n" |
6516 | "job control stop." ); |
6517 | |
6518 | #define OS_WIFCONTINUED_METHODDEF \ |
6519 | {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__}, |
6520 | |
6521 | static int |
6522 | os_WIFCONTINUED_impl(PyObject *module, int status); |
6523 | |
6524 | static PyObject * |
6525 | os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6526 | { |
6527 | PyObject *return_value = NULL; |
6528 | static const char * const _keywords[] = {"status" , NULL}; |
6529 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFCONTINUED" , 0}; |
6530 | PyObject *argsbuf[1]; |
6531 | int status; |
6532 | int _return_value; |
6533 | |
6534 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6535 | if (!args) { |
6536 | goto exit; |
6537 | } |
6538 | status = _PyLong_AsInt(args[0]); |
6539 | if (status == -1 && PyErr_Occurred()) { |
6540 | goto exit; |
6541 | } |
6542 | _return_value = os_WIFCONTINUED_impl(module, status); |
6543 | if ((_return_value == -1) && PyErr_Occurred()) { |
6544 | goto exit; |
6545 | } |
6546 | return_value = PyBool_FromLong((long)_return_value); |
6547 | |
6548 | exit: |
6549 | return return_value; |
6550 | } |
6551 | |
6552 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */ |
6553 | |
6554 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) |
6555 | |
6556 | PyDoc_STRVAR(os_WIFSTOPPED__doc__, |
6557 | "WIFSTOPPED($module, /, status)\n" |
6558 | "--\n" |
6559 | "\n" |
6560 | "Return True if the process returning status was stopped." ); |
6561 | |
6562 | #define OS_WIFSTOPPED_METHODDEF \ |
6563 | {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__}, |
6564 | |
6565 | static int |
6566 | os_WIFSTOPPED_impl(PyObject *module, int status); |
6567 | |
6568 | static PyObject * |
6569 | os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6570 | { |
6571 | PyObject *return_value = NULL; |
6572 | static const char * const _keywords[] = {"status" , NULL}; |
6573 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFSTOPPED" , 0}; |
6574 | PyObject *argsbuf[1]; |
6575 | int status; |
6576 | int _return_value; |
6577 | |
6578 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6579 | if (!args) { |
6580 | goto exit; |
6581 | } |
6582 | status = _PyLong_AsInt(args[0]); |
6583 | if (status == -1 && PyErr_Occurred()) { |
6584 | goto exit; |
6585 | } |
6586 | _return_value = os_WIFSTOPPED_impl(module, status); |
6587 | if ((_return_value == -1) && PyErr_Occurred()) { |
6588 | goto exit; |
6589 | } |
6590 | return_value = PyBool_FromLong((long)_return_value); |
6591 | |
6592 | exit: |
6593 | return return_value; |
6594 | } |
6595 | |
6596 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */ |
6597 | |
6598 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) |
6599 | |
6600 | PyDoc_STRVAR(os_WIFSIGNALED__doc__, |
6601 | "WIFSIGNALED($module, /, status)\n" |
6602 | "--\n" |
6603 | "\n" |
6604 | "Return True if the process returning status was terminated by a signal." ); |
6605 | |
6606 | #define OS_WIFSIGNALED_METHODDEF \ |
6607 | {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__}, |
6608 | |
6609 | static int |
6610 | os_WIFSIGNALED_impl(PyObject *module, int status); |
6611 | |
6612 | static PyObject * |
6613 | os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6614 | { |
6615 | PyObject *return_value = NULL; |
6616 | static const char * const _keywords[] = {"status" , NULL}; |
6617 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFSIGNALED" , 0}; |
6618 | PyObject *argsbuf[1]; |
6619 | int status; |
6620 | int _return_value; |
6621 | |
6622 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6623 | if (!args) { |
6624 | goto exit; |
6625 | } |
6626 | status = _PyLong_AsInt(args[0]); |
6627 | if (status == -1 && PyErr_Occurred()) { |
6628 | goto exit; |
6629 | } |
6630 | _return_value = os_WIFSIGNALED_impl(module, status); |
6631 | if ((_return_value == -1) && PyErr_Occurred()) { |
6632 | goto exit; |
6633 | } |
6634 | return_value = PyBool_FromLong((long)_return_value); |
6635 | |
6636 | exit: |
6637 | return return_value; |
6638 | } |
6639 | |
6640 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */ |
6641 | |
6642 | #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) |
6643 | |
6644 | PyDoc_STRVAR(os_WIFEXITED__doc__, |
6645 | "WIFEXITED($module, /, status)\n" |
6646 | "--\n" |
6647 | "\n" |
6648 | "Return True if the process returning status exited via the exit() system call." ); |
6649 | |
6650 | #define OS_WIFEXITED_METHODDEF \ |
6651 | {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__}, |
6652 | |
6653 | static int |
6654 | os_WIFEXITED_impl(PyObject *module, int status); |
6655 | |
6656 | static PyObject * |
6657 | os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6658 | { |
6659 | PyObject *return_value = NULL; |
6660 | static const char * const _keywords[] = {"status" , NULL}; |
6661 | static _PyArg_Parser _parser = {NULL, _keywords, "WIFEXITED" , 0}; |
6662 | PyObject *argsbuf[1]; |
6663 | int status; |
6664 | int _return_value; |
6665 | |
6666 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6667 | if (!args) { |
6668 | goto exit; |
6669 | } |
6670 | status = _PyLong_AsInt(args[0]); |
6671 | if (status == -1 && PyErr_Occurred()) { |
6672 | goto exit; |
6673 | } |
6674 | _return_value = os_WIFEXITED_impl(module, status); |
6675 | if ((_return_value == -1) && PyErr_Occurred()) { |
6676 | goto exit; |
6677 | } |
6678 | return_value = PyBool_FromLong((long)_return_value); |
6679 | |
6680 | exit: |
6681 | return return_value; |
6682 | } |
6683 | |
6684 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */ |
6685 | |
6686 | #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) |
6687 | |
6688 | PyDoc_STRVAR(os_WEXITSTATUS__doc__, |
6689 | "WEXITSTATUS($module, /, status)\n" |
6690 | "--\n" |
6691 | "\n" |
6692 | "Return the process return code from status." ); |
6693 | |
6694 | #define OS_WEXITSTATUS_METHODDEF \ |
6695 | {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__}, |
6696 | |
6697 | static int |
6698 | os_WEXITSTATUS_impl(PyObject *module, int status); |
6699 | |
6700 | static PyObject * |
6701 | os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6702 | { |
6703 | PyObject *return_value = NULL; |
6704 | static const char * const _keywords[] = {"status" , NULL}; |
6705 | static _PyArg_Parser _parser = {NULL, _keywords, "WEXITSTATUS" , 0}; |
6706 | PyObject *argsbuf[1]; |
6707 | int status; |
6708 | int _return_value; |
6709 | |
6710 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6711 | if (!args) { |
6712 | goto exit; |
6713 | } |
6714 | status = _PyLong_AsInt(args[0]); |
6715 | if (status == -1 && PyErr_Occurred()) { |
6716 | goto exit; |
6717 | } |
6718 | _return_value = os_WEXITSTATUS_impl(module, status); |
6719 | if ((_return_value == -1) && PyErr_Occurred()) { |
6720 | goto exit; |
6721 | } |
6722 | return_value = PyLong_FromLong((long)_return_value); |
6723 | |
6724 | exit: |
6725 | return return_value; |
6726 | } |
6727 | |
6728 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */ |
6729 | |
6730 | #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) |
6731 | |
6732 | PyDoc_STRVAR(os_WTERMSIG__doc__, |
6733 | "WTERMSIG($module, /, status)\n" |
6734 | "--\n" |
6735 | "\n" |
6736 | "Return the signal that terminated the process that provided the status value." ); |
6737 | |
6738 | #define OS_WTERMSIG_METHODDEF \ |
6739 | {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__}, |
6740 | |
6741 | static int |
6742 | os_WTERMSIG_impl(PyObject *module, int status); |
6743 | |
6744 | static PyObject * |
6745 | os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6746 | { |
6747 | PyObject *return_value = NULL; |
6748 | static const char * const _keywords[] = {"status" , NULL}; |
6749 | static _PyArg_Parser _parser = {NULL, _keywords, "WTERMSIG" , 0}; |
6750 | PyObject *argsbuf[1]; |
6751 | int status; |
6752 | int _return_value; |
6753 | |
6754 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6755 | if (!args) { |
6756 | goto exit; |
6757 | } |
6758 | status = _PyLong_AsInt(args[0]); |
6759 | if (status == -1 && PyErr_Occurred()) { |
6760 | goto exit; |
6761 | } |
6762 | _return_value = os_WTERMSIG_impl(module, status); |
6763 | if ((_return_value == -1) && PyErr_Occurred()) { |
6764 | goto exit; |
6765 | } |
6766 | return_value = PyLong_FromLong((long)_return_value); |
6767 | |
6768 | exit: |
6769 | return return_value; |
6770 | } |
6771 | |
6772 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */ |
6773 | |
6774 | #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) |
6775 | |
6776 | PyDoc_STRVAR(os_WSTOPSIG__doc__, |
6777 | "WSTOPSIG($module, /, status)\n" |
6778 | "--\n" |
6779 | "\n" |
6780 | "Return the signal that stopped the process that provided the status value." ); |
6781 | |
6782 | #define OS_WSTOPSIG_METHODDEF \ |
6783 | {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__}, |
6784 | |
6785 | static int |
6786 | os_WSTOPSIG_impl(PyObject *module, int status); |
6787 | |
6788 | static PyObject * |
6789 | os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6790 | { |
6791 | PyObject *return_value = NULL; |
6792 | static const char * const _keywords[] = {"status" , NULL}; |
6793 | static _PyArg_Parser _parser = {NULL, _keywords, "WSTOPSIG" , 0}; |
6794 | PyObject *argsbuf[1]; |
6795 | int status; |
6796 | int _return_value; |
6797 | |
6798 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6799 | if (!args) { |
6800 | goto exit; |
6801 | } |
6802 | status = _PyLong_AsInt(args[0]); |
6803 | if (status == -1 && PyErr_Occurred()) { |
6804 | goto exit; |
6805 | } |
6806 | _return_value = os_WSTOPSIG_impl(module, status); |
6807 | if ((_return_value == -1) && PyErr_Occurred()) { |
6808 | goto exit; |
6809 | } |
6810 | return_value = PyLong_FromLong((long)_return_value); |
6811 | |
6812 | exit: |
6813 | return return_value; |
6814 | } |
6815 | |
6816 | #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */ |
6817 | |
6818 | #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) |
6819 | |
6820 | PyDoc_STRVAR(os_fstatvfs__doc__, |
6821 | "fstatvfs($module, fd, /)\n" |
6822 | "--\n" |
6823 | "\n" |
6824 | "Perform an fstatvfs system call on the given fd.\n" |
6825 | "\n" |
6826 | "Equivalent to statvfs(fd)." ); |
6827 | |
6828 | #define OS_FSTATVFS_METHODDEF \ |
6829 | {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__}, |
6830 | |
6831 | static PyObject * |
6832 | os_fstatvfs_impl(PyObject *module, int fd); |
6833 | |
6834 | static PyObject * |
6835 | os_fstatvfs(PyObject *module, PyObject *arg) |
6836 | { |
6837 | PyObject *return_value = NULL; |
6838 | int fd; |
6839 | |
6840 | fd = _PyLong_AsInt(arg); |
6841 | if (fd == -1 && PyErr_Occurred()) { |
6842 | goto exit; |
6843 | } |
6844 | return_value = os_fstatvfs_impl(module, fd); |
6845 | |
6846 | exit: |
6847 | return return_value; |
6848 | } |
6849 | |
6850 | #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
6851 | |
6852 | #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) |
6853 | |
6854 | PyDoc_STRVAR(os_statvfs__doc__, |
6855 | "statvfs($module, /, path)\n" |
6856 | "--\n" |
6857 | "\n" |
6858 | "Perform a statvfs system call on the given path.\n" |
6859 | "\n" |
6860 | "path may always be specified as a string.\n" |
6861 | "On some platforms, path may also be specified as an open file descriptor.\n" |
6862 | " If this functionality is unavailable, using it raises an exception." ); |
6863 | |
6864 | #define OS_STATVFS_METHODDEF \ |
6865 | {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__}, |
6866 | |
6867 | static PyObject * |
6868 | os_statvfs_impl(PyObject *module, path_t *path); |
6869 | |
6870 | static PyObject * |
6871 | os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6872 | { |
6873 | PyObject *return_value = NULL; |
6874 | static const char * const _keywords[] = {"path" , NULL}; |
6875 | static _PyArg_Parser _parser = {NULL, _keywords, "statvfs" , 0}; |
6876 | PyObject *argsbuf[1]; |
6877 | path_t path = PATH_T_INITIALIZE("statvfs" , "path" , 0, PATH_HAVE_FSTATVFS); |
6878 | |
6879 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6880 | if (!args) { |
6881 | goto exit; |
6882 | } |
6883 | if (!path_converter(args[0], &path)) { |
6884 | goto exit; |
6885 | } |
6886 | return_value = os_statvfs_impl(module, &path); |
6887 | |
6888 | exit: |
6889 | /* Cleanup for path */ |
6890 | path_cleanup(&path); |
6891 | |
6892 | return return_value; |
6893 | } |
6894 | |
6895 | #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */ |
6896 | |
6897 | #if defined(MS_WINDOWS) |
6898 | |
6899 | PyDoc_STRVAR(os__getdiskusage__doc__, |
6900 | "_getdiskusage($module, /, path)\n" |
6901 | "--\n" |
6902 | "\n" |
6903 | "Return disk usage statistics about the given path as a (total, free) tuple." ); |
6904 | |
6905 | #define OS__GETDISKUSAGE_METHODDEF \ |
6906 | {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__}, |
6907 | |
6908 | static PyObject * |
6909 | os__getdiskusage_impl(PyObject *module, path_t *path); |
6910 | |
6911 | static PyObject * |
6912 | os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
6913 | { |
6914 | PyObject *return_value = NULL; |
6915 | static const char * const _keywords[] = {"path" , NULL}; |
6916 | static _PyArg_Parser _parser = {NULL, _keywords, "_getdiskusage" , 0}; |
6917 | PyObject *argsbuf[1]; |
6918 | path_t path = PATH_T_INITIALIZE("_getdiskusage" , "path" , 0, 0); |
6919 | |
6920 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
6921 | if (!args) { |
6922 | goto exit; |
6923 | } |
6924 | if (!path_converter(args[0], &path)) { |
6925 | goto exit; |
6926 | } |
6927 | return_value = os__getdiskusage_impl(module, &path); |
6928 | |
6929 | exit: |
6930 | /* Cleanup for path */ |
6931 | path_cleanup(&path); |
6932 | |
6933 | return return_value; |
6934 | } |
6935 | |
6936 | #endif /* defined(MS_WINDOWS) */ |
6937 | |
6938 | #if defined(HAVE_FPATHCONF) |
6939 | |
6940 | PyDoc_STRVAR(os_fpathconf__doc__, |
6941 | "fpathconf($module, fd, name, /)\n" |
6942 | "--\n" |
6943 | "\n" |
6944 | "Return the configuration limit name for the file descriptor fd.\n" |
6945 | "\n" |
6946 | "If there is no limit, return -1." ); |
6947 | |
6948 | #define OS_FPATHCONF_METHODDEF \ |
6949 | {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__}, |
6950 | |
6951 | static long |
6952 | os_fpathconf_impl(PyObject *module, int fd, int name); |
6953 | |
6954 | static PyObject * |
6955 | os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
6956 | { |
6957 | PyObject *return_value = NULL; |
6958 | int fd; |
6959 | int name; |
6960 | long _return_value; |
6961 | |
6962 | if (!_PyArg_CheckPositional("fpathconf" , nargs, 2, 2)) { |
6963 | goto exit; |
6964 | } |
6965 | if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
6966 | goto exit; |
6967 | } |
6968 | if (!conv_path_confname(args[1], &name)) { |
6969 | goto exit; |
6970 | } |
6971 | _return_value = os_fpathconf_impl(module, fd, name); |
6972 | if ((_return_value == -1) && PyErr_Occurred()) { |
6973 | goto exit; |
6974 | } |
6975 | return_value = PyLong_FromLong(_return_value); |
6976 | |
6977 | exit: |
6978 | return return_value; |
6979 | } |
6980 | |
6981 | #endif /* defined(HAVE_FPATHCONF) */ |
6982 | |
6983 | #if defined(HAVE_PATHCONF) |
6984 | |
6985 | PyDoc_STRVAR(os_pathconf__doc__, |
6986 | "pathconf($module, /, path, name)\n" |
6987 | "--\n" |
6988 | "\n" |
6989 | "Return the configuration limit name for the file or directory path.\n" |
6990 | "\n" |
6991 | "If there is no limit, return -1.\n" |
6992 | "On some platforms, path may also be specified as an open file descriptor.\n" |
6993 | " If this functionality is unavailable, using it raises an exception." ); |
6994 | |
6995 | #define OS_PATHCONF_METHODDEF \ |
6996 | {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__}, |
6997 | |
6998 | static long |
6999 | os_pathconf_impl(PyObject *module, path_t *path, int name); |
7000 | |
7001 | static PyObject * |
7002 | os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7003 | { |
7004 | PyObject *return_value = NULL; |
7005 | static const char * const _keywords[] = {"path" , "name" , NULL}; |
7006 | static _PyArg_Parser _parser = {NULL, _keywords, "pathconf" , 0}; |
7007 | PyObject *argsbuf[2]; |
7008 | path_t path = PATH_T_INITIALIZE("pathconf" , "path" , 0, PATH_HAVE_FPATHCONF); |
7009 | int name; |
7010 | long _return_value; |
7011 | |
7012 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
7013 | if (!args) { |
7014 | goto exit; |
7015 | } |
7016 | if (!path_converter(args[0], &path)) { |
7017 | goto exit; |
7018 | } |
7019 | if (!conv_path_confname(args[1], &name)) { |
7020 | goto exit; |
7021 | } |
7022 | _return_value = os_pathconf_impl(module, &path, name); |
7023 | if ((_return_value == -1) && PyErr_Occurred()) { |
7024 | goto exit; |
7025 | } |
7026 | return_value = PyLong_FromLong(_return_value); |
7027 | |
7028 | exit: |
7029 | /* Cleanup for path */ |
7030 | path_cleanup(&path); |
7031 | |
7032 | return return_value; |
7033 | } |
7034 | |
7035 | #endif /* defined(HAVE_PATHCONF) */ |
7036 | |
7037 | #if defined(HAVE_CONFSTR) |
7038 | |
7039 | PyDoc_STRVAR(os_confstr__doc__, |
7040 | "confstr($module, name, /)\n" |
7041 | "--\n" |
7042 | "\n" |
7043 | "Return a string-valued system configuration variable." ); |
7044 | |
7045 | #define OS_CONFSTR_METHODDEF \ |
7046 | {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__}, |
7047 | |
7048 | static PyObject * |
7049 | os_confstr_impl(PyObject *module, int name); |
7050 | |
7051 | static PyObject * |
7052 | os_confstr(PyObject *module, PyObject *arg) |
7053 | { |
7054 | PyObject *return_value = NULL; |
7055 | int name; |
7056 | |
7057 | if (!conv_confstr_confname(arg, &name)) { |
7058 | goto exit; |
7059 | } |
7060 | return_value = os_confstr_impl(module, name); |
7061 | |
7062 | exit: |
7063 | return return_value; |
7064 | } |
7065 | |
7066 | #endif /* defined(HAVE_CONFSTR) */ |
7067 | |
7068 | #if defined(HAVE_SYSCONF) |
7069 | |
7070 | PyDoc_STRVAR(os_sysconf__doc__, |
7071 | "sysconf($module, name, /)\n" |
7072 | "--\n" |
7073 | "\n" |
7074 | "Return an integer-valued system configuration variable." ); |
7075 | |
7076 | #define OS_SYSCONF_METHODDEF \ |
7077 | {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__}, |
7078 | |
7079 | static long |
7080 | os_sysconf_impl(PyObject *module, int name); |
7081 | |
7082 | static PyObject * |
7083 | os_sysconf(PyObject *module, PyObject *arg) |
7084 | { |
7085 | PyObject *return_value = NULL; |
7086 | int name; |
7087 | long _return_value; |
7088 | |
7089 | if (!conv_sysconf_confname(arg, &name)) { |
7090 | goto exit; |
7091 | } |
7092 | _return_value = os_sysconf_impl(module, name); |
7093 | if ((_return_value == -1) && PyErr_Occurred()) { |
7094 | goto exit; |
7095 | } |
7096 | return_value = PyLong_FromLong(_return_value); |
7097 | |
7098 | exit: |
7099 | return return_value; |
7100 | } |
7101 | |
7102 | #endif /* defined(HAVE_SYSCONF) */ |
7103 | |
7104 | PyDoc_STRVAR(os_abort__doc__, |
7105 | "abort($module, /)\n" |
7106 | "--\n" |
7107 | "\n" |
7108 | "Abort the interpreter immediately.\n" |
7109 | "\n" |
7110 | "This function \'dumps core\' or otherwise fails in the hardest way possible\n" |
7111 | "on the hosting operating system. This function never returns." ); |
7112 | |
7113 | #define OS_ABORT_METHODDEF \ |
7114 | {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, |
7115 | |
7116 | static PyObject * |
7117 | os_abort_impl(PyObject *module); |
7118 | |
7119 | static PyObject * |
7120 | os_abort(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7121 | { |
7122 | return os_abort_impl(module); |
7123 | } |
7124 | |
7125 | #if defined(MS_WINDOWS) |
7126 | |
7127 | PyDoc_STRVAR(os_startfile__doc__, |
7128 | "startfile($module, /, filepath, operation=<unrepresentable>,\n" |
7129 | " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n" |
7130 | "--\n" |
7131 | "\n" |
7132 | "Start a file with its associated application.\n" |
7133 | "\n" |
7134 | "When \"operation\" is not specified or \"open\", this acts like\n" |
7135 | "double-clicking the file in Explorer, or giving the file name as an\n" |
7136 | "argument to the DOS \"start\" command: the file is opened with whatever\n" |
7137 | "application (if any) its extension is associated.\n" |
7138 | "When another \"operation\" is given, it specifies what should be done with\n" |
7139 | "the file. A typical operation is \"print\".\n" |
7140 | "\n" |
7141 | "\"arguments\" is passed to the application, but should be omitted if the\n" |
7142 | "file is a document.\n" |
7143 | "\n" |
7144 | "\"cwd\" is the working directory for the operation. If \"filepath\" is\n" |
7145 | "relative, it will be resolved against this directory. This argument\n" |
7146 | "should usually be an absolute path.\n" |
7147 | "\n" |
7148 | "\"show_cmd\" can be used to override the recommended visibility option.\n" |
7149 | "See the Windows ShellExecute documentation for values.\n" |
7150 | "\n" |
7151 | "startfile returns as soon as the associated application is launched.\n" |
7152 | "There is no option to wait for the application to close, and no way\n" |
7153 | "to retrieve the application\'s exit status.\n" |
7154 | "\n" |
7155 | "The filepath is relative to the current directory. If you want to use\n" |
7156 | "an absolute path, make sure the first character is not a slash (\"/\");\n" |
7157 | "the underlying Win32 ShellExecute function doesn\'t work if it is." ); |
7158 | |
7159 | #define OS_STARTFILE_METHODDEF \ |
7160 | {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__}, |
7161 | |
7162 | static PyObject * |
7163 | os_startfile_impl(PyObject *module, path_t *filepath, |
7164 | const Py_UNICODE *operation, const Py_UNICODE *arguments, |
7165 | path_t *cwd, int show_cmd); |
7166 | |
7167 | static PyObject * |
7168 | os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7169 | { |
7170 | PyObject *return_value = NULL; |
7171 | static const char * const _keywords[] = {"filepath" , "operation" , "arguments" , "cwd" , "show_cmd" , NULL}; |
7172 | static _PyArg_Parser _parser = {NULL, _keywords, "startfile" , 0}; |
7173 | PyObject *argsbuf[5]; |
7174 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
7175 | path_t filepath = PATH_T_INITIALIZE("startfile" , "filepath" , 0, 0); |
7176 | const Py_UNICODE *operation = NULL; |
7177 | const Py_UNICODE *arguments = NULL; |
7178 | path_t cwd = PATH_T_INITIALIZE("startfile" , "cwd" , 1, 0); |
7179 | int show_cmd = 1; |
7180 | |
7181 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf); |
7182 | if (!args) { |
7183 | goto exit; |
7184 | } |
7185 | if (!path_converter(args[0], &filepath)) { |
7186 | goto exit; |
7187 | } |
7188 | if (!noptargs) { |
7189 | goto skip_optional_pos; |
7190 | } |
7191 | if (args[1]) { |
7192 | if (!PyUnicode_Check(args[1])) { |
7193 | _PyArg_BadArgument("startfile" , "argument 'operation'" , "str" , args[1]); |
7194 | goto exit; |
7195 | } |
7196 | #if USE_UNICODE_WCHAR_CACHE |
7197 | operation = _PyUnicode_AsUnicode(args[1]); |
7198 | #else /* USE_UNICODE_WCHAR_CACHE */ |
7199 | operation = PyUnicode_AsWideCharString(args[1], NULL); |
7200 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
7201 | if (operation == NULL) { |
7202 | goto exit; |
7203 | } |
7204 | if (!--noptargs) { |
7205 | goto skip_optional_pos; |
7206 | } |
7207 | } |
7208 | if (args[2]) { |
7209 | if (!PyUnicode_Check(args[2])) { |
7210 | _PyArg_BadArgument("startfile" , "argument 'arguments'" , "str" , args[2]); |
7211 | goto exit; |
7212 | } |
7213 | #if USE_UNICODE_WCHAR_CACHE |
7214 | arguments = _PyUnicode_AsUnicode(args[2]); |
7215 | #else /* USE_UNICODE_WCHAR_CACHE */ |
7216 | arguments = PyUnicode_AsWideCharString(args[2], NULL); |
7217 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
7218 | if (arguments == NULL) { |
7219 | goto exit; |
7220 | } |
7221 | if (!--noptargs) { |
7222 | goto skip_optional_pos; |
7223 | } |
7224 | } |
7225 | if (args[3]) { |
7226 | if (!path_converter(args[3], &cwd)) { |
7227 | goto exit; |
7228 | } |
7229 | if (!--noptargs) { |
7230 | goto skip_optional_pos; |
7231 | } |
7232 | } |
7233 | show_cmd = _PyLong_AsInt(args[4]); |
7234 | if (show_cmd == -1 && PyErr_Occurred()) { |
7235 | goto exit; |
7236 | } |
7237 | skip_optional_pos: |
7238 | return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd); |
7239 | |
7240 | exit: |
7241 | /* Cleanup for filepath */ |
7242 | path_cleanup(&filepath); |
7243 | /* Cleanup for operation */ |
7244 | #if !USE_UNICODE_WCHAR_CACHE |
7245 | PyMem_Free((void *)operation); |
7246 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
7247 | /* Cleanup for arguments */ |
7248 | #if !USE_UNICODE_WCHAR_CACHE |
7249 | PyMem_Free((void *)arguments); |
7250 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
7251 | /* Cleanup for cwd */ |
7252 | path_cleanup(&cwd); |
7253 | |
7254 | return return_value; |
7255 | } |
7256 | |
7257 | #endif /* defined(MS_WINDOWS) */ |
7258 | |
7259 | #if defined(HAVE_GETLOADAVG) |
7260 | |
7261 | PyDoc_STRVAR(os_getloadavg__doc__, |
7262 | "getloadavg($module, /)\n" |
7263 | "--\n" |
7264 | "\n" |
7265 | "Return average recent system load information.\n" |
7266 | "\n" |
7267 | "Return the number of processes in the system run queue averaged over\n" |
7268 | "the last 1, 5, and 15 minutes as a tuple of three floats.\n" |
7269 | "Raises OSError if the load average was unobtainable." ); |
7270 | |
7271 | #define OS_GETLOADAVG_METHODDEF \ |
7272 | {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, |
7273 | |
7274 | static PyObject * |
7275 | os_getloadavg_impl(PyObject *module); |
7276 | |
7277 | static PyObject * |
7278 | os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7279 | { |
7280 | return os_getloadavg_impl(module); |
7281 | } |
7282 | |
7283 | #endif /* defined(HAVE_GETLOADAVG) */ |
7284 | |
7285 | PyDoc_STRVAR(os_device_encoding__doc__, |
7286 | "device_encoding($module, /, fd)\n" |
7287 | "--\n" |
7288 | "\n" |
7289 | "Return a string describing the encoding of a terminal\'s file descriptor.\n" |
7290 | "\n" |
7291 | "The file descriptor must be attached to a terminal.\n" |
7292 | "If the device is not a terminal, return None." ); |
7293 | |
7294 | #define OS_DEVICE_ENCODING_METHODDEF \ |
7295 | {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__}, |
7296 | |
7297 | static PyObject * |
7298 | os_device_encoding_impl(PyObject *module, int fd); |
7299 | |
7300 | static PyObject * |
7301 | os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7302 | { |
7303 | PyObject *return_value = NULL; |
7304 | static const char * const _keywords[] = {"fd" , NULL}; |
7305 | static _PyArg_Parser _parser = {NULL, _keywords, "device_encoding" , 0}; |
7306 | PyObject *argsbuf[1]; |
7307 | int fd; |
7308 | |
7309 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
7310 | if (!args) { |
7311 | goto exit; |
7312 | } |
7313 | fd = _PyLong_AsInt(args[0]); |
7314 | if (fd == -1 && PyErr_Occurred()) { |
7315 | goto exit; |
7316 | } |
7317 | return_value = os_device_encoding_impl(module, fd); |
7318 | |
7319 | exit: |
7320 | return return_value; |
7321 | } |
7322 | |
7323 | #if defined(HAVE_SETRESUID) |
7324 | |
7325 | PyDoc_STRVAR(os_setresuid__doc__, |
7326 | "setresuid($module, ruid, euid, suid, /)\n" |
7327 | "--\n" |
7328 | "\n" |
7329 | "Set the current process\'s real, effective, and saved user ids." ); |
7330 | |
7331 | #define OS_SETRESUID_METHODDEF \ |
7332 | {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__}, |
7333 | |
7334 | static PyObject * |
7335 | os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid); |
7336 | |
7337 | static PyObject * |
7338 | os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7339 | { |
7340 | PyObject *return_value = NULL; |
7341 | uid_t ruid; |
7342 | uid_t euid; |
7343 | uid_t suid; |
7344 | |
7345 | if (!_PyArg_CheckPositional("setresuid" , nargs, 3, 3)) { |
7346 | goto exit; |
7347 | } |
7348 | if (!_Py_Uid_Converter(args[0], &ruid)) { |
7349 | goto exit; |
7350 | } |
7351 | if (!_Py_Uid_Converter(args[1], &euid)) { |
7352 | goto exit; |
7353 | } |
7354 | if (!_Py_Uid_Converter(args[2], &suid)) { |
7355 | goto exit; |
7356 | } |
7357 | return_value = os_setresuid_impl(module, ruid, euid, suid); |
7358 | |
7359 | exit: |
7360 | return return_value; |
7361 | } |
7362 | |
7363 | #endif /* defined(HAVE_SETRESUID) */ |
7364 | |
7365 | #if defined(HAVE_SETRESGID) |
7366 | |
7367 | PyDoc_STRVAR(os_setresgid__doc__, |
7368 | "setresgid($module, rgid, egid, sgid, /)\n" |
7369 | "--\n" |
7370 | "\n" |
7371 | "Set the current process\'s real, effective, and saved group ids." ); |
7372 | |
7373 | #define OS_SETRESGID_METHODDEF \ |
7374 | {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__}, |
7375 | |
7376 | static PyObject * |
7377 | os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid); |
7378 | |
7379 | static PyObject * |
7380 | os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7381 | { |
7382 | PyObject *return_value = NULL; |
7383 | gid_t rgid; |
7384 | gid_t egid; |
7385 | gid_t sgid; |
7386 | |
7387 | if (!_PyArg_CheckPositional("setresgid" , nargs, 3, 3)) { |
7388 | goto exit; |
7389 | } |
7390 | if (!_Py_Gid_Converter(args[0], &rgid)) { |
7391 | goto exit; |
7392 | } |
7393 | if (!_Py_Gid_Converter(args[1], &egid)) { |
7394 | goto exit; |
7395 | } |
7396 | if (!_Py_Gid_Converter(args[2], &sgid)) { |
7397 | goto exit; |
7398 | } |
7399 | return_value = os_setresgid_impl(module, rgid, egid, sgid); |
7400 | |
7401 | exit: |
7402 | return return_value; |
7403 | } |
7404 | |
7405 | #endif /* defined(HAVE_SETRESGID) */ |
7406 | |
7407 | #if defined(HAVE_GETRESUID) |
7408 | |
7409 | PyDoc_STRVAR(os_getresuid__doc__, |
7410 | "getresuid($module, /)\n" |
7411 | "--\n" |
7412 | "\n" |
7413 | "Return a tuple of the current process\'s real, effective, and saved user ids." ); |
7414 | |
7415 | #define OS_GETRESUID_METHODDEF \ |
7416 | {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, |
7417 | |
7418 | static PyObject * |
7419 | os_getresuid_impl(PyObject *module); |
7420 | |
7421 | static PyObject * |
7422 | os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7423 | { |
7424 | return os_getresuid_impl(module); |
7425 | } |
7426 | |
7427 | #endif /* defined(HAVE_GETRESUID) */ |
7428 | |
7429 | #if defined(HAVE_GETRESGID) |
7430 | |
7431 | PyDoc_STRVAR(os_getresgid__doc__, |
7432 | "getresgid($module, /)\n" |
7433 | "--\n" |
7434 | "\n" |
7435 | "Return a tuple of the current process\'s real, effective, and saved group ids." ); |
7436 | |
7437 | #define OS_GETRESGID_METHODDEF \ |
7438 | {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, |
7439 | |
7440 | static PyObject * |
7441 | os_getresgid_impl(PyObject *module); |
7442 | |
7443 | static PyObject * |
7444 | os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored)) |
7445 | { |
7446 | return os_getresgid_impl(module); |
7447 | } |
7448 | |
7449 | #endif /* defined(HAVE_GETRESGID) */ |
7450 | |
7451 | #if defined(USE_XATTRS) |
7452 | |
7453 | PyDoc_STRVAR(os_getxattr__doc__, |
7454 | "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
7455 | "--\n" |
7456 | "\n" |
7457 | "Return the value of extended attribute attribute on path.\n" |
7458 | "\n" |
7459 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
7460 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
7461 | " link, getxattr will examine the symbolic link itself instead of the file\n" |
7462 | " the link points to." ); |
7463 | |
7464 | #define OS_GETXATTR_METHODDEF \ |
7465 | {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__}, |
7466 | |
7467 | static PyObject * |
7468 | os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
7469 | int follow_symlinks); |
7470 | |
7471 | static PyObject * |
7472 | os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7473 | { |
7474 | PyObject *return_value = NULL; |
7475 | static const char * const _keywords[] = {"path" , "attribute" , "follow_symlinks" , NULL}; |
7476 | static _PyArg_Parser _parser = {NULL, _keywords, "getxattr" , 0}; |
7477 | PyObject *argsbuf[3]; |
7478 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7479 | path_t path = PATH_T_INITIALIZE("getxattr" , "path" , 0, 1); |
7480 | path_t attribute = PATH_T_INITIALIZE("getxattr" , "attribute" , 0, 0); |
7481 | int follow_symlinks = 1; |
7482 | |
7483 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
7484 | if (!args) { |
7485 | goto exit; |
7486 | } |
7487 | if (!path_converter(args[0], &path)) { |
7488 | goto exit; |
7489 | } |
7490 | if (!path_converter(args[1], &attribute)) { |
7491 | goto exit; |
7492 | } |
7493 | if (!noptargs) { |
7494 | goto skip_optional_kwonly; |
7495 | } |
7496 | follow_symlinks = PyObject_IsTrue(args[2]); |
7497 | if (follow_symlinks < 0) { |
7498 | goto exit; |
7499 | } |
7500 | skip_optional_kwonly: |
7501 | return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); |
7502 | |
7503 | exit: |
7504 | /* Cleanup for path */ |
7505 | path_cleanup(&path); |
7506 | /* Cleanup for attribute */ |
7507 | path_cleanup(&attribute); |
7508 | |
7509 | return return_value; |
7510 | } |
7511 | |
7512 | #endif /* defined(USE_XATTRS) */ |
7513 | |
7514 | #if defined(USE_XATTRS) |
7515 | |
7516 | PyDoc_STRVAR(os_setxattr__doc__, |
7517 | "setxattr($module, /, path, attribute, value, flags=0, *,\n" |
7518 | " follow_symlinks=True)\n" |
7519 | "--\n" |
7520 | "\n" |
7521 | "Set extended attribute attribute on path to value.\n" |
7522 | "\n" |
7523 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
7524 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
7525 | " link, setxattr will modify the symbolic link itself instead of the file\n" |
7526 | " the link points to." ); |
7527 | |
7528 | #define OS_SETXATTR_METHODDEF \ |
7529 | {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__}, |
7530 | |
7531 | static PyObject * |
7532 | os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute, |
7533 | Py_buffer *value, int flags, int follow_symlinks); |
7534 | |
7535 | static PyObject * |
7536 | os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7537 | { |
7538 | PyObject *return_value = NULL; |
7539 | static const char * const _keywords[] = {"path" , "attribute" , "value" , "flags" , "follow_symlinks" , NULL}; |
7540 | static _PyArg_Parser _parser = {NULL, _keywords, "setxattr" , 0}; |
7541 | PyObject *argsbuf[5]; |
7542 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
7543 | path_t path = PATH_T_INITIALIZE("setxattr" , "path" , 0, 1); |
7544 | path_t attribute = PATH_T_INITIALIZE("setxattr" , "attribute" , 0, 0); |
7545 | Py_buffer value = {NULL, NULL}; |
7546 | int flags = 0; |
7547 | int follow_symlinks = 1; |
7548 | |
7549 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf); |
7550 | if (!args) { |
7551 | goto exit; |
7552 | } |
7553 | if (!path_converter(args[0], &path)) { |
7554 | goto exit; |
7555 | } |
7556 | if (!path_converter(args[1], &attribute)) { |
7557 | goto exit; |
7558 | } |
7559 | if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) { |
7560 | goto exit; |
7561 | } |
7562 | if (!PyBuffer_IsContiguous(&value, 'C')) { |
7563 | _PyArg_BadArgument("setxattr" , "argument 'value'" , "contiguous buffer" , args[2]); |
7564 | goto exit; |
7565 | } |
7566 | if (!noptargs) { |
7567 | goto skip_optional_pos; |
7568 | } |
7569 | if (args[3]) { |
7570 | flags = _PyLong_AsInt(args[3]); |
7571 | if (flags == -1 && PyErr_Occurred()) { |
7572 | goto exit; |
7573 | } |
7574 | if (!--noptargs) { |
7575 | goto skip_optional_pos; |
7576 | } |
7577 | } |
7578 | skip_optional_pos: |
7579 | if (!noptargs) { |
7580 | goto skip_optional_kwonly; |
7581 | } |
7582 | follow_symlinks = PyObject_IsTrue(args[4]); |
7583 | if (follow_symlinks < 0) { |
7584 | goto exit; |
7585 | } |
7586 | skip_optional_kwonly: |
7587 | return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); |
7588 | |
7589 | exit: |
7590 | /* Cleanup for path */ |
7591 | path_cleanup(&path); |
7592 | /* Cleanup for attribute */ |
7593 | path_cleanup(&attribute); |
7594 | /* Cleanup for value */ |
7595 | if (value.obj) { |
7596 | PyBuffer_Release(&value); |
7597 | } |
7598 | |
7599 | return return_value; |
7600 | } |
7601 | |
7602 | #endif /* defined(USE_XATTRS) */ |
7603 | |
7604 | #if defined(USE_XATTRS) |
7605 | |
7606 | PyDoc_STRVAR(os_removexattr__doc__, |
7607 | "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" |
7608 | "--\n" |
7609 | "\n" |
7610 | "Remove extended attribute attribute on path.\n" |
7611 | "\n" |
7612 | "path may be either a string, a path-like object, or an open file descriptor.\n" |
7613 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
7614 | " link, removexattr will modify the symbolic link itself instead of the file\n" |
7615 | " the link points to." ); |
7616 | |
7617 | #define OS_REMOVEXATTR_METHODDEF \ |
7618 | {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__}, |
7619 | |
7620 | static PyObject * |
7621 | os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute, |
7622 | int follow_symlinks); |
7623 | |
7624 | static PyObject * |
7625 | os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7626 | { |
7627 | PyObject *return_value = NULL; |
7628 | static const char * const _keywords[] = {"path" , "attribute" , "follow_symlinks" , NULL}; |
7629 | static _PyArg_Parser _parser = {NULL, _keywords, "removexattr" , 0}; |
7630 | PyObject *argsbuf[3]; |
7631 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
7632 | path_t path = PATH_T_INITIALIZE("removexattr" , "path" , 0, 1); |
7633 | path_t attribute = PATH_T_INITIALIZE("removexattr" , "attribute" , 0, 0); |
7634 | int follow_symlinks = 1; |
7635 | |
7636 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
7637 | if (!args) { |
7638 | goto exit; |
7639 | } |
7640 | if (!path_converter(args[0], &path)) { |
7641 | goto exit; |
7642 | } |
7643 | if (!path_converter(args[1], &attribute)) { |
7644 | goto exit; |
7645 | } |
7646 | if (!noptargs) { |
7647 | goto skip_optional_kwonly; |
7648 | } |
7649 | follow_symlinks = PyObject_IsTrue(args[2]); |
7650 | if (follow_symlinks < 0) { |
7651 | goto exit; |
7652 | } |
7653 | skip_optional_kwonly: |
7654 | return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); |
7655 | |
7656 | exit: |
7657 | /* Cleanup for path */ |
7658 | path_cleanup(&path); |
7659 | /* Cleanup for attribute */ |
7660 | path_cleanup(&attribute); |
7661 | |
7662 | return return_value; |
7663 | } |
7664 | |
7665 | #endif /* defined(USE_XATTRS) */ |
7666 | |
7667 | #if defined(USE_XATTRS) |
7668 | |
7669 | PyDoc_STRVAR(os_listxattr__doc__, |
7670 | "listxattr($module, /, path=None, *, follow_symlinks=True)\n" |
7671 | "--\n" |
7672 | "\n" |
7673 | "Return a list of extended attributes on path.\n" |
7674 | "\n" |
7675 | "path may be either None, a string, a path-like object, or an open file descriptor.\n" |
7676 | "if path is None, listxattr will examine the current directory.\n" |
7677 | "If follow_symlinks is False, and the last element of the path is a symbolic\n" |
7678 | " link, listxattr will examine the symbolic link itself instead of the file\n" |
7679 | " the link points to." ); |
7680 | |
7681 | #define OS_LISTXATTR_METHODDEF \ |
7682 | {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__}, |
7683 | |
7684 | static PyObject * |
7685 | os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks); |
7686 | |
7687 | static PyObject * |
7688 | os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7689 | { |
7690 | PyObject *return_value = NULL; |
7691 | static const char * const _keywords[] = {"path" , "follow_symlinks" , NULL}; |
7692 | static _PyArg_Parser _parser = {NULL, _keywords, "listxattr" , 0}; |
7693 | PyObject *argsbuf[2]; |
7694 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
7695 | path_t path = PATH_T_INITIALIZE("listxattr" , "path" , 1, 1); |
7696 | int follow_symlinks = 1; |
7697 | |
7698 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
7699 | if (!args) { |
7700 | goto exit; |
7701 | } |
7702 | if (!noptargs) { |
7703 | goto skip_optional_pos; |
7704 | } |
7705 | if (args[0]) { |
7706 | if (!path_converter(args[0], &path)) { |
7707 | goto exit; |
7708 | } |
7709 | if (!--noptargs) { |
7710 | goto skip_optional_pos; |
7711 | } |
7712 | } |
7713 | skip_optional_pos: |
7714 | if (!noptargs) { |
7715 | goto skip_optional_kwonly; |
7716 | } |
7717 | follow_symlinks = PyObject_IsTrue(args[1]); |
7718 | if (follow_symlinks < 0) { |
7719 | goto exit; |
7720 | } |
7721 | skip_optional_kwonly: |
7722 | return_value = os_listxattr_impl(module, &path, follow_symlinks); |
7723 | |
7724 | exit: |
7725 | /* Cleanup for path */ |
7726 | path_cleanup(&path); |
7727 | |
7728 | return return_value; |
7729 | } |
7730 | |
7731 | #endif /* defined(USE_XATTRS) */ |
7732 | |
7733 | PyDoc_STRVAR(os_urandom__doc__, |
7734 | "urandom($module, size, /)\n" |
7735 | "--\n" |
7736 | "\n" |
7737 | "Return a bytes object containing random bytes suitable for cryptographic use." ); |
7738 | |
7739 | #define OS_URANDOM_METHODDEF \ |
7740 | {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__}, |
7741 | |
7742 | static PyObject * |
7743 | os_urandom_impl(PyObject *module, Py_ssize_t size); |
7744 | |
7745 | static PyObject * |
7746 | os_urandom(PyObject *module, PyObject *arg) |
7747 | { |
7748 | PyObject *return_value = NULL; |
7749 | Py_ssize_t size; |
7750 | |
7751 | { |
7752 | Py_ssize_t ival = -1; |
7753 | PyObject *iobj = _PyNumber_Index(arg); |
7754 | if (iobj != NULL) { |
7755 | ival = PyLong_AsSsize_t(iobj); |
7756 | Py_DECREF(iobj); |
7757 | } |
7758 | if (ival == -1 && PyErr_Occurred()) { |
7759 | goto exit; |
7760 | } |
7761 | size = ival; |
7762 | } |
7763 | return_value = os_urandom_impl(module, size); |
7764 | |
7765 | exit: |
7766 | return return_value; |
7767 | } |
7768 | |
7769 | #if defined(HAVE_MEMFD_CREATE) |
7770 | |
7771 | PyDoc_STRVAR(os_memfd_create__doc__, |
7772 | "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n" |
7773 | "--\n" |
7774 | "\n" ); |
7775 | |
7776 | #define OS_MEMFD_CREATE_METHODDEF \ |
7777 | {"memfd_create", (PyCFunction)(void(*)(void))os_memfd_create, METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__}, |
7778 | |
7779 | static PyObject * |
7780 | os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags); |
7781 | |
7782 | static PyObject * |
7783 | os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7784 | { |
7785 | PyObject *return_value = NULL; |
7786 | static const char * const _keywords[] = {"name" , "flags" , NULL}; |
7787 | static _PyArg_Parser _parser = {NULL, _keywords, "memfd_create" , 0}; |
7788 | PyObject *argsbuf[2]; |
7789 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
7790 | PyObject *name = NULL; |
7791 | unsigned int flags = MFD_CLOEXEC; |
7792 | |
7793 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
7794 | if (!args) { |
7795 | goto exit; |
7796 | } |
7797 | if (!PyUnicode_FSConverter(args[0], &name)) { |
7798 | goto exit; |
7799 | } |
7800 | if (!noptargs) { |
7801 | goto skip_optional_pos; |
7802 | } |
7803 | flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); |
7804 | if (flags == (unsigned int)-1 && PyErr_Occurred()) { |
7805 | goto exit; |
7806 | } |
7807 | skip_optional_pos: |
7808 | return_value = os_memfd_create_impl(module, name, flags); |
7809 | |
7810 | exit: |
7811 | /* Cleanup for name */ |
7812 | Py_XDECREF(name); |
7813 | |
7814 | return return_value; |
7815 | } |
7816 | |
7817 | #endif /* defined(HAVE_MEMFD_CREATE) */ |
7818 | |
7819 | #if defined(HAVE_EVENTFD) |
7820 | |
7821 | PyDoc_STRVAR(os_eventfd__doc__, |
7822 | "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n" |
7823 | "--\n" |
7824 | "\n" |
7825 | "Creates and returns an event notification file descriptor." ); |
7826 | |
7827 | #define OS_EVENTFD_METHODDEF \ |
7828 | {"eventfd", (PyCFunction)(void(*)(void))os_eventfd, METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__}, |
7829 | |
7830 | static PyObject * |
7831 | os_eventfd_impl(PyObject *module, unsigned int initval, int flags); |
7832 | |
7833 | static PyObject * |
7834 | os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7835 | { |
7836 | PyObject *return_value = NULL; |
7837 | static const char * const _keywords[] = {"initval" , "flags" , NULL}; |
7838 | static _PyArg_Parser _parser = {NULL, _keywords, "eventfd" , 0}; |
7839 | PyObject *argsbuf[2]; |
7840 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
7841 | unsigned int initval; |
7842 | int flags = EFD_CLOEXEC; |
7843 | |
7844 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
7845 | if (!args) { |
7846 | goto exit; |
7847 | } |
7848 | if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) { |
7849 | goto exit; |
7850 | } |
7851 | if (!noptargs) { |
7852 | goto skip_optional_pos; |
7853 | } |
7854 | flags = _PyLong_AsInt(args[1]); |
7855 | if (flags == -1 && PyErr_Occurred()) { |
7856 | goto exit; |
7857 | } |
7858 | skip_optional_pos: |
7859 | return_value = os_eventfd_impl(module, initval, flags); |
7860 | |
7861 | exit: |
7862 | return return_value; |
7863 | } |
7864 | |
7865 | #endif /* defined(HAVE_EVENTFD) */ |
7866 | |
7867 | #if defined(HAVE_EVENTFD) |
7868 | |
7869 | PyDoc_STRVAR(os_eventfd_read__doc__, |
7870 | "eventfd_read($module, /, fd)\n" |
7871 | "--\n" |
7872 | "\n" |
7873 | "Read eventfd value" ); |
7874 | |
7875 | #define OS_EVENTFD_READ_METHODDEF \ |
7876 | {"eventfd_read", (PyCFunction)(void(*)(void))os_eventfd_read, METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__}, |
7877 | |
7878 | static PyObject * |
7879 | os_eventfd_read_impl(PyObject *module, int fd); |
7880 | |
7881 | static PyObject * |
7882 | os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7883 | { |
7884 | PyObject *return_value = NULL; |
7885 | static const char * const _keywords[] = {"fd" , NULL}; |
7886 | static _PyArg_Parser _parser = {NULL, _keywords, "eventfd_read" , 0}; |
7887 | PyObject *argsbuf[1]; |
7888 | int fd; |
7889 | |
7890 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
7891 | if (!args) { |
7892 | goto exit; |
7893 | } |
7894 | if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
7895 | goto exit; |
7896 | } |
7897 | return_value = os_eventfd_read_impl(module, fd); |
7898 | |
7899 | exit: |
7900 | return return_value; |
7901 | } |
7902 | |
7903 | #endif /* defined(HAVE_EVENTFD) */ |
7904 | |
7905 | #if defined(HAVE_EVENTFD) |
7906 | |
7907 | PyDoc_STRVAR(os_eventfd_write__doc__, |
7908 | "eventfd_write($module, /, fd, value)\n" |
7909 | "--\n" |
7910 | "\n" |
7911 | "Write eventfd value." ); |
7912 | |
7913 | #define OS_EVENTFD_WRITE_METHODDEF \ |
7914 | {"eventfd_write", (PyCFunction)(void(*)(void))os_eventfd_write, METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__}, |
7915 | |
7916 | static PyObject * |
7917 | os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value); |
7918 | |
7919 | static PyObject * |
7920 | os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
7921 | { |
7922 | PyObject *return_value = NULL; |
7923 | static const char * const _keywords[] = {"fd" , "value" , NULL}; |
7924 | static _PyArg_Parser _parser = {NULL, _keywords, "eventfd_write" , 0}; |
7925 | PyObject *argsbuf[2]; |
7926 | int fd; |
7927 | unsigned long long value; |
7928 | |
7929 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
7930 | if (!args) { |
7931 | goto exit; |
7932 | } |
7933 | if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
7934 | goto exit; |
7935 | } |
7936 | if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) { |
7937 | goto exit; |
7938 | } |
7939 | return_value = os_eventfd_write_impl(module, fd, value); |
7940 | |
7941 | exit: |
7942 | return return_value; |
7943 | } |
7944 | |
7945 | #endif /* defined(HAVE_EVENTFD) */ |
7946 | |
7947 | #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) |
7948 | |
7949 | PyDoc_STRVAR(os_get_terminal_size__doc__, |
7950 | "get_terminal_size($module, fd=<unrepresentable>, /)\n" |
7951 | "--\n" |
7952 | "\n" |
7953 | "Return the size of the terminal window as (columns, lines).\n" |
7954 | "\n" |
7955 | "The optional argument fd (default standard output) specifies\n" |
7956 | "which file descriptor should be queried.\n" |
7957 | "\n" |
7958 | "If the file descriptor is not connected to a terminal, an OSError\n" |
7959 | "is thrown.\n" |
7960 | "\n" |
7961 | "This function will only be defined if an implementation is\n" |
7962 | "available for this system.\n" |
7963 | "\n" |
7964 | "shutil.get_terminal_size is the high-level function which should\n" |
7965 | "normally be used, os.get_terminal_size is the low-level implementation." ); |
7966 | |
7967 | #define OS_GET_TERMINAL_SIZE_METHODDEF \ |
7968 | {"get_terminal_size", (PyCFunction)(void(*)(void))os_get_terminal_size, METH_FASTCALL, os_get_terminal_size__doc__}, |
7969 | |
7970 | static PyObject * |
7971 | os_get_terminal_size_impl(PyObject *module, int fd); |
7972 | |
7973 | static PyObject * |
7974 | os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
7975 | { |
7976 | PyObject *return_value = NULL; |
7977 | int fd = fileno(stdout); |
7978 | |
7979 | if (!_PyArg_CheckPositional("get_terminal_size" , nargs, 0, 1)) { |
7980 | goto exit; |
7981 | } |
7982 | if (nargs < 1) { |
7983 | goto skip_optional; |
7984 | } |
7985 | fd = _PyLong_AsInt(args[0]); |
7986 | if (fd == -1 && PyErr_Occurred()) { |
7987 | goto exit; |
7988 | } |
7989 | skip_optional: |
7990 | return_value = os_get_terminal_size_impl(module, fd); |
7991 | |
7992 | exit: |
7993 | return return_value; |
7994 | } |
7995 | |
7996 | #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */ |
7997 | |
7998 | PyDoc_STRVAR(os_cpu_count__doc__, |
7999 | "cpu_count($module, /)\n" |
8000 | "--\n" |
8001 | "\n" |
8002 | "Return the number of CPUs in the system; return None if indeterminable.\n" |
8003 | "\n" |
8004 | "This number is not equivalent to the number of CPUs the current process can\n" |
8005 | "use. The number of usable CPUs can be obtained with\n" |
8006 | "``len(os.sched_getaffinity(0))``" ); |
8007 | |
8008 | #define OS_CPU_COUNT_METHODDEF \ |
8009 | {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, |
8010 | |
8011 | static PyObject * |
8012 | os_cpu_count_impl(PyObject *module); |
8013 | |
8014 | static PyObject * |
8015 | os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
8016 | { |
8017 | return os_cpu_count_impl(module); |
8018 | } |
8019 | |
8020 | PyDoc_STRVAR(os_get_inheritable__doc__, |
8021 | "get_inheritable($module, fd, /)\n" |
8022 | "--\n" |
8023 | "\n" |
8024 | "Get the close-on-exe flag of the specified file descriptor." ); |
8025 | |
8026 | #define OS_GET_INHERITABLE_METHODDEF \ |
8027 | {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__}, |
8028 | |
8029 | static int |
8030 | os_get_inheritable_impl(PyObject *module, int fd); |
8031 | |
8032 | static PyObject * |
8033 | os_get_inheritable(PyObject *module, PyObject *arg) |
8034 | { |
8035 | PyObject *return_value = NULL; |
8036 | int fd; |
8037 | int _return_value; |
8038 | |
8039 | fd = _PyLong_AsInt(arg); |
8040 | if (fd == -1 && PyErr_Occurred()) { |
8041 | goto exit; |
8042 | } |
8043 | _return_value = os_get_inheritable_impl(module, fd); |
8044 | if ((_return_value == -1) && PyErr_Occurred()) { |
8045 | goto exit; |
8046 | } |
8047 | return_value = PyBool_FromLong((long)_return_value); |
8048 | |
8049 | exit: |
8050 | return return_value; |
8051 | } |
8052 | |
8053 | PyDoc_STRVAR(os_set_inheritable__doc__, |
8054 | "set_inheritable($module, fd, inheritable, /)\n" |
8055 | "--\n" |
8056 | "\n" |
8057 | "Set the inheritable flag of the specified file descriptor." ); |
8058 | |
8059 | #define OS_SET_INHERITABLE_METHODDEF \ |
8060 | {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__}, |
8061 | |
8062 | static PyObject * |
8063 | os_set_inheritable_impl(PyObject *module, int fd, int inheritable); |
8064 | |
8065 | static PyObject * |
8066 | os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8067 | { |
8068 | PyObject *return_value = NULL; |
8069 | int fd; |
8070 | int inheritable; |
8071 | |
8072 | if (!_PyArg_CheckPositional("set_inheritable" , nargs, 2, 2)) { |
8073 | goto exit; |
8074 | } |
8075 | fd = _PyLong_AsInt(args[0]); |
8076 | if (fd == -1 && PyErr_Occurred()) { |
8077 | goto exit; |
8078 | } |
8079 | inheritable = _PyLong_AsInt(args[1]); |
8080 | if (inheritable == -1 && PyErr_Occurred()) { |
8081 | goto exit; |
8082 | } |
8083 | return_value = os_set_inheritable_impl(module, fd, inheritable); |
8084 | |
8085 | exit: |
8086 | return return_value; |
8087 | } |
8088 | |
8089 | #if defined(MS_WINDOWS) |
8090 | |
8091 | PyDoc_STRVAR(os_get_handle_inheritable__doc__, |
8092 | "get_handle_inheritable($module, handle, /)\n" |
8093 | "--\n" |
8094 | "\n" |
8095 | "Get the close-on-exe flag of the specified file descriptor." ); |
8096 | |
8097 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF \ |
8098 | {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__}, |
8099 | |
8100 | static int |
8101 | os_get_handle_inheritable_impl(PyObject *module, intptr_t handle); |
8102 | |
8103 | static PyObject * |
8104 | os_get_handle_inheritable(PyObject *module, PyObject *arg) |
8105 | { |
8106 | PyObject *return_value = NULL; |
8107 | intptr_t handle; |
8108 | int _return_value; |
8109 | |
8110 | if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable" , &handle)) { |
8111 | goto exit; |
8112 | } |
8113 | _return_value = os_get_handle_inheritable_impl(module, handle); |
8114 | if ((_return_value == -1) && PyErr_Occurred()) { |
8115 | goto exit; |
8116 | } |
8117 | return_value = PyBool_FromLong((long)_return_value); |
8118 | |
8119 | exit: |
8120 | return return_value; |
8121 | } |
8122 | |
8123 | #endif /* defined(MS_WINDOWS) */ |
8124 | |
8125 | #if defined(MS_WINDOWS) |
8126 | |
8127 | PyDoc_STRVAR(os_set_handle_inheritable__doc__, |
8128 | "set_handle_inheritable($module, handle, inheritable, /)\n" |
8129 | "--\n" |
8130 | "\n" |
8131 | "Set the inheritable flag of the specified handle." ); |
8132 | |
8133 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF \ |
8134 | {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__}, |
8135 | |
8136 | static PyObject * |
8137 | os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, |
8138 | int inheritable); |
8139 | |
8140 | static PyObject * |
8141 | os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8142 | { |
8143 | PyObject *return_value = NULL; |
8144 | intptr_t handle; |
8145 | int inheritable; |
8146 | |
8147 | if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable" , |
8148 | &handle, &inheritable)) { |
8149 | goto exit; |
8150 | } |
8151 | return_value = os_set_handle_inheritable_impl(module, handle, inheritable); |
8152 | |
8153 | exit: |
8154 | return return_value; |
8155 | } |
8156 | |
8157 | #endif /* defined(MS_WINDOWS) */ |
8158 | |
8159 | #if !defined(MS_WINDOWS) |
8160 | |
8161 | PyDoc_STRVAR(os_get_blocking__doc__, |
8162 | "get_blocking($module, fd, /)\n" |
8163 | "--\n" |
8164 | "\n" |
8165 | "Get the blocking mode of the file descriptor.\n" |
8166 | "\n" |
8167 | "Return False if the O_NONBLOCK flag is set, True if the flag is cleared." ); |
8168 | |
8169 | #define OS_GET_BLOCKING_METHODDEF \ |
8170 | {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__}, |
8171 | |
8172 | static int |
8173 | os_get_blocking_impl(PyObject *module, int fd); |
8174 | |
8175 | static PyObject * |
8176 | os_get_blocking(PyObject *module, PyObject *arg) |
8177 | { |
8178 | PyObject *return_value = NULL; |
8179 | int fd; |
8180 | int _return_value; |
8181 | |
8182 | fd = _PyLong_AsInt(arg); |
8183 | if (fd == -1 && PyErr_Occurred()) { |
8184 | goto exit; |
8185 | } |
8186 | _return_value = os_get_blocking_impl(module, fd); |
8187 | if ((_return_value == -1) && PyErr_Occurred()) { |
8188 | goto exit; |
8189 | } |
8190 | return_value = PyBool_FromLong((long)_return_value); |
8191 | |
8192 | exit: |
8193 | return return_value; |
8194 | } |
8195 | |
8196 | #endif /* !defined(MS_WINDOWS) */ |
8197 | |
8198 | #if !defined(MS_WINDOWS) |
8199 | |
8200 | PyDoc_STRVAR(os_set_blocking__doc__, |
8201 | "set_blocking($module, fd, blocking, /)\n" |
8202 | "--\n" |
8203 | "\n" |
8204 | "Set the blocking mode of the specified file descriptor.\n" |
8205 | "\n" |
8206 | "Set the O_NONBLOCK flag if blocking is False,\n" |
8207 | "clear the O_NONBLOCK flag otherwise." ); |
8208 | |
8209 | #define OS_SET_BLOCKING_METHODDEF \ |
8210 | {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__}, |
8211 | |
8212 | static PyObject * |
8213 | os_set_blocking_impl(PyObject *module, int fd, int blocking); |
8214 | |
8215 | static PyObject * |
8216 | os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
8217 | { |
8218 | PyObject *return_value = NULL; |
8219 | int fd; |
8220 | int blocking; |
8221 | |
8222 | if (!_PyArg_CheckPositional("set_blocking" , nargs, 2, 2)) { |
8223 | goto exit; |
8224 | } |
8225 | fd = _PyLong_AsInt(args[0]); |
8226 | if (fd == -1 && PyErr_Occurred()) { |
8227 | goto exit; |
8228 | } |
8229 | blocking = _PyLong_AsInt(args[1]); |
8230 | if (blocking == -1 && PyErr_Occurred()) { |
8231 | goto exit; |
8232 | } |
8233 | return_value = os_set_blocking_impl(module, fd, blocking); |
8234 | |
8235 | exit: |
8236 | return return_value; |
8237 | } |
8238 | |
8239 | #endif /* !defined(MS_WINDOWS) */ |
8240 | |
8241 | PyDoc_STRVAR(os_DirEntry_is_symlink__doc__, |
8242 | "is_symlink($self, /)\n" |
8243 | "--\n" |
8244 | "\n" |
8245 | "Return True if the entry is a symbolic link; cached per entry." ); |
8246 | |
8247 | #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \ |
8248 | {"is_symlink", (PyCFunction)(void(*)(void))os_DirEntry_is_symlink, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__}, |
8249 | |
8250 | static int |
8251 | os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class); |
8252 | |
8253 | static PyObject * |
8254 | os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8255 | { |
8256 | PyObject *return_value = NULL; |
8257 | int _return_value; |
8258 | |
8259 | if (nargs) { |
8260 | PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments" ); |
8261 | goto exit; |
8262 | } |
8263 | _return_value = os_DirEntry_is_symlink_impl(self, defining_class); |
8264 | if ((_return_value == -1) && PyErr_Occurred()) { |
8265 | goto exit; |
8266 | } |
8267 | return_value = PyBool_FromLong((long)_return_value); |
8268 | |
8269 | exit: |
8270 | return return_value; |
8271 | } |
8272 | |
8273 | PyDoc_STRVAR(os_DirEntry_stat__doc__, |
8274 | "stat($self, /, *, follow_symlinks=True)\n" |
8275 | "--\n" |
8276 | "\n" |
8277 | "Return stat_result object for the entry; cached per entry." ); |
8278 | |
8279 | #define OS_DIRENTRY_STAT_METHODDEF \ |
8280 | {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__}, |
8281 | |
8282 | static PyObject * |
8283 | os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class, |
8284 | int follow_symlinks); |
8285 | |
8286 | static PyObject * |
8287 | os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8288 | { |
8289 | PyObject *return_value = NULL; |
8290 | static const char * const _keywords[] = {"follow_symlinks" , NULL}; |
8291 | static _PyArg_Parser _parser = {NULL, _keywords, "stat" , 0}; |
8292 | PyObject *argsbuf[1]; |
8293 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
8294 | int follow_symlinks = 1; |
8295 | |
8296 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
8297 | if (!args) { |
8298 | goto exit; |
8299 | } |
8300 | if (!noptargs) { |
8301 | goto skip_optional_kwonly; |
8302 | } |
8303 | follow_symlinks = PyObject_IsTrue(args[0]); |
8304 | if (follow_symlinks < 0) { |
8305 | goto exit; |
8306 | } |
8307 | skip_optional_kwonly: |
8308 | return_value = os_DirEntry_stat_impl(self, defining_class, follow_symlinks); |
8309 | |
8310 | exit: |
8311 | return return_value; |
8312 | } |
8313 | |
8314 | PyDoc_STRVAR(os_DirEntry_is_dir__doc__, |
8315 | "is_dir($self, /, *, follow_symlinks=True)\n" |
8316 | "--\n" |
8317 | "\n" |
8318 | "Return True if the entry is a directory; cached per entry." ); |
8319 | |
8320 | #define OS_DIRENTRY_IS_DIR_METHODDEF \ |
8321 | {"is_dir", (PyCFunction)(void(*)(void))os_DirEntry_is_dir, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__}, |
8322 | |
8323 | static int |
8324 | os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class, |
8325 | int follow_symlinks); |
8326 | |
8327 | static PyObject * |
8328 | os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8329 | { |
8330 | PyObject *return_value = NULL; |
8331 | static const char * const _keywords[] = {"follow_symlinks" , NULL}; |
8332 | static _PyArg_Parser _parser = {NULL, _keywords, "is_dir" , 0}; |
8333 | PyObject *argsbuf[1]; |
8334 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
8335 | int follow_symlinks = 1; |
8336 | int _return_value; |
8337 | |
8338 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
8339 | if (!args) { |
8340 | goto exit; |
8341 | } |
8342 | if (!noptargs) { |
8343 | goto skip_optional_kwonly; |
8344 | } |
8345 | follow_symlinks = PyObject_IsTrue(args[0]); |
8346 | if (follow_symlinks < 0) { |
8347 | goto exit; |
8348 | } |
8349 | skip_optional_kwonly: |
8350 | _return_value = os_DirEntry_is_dir_impl(self, defining_class, follow_symlinks); |
8351 | if ((_return_value == -1) && PyErr_Occurred()) { |
8352 | goto exit; |
8353 | } |
8354 | return_value = PyBool_FromLong((long)_return_value); |
8355 | |
8356 | exit: |
8357 | return return_value; |
8358 | } |
8359 | |
8360 | PyDoc_STRVAR(os_DirEntry_is_file__doc__, |
8361 | "is_file($self, /, *, follow_symlinks=True)\n" |
8362 | "--\n" |
8363 | "\n" |
8364 | "Return True if the entry is a file; cached per entry." ); |
8365 | |
8366 | #define OS_DIRENTRY_IS_FILE_METHODDEF \ |
8367 | {"is_file", (PyCFunction)(void(*)(void))os_DirEntry_is_file, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__}, |
8368 | |
8369 | static int |
8370 | os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class, |
8371 | int follow_symlinks); |
8372 | |
8373 | static PyObject * |
8374 | os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8375 | { |
8376 | PyObject *return_value = NULL; |
8377 | static const char * const _keywords[] = {"follow_symlinks" , NULL}; |
8378 | static _PyArg_Parser _parser = {NULL, _keywords, "is_file" , 0}; |
8379 | PyObject *argsbuf[1]; |
8380 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
8381 | int follow_symlinks = 1; |
8382 | int _return_value; |
8383 | |
8384 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
8385 | if (!args) { |
8386 | goto exit; |
8387 | } |
8388 | if (!noptargs) { |
8389 | goto skip_optional_kwonly; |
8390 | } |
8391 | follow_symlinks = PyObject_IsTrue(args[0]); |
8392 | if (follow_symlinks < 0) { |
8393 | goto exit; |
8394 | } |
8395 | skip_optional_kwonly: |
8396 | _return_value = os_DirEntry_is_file_impl(self, defining_class, follow_symlinks); |
8397 | if ((_return_value == -1) && PyErr_Occurred()) { |
8398 | goto exit; |
8399 | } |
8400 | return_value = PyBool_FromLong((long)_return_value); |
8401 | |
8402 | exit: |
8403 | return return_value; |
8404 | } |
8405 | |
8406 | PyDoc_STRVAR(os_DirEntry_inode__doc__, |
8407 | "inode($self, /)\n" |
8408 | "--\n" |
8409 | "\n" |
8410 | "Return inode of the entry; cached per entry." ); |
8411 | |
8412 | #define OS_DIRENTRY_INODE_METHODDEF \ |
8413 | {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__}, |
8414 | |
8415 | static PyObject * |
8416 | os_DirEntry_inode_impl(DirEntry *self); |
8417 | |
8418 | static PyObject * |
8419 | os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
8420 | { |
8421 | return os_DirEntry_inode_impl(self); |
8422 | } |
8423 | |
8424 | PyDoc_STRVAR(os_DirEntry___fspath____doc__, |
8425 | "__fspath__($self, /)\n" |
8426 | "--\n" |
8427 | "\n" |
8428 | "Returns the path for the entry." ); |
8429 | |
8430 | #define OS_DIRENTRY___FSPATH___METHODDEF \ |
8431 | {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__}, |
8432 | |
8433 | static PyObject * |
8434 | os_DirEntry___fspath___impl(DirEntry *self); |
8435 | |
8436 | static PyObject * |
8437 | os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored)) |
8438 | { |
8439 | return os_DirEntry___fspath___impl(self); |
8440 | } |
8441 | |
8442 | PyDoc_STRVAR(os_scandir__doc__, |
8443 | "scandir($module, /, path=None)\n" |
8444 | "--\n" |
8445 | "\n" |
8446 | "Return an iterator of DirEntry objects for given path.\n" |
8447 | "\n" |
8448 | "path can be specified as either str, bytes, or a path-like object. If path\n" |
8449 | "is bytes, the names of yielded DirEntry objects will also be bytes; in\n" |
8450 | "all other circumstances they will be str.\n" |
8451 | "\n" |
8452 | "If path is None, uses the path=\'.\'." ); |
8453 | |
8454 | #define OS_SCANDIR_METHODDEF \ |
8455 | {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__}, |
8456 | |
8457 | static PyObject * |
8458 | os_scandir_impl(PyObject *module, path_t *path); |
8459 | |
8460 | static PyObject * |
8461 | os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8462 | { |
8463 | PyObject *return_value = NULL; |
8464 | static const char * const _keywords[] = {"path" , NULL}; |
8465 | static _PyArg_Parser _parser = {NULL, _keywords, "scandir" , 0}; |
8466 | PyObject *argsbuf[1]; |
8467 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
8468 | path_t path = PATH_T_INITIALIZE("scandir" , "path" , 1, PATH_HAVE_FDOPENDIR); |
8469 | |
8470 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
8471 | if (!args) { |
8472 | goto exit; |
8473 | } |
8474 | if (!noptargs) { |
8475 | goto skip_optional_pos; |
8476 | } |
8477 | if (!path_converter(args[0], &path)) { |
8478 | goto exit; |
8479 | } |
8480 | skip_optional_pos: |
8481 | return_value = os_scandir_impl(module, &path); |
8482 | |
8483 | exit: |
8484 | /* Cleanup for path */ |
8485 | path_cleanup(&path); |
8486 | |
8487 | return return_value; |
8488 | } |
8489 | |
8490 | PyDoc_STRVAR(os_fspath__doc__, |
8491 | "fspath($module, /, path)\n" |
8492 | "--\n" |
8493 | "\n" |
8494 | "Return the file system path representation of the object.\n" |
8495 | "\n" |
8496 | "If the object is str or bytes, then allow it to pass through as-is. If the\n" |
8497 | "object defines __fspath__(), then return the result of that method. All other\n" |
8498 | "types raise a TypeError." ); |
8499 | |
8500 | #define OS_FSPATH_METHODDEF \ |
8501 | {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__}, |
8502 | |
8503 | static PyObject * |
8504 | os_fspath_impl(PyObject *module, PyObject *path); |
8505 | |
8506 | static PyObject * |
8507 | os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8508 | { |
8509 | PyObject *return_value = NULL; |
8510 | static const char * const _keywords[] = {"path" , NULL}; |
8511 | static _PyArg_Parser _parser = {NULL, _keywords, "fspath" , 0}; |
8512 | PyObject *argsbuf[1]; |
8513 | PyObject *path; |
8514 | |
8515 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
8516 | if (!args) { |
8517 | goto exit; |
8518 | } |
8519 | path = args[0]; |
8520 | return_value = os_fspath_impl(module, path); |
8521 | |
8522 | exit: |
8523 | return return_value; |
8524 | } |
8525 | |
8526 | #if defined(HAVE_GETRANDOM_SYSCALL) |
8527 | |
8528 | PyDoc_STRVAR(os_getrandom__doc__, |
8529 | "getrandom($module, /, size, flags=0)\n" |
8530 | "--\n" |
8531 | "\n" |
8532 | "Obtain a series of random bytes." ); |
8533 | |
8534 | #define OS_GETRANDOM_METHODDEF \ |
8535 | {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__}, |
8536 | |
8537 | static PyObject * |
8538 | os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags); |
8539 | |
8540 | static PyObject * |
8541 | os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8542 | { |
8543 | PyObject *return_value = NULL; |
8544 | static const char * const _keywords[] = {"size" , "flags" , NULL}; |
8545 | static _PyArg_Parser _parser = {NULL, _keywords, "getrandom" , 0}; |
8546 | PyObject *argsbuf[2]; |
8547 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
8548 | Py_ssize_t size; |
8549 | int flags = 0; |
8550 | |
8551 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
8552 | if (!args) { |
8553 | goto exit; |
8554 | } |
8555 | { |
8556 | Py_ssize_t ival = -1; |
8557 | PyObject *iobj = _PyNumber_Index(args[0]); |
8558 | if (iobj != NULL) { |
8559 | ival = PyLong_AsSsize_t(iobj); |
8560 | Py_DECREF(iobj); |
8561 | } |
8562 | if (ival == -1 && PyErr_Occurred()) { |
8563 | goto exit; |
8564 | } |
8565 | size = ival; |
8566 | } |
8567 | if (!noptargs) { |
8568 | goto skip_optional_pos; |
8569 | } |
8570 | flags = _PyLong_AsInt(args[1]); |
8571 | if (flags == -1 && PyErr_Occurred()) { |
8572 | goto exit; |
8573 | } |
8574 | skip_optional_pos: |
8575 | return_value = os_getrandom_impl(module, size, flags); |
8576 | |
8577 | exit: |
8578 | return return_value; |
8579 | } |
8580 | |
8581 | #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ |
8582 | |
8583 | #if defined(MS_WINDOWS) |
8584 | |
8585 | PyDoc_STRVAR(os__add_dll_directory__doc__, |
8586 | "_add_dll_directory($module, /, path)\n" |
8587 | "--\n" |
8588 | "\n" |
8589 | "Add a path to the DLL search path.\n" |
8590 | "\n" |
8591 | "This search path is used when resolving dependencies for imported\n" |
8592 | "extension modules (the module itself is resolved through sys.path),\n" |
8593 | "and also by ctypes.\n" |
8594 | "\n" |
8595 | "Returns an opaque value that may be passed to os.remove_dll_directory\n" |
8596 | "to remove this directory from the search path." ); |
8597 | |
8598 | #define OS__ADD_DLL_DIRECTORY_METHODDEF \ |
8599 | {"_add_dll_directory", (PyCFunction)(void(*)(void))os__add_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__}, |
8600 | |
8601 | static PyObject * |
8602 | os__add_dll_directory_impl(PyObject *module, path_t *path); |
8603 | |
8604 | static PyObject * |
8605 | os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8606 | { |
8607 | PyObject *return_value = NULL; |
8608 | static const char * const _keywords[] = {"path" , NULL}; |
8609 | static _PyArg_Parser _parser = {NULL, _keywords, "_add_dll_directory" , 0}; |
8610 | PyObject *argsbuf[1]; |
8611 | path_t path = PATH_T_INITIALIZE("_add_dll_directory" , "path" , 0, 0); |
8612 | |
8613 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
8614 | if (!args) { |
8615 | goto exit; |
8616 | } |
8617 | if (!path_converter(args[0], &path)) { |
8618 | goto exit; |
8619 | } |
8620 | return_value = os__add_dll_directory_impl(module, &path); |
8621 | |
8622 | exit: |
8623 | /* Cleanup for path */ |
8624 | path_cleanup(&path); |
8625 | |
8626 | return return_value; |
8627 | } |
8628 | |
8629 | #endif /* defined(MS_WINDOWS) */ |
8630 | |
8631 | #if defined(MS_WINDOWS) |
8632 | |
8633 | PyDoc_STRVAR(os__remove_dll_directory__doc__, |
8634 | "_remove_dll_directory($module, /, cookie)\n" |
8635 | "--\n" |
8636 | "\n" |
8637 | "Removes a path from the DLL search path.\n" |
8638 | "\n" |
8639 | "The parameter is an opaque value that was returned from\n" |
8640 | "os.add_dll_directory. You can only remove directories that you added\n" |
8641 | "yourself." ); |
8642 | |
8643 | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \ |
8644 | {"_remove_dll_directory", (PyCFunction)(void(*)(void))os__remove_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__}, |
8645 | |
8646 | static PyObject * |
8647 | os__remove_dll_directory_impl(PyObject *module, PyObject *cookie); |
8648 | |
8649 | static PyObject * |
8650 | os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8651 | { |
8652 | PyObject *return_value = NULL; |
8653 | static const char * const _keywords[] = {"cookie" , NULL}; |
8654 | static _PyArg_Parser _parser = {NULL, _keywords, "_remove_dll_directory" , 0}; |
8655 | PyObject *argsbuf[1]; |
8656 | PyObject *cookie; |
8657 | |
8658 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
8659 | if (!args) { |
8660 | goto exit; |
8661 | } |
8662 | cookie = args[0]; |
8663 | return_value = os__remove_dll_directory_impl(module, cookie); |
8664 | |
8665 | exit: |
8666 | return return_value; |
8667 | } |
8668 | |
8669 | #endif /* defined(MS_WINDOWS) */ |
8670 | |
8671 | #if (defined(WIFEXITED) || defined(MS_WINDOWS)) |
8672 | |
8673 | PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__, |
8674 | "waitstatus_to_exitcode($module, /, status)\n" |
8675 | "--\n" |
8676 | "\n" |
8677 | "Convert a wait status to an exit code.\n" |
8678 | "\n" |
8679 | "On Unix:\n" |
8680 | "\n" |
8681 | "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n" |
8682 | "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n" |
8683 | "* Otherwise, raise a ValueError.\n" |
8684 | "\n" |
8685 | "On Windows, return status shifted right by 8 bits.\n" |
8686 | "\n" |
8687 | "On Unix, if the process is being traced or if waitpid() was called with\n" |
8688 | "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n" |
8689 | "This function must not be called if WIFSTOPPED(status) is true." ); |
8690 | |
8691 | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \ |
8692 | {"waitstatus_to_exitcode", (PyCFunction)(void(*)(void))os_waitstatus_to_exitcode, METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__}, |
8693 | |
8694 | static PyObject * |
8695 | os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj); |
8696 | |
8697 | static PyObject * |
8698 | os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
8699 | { |
8700 | PyObject *return_value = NULL; |
8701 | static const char * const _keywords[] = {"status" , NULL}; |
8702 | static _PyArg_Parser _parser = {NULL, _keywords, "waitstatus_to_exitcode" , 0}; |
8703 | PyObject *argsbuf[1]; |
8704 | PyObject *status_obj; |
8705 | |
8706 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
8707 | if (!args) { |
8708 | goto exit; |
8709 | } |
8710 | status_obj = args[0]; |
8711 | return_value = os_waitstatus_to_exitcode_impl(module, status_obj); |
8712 | |
8713 | exit: |
8714 | return return_value; |
8715 | } |
8716 | |
8717 | #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */ |
8718 | |
8719 | #ifndef OS_TTYNAME_METHODDEF |
8720 | #define OS_TTYNAME_METHODDEF |
8721 | #endif /* !defined(OS_TTYNAME_METHODDEF) */ |
8722 | |
8723 | #ifndef OS_CTERMID_METHODDEF |
8724 | #define OS_CTERMID_METHODDEF |
8725 | #endif /* !defined(OS_CTERMID_METHODDEF) */ |
8726 | |
8727 | #ifndef OS_FCHDIR_METHODDEF |
8728 | #define OS_FCHDIR_METHODDEF |
8729 | #endif /* !defined(OS_FCHDIR_METHODDEF) */ |
8730 | |
8731 | #ifndef OS_FCHMOD_METHODDEF |
8732 | #define OS_FCHMOD_METHODDEF |
8733 | #endif /* !defined(OS_FCHMOD_METHODDEF) */ |
8734 | |
8735 | #ifndef OS_LCHMOD_METHODDEF |
8736 | #define OS_LCHMOD_METHODDEF |
8737 | #endif /* !defined(OS_LCHMOD_METHODDEF) */ |
8738 | |
8739 | #ifndef OS_CHFLAGS_METHODDEF |
8740 | #define OS_CHFLAGS_METHODDEF |
8741 | #endif /* !defined(OS_CHFLAGS_METHODDEF) */ |
8742 | |
8743 | #ifndef OS_LCHFLAGS_METHODDEF |
8744 | #define OS_LCHFLAGS_METHODDEF |
8745 | #endif /* !defined(OS_LCHFLAGS_METHODDEF) */ |
8746 | |
8747 | #ifndef OS_CHROOT_METHODDEF |
8748 | #define OS_CHROOT_METHODDEF |
8749 | #endif /* !defined(OS_CHROOT_METHODDEF) */ |
8750 | |
8751 | #ifndef OS_FSYNC_METHODDEF |
8752 | #define OS_FSYNC_METHODDEF |
8753 | #endif /* !defined(OS_FSYNC_METHODDEF) */ |
8754 | |
8755 | #ifndef OS_SYNC_METHODDEF |
8756 | #define OS_SYNC_METHODDEF |
8757 | #endif /* !defined(OS_SYNC_METHODDEF) */ |
8758 | |
8759 | #ifndef OS_FDATASYNC_METHODDEF |
8760 | #define OS_FDATASYNC_METHODDEF |
8761 | #endif /* !defined(OS_FDATASYNC_METHODDEF) */ |
8762 | |
8763 | #ifndef OS_CHOWN_METHODDEF |
8764 | #define OS_CHOWN_METHODDEF |
8765 | #endif /* !defined(OS_CHOWN_METHODDEF) */ |
8766 | |
8767 | #ifndef OS_FCHOWN_METHODDEF |
8768 | #define OS_FCHOWN_METHODDEF |
8769 | #endif /* !defined(OS_FCHOWN_METHODDEF) */ |
8770 | |
8771 | #ifndef OS_LCHOWN_METHODDEF |
8772 | #define OS_LCHOWN_METHODDEF |
8773 | #endif /* !defined(OS_LCHOWN_METHODDEF) */ |
8774 | |
8775 | #ifndef OS_LINK_METHODDEF |
8776 | #define OS_LINK_METHODDEF |
8777 | #endif /* !defined(OS_LINK_METHODDEF) */ |
8778 | |
8779 | #ifndef OS__GETFULLPATHNAME_METHODDEF |
8780 | #define OS__GETFULLPATHNAME_METHODDEF |
8781 | #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */ |
8782 | |
8783 | #ifndef OS__GETFINALPATHNAME_METHODDEF |
8784 | #define OS__GETFINALPATHNAME_METHODDEF |
8785 | #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ |
8786 | |
8787 | #ifndef OS__GETVOLUMEPATHNAME_METHODDEF |
8788 | #define OS__GETVOLUMEPATHNAME_METHODDEF |
8789 | #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ |
8790 | |
8791 | #ifndef OS__PATH_SPLITROOT_METHODDEF |
8792 | #define OS__PATH_SPLITROOT_METHODDEF |
8793 | #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */ |
8794 | |
8795 | #ifndef OS_NICE_METHODDEF |
8796 | #define OS_NICE_METHODDEF |
8797 | #endif /* !defined(OS_NICE_METHODDEF) */ |
8798 | |
8799 | #ifndef OS_GETPRIORITY_METHODDEF |
8800 | #define OS_GETPRIORITY_METHODDEF |
8801 | #endif /* !defined(OS_GETPRIORITY_METHODDEF) */ |
8802 | |
8803 | #ifndef OS_SETPRIORITY_METHODDEF |
8804 | #define OS_SETPRIORITY_METHODDEF |
8805 | #endif /* !defined(OS_SETPRIORITY_METHODDEF) */ |
8806 | |
8807 | #ifndef OS_SYSTEM_METHODDEF |
8808 | #define OS_SYSTEM_METHODDEF |
8809 | #endif /* !defined(OS_SYSTEM_METHODDEF) */ |
8810 | |
8811 | #ifndef OS_UNAME_METHODDEF |
8812 | #define OS_UNAME_METHODDEF |
8813 | #endif /* !defined(OS_UNAME_METHODDEF) */ |
8814 | |
8815 | #ifndef OS_EXECV_METHODDEF |
8816 | #define OS_EXECV_METHODDEF |
8817 | #endif /* !defined(OS_EXECV_METHODDEF) */ |
8818 | |
8819 | #ifndef OS_EXECVE_METHODDEF |
8820 | #define OS_EXECVE_METHODDEF |
8821 | #endif /* !defined(OS_EXECVE_METHODDEF) */ |
8822 | |
8823 | #ifndef OS_POSIX_SPAWN_METHODDEF |
8824 | #define OS_POSIX_SPAWN_METHODDEF |
8825 | #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */ |
8826 | |
8827 | #ifndef OS_POSIX_SPAWNP_METHODDEF |
8828 | #define OS_POSIX_SPAWNP_METHODDEF |
8829 | #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */ |
8830 | |
8831 | #ifndef OS_SPAWNV_METHODDEF |
8832 | #define OS_SPAWNV_METHODDEF |
8833 | #endif /* !defined(OS_SPAWNV_METHODDEF) */ |
8834 | |
8835 | #ifndef OS_SPAWNVE_METHODDEF |
8836 | #define OS_SPAWNVE_METHODDEF |
8837 | #endif /* !defined(OS_SPAWNVE_METHODDEF) */ |
8838 | |
8839 | #ifndef OS_REGISTER_AT_FORK_METHODDEF |
8840 | #define OS_REGISTER_AT_FORK_METHODDEF |
8841 | #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */ |
8842 | |
8843 | #ifndef OS_FORK1_METHODDEF |
8844 | #define OS_FORK1_METHODDEF |
8845 | #endif /* !defined(OS_FORK1_METHODDEF) */ |
8846 | |
8847 | #ifndef OS_FORK_METHODDEF |
8848 | #define OS_FORK_METHODDEF |
8849 | #endif /* !defined(OS_FORK_METHODDEF) */ |
8850 | |
8851 | #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
8852 | #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF |
8853 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ |
8854 | |
8855 | #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
8856 | #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF |
8857 | #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ |
8858 | |
8859 | #ifndef OS_SCHED_GETSCHEDULER_METHODDEF |
8860 | #define OS_SCHED_GETSCHEDULER_METHODDEF |
8861 | #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ |
8862 | |
8863 | #ifndef OS_SCHED_SETSCHEDULER_METHODDEF |
8864 | #define OS_SCHED_SETSCHEDULER_METHODDEF |
8865 | #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ |
8866 | |
8867 | #ifndef OS_SCHED_GETPARAM_METHODDEF |
8868 | #define OS_SCHED_GETPARAM_METHODDEF |
8869 | #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ |
8870 | |
8871 | #ifndef OS_SCHED_SETPARAM_METHODDEF |
8872 | #define OS_SCHED_SETPARAM_METHODDEF |
8873 | #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ |
8874 | |
8875 | #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF |
8876 | #define OS_SCHED_RR_GET_INTERVAL_METHODDEF |
8877 | #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ |
8878 | |
8879 | #ifndef OS_SCHED_YIELD_METHODDEF |
8880 | #define OS_SCHED_YIELD_METHODDEF |
8881 | #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ |
8882 | |
8883 | #ifndef OS_SCHED_SETAFFINITY_METHODDEF |
8884 | #define OS_SCHED_SETAFFINITY_METHODDEF |
8885 | #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ |
8886 | |
8887 | #ifndef OS_SCHED_GETAFFINITY_METHODDEF |
8888 | #define OS_SCHED_GETAFFINITY_METHODDEF |
8889 | #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ |
8890 | |
8891 | #ifndef OS_OPENPTY_METHODDEF |
8892 | #define OS_OPENPTY_METHODDEF |
8893 | #endif /* !defined(OS_OPENPTY_METHODDEF) */ |
8894 | |
8895 | #ifndef OS_FORKPTY_METHODDEF |
8896 | #define OS_FORKPTY_METHODDEF |
8897 | #endif /* !defined(OS_FORKPTY_METHODDEF) */ |
8898 | |
8899 | #ifndef OS_GETEGID_METHODDEF |
8900 | #define OS_GETEGID_METHODDEF |
8901 | #endif /* !defined(OS_GETEGID_METHODDEF) */ |
8902 | |
8903 | #ifndef OS_GETEUID_METHODDEF |
8904 | #define OS_GETEUID_METHODDEF |
8905 | #endif /* !defined(OS_GETEUID_METHODDEF) */ |
8906 | |
8907 | #ifndef OS_GETGID_METHODDEF |
8908 | #define OS_GETGID_METHODDEF |
8909 | #endif /* !defined(OS_GETGID_METHODDEF) */ |
8910 | |
8911 | #ifndef OS_GETPID_METHODDEF |
8912 | #define OS_GETPID_METHODDEF |
8913 | #endif /* !defined(OS_GETPID_METHODDEF) */ |
8914 | |
8915 | #ifndef OS_GETGROUPLIST_METHODDEF |
8916 | #define OS_GETGROUPLIST_METHODDEF |
8917 | #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */ |
8918 | |
8919 | #ifndef OS_GETGROUPS_METHODDEF |
8920 | #define OS_GETGROUPS_METHODDEF |
8921 | #endif /* !defined(OS_GETGROUPS_METHODDEF) */ |
8922 | |
8923 | #ifndef OS_INITGROUPS_METHODDEF |
8924 | #define OS_INITGROUPS_METHODDEF |
8925 | #endif /* !defined(OS_INITGROUPS_METHODDEF) */ |
8926 | |
8927 | #ifndef OS_GETPGID_METHODDEF |
8928 | #define OS_GETPGID_METHODDEF |
8929 | #endif /* !defined(OS_GETPGID_METHODDEF) */ |
8930 | |
8931 | #ifndef OS_GETPGRP_METHODDEF |
8932 | #define OS_GETPGRP_METHODDEF |
8933 | #endif /* !defined(OS_GETPGRP_METHODDEF) */ |
8934 | |
8935 | #ifndef OS_SETPGRP_METHODDEF |
8936 | #define OS_SETPGRP_METHODDEF |
8937 | #endif /* !defined(OS_SETPGRP_METHODDEF) */ |
8938 | |
8939 | #ifndef OS_GETPPID_METHODDEF |
8940 | #define OS_GETPPID_METHODDEF |
8941 | #endif /* !defined(OS_GETPPID_METHODDEF) */ |
8942 | |
8943 | #ifndef OS_GETLOGIN_METHODDEF |
8944 | #define OS_GETLOGIN_METHODDEF |
8945 | #endif /* !defined(OS_GETLOGIN_METHODDEF) */ |
8946 | |
8947 | #ifndef OS_GETUID_METHODDEF |
8948 | #define OS_GETUID_METHODDEF |
8949 | #endif /* !defined(OS_GETUID_METHODDEF) */ |
8950 | |
8951 | #ifndef OS_KILL_METHODDEF |
8952 | #define OS_KILL_METHODDEF |
8953 | #endif /* !defined(OS_KILL_METHODDEF) */ |
8954 | |
8955 | #ifndef OS_KILLPG_METHODDEF |
8956 | #define OS_KILLPG_METHODDEF |
8957 | #endif /* !defined(OS_KILLPG_METHODDEF) */ |
8958 | |
8959 | #ifndef OS_PLOCK_METHODDEF |
8960 | #define OS_PLOCK_METHODDEF |
8961 | #endif /* !defined(OS_PLOCK_METHODDEF) */ |
8962 | |
8963 | #ifndef OS_SETUID_METHODDEF |
8964 | #define OS_SETUID_METHODDEF |
8965 | #endif /* !defined(OS_SETUID_METHODDEF) */ |
8966 | |
8967 | #ifndef OS_SETEUID_METHODDEF |
8968 | #define OS_SETEUID_METHODDEF |
8969 | #endif /* !defined(OS_SETEUID_METHODDEF) */ |
8970 | |
8971 | #ifndef OS_SETEGID_METHODDEF |
8972 | #define OS_SETEGID_METHODDEF |
8973 | #endif /* !defined(OS_SETEGID_METHODDEF) */ |
8974 | |
8975 | #ifndef OS_SETREUID_METHODDEF |
8976 | #define OS_SETREUID_METHODDEF |
8977 | #endif /* !defined(OS_SETREUID_METHODDEF) */ |
8978 | |
8979 | #ifndef OS_SETREGID_METHODDEF |
8980 | #define OS_SETREGID_METHODDEF |
8981 | #endif /* !defined(OS_SETREGID_METHODDEF) */ |
8982 | |
8983 | #ifndef OS_SETGID_METHODDEF |
8984 | #define OS_SETGID_METHODDEF |
8985 | #endif /* !defined(OS_SETGID_METHODDEF) */ |
8986 | |
8987 | #ifndef OS_SETGROUPS_METHODDEF |
8988 | #define OS_SETGROUPS_METHODDEF |
8989 | #endif /* !defined(OS_SETGROUPS_METHODDEF) */ |
8990 | |
8991 | #ifndef OS_WAIT3_METHODDEF |
8992 | #define OS_WAIT3_METHODDEF |
8993 | #endif /* !defined(OS_WAIT3_METHODDEF) */ |
8994 | |
8995 | #ifndef OS_WAIT4_METHODDEF |
8996 | #define OS_WAIT4_METHODDEF |
8997 | #endif /* !defined(OS_WAIT4_METHODDEF) */ |
8998 | |
8999 | #ifndef OS_WAITID_METHODDEF |
9000 | #define OS_WAITID_METHODDEF |
9001 | #endif /* !defined(OS_WAITID_METHODDEF) */ |
9002 | |
9003 | #ifndef OS_WAITPID_METHODDEF |
9004 | #define OS_WAITPID_METHODDEF |
9005 | #endif /* !defined(OS_WAITPID_METHODDEF) */ |
9006 | |
9007 | #ifndef OS_WAIT_METHODDEF |
9008 | #define OS_WAIT_METHODDEF |
9009 | #endif /* !defined(OS_WAIT_METHODDEF) */ |
9010 | |
9011 | #ifndef OS_PIDFD_OPEN_METHODDEF |
9012 | #define OS_PIDFD_OPEN_METHODDEF |
9013 | #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */ |
9014 | |
9015 | #ifndef OS_READLINK_METHODDEF |
9016 | #define OS_READLINK_METHODDEF |
9017 | #endif /* !defined(OS_READLINK_METHODDEF) */ |
9018 | |
9019 | #ifndef OS_SYMLINK_METHODDEF |
9020 | #define OS_SYMLINK_METHODDEF |
9021 | #endif /* !defined(OS_SYMLINK_METHODDEF) */ |
9022 | |
9023 | #ifndef OS_TIMES_METHODDEF |
9024 | #define OS_TIMES_METHODDEF |
9025 | #endif /* !defined(OS_TIMES_METHODDEF) */ |
9026 | |
9027 | #ifndef OS_GETSID_METHODDEF |
9028 | #define OS_GETSID_METHODDEF |
9029 | #endif /* !defined(OS_GETSID_METHODDEF) */ |
9030 | |
9031 | #ifndef OS_SETSID_METHODDEF |
9032 | #define OS_SETSID_METHODDEF |
9033 | #endif /* !defined(OS_SETSID_METHODDEF) */ |
9034 | |
9035 | #ifndef OS_SETPGID_METHODDEF |
9036 | #define OS_SETPGID_METHODDEF |
9037 | #endif /* !defined(OS_SETPGID_METHODDEF) */ |
9038 | |
9039 | #ifndef OS_TCGETPGRP_METHODDEF |
9040 | #define OS_TCGETPGRP_METHODDEF |
9041 | #endif /* !defined(OS_TCGETPGRP_METHODDEF) */ |
9042 | |
9043 | #ifndef OS_TCSETPGRP_METHODDEF |
9044 | #define OS_TCSETPGRP_METHODDEF |
9045 | #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ |
9046 | |
9047 | #ifndef OS_LOCKF_METHODDEF |
9048 | #define OS_LOCKF_METHODDEF |
9049 | #endif /* !defined(OS_LOCKF_METHODDEF) */ |
9050 | |
9051 | #ifndef OS_READV_METHODDEF |
9052 | #define OS_READV_METHODDEF |
9053 | #endif /* !defined(OS_READV_METHODDEF) */ |
9054 | |
9055 | #ifndef OS_PREAD_METHODDEF |
9056 | #define OS_PREAD_METHODDEF |
9057 | #endif /* !defined(OS_PREAD_METHODDEF) */ |
9058 | |
9059 | #ifndef OS_PREADV_METHODDEF |
9060 | #define OS_PREADV_METHODDEF |
9061 | #endif /* !defined(OS_PREADV_METHODDEF) */ |
9062 | |
9063 | #ifndef OS_SENDFILE_METHODDEF |
9064 | #define OS_SENDFILE_METHODDEF |
9065 | #endif /* !defined(OS_SENDFILE_METHODDEF) */ |
9066 | |
9067 | #ifndef OS__FCOPYFILE_METHODDEF |
9068 | #define OS__FCOPYFILE_METHODDEF |
9069 | #endif /* !defined(OS__FCOPYFILE_METHODDEF) */ |
9070 | |
9071 | #ifndef OS_PIPE_METHODDEF |
9072 | #define OS_PIPE_METHODDEF |
9073 | #endif /* !defined(OS_PIPE_METHODDEF) */ |
9074 | |
9075 | #ifndef OS_PIPE2_METHODDEF |
9076 | #define OS_PIPE2_METHODDEF |
9077 | #endif /* !defined(OS_PIPE2_METHODDEF) */ |
9078 | |
9079 | #ifndef OS_WRITEV_METHODDEF |
9080 | #define OS_WRITEV_METHODDEF |
9081 | #endif /* !defined(OS_WRITEV_METHODDEF) */ |
9082 | |
9083 | #ifndef OS_PWRITE_METHODDEF |
9084 | #define OS_PWRITE_METHODDEF |
9085 | #endif /* !defined(OS_PWRITE_METHODDEF) */ |
9086 | |
9087 | #ifndef OS_PWRITEV_METHODDEF |
9088 | #define OS_PWRITEV_METHODDEF |
9089 | #endif /* !defined(OS_PWRITEV_METHODDEF) */ |
9090 | |
9091 | #ifndef OS_COPY_FILE_RANGE_METHODDEF |
9092 | #define OS_COPY_FILE_RANGE_METHODDEF |
9093 | #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */ |
9094 | |
9095 | #ifndef OS_SPLICE_METHODDEF |
9096 | #define OS_SPLICE_METHODDEF |
9097 | #endif /* !defined(OS_SPLICE_METHODDEF) */ |
9098 | |
9099 | #ifndef OS_MKFIFO_METHODDEF |
9100 | #define OS_MKFIFO_METHODDEF |
9101 | #endif /* !defined(OS_MKFIFO_METHODDEF) */ |
9102 | |
9103 | #ifndef OS_MKNOD_METHODDEF |
9104 | #define OS_MKNOD_METHODDEF |
9105 | #endif /* !defined(OS_MKNOD_METHODDEF) */ |
9106 | |
9107 | #ifndef OS_MAJOR_METHODDEF |
9108 | #define OS_MAJOR_METHODDEF |
9109 | #endif /* !defined(OS_MAJOR_METHODDEF) */ |
9110 | |
9111 | #ifndef OS_MINOR_METHODDEF |
9112 | #define OS_MINOR_METHODDEF |
9113 | #endif /* !defined(OS_MINOR_METHODDEF) */ |
9114 | |
9115 | #ifndef OS_MAKEDEV_METHODDEF |
9116 | #define OS_MAKEDEV_METHODDEF |
9117 | #endif /* !defined(OS_MAKEDEV_METHODDEF) */ |
9118 | |
9119 | #ifndef OS_FTRUNCATE_METHODDEF |
9120 | #define OS_FTRUNCATE_METHODDEF |
9121 | #endif /* !defined(OS_FTRUNCATE_METHODDEF) */ |
9122 | |
9123 | #ifndef OS_TRUNCATE_METHODDEF |
9124 | #define OS_TRUNCATE_METHODDEF |
9125 | #endif /* !defined(OS_TRUNCATE_METHODDEF) */ |
9126 | |
9127 | #ifndef OS_POSIX_FALLOCATE_METHODDEF |
9128 | #define OS_POSIX_FALLOCATE_METHODDEF |
9129 | #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ |
9130 | |
9131 | #ifndef OS_POSIX_FADVISE_METHODDEF |
9132 | #define OS_POSIX_FADVISE_METHODDEF |
9133 | #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ |
9134 | |
9135 | #ifndef OS_PUTENV_METHODDEF |
9136 | #define OS_PUTENV_METHODDEF |
9137 | #endif /* !defined(OS_PUTENV_METHODDEF) */ |
9138 | |
9139 | #ifndef OS_UNSETENV_METHODDEF |
9140 | #define OS_UNSETENV_METHODDEF |
9141 | #endif /* !defined(OS_UNSETENV_METHODDEF) */ |
9142 | |
9143 | #ifndef OS_WCOREDUMP_METHODDEF |
9144 | #define OS_WCOREDUMP_METHODDEF |
9145 | #endif /* !defined(OS_WCOREDUMP_METHODDEF) */ |
9146 | |
9147 | #ifndef OS_WIFCONTINUED_METHODDEF |
9148 | #define OS_WIFCONTINUED_METHODDEF |
9149 | #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ |
9150 | |
9151 | #ifndef OS_WIFSTOPPED_METHODDEF |
9152 | #define OS_WIFSTOPPED_METHODDEF |
9153 | #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ |
9154 | |
9155 | #ifndef OS_WIFSIGNALED_METHODDEF |
9156 | #define OS_WIFSIGNALED_METHODDEF |
9157 | #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ |
9158 | |
9159 | #ifndef OS_WIFEXITED_METHODDEF |
9160 | #define OS_WIFEXITED_METHODDEF |
9161 | #endif /* !defined(OS_WIFEXITED_METHODDEF) */ |
9162 | |
9163 | #ifndef OS_WEXITSTATUS_METHODDEF |
9164 | #define OS_WEXITSTATUS_METHODDEF |
9165 | #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ |
9166 | |
9167 | #ifndef OS_WTERMSIG_METHODDEF |
9168 | #define OS_WTERMSIG_METHODDEF |
9169 | #endif /* !defined(OS_WTERMSIG_METHODDEF) */ |
9170 | |
9171 | #ifndef OS_WSTOPSIG_METHODDEF |
9172 | #define OS_WSTOPSIG_METHODDEF |
9173 | #endif /* !defined(OS_WSTOPSIG_METHODDEF) */ |
9174 | |
9175 | #ifndef OS_FSTATVFS_METHODDEF |
9176 | #define OS_FSTATVFS_METHODDEF |
9177 | #endif /* !defined(OS_FSTATVFS_METHODDEF) */ |
9178 | |
9179 | #ifndef OS_STATVFS_METHODDEF |
9180 | #define OS_STATVFS_METHODDEF |
9181 | #endif /* !defined(OS_STATVFS_METHODDEF) */ |
9182 | |
9183 | #ifndef OS__GETDISKUSAGE_METHODDEF |
9184 | #define OS__GETDISKUSAGE_METHODDEF |
9185 | #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ |
9186 | |
9187 | #ifndef OS_FPATHCONF_METHODDEF |
9188 | #define OS_FPATHCONF_METHODDEF |
9189 | #endif /* !defined(OS_FPATHCONF_METHODDEF) */ |
9190 | |
9191 | #ifndef OS_PATHCONF_METHODDEF |
9192 | #define OS_PATHCONF_METHODDEF |
9193 | #endif /* !defined(OS_PATHCONF_METHODDEF) */ |
9194 | |
9195 | #ifndef OS_CONFSTR_METHODDEF |
9196 | #define OS_CONFSTR_METHODDEF |
9197 | #endif /* !defined(OS_CONFSTR_METHODDEF) */ |
9198 | |
9199 | #ifndef OS_SYSCONF_METHODDEF |
9200 | #define OS_SYSCONF_METHODDEF |
9201 | #endif /* !defined(OS_SYSCONF_METHODDEF) */ |
9202 | |
9203 | #ifndef OS_STARTFILE_METHODDEF |
9204 | #define OS_STARTFILE_METHODDEF |
9205 | #endif /* !defined(OS_STARTFILE_METHODDEF) */ |
9206 | |
9207 | #ifndef OS_GETLOADAVG_METHODDEF |
9208 | #define OS_GETLOADAVG_METHODDEF |
9209 | #endif /* !defined(OS_GETLOADAVG_METHODDEF) */ |
9210 | |
9211 | #ifndef OS_SETRESUID_METHODDEF |
9212 | #define OS_SETRESUID_METHODDEF |
9213 | #endif /* !defined(OS_SETRESUID_METHODDEF) */ |
9214 | |
9215 | #ifndef OS_SETRESGID_METHODDEF |
9216 | #define OS_SETRESGID_METHODDEF |
9217 | #endif /* !defined(OS_SETRESGID_METHODDEF) */ |
9218 | |
9219 | #ifndef OS_GETRESUID_METHODDEF |
9220 | #define OS_GETRESUID_METHODDEF |
9221 | #endif /* !defined(OS_GETRESUID_METHODDEF) */ |
9222 | |
9223 | #ifndef OS_GETRESGID_METHODDEF |
9224 | #define OS_GETRESGID_METHODDEF |
9225 | #endif /* !defined(OS_GETRESGID_METHODDEF) */ |
9226 | |
9227 | #ifndef OS_GETXATTR_METHODDEF |
9228 | #define OS_GETXATTR_METHODDEF |
9229 | #endif /* !defined(OS_GETXATTR_METHODDEF) */ |
9230 | |
9231 | #ifndef OS_SETXATTR_METHODDEF |
9232 | #define OS_SETXATTR_METHODDEF |
9233 | #endif /* !defined(OS_SETXATTR_METHODDEF) */ |
9234 | |
9235 | #ifndef OS_REMOVEXATTR_METHODDEF |
9236 | #define OS_REMOVEXATTR_METHODDEF |
9237 | #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ |
9238 | |
9239 | #ifndef OS_LISTXATTR_METHODDEF |
9240 | #define OS_LISTXATTR_METHODDEF |
9241 | #endif /* !defined(OS_LISTXATTR_METHODDEF) */ |
9242 | |
9243 | #ifndef OS_MEMFD_CREATE_METHODDEF |
9244 | #define OS_MEMFD_CREATE_METHODDEF |
9245 | #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */ |
9246 | |
9247 | #ifndef OS_EVENTFD_METHODDEF |
9248 | #define OS_EVENTFD_METHODDEF |
9249 | #endif /* !defined(OS_EVENTFD_METHODDEF) */ |
9250 | |
9251 | #ifndef OS_EVENTFD_READ_METHODDEF |
9252 | #define OS_EVENTFD_READ_METHODDEF |
9253 | #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */ |
9254 | |
9255 | #ifndef OS_EVENTFD_WRITE_METHODDEF |
9256 | #define OS_EVENTFD_WRITE_METHODDEF |
9257 | #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */ |
9258 | |
9259 | #ifndef OS_GET_TERMINAL_SIZE_METHODDEF |
9260 | #define OS_GET_TERMINAL_SIZE_METHODDEF |
9261 | #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */ |
9262 | |
9263 | #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF |
9264 | #define OS_GET_HANDLE_INHERITABLE_METHODDEF |
9265 | #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ |
9266 | |
9267 | #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF |
9268 | #define OS_SET_HANDLE_INHERITABLE_METHODDEF |
9269 | #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ |
9270 | |
9271 | #ifndef OS_GET_BLOCKING_METHODDEF |
9272 | #define OS_GET_BLOCKING_METHODDEF |
9273 | #endif /* !defined(OS_GET_BLOCKING_METHODDEF) */ |
9274 | |
9275 | #ifndef OS_SET_BLOCKING_METHODDEF |
9276 | #define OS_SET_BLOCKING_METHODDEF |
9277 | #endif /* !defined(OS_SET_BLOCKING_METHODDEF) */ |
9278 | |
9279 | #ifndef OS_GETRANDOM_METHODDEF |
9280 | #define OS_GETRANDOM_METHODDEF |
9281 | #endif /* !defined(OS_GETRANDOM_METHODDEF) */ |
9282 | |
9283 | #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF |
9284 | #define OS__ADD_DLL_DIRECTORY_METHODDEF |
9285 | #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */ |
9286 | |
9287 | #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF |
9288 | #define OS__REMOVE_DLL_DIRECTORY_METHODDEF |
9289 | #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ |
9290 | |
9291 | #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
9292 | #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF |
9293 | #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ |
9294 | /*[clinic end generated code: output=debefcf43738ec66 input=a9049054013a1b77]*/ |
9295 | |