Debian Codegraph @

Modules/clinic/posixmodule.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_abstract.h" // _PyNumber_Index()
10 #include "pycore_long.h" // _PyLong_UnsignedInt_Converter()
11 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
12
13 PyDoc_STRVAR(os_stat__doc__,
14 "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
15 "--\n"
16 "\n"
17 "Perform a stat system call on the given path.\n"
18 "\n"
19 " path\n"
20 " Path to be examined; can be string, bytes, a path-like object or\n"
21 " open-file-descriptor int.\n"
22 " dir_fd\n"
23 " If not None, it should be a file descriptor open to a directory,\n"
24 " and path should be a relative string; path will then be relative to\n"
25 " that directory.\n"
26 " follow_symlinks\n"
27 " If False, and the last element of the path is a symbolic link,\n"
28 " stat will examine the symbolic link itself instead of the file\n"
29 " the link points to.\n"
30 "\n"
31 "dir_fd and follow_symlinks may not be implemented\n"
32 " on your platform. If they are unavailable, using them will raise a\n"
33 " NotImplementedError.\n"
34 "\n"
35 "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
36 " an open file descriptor.");
37
38 #define OS_STAT_METHODDEF \
39 {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
40
41 static PyObject *
42 os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
43
44 static PyObject *
45 os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
46 {
47 PyObject *return_value = NULL;
48 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
49
50 #define NUM_KEYWORDS 3
51 static struct {
52 PyGC_Head _this_is_not_used;
53 PyObject_VAR_HEAD
54 Py_hash_t ob_hash;
55 PyObject *ob_item[NUM_KEYWORDS];
56 } _kwtuple = {
57 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
58 .ob_hash = -1,
59 .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
60 };
61 #undef NUM_KEYWORDS
62 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
63
64 #else // !Py_BUILD_CORE
65 # define KWTUPLE NULL
66 #endif // !Py_BUILD_CORE
67
68 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
69 static _PyArg_Parser _parser = {
70 .keywords = _keywords,
71 .fname = "stat",
72 .kwtuple = KWTUPLE,
73 };
74 #undef KWTUPLE
75 PyObject *argsbuf[3];
76 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
77 path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
78 int dir_fd = DEFAULT_DIR_FD;
79 int follow_symlinks = 1;
80
81 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
82 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
83 if (!args) {
84 goto exit;
85 }
86 if (!path_converter(args[0], &path)) {
87 goto exit;
88 }
89 if (!noptargs) {
90 goto skip_optional_kwonly;
91 }
92 if (args[1]) {
93 if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
94 goto exit;
95 }
96 if (!--noptargs) {
97 goto skip_optional_kwonly;
98 }
99 }
100 follow_symlinks = PyObject_IsTrue(args[2]);
101 if (follow_symlinks < 0) {
102 goto exit;
103 }
104 skip_optional_kwonly:
105 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
106
107 exit:
108 /* Cleanup for path */
109 path_cleanup(&path);
110
111 return return_value;
112 }
113
114 PyDoc_STRVAR(os_lstat__doc__,
115 "lstat($module, /, path, *, dir_fd=None)\n"
116 "--\n"
117 "\n"
118 "Perform a stat system call on the given path, without following symbolic links.\n"
119 "\n"
120 "Like stat(), but do not follow symbolic links.\n"
121 "Equivalent to stat(path, follow_symlinks=False).");
122
123 #define OS_LSTAT_METHODDEF \
124 {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
125
126 static PyObject *
127 os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
128
129 static PyObject *
130 os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
131 {
132 PyObject *return_value = NULL;
133 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
134
135 #define NUM_KEYWORDS 2
136 static struct {
137 PyGC_Head _this_is_not_used;
138 PyObject_VAR_HEAD
139 Py_hash_t ob_hash;
140 PyObject *ob_item[NUM_KEYWORDS];
141 } _kwtuple = {
142 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
143 .ob_hash = -1,
144 .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
145 };
146 #undef NUM_KEYWORDS
147 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
148
149 #else // !Py_BUILD_CORE
150 # define KWTUPLE NULL
151 #endif // !Py_BUILD_CORE
152
153 static const char * const _keywords[] = {"path", "dir_fd", NULL};
154 static _PyArg_Parser _parser = {
155 .keywords = _keywords,
156 .fname = "lstat",
157 .kwtuple = KWTUPLE,
158 };
159 #undef KWTUPLE
160 PyObject *argsbuf[2];
161 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
162 path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0);
163 int dir_fd = DEFAULT_DIR_FD;
164
165 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
166 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
167 if (!args) {
168 goto exit;
169 }
170 if (!path_converter(args[0], &path)) {
171 goto exit;
172 }
173 if (!noptargs) {
174 goto skip_optional_kwonly;
175 }
176 if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
177 goto exit;
178 }
179 skip_optional_kwonly:
180 return_value = os_lstat_impl(module, &path, dir_fd);
181
182 exit:
183 /* Cleanup for path */
184 path_cleanup(&path);
185
186 return return_value;
187 }
188
189 PyDoc_STRVAR(os_access__doc__,
190 "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
191 " follow_symlinks=True)\n"
192 "--\n"
193 "\n"
194 "Use the real uid/gid to test for access to a path.\n"
195 "\n"
196 " path\n"
197 " Path to be tested; can be string, bytes, or a path-like object.\n"
198 " mode\n"
199 " Operating-system mode bitfield. Can be F_OK to test existence,\n"
200 " or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
201 " dir_fd\n"
202 " If not None, it should be a file descriptor open to a directory,\n"
203 " and path should be relative; path will then be relative to that\n"
204 " directory.\n"
205 " effective_ids\n"
206 " If True, access will use the effective uid/gid instead of\n"
207 " the real uid/gid.\n"
208 " follow_symlinks\n"
209 " If False, and the last element of the path is a symbolic link,\n"
210 " access will examine the symbolic link itself instead of the file\n"
211 " the link points to.\n"
212 "\n"
213 "dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
214 " on your platform. If they are unavailable, using them will raise a\n"
215 " NotImplementedError.\n"
216 "\n"
217 "Note that most operations will use the effective uid/gid, therefore this\n"
218 " routine can be used in a suid/sgid environment to test if the invoking user\n"
219 " has the specified access to the path.");
220
221 #define OS_ACCESS_METHODDEF \
222 {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
223
224 static int
225 os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
226 int effective_ids, int follow_symlinks);
227
228 static PyObject *
229 os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
230 {
231 PyObject *return_value = NULL;
232 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
233
234 #define NUM_KEYWORDS 5
235 static struct {
236 PyGC_Head _this_is_not_used;
237 PyObject_VAR_HEAD
238 Py_hash_t ob_hash;
239 PyObject *ob_item[NUM_KEYWORDS];
240 } _kwtuple = {
241 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
242 .ob_hash = -1,
243 .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), },
244 };
245 #undef NUM_KEYWORDS
246 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
247
248 #else // !Py_BUILD_CORE
249 # define KWTUPLE NULL
250 #endif // !Py_BUILD_CORE
251
252 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
253 static _PyArg_Parser _parser = {
254 .keywords = _keywords,
255 .fname = "access",
256 .kwtuple = KWTUPLE,
257 };
258 #undef KWTUPLE
259 PyObject *argsbuf[5];
260 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
261 path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0);
262 int mode;
263 int dir_fd = DEFAULT_DIR_FD;
264 int effective_ids = 0;
265 int follow_symlinks = 1;
266 int _return_value;
267
268 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
269 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
270 if (!args) {
271 goto exit;
272 }
273 if (!path_converter(args[0], &path)) {
274 goto exit;
275 }
276 mode = PyLong_AsInt(args[1]);
277 if (mode == -1 && PyErr_Occurred()) {
278 goto exit;
279 }
280 if (!noptargs) {
281 goto skip_optional_kwonly;
282 }
283 if (args[2]) {
284 if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
285 goto exit;
286 }
287 if (!--noptargs) {
288 goto skip_optional_kwonly;
289 }
290 }
291 if (args[3]) {
292 effective_ids = PyObject_IsTrue(args[3]);
293 if (effective_ids < 0) {
294 goto exit;
295 }
296 if (!--noptargs) {
297 goto skip_optional_kwonly;
298 }
299 }
300 follow_symlinks = PyObject_IsTrue(args[4]);
301 if (follow_symlinks < 0) {
302 goto exit;
303 }
304 skip_optional_kwonly:
305 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
306 if ((_return_value == -1) && PyErr_Occurred()) {
307 goto exit;
308 }
309 return_value = PyBool_FromLong((long)_return_value);
310
311 exit:
312 /* Cleanup for path */
313 path_cleanup(&path);
314
315 return return_value;
316 }
317
318 #if defined(HAVE_TTYNAME_R)
319
320 PyDoc_STRVAR(os_ttyname__doc__,
321 "ttyname($module, fd, /)\n"
322 "--\n"
323 "\n"
324 "Return the name of the terminal device connected to \'fd\'.\n"
325 "\n"
326 " fd\n"
327 " Integer file descriptor handle.");
328
329 #define OS_TTYNAME_METHODDEF \
330 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
331
332 static PyObject *
333 os_ttyname_impl(PyObject *module, int fd);
334
335 static PyObject *
336 os_ttyname(PyObject *module, PyObject *arg)
337 {
338 PyObject *return_value = NULL;
339 int fd;
340
341 fd = PyLong_AsInt(arg);
342 if (fd == -1 && PyErr_Occurred()) {
343 goto exit;
344 }
345 return_value = os_ttyname_impl(module, fd);
346
347 exit:
348 return return_value;
349 }
350
351 #endif /* defined(HAVE_TTYNAME_R) */
352
353 #if defined(HAVE_CTERMID)
354
355 PyDoc_STRVAR(os_ctermid__doc__,
356 "ctermid($module, /)\n"
357 "--\n"
358 "\n"
359 "Return the name of the controlling terminal for this process.");
360
361 #define OS_CTERMID_METHODDEF \
362 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
363
364 static PyObject *
365 os_ctermid_impl(PyObject *module);
366
367 static PyObject *
368 os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
369 {
370 return os_ctermid_impl(module);
371 }
372
373 #endif /* defined(HAVE_CTERMID) */
374
375 PyDoc_STRVAR(os_chdir__doc__,
376 "chdir($module, /, path)\n"
377 "--\n"
378 "\n"
379 "Change the current working directory to the specified path.\n"
380 "\n"
381 "path may always be specified as a string. On some platforms, path may\n"
382 "also be specified as an open file descriptor. If this functionality is\n"
383 "unavailable, using it raises an exception.");
384
385 #define OS_CHDIR_METHODDEF \
386 {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
387
388 static PyObject *
389 os_chdir_impl(PyObject *module, path_t *path);
390
391 static PyObject *
392 os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
393 {
394 PyObject *return_value = NULL;
395 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
396
397 #define NUM_KEYWORDS 1
398 static struct {
399 PyGC_Head _this_is_not_used;
400 PyObject_VAR_HEAD
401 Py_hash_t ob_hash;
402 PyObject *ob_item[NUM_KEYWORDS];
403 } _kwtuple = {
404 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
405 .ob_hash = -1,
406 .ob_item = { &_Py_ID(path), },
407 };
408 #undef NUM_KEYWORDS
409 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
410
411 #else // !Py_BUILD_CORE
412 # define KWTUPLE NULL
413 #endif // !Py_BUILD_CORE
414
415 static const char * const _keywords[] = {"path", NULL};
416 static _PyArg_Parser _parser = {
417 .keywords = _keywords,
418 .fname = "chdir",
419 .kwtuple = KWTUPLE,
420 };
421 #undef KWTUPLE
422 PyObject *argsbuf[1];
423 path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR);
424
425 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
426 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
427 if (!args) {
428 goto exit;
429 }
430 if (!path_converter(args[0], &path)) {
431 goto exit;
432 }
433 return_value = os_chdir_impl(module, &path);
434
435 exit:
436 /* Cleanup for path */
437 path_cleanup(&path);
438
439 return return_value;
440 }
441
442 #if defined(HAVE_FCHDIR)
443
444 PyDoc_STRVAR(os_fchdir__doc__,
445 "fchdir($module, /, fd)\n"
446 "--\n"
447 "\n"
448 "Change to the directory of the given file descriptor.\n"
449 "\n"
450 "fd must be opened on a directory, not a file.\n"
451 "Equivalent to os.chdir(fd).");
452
453 #define OS_FCHDIR_METHODDEF \
454 {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
455
456 static PyObject *
457 os_fchdir_impl(PyObject *module, int fd);
458
459 static PyObject *
460 os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
461 {
462 PyObject *return_value = NULL;
463 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
464
465 #define NUM_KEYWORDS 1
466 static struct {
467 PyGC_Head _this_is_not_used;
468 PyObject_VAR_HEAD
469 Py_hash_t ob_hash;
470 PyObject *ob_item[NUM_KEYWORDS];
471 } _kwtuple = {
472 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
473 .ob_hash = -1,
474 .ob_item = { &_Py_ID(fd), },
475 };
476 #undef NUM_KEYWORDS
477 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
478
479 #else // !Py_BUILD_CORE
480 # define KWTUPLE NULL
481 #endif // !Py_BUILD_CORE
482
483 static const char * const _keywords[] = {"fd", NULL};
484 static _PyArg_Parser _parser = {
485 .keywords = _keywords,
486 .fname = "fchdir",
487 .kwtuple = KWTUPLE,
488 };
489 #undef KWTUPLE
490 PyObject *argsbuf[1];
491 int fd;
492
493 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
494 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
495 if (!args) {
496 goto exit;
497 }
498 fd = PyObject_AsFileDescriptor(args[0]);
499 if (fd < 0) {
500 goto exit;
501 }
502 return_value = os_fchdir_impl(module, fd);
503
504 exit:
505 return return_value;
506 }
507
508 #endif /* defined(HAVE_FCHDIR) */
509
510 PyDoc_STRVAR(os_chmod__doc__,
511 "chmod($module, /, path, mode, *, dir_fd=None,\n"
512 " follow_symlinks=(os.name != \'nt\'))\n"
513 "--\n"
514 "\n"
515 "Change the access permissions of a file.\n"
516 "\n"
517 " path\n"
518 " Path to be modified. May always be specified as a str, bytes, or\n"
519 " a path-like object. On some platforms, path may also be specified\n"
520 " as an open file descriptor. If this functionality is unavailable,\n"
521 " using it raises an exception.\n"
522 " mode\n"
523 " Operating-system mode bitfield.\n"
524 " Be careful when using number literals for *mode*. The conventional\n"
525 " UNIX notation for numeric modes uses an octal base, which needs to\n"
526 " be indicated with a ``0o`` prefix in Python.\n"
527 " dir_fd\n"
528 " If not None, it should be a file descriptor open to a directory,\n"
529 " and path should be relative; path will then be relative to that\n"
530 " directory.\n"
531 " follow_symlinks\n"
532 " If False, and the last element of the path is a symbolic link,\n"
533 " chmod will modify the symbolic link itself instead of the file\n"
534 " the link points to.\n"
535 "\n"
536 "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
537 " an open file descriptor.\n"
538 "dir_fd and follow_symlinks may not be implemented on your platform.\n"
539 " If they are unavailable, using them will raise a NotImplementedError.");
540
541 #define OS_CHMOD_METHODDEF \
542 {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
543
544 static PyObject *
545 os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
546 int follow_symlinks);
547
548 static PyObject *
549 os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
550 {
551 PyObject *return_value = NULL;
552 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
553
554 #define NUM_KEYWORDS 4
555 static struct {
556 PyGC_Head _this_is_not_used;
557 PyObject_VAR_HEAD
558 Py_hash_t ob_hash;
559 PyObject *ob_item[NUM_KEYWORDS];
560 } _kwtuple = {
561 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
562 .ob_hash = -1,
563 .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
564 };
565 #undef NUM_KEYWORDS
566 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
567
568 #else // !Py_BUILD_CORE
569 # define KWTUPLE NULL
570 #endif // !Py_BUILD_CORE
571
572 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
573 static _PyArg_Parser _parser = {
574 .keywords = _keywords,
575 .fname = "chmod",
576 .kwtuple = KWTUPLE,
577 };
578 #undef KWTUPLE
579 PyObject *argsbuf[4];
580 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
581 path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
582 int mode;
583 int dir_fd = DEFAULT_DIR_FD;
584 int follow_symlinks = CHMOD_DEFAULT_FOLLOW_SYMLINKS;
585
586 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
587 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
588 if (!args) {
589 goto exit;
590 }
591 if (!path_converter(args[0], &path)) {
592 goto exit;
593 }
594 mode = PyLong_AsInt(args[1]);
595 if (mode == -1 && PyErr_Occurred()) {
596 goto exit;
597 }
598 if (!noptargs) {
599 goto skip_optional_kwonly;
600 }
601 if (args[2]) {
602 if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
603 goto exit;
604 }
605 if (!--noptargs) {
606 goto skip_optional_kwonly;
607 }
608 }
609 follow_symlinks = PyObject_IsTrue(args[3]);
610 if (follow_symlinks < 0) {
611 goto exit;
612 }
613 skip_optional_kwonly:
614 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
615
616 exit:
617 /* Cleanup for path */
618 path_cleanup(&path);
619
620 return return_value;
621 }
622
623 #if (defined(HAVE_FCHMOD) || defined(MS_WINDOWS))
624
625 PyDoc_STRVAR(os_fchmod__doc__,
626 "fchmod($module, /, fd, mode)\n"
627 "--\n"
628 "\n"
629 "Change the access permissions of the file given by file descriptor fd.\n"
630 "\n"
631 " fd\n"
632 " The file descriptor of the file to be modified.\n"
633 " mode\n"
634 " Operating-system mode bitfield.\n"
635 " Be careful when using number literals for *mode*. The conventional\n"
636 " UNIX notation for numeric modes uses an octal base, which needs to\n"
637 " be indicated with a ``0o`` prefix in Python.\n"
638 "\n"
639 "Equivalent to os.chmod(fd, mode).");
640
641 #define OS_FCHMOD_METHODDEF \
642 {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
643
644 static PyObject *
645 os_fchmod_impl(PyObject *module, int fd, int mode);
646
647 static PyObject *
648 os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
649 {
650 PyObject *return_value = NULL;
651 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
652
653 #define NUM_KEYWORDS 2
654 static struct {
655 PyGC_Head _this_is_not_used;
656 PyObject_VAR_HEAD
657 Py_hash_t ob_hash;
658 PyObject *ob_item[NUM_KEYWORDS];
659 } _kwtuple = {
660 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
661 .ob_hash = -1,
662 .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
663 };
664 #undef NUM_KEYWORDS
665 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
666
667 #else // !Py_BUILD_CORE
668 # define KWTUPLE NULL
669 #endif // !Py_BUILD_CORE
670
671 static const char * const _keywords[] = {"fd", "mode", NULL};
672 static _PyArg_Parser _parser = {
673 .keywords = _keywords,
674 .fname = "fchmod",
675 .kwtuple = KWTUPLE,
676 };
677 #undef KWTUPLE
678 PyObject *argsbuf[2];
679 int fd;
680 int mode;
681
682 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
683 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
684 if (!args) {
685 goto exit;
686 }
687 fd = PyLong_AsInt(args[0]);
688 if (fd == -1 && PyErr_Occurred()) {
689 goto exit;
690 }
691 mode = PyLong_AsInt(args[1]);
692 if (mode == -1 && PyErr_Occurred()) {
693 goto exit;
694 }
695 return_value = os_fchmod_impl(module, fd, mode);
696
697 exit:
698 return return_value;
699 }
700
701 #endif /* (defined(HAVE_FCHMOD) || defined(MS_WINDOWS)) */
702
703 #if (defined(HAVE_LCHMOD) || defined(MS_WINDOWS))
704
705 PyDoc_STRVAR(os_lchmod__doc__,
706 "lchmod($module, /, path, mode)\n"
707 "--\n"
708 "\n"
709 "Change the access permissions of a file, without following symbolic links.\n"
710 "\n"
711 "If path is a symlink, this affects the link itself rather than the\n"
712 "target. Equivalent to chmod(path, mode, follow_symlinks=False).");
713
714 #define OS_LCHMOD_METHODDEF \
715 {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
716
717 static PyObject *
718 os_lchmod_impl(PyObject *module, path_t *path, int mode);
719
720 static PyObject *
721 os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
722 {
723 PyObject *return_value = NULL;
724 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
725
726 #define NUM_KEYWORDS 2
727 static struct {
728 PyGC_Head _this_is_not_used;
729 PyObject_VAR_HEAD
730 Py_hash_t ob_hash;
731 PyObject *ob_item[NUM_KEYWORDS];
732 } _kwtuple = {
733 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
734 .ob_hash = -1,
735 .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
736 };
737 #undef NUM_KEYWORDS
738 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
739
740 #else // !Py_BUILD_CORE
741 # define KWTUPLE NULL
742 #endif // !Py_BUILD_CORE
743
744 static const char * const _keywords[] = {"path", "mode", NULL};
745 static _PyArg_Parser _parser = {
746 .keywords = _keywords,
747 .fname = "lchmod",
748 .kwtuple = KWTUPLE,
749 };
750 #undef KWTUPLE
751 PyObject *argsbuf[2];
752 path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
753 int mode;
754
755 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
756 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
757 if (!args) {
758 goto exit;
759 }
760 if (!path_converter(args[0], &path)) {
761 goto exit;
762 }
763 mode = PyLong_AsInt(args[1]);
764 if (mode == -1 && PyErr_Occurred()) {
765 goto exit;
766 }
767 return_value = os_lchmod_impl(module, &path, mode);
768
769 exit:
770 /* Cleanup for path */
771 path_cleanup(&path);
772
773 return return_value;
774 }
775
776 #endif /* (defined(HAVE_LCHMOD) || defined(MS_WINDOWS)) */
777
778 #if defined(HAVE_CHFLAGS)
779
780 PyDoc_STRVAR(os_chflags__doc__,
781 "chflags($module, /, path, flags, follow_symlinks=True)\n"
782 "--\n"
783 "\n"
784 "Set file flags.\n"
785 "\n"
786 "If follow_symlinks is False, and the last element of the path is\n"
787 "a symbolic link, chflags() will change flags on the symbolic link itself\n"
788 "instead of the file the link points to.\n"
789 "follow_symlinks may not be implemented on your platform. If it is\n"
790 "unavailable, using it will raise a NotImplementedError.");
791
792 #define OS_CHFLAGS_METHODDEF \
793 {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
794
795 static PyObject *
796 os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
797 int follow_symlinks);
798
799 static PyObject *
800 os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
801 {
802 PyObject *return_value = NULL;
803 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
804
805 #define NUM_KEYWORDS 3
806 static struct {
807 PyGC_Head _this_is_not_used;
808 PyObject_VAR_HEAD
809 Py_hash_t ob_hash;
810 PyObject *ob_item[NUM_KEYWORDS];
811 } _kwtuple = {
812 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
813 .ob_hash = -1,
814 .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
815 };
816 #undef NUM_KEYWORDS
817 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
818
819 #else // !Py_BUILD_CORE
820 # define KWTUPLE NULL
821 #endif // !Py_BUILD_CORE
822
823 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
824 static _PyArg_Parser _parser = {
825 .keywords = _keywords,
826 .fname = "chflags",
827 .kwtuple = KWTUPLE,
828 };
829 #undef KWTUPLE
830 PyObject *argsbuf[3];
831 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
832 path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
833 unsigned long flags;
834 int follow_symlinks = 1;
835
836 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
837 /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
838 if (!args) {
839 goto exit;
840 }
841 if (!path_converter(args[0], &path)) {
842 goto exit;
843 }
844 if (!PyIndex_Check(args[1])) {
845 _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
846 goto exit;
847 }
848 flags = PyLong_AsUnsignedLongMask(args[1]);
849 if (!noptargs) {
850 goto skip_optional_pos;
851 }
852 follow_symlinks = PyObject_IsTrue(args[2]);
853 if (follow_symlinks < 0) {
854 goto exit;
855 }
856 skip_optional_pos:
857 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
858
859 exit:
860 /* Cleanup for path */
861 path_cleanup(&path);
862
863 return return_value;
864 }
865
866 #endif /* defined(HAVE_CHFLAGS) */
867
868 #if defined(HAVE_LCHFLAGS)
869
870 PyDoc_STRVAR(os_lchflags__doc__,
871 "lchflags($module, /, path, flags)\n"
872 "--\n"
873 "\n"
874 "Set file flags.\n"
875 "\n"
876 "This function will not follow symbolic links.\n"
877 "Equivalent to chflags(path, flags, follow_symlinks=False).");
878
879 #define OS_LCHFLAGS_METHODDEF \
880 {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
881
882 static PyObject *
883 os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
884
885 static PyObject *
886 os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
887 {
888 PyObject *return_value = NULL;
889 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
890
891 #define NUM_KEYWORDS 2
892 static struct {
893 PyGC_Head _this_is_not_used;
894 PyObject_VAR_HEAD
895 Py_hash_t ob_hash;
896 PyObject *ob_item[NUM_KEYWORDS];
897 } _kwtuple = {
898 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
899 .ob_hash = -1,
900 .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
901 };
902 #undef NUM_KEYWORDS
903 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
904
905 #else // !Py_BUILD_CORE
906 # define KWTUPLE NULL
907 #endif // !Py_BUILD_CORE
908
909 static const char * const _keywords[] = {"path", "flags", NULL};
910 static _PyArg_Parser _parser = {
911 .keywords = _keywords,
912 .fname = "lchflags",
913 .kwtuple = KWTUPLE,
914 };
915 #undef KWTUPLE
916 PyObject *argsbuf[2];
917 path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
918 unsigned long flags;
919
920 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
921 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
922 if (!args) {
923 goto exit;
924 }
925 if (!path_converter(args[0], &path)) {
926 goto exit;
927 }
928 if (!PyIndex_Check(args[1])) {
929 _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
930 goto exit;
931 }
932 flags = PyLong_AsUnsignedLongMask(args[1]);
933 return_value = os_lchflags_impl(module, &path, flags);
934
935 exit:
936 /* Cleanup for path */
937 path_cleanup(&path);
938
939 return return_value;
940 }
941
942 #endif /* defined(HAVE_LCHFLAGS) */
943
944 #if defined(HAVE_CHROOT)
945
946 PyDoc_STRVAR(os_chroot__doc__,
947 "chroot($module, /, path)\n"
948 "--\n"
949 "\n"
950 "Change root directory to path.");
951
952 #define OS_CHROOT_METHODDEF \
953 {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
954
955 static PyObject *
956 os_chroot_impl(PyObject *module, path_t *path);
957
958 static PyObject *
959 os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
960 {
961 PyObject *return_value = NULL;
962 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
963
964 #define NUM_KEYWORDS 1
965 static struct {
966 PyGC_Head _this_is_not_used;
967 PyObject_VAR_HEAD
968 Py_hash_t ob_hash;
969 PyObject *ob_item[NUM_KEYWORDS];
970 } _kwtuple = {
971 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
972 .ob_hash = -1,
973 .ob_item = { &_Py_ID(path), },
974 };
975 #undef NUM_KEYWORDS
976 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
977
978 #else // !Py_BUILD_CORE
979 # define KWTUPLE NULL
980 #endif // !Py_BUILD_CORE
981
982 static const char * const _keywords[] = {"path", NULL};
983 static _PyArg_Parser _parser = {
984 .keywords = _keywords,
985 .fname = "chroot",
986 .kwtuple = KWTUPLE,
987 };
988 #undef KWTUPLE
989 PyObject *argsbuf[1];
990 path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
991
992 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
993 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
994 if (!args) {
995 goto exit;
996 }
997 if (!path_converter(args[0], &path)) {
998 goto exit;
999 }
1000 return_value = os_chroot_impl(module, &path);
1001
1002 exit:
1003 /* Cleanup for path */
1004 path_cleanup(&path);
1005
1006 return return_value;
1007 }
1008
1009 #endif /* defined(HAVE_CHROOT) */
1010
1011 #if defined(HAVE_FSYNC)
1012
1013 PyDoc_STRVAR(os_fsync__doc__,
1014 "fsync($module, /, fd)\n"
1015 "--\n"
1016 "\n"
1017 "Force write of fd to disk.");
1018
1019 #define OS_FSYNC_METHODDEF \
1020 {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
1021
1022 static PyObject *
1023 os_fsync_impl(PyObject *module, int fd);
1024
1025 static PyObject *
1026 os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1027 {
1028 PyObject *return_value = NULL;
1029 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1030
1031 #define NUM_KEYWORDS 1
1032 static struct {
1033 PyGC_Head _this_is_not_used;
1034 PyObject_VAR_HEAD
1035 Py_hash_t ob_hash;
1036 PyObject *ob_item[NUM_KEYWORDS];
1037 } _kwtuple = {
1038 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1039 .ob_hash = -1,
1040 .ob_item = { &_Py_ID(fd), },
1041 };
1042 #undef NUM_KEYWORDS
1043 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1044
1045 #else // !Py_BUILD_CORE
1046 # define KWTUPLE NULL
1047 #endif // !Py_BUILD_CORE
1048
1049 static const char * const _keywords[] = {"fd", NULL};
1050 static _PyArg_Parser _parser = {
1051 .keywords = _keywords,
1052 .fname = "fsync",
1053 .kwtuple = KWTUPLE,
1054 };
1055 #undef KWTUPLE
1056 PyObject *argsbuf[1];
1057 int fd;
1058
1059 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1060 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1061 if (!args) {
1062 goto exit;
1063 }
1064 fd = PyObject_AsFileDescriptor(args[0]);
1065 if (fd < 0) {
1066 goto exit;
1067 }
1068 return_value = os_fsync_impl(module, fd);
1069
1070 exit:
1071 return return_value;
1072 }
1073
1074 #endif /* defined(HAVE_FSYNC) */
1075
1076 #if defined(HAVE_SYNC)
1077
1078 PyDoc_STRVAR(os_sync__doc__,
1079 "sync($module, /)\n"
1080 "--\n"
1081 "\n"
1082 "Force write of everything to disk.");
1083
1084 #define OS_SYNC_METHODDEF \
1085 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
1086
1087 static PyObject *
1088 os_sync_impl(PyObject *module);
1089
1090 static PyObject *
1091 os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
1092 {
1093 return os_sync_impl(module);
1094 }
1095
1096 #endif /* defined(HAVE_SYNC) */
1097
1098 #if defined(HAVE_FDATASYNC)
1099
1100 PyDoc_STRVAR(os_fdatasync__doc__,
1101 "fdatasync($module, /, fd)\n"
1102 "--\n"
1103 "\n"
1104 "Force write of fd to disk without forcing update of metadata.");
1105
1106 #define OS_FDATASYNC_METHODDEF \
1107 {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
1108
1109 static PyObject *
1110 os_fdatasync_impl(PyObject *module, int fd);
1111
1112 static PyObject *
1113 os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1114 {
1115 PyObject *return_value = NULL;
1116 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1117
1118 #define NUM_KEYWORDS 1
1119 static struct {
1120 PyGC_Head _this_is_not_used;
1121 PyObject_VAR_HEAD
1122 Py_hash_t ob_hash;
1123 PyObject *ob_item[NUM_KEYWORDS];
1124 } _kwtuple = {
1125 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1126 .ob_hash = -1,
1127 .ob_item = { &_Py_ID(fd), },
1128 };
1129 #undef NUM_KEYWORDS
1130 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1131
1132 #else // !Py_BUILD_CORE
1133 # define KWTUPLE NULL
1134 #endif // !Py_BUILD_CORE
1135
1136 static const char * const _keywords[] = {"fd", NULL};
1137 static _PyArg_Parser _parser = {
1138 .keywords = _keywords,
1139 .fname = "fdatasync",
1140 .kwtuple = KWTUPLE,
1141 };
1142 #undef KWTUPLE
1143 PyObject *argsbuf[1];
1144 int fd;
1145
1146 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1147 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1148 if (!args) {
1149 goto exit;
1150 }
1151 fd = PyObject_AsFileDescriptor(args[0]);
1152 if (fd < 0) {
1153 goto exit;
1154 }
1155 return_value = os_fdatasync_impl(module, fd);
1156
1157 exit:
1158 return return_value;
1159 }
1160
1161 #endif /* defined(HAVE_FDATASYNC) */
1162
1163 #if defined(HAVE_CHOWN)
1164
1165 PyDoc_STRVAR(os_chown__doc__,
1166 "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
1167 "--\n"
1168 "\n"
1169 "Change the owner and group id of path to the numeric uid and gid.\n"
1170 "\n"
1171 " path\n"
1172 " Path to be examined; can be string, bytes, a path-like object, or\n"
1173 " open-file-descriptor int.\n"
1174 " dir_fd\n"
1175 " If not None, it should be a file descriptor open to a directory,\n"
1176 " and path should be relative; path will then be relative to that\n"
1177 " directory.\n"
1178 " follow_symlinks\n"
1179 " If False, and the last element of the path is a symbolic link,\n"
1180 " stat will examine the symbolic link itself instead of the file\n"
1181 " the link points to.\n"
1182 "\n"
1183 "path may always be specified as a string. On some platforms, path may\n"
1184 "also be specified as an open file descriptor. If this functionality is\n"
1185 "unavailable, using it raises an exception.\n"
1186 "If dir_fd is not None, it should be a file descriptor open to\n"
1187 "a directory, and path should be relative; path will then be relative to\n"
1188 "that directory.\n"
1189 "If follow_symlinks is False, and the last element of the path is\n"
1190 "a symbolic link, chown will modify the symbolic link itself instead of\n"
1191 "the file the link points to.\n"
1192 "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
1193 "an open file descriptor.\n"
1194 "dir_fd and follow_symlinks may not be implemented on your platform. If\n"
1195 "they are unavailable, using them will raise a NotImplementedError.");
1196
1197 #define OS_CHOWN_METHODDEF \
1198 {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
1199
1200 static PyObject *
1201 os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
1202 int dir_fd, int follow_symlinks);
1203
1204 static PyObject *
1205 os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1206 {
1207 PyObject *return_value = NULL;
1208 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1209
1210 #define NUM_KEYWORDS 5
1211 static struct {
1212 PyGC_Head _this_is_not_used;
1213 PyObject_VAR_HEAD
1214 Py_hash_t ob_hash;
1215 PyObject *ob_item[NUM_KEYWORDS];
1216 } _kwtuple = {
1217 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1218 .ob_hash = -1,
1219 .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
1220 };
1221 #undef NUM_KEYWORDS
1222 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1223
1224 #else // !Py_BUILD_CORE
1225 # define KWTUPLE NULL
1226 #endif // !Py_BUILD_CORE
1227
1228 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
1229 static _PyArg_Parser _parser = {
1230 .keywords = _keywords,
1231 .fname = "chown",
1232 .kwtuple = KWTUPLE,
1233 };
1234 #undef KWTUPLE
1235 PyObject *argsbuf[5];
1236 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
1237 path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
1238 uid_t uid;
1239 gid_t gid;
1240 int dir_fd = DEFAULT_DIR_FD;
1241 int follow_symlinks = 1;
1242
1243 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1244 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1245 if (!args) {
1246 goto exit;
1247 }
1248 if (!path_converter(args[0], &path)) {
1249 goto exit;
1250 }
1251 if (!_Py_Uid_Converter(args[1], &uid)) {
1252 goto exit;
1253 }
1254 if (!_Py_Gid_Converter(args[2], &gid)) {
1255 goto exit;
1256 }
1257 if (!noptargs) {
1258 goto skip_optional_kwonly;
1259 }
1260 if (args[3]) {
1261 if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
1262 goto exit;
1263 }
1264 if (!--noptargs) {
1265 goto skip_optional_kwonly;
1266 }
1267 }
1268 follow_symlinks = PyObject_IsTrue(args[4]);
1269 if (follow_symlinks < 0) {
1270 goto exit;
1271 }
1272 skip_optional_kwonly:
1273 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
1274
1275 exit:
1276 /* Cleanup for path */
1277 path_cleanup(&path);
1278
1279 return return_value;
1280 }
1281
1282 #endif /* defined(HAVE_CHOWN) */
1283
1284 #if defined(HAVE_FCHOWN)
1285
1286 PyDoc_STRVAR(os_fchown__doc__,
1287 "fchown($module, /, fd, uid, gid)\n"
1288 "--\n"
1289 "\n"
1290 "Change the owner and group id of the file specified by file descriptor.\n"
1291 "\n"
1292 "Equivalent to os.chown(fd, uid, gid).");
1293
1294 #define OS_FCHOWN_METHODDEF \
1295 {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
1296
1297 static PyObject *
1298 os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
1299
1300 static PyObject *
1301 os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1302 {
1303 PyObject *return_value = NULL;
1304 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1305
1306 #define NUM_KEYWORDS 3
1307 static struct {
1308 PyGC_Head _this_is_not_used;
1309 PyObject_VAR_HEAD
1310 Py_hash_t ob_hash;
1311 PyObject *ob_item[NUM_KEYWORDS];
1312 } _kwtuple = {
1313 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1314 .ob_hash = -1,
1315 .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
1316 };
1317 #undef NUM_KEYWORDS
1318 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1319
1320 #else // !Py_BUILD_CORE
1321 # define KWTUPLE NULL
1322 #endif // !Py_BUILD_CORE
1323
1324 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
1325 static _PyArg_Parser _parser = {
1326 .keywords = _keywords,
1327 .fname = "fchown",
1328 .kwtuple = KWTUPLE,
1329 };
1330 #undef KWTUPLE
1331 PyObject *argsbuf[3];
1332 int fd;
1333 uid_t uid;
1334 gid_t gid;
1335
1336 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1337 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1338 if (!args) {
1339 goto exit;
1340 }
1341 fd = PyLong_AsInt(args[0]);
1342 if (fd == -1 && PyErr_Occurred()) {
1343 goto exit;
1344 }
1345 if (!_Py_Uid_Converter(args[1], &uid)) {
1346 goto exit;
1347 }
1348 if (!_Py_Gid_Converter(args[2], &gid)) {
1349 goto exit;
1350 }
1351 return_value = os_fchown_impl(module, fd, uid, gid);
1352
1353 exit:
1354 return return_value;
1355 }
1356
1357 #endif /* defined(HAVE_FCHOWN) */
1358
1359 #if defined(HAVE_LCHOWN)
1360
1361 PyDoc_STRVAR(os_lchown__doc__,
1362 "lchown($module, /, path, uid, gid)\n"
1363 "--\n"
1364 "\n"
1365 "Change the owner and group id of path to the numeric uid and gid.\n"
1366 "\n"
1367 "This function will not follow symbolic links.\n"
1368 "Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
1369
1370 #define OS_LCHOWN_METHODDEF \
1371 {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
1372
1373 static PyObject *
1374 os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
1375
1376 static PyObject *
1377 os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1378 {
1379 PyObject *return_value = NULL;
1380 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1381
1382 #define NUM_KEYWORDS 3
1383 static struct {
1384 PyGC_Head _this_is_not_used;
1385 PyObject_VAR_HEAD
1386 Py_hash_t ob_hash;
1387 PyObject *ob_item[NUM_KEYWORDS];
1388 } _kwtuple = {
1389 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1390 .ob_hash = -1,
1391 .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
1392 };
1393 #undef NUM_KEYWORDS
1394 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1395
1396 #else // !Py_BUILD_CORE
1397 # define KWTUPLE NULL
1398 #endif // !Py_BUILD_CORE
1399
1400 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
1401 static _PyArg_Parser _parser = {
1402 .keywords = _keywords,
1403 .fname = "lchown",
1404 .kwtuple = KWTUPLE,
1405 };
1406 #undef KWTUPLE
1407 PyObject *argsbuf[3];
1408 path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
1409 uid_t uid;
1410 gid_t gid;
1411
1412 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1413 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1414 if (!args) {
1415 goto exit;
1416 }
1417 if (!path_converter(args[0], &path)) {
1418 goto exit;
1419 }
1420 if (!_Py_Uid_Converter(args[1], &uid)) {
1421 goto exit;
1422 }
1423 if (!_Py_Gid_Converter(args[2], &gid)) {
1424 goto exit;
1425 }
1426 return_value = os_lchown_impl(module, &path, uid, gid);
1427
1428 exit:
1429 /* Cleanup for path */
1430 path_cleanup(&path);
1431
1432 return return_value;
1433 }
1434
1435 #endif /* defined(HAVE_LCHOWN) */
1436
1437 PyDoc_STRVAR(os_getcwd__doc__,
1438 "getcwd($module, /)\n"
1439 "--\n"
1440 "\n"
1441 "Return a unicode string representing the current working directory.");
1442
1443 #define OS_GETCWD_METHODDEF \
1444 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1445
1446 static PyObject *
1447 os_getcwd_impl(PyObject *module);
1448
1449 static PyObject *
1450 os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
1451 {
1452 return os_getcwd_impl(module);
1453 }
1454
1455 PyDoc_STRVAR(os_getcwdb__doc__,
1456 "getcwdb($module, /)\n"
1457 "--\n"
1458 "\n"
1459 "Return a bytes string representing the current working directory.");
1460
1461 #define OS_GETCWDB_METHODDEF \
1462 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1463
1464 static PyObject *
1465 os_getcwdb_impl(PyObject *module);
1466
1467 static PyObject *
1468 os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
1469 {
1470 return os_getcwdb_impl(module);
1471 }
1472
1473 #if defined(HAVE_LINK)
1474
1475 PyDoc_STRVAR(os_link__doc__,
1476 "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1477 " follow_symlinks=(os.name != \'nt\'))\n"
1478 "--\n"
1479 "\n"
1480 "Create a hard link to a file.\n"
1481 "\n"
1482 "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1483 "descriptor open to a directory, and the respective path string (src or\n"
1484 "dst) should be relative; the path will then be relative to that\n"
1485 "directory.\n"
1486 "If follow_symlinks is False, and the last element of src is a symbolic\n"
1487 "link, link will create a link to the symbolic link itself instead of the\n"
1488 "file the link points to.\n"
1489 "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on\n"
1490 "your platform. If they are unavailable, using them will raise\n"
1491 "a NotImplementedError.");
1492
1493 #define OS_LINK_METHODDEF \
1494 {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
1495
1496 static PyObject *
1497 os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1498 int dst_dir_fd, int follow_symlinks);
1499
1500 static PyObject *
1501 os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1502 {
1503 PyObject *return_value = NULL;
1504 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1505
1506 #define NUM_KEYWORDS 5
1507 static struct {
1508 PyGC_Head _this_is_not_used;
1509 PyObject_VAR_HEAD
1510 Py_hash_t ob_hash;
1511 PyObject *ob_item[NUM_KEYWORDS];
1512 } _kwtuple = {
1513 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1514 .ob_hash = -1,
1515 .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
1516 };
1517 #undef NUM_KEYWORDS
1518 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1519
1520 #else // !Py_BUILD_CORE
1521 # define KWTUPLE NULL
1522 #endif // !Py_BUILD_CORE
1523
1524 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
1525 static _PyArg_Parser _parser = {
1526 .keywords = _keywords,
1527 .fname = "link",
1528 .kwtuple = KWTUPLE,
1529 };
1530 #undef KWTUPLE
1531 PyObject *argsbuf[5];
1532 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1533 path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
1534 path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
1535 int src_dir_fd = DEFAULT_DIR_FD;
1536 int dst_dir_fd = DEFAULT_DIR_FD;
1537 int follow_symlinks = -1;
1538
1539 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1540 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1541 if (!args) {
1542 goto exit;
1543 }
1544 if (!path_converter(args[0], &src)) {
1545 goto exit;
1546 }
1547 if (!path_converter(args[1], &dst)) {
1548 goto exit;
1549 }
1550 if (!noptargs) {
1551 goto skip_optional_kwonly;
1552 }
1553 if (args[2]) {
1554 if (!dir_fd_converter(args[2], &src_dir_fd)) {
1555 goto exit;
1556 }
1557 if (!--noptargs) {
1558 goto skip_optional_kwonly;
1559 }
1560 }
1561 if (args[3]) {
1562 if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1563 goto exit;
1564 }
1565 if (!--noptargs) {
1566 goto skip_optional_kwonly;
1567 }
1568 }
1569 follow_symlinks = PyObject_IsTrue(args[4]);
1570 if (follow_symlinks < 0) {
1571 goto exit;
1572 }
1573 skip_optional_kwonly:
1574 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1575
1576 exit:
1577 /* Cleanup for src */
1578 path_cleanup(&src);
1579 /* Cleanup for dst */
1580 path_cleanup(&dst);
1581
1582 return return_value;
1583 }
1584
1585 #endif /* defined(HAVE_LINK) */
1586
1587 PyDoc_STRVAR(os_listdir__doc__,
1588 "listdir($module, /, path=None)\n"
1589 "--\n"
1590 "\n"
1591 "Return a list containing the names of the files in the directory.\n"
1592 "\n"
1593 "path can be specified as either str, bytes, or a path-like object. If\n"
1594 "path is bytes, the filenames returned will also be bytes; in all other\n"
1595 "circumstances the filenames returned will be str.\n"
1596 "If path is None, uses the path=\'.\'.\n"
1597 "On some platforms, path may also be specified as an open file\n"
1598 "descriptor; the file descriptor must refer to a directory. If this\n"
1599 "functionality is unavailable, using it raises NotImplementedError.\n"
1600 "\n"
1601 "The list is in arbitrary order. It does not include the special\n"
1602 "entries \'.\' and \'..\' even if they are present in the directory.");
1603
1604 #define OS_LISTDIR_METHODDEF \
1605 {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
1606
1607 static PyObject *
1608 os_listdir_impl(PyObject *module, path_t *path);
1609
1610 static PyObject *
1611 os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1612 {
1613 PyObject *return_value = NULL;
1614 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1615
1616 #define NUM_KEYWORDS 1
1617 static struct {
1618 PyGC_Head _this_is_not_used;
1619 PyObject_VAR_HEAD
1620 Py_hash_t ob_hash;
1621 PyObject *ob_item[NUM_KEYWORDS];
1622 } _kwtuple = {
1623 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1624 .ob_hash = -1,
1625 .ob_item = { &_Py_ID(path), },
1626 };
1627 #undef NUM_KEYWORDS
1628 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1629
1630 #else // !Py_BUILD_CORE
1631 # define KWTUPLE NULL
1632 #endif // !Py_BUILD_CORE
1633
1634 static const char * const _keywords[] = {"path", NULL};
1635 static _PyArg_Parser _parser = {
1636 .keywords = _keywords,
1637 .fname = "listdir",
1638 .kwtuple = KWTUPLE,
1639 };
1640 #undef KWTUPLE
1641 PyObject *argsbuf[1];
1642 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1643 path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
1644
1645 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1646 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1647 if (!args) {
1648 goto exit;
1649 }
1650 if (!noptargs) {
1651 goto skip_optional_pos;
1652 }
1653 if (!path_converter(args[0], &path)) {
1654 goto exit;
1655 }
1656 skip_optional_pos:
1657 return_value = os_listdir_impl(module, &path);
1658
1659 exit:
1660 /* Cleanup for path */
1661 path_cleanup(&path);
1662
1663 return return_value;
1664 }
1665
1666 #if defined(MS_WINDOWS)
1667
1668 PyDoc_STRVAR(os_listdrives__doc__,
1669 "listdrives($module, /)\n"
1670 "--\n"
1671 "\n"
1672 "Return a list containing the names of drives in the system.\n"
1673 "\n"
1674 "A drive name typically looks like \'C:\\\\\'.");
1675
1676 #define OS_LISTDRIVES_METHODDEF \
1677 {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
1678
1679 static PyObject *
1680 os_listdrives_impl(PyObject *module);
1681
1682 static PyObject *
1683 os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
1684 {
1685 return os_listdrives_impl(module);
1686 }
1687
1688 #endif /* defined(MS_WINDOWS) */
1689
1690 #if defined(MS_WINDOWS)
1691
1692 PyDoc_STRVAR(os_listvolumes__doc__,
1693 "listvolumes($module, /)\n"
1694 "--\n"
1695 "\n"
1696 "Return a list containing the volumes in the system.\n"
1697 "\n"
1698 "Volumes are typically represented as a GUID path.");
1699
1700 #define OS_LISTVOLUMES_METHODDEF \
1701 {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
1702
1703 static PyObject *
1704 os_listvolumes_impl(PyObject *module);
1705
1706 static PyObject *
1707 os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
1708 {
1709 return os_listvolumes_impl(module);
1710 }
1711
1712 #endif /* defined(MS_WINDOWS) */
1713
1714 #if defined(MS_WINDOWS)
1715
1716 PyDoc_STRVAR(os_listmounts__doc__,
1717 "listmounts($module, /, volume)\n"
1718 "--\n"
1719 "\n"
1720 "Return a list containing mount points for a particular volume.\n"
1721 "\n"
1722 "\'volume\' should be a GUID path as returned from os.listvolumes.");
1723
1724 #define OS_LISTMOUNTS_METHODDEF \
1725 {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
1726
1727 static PyObject *
1728 os_listmounts_impl(PyObject *module, path_t *volume);
1729
1730 static PyObject *
1731 os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1732 {
1733 PyObject *return_value = NULL;
1734 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1735
1736 #define NUM_KEYWORDS 1
1737 static struct {
1738 PyGC_Head _this_is_not_used;
1739 PyObject_VAR_HEAD
1740 Py_hash_t ob_hash;
1741 PyObject *ob_item[NUM_KEYWORDS];
1742 } _kwtuple = {
1743 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1744 .ob_hash = -1,
1745 .ob_item = { &_Py_ID(volume), },
1746 };
1747 #undef NUM_KEYWORDS
1748 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1749
1750 #else // !Py_BUILD_CORE
1751 # define KWTUPLE NULL
1752 #endif // !Py_BUILD_CORE
1753
1754 static const char * const _keywords[] = {"volume", NULL};
1755 static _PyArg_Parser _parser = {
1756 .keywords = _keywords,
1757 .fname = "listmounts",
1758 .kwtuple = KWTUPLE,
1759 };
1760 #undef KWTUPLE
1761 PyObject *argsbuf[1];
1762 path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
1763
1764 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1765 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1766 if (!args) {
1767 goto exit;
1768 }
1769 if (!path_converter(args[0], &volume)) {
1770 goto exit;
1771 }
1772 return_value = os_listmounts_impl(module, &volume);
1773
1774 exit:
1775 /* Cleanup for volume */
1776 path_cleanup(&volume);
1777
1778 return return_value;
1779 }
1780
1781 #endif /* defined(MS_WINDOWS) */
1782
1783 #if defined(MS_WINDOWS)
1784
1785 PyDoc_STRVAR(os__path_isdevdrive__doc__,
1786 "_path_isdevdrive($module, /, path)\n"
1787 "--\n"
1788 "\n"
1789 "Determines whether the specified path is on a Windows Dev Drive.");
1790
1791 #define OS__PATH_ISDEVDRIVE_METHODDEF \
1792 {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__},
1793
1794 static PyObject *
1795 os__path_isdevdrive_impl(PyObject *module, path_t *path);
1796
1797 static PyObject *
1798 os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1799 {
1800 PyObject *return_value = NULL;
1801 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1802
1803 #define NUM_KEYWORDS 1
1804 static struct {
1805 PyGC_Head _this_is_not_used;
1806 PyObject_VAR_HEAD
1807 Py_hash_t ob_hash;
1808 PyObject *ob_item[NUM_KEYWORDS];
1809 } _kwtuple = {
1810 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1811 .ob_hash = -1,
1812 .ob_item = { &_Py_ID(path), },
1813 };
1814 #undef NUM_KEYWORDS
1815 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1816
1817 #else // !Py_BUILD_CORE
1818 # define KWTUPLE NULL
1819 #endif // !Py_BUILD_CORE
1820
1821 static const char * const _keywords[] = {"path", NULL};
1822 static _PyArg_Parser _parser = {
1823 .keywords = _keywords,
1824 .fname = "_path_isdevdrive",
1825 .kwtuple = KWTUPLE,
1826 };
1827 #undef KWTUPLE
1828 PyObject *argsbuf[1];
1829 path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
1830
1831 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1832 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1833 if (!args) {
1834 goto exit;
1835 }
1836 if (!path_converter(args[0], &path)) {
1837 goto exit;
1838 }
1839 return_value = os__path_isdevdrive_impl(module, &path);
1840
1841 exit:
1842 /* Cleanup for path */
1843 path_cleanup(&path);
1844
1845 return return_value;
1846 }
1847
1848 #endif /* defined(MS_WINDOWS) */
1849
1850 #if defined(MS_WINDOWS)
1851
1852 PyDoc_STRVAR(os__getfullpathname__doc__,
1853 "_getfullpathname($module, path, /)\n"
1854 "--\n"
1855 "\n");
1856
1857 #define OS__GETFULLPATHNAME_METHODDEF \
1858 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
1859
1860 static PyObject *
1861 os__getfullpathname_impl(PyObject *module, path_t *path);
1862
1863 static PyObject *
1864 os__getfullpathname(PyObject *module, PyObject *arg)
1865 {
1866 PyObject *return_value = NULL;
1867 path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
1868
1869 if (!path_converter(arg, &path)) {
1870 goto exit;
1871 }
1872 return_value = os__getfullpathname_impl(module, &path);
1873
1874 exit:
1875 /* Cleanup for path */
1876 path_cleanup(&path);
1877
1878 return return_value;
1879 }
1880
1881 #endif /* defined(MS_WINDOWS) */
1882
1883 #if defined(MS_WINDOWS)
1884
1885 PyDoc_STRVAR(os__getfinalpathname__doc__,
1886 "_getfinalpathname($module, path, /)\n"
1887 "--\n"
1888 "\n"
1889 "A helper function for samepath on windows.");
1890
1891 #define OS__GETFINALPATHNAME_METHODDEF \
1892 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
1893
1894 static PyObject *
1895 os__getfinalpathname_impl(PyObject *module, path_t *path);
1896
1897 static PyObject *
1898 os__getfinalpathname(PyObject *module, PyObject *arg)
1899 {
1900 PyObject *return_value = NULL;
1901 path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
1902
1903 if (!path_converter(arg, &path)) {
1904 goto exit;
1905 }
1906 return_value = os__getfinalpathname_impl(module, &path);
1907
1908 exit:
1909 /* Cleanup for path */
1910 path_cleanup(&path);
1911
1912 return return_value;
1913 }
1914
1915 #endif /* defined(MS_WINDOWS) */
1916
1917 #if defined(MS_WINDOWS)
1918
1919 PyDoc_STRVAR(os__findfirstfile__doc__,
1920 "_findfirstfile($module, path, /)\n"
1921 "--\n"
1922 "\n"
1923 "A function to get the real file name without accessing the file in Windows.");
1924
1925 #define OS__FINDFIRSTFILE_METHODDEF \
1926 {"_findfirstfile", (PyCFunction)os__findfirstfile, METH_O, os__findfirstfile__doc__},
1927
1928 static PyObject *
1929 os__findfirstfile_impl(PyObject *module, path_t *path);
1930
1931 static PyObject *
1932 os__findfirstfile(PyObject *module, PyObject *arg)
1933 {
1934 PyObject *return_value = NULL;
1935 path_t path = PATH_T_INITIALIZE_P("_findfirstfile", "path", 0, 0, 0, 0);
1936
1937 if (!path_converter(arg, &path)) {
1938 goto exit;
1939 }
1940 return_value = os__findfirstfile_impl(module, &path);
1941
1942 exit:
1943 /* Cleanup for path */
1944 path_cleanup(&path);
1945
1946 return return_value;
1947 }
1948
1949 #endif /* defined(MS_WINDOWS) */
1950
1951 #if defined(MS_WINDOWS)
1952
1953 PyDoc_STRVAR(os__getvolumepathname__doc__,
1954 "_getvolumepathname($module, /, path)\n"
1955 "--\n"
1956 "\n"
1957 "A helper function for ismount on Win32.");
1958
1959 #define OS__GETVOLUMEPATHNAME_METHODDEF \
1960 {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
1961
1962 static PyObject *
1963 os__getvolumepathname_impl(PyObject *module, path_t *path);
1964
1965 static PyObject *
1966 os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1967 {
1968 PyObject *return_value = NULL;
1969 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1970
1971 #define NUM_KEYWORDS 1
1972 static struct {
1973 PyGC_Head _this_is_not_used;
1974 PyObject_VAR_HEAD
1975 Py_hash_t ob_hash;
1976 PyObject *ob_item[NUM_KEYWORDS];
1977 } _kwtuple = {
1978 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1979 .ob_hash = -1,
1980 .ob_item = { &_Py_ID(path), },
1981 };
1982 #undef NUM_KEYWORDS
1983 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1984
1985 #else // !Py_BUILD_CORE
1986 # define KWTUPLE NULL
1987 #endif // !Py_BUILD_CORE
1988
1989 static const char * const _keywords[] = {"path", NULL};
1990 static _PyArg_Parser _parser = {
1991 .keywords = _keywords,
1992 .fname = "_getvolumepathname",
1993 .kwtuple = KWTUPLE,
1994 };
1995 #undef KWTUPLE
1996 PyObject *argsbuf[1];
1997 path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
1998
1999 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2000 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2001 if (!args) {
2002 goto exit;
2003 }
2004 if (!path_converter(args[0], &path)) {
2005 goto exit;
2006 }
2007 return_value = os__getvolumepathname_impl(module, &path);
2008
2009 exit:
2010 /* Cleanup for path */
2011 path_cleanup(&path);
2012
2013 return return_value;
2014 }
2015
2016 #endif /* defined(MS_WINDOWS) */
2017
2018 #if defined(MS_WINDOWS)
2019
2020 PyDoc_STRVAR(os__path_splitroot__doc__,
2021 "_path_splitroot($module, /, path)\n"
2022 "--\n"
2023 "\n"
2024 "Removes everything after the root on Win32.");
2025
2026 #define OS__PATH_SPLITROOT_METHODDEF \
2027 {"_path_splitroot", _PyCFunction_CAST(os__path_splitroot), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot__doc__},
2028
2029 static PyObject *
2030 os__path_splitroot_impl(PyObject *module, path_t *path);
2031
2032 static PyObject *
2033 os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2034 {
2035 PyObject *return_value = NULL;
2036 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2037
2038 #define NUM_KEYWORDS 1
2039 static struct {
2040 PyGC_Head _this_is_not_used;
2041 PyObject_VAR_HEAD
2042 Py_hash_t ob_hash;
2043 PyObject *ob_item[NUM_KEYWORDS];
2044 } _kwtuple = {
2045 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2046 .ob_hash = -1,
2047 .ob_item = { &_Py_ID(path), },
2048 };
2049 #undef NUM_KEYWORDS
2050 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2051
2052 #else // !Py_BUILD_CORE
2053 # define KWTUPLE NULL
2054 #endif // !Py_BUILD_CORE
2055
2056 static const char * const _keywords[] = {"path", NULL};
2057 static _PyArg_Parser _parser = {
2058 .keywords = _keywords,
2059 .fname = "_path_splitroot",
2060 .kwtuple = KWTUPLE,
2061 };
2062 #undef KWTUPLE
2063 PyObject *argsbuf[1];
2064 path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
2065
2066 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2067 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2068 if (!args) {
2069 goto exit;
2070 }
2071 if (!path_converter(args[0], &path)) {
2072 goto exit;
2073 }
2074 return_value = os__path_splitroot_impl(module, &path);
2075
2076 exit:
2077 /* Cleanup for path */
2078 path_cleanup(&path);
2079
2080 return return_value;
2081 }
2082
2083 #endif /* defined(MS_WINDOWS) */
2084
2085 #if defined(MS_WINDOWS)
2086
2087 PyDoc_STRVAR(os__path_exists__doc__,
2088 "_path_exists($module, /, path)\n"
2089 "--\n"
2090 "\n"
2091 "Test whether a path exists. Returns False for broken symbolic links.");
2092
2093 #define OS__PATH_EXISTS_METHODDEF \
2094 {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__},
2095
2096 static int
2097 os__path_exists_impl(PyObject *module, path_t *path);
2098
2099 static PyObject *
2100 os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2101 {
2102 PyObject *return_value = NULL;
2103 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2104
2105 #define NUM_KEYWORDS 1
2106 static struct {
2107 PyGC_Head _this_is_not_used;
2108 PyObject_VAR_HEAD
2109 Py_hash_t ob_hash;
2110 PyObject *ob_item[NUM_KEYWORDS];
2111 } _kwtuple = {
2112 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2113 .ob_hash = -1,
2114 .ob_item = { &_Py_ID(path), },
2115 };
2116 #undef NUM_KEYWORDS
2117 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2118
2119 #else // !Py_BUILD_CORE
2120 # define KWTUPLE NULL
2121 #endif // !Py_BUILD_CORE
2122
2123 static const char * const _keywords[] = {"path", NULL};
2124 static _PyArg_Parser _parser = {
2125 .keywords = _keywords,
2126 .fname = "_path_exists",
2127 .kwtuple = KWTUPLE,
2128 };
2129 #undef KWTUPLE
2130 PyObject *argsbuf[1];
2131 path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
2132 int _return_value;
2133
2134 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2135 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2136 if (!args) {
2137 goto exit;
2138 }
2139 if (!path_converter(args[0], &path)) {
2140 goto exit;
2141 }
2142 _return_value = os__path_exists_impl(module, &path);
2143 if ((_return_value == -1) && PyErr_Occurred()) {
2144 goto exit;
2145 }
2146 return_value = PyBool_FromLong((long)_return_value);
2147
2148 exit:
2149 /* Cleanup for path */
2150 path_cleanup(&path);
2151
2152 return return_value;
2153 }
2154
2155 #endif /* defined(MS_WINDOWS) */
2156
2157 #if defined(MS_WINDOWS)
2158
2159 PyDoc_STRVAR(os__path_lexists__doc__,
2160 "_path_lexists($module, /, path)\n"
2161 "--\n"
2162 "\n"
2163 "Test whether a path exists. Returns True for broken symbolic links.");
2164
2165 #define OS__PATH_LEXISTS_METHODDEF \
2166 {"_path_lexists", _PyCFunction_CAST(os__path_lexists), METH_FASTCALL|METH_KEYWORDS, os__path_lexists__doc__},
2167
2168 static int
2169 os__path_lexists_impl(PyObject *module, path_t *path);
2170
2171 static PyObject *
2172 os__path_lexists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2173 {
2174 PyObject *return_value = NULL;
2175 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2176
2177 #define NUM_KEYWORDS 1
2178 static struct {
2179 PyGC_Head _this_is_not_used;
2180 PyObject_VAR_HEAD
2181 Py_hash_t ob_hash;
2182 PyObject *ob_item[NUM_KEYWORDS];
2183 } _kwtuple = {
2184 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2185 .ob_hash = -1,
2186 .ob_item = { &_Py_ID(path), },
2187 };
2188 #undef NUM_KEYWORDS
2189 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2190
2191 #else // !Py_BUILD_CORE
2192 # define KWTUPLE NULL
2193 #endif // !Py_BUILD_CORE
2194
2195 static const char * const _keywords[] = {"path", NULL};
2196 static _PyArg_Parser _parser = {
2197 .keywords = _keywords,
2198 .fname = "_path_lexists",
2199 .kwtuple = KWTUPLE,
2200 };
2201 #undef KWTUPLE
2202 PyObject *argsbuf[1];
2203 path_t path = PATH_T_INITIALIZE_P("_path_lexists", "path", 0, 0, 1, 1);
2204 int _return_value;
2205
2206 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2207 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2208 if (!args) {
2209 goto exit;
2210 }
2211 if (!path_converter(args[0], &path)) {
2212 goto exit;
2213 }
2214 _return_value = os__path_lexists_impl(module, &path);
2215 if ((_return_value == -1) && PyErr_Occurred()) {
2216 goto exit;
2217 }
2218 return_value = PyBool_FromLong((long)_return_value);
2219
2220 exit:
2221 /* Cleanup for path */
2222 path_cleanup(&path);
2223
2224 return return_value;
2225 }
2226
2227 #endif /* defined(MS_WINDOWS) */
2228
2229 #if defined(MS_WINDOWS)
2230
2231 PyDoc_STRVAR(os__path_isdir__doc__,
2232 "_path_isdir($module, /, s)\n"
2233 "--\n"
2234 "\n"
2235 "Return true if the pathname refers to an existing directory.");
2236
2237 #define OS__PATH_ISDIR_METHODDEF \
2238 {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__},
2239
2240 static int
2241 os__path_isdir_impl(PyObject *module, path_t *path);
2242
2243 static PyObject *
2244 os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2245 {
2246 PyObject *return_value = NULL;
2247 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2248
2249 #define NUM_KEYWORDS 1
2250 static struct {
2251 PyGC_Head _this_is_not_used;
2252 PyObject_VAR_HEAD
2253 Py_hash_t ob_hash;
2254 PyObject *ob_item[NUM_KEYWORDS];
2255 } _kwtuple = {
2256 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2257 .ob_hash = -1,
2258 .ob_item = { _Py_LATIN1_CHR('s'), },
2259 };
2260 #undef NUM_KEYWORDS
2261 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2262
2263 #else // !Py_BUILD_CORE
2264 # define KWTUPLE NULL
2265 #endif // !Py_BUILD_CORE
2266
2267 static const char * const _keywords[] = {"s", NULL};
2268 static _PyArg_Parser _parser = {
2269 .keywords = _keywords,
2270 .fname = "_path_isdir",
2271 .kwtuple = KWTUPLE,
2272 };
2273 #undef KWTUPLE
2274 PyObject *argsbuf[1];
2275 path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
2276 int _return_value;
2277
2278 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2279 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2280 if (!args) {
2281 goto exit;
2282 }
2283 if (!path_converter(args[0], &path)) {
2284 goto exit;
2285 }
2286 _return_value = os__path_isdir_impl(module, &path);
2287 if ((_return_value == -1) && PyErr_Occurred()) {
2288 goto exit;
2289 }
2290 return_value = PyBool_FromLong((long)_return_value);
2291
2292 exit:
2293 /* Cleanup for path */
2294 path_cleanup(&path);
2295
2296 return return_value;
2297 }
2298
2299 #endif /* defined(MS_WINDOWS) */
2300
2301 #if defined(MS_WINDOWS)
2302
2303 PyDoc_STRVAR(os__path_isfile__doc__,
2304 "_path_isfile($module, /, path)\n"
2305 "--\n"
2306 "\n"
2307 "Test whether a path is a regular file");
2308
2309 #define OS__PATH_ISFILE_METHODDEF \
2310 {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
2311
2312 static int
2313 os__path_isfile_impl(PyObject *module, path_t *path);
2314
2315 static PyObject *
2316 os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2317 {
2318 PyObject *return_value = NULL;
2319 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2320
2321 #define NUM_KEYWORDS 1
2322 static struct {
2323 PyGC_Head _this_is_not_used;
2324 PyObject_VAR_HEAD
2325 Py_hash_t ob_hash;
2326 PyObject *ob_item[NUM_KEYWORDS];
2327 } _kwtuple = {
2328 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2329 .ob_hash = -1,
2330 .ob_item = { &_Py_ID(path), },
2331 };
2332 #undef NUM_KEYWORDS
2333 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2334
2335 #else // !Py_BUILD_CORE
2336 # define KWTUPLE NULL
2337 #endif // !Py_BUILD_CORE
2338
2339 static const char * const _keywords[] = {"path", NULL};
2340 static _PyArg_Parser _parser = {
2341 .keywords = _keywords,
2342 .fname = "_path_isfile",
2343 .kwtuple = KWTUPLE,
2344 };
2345 #undef KWTUPLE
2346 PyObject *argsbuf[1];
2347 path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
2348 int _return_value;
2349
2350 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2351 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2352 if (!args) {
2353 goto exit;
2354 }
2355 if (!path_converter(args[0], &path)) {
2356 goto exit;
2357 }
2358 _return_value = os__path_isfile_impl(module, &path);
2359 if ((_return_value == -1) && PyErr_Occurred()) {
2360 goto exit;
2361 }
2362 return_value = PyBool_FromLong((long)_return_value);
2363
2364 exit:
2365 /* Cleanup for path */
2366 path_cleanup(&path);
2367
2368 return return_value;
2369 }
2370
2371 #endif /* defined(MS_WINDOWS) */
2372
2373 #if defined(MS_WINDOWS)
2374
2375 PyDoc_STRVAR(os__path_islink__doc__,
2376 "_path_islink($module, /, path)\n"
2377 "--\n"
2378 "\n"
2379 "Test whether a path is a symbolic link");
2380
2381 #define OS__PATH_ISLINK_METHODDEF \
2382 {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
2383
2384 static int
2385 os__path_islink_impl(PyObject *module, path_t *path);
2386
2387 static PyObject *
2388 os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2389 {
2390 PyObject *return_value = NULL;
2391 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2392
2393 #define NUM_KEYWORDS 1
2394 static struct {
2395 PyGC_Head _this_is_not_used;
2396 PyObject_VAR_HEAD
2397 Py_hash_t ob_hash;
2398 PyObject *ob_item[NUM_KEYWORDS];
2399 } _kwtuple = {
2400 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2401 .ob_hash = -1,
2402 .ob_item = { &_Py_ID(path), },
2403 };
2404 #undef NUM_KEYWORDS
2405 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2406
2407 #else // !Py_BUILD_CORE
2408 # define KWTUPLE NULL
2409 #endif // !Py_BUILD_CORE
2410
2411 static const char * const _keywords[] = {"path", NULL};
2412 static _PyArg_Parser _parser = {
2413 .keywords = _keywords,
2414 .fname = "_path_islink",
2415 .kwtuple = KWTUPLE,
2416 };
2417 #undef KWTUPLE
2418 PyObject *argsbuf[1];
2419 path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
2420 int _return_value;
2421
2422 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2423 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2424 if (!args) {
2425 goto exit;
2426 }
2427 if (!path_converter(args[0], &path)) {
2428 goto exit;
2429 }
2430 _return_value = os__path_islink_impl(module, &path);
2431 if ((_return_value == -1) && PyErr_Occurred()) {
2432 goto exit;
2433 }
2434 return_value = PyBool_FromLong((long)_return_value);
2435
2436 exit:
2437 /* Cleanup for path */
2438 path_cleanup(&path);
2439
2440 return return_value;
2441 }
2442
2443 #endif /* defined(MS_WINDOWS) */
2444
2445 #if defined(MS_WINDOWS)
2446
2447 PyDoc_STRVAR(os__path_isjunction__doc__,
2448 "_path_isjunction($module, /, path)\n"
2449 "--\n"
2450 "\n"
2451 "Test whether a path is a junction");
2452
2453 #define OS__PATH_ISJUNCTION_METHODDEF \
2454 {"_path_isjunction", _PyCFunction_CAST(os__path_isjunction), METH_FASTCALL|METH_KEYWORDS, os__path_isjunction__doc__},
2455
2456 static int
2457 os__path_isjunction_impl(PyObject *module, path_t *path);
2458
2459 static PyObject *
2460 os__path_isjunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2461 {
2462 PyObject *return_value = NULL;
2463 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2464
2465 #define NUM_KEYWORDS 1
2466 static struct {
2467 PyGC_Head _this_is_not_used;
2468 PyObject_VAR_HEAD
2469 Py_hash_t ob_hash;
2470 PyObject *ob_item[NUM_KEYWORDS];
2471 } _kwtuple = {
2472 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2473 .ob_hash = -1,
2474 .ob_item = { &_Py_ID(path), },
2475 };
2476 #undef NUM_KEYWORDS
2477 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2478
2479 #else // !Py_BUILD_CORE
2480 # define KWTUPLE NULL
2481 #endif // !Py_BUILD_CORE
2482
2483 static const char * const _keywords[] = {"path", NULL};
2484 static _PyArg_Parser _parser = {
2485 .keywords = _keywords,
2486 .fname = "_path_isjunction",
2487 .kwtuple = KWTUPLE,
2488 };
2489 #undef KWTUPLE
2490 PyObject *argsbuf[1];
2491 path_t path = PATH_T_INITIALIZE_P("_path_isjunction", "path", 0, 0, 1, 1);
2492 int _return_value;
2493
2494 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2495 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2496 if (!args) {
2497 goto exit;
2498 }
2499 if (!path_converter(args[0], &path)) {
2500 goto exit;
2501 }
2502 _return_value = os__path_isjunction_impl(module, &path);
2503 if ((_return_value == -1) && PyErr_Occurred()) {
2504 goto exit;
2505 }
2506 return_value = PyBool_FromLong((long)_return_value);
2507
2508 exit:
2509 /* Cleanup for path */
2510 path_cleanup(&path);
2511
2512 return return_value;
2513 }
2514
2515 #endif /* defined(MS_WINDOWS) */
2516
2517 PyDoc_STRVAR(os__path_splitroot_ex__doc__,
2518 "_path_splitroot_ex($module, /, p)\n"
2519 "--\n"
2520 "\n"
2521 "Split a pathname into drive, root and tail.\n"
2522 "\n"
2523 "The tail contains anything after the root.");
2524
2525 #define OS__PATH_SPLITROOT_EX_METHODDEF \
2526 {"_path_splitroot_ex", _PyCFunction_CAST(os__path_splitroot_ex), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot_ex__doc__},
2527
2528 static PyObject *
2529 os__path_splitroot_ex_impl(PyObject *module, path_t *path);
2530
2531 static PyObject *
2532 os__path_splitroot_ex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2533 {
2534 PyObject *return_value = NULL;
2535 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2536
2537 #define NUM_KEYWORDS 1
2538 static struct {
2539 PyGC_Head _this_is_not_used;
2540 PyObject_VAR_HEAD
2541 Py_hash_t ob_hash;
2542 PyObject *ob_item[NUM_KEYWORDS];
2543 } _kwtuple = {
2544 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2545 .ob_hash = -1,
2546 .ob_item = { _Py_LATIN1_CHR('p'), },
2547 };
2548 #undef NUM_KEYWORDS
2549 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2550
2551 #else // !Py_BUILD_CORE
2552 # define KWTUPLE NULL
2553 #endif // !Py_BUILD_CORE
2554
2555 static const char * const _keywords[] = {"p", NULL};
2556 static _PyArg_Parser _parser = {
2557 .keywords = _keywords,
2558 .fname = "_path_splitroot_ex",
2559 .kwtuple = KWTUPLE,
2560 };
2561 #undef KWTUPLE
2562 PyObject *argsbuf[1];
2563 path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0);
2564
2565 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2566 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2567 if (!args) {
2568 goto exit;
2569 }
2570 if (!path_converter(args[0], &path)) {
2571 goto exit;
2572 }
2573 return_value = os__path_splitroot_ex_impl(module, &path);
2574
2575 exit:
2576 /* Cleanup for path */
2577 path_cleanup(&path);
2578
2579 return return_value;
2580 }
2581
2582 PyDoc_STRVAR(os__path_normpath__doc__,
2583 "_path_normpath($module, /, path)\n"
2584 "--\n"
2585 "\n"
2586 "Normalize path, eliminating double slashes, etc.");
2587
2588 #define OS__PATH_NORMPATH_METHODDEF \
2589 {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
2590
2591 static PyObject *
2592 os__path_normpath_impl(PyObject *module, path_t *path);
2593
2594 static PyObject *
2595 os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2596 {
2597 PyObject *return_value = NULL;
2598 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2599
2600 #define NUM_KEYWORDS 1
2601 static struct {
2602 PyGC_Head _this_is_not_used;
2603 PyObject_VAR_HEAD
2604 Py_hash_t ob_hash;
2605 PyObject *ob_item[NUM_KEYWORDS];
2606 } _kwtuple = {
2607 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2608 .ob_hash = -1,
2609 .ob_item = { &_Py_ID(path), },
2610 };
2611 #undef NUM_KEYWORDS
2612 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2613
2614 #else // !Py_BUILD_CORE
2615 # define KWTUPLE NULL
2616 #endif // !Py_BUILD_CORE
2617
2618 static const char * const _keywords[] = {"path", NULL};
2619 static _PyArg_Parser _parser = {
2620 .keywords = _keywords,
2621 .fname = "_path_normpath",
2622 .kwtuple = KWTUPLE,
2623 };
2624 #undef KWTUPLE
2625 PyObject *argsbuf[1];
2626 path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
2627
2628 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2629 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2630 if (!args) {
2631 goto exit;
2632 }
2633 if (!path_converter(args[0], &path)) {
2634 goto exit;
2635 }
2636 return_value = os__path_normpath_impl(module, &path);
2637
2638 exit:
2639 /* Cleanup for path */
2640 path_cleanup(&path);
2641
2642 return return_value;
2643 }
2644
2645 PyDoc_STRVAR(os_mkdir__doc__,
2646 "mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
2647 "--\n"
2648 "\n"
2649 "Create a directory.\n"
2650 "\n"
2651 "If dir_fd is not None, it should be a file descriptor open to\n"
2652 "a directory, and path should be relative; path will then be relative to\n"
2653 "that directory.\n"
2654 "dir_fd may not be implemented on your platform. If it is unavailable,\n"
2655 "using it will raise a NotImplementedError.\n"
2656 "\n"
2657 "The mode argument is ignored on Windows. Where it is used, the current\n"
2658 "umask value is first masked out.");
2659
2660 #define OS_MKDIR_METHODDEF \
2661 {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
2662
2663 static PyObject *
2664 os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
2665
2666 static PyObject *
2667 os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2668 {
2669 PyObject *return_value = NULL;
2670 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2671
2672 #define NUM_KEYWORDS 3
2673 static struct {
2674 PyGC_Head _this_is_not_used;
2675 PyObject_VAR_HEAD
2676 Py_hash_t ob_hash;
2677 PyObject *ob_item[NUM_KEYWORDS];
2678 } _kwtuple = {
2679 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2680 .ob_hash = -1,
2681 .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
2682 };
2683 #undef NUM_KEYWORDS
2684 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2685
2686 #else // !Py_BUILD_CORE
2687 # define KWTUPLE NULL
2688 #endif // !Py_BUILD_CORE
2689
2690 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
2691 static _PyArg_Parser _parser = {
2692 .keywords = _keywords,
2693 .fname = "mkdir",
2694 .kwtuple = KWTUPLE,
2695 };
2696 #undef KWTUPLE
2697 PyObject *argsbuf[3];
2698 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2699 path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
2700 int mode = 511;
2701 int dir_fd = DEFAULT_DIR_FD;
2702
2703 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2704 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2705 if (!args) {
2706 goto exit;
2707 }
2708 if (!path_converter(args[0], &path)) {
2709 goto exit;
2710 }
2711 if (!noptargs) {
2712 goto skip_optional_pos;
2713 }
2714 if (args[1]) {
2715 mode = PyLong_AsInt(args[1]);
2716 if (mode == -1 && PyErr_Occurred()) {
2717 goto exit;
2718 }
2719 if (!--noptargs) {
2720 goto skip_optional_pos;
2721 }
2722 }
2723 skip_optional_pos:
2724 if (!noptargs) {
2725 goto skip_optional_kwonly;
2726 }
2727 if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
2728 goto exit;
2729 }
2730 skip_optional_kwonly:
2731 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
2732
2733 exit:
2734 /* Cleanup for path */
2735 path_cleanup(&path);
2736
2737 return return_value;
2738 }
2739
2740 #if defined(HAVE_NICE)
2741
2742 PyDoc_STRVAR(os_nice__doc__,
2743 "nice($module, increment, /)\n"
2744 "--\n"
2745 "\n"
2746 "Add increment to the priority of process and return the new priority.");
2747
2748 #define OS_NICE_METHODDEF \
2749 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
2750
2751 static PyObject *
2752 os_nice_impl(PyObject *module, int increment);
2753
2754 static PyObject *
2755 os_nice(PyObject *module, PyObject *arg)
2756 {
2757 PyObject *return_value = NULL;
2758 int increment;
2759
2760 increment = PyLong_AsInt(arg);
2761 if (increment == -1 && PyErr_Occurred()) {
2762 goto exit;
2763 }
2764 return_value = os_nice_impl(module, increment);
2765
2766 exit:
2767 return return_value;
2768 }
2769
2770 #endif /* defined(HAVE_NICE) */
2771
2772 #if defined(HAVE_GETPRIORITY)
2773
2774 PyDoc_STRVAR(os_getpriority__doc__,
2775 "getpriority($module, /, which, who)\n"
2776 "--\n"
2777 "\n"
2778 "Return program scheduling priority.");
2779
2780 #define OS_GETPRIORITY_METHODDEF \
2781 {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
2782
2783 static PyObject *
2784 os_getpriority_impl(PyObject *module, int which, int who);
2785
2786 static PyObject *
2787 os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2788 {
2789 PyObject *return_value = NULL;
2790 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2791
2792 #define NUM_KEYWORDS 2
2793 static struct {
2794 PyGC_Head _this_is_not_used;
2795 PyObject_VAR_HEAD
2796 Py_hash_t ob_hash;
2797 PyObject *ob_item[NUM_KEYWORDS];
2798 } _kwtuple = {
2799 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2800 .ob_hash = -1,
2801 .ob_item = { &_Py_ID(which), &_Py_ID(who), },
2802 };
2803 #undef NUM_KEYWORDS
2804 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2805
2806 #else // !Py_BUILD_CORE
2807 # define KWTUPLE NULL
2808 #endif // !Py_BUILD_CORE
2809
2810 static const char * const _keywords[] = {"which", "who", NULL};
2811 static _PyArg_Parser _parser = {
2812 .keywords = _keywords,
2813 .fname = "getpriority",
2814 .kwtuple = KWTUPLE,
2815 };
2816 #undef KWTUPLE
2817 PyObject *argsbuf[2];
2818 int which;
2819 int who;
2820
2821 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2822 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2823 if (!args) {
2824 goto exit;
2825 }
2826 which = PyLong_AsInt(args[0]);
2827 if (which == -1 && PyErr_Occurred()) {
2828 goto exit;
2829 }
2830 who = PyLong_AsInt(args[1]);
2831 if (who == -1 && PyErr_Occurred()) {
2832 goto exit;
2833 }
2834 return_value = os_getpriority_impl(module, which, who);
2835
2836 exit:
2837 return return_value;
2838 }
2839
2840 #endif /* defined(HAVE_GETPRIORITY) */
2841
2842 #if defined(HAVE_SETPRIORITY)
2843
2844 PyDoc_STRVAR(os_setpriority__doc__,
2845 "setpriority($module, /, which, who, priority)\n"
2846 "--\n"
2847 "\n"
2848 "Set program scheduling priority.");
2849
2850 #define OS_SETPRIORITY_METHODDEF \
2851 {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
2852
2853 static PyObject *
2854 os_setpriority_impl(PyObject *module, int which, int who, int priority);
2855
2856 static PyObject *
2857 os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2858 {
2859 PyObject *return_value = NULL;
2860 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2861
2862 #define NUM_KEYWORDS 3
2863 static struct {
2864 PyGC_Head _this_is_not_used;
2865 PyObject_VAR_HEAD
2866 Py_hash_t ob_hash;
2867 PyObject *ob_item[NUM_KEYWORDS];
2868 } _kwtuple = {
2869 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2870 .ob_hash = -1,
2871 .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
2872 };
2873 #undef NUM_KEYWORDS
2874 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2875
2876 #else // !Py_BUILD_CORE
2877 # define KWTUPLE NULL
2878 #endif // !Py_BUILD_CORE
2879
2880 static const char * const _keywords[] = {"which", "who", "priority", NULL};
2881 static _PyArg_Parser _parser = {
2882 .keywords = _keywords,
2883 .fname = "setpriority",
2884 .kwtuple = KWTUPLE,
2885 };
2886 #undef KWTUPLE
2887 PyObject *argsbuf[3];
2888 int which;
2889 int who;
2890 int priority;
2891
2892 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2893 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2894 if (!args) {
2895 goto exit;
2896 }
2897 which = PyLong_AsInt(args[0]);
2898 if (which == -1 && PyErr_Occurred()) {
2899 goto exit;
2900 }
2901 who = PyLong_AsInt(args[1]);
2902 if (who == -1 && PyErr_Occurred()) {
2903 goto exit;
2904 }
2905 priority = PyLong_AsInt(args[2]);
2906 if (priority == -1 && PyErr_Occurred()) {
2907 goto exit;
2908 }
2909 return_value = os_setpriority_impl(module, which, who, priority);
2910
2911 exit:
2912 return return_value;
2913 }
2914
2915 #endif /* defined(HAVE_SETPRIORITY) */
2916
2917 PyDoc_STRVAR(os_rename__doc__,
2918 "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2919 "--\n"
2920 "\n"
2921 "Rename a file or directory.\n"
2922 "\n"
2923 "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2924 "descriptor open to a directory, and the respective path string (src or\n"
2925 "dst) should be relative; the path will then be relative to that\n"
2926 "directory.\n"
2927 "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2928 "If they are unavailable, using them will raise a NotImplementedError.");
2929
2930 #define OS_RENAME_METHODDEF \
2931 {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
2932
2933 static PyObject *
2934 os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2935 int dst_dir_fd);
2936
2937 static PyObject *
2938 os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2939 {
2940 PyObject *return_value = NULL;
2941 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2942
2943 #define NUM_KEYWORDS 4
2944 static struct {
2945 PyGC_Head _this_is_not_used;
2946 PyObject_VAR_HEAD
2947 Py_hash_t ob_hash;
2948 PyObject *ob_item[NUM_KEYWORDS];
2949 } _kwtuple = {
2950 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2951 .ob_hash = -1,
2952 .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
2953 };
2954 #undef NUM_KEYWORDS
2955 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2956
2957 #else // !Py_BUILD_CORE
2958 # define KWTUPLE NULL
2959 #endif // !Py_BUILD_CORE
2960
2961 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
2962 static _PyArg_Parser _parser = {
2963 .keywords = _keywords,
2964 .fname = "rename",
2965 .kwtuple = KWTUPLE,
2966 };
2967 #undef KWTUPLE
2968 PyObject *argsbuf[4];
2969 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
2970 path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
2971 path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
2972 int src_dir_fd = DEFAULT_DIR_FD;
2973 int dst_dir_fd = DEFAULT_DIR_FD;
2974
2975 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
2976 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
2977 if (!args) {
2978 goto exit;
2979 }
2980 if (!path_converter(args[0], &src)) {
2981 goto exit;
2982 }
2983 if (!path_converter(args[1], &dst)) {
2984 goto exit;
2985 }
2986 if (!noptargs) {
2987 goto skip_optional_kwonly;
2988 }
2989 if (args[2]) {
2990 if (!dir_fd_converter(args[2], &src_dir_fd)) {
2991 goto exit;
2992 }
2993 if (!--noptargs) {
2994 goto skip_optional_kwonly;
2995 }
2996 }
2997 if (!dir_fd_converter(args[3], &dst_dir_fd)) {
2998 goto exit;
2999 }
3000 skip_optional_kwonly:
3001 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3002
3003 exit:
3004 /* Cleanup for src */
3005 path_cleanup(&src);
3006 /* Cleanup for dst */
3007 path_cleanup(&dst);
3008
3009 return return_value;
3010 }
3011
3012 PyDoc_STRVAR(os_replace__doc__,
3013 "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
3014 "--\n"
3015 "\n"
3016 "Rename a file or directory, overwriting the destination.\n"
3017 "\n"
3018 "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
3019 "descriptor open to a directory, and the respective path string (src or\n"
3020 "dst) should be relative; the path will then be relative to that\n"
3021 "directory.\n"
3022 "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
3023 "If they are unavailable, using them will raise a NotImplementedError.");
3024
3025 #define OS_REPLACE_METHODDEF \
3026 {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
3027
3028 static PyObject *
3029 os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
3030 int dst_dir_fd);
3031
3032 static PyObject *
3033 os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3034 {
3035 PyObject *return_value = NULL;
3036 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3037
3038 #define NUM_KEYWORDS 4
3039 static struct {
3040 PyGC_Head _this_is_not_used;
3041 PyObject_VAR_HEAD
3042 Py_hash_t ob_hash;
3043 PyObject *ob_item[NUM_KEYWORDS];
3044 } _kwtuple = {
3045 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3046 .ob_hash = -1,
3047 .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
3048 };
3049 #undef NUM_KEYWORDS
3050 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3051
3052 #else // !Py_BUILD_CORE
3053 # define KWTUPLE NULL
3054 #endif // !Py_BUILD_CORE
3055
3056 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
3057 static _PyArg_Parser _parser = {
3058 .keywords = _keywords,
3059 .fname = "replace",
3060 .kwtuple = KWTUPLE,
3061 };
3062 #undef KWTUPLE
3063 PyObject *argsbuf[4];
3064 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
3065 path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
3066 path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
3067 int src_dir_fd = DEFAULT_DIR_FD;
3068 int dst_dir_fd = DEFAULT_DIR_FD;
3069
3070 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3071 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3072 if (!args) {
3073 goto exit;
3074 }
3075 if (!path_converter(args[0], &src)) {
3076 goto exit;
3077 }
3078 if (!path_converter(args[1], &dst)) {
3079 goto exit;
3080 }
3081 if (!noptargs) {
3082 goto skip_optional_kwonly;
3083 }
3084 if (args[2]) {
3085 if (!dir_fd_converter(args[2], &src_dir_fd)) {
3086 goto exit;
3087 }
3088 if (!--noptargs) {
3089 goto skip_optional_kwonly;
3090 }
3091 }
3092 if (!dir_fd_converter(args[3], &dst_dir_fd)) {
3093 goto exit;
3094 }
3095 skip_optional_kwonly:
3096 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
3097
3098 exit:
3099 /* Cleanup for src */
3100 path_cleanup(&src);
3101 /* Cleanup for dst */
3102 path_cleanup(&dst);
3103
3104 return return_value;
3105 }
3106
3107 PyDoc_STRVAR(os_rmdir__doc__,
3108 "rmdir($module, /, path, *, dir_fd=None)\n"
3109 "--\n"
3110 "\n"
3111 "Remove a directory.\n"
3112 "\n"
3113 "If dir_fd is not None, it should be a file descriptor open to\n"
3114 "a directory, and path should be relative; path will then be relative\n"
3115 "to that directory.\n"
3116 "dir_fd may not be implemented on your platform.\n"
3117 "If it is unavailable, using it will raise a NotImplementedError.");
3118
3119 #define OS_RMDIR_METHODDEF \
3120 {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
3121
3122 static PyObject *
3123 os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
3124
3125 static PyObject *
3126 os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3127 {
3128 PyObject *return_value = NULL;
3129 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3130
3131 #define NUM_KEYWORDS 2
3132 static struct {
3133 PyGC_Head _this_is_not_used;
3134 PyObject_VAR_HEAD
3135 Py_hash_t ob_hash;
3136 PyObject *ob_item[NUM_KEYWORDS];
3137 } _kwtuple = {
3138 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3139 .ob_hash = -1,
3140 .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3141 };
3142 #undef NUM_KEYWORDS
3143 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3144
3145 #else // !Py_BUILD_CORE
3146 # define KWTUPLE NULL
3147 #endif // !Py_BUILD_CORE
3148
3149 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3150 static _PyArg_Parser _parser = {
3151 .keywords = _keywords,
3152 .fname = "rmdir",
3153 .kwtuple = KWTUPLE,
3154 };
3155 #undef KWTUPLE
3156 PyObject *argsbuf[2];
3157 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3158 path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
3159 int dir_fd = DEFAULT_DIR_FD;
3160
3161 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3162 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3163 if (!args) {
3164 goto exit;
3165 }
3166 if (!path_converter(args[0], &path)) {
3167 goto exit;
3168 }
3169 if (!noptargs) {
3170 goto skip_optional_kwonly;
3171 }
3172 if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3173 goto exit;
3174 }
3175 skip_optional_kwonly:
3176 return_value = os_rmdir_impl(module, &path, dir_fd);
3177
3178 exit:
3179 /* Cleanup for path */
3180 path_cleanup(&path);
3181
3182 return return_value;
3183 }
3184
3185 #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
3186
3187 PyDoc_STRVAR(os_system__doc__,
3188 "system($module, /, command)\n"
3189 "--\n"
3190 "\n"
3191 "Execute the command in a subshell.");
3192
3193 #define OS_SYSTEM_METHODDEF \
3194 {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3195
3196 static long
3197 os_system_impl(PyObject *module, const wchar_t *command);
3198
3199 static PyObject *
3200 os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3201 {
3202 PyObject *return_value = NULL;
3203 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3204
3205 #define NUM_KEYWORDS 1
3206 static struct {
3207 PyGC_Head _this_is_not_used;
3208 PyObject_VAR_HEAD
3209 Py_hash_t ob_hash;
3210 PyObject *ob_item[NUM_KEYWORDS];
3211 } _kwtuple = {
3212 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3213 .ob_hash = -1,
3214 .ob_item = { &_Py_ID(command), },
3215 };
3216 #undef NUM_KEYWORDS
3217 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3218
3219 #else // !Py_BUILD_CORE
3220 # define KWTUPLE NULL
3221 #endif // !Py_BUILD_CORE
3222
3223 static const char * const _keywords[] = {"command", NULL};
3224 static _PyArg_Parser _parser = {
3225 .keywords = _keywords,
3226 .fname = "system",
3227 .kwtuple = KWTUPLE,
3228 };
3229 #undef KWTUPLE
3230 PyObject *argsbuf[1];
3231 const wchar_t *command = NULL;
3232 long _return_value;
3233
3234 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3235 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3236 if (!args) {
3237 goto exit;
3238 }
3239 if (!PyUnicode_Check(args[0])) {
3240 _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
3241 goto exit;
3242 }
3243 command = PyUnicode_AsWideCharString(args[0], NULL);
3244 if (command == NULL) {
3245 goto exit;
3246 }
3247 _return_value = os_system_impl(module, command);
3248 if ((_return_value == -1) && PyErr_Occurred()) {
3249 goto exit;
3250 }
3251 return_value = PyLong_FromLong(_return_value);
3252
3253 exit:
3254 /* Cleanup for command */
3255 PyMem_Free((void *)command);
3256
3257 return return_value;
3258 }
3259
3260 #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
3261
3262 #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
3263
3264 PyDoc_STRVAR(os_system__doc__,
3265 "system($module, /, command)\n"
3266 "--\n"
3267 "\n"
3268 "Execute the command in a subshell.");
3269
3270 #define OS_SYSTEM_METHODDEF \
3271 {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
3272
3273 static long
3274 os_system_impl(PyObject *module, PyObject *command);
3275
3276 static PyObject *
3277 os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3278 {
3279 PyObject *return_value = NULL;
3280 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3281
3282 #define NUM_KEYWORDS 1
3283 static struct {
3284 PyGC_Head _this_is_not_used;
3285 PyObject_VAR_HEAD
3286 Py_hash_t ob_hash;
3287 PyObject *ob_item[NUM_KEYWORDS];
3288 } _kwtuple = {
3289 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3290 .ob_hash = -1,
3291 .ob_item = { &_Py_ID(command), },
3292 };
3293 #undef NUM_KEYWORDS
3294 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3295
3296 #else // !Py_BUILD_CORE
3297 # define KWTUPLE NULL
3298 #endif // !Py_BUILD_CORE
3299
3300 static const char * const _keywords[] = {"command", NULL};
3301 static _PyArg_Parser _parser = {
3302 .keywords = _keywords,
3303 .fname = "system",
3304 .kwtuple = KWTUPLE,
3305 };
3306 #undef KWTUPLE
3307 PyObject *argsbuf[1];
3308 PyObject *command = NULL;
3309 long _return_value;
3310
3311 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3312 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3313 if (!args) {
3314 goto exit;
3315 }
3316 if (!PyUnicode_FSConverter(args[0], &command)) {
3317 goto exit;
3318 }
3319 _return_value = os_system_impl(module, command);
3320 if ((_return_value == -1) && PyErr_Occurred()) {
3321 goto exit;
3322 }
3323 return_value = PyLong_FromLong(_return_value);
3324
3325 exit:
3326 /* Cleanup for command */
3327 Py_XDECREF(command);
3328
3329 return return_value;
3330 }
3331
3332 #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
3333
3334 #if defined(HAVE_UMASK)
3335
3336 PyDoc_STRVAR(os_umask__doc__,
3337 "umask($module, mask, /)\n"
3338 "--\n"
3339 "\n"
3340 "Set the current numeric umask and return the previous umask.");
3341
3342 #define OS_UMASK_METHODDEF \
3343 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
3344
3345 static PyObject *
3346 os_umask_impl(PyObject *module, int mask);
3347
3348 static PyObject *
3349 os_umask(PyObject *module, PyObject *arg)
3350 {
3351 PyObject *return_value = NULL;
3352 int mask;
3353
3354 mask = PyLong_AsInt(arg);
3355 if (mask == -1 && PyErr_Occurred()) {
3356 goto exit;
3357 }
3358 return_value = os_umask_impl(module, mask);
3359
3360 exit:
3361 return return_value;
3362 }
3363
3364 #endif /* defined(HAVE_UMASK) */
3365
3366 PyDoc_STRVAR(os_unlink__doc__,
3367 "unlink($module, /, path, *, dir_fd=None)\n"
3368 "--\n"
3369 "\n"
3370 "Remove a file (same as remove()).\n"
3371 "\n"
3372 "If dir_fd is not None, it should be a file descriptor open to\n"
3373 "a directory, and path should be relative; path will then be relative to\n"
3374 "that directory.\n"
3375 "dir_fd may not be implemented on your platform.\n"
3376 "If it is unavailable, using it will raise a NotImplementedError.");
3377
3378 #define OS_UNLINK_METHODDEF \
3379 {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
3380
3381 static PyObject *
3382 os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
3383
3384 static PyObject *
3385 os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3386 {
3387 PyObject *return_value = NULL;
3388 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3389
3390 #define NUM_KEYWORDS 2
3391 static struct {
3392 PyGC_Head _this_is_not_used;
3393 PyObject_VAR_HEAD
3394 Py_hash_t ob_hash;
3395 PyObject *ob_item[NUM_KEYWORDS];
3396 } _kwtuple = {
3397 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3398 .ob_hash = -1,
3399 .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3400 };
3401 #undef NUM_KEYWORDS
3402 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3403
3404 #else // !Py_BUILD_CORE
3405 # define KWTUPLE NULL
3406 #endif // !Py_BUILD_CORE
3407
3408 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3409 static _PyArg_Parser _parser = {
3410 .keywords = _keywords,
3411 .fname = "unlink",
3412 .kwtuple = KWTUPLE,
3413 };
3414 #undef KWTUPLE
3415 PyObject *argsbuf[2];
3416 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3417 path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
3418 int dir_fd = DEFAULT_DIR_FD;
3419
3420 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3421 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3422 if (!args) {
3423 goto exit;
3424 }
3425 if (!path_converter(args[0], &path)) {
3426 goto exit;
3427 }
3428 if (!noptargs) {
3429 goto skip_optional_kwonly;
3430 }
3431 if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3432 goto exit;
3433 }
3434 skip_optional_kwonly:
3435 return_value = os_unlink_impl(module, &path, dir_fd);
3436
3437 exit:
3438 /* Cleanup for path */
3439 path_cleanup(&path);
3440
3441 return return_value;
3442 }
3443
3444 PyDoc_STRVAR(os_remove__doc__,
3445 "remove($module, /, path, *, dir_fd=None)\n"
3446 "--\n"
3447 "\n"
3448 "Remove a file (same as unlink()).\n"
3449 "\n"
3450 "If dir_fd is not None, it should be a file descriptor open to\n"
3451 "a directory, and path should be relative; path will then be relative\n"
3452 "to that directory.\n"
3453 "dir_fd may not be implemented on your platform.\n"
3454 "If it is unavailable, using it will raise a NotImplementedError.");
3455
3456 #define OS_REMOVE_METHODDEF \
3457 {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
3458
3459 static PyObject *
3460 os_remove_impl(PyObject *module, path_t *path, int dir_fd);
3461
3462 static PyObject *
3463 os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3464 {
3465 PyObject *return_value = NULL;
3466 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3467
3468 #define NUM_KEYWORDS 2
3469 static struct {
3470 PyGC_Head _this_is_not_used;
3471 PyObject_VAR_HEAD
3472 Py_hash_t ob_hash;
3473 PyObject *ob_item[NUM_KEYWORDS];
3474 } _kwtuple = {
3475 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3476 .ob_hash = -1,
3477 .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3478 };
3479 #undef NUM_KEYWORDS
3480 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3481
3482 #else // !Py_BUILD_CORE
3483 # define KWTUPLE NULL
3484 #endif // !Py_BUILD_CORE
3485
3486 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3487 static _PyArg_Parser _parser = {
3488 .keywords = _keywords,
3489 .fname = "remove",
3490 .kwtuple = KWTUPLE,
3491 };
3492 #undef KWTUPLE
3493 PyObject *argsbuf[2];
3494 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3495 path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
3496 int dir_fd = DEFAULT_DIR_FD;
3497
3498 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3499 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3500 if (!args) {
3501 goto exit;
3502 }
3503 if (!path_converter(args[0], &path)) {
3504 goto exit;
3505 }
3506 if (!noptargs) {
3507 goto skip_optional_kwonly;
3508 }
3509 if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3510 goto exit;
3511 }
3512 skip_optional_kwonly:
3513 return_value = os_remove_impl(module, &path, dir_fd);
3514
3515 exit:
3516 /* Cleanup for path */
3517 path_cleanup(&path);
3518
3519 return return_value;
3520 }
3521
3522 #if defined(HAVE_UNAME)
3523
3524 PyDoc_STRVAR(os_uname__doc__,
3525 "uname($module, /)\n"
3526 "--\n"
3527 "\n"
3528 "Return an object identifying the current operating system.\n"
3529 "\n"
3530 "The object behaves like a named tuple with the following fields:\n"
3531 " (sysname, nodename, release, version, machine)");
3532
3533 #define OS_UNAME_METHODDEF \
3534 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
3535
3536 static PyObject *
3537 os_uname_impl(PyObject *module);
3538
3539 static PyObject *
3540 os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
3541 {
3542 return os_uname_impl(module);
3543 }
3544
3545 #endif /* defined(HAVE_UNAME) */
3546
3547 PyDoc_STRVAR(os_utime__doc__,
3548 "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
3549 " dir_fd=None, follow_symlinks=True)\n"
3550 "--\n"
3551 "\n"
3552 "Set the access and modified time of path.\n"
3553 "\n"
3554 "path may always be specified as a string. On some platforms, path may\n"
3555 "also be specified as an open file descriptor. If this functionality is\n"
3556 "unavailable, using it raises an exception.\n"
3557 "\n"
3558 "If times is not None, it must be a tuple (atime, mtime);\n"
3559 "atime and mtime should be expressed as float seconds since the epoch.\n"
3560 "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
3561 "atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
3562 "since the epoch.\n"
3563 "If times is None and ns is unspecified, utime uses the current time.\n"
3564 "Specifying tuples for both times and ns is an error.\n"
3565 "\n"
3566 "If dir_fd is not None, it should be a file descriptor open to\n"
3567 "a directory, and path should be relative; path will then be relative to\n"
3568 "that directory.\n"
3569 "If follow_symlinks is False, and the last element of the path is\n"
3570 "a symbolic link, utime will modify the symbolic link itself instead of\n"
3571 "the file the link points to.\n"
3572 "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
3573 "an open file descriptor.\n"
3574 "dir_fd and follow_symlinks may not be available on your platform.\n"
3575 "If they are unavailable, using them will raise a NotImplementedError.");
3576
3577 #define OS_UTIME_METHODDEF \
3578 {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
3579
3580 static PyObject *
3581 os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
3582 int dir_fd, int follow_symlinks);
3583
3584 static PyObject *
3585 os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3586 {
3587 PyObject *return_value = NULL;
3588 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3589
3590 #define NUM_KEYWORDS 5
3591 static struct {
3592 PyGC_Head _this_is_not_used;
3593 PyObject_VAR_HEAD
3594 Py_hash_t ob_hash;
3595 PyObject *ob_item[NUM_KEYWORDS];
3596 } _kwtuple = {
3597 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3598 .ob_hash = -1,
3599 .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
3600 };
3601 #undef NUM_KEYWORDS
3602 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3603
3604 #else // !Py_BUILD_CORE
3605 # define KWTUPLE NULL
3606 #endif // !Py_BUILD_CORE
3607
3608 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
3609 static _PyArg_Parser _parser = {
3610 .keywords = _keywords,
3611 .fname = "utime",
3612 .kwtuple = KWTUPLE,
3613 };
3614 #undef KWTUPLE
3615 PyObject *argsbuf[5];
3616 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3617 path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
3618 PyObject *times = Py_None;
3619 PyObject *ns = NULL;
3620 int dir_fd = DEFAULT_DIR_FD;
3621 int follow_symlinks = 1;
3622
3623 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3624 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3625 if (!args) {
3626 goto exit;
3627 }
3628 if (!path_converter(args[0], &path)) {
3629 goto exit;
3630 }
3631 if (!noptargs) {
3632 goto skip_optional_pos;
3633 }
3634 if (args[1]) {
3635 times = args[1];
3636 if (!--noptargs) {
3637 goto skip_optional_pos;
3638 }
3639 }
3640 skip_optional_pos:
3641 if (!noptargs) {
3642 goto skip_optional_kwonly;
3643 }
3644 if (args[2]) {
3645 ns = args[2];
3646 if (!--noptargs) {
3647 goto skip_optional_kwonly;
3648 }
3649 }
3650 if (args[3]) {
3651 if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
3652 goto exit;
3653 }
3654 if (!--noptargs) {
3655 goto skip_optional_kwonly;
3656 }
3657 }
3658 follow_symlinks = PyObject_IsTrue(args[4]);
3659 if (follow_symlinks < 0) {
3660 goto exit;
3661 }
3662 skip_optional_kwonly:
3663 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
3664
3665 exit:
3666 /* Cleanup for path */
3667 path_cleanup(&path);
3668
3669 return return_value;
3670 }
3671
3672 PyDoc_STRVAR(os__exit__doc__,
3673 "_exit($module, /, status)\n"
3674 "--\n"
3675 "\n"
3676 "Exit to the system with specified status, without normal exit processing.");
3677
3678 #define OS__EXIT_METHODDEF \
3679 {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
3680
3681 static PyObject *
3682 os__exit_impl(PyObject *module, int status);
3683
3684 static PyObject *
3685 os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3686 {
3687 PyObject *return_value = NULL;
3688 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3689
3690 #define NUM_KEYWORDS 1
3691 static struct {
3692 PyGC_Head _this_is_not_used;
3693 PyObject_VAR_HEAD
3694 Py_hash_t ob_hash;
3695 PyObject *ob_item[NUM_KEYWORDS];
3696 } _kwtuple = {
3697 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3698 .ob_hash = -1,
3699 .ob_item = { &_Py_ID(status), },
3700 };
3701 #undef NUM_KEYWORDS
3702 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3703
3704 #else // !Py_BUILD_CORE
3705 # define KWTUPLE NULL
3706 #endif // !Py_BUILD_CORE
3707
3708 static const char * const _keywords[] = {"status", NULL};
3709 static _PyArg_Parser _parser = {
3710 .keywords = _keywords,
3711 .fname = "_exit",
3712 .kwtuple = KWTUPLE,
3713 };
3714 #undef KWTUPLE
3715 PyObject *argsbuf[1];
3716 int status;
3717
3718 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3719 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3720 if (!args) {
3721 goto exit;
3722 }
3723 status = PyLong_AsInt(args[0]);
3724 if (status == -1 && PyErr_Occurred()) {
3725 goto exit;
3726 }
3727 return_value = os__exit_impl(module, status);
3728
3729 exit:
3730 return return_value;
3731 }
3732
3733 #if defined(HAVE_EXECV)
3734
3735 PyDoc_STRVAR(os_execv__doc__,
3736 "execv($module, path, argv, /)\n"
3737 "--\n"
3738 "\n"
3739 "Execute an executable path with arguments, replacing current process.\n"
3740 "\n"
3741 " path\n"
3742 " Path of executable file.\n"
3743 " argv\n"
3744 " Tuple or list of strings.");
3745
3746 #define OS_EXECV_METHODDEF \
3747 {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
3748
3749 static PyObject *
3750 os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
3751
3752 static PyObject *
3753 os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3754 {
3755 PyObject *return_value = NULL;
3756 path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
3757 PyObject *argv;
3758
3759 if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
3760 goto exit;
3761 }
3762 if (!path_converter(args[0], &path)) {
3763 goto exit;
3764 }
3765 argv = args[1];
3766 return_value = os_execv_impl(module, &path, argv);
3767
3768 exit:
3769 /* Cleanup for path */
3770 path_cleanup(&path);
3771
3772 return return_value;
3773 }
3774
3775 #endif /* defined(HAVE_EXECV) */
3776
3777 #if defined(HAVE_EXECV)
3778
3779 PyDoc_STRVAR(os_execve__doc__,
3780 "execve($module, /, path, argv, env)\n"
3781 "--\n"
3782 "\n"
3783 "Execute an executable path with arguments, replacing current process.\n"
3784 "\n"
3785 " path\n"
3786 " Path of executable file.\n"
3787 " argv\n"
3788 " Tuple or list of strings.\n"
3789 " env\n"
3790 " Dictionary of strings mapping to strings.");
3791
3792 #define OS_EXECVE_METHODDEF \
3793 {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
3794
3795 static PyObject *
3796 os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
3797
3798 static PyObject *
3799 os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3800 {
3801 PyObject *return_value = NULL;
3802 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3803
3804 #define NUM_KEYWORDS 3
3805 static struct {
3806 PyGC_Head _this_is_not_used;
3807 PyObject_VAR_HEAD
3808 Py_hash_t ob_hash;
3809 PyObject *ob_item[NUM_KEYWORDS];
3810 } _kwtuple = {
3811 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3812 .ob_hash = -1,
3813 .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
3814 };
3815 #undef NUM_KEYWORDS
3816 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3817
3818 #else // !Py_BUILD_CORE
3819 # define KWTUPLE NULL
3820 #endif // !Py_BUILD_CORE
3821
3822 static const char * const _keywords[] = {"path", "argv", "env", NULL};
3823 static _PyArg_Parser _parser = {
3824 .keywords = _keywords,
3825 .fname = "execve",
3826 .kwtuple = KWTUPLE,
3827 };
3828 #undef KWTUPLE
3829 PyObject *argsbuf[3];
3830 path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
3831 PyObject *argv;
3832 PyObject *env;
3833
3834 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3835 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3836 if (!args) {
3837 goto exit;
3838 }
3839 if (!path_converter(args[0], &path)) {
3840 goto exit;
3841 }
3842 argv = args[1];
3843 env = args[2];
3844 return_value = os_execve_impl(module, &path, argv, env);
3845
3846 exit:
3847 /* Cleanup for path */
3848 path_cleanup(&path);
3849
3850 return return_value;
3851 }
3852
3853 #endif /* defined(HAVE_EXECV) */
3854
3855 #if defined(HAVE_POSIX_SPAWN)
3856
3857 PyDoc_STRVAR(os_posix_spawn__doc__,
3858 "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
3859 " setpgroup=None, resetids=False, setsid=False,\n"
3860 " setsigmask=(), setsigdef=(), scheduler=None)\n"
3861 "--\n"
3862 "\n"
3863 "Execute the program specified by path in a new process.\n"
3864 "\n"
3865 " path\n"
3866 " Path of executable file.\n"
3867 " argv\n"
3868 " Tuple or list of strings.\n"
3869 " env\n"
3870 " Dictionary of strings mapping to strings.\n"
3871 " file_actions\n"
3872 " A sequence of file action tuples.\n"
3873 " setpgroup\n"
3874 " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3875 " resetids\n"
3876 " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
3877 " setsid\n"
3878 " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP\n"
3879 " will be activated.\n"
3880 " setsigmask\n"
3881 " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3882 " setsigdef\n"
3883 " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3884 " scheduler\n"
3885 " A tuple with the scheduler policy (optional) and parameters.");
3886
3887 #define OS_POSIX_SPAWN_METHODDEF \
3888 {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
3889
3890 static PyObject *
3891 os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
3892 PyObject *env, PyObject *file_actions,
3893 PyObject *setpgroup, int resetids, int setsid,
3894 PyObject *setsigmask, PyObject *setsigdef,
3895 PyObject *scheduler);
3896
3897 static PyObject *
3898 os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3899 {
3900 PyObject *return_value = NULL;
3901 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3902
3903 #define NUM_KEYWORDS 7
3904 static struct {
3905 PyGC_Head _this_is_not_used;
3906 PyObject_VAR_HEAD
3907 Py_hash_t ob_hash;
3908 PyObject *ob_item[NUM_KEYWORDS];
3909 } _kwtuple = {
3910 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3911 .ob_hash = -1,
3912 .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
3913 };
3914 #undef NUM_KEYWORDS
3915 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3916
3917 #else // !Py_BUILD_CORE
3918 # define KWTUPLE NULL
3919 #endif // !Py_BUILD_CORE
3920
3921 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3922 static _PyArg_Parser _parser = {
3923 .keywords = _keywords,
3924 .fname = "posix_spawn",
3925 .kwtuple = KWTUPLE,
3926 };
3927 #undef KWTUPLE
3928 PyObject *argsbuf[10];
3929 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
3930 path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
3931 PyObject *argv;
3932 PyObject *env;
3933 PyObject *file_actions = NULL;
3934 PyObject *setpgroup = NULL;
3935 int resetids = 0;
3936 int setsid = 0;
3937 PyObject *setsigmask = NULL;
3938 PyObject *setsigdef = NULL;
3939 PyObject *scheduler = NULL;
3940
3941 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
3942 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
3943 if (!args) {
3944 goto exit;
3945 }
3946 if (!path_converter(args[0], &path)) {
3947 goto exit;
3948 }
3949 argv = args[1];
3950 env = args[2];
3951 if (!noptargs) {
3952 goto skip_optional_kwonly;
3953 }
3954 if (args[3]) {
3955 file_actions = args[3];
3956 if (!--noptargs) {
3957 goto skip_optional_kwonly;
3958 }
3959 }
3960 if (args[4]) {
3961 setpgroup = args[4];
3962 if (!--noptargs) {
3963 goto skip_optional_kwonly;
3964 }
3965 }
3966 if (args[5]) {
3967 resetids = PyObject_IsTrue(args[5]);
3968 if (resetids < 0) {
3969 goto exit;
3970 }
3971 if (!--noptargs) {
3972 goto skip_optional_kwonly;
3973 }
3974 }
3975 if (args[6]) {
3976 setsid = PyObject_IsTrue(args[6]);
3977 if (setsid < 0) {
3978 goto exit;
3979 }
3980 if (!--noptargs) {
3981 goto skip_optional_kwonly;
3982 }
3983 }
3984 if (args[7]) {
3985 setsigmask = args[7];
3986 if (!--noptargs) {
3987 goto skip_optional_kwonly;
3988 }
3989 }
3990 if (args[8]) {
3991 setsigdef = args[8];
3992 if (!--noptargs) {
3993 goto skip_optional_kwonly;
3994 }
3995 }
3996 scheduler = args[9];
3997 skip_optional_kwonly:
3998 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
3999
4000 exit:
4001 /* Cleanup for path */
4002 path_cleanup(&path);
4003
4004 return return_value;
4005 }
4006
4007 #endif /* defined(HAVE_POSIX_SPAWN) */
4008
4009 #if defined(HAVE_POSIX_SPAWNP)
4010
4011 PyDoc_STRVAR(os_posix_spawnp__doc__,
4012 "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
4013 " setpgroup=None, resetids=False, setsid=False,\n"
4014 " setsigmask=(), setsigdef=(), scheduler=None)\n"
4015 "--\n"
4016 "\n"
4017 "Execute the program specified by path in a new process.\n"
4018 "\n"
4019 " path\n"
4020 " Path of executable file.\n"
4021 " argv\n"
4022 " Tuple or list of strings.\n"
4023 " env\n"
4024 " Dictionary of strings mapping to strings.\n"
4025 " file_actions\n"
4026 " A sequence of file action tuples.\n"
4027 " setpgroup\n"
4028 " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
4029 " resetids\n"
4030 " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
4031 " setsid\n"
4032 " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP\n"
4033 " will be activated.\n"
4034 " setsigmask\n"
4035 " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
4036 " setsigdef\n"
4037 " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
4038 " scheduler\n"
4039 " A tuple with the scheduler policy (optional) and parameters.");
4040
4041 #define OS_POSIX_SPAWNP_METHODDEF \
4042 {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
4043
4044 static PyObject *
4045 os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
4046 PyObject *env, PyObject *file_actions,
4047 PyObject *setpgroup, int resetids, int setsid,
4048 PyObject *setsigmask, PyObject *setsigdef,
4049 PyObject *scheduler);
4050
4051 static PyObject *
4052 os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4053 {
4054 PyObject *return_value = NULL;
4055 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4056
4057 #define NUM_KEYWORDS 7
4058 static struct {
4059 PyGC_Head _this_is_not_used;
4060 PyObject_VAR_HEAD
4061 Py_hash_t ob_hash;
4062 PyObject *ob_item[NUM_KEYWORDS];
4063 } _kwtuple = {
4064 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4065 .ob_hash = -1,
4066 .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
4067 };
4068 #undef NUM_KEYWORDS
4069 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4070
4071 #else // !Py_BUILD_CORE
4072 # define KWTUPLE NULL
4073 #endif // !Py_BUILD_CORE
4074
4075 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
4076 static _PyArg_Parser _parser = {
4077 .keywords = _keywords,
4078 .fname = "posix_spawnp",
4079 .kwtuple = KWTUPLE,
4080 };
4081 #undef KWTUPLE
4082 PyObject *argsbuf[10];
4083 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
4084 path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
4085 PyObject *argv;
4086 PyObject *env;
4087 PyObject *file_actions = NULL;
4088 PyObject *setpgroup = NULL;
4089 int resetids = 0;
4090 int setsid = 0;
4091 PyObject *setsigmask = NULL;
4092 PyObject *setsigdef = NULL;
4093 PyObject *scheduler = NULL;
4094
4095 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4096 /*minpos*/ 3, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4097 if (!args) {
4098 goto exit;
4099 }
4100 if (!path_converter(args[0], &path)) {
4101 goto exit;
4102 }
4103 argv = args[1];
4104 env = args[2];
4105 if (!noptargs) {
4106 goto skip_optional_kwonly;
4107 }
4108 if (args[3]) {
4109 file_actions = args[3];
4110 if (!--noptargs) {
4111 goto skip_optional_kwonly;
4112 }
4113 }
4114 if (args[4]) {
4115 setpgroup = args[4];
4116 if (!--noptargs) {
4117 goto skip_optional_kwonly;
4118 }
4119 }
4120 if (args[5]) {
4121 resetids = PyObject_IsTrue(args[5]);
4122 if (resetids < 0) {
4123 goto exit;
4124 }
4125 if (!--noptargs) {
4126 goto skip_optional_kwonly;
4127 }
4128 }
4129 if (args[6]) {
4130 setsid = PyObject_IsTrue(args[6]);
4131 if (setsid < 0) {
4132 goto exit;
4133 }
4134 if (!--noptargs) {
4135 goto skip_optional_kwonly;
4136 }
4137 }
4138 if (args[7]) {
4139 setsigmask = args[7];
4140 if (!--noptargs) {
4141 goto skip_optional_kwonly;
4142 }
4143 }
4144 if (args[8]) {
4145 setsigdef = args[8];
4146 if (!--noptargs) {
4147 goto skip_optional_kwonly;
4148 }
4149 }
4150 scheduler = args[9];
4151 skip_optional_kwonly:
4152 return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
4153
4154 exit:
4155 /* Cleanup for path */
4156 path_cleanup(&path);
4157
4158 return return_value;
4159 }
4160
4161 #endif /* defined(HAVE_POSIX_SPAWNP) */
4162
4163 #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4164
4165 PyDoc_STRVAR(os_spawnv__doc__,
4166 "spawnv($module, mode, path, argv, /)\n"
4167 "--\n"
4168 "\n"
4169 "Execute the program specified by path in a new process.\n"
4170 "\n"
4171 " mode\n"
4172 " Mode of process creation.\n"
4173 " path\n"
4174 " Path of executable file.\n"
4175 " argv\n"
4176 " Tuple or list of strings.");
4177
4178 #define OS_SPAWNV_METHODDEF \
4179 {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
4180
4181 static PyObject *
4182 os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
4183
4184 static PyObject *
4185 os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4186 {
4187 PyObject *return_value = NULL;
4188 int mode;
4189 path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
4190 PyObject *argv;
4191
4192 if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
4193 goto exit;
4194 }
4195 mode = PyLong_AsInt(args[0]);
4196 if (mode == -1 && PyErr_Occurred()) {
4197 goto exit;
4198 }
4199 if (!path_converter(args[1], &path)) {
4200 goto exit;
4201 }
4202 argv = args[2];
4203 return_value = os_spawnv_impl(module, mode, &path, argv);
4204
4205 exit:
4206 /* Cleanup for path */
4207 path_cleanup(&path);
4208
4209 return return_value;
4210 }
4211
4212 #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4213
4214 #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
4215
4216 PyDoc_STRVAR(os_spawnve__doc__,
4217 "spawnve($module, mode, path, argv, env, /)\n"
4218 "--\n"
4219 "\n"
4220 "Execute the program specified by path in a new process.\n"
4221 "\n"
4222 " mode\n"
4223 " Mode of process creation.\n"
4224 " path\n"
4225 " Path of executable file.\n"
4226 " argv\n"
4227 " Tuple or list of strings.\n"
4228 " env\n"
4229 " Dictionary of strings mapping to strings.");
4230
4231 #define OS_SPAWNVE_METHODDEF \
4232 {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
4233
4234 static PyObject *
4235 os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
4236 PyObject *env);
4237
4238 static PyObject *
4239 os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4240 {
4241 PyObject *return_value = NULL;
4242 int mode;
4243 path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
4244 PyObject *argv;
4245 PyObject *env;
4246
4247 if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
4248 goto exit;
4249 }
4250 mode = PyLong_AsInt(args[0]);
4251 if (mode == -1 && PyErr_Occurred()) {
4252 goto exit;
4253 }
4254 if (!path_converter(args[1], &path)) {
4255 goto exit;
4256 }
4257 argv = args[2];
4258 env = args[3];
4259 return_value = os_spawnve_impl(module, mode, &path, argv, env);
4260
4261 exit:
4262 /* Cleanup for path */
4263 path_cleanup(&path);
4264
4265 return return_value;
4266 }
4267
4268 #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
4269
4270 #if defined(HAVE_FORK)
4271
4272 PyDoc_STRVAR(os_register_at_fork__doc__,
4273 "register_at_fork($module, /, *, before=<unrepresentable>,\n"
4274 " after_in_child=<unrepresentable>,\n"
4275 " after_in_parent=<unrepresentable>)\n"
4276 "--\n"
4277 "\n"
4278 "Register callables to be called when forking a new process.\n"
4279 "\n"
4280 " before\n"
4281 " A callable to be called in the parent before the fork() syscall.\n"
4282 " after_in_child\n"
4283 " A callable to be called in the child after fork().\n"
4284 " after_in_parent\n"
4285 " A callable to be called in the parent after fork().\n"
4286 "\n"
4287 "\'before\' callbacks are called in reverse order.\n"
4288 "\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
4289
4290 #define OS_REGISTER_AT_FORK_METHODDEF \
4291 {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
4292
4293 static PyObject *
4294 os_register_at_fork_impl(PyObject *module, PyObject *before,
4295 PyObject *after_in_child, PyObject *after_in_parent);
4296
4297 static PyObject *
4298 os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4299 {
4300 PyObject *return_value = NULL;
4301 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4302
4303 #define NUM_KEYWORDS 3
4304 static struct {
4305 PyGC_Head _this_is_not_used;
4306 PyObject_VAR_HEAD
4307 Py_hash_t ob_hash;
4308 PyObject *ob_item[NUM_KEYWORDS];
4309 } _kwtuple = {
4310 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4311 .ob_hash = -1,
4312 .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
4313 };
4314 #undef NUM_KEYWORDS
4315 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4316
4317 #else // !Py_BUILD_CORE
4318 # define KWTUPLE NULL
4319 #endif // !Py_BUILD_CORE
4320
4321 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
4322 static _PyArg_Parser _parser = {
4323 .keywords = _keywords,
4324 .fname = "register_at_fork",
4325 .kwtuple = KWTUPLE,
4326 };
4327 #undef KWTUPLE
4328 PyObject *argsbuf[3];
4329 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
4330 PyObject *before = NULL;
4331 PyObject *after_in_child = NULL;
4332 PyObject *after_in_parent = NULL;
4333
4334 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4335 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4336 if (!args) {
4337 goto exit;
4338 }
4339 if (!noptargs) {
4340 goto skip_optional_kwonly;
4341 }
4342 if (args[0]) {
4343 before = args[0];
4344 if (!--noptargs) {
4345 goto skip_optional_kwonly;
4346 }
4347 }
4348 if (args[1]) {
4349 after_in_child = args[1];
4350 if (!--noptargs) {
4351 goto skip_optional_kwonly;
4352 }
4353 }
4354 after_in_parent = args[2];
4355 skip_optional_kwonly:
4356 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
4357
4358 exit:
4359 return return_value;
4360 }
4361
4362 #endif /* defined(HAVE_FORK) */
4363
4364 #if defined(HAVE_FORK1)
4365
4366 PyDoc_STRVAR(os_fork1__doc__,
4367 "fork1($module, /)\n"
4368 "--\n"
4369 "\n"
4370 "Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
4371 "\n"
4372 "Return 0 to child process and PID of child to parent process.");
4373
4374 #define OS_FORK1_METHODDEF \
4375 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
4376
4377 static PyObject *
4378 os_fork1_impl(PyObject *module);
4379
4380 static PyObject *
4381 os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
4382 {
4383 return os_fork1_impl(module);
4384 }
4385
4386 #endif /* defined(HAVE_FORK1) */
4387
4388 #if defined(HAVE_FORK)
4389
4390 PyDoc_STRVAR(os_fork__doc__,
4391 "fork($module, /)\n"
4392 "--\n"
4393 "\n"
4394 "Fork a child process.\n"
4395 "\n"
4396 "Return 0 to child process and PID of child to parent process.");
4397
4398 #define OS_FORK_METHODDEF \
4399 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
4400
4401 static PyObject *
4402 os_fork_impl(PyObject *module);
4403
4404 static PyObject *
4405 os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
4406 {
4407 return os_fork_impl(module);
4408 }
4409
4410 #endif /* defined(HAVE_FORK) */
4411
4412 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4413
4414 PyDoc_STRVAR(os_sched_get_priority_max__doc__,
4415 "sched_get_priority_max($module, /, policy)\n"
4416 "--\n"
4417 "\n"
4418 "Get the maximum scheduling priority for policy.");
4419
4420 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
4421 {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
4422
4423 static PyObject *
4424 os_sched_get_priority_max_impl(PyObject *module, int policy);
4425
4426 static PyObject *
4427 os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4428 {
4429 PyObject *return_value = NULL;
4430 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4431
4432 #define NUM_KEYWORDS 1
4433 static struct {
4434 PyGC_Head _this_is_not_used;
4435 PyObject_VAR_HEAD
4436 Py_hash_t ob_hash;
4437 PyObject *ob_item[NUM_KEYWORDS];
4438 } _kwtuple = {
4439 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4440 .ob_hash = -1,
4441 .ob_item = { &_Py_ID(policy), },
4442 };
4443 #undef NUM_KEYWORDS
4444 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4445
4446 #else // !Py_BUILD_CORE
4447 # define KWTUPLE NULL
4448 #endif // !Py_BUILD_CORE
4449
4450 static const char * const _keywords[] = {"policy", NULL};
4451 static _PyArg_Parser _parser = {
4452 .keywords = _keywords,
4453 .fname = "sched_get_priority_max",
4454 .kwtuple = KWTUPLE,
4455 };
4456 #undef KWTUPLE
4457 PyObject *argsbuf[1];
4458 int policy;
4459
4460 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4461 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4462 if (!args) {
4463 goto exit;
4464 }
4465 policy = PyLong_AsInt(args[0]);
4466 if (policy == -1 && PyErr_Occurred()) {
4467 goto exit;
4468 }
4469 return_value = os_sched_get_priority_max_impl(module, policy);
4470
4471 exit:
4472 return return_value;
4473 }
4474
4475 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4476
4477 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
4478
4479 PyDoc_STRVAR(os_sched_get_priority_min__doc__,
4480 "sched_get_priority_min($module, /, policy)\n"
4481 "--\n"
4482 "\n"
4483 "Get the minimum scheduling priority for policy.");
4484
4485 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
4486 {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
4487
4488 static PyObject *
4489 os_sched_get_priority_min_impl(PyObject *module, int policy);
4490
4491 static PyObject *
4492 os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4493 {
4494 PyObject *return_value = NULL;
4495 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4496
4497 #define NUM_KEYWORDS 1
4498 static struct {
4499 PyGC_Head _this_is_not_used;
4500 PyObject_VAR_HEAD
4501 Py_hash_t ob_hash;
4502 PyObject *ob_item[NUM_KEYWORDS];
4503 } _kwtuple = {
4504 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4505 .ob_hash = -1,
4506 .ob_item = { &_Py_ID(policy), },
4507 };
4508 #undef NUM_KEYWORDS
4509 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4510
4511 #else // !Py_BUILD_CORE
4512 # define KWTUPLE NULL
4513 #endif // !Py_BUILD_CORE
4514
4515 static const char * const _keywords[] = {"policy", NULL};
4516 static _PyArg_Parser _parser = {
4517 .keywords = _keywords,
4518 .fname = "sched_get_priority_min",
4519 .kwtuple = KWTUPLE,
4520 };
4521 #undef KWTUPLE
4522 PyObject *argsbuf[1];
4523 int policy;
4524
4525 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
4526 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4527 if (!args) {
4528 goto exit;
4529 }
4530 policy = PyLong_AsInt(args[0]);
4531 if (policy == -1 && PyErr_Occurred()) {
4532 goto exit;
4533 }
4534 return_value = os_sched_get_priority_min_impl(module, policy);
4535
4536 exit:
4537 return return_value;
4538 }
4539
4540 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4541
4542 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4543
4544 PyDoc_STRVAR(os_sched_getscheduler__doc__,
4545 "sched_getscheduler($module, pid, /)\n"
4546 "--\n"
4547 "\n"
4548 "Get the scheduling policy for the process identified by pid.\n"
4549 "\n"
4550 "Passing 0 for pid returns the scheduling policy for the calling process.");
4551
4552 #define OS_SCHED_GETSCHEDULER_METHODDEF \
4553 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
4554
4555 static PyObject *
4556 os_sched_getscheduler_impl(PyObject *module, pid_t pid);
4557
4558 static PyObject *
4559 os_sched_getscheduler(PyObject *module, PyObject *arg)
4560 {
4561 PyObject *return_value = NULL;
4562 pid_t pid;
4563
4564 pid = PyLong_AsPid(arg);
4565 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4566 goto exit;
4567 }
4568 return_value = os_sched_getscheduler_impl(module, pid);
4569
4570 exit:
4571 return return_value;
4572 }
4573
4574 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4575
4576 #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
4577
4578 PyDoc_STRVAR(os_sched_param__doc__,
4579 "sched_param(sched_priority)\n"
4580 "--\n"
4581 "\n"
4582 "Currently has only one field: sched_priority\n"
4583 "\n"
4584 " sched_priority\n"
4585 " A scheduling parameter.");
4586
4587 static PyObject *
4588 os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
4589
4590 static PyObject *
4591 os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
4592 {
4593 PyObject *return_value = NULL;
4594 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4595
4596 #define NUM_KEYWORDS 1
4597 static struct {
4598 PyGC_Head _this_is_not_used;
4599 PyObject_VAR_HEAD
4600 Py_hash_t ob_hash;
4601 PyObject *ob_item[NUM_KEYWORDS];
4602 } _kwtuple = {
4603 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4604 .ob_hash = -1,
4605 .ob_item = { &_Py_ID(sched_priority), },
4606 };
4607 #undef NUM_KEYWORDS
4608 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4609
4610 #else // !Py_BUILD_CORE
4611 # define KWTUPLE NULL
4612 #endif // !Py_BUILD_CORE
4613
4614 static const char * const _keywords[] = {"sched_priority", NULL};
4615 static _PyArg_Parser _parser = {
4616 .keywords = _keywords,
4617 .fname = "sched_param",
4618 .kwtuple = KWTUPLE,
4619 };
4620 #undef KWTUPLE
4621 PyObject *argsbuf[1];
4622 PyObject * const *fastargs;
4623 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
4624 PyObject *sched_priority;
4625
4626 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
4627 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
4628 if (!fastargs) {
4629 goto exit;
4630 }
4631 sched_priority = fastargs[0];
4632 return_value = os_sched_param_impl(type, sched_priority);
4633
4634 exit:
4635 return return_value;
4636 }
4637
4638 #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
4639
4640 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4641
4642 PyDoc_STRVAR(os_sched_setscheduler__doc__,
4643 "sched_setscheduler($module, pid, policy, param, /)\n"
4644 "--\n"
4645 "\n"
4646 "Set the scheduling policy for the process identified by pid.\n"
4647 "\n"
4648 "If pid is 0, the calling process is changed.\n"
4649 "param is an instance of sched_param.");
4650
4651 #define OS_SCHED_SETSCHEDULER_METHODDEF \
4652 {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
4653
4654 static PyObject *
4655 os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
4656 PyObject *param_obj);
4657
4658 static PyObject *
4659 os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4660 {
4661 PyObject *return_value = NULL;
4662 pid_t pid;
4663 int policy;
4664 PyObject *param_obj;
4665
4666 if (!_PyArg_CheckPositional("sched_setscheduler", nargs, 3, 3)) {
4667 goto exit;
4668 }
4669 pid = PyLong_AsPid(args[0]);
4670 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4671 goto exit;
4672 }
4673 policy = PyLong_AsInt(args[1]);
4674 if (policy == -1 && PyErr_Occurred()) {
4675 goto exit;
4676 }
4677 param_obj = args[2];
4678 return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
4679
4680 exit:
4681 return return_value;
4682 }
4683
4684 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4685
4686 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4687
4688 PyDoc_STRVAR(os_sched_getparam__doc__,
4689 "sched_getparam($module, pid, /)\n"
4690 "--\n"
4691 "\n"
4692 "Returns scheduling parameters for the process identified by pid.\n"
4693 "\n"
4694 "If pid is 0, returns parameters for the calling process.\n"
4695 "Return value is an instance of sched_param.");
4696
4697 #define OS_SCHED_GETPARAM_METHODDEF \
4698 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
4699
4700 static PyObject *
4701 os_sched_getparam_impl(PyObject *module, pid_t pid);
4702
4703 static PyObject *
4704 os_sched_getparam(PyObject *module, PyObject *arg)
4705 {
4706 PyObject *return_value = NULL;
4707 pid_t pid;
4708
4709 pid = PyLong_AsPid(arg);
4710 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4711 goto exit;
4712 }
4713 return_value = os_sched_getparam_impl(module, pid);
4714
4715 exit:
4716 return return_value;
4717 }
4718
4719 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4720
4721 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4722
4723 PyDoc_STRVAR(os_sched_setparam__doc__,
4724 "sched_setparam($module, pid, param, /)\n"
4725 "--\n"
4726 "\n"
4727 "Set scheduling parameters for the process identified by pid.\n"
4728 "\n"
4729 "If pid is 0, sets parameters for the calling process.\n"
4730 "param should be an instance of sched_param.");
4731
4732 #define OS_SCHED_SETPARAM_METHODDEF \
4733 {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
4734
4735 static PyObject *
4736 os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
4737
4738 static PyObject *
4739 os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4740 {
4741 PyObject *return_value = NULL;
4742 pid_t pid;
4743 PyObject *param_obj;
4744
4745 if (!_PyArg_CheckPositional("sched_setparam", nargs, 2, 2)) {
4746 goto exit;
4747 }
4748 pid = PyLong_AsPid(args[0]);
4749 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4750 goto exit;
4751 }
4752 param_obj = args[1];
4753 return_value = os_sched_setparam_impl(module, pid, param_obj);
4754
4755 exit:
4756 return return_value;
4757 }
4758
4759 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4760
4761 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
4762
4763 PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
4764 "sched_rr_get_interval($module, pid, /)\n"
4765 "--\n"
4766 "\n"
4767 "Return the round-robin quantum for the process identified by pid, in seconds.\n"
4768 "\n"
4769 "Value returned is a float.");
4770
4771 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
4772 {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
4773
4774 static double
4775 os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
4776
4777 static PyObject *
4778 os_sched_rr_get_interval(PyObject *module, PyObject *arg)
4779 {
4780 PyObject *return_value = NULL;
4781 pid_t pid;
4782 double _return_value;
4783
4784 pid = PyLong_AsPid(arg);
4785 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4786 goto exit;
4787 }
4788 _return_value = os_sched_rr_get_interval_impl(module, pid);
4789 if ((_return_value == -1.0) && PyErr_Occurred()) {
4790 goto exit;
4791 }
4792 return_value = PyFloat_FromDouble(_return_value);
4793
4794 exit:
4795 return return_value;
4796 }
4797
4798 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
4799
4800 #if defined(HAVE_SCHED_H)
4801
4802 PyDoc_STRVAR(os_sched_yield__doc__,
4803 "sched_yield($module, /)\n"
4804 "--\n"
4805 "\n"
4806 "Voluntarily relinquish the CPU.");
4807
4808 #define OS_SCHED_YIELD_METHODDEF \
4809 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
4810
4811 static PyObject *
4812 os_sched_yield_impl(PyObject *module);
4813
4814 static PyObject *
4815 os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
4816 {
4817 return os_sched_yield_impl(module);
4818 }
4819
4820 #endif /* defined(HAVE_SCHED_H) */
4821
4822 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4823
4824 PyDoc_STRVAR(os_sched_setaffinity__doc__,
4825 "sched_setaffinity($module, pid, mask, /)\n"
4826 "--\n"
4827 "\n"
4828 "Set the CPU affinity of the process identified by pid to mask.\n"
4829 "\n"
4830 "mask should be an iterable of integers identifying CPUs.");
4831
4832 #define OS_SCHED_SETAFFINITY_METHODDEF \
4833 {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
4834
4835 static PyObject *
4836 os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
4837
4838 static PyObject *
4839 os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4840 {
4841 PyObject *return_value = NULL;
4842 pid_t pid;
4843 PyObject *mask;
4844
4845 if (!_PyArg_CheckPositional("sched_setaffinity", nargs, 2, 2)) {
4846 goto exit;
4847 }
4848 pid = PyLong_AsPid(args[0]);
4849 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4850 goto exit;
4851 }
4852 mask = args[1];
4853 return_value = os_sched_setaffinity_impl(module, pid, mask);
4854
4855 exit:
4856 return return_value;
4857 }
4858
4859 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4860
4861 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4862
4863 PyDoc_STRVAR(os_sched_getaffinity__doc__,
4864 "sched_getaffinity($module, pid, /)\n"
4865 "--\n"
4866 "\n"
4867 "Return the affinity of the process identified by pid (or the current process if zero).\n"
4868 "\n"
4869 "The affinity is returned as a set of CPU identifiers.");
4870
4871 #define OS_SCHED_GETAFFINITY_METHODDEF \
4872 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
4873
4874 static PyObject *
4875 os_sched_getaffinity_impl(PyObject *module, pid_t pid);
4876
4877 static PyObject *
4878 os_sched_getaffinity(PyObject *module, PyObject *arg)
4879 {
4880 PyObject *return_value = NULL;
4881 pid_t pid;
4882
4883 pid = PyLong_AsPid(arg);
4884 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
4885 goto exit;
4886 }
4887 return_value = os_sched_getaffinity_impl(module, pid);
4888
4889 exit:
4890 return return_value;
4891 }
4892
4893 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4894
4895 #if defined(HAVE_POSIX_OPENPT)
4896
4897 PyDoc_STRVAR(os_posix_openpt__doc__,
4898 "posix_openpt($module, oflag, /)\n"
4899 "--\n"
4900 "\n"
4901 "Open and return a file descriptor for a master pseudo-terminal device.\n"
4902 "\n"
4903 "Performs a posix_openpt() C function call. The oflag argument is used to\n"
4904 "set file status flags and file access modes as specified in the manual\n"
4905 "page of posix_openpt() of your system.");
4906
4907 #define OS_POSIX_OPENPT_METHODDEF \
4908 {"posix_openpt", (PyCFunction)os_posix_openpt, METH_O, os_posix_openpt__doc__},
4909
4910 static int
4911 os_posix_openpt_impl(PyObject *module, int oflag);
4912
4913 static PyObject *
4914 os_posix_openpt(PyObject *module, PyObject *arg)
4915 {
4916 PyObject *return_value = NULL;
4917 int oflag;
4918 int _return_value;
4919
4920 oflag = PyLong_AsInt(arg);
4921 if (oflag == -1 && PyErr_Occurred()) {
4922 goto exit;
4923 }
4924 _return_value = os_posix_openpt_impl(module, oflag);
4925 if ((_return_value == -1) && PyErr_Occurred()) {
4926 goto exit;
4927 }
4928 return_value = PyLong_FromLong((long)_return_value);
4929
4930 exit:
4931 return return_value;
4932 }
4933
4934 #endif /* defined(HAVE_POSIX_OPENPT) */
4935
4936 #if defined(HAVE_GRANTPT)
4937
4938 PyDoc_STRVAR(os_grantpt__doc__,
4939 "grantpt($module, fd, /)\n"
4940 "--\n"
4941 "\n"
4942 "Grant access to the slave pseudo-terminal device.\n"
4943 "\n"
4944 " fd\n"
4945 " File descriptor of a master pseudo-terminal device.\n"
4946 "\n"
4947 "Performs a grantpt() C function call.");
4948
4949 #define OS_GRANTPT_METHODDEF \
4950 {"grantpt", (PyCFunction)os_grantpt, METH_O, os_grantpt__doc__},
4951
4952 static PyObject *
4953 os_grantpt_impl(PyObject *module, int fd);
4954
4955 static PyObject *
4956 os_grantpt(PyObject *module, PyObject *arg)
4957 {
4958 PyObject *return_value = NULL;
4959 int fd;
4960
4961 fd = PyObject_AsFileDescriptor(arg);
4962 if (fd < 0) {
4963 goto exit;
4964 }
4965 return_value = os_grantpt_impl(module, fd);
4966
4967 exit:
4968 return return_value;
4969 }
4970
4971 #endif /* defined(HAVE_GRANTPT) */
4972
4973 #if defined(HAVE_UNLOCKPT)
4974
4975 PyDoc_STRVAR(os_unlockpt__doc__,
4976 "unlockpt($module, fd, /)\n"
4977 "--\n"
4978 "\n"
4979 "Unlock a pseudo-terminal master/slave pair.\n"
4980 "\n"
4981 " fd\n"
4982 " File descriptor of a master pseudo-terminal device.\n"
4983 "\n"
4984 "Performs an unlockpt() C function call.");
4985
4986 #define OS_UNLOCKPT_METHODDEF \
4987 {"unlockpt", (PyCFunction)os_unlockpt, METH_O, os_unlockpt__doc__},
4988
4989 static PyObject *
4990 os_unlockpt_impl(PyObject *module, int fd);
4991
4992 static PyObject *
4993 os_unlockpt(PyObject *module, PyObject *arg)
4994 {
4995 PyObject *return_value = NULL;
4996 int fd;
4997
4998 fd = PyObject_AsFileDescriptor(arg);
4999 if (fd < 0) {
5000 goto exit;
5001 }
5002 return_value = os_unlockpt_impl(module, fd);
5003
5004 exit:
5005 return return_value;
5006 }
5007
5008 #endif /* defined(HAVE_UNLOCKPT) */
5009
5010 #if (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R))
5011
5012 PyDoc_STRVAR(os_ptsname__doc__,
5013 "ptsname($module, fd, /)\n"
5014 "--\n"
5015 "\n"
5016 "Return the name of the slave pseudo-terminal device.\n"
5017 "\n"
5018 " fd\n"
5019 " File descriptor of a master pseudo-terminal device.\n"
5020 "\n"
5021 "If the ptsname_r() C function is available, it is called;\n"
5022 "otherwise, performs a ptsname() C function call.");
5023
5024 #define OS_PTSNAME_METHODDEF \
5025 {"ptsname", (PyCFunction)os_ptsname, METH_O, os_ptsname__doc__},
5026
5027 static PyObject *
5028 os_ptsname_impl(PyObject *module, int fd);
5029
5030 static PyObject *
5031 os_ptsname(PyObject *module, PyObject *arg)
5032 {
5033 PyObject *return_value = NULL;
5034 int fd;
5035
5036 fd = PyObject_AsFileDescriptor(arg);
5037 if (fd < 0) {
5038 goto exit;
5039 }
5040 return_value = os_ptsname_impl(module, fd);
5041
5042 exit:
5043 return return_value;
5044 }
5045
5046 #endif /* (defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)) */
5047
5048 #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
5049
5050 PyDoc_STRVAR(os_openpty__doc__,
5051 "openpty($module, /)\n"
5052 "--\n"
5053 "\n"
5054 "Open a pseudo-terminal.\n"
5055 "\n"
5056 "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
5057 "for both the master and slave ends.");
5058
5059 #define OS_OPENPTY_METHODDEF \
5060 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
5061
5062 static PyObject *
5063 os_openpty_impl(PyObject *module);
5064
5065 static PyObject *
5066 os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5067 {
5068 return os_openpty_impl(module);
5069 }
5070
5071 #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
5072
5073 #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
5074
5075 PyDoc_STRVAR(os_login_tty__doc__,
5076 "login_tty($module, fd, /)\n"
5077 "--\n"
5078 "\n"
5079 "Prepare the tty of which fd is a file descriptor for a new login session.\n"
5080 "\n"
5081 "Make the calling process a session leader; make the tty the\n"
5082 "controlling tty, the stdin, the stdout, and the stderr of the\n"
5083 "calling process; close fd.");
5084
5085 #define OS_LOGIN_TTY_METHODDEF \
5086 {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
5087
5088 static PyObject *
5089 os_login_tty_impl(PyObject *module, int fd);
5090
5091 static PyObject *
5092 os_login_tty(PyObject *module, PyObject *arg)
5093 {
5094 PyObject *return_value = NULL;
5095 int fd;
5096
5097 fd = PyObject_AsFileDescriptor(arg);
5098 if (fd < 0) {
5099 goto exit;
5100 }
5101 return_value = os_login_tty_impl(module, fd);
5102
5103 exit:
5104 return return_value;
5105 }
5106
5107 #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
5108
5109 #if defined(HAVE_FORKPTY)
5110
5111 PyDoc_STRVAR(os_forkpty__doc__,
5112 "forkpty($module, /)\n"
5113 "--\n"
5114 "\n"
5115 "Fork a new process with a new pseudo-terminal as controlling tty.\n"
5116 "\n"
5117 "Returns a tuple of (pid, master_fd).\n"
5118 "Like fork(), return pid of 0 to the child process,\n"
5119 "and pid of child to the parent process.\n"
5120 "To both, return fd of newly opened pseudo-terminal.");
5121
5122 #define OS_FORKPTY_METHODDEF \
5123 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
5124
5125 static PyObject *
5126 os_forkpty_impl(PyObject *module);
5127
5128 static PyObject *
5129 os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
5130 {
5131 return os_forkpty_impl(module);
5132 }
5133
5134 #endif /* defined(HAVE_FORKPTY) */
5135
5136 #if defined(HAVE_GETEGID)
5137
5138 PyDoc_STRVAR(os_getegid__doc__,
5139 "getegid($module, /)\n"
5140 "--\n"
5141 "\n"
5142 "Return the current process\'s effective group id.");
5143
5144 #define OS_GETEGID_METHODDEF \
5145 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
5146
5147 static PyObject *
5148 os_getegid_impl(PyObject *module);
5149
5150 static PyObject *
5151 os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
5152 {
5153 return os_getegid_impl(module);
5154 }
5155
5156 #endif /* defined(HAVE_GETEGID) */
5157
5158 #if defined(HAVE_GETEUID)
5159
5160 PyDoc_STRVAR(os_geteuid__doc__,
5161 "geteuid($module, /)\n"
5162 "--\n"
5163 "\n"
5164 "Return the current process\'s effective user id.");
5165
5166 #define OS_GETEUID_METHODDEF \
5167 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
5168
5169 static PyObject *
5170 os_geteuid_impl(PyObject *module);
5171
5172 static PyObject *
5173 os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5174 {
5175 return os_geteuid_impl(module);
5176 }
5177
5178 #endif /* defined(HAVE_GETEUID) */
5179
5180 #if defined(HAVE_GETGID)
5181
5182 PyDoc_STRVAR(os_getgid__doc__,
5183 "getgid($module, /)\n"
5184 "--\n"
5185 "\n"
5186 "Return the current process\'s group id.");
5187
5188 #define OS_GETGID_METHODDEF \
5189 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
5190
5191 static PyObject *
5192 os_getgid_impl(PyObject *module);
5193
5194 static PyObject *
5195 os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
5196 {
5197 return os_getgid_impl(module);
5198 }
5199
5200 #endif /* defined(HAVE_GETGID) */
5201
5202 #if defined(HAVE_GETPID)
5203
5204 PyDoc_STRVAR(os_getpid__doc__,
5205 "getpid($module, /)\n"
5206 "--\n"
5207 "\n"
5208 "Return the current process id.");
5209
5210 #define OS_GETPID_METHODDEF \
5211 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
5212
5213 static PyObject *
5214 os_getpid_impl(PyObject *module);
5215
5216 static PyObject *
5217 os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
5218 {
5219 return os_getpid_impl(module);
5220 }
5221
5222 #endif /* defined(HAVE_GETPID) */
5223
5224 #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
5225
5226 PyDoc_STRVAR(os_getgrouplist__doc__,
5227 "getgrouplist($module, user, group, /)\n"
5228 "--\n"
5229 "\n"
5230 "Returns a list of groups to which a user belongs.\n"
5231 "\n"
5232 " user\n"
5233 " username to lookup\n"
5234 " group\n"
5235 " base group id of the user");
5236
5237 #define OS_GETGROUPLIST_METHODDEF \
5238 {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5239
5240 static PyObject *
5241 os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
5242
5243 static PyObject *
5244 os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5245 {
5246 PyObject *return_value = NULL;
5247 const char *user;
5248 int basegid;
5249
5250 if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5251 goto exit;
5252 }
5253 if (!PyUnicode_Check(args[0])) {
5254 _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5255 goto exit;
5256 }
5257 Py_ssize_t user_length;
5258 user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5259 if (user == NULL) {
5260 goto exit;
5261 }
5262 if (strlen(user) != (size_t)user_length) {
5263 PyErr_SetString(PyExc_ValueError, "embedded null character");
5264 goto exit;
5265 }
5266 basegid = PyLong_AsInt(args[1]);
5267 if (basegid == -1 && PyErr_Occurred()) {
5268 goto exit;
5269 }
5270 return_value = os_getgrouplist_impl(module, user, basegid);
5271
5272 exit:
5273 return return_value;
5274 }
5275
5276 #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
5277
5278 #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
5279
5280 PyDoc_STRVAR(os_getgrouplist__doc__,
5281 "getgrouplist($module, user, group, /)\n"
5282 "--\n"
5283 "\n"
5284 "Returns a list of groups to which a user belongs.\n"
5285 "\n"
5286 " user\n"
5287 " username to lookup\n"
5288 " group\n"
5289 " base group id of the user");
5290
5291 #define OS_GETGROUPLIST_METHODDEF \
5292 {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
5293
5294 static PyObject *
5295 os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
5296
5297 static PyObject *
5298 os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5299 {
5300 PyObject *return_value = NULL;
5301 const char *user;
5302 gid_t basegid;
5303
5304 if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
5305 goto exit;
5306 }
5307 if (!PyUnicode_Check(args[0])) {
5308 _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
5309 goto exit;
5310 }
5311 Py_ssize_t user_length;
5312 user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
5313 if (user == NULL) {
5314 goto exit;
5315 }
5316 if (strlen(user) != (size_t)user_length) {
5317 PyErr_SetString(PyExc_ValueError, "embedded null character");
5318 goto exit;
5319 }
5320 if (!_Py_Gid_Converter(args[1], &basegid)) {
5321 goto exit;
5322 }
5323 return_value = os_getgrouplist_impl(module, user, basegid);
5324
5325 exit:
5326 return return_value;
5327 }
5328
5329 #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
5330
5331 #if defined(HAVE_GETGROUPS)
5332
5333 PyDoc_STRVAR(os_getgroups__doc__,
5334 "getgroups($module, /)\n"
5335 "--\n"
5336 "\n"
5337 "Return list of supplemental group IDs for the process.");
5338
5339 #define OS_GETGROUPS_METHODDEF \
5340 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
5341
5342 static PyObject *
5343 os_getgroups_impl(PyObject *module);
5344
5345 static PyObject *
5346 os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
5347 {
5348 return os_getgroups_impl(module);
5349 }
5350
5351 #endif /* defined(HAVE_GETGROUPS) */
5352
5353 #if defined(HAVE_INITGROUPS) && defined(__APPLE__)
5354
5355 PyDoc_STRVAR(os_initgroups__doc__,
5356 "initgroups($module, username, gid, /)\n"
5357 "--\n"
5358 "\n"
5359 "Initialize the group access list.\n"
5360 "\n"
5361 "Call the system initgroups() to initialize the group access list with\n"
5362 "all of the groups of which the specified username is a member, plus the\n"
5363 "specified group id.");
5364
5365 #define OS_INITGROUPS_METHODDEF \
5366 {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5367
5368 static PyObject *
5369 os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
5370
5371 static PyObject *
5372 os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5373 {
5374 PyObject *return_value = NULL;
5375 PyObject *oname = NULL;
5376 int gid;
5377
5378 if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5379 goto exit;
5380 }
5381 if (!PyUnicode_FSConverter(args[0], &oname)) {
5382 goto exit;
5383 }
5384 gid = PyLong_AsInt(args[1]);
5385 if (gid == -1 && PyErr_Occurred()) {
5386 goto exit;
5387 }
5388 return_value = os_initgroups_impl(module, oname, gid);
5389
5390 exit:
5391 /* Cleanup for oname */
5392 Py_XDECREF(oname);
5393
5394 return return_value;
5395 }
5396
5397 #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
5398
5399 #if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
5400
5401 PyDoc_STRVAR(os_initgroups__doc__,
5402 "initgroups($module, username, gid, /)\n"
5403 "--\n"
5404 "\n"
5405 "Initialize the group access list.\n"
5406 "\n"
5407 "Call the system initgroups() to initialize the group access list with\n"
5408 "all of the groups of which the specified username is a member, plus the\n"
5409 "specified group id.");
5410
5411 #define OS_INITGROUPS_METHODDEF \
5412 {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
5413
5414 static PyObject *
5415 os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
5416
5417 static PyObject *
5418 os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5419 {
5420 PyObject *return_value = NULL;
5421 PyObject *oname = NULL;
5422 gid_t gid;
5423
5424 if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
5425 goto exit;
5426 }
5427 if (!PyUnicode_FSConverter(args[0], &oname)) {
5428 goto exit;
5429 }
5430 if (!_Py_Gid_Converter(args[1], &gid)) {
5431 goto exit;
5432 }
5433 return_value = os_initgroups_impl(module, oname, gid);
5434
5435 exit:
5436 /* Cleanup for oname */
5437 Py_XDECREF(oname);
5438
5439 return return_value;
5440 }
5441
5442 #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
5443
5444 #if defined(HAVE_GETPGID)
5445
5446 PyDoc_STRVAR(os_getpgid__doc__,
5447 "getpgid($module, /, pid)\n"
5448 "--\n"
5449 "\n"
5450 "Call the system call getpgid(), and return the result.");
5451
5452 #define OS_GETPGID_METHODDEF \
5453 {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
5454
5455 static PyObject *
5456 os_getpgid_impl(PyObject *module, pid_t pid);
5457
5458 static PyObject *
5459 os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5460 {
5461 PyObject *return_value = NULL;
5462 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5463
5464 #define NUM_KEYWORDS 1
5465 static struct {
5466 PyGC_Head _this_is_not_used;
5467 PyObject_VAR_HEAD
5468 Py_hash_t ob_hash;
5469 PyObject *ob_item[NUM_KEYWORDS];
5470 } _kwtuple = {
5471 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5472 .ob_hash = -1,
5473 .ob_item = { &_Py_ID(pid), },
5474 };
5475 #undef NUM_KEYWORDS
5476 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5477
5478 #else // !Py_BUILD_CORE
5479 # define KWTUPLE NULL
5480 #endif // !Py_BUILD_CORE
5481
5482 static const char * const _keywords[] = {"pid", NULL};
5483 static _PyArg_Parser _parser = {
5484 .keywords = _keywords,
5485 .fname = "getpgid",
5486 .kwtuple = KWTUPLE,
5487 };
5488 #undef KWTUPLE
5489 PyObject *argsbuf[1];
5490 pid_t pid;
5491
5492 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
5493 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
5494 if (!args) {
5495 goto exit;
5496 }
5497 pid = PyLong_AsPid(args[0]);
5498 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5499 goto exit;
5500 }
5501 return_value = os_getpgid_impl(module, pid);
5502
5503 exit:
5504 return return_value;
5505 }
5506
5507 #endif /* defined(HAVE_GETPGID) */
5508
5509 #if defined(HAVE_GETPGRP)
5510
5511 PyDoc_STRVAR(os_getpgrp__doc__,
5512 "getpgrp($module, /)\n"
5513 "--\n"
5514 "\n"
5515 "Return the current process group id.");
5516
5517 #define OS_GETPGRP_METHODDEF \
5518 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
5519
5520 static PyObject *
5521 os_getpgrp_impl(PyObject *module);
5522
5523 static PyObject *
5524 os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5525 {
5526 return os_getpgrp_impl(module);
5527 }
5528
5529 #endif /* defined(HAVE_GETPGRP) */
5530
5531 #if defined(HAVE_SETPGRP)
5532
5533 PyDoc_STRVAR(os_setpgrp__doc__,
5534 "setpgrp($module, /)\n"
5535 "--\n"
5536 "\n"
5537 "Make the current process the leader of its process group.");
5538
5539 #define OS_SETPGRP_METHODDEF \
5540 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
5541
5542 static PyObject *
5543 os_setpgrp_impl(PyObject *module);
5544
5545 static PyObject *
5546 os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
5547 {
5548 return os_setpgrp_impl(module);
5549 }
5550
5551 #endif /* defined(HAVE_SETPGRP) */
5552
5553 #if defined(HAVE_GETPPID)
5554
5555 PyDoc_STRVAR(os_getppid__doc__,
5556 "getppid($module, /)\n"
5557 "--\n"
5558 "\n"
5559 "Return the parent\'s process id.\n"
5560 "\n"
5561 "If the parent process has already exited, Windows machines will still\n"
5562 "return its id; others systems will return the id of the \'init\' proces\n"
5563 "(1).");
5564
5565 #define OS_GETPPID_METHODDEF \
5566 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
5567
5568 static PyObject *
5569 os_getppid_impl(PyObject *module);
5570
5571 static PyObject *
5572 os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
5573 {
5574 return os_getppid_impl(module);
5575 }
5576
5577 #endif /* defined(HAVE_GETPPID) */
5578
5579 #if defined(HAVE_GETLOGIN)
5580
5581 PyDoc_STRVAR(os_getlogin__doc__,
5582 "getlogin($module, /)\n"
5583 "--\n"
5584 "\n"
5585 "Return the actual login name.");
5586
5587 #define OS_GETLOGIN_METHODDEF \
5588 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
5589
5590 static PyObject *
5591 os_getlogin_impl(PyObject *module);
5592
5593 static PyObject *
5594 os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
5595 {
5596 return os_getlogin_impl(module);
5597 }
5598
5599 #endif /* defined(HAVE_GETLOGIN) */
5600
5601 #if defined(HAVE_GETUID)
5602
5603 PyDoc_STRVAR(os_getuid__doc__,
5604 "getuid($module, /)\n"
5605 "--\n"
5606 "\n"
5607 "Return the current process\'s user id.");
5608
5609 #define OS_GETUID_METHODDEF \
5610 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
5611
5612 static PyObject *
5613 os_getuid_impl(PyObject *module);
5614
5615 static PyObject *
5616 os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5617 {
5618 return os_getuid_impl(module);
5619 }
5620
5621 #endif /* defined(HAVE_GETUID) */
5622
5623 #if defined(HAVE_KILL)
5624
5625 PyDoc_STRVAR(os_kill__doc__,
5626 "kill($module, pid, signal, /)\n"
5627 "--\n"
5628 "\n"
5629 "Kill a process with a signal.");
5630
5631 #define OS_KILL_METHODDEF \
5632 {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
5633
5634 static PyObject *
5635 os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
5636
5637 static PyObject *
5638 os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5639 {
5640 PyObject *return_value = NULL;
5641 pid_t pid;
5642 Py_ssize_t signal;
5643
5644 if (!_PyArg_CheckPositional("kill", nargs, 2, 2)) {
5645 goto exit;
5646 }
5647 pid = PyLong_AsPid(args[0]);
5648 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
5649 goto exit;
5650 }
5651 {
5652 Py_ssize_t ival = -1;
5653 PyObject *iobj = _PyNumber_Index(args[1]);
5654 if (iobj != NULL) {
5655 ival = PyLong_AsSsize_t(iobj);
5656 Py_DECREF(iobj);
5657 }
5658 if (ival == -1 && PyErr_Occurred()) {
5659 goto exit;
5660 }
5661 signal = ival;
5662 }
5663 return_value = os_kill_impl(module, pid, signal);
5664
5665 exit:
5666 return return_value;
5667 }
5668
5669 #endif /* defined(HAVE_KILL) */
5670
5671 #if defined(HAVE_KILLPG)
5672
5673 PyDoc_STRVAR(os_killpg__doc__,
5674 "killpg($module, pgid, signal, /)\n"
5675 "--\n"
5676 "\n"
5677 "Kill a process group with a signal.");
5678
5679 #define OS_KILLPG_METHODDEF \
5680 {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
5681
5682 static PyObject *
5683 os_killpg_impl(PyObject *module, pid_t pgid, int signal);
5684
5685 static PyObject *
5686 os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5687 {
5688 PyObject *return_value = NULL;
5689 pid_t pgid;
5690 int signal;
5691
5692 if (!_PyArg_CheckPositional("killpg", nargs, 2, 2)) {
5693 goto exit;
5694 }
5695 pgid = PyLong_AsPid(args[0]);
5696 if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
5697 goto exit;
5698 }
5699 signal = PyLong_AsInt(args[1]);
5700 if (signal == -1 && PyErr_Occurred()) {
5701 goto exit;
5702 }
5703 return_value = os_killpg_impl(module, pgid, signal);
5704
5705 exit:
5706 return return_value;
5707 }
5708
5709 #endif /* defined(HAVE_KILLPG) */
5710
5711 #if defined(HAVE_PLOCK)
5712
5713 PyDoc_STRVAR(os_plock__doc__,
5714 "plock($module, op, /)\n"
5715 "--\n"
5716 "\n"
5717 "Lock program segments into memory.\");");
5718
5719 #define OS_PLOCK_METHODDEF \
5720 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
5721
5722 static PyObject *
5723 os_plock_impl(PyObject *module, int op);
5724
5725 static PyObject *
5726 os_plock(PyObject *module, PyObject *arg)
5727 {
5728 PyObject *return_value = NULL;
5729 int op;
5730
5731 op = PyLong_AsInt(arg);
5732 if (op == -1 && PyErr_Occurred()) {
5733 goto exit;
5734 }
5735 return_value = os_plock_impl(module, op);
5736
5737 exit:
5738 return return_value;
5739 }
5740
5741 #endif /* defined(HAVE_PLOCK) */
5742
5743 #if defined(HAVE_SETUID)
5744
5745 PyDoc_STRVAR(os_setuid__doc__,
5746 "setuid($module, uid, /)\n"
5747 "--\n"
5748 "\n"
5749 "Set the current process\'s user id.");
5750
5751 #define OS_SETUID_METHODDEF \
5752 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
5753
5754 static PyObject *
5755 os_setuid_impl(PyObject *module, uid_t uid);
5756
5757 static PyObject *
5758 os_setuid(PyObject *module, PyObject *arg)
5759 {
5760 PyObject *return_value = NULL;
5761 uid_t uid;
5762
5763 if (!_Py_Uid_Converter(arg, &uid)) {
5764 goto exit;
5765 }
5766 return_value = os_setuid_impl(module, uid);
5767
5768 exit:
5769 return return_value;
5770 }
5771
5772 #endif /* defined(HAVE_SETUID) */
5773
5774 #if defined(HAVE_SETEUID)
5775
5776 PyDoc_STRVAR(os_seteuid__doc__,
5777 "seteuid($module, euid, /)\n"
5778 "--\n"
5779 "\n"
5780 "Set the current process\'s effective user id.");
5781
5782 #define OS_SETEUID_METHODDEF \
5783 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
5784
5785 static PyObject *
5786 os_seteuid_impl(PyObject *module, uid_t euid);
5787
5788 static PyObject *
5789 os_seteuid(PyObject *module, PyObject *arg)
5790 {
5791 PyObject *return_value = NULL;
5792 uid_t euid;
5793
5794 if (!_Py_Uid_Converter(arg, &euid)) {
5795 goto exit;
5796 }
5797 return_value = os_seteuid_impl(module, euid);
5798
5799 exit:
5800 return return_value;
5801 }
5802
5803 #endif /* defined(HAVE_SETEUID) */
5804
5805 #if defined(HAVE_SETEGID)
5806
5807 PyDoc_STRVAR(os_setegid__doc__,
5808 "setegid($module, egid, /)\n"
5809 "--\n"
5810 "\n"
5811 "Set the current process\'s effective group id.");
5812
5813 #define OS_SETEGID_METHODDEF \
5814 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
5815
5816 static PyObject *
5817 os_setegid_impl(PyObject *module, gid_t egid);
5818
5819 static PyObject *
5820 os_setegid(PyObject *module, PyObject *arg)
5821 {
5822 PyObject *return_value = NULL;
5823 gid_t egid;
5824
5825 if (!_Py_Gid_Converter(arg, &egid)) {
5826 goto exit;
5827 }
5828 return_value = os_setegid_impl(module, egid);
5829
5830 exit:
5831 return return_value;
5832 }
5833
5834 #endif /* defined(HAVE_SETEGID) */
5835
5836 #if defined(HAVE_SETREUID)
5837
5838 PyDoc_STRVAR(os_setreuid__doc__,
5839 "setreuid($module, ruid, euid, /)\n"
5840 "--\n"
5841 "\n"
5842 "Set the current process\'s real and effective user ids.");
5843
5844 #define OS_SETREUID_METHODDEF \
5845 {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
5846
5847 static PyObject *
5848 os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
5849
5850 static PyObject *
5851 os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5852 {
5853 PyObject *return_value = NULL;
5854 uid_t ruid;
5855 uid_t euid;
5856
5857 if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
5858 goto exit;
5859 }
5860 if (!_Py_Uid_Converter(args[0], &ruid)) {
5861 goto exit;
5862 }
5863 if (!_Py_Uid_Converter(args[1], &euid)) {
5864 goto exit;
5865 }
5866 return_value = os_setreuid_impl(module, ruid, euid);
5867
5868 exit:
5869 return return_value;
5870 }
5871
5872 #endif /* defined(HAVE_SETREUID) */
5873
5874 #if defined(HAVE_SETREGID)
5875
5876 PyDoc_STRVAR(os_setregid__doc__,
5877 "setregid($module, rgid, egid, /)\n"
5878 "--\n"
5879 "\n"
5880 "Set the current process\'s real and effective group ids.");
5881
5882 #define OS_SETREGID_METHODDEF \
5883 {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
5884
5885 static PyObject *
5886 os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
5887
5888 static PyObject *
5889 os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5890 {
5891 PyObject *return_value = NULL;
5892 gid_t rgid;
5893 gid_t egid;
5894
5895 if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
5896 goto exit;
5897 }
5898 if (!_Py_Gid_Converter(args[0], &rgid)) {
5899 goto exit;
5900 }
5901 if (!_Py_Gid_Converter(args[1], &egid)) {
5902 goto exit;
5903 }
5904 return_value = os_setregid_impl(module, rgid, egid);
5905
5906 exit:
5907 return return_value;
5908 }
5909
5910 #endif /* defined(HAVE_SETREGID) */
5911
5912 #if defined(HAVE_SETGID)
5913
5914 PyDoc_STRVAR(os_setgid__doc__,
5915 "setgid($module, gid, /)\n"
5916 "--\n"
5917 "\n"
5918 "Set the current process\'s group id.");
5919
5920 #define OS_SETGID_METHODDEF \
5921 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
5922
5923 static PyObject *
5924 os_setgid_impl(PyObject *module, gid_t gid);
5925
5926 static PyObject *
5927 os_setgid(PyObject *module, PyObject *arg)
5928 {
5929 PyObject *return_value = NULL;
5930 gid_t gid;
5931
5932 if (!_Py_Gid_Converter(arg, &gid)) {
5933 goto exit;
5934 }
5935 return_value = os_setgid_impl(module, gid);
5936
5937 exit:
5938 return return_value;
5939 }
5940
5941 #endif /* defined(HAVE_SETGID) */
5942
5943 #if defined(HAVE_SETGROUPS)
5944
5945 PyDoc_STRVAR(os_setgroups__doc__,
5946 "setgroups($module, groups, /)\n"
5947 "--\n"
5948 "\n"
5949 "Set the groups of the current process to list.");
5950
5951 #define OS_SETGROUPS_METHODDEF \
5952 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
5953
5954 #endif /* defined(HAVE_SETGROUPS) */
5955
5956 #if defined(HAVE_WAIT3)
5957
5958 PyDoc_STRVAR(os_wait3__doc__,
5959 "wait3($module, /, options)\n"
5960 "--\n"
5961 "\n"
5962 "Wait for completion of a child process.\n"
5963 "\n"
5964 "Returns a tuple of information about the child process:\n"
5965 " (pid, status, rusage)");
5966
5967 #define OS_WAIT3_METHODDEF \
5968 {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
5969
5970 static PyObject *
5971 os_wait3_impl(PyObject *module, int options);
5972
5973 static PyObject *
5974 os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5975 {
5976 PyObject *return_value = NULL;
5977 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5978
5979 #define NUM_KEYWORDS 1
5980 static struct {
5981 PyGC_Head _this_is_not_used;
5982 PyObject_VAR_HEAD
5983 Py_hash_t ob_hash;
5984 PyObject *ob_item[NUM_KEYWORDS];
5985 } _kwtuple = {
5986 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5987 .ob_hash = -1,
5988 .ob_item = { &_Py_ID(options), },
5989 };
5990 #undef NUM_KEYWORDS
5991 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5992
5993 #else // !Py_BUILD_CORE
5994 # define KWTUPLE NULL
5995 #endif // !Py_BUILD_CORE
5996
5997 static const char * const _keywords[] = {"options", NULL};
5998 static _PyArg_Parser _parser = {
5999 .keywords = _keywords,
6000 .fname = "wait3",
6001 .kwtuple = KWTUPLE,
6002 };
6003 #undef KWTUPLE
6004 PyObject *argsbuf[1];
6005 int options;
6006
6007 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6008 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6009 if (!args) {
6010 goto exit;
6011 }
6012 options = PyLong_AsInt(args[0]);
6013 if (options == -1 && PyErr_Occurred()) {
6014 goto exit;
6015 }
6016 return_value = os_wait3_impl(module, options);
6017
6018 exit:
6019 return return_value;
6020 }
6021
6022 #endif /* defined(HAVE_WAIT3) */
6023
6024 #if defined(HAVE_WAIT4)
6025
6026 PyDoc_STRVAR(os_wait4__doc__,
6027 "wait4($module, /, pid, options)\n"
6028 "--\n"
6029 "\n"
6030 "Wait for completion of a specific child process.\n"
6031 "\n"
6032 "Returns a tuple of information about the child process:\n"
6033 " (pid, status, rusage)");
6034
6035 #define OS_WAIT4_METHODDEF \
6036 {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
6037
6038 static PyObject *
6039 os_wait4_impl(PyObject *module, pid_t pid, int options);
6040
6041 static PyObject *
6042 os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6043 {
6044 PyObject *return_value = NULL;
6045 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6046
6047 #define NUM_KEYWORDS 2
6048 static struct {
6049 PyGC_Head _this_is_not_used;
6050 PyObject_VAR_HEAD
6051 Py_hash_t ob_hash;
6052 PyObject *ob_item[NUM_KEYWORDS];
6053 } _kwtuple = {
6054 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6055 .ob_hash = -1,
6056 .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
6057 };
6058 #undef NUM_KEYWORDS
6059 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6060
6061 #else // !Py_BUILD_CORE
6062 # define KWTUPLE NULL
6063 #endif // !Py_BUILD_CORE
6064
6065 static const char * const _keywords[] = {"pid", "options", NULL};
6066 static _PyArg_Parser _parser = {
6067 .keywords = _keywords,
6068 .fname = "wait4",
6069 .kwtuple = KWTUPLE,
6070 };
6071 #undef KWTUPLE
6072 PyObject *argsbuf[2];
6073 pid_t pid;
6074 int options;
6075
6076 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6077 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6078 if (!args) {
6079 goto exit;
6080 }
6081 pid = PyLong_AsPid(args[0]);
6082 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6083 goto exit;
6084 }
6085 options = PyLong_AsInt(args[1]);
6086 if (options == -1 && PyErr_Occurred()) {
6087 goto exit;
6088 }
6089 return_value = os_wait4_impl(module, pid, options);
6090
6091 exit:
6092 return return_value;
6093 }
6094
6095 #endif /* defined(HAVE_WAIT4) */
6096
6097 #if defined(HAVE_WAITID)
6098
6099 PyDoc_STRVAR(os_waitid__doc__,
6100 "waitid($module, idtype, id, options, /)\n"
6101 "--\n"
6102 "\n"
6103 "Returns the result of waiting for a process or processes.\n"
6104 "\n"
6105 " idtype\n"
6106 " Must be one of be P_PID, P_PGID or P_ALL.\n"
6107 " id\n"
6108 " The id to wait on.\n"
6109 " options\n"
6110 " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
6111 " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
6112 "\n"
6113 "Returns either waitid_result or None if WNOHANG is specified and there\n"
6114 "are no children in a waitable state.");
6115
6116 #define OS_WAITID_METHODDEF \
6117 {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
6118
6119 static PyObject *
6120 os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
6121
6122 static PyObject *
6123 os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6124 {
6125 PyObject *return_value = NULL;
6126 idtype_t idtype;
6127 id_t id;
6128 int options;
6129
6130 if (!_PyArg_CheckPositional("waitid", nargs, 3, 3)) {
6131 goto exit;
6132 }
6133 if (!idtype_t_converter(args[0], &idtype)) {
6134 goto exit;
6135 }
6136 id = (id_t)PyLong_AsPid(args[1]);
6137 if (id == (id_t)(-1) && PyErr_Occurred()) {
6138 goto exit;
6139 }
6140 options = PyLong_AsInt(args[2]);
6141 if (options == -1 && PyErr_Occurred()) {
6142 goto exit;
6143 }
6144 return_value = os_waitid_impl(module, idtype, id, options);
6145
6146 exit:
6147 return return_value;
6148 }
6149
6150 #endif /* defined(HAVE_WAITID) */
6151
6152 #if defined(HAVE_WAITPID)
6153
6154 PyDoc_STRVAR(os_waitpid__doc__,
6155 "waitpid($module, pid, options, /)\n"
6156 "--\n"
6157 "\n"
6158 "Wait for completion of a given child process.\n"
6159 "\n"
6160 "Returns a tuple of information regarding the child process:\n"
6161 " (pid, status)\n"
6162 "\n"
6163 "The options argument is ignored on Windows.");
6164
6165 #define OS_WAITPID_METHODDEF \
6166 {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6167
6168 static PyObject *
6169 os_waitpid_impl(PyObject *module, pid_t pid, int options);
6170
6171 static PyObject *
6172 os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6173 {
6174 PyObject *return_value = NULL;
6175 pid_t pid;
6176 int options;
6177
6178 if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6179 goto exit;
6180 }
6181 pid = PyLong_AsPid(args[0]);
6182 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6183 goto exit;
6184 }
6185 options = PyLong_AsInt(args[1]);
6186 if (options == -1 && PyErr_Occurred()) {
6187 goto exit;
6188 }
6189 return_value = os_waitpid_impl(module, pid, options);
6190
6191 exit:
6192 return return_value;
6193 }
6194
6195 #endif /* defined(HAVE_WAITPID) */
6196
6197 #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
6198
6199 PyDoc_STRVAR(os_waitpid__doc__,
6200 "waitpid($module, pid, options, /)\n"
6201 "--\n"
6202 "\n"
6203 "Wait for completion of a given process.\n"
6204 "\n"
6205 "Returns a tuple of information regarding the process:\n"
6206 " (pid, status << 8)\n"
6207 "\n"
6208 "The options argument is ignored on Windows.");
6209
6210 #define OS_WAITPID_METHODDEF \
6211 {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
6212
6213 static PyObject *
6214 os_waitpid_impl(PyObject *module, intptr_t pid, int options);
6215
6216 static PyObject *
6217 os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6218 {
6219 PyObject *return_value = NULL;
6220 intptr_t pid;
6221 int options;
6222
6223 if (!_PyArg_CheckPositional("waitpid", nargs, 2, 2)) {
6224 goto exit;
6225 }
6226 pid = (intptr_t)PyLong_AsVoidPtr(args[0]);
6227 if (!pid && PyErr_Occurred()) {
6228 goto exit;
6229 }
6230 options = PyLong_AsInt(args[1]);
6231 if (options == -1 && PyErr_Occurred()) {
6232 goto exit;
6233 }
6234 return_value = os_waitpid_impl(module, pid, options);
6235
6236 exit:
6237 return return_value;
6238 }
6239
6240 #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
6241
6242 #if defined(HAVE_WAIT)
6243
6244 PyDoc_STRVAR(os_wait__doc__,
6245 "wait($module, /)\n"
6246 "--\n"
6247 "\n"
6248 "Wait for completion of a child process.\n"
6249 "\n"
6250 "Returns a tuple of information about the child process:\n"
6251 " (pid, status)");
6252
6253 #define OS_WAIT_METHODDEF \
6254 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
6255
6256 static PyObject *
6257 os_wait_impl(PyObject *module);
6258
6259 static PyObject *
6260 os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
6261 {
6262 return os_wait_impl(module);
6263 }
6264
6265 #endif /* defined(HAVE_WAIT) */
6266
6267 #if (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))
6268
6269 PyDoc_STRVAR(os_pidfd_open__doc__,
6270 "pidfd_open($module, /, pid, flags=0)\n"
6271 "--\n"
6272 "\n"
6273 "Return a file descriptor referring to the process *pid*.\n"
6274 "\n"
6275 "The descriptor can be used to perform process management without races\n"
6276 "and signals.");
6277
6278 #define OS_PIDFD_OPEN_METHODDEF \
6279 {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
6280
6281 static PyObject *
6282 os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
6283
6284 static PyObject *
6285 os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6286 {
6287 PyObject *return_value = NULL;
6288 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6289
6290 #define NUM_KEYWORDS 2
6291 static struct {
6292 PyGC_Head _this_is_not_used;
6293 PyObject_VAR_HEAD
6294 Py_hash_t ob_hash;
6295 PyObject *ob_item[NUM_KEYWORDS];
6296 } _kwtuple = {
6297 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6298 .ob_hash = -1,
6299 .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
6300 };
6301 #undef NUM_KEYWORDS
6302 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6303
6304 #else // !Py_BUILD_CORE
6305 # define KWTUPLE NULL
6306 #endif // !Py_BUILD_CORE
6307
6308 static const char * const _keywords[] = {"pid", "flags", NULL};
6309 static _PyArg_Parser _parser = {
6310 .keywords = _keywords,
6311 .fname = "pidfd_open",
6312 .kwtuple = KWTUPLE,
6313 };
6314 #undef KWTUPLE
6315 PyObject *argsbuf[2];
6316 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6317 pid_t pid;
6318 unsigned int flags = 0;
6319
6320 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6321 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6322 if (!args) {
6323 goto exit;
6324 }
6325 pid = PyLong_AsPid(args[0]);
6326 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
6327 goto exit;
6328 }
6329 if (!noptargs) {
6330 goto skip_optional_pos;
6331 }
6332 if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) {
6333 goto exit;
6334 }
6335 skip_optional_pos:
6336 return_value = os_pidfd_open_impl(module, pid, flags);
6337
6338 exit:
6339 return return_value;
6340 }
6341
6342 #endif /* (defined(__linux__) && defined(__NR_pidfd_open) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */
6343
6344 #if defined(HAVE_SETNS)
6345
6346 PyDoc_STRVAR(os_setns__doc__,
6347 "setns($module, /, fd, nstype=0)\n"
6348 "--\n"
6349 "\n"
6350 "Move the calling thread into different namespaces.\n"
6351 "\n"
6352 " fd\n"
6353 " A file descriptor to a namespace.\n"
6354 " nstype\n"
6355 " Type of namespace.");
6356
6357 #define OS_SETNS_METHODDEF \
6358 {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
6359
6360 static PyObject *
6361 os_setns_impl(PyObject *module, int fd, int nstype);
6362
6363 static PyObject *
6364 os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6365 {
6366 PyObject *return_value = NULL;
6367 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6368
6369 #define NUM_KEYWORDS 2
6370 static struct {
6371 PyGC_Head _this_is_not_used;
6372 PyObject_VAR_HEAD
6373 Py_hash_t ob_hash;
6374 PyObject *ob_item[NUM_KEYWORDS];
6375 } _kwtuple = {
6376 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6377 .ob_hash = -1,
6378 .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
6379 };
6380 #undef NUM_KEYWORDS
6381 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6382
6383 #else // !Py_BUILD_CORE
6384 # define KWTUPLE NULL
6385 #endif // !Py_BUILD_CORE
6386
6387 static const char * const _keywords[] = {"fd", "nstype", NULL};
6388 static _PyArg_Parser _parser = {
6389 .keywords = _keywords,
6390 .fname = "setns",
6391 .kwtuple = KWTUPLE,
6392 };
6393 #undef KWTUPLE
6394 PyObject *argsbuf[2];
6395 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6396 int fd;
6397 int nstype = 0;
6398
6399 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6400 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6401 if (!args) {
6402 goto exit;
6403 }
6404 fd = PyObject_AsFileDescriptor(args[0]);
6405 if (fd < 0) {
6406 goto exit;
6407 }
6408 if (!noptargs) {
6409 goto skip_optional_pos;
6410 }
6411 nstype = PyLong_AsInt(args[1]);
6412 if (nstype == -1 && PyErr_Occurred()) {
6413 goto exit;
6414 }
6415 skip_optional_pos:
6416 return_value = os_setns_impl(module, fd, nstype);
6417
6418 exit:
6419 return return_value;
6420 }
6421
6422 #endif /* defined(HAVE_SETNS) */
6423
6424 #if defined(HAVE_UNSHARE)
6425
6426 PyDoc_STRVAR(os_unshare__doc__,
6427 "unshare($module, /, flags)\n"
6428 "--\n"
6429 "\n"
6430 "Disassociate parts of a process (or thread) execution context.\n"
6431 "\n"
6432 " flags\n"
6433 " Namespaces to be unshared.");
6434
6435 #define OS_UNSHARE_METHODDEF \
6436 {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
6437
6438 static PyObject *
6439 os_unshare_impl(PyObject *module, int flags);
6440
6441 static PyObject *
6442 os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6443 {
6444 PyObject *return_value = NULL;
6445 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6446
6447 #define NUM_KEYWORDS 1
6448 static struct {
6449 PyGC_Head _this_is_not_used;
6450 PyObject_VAR_HEAD
6451 Py_hash_t ob_hash;
6452 PyObject *ob_item[NUM_KEYWORDS];
6453 } _kwtuple = {
6454 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6455 .ob_hash = -1,
6456 .ob_item = { &_Py_ID(flags), },
6457 };
6458 #undef NUM_KEYWORDS
6459 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6460
6461 #else // !Py_BUILD_CORE
6462 # define KWTUPLE NULL
6463 #endif // !Py_BUILD_CORE
6464
6465 static const char * const _keywords[] = {"flags", NULL};
6466 static _PyArg_Parser _parser = {
6467 .keywords = _keywords,
6468 .fname = "unshare",
6469 .kwtuple = KWTUPLE,
6470 };
6471 #undef KWTUPLE
6472 PyObject *argsbuf[1];
6473 int flags;
6474
6475 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6476 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6477 if (!args) {
6478 goto exit;
6479 }
6480 flags = PyLong_AsInt(args[0]);
6481 if (flags == -1 && PyErr_Occurred()) {
6482 goto exit;
6483 }
6484 return_value = os_unshare_impl(module, flags);
6485
6486 exit:
6487 return return_value;
6488 }
6489
6490 #endif /* defined(HAVE_UNSHARE) */
6491
6492 #if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
6493
6494 PyDoc_STRVAR(os_readlink__doc__,
6495 "readlink($module, /, path, *, dir_fd=None)\n"
6496 "--\n"
6497 "\n"
6498 "Return a string representing the path to which the symbolic link points.\n"
6499 "\n"
6500 "If dir_fd is not None, it should be a file descriptor open to\n"
6501 "a directory, and path should be relative; path will then be relative to\n"
6502 "that directory.\n"
6503 "\n"
6504 "dir_fd may not be implemented on your platform. If it is unavailable,\n"
6505 "using it will raise a NotImplementedError.");
6506
6507 #define OS_READLINK_METHODDEF \
6508 {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
6509
6510 static PyObject *
6511 os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
6512
6513 static PyObject *
6514 os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6515 {
6516 PyObject *return_value = NULL;
6517 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6518
6519 #define NUM_KEYWORDS 2
6520 static struct {
6521 PyGC_Head _this_is_not_used;
6522 PyObject_VAR_HEAD
6523 Py_hash_t ob_hash;
6524 PyObject *ob_item[NUM_KEYWORDS];
6525 } _kwtuple = {
6526 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6527 .ob_hash = -1,
6528 .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
6529 };
6530 #undef NUM_KEYWORDS
6531 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6532
6533 #else // !Py_BUILD_CORE
6534 # define KWTUPLE NULL
6535 #endif // !Py_BUILD_CORE
6536
6537 static const char * const _keywords[] = {"path", "dir_fd", NULL};
6538 static _PyArg_Parser _parser = {
6539 .keywords = _keywords,
6540 .fname = "readlink",
6541 .kwtuple = KWTUPLE,
6542 };
6543 #undef KWTUPLE
6544 PyObject *argsbuf[2];
6545 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6546 path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
6547 int dir_fd = DEFAULT_DIR_FD;
6548
6549 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6550 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6551 if (!args) {
6552 goto exit;
6553 }
6554 if (!path_converter(args[0], &path)) {
6555 goto exit;
6556 }
6557 if (!noptargs) {
6558 goto skip_optional_kwonly;
6559 }
6560 if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
6561 goto exit;
6562 }
6563 skip_optional_kwonly:
6564 return_value = os_readlink_impl(module, &path, dir_fd);
6565
6566 exit:
6567 /* Cleanup for path */
6568 path_cleanup(&path);
6569
6570 return return_value;
6571 }
6572
6573 #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
6574
6575 #if defined(HAVE_SYMLINK)
6576
6577 PyDoc_STRVAR(os_symlink__doc__,
6578 "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
6579 "--\n"
6580 "\n"
6581 "Create a symbolic link pointing to src named dst.\n"
6582 "\n"
6583 "target_is_directory is required on Windows if the target is to be\n"
6584 "interpreted as a directory. (On Windows, symlink requires Windows 6.0\n"
6585 "or greater, and raises a NotImplementedError otherwise.)\n"
6586 "target_is_directory is ignored on non-Windows platforms.\n"
6587 "\n"
6588 "If dir_fd is not None, it should be a file descriptor open to\n"
6589 "a directory, and path should be relative; path will then be relative\n"
6590 "to that directory.\n"
6591 "dir_fd may not be implemented on your platform. If it is unavailable,\n"
6592 "using it will raise a NotImplementedError.");
6593
6594 #define OS_SYMLINK_METHODDEF \
6595 {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
6596
6597 static PyObject *
6598 os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
6599 int target_is_directory, int dir_fd);
6600
6601 static PyObject *
6602 os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6603 {
6604 PyObject *return_value = NULL;
6605 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6606
6607 #define NUM_KEYWORDS 4
6608 static struct {
6609 PyGC_Head _this_is_not_used;
6610 PyObject_VAR_HEAD
6611 Py_hash_t ob_hash;
6612 PyObject *ob_item[NUM_KEYWORDS];
6613 } _kwtuple = {
6614 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6615 .ob_hash = -1,
6616 .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
6617 };
6618 #undef NUM_KEYWORDS
6619 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6620
6621 #else // !Py_BUILD_CORE
6622 # define KWTUPLE NULL
6623 #endif // !Py_BUILD_CORE
6624
6625 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
6626 static _PyArg_Parser _parser = {
6627 .keywords = _keywords,
6628 .fname = "symlink",
6629 .kwtuple = KWTUPLE,
6630 };
6631 #undef KWTUPLE
6632 PyObject *argsbuf[4];
6633 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6634 path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
6635 path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
6636 int target_is_directory = 0;
6637 int dir_fd = DEFAULT_DIR_FD;
6638
6639 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6640 /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6641 if (!args) {
6642 goto exit;
6643 }
6644 if (!path_converter(args[0], &src)) {
6645 goto exit;
6646 }
6647 if (!path_converter(args[1], &dst)) {
6648 goto exit;
6649 }
6650 if (!noptargs) {
6651 goto skip_optional_pos;
6652 }
6653 if (args[2]) {
6654 target_is_directory = PyObject_IsTrue(args[2]);
6655 if (target_is_directory < 0) {
6656 goto exit;
6657 }
6658 if (!--noptargs) {
6659 goto skip_optional_pos;
6660 }
6661 }
6662 skip_optional_pos:
6663 if (!noptargs) {
6664 goto skip_optional_kwonly;
6665 }
6666 if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
6667 goto exit;
6668 }
6669 skip_optional_kwonly:
6670 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
6671
6672 exit:
6673 /* Cleanup for src */
6674 path_cleanup(&src);
6675 /* Cleanup for dst */
6676 path_cleanup(&dst);
6677
6678 return return_value;
6679 }
6680
6681 #endif /* defined(HAVE_SYMLINK) */
6682
6683 PyDoc_STRVAR(os_times__doc__,
6684 "times($module, /)\n"
6685 "--\n"
6686 "\n"
6687 "Return a collection containing process timing information.\n"
6688 "\n"
6689 "The object returned behaves like a named tuple with these fields:\n"
6690 " (utime, stime, cutime, cstime, elapsed_time)\n"
6691 "All fields are floating-point numbers.");
6692
6693 #define OS_TIMES_METHODDEF \
6694 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
6695
6696 static PyObject *
6697 os_times_impl(PyObject *module);
6698
6699 static PyObject *
6700 os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
6701 {
6702 return os_times_impl(module);
6703 }
6704
6705 #if defined(HAVE_TIMERFD_CREATE)
6706
6707 PyDoc_STRVAR(os_timerfd_create__doc__,
6708 "timerfd_create($module, clockid, /, *, flags=0)\n"
6709 "--\n"
6710 "\n"
6711 "Create and return a timer file descriptor.\n"
6712 "\n"
6713 " clockid\n"
6714 " A valid clock ID constant as timer file descriptor.\n"
6715 "\n"
6716 " time.CLOCK_REALTIME\n"
6717 " time.CLOCK_MONOTONIC\n"
6718 " time.CLOCK_BOOTTIME\n"
6719 " flags\n"
6720 " 0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC.\n"
6721 "\n"
6722 " os.TFD_NONBLOCK\n"
6723 " If *TFD_NONBLOCK* is set as a flag, read doesn\'t blocks.\n"
6724 " If *TFD_NONBLOCK* is not set as a flag, read block until the timer fires.\n"
6725 "\n"
6726 " os.TFD_CLOEXEC\n"
6727 " If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag");
6728
6729 #define OS_TIMERFD_CREATE_METHODDEF \
6730 {"timerfd_create", _PyCFunction_CAST(os_timerfd_create), METH_FASTCALL|METH_KEYWORDS, os_timerfd_create__doc__},
6731
6732 static PyObject *
6733 os_timerfd_create_impl(PyObject *module, int clockid, int flags);
6734
6735 static PyObject *
6736 os_timerfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6737 {
6738 PyObject *return_value = NULL;
6739 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6740
6741 #define NUM_KEYWORDS 1
6742 static struct {
6743 PyGC_Head _this_is_not_used;
6744 PyObject_VAR_HEAD
6745 Py_hash_t ob_hash;
6746 PyObject *ob_item[NUM_KEYWORDS];
6747 } _kwtuple = {
6748 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6749 .ob_hash = -1,
6750 .ob_item = { &_Py_ID(flags), },
6751 };
6752 #undef NUM_KEYWORDS
6753 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6754
6755 #else // !Py_BUILD_CORE
6756 # define KWTUPLE NULL
6757 #endif // !Py_BUILD_CORE
6758
6759 static const char * const _keywords[] = {"", "flags", NULL};
6760 static _PyArg_Parser _parser = {
6761 .keywords = _keywords,
6762 .fname = "timerfd_create",
6763 .kwtuple = KWTUPLE,
6764 };
6765 #undef KWTUPLE
6766 PyObject *argsbuf[2];
6767 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6768 int clockid;
6769 int flags = 0;
6770
6771 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6772 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6773 if (!args) {
6774 goto exit;
6775 }
6776 clockid = PyLong_AsInt(args[0]);
6777 if (clockid == -1 && PyErr_Occurred()) {
6778 goto exit;
6779 }
6780 if (!noptargs) {
6781 goto skip_optional_kwonly;
6782 }
6783 flags = PyLong_AsInt(args[1]);
6784 if (flags == -1 && PyErr_Occurred()) {
6785 goto exit;
6786 }
6787 skip_optional_kwonly:
6788 return_value = os_timerfd_create_impl(module, clockid, flags);
6789
6790 exit:
6791 return return_value;
6792 }
6793
6794 #endif /* defined(HAVE_TIMERFD_CREATE) */
6795
6796 #if defined(HAVE_TIMERFD_CREATE)
6797
6798 PyDoc_STRVAR(os_timerfd_settime__doc__,
6799 "timerfd_settime($module, fd, /, *, flags=0, initial=0.0, interval=0.0)\n"
6800 "--\n"
6801 "\n"
6802 "Alter a timer file descriptor\'s internal timer in seconds.\n"
6803 "\n"
6804 " fd\n"
6805 " A timer file descriptor.\n"
6806 " flags\n"
6807 " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6808 " initial\n"
6809 " The initial expiration time, in seconds.\n"
6810 " interval\n"
6811 " The timer\'s interval, in seconds.");
6812
6813 #define OS_TIMERFD_SETTIME_METHODDEF \
6814 {"timerfd_settime", _PyCFunction_CAST(os_timerfd_settime), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime__doc__},
6815
6816 static PyObject *
6817 os_timerfd_settime_impl(PyObject *module, int fd, int flags,
6818 double initial_double, double interval_double);
6819
6820 static PyObject *
6821 os_timerfd_settime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6822 {
6823 PyObject *return_value = NULL;
6824 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6825
6826 #define NUM_KEYWORDS 3
6827 static struct {
6828 PyGC_Head _this_is_not_used;
6829 PyObject_VAR_HEAD
6830 Py_hash_t ob_hash;
6831 PyObject *ob_item[NUM_KEYWORDS];
6832 } _kwtuple = {
6833 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6834 .ob_hash = -1,
6835 .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6836 };
6837 #undef NUM_KEYWORDS
6838 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6839
6840 #else // !Py_BUILD_CORE
6841 # define KWTUPLE NULL
6842 #endif // !Py_BUILD_CORE
6843
6844 static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6845 static _PyArg_Parser _parser = {
6846 .keywords = _keywords,
6847 .fname = "timerfd_settime",
6848 .kwtuple = KWTUPLE,
6849 };
6850 #undef KWTUPLE
6851 PyObject *argsbuf[4];
6852 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6853 int fd;
6854 int flags = 0;
6855 double initial_double = 0.0;
6856 double interval_double = 0.0;
6857
6858 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6859 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6860 if (!args) {
6861 goto exit;
6862 }
6863 fd = PyObject_AsFileDescriptor(args[0]);
6864 if (fd < 0) {
6865 goto exit;
6866 }
6867 if (!noptargs) {
6868 goto skip_optional_kwonly;
6869 }
6870 if (args[1]) {
6871 flags = PyLong_AsInt(args[1]);
6872 if (flags == -1 && PyErr_Occurred()) {
6873 goto exit;
6874 }
6875 if (!--noptargs) {
6876 goto skip_optional_kwonly;
6877 }
6878 }
6879 if (args[2]) {
6880 if (PyFloat_CheckExact(args[2])) {
6881 initial_double = PyFloat_AS_DOUBLE(args[2]);
6882 }
6883 else
6884 {
6885 initial_double = PyFloat_AsDouble(args[2]);
6886 if (initial_double == -1.0 && PyErr_Occurred()) {
6887 goto exit;
6888 }
6889 }
6890 if (!--noptargs) {
6891 goto skip_optional_kwonly;
6892 }
6893 }
6894 if (PyFloat_CheckExact(args[3])) {
6895 interval_double = PyFloat_AS_DOUBLE(args[3]);
6896 }
6897 else
6898 {
6899 interval_double = PyFloat_AsDouble(args[3]);
6900 if (interval_double == -1.0 && PyErr_Occurred()) {
6901 goto exit;
6902 }
6903 }
6904 skip_optional_kwonly:
6905 return_value = os_timerfd_settime_impl(module, fd, flags, initial_double, interval_double);
6906
6907 exit:
6908 return return_value;
6909 }
6910
6911 #endif /* defined(HAVE_TIMERFD_CREATE) */
6912
6913 #if defined(HAVE_TIMERFD_CREATE)
6914
6915 PyDoc_STRVAR(os_timerfd_settime_ns__doc__,
6916 "timerfd_settime_ns($module, fd, /, *, flags=0, initial=0, interval=0)\n"
6917 "--\n"
6918 "\n"
6919 "Alter a timer file descriptor\'s internal timer in nanoseconds.\n"
6920 "\n"
6921 " fd\n"
6922 " A timer file descriptor.\n"
6923 " flags\n"
6924 " 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.\n"
6925 " initial\n"
6926 " initial expiration timing in seconds.\n"
6927 " interval\n"
6928 " interval for the timer in seconds.");
6929
6930 #define OS_TIMERFD_SETTIME_NS_METHODDEF \
6931 {"timerfd_settime_ns", _PyCFunction_CAST(os_timerfd_settime_ns), METH_FASTCALL|METH_KEYWORDS, os_timerfd_settime_ns__doc__},
6932
6933 static PyObject *
6934 os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags,
6935 long long initial, long long interval);
6936
6937 static PyObject *
6938 os_timerfd_settime_ns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6939 {
6940 PyObject *return_value = NULL;
6941 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6942
6943 #define NUM_KEYWORDS 3
6944 static struct {
6945 PyGC_Head _this_is_not_used;
6946 PyObject_VAR_HEAD
6947 Py_hash_t ob_hash;
6948 PyObject *ob_item[NUM_KEYWORDS];
6949 } _kwtuple = {
6950 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6951 .ob_hash = -1,
6952 .ob_item = { &_Py_ID(flags), &_Py_ID(initial), &_Py_ID(interval), },
6953 };
6954 #undef NUM_KEYWORDS
6955 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6956
6957 #else // !Py_BUILD_CORE
6958 # define KWTUPLE NULL
6959 #endif // !Py_BUILD_CORE
6960
6961 static const char * const _keywords[] = {"", "flags", "initial", "interval", NULL};
6962 static _PyArg_Parser _parser = {
6963 .keywords = _keywords,
6964 .fname = "timerfd_settime_ns",
6965 .kwtuple = KWTUPLE,
6966 };
6967 #undef KWTUPLE
6968 PyObject *argsbuf[4];
6969 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
6970 int fd;
6971 int flags = 0;
6972 long long initial = 0;
6973 long long interval = 0;
6974
6975 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
6976 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
6977 if (!args) {
6978 goto exit;
6979 }
6980 fd = PyObject_AsFileDescriptor(args[0]);
6981 if (fd < 0) {
6982 goto exit;
6983 }
6984 if (!noptargs) {
6985 goto skip_optional_kwonly;
6986 }
6987 if (args[1]) {
6988 flags = PyLong_AsInt(args[1]);
6989 if (flags == -1 && PyErr_Occurred()) {
6990 goto exit;
6991 }
6992 if (!--noptargs) {
6993 goto skip_optional_kwonly;
6994 }
6995 }
6996 if (args[2]) {
6997 initial = PyLong_AsLongLong(args[2]);
6998 if (initial == -1 && PyErr_Occurred()) {
6999 goto exit;
7000 }
7001 if (!--noptargs) {
7002 goto skip_optional_kwonly;
7003 }
7004 }
7005 interval = PyLong_AsLongLong(args[3]);
7006 if (interval == -1 && PyErr_Occurred()) {
7007 goto exit;
7008 }
7009 skip_optional_kwonly:
7010 return_value = os_timerfd_settime_ns_impl(module, fd, flags, initial, interval);
7011
7012 exit:
7013 return return_value;
7014 }
7015
7016 #endif /* defined(HAVE_TIMERFD_CREATE) */
7017
7018 #if defined(HAVE_TIMERFD_CREATE)
7019
7020 PyDoc_STRVAR(os_timerfd_gettime__doc__,
7021 "timerfd_gettime($module, fd, /)\n"
7022 "--\n"
7023 "\n"
7024 "Return a tuple of a timer file descriptor\'s (interval, next expiration) in float seconds.\n"
7025 "\n"
7026 " fd\n"
7027 " A timer file descriptor.");
7028
7029 #define OS_TIMERFD_GETTIME_METHODDEF \
7030 {"timerfd_gettime", (PyCFunction)os_timerfd_gettime, METH_O, os_timerfd_gettime__doc__},
7031
7032 static PyObject *
7033 os_timerfd_gettime_impl(PyObject *module, int fd);
7034
7035 static PyObject *
7036 os_timerfd_gettime(PyObject *module, PyObject *arg)
7037 {
7038 PyObject *return_value = NULL;
7039 int fd;
7040
7041 fd = PyObject_AsFileDescriptor(arg);
7042 if (fd < 0) {
7043 goto exit;
7044 }
7045 return_value = os_timerfd_gettime_impl(module, fd);
7046
7047 exit:
7048 return return_value;
7049 }
7050
7051 #endif /* defined(HAVE_TIMERFD_CREATE) */
7052
7053 #if defined(HAVE_TIMERFD_CREATE)
7054
7055 PyDoc_STRVAR(os_timerfd_gettime_ns__doc__,
7056 "timerfd_gettime_ns($module, fd, /)\n"
7057 "--\n"
7058 "\n"
7059 "Return a tuple of a timer file descriptor\'s (interval, next expiration) in nanoseconds.\n"
7060 "\n"
7061 " fd\n"
7062 " A timer file descriptor.");
7063
7064 #define OS_TIMERFD_GETTIME_NS_METHODDEF \
7065 {"timerfd_gettime_ns", (PyCFunction)os_timerfd_gettime_ns, METH_O, os_timerfd_gettime_ns__doc__},
7066
7067 static PyObject *
7068 os_timerfd_gettime_ns_impl(PyObject *module, int fd);
7069
7070 static PyObject *
7071 os_timerfd_gettime_ns(PyObject *module, PyObject *arg)
7072 {
7073 PyObject *return_value = NULL;
7074 int fd;
7075
7076 fd = PyObject_AsFileDescriptor(arg);
7077 if (fd < 0) {
7078 goto exit;
7079 }
7080 return_value = os_timerfd_gettime_ns_impl(module, fd);
7081
7082 exit:
7083 return return_value;
7084 }
7085
7086 #endif /* defined(HAVE_TIMERFD_CREATE) */
7087
7088 #if defined(HAVE_GETSID)
7089
7090 PyDoc_STRVAR(os_getsid__doc__,
7091 "getsid($module, pid, /)\n"
7092 "--\n"
7093 "\n"
7094 "Call the system call getsid(pid) and return the result.");
7095
7096 #define OS_GETSID_METHODDEF \
7097 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
7098
7099 static PyObject *
7100 os_getsid_impl(PyObject *module, pid_t pid);
7101
7102 static PyObject *
7103 os_getsid(PyObject *module, PyObject *arg)
7104 {
7105 PyObject *return_value = NULL;
7106 pid_t pid;
7107
7108 pid = PyLong_AsPid(arg);
7109 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7110 goto exit;
7111 }
7112 return_value = os_getsid_impl(module, pid);
7113
7114 exit:
7115 return return_value;
7116 }
7117
7118 #endif /* defined(HAVE_GETSID) */
7119
7120 #if defined(HAVE_SETSID)
7121
7122 PyDoc_STRVAR(os_setsid__doc__,
7123 "setsid($module, /)\n"
7124 "--\n"
7125 "\n"
7126 "Call the system call setsid().");
7127
7128 #define OS_SETSID_METHODDEF \
7129 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
7130
7131 static PyObject *
7132 os_setsid_impl(PyObject *module);
7133
7134 static PyObject *
7135 os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
7136 {
7137 return os_setsid_impl(module);
7138 }
7139
7140 #endif /* defined(HAVE_SETSID) */
7141
7142 #if defined(HAVE_SETPGID)
7143
7144 PyDoc_STRVAR(os_setpgid__doc__,
7145 "setpgid($module, pid, pgrp, /)\n"
7146 "--\n"
7147 "\n"
7148 "Call the system call setpgid(pid, pgrp).");
7149
7150 #define OS_SETPGID_METHODDEF \
7151 {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
7152
7153 static PyObject *
7154 os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
7155
7156 static PyObject *
7157 os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7158 {
7159 PyObject *return_value = NULL;
7160 pid_t pid;
7161 pid_t pgrp;
7162
7163 if (!_PyArg_CheckPositional("setpgid", nargs, 2, 2)) {
7164 goto exit;
7165 }
7166 pid = PyLong_AsPid(args[0]);
7167 if (pid == (pid_t)(-1) && PyErr_Occurred()) {
7168 goto exit;
7169 }
7170 pgrp = PyLong_AsPid(args[1]);
7171 if (pgrp == (pid_t)(-1) && PyErr_Occurred()) {
7172 goto exit;
7173 }
7174 return_value = os_setpgid_impl(module, pid, pgrp);
7175
7176 exit:
7177 return return_value;
7178 }
7179
7180 #endif /* defined(HAVE_SETPGID) */
7181
7182 #if defined(HAVE_TCGETPGRP)
7183
7184 PyDoc_STRVAR(os_tcgetpgrp__doc__,
7185 "tcgetpgrp($module, fd, /)\n"
7186 "--\n"
7187 "\n"
7188 "Return the process group associated with the terminal specified by fd.");
7189
7190 #define OS_TCGETPGRP_METHODDEF \
7191 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
7192
7193 static PyObject *
7194 os_tcgetpgrp_impl(PyObject *module, int fd);
7195
7196 static PyObject *
7197 os_tcgetpgrp(PyObject *module, PyObject *arg)
7198 {
7199 PyObject *return_value = NULL;
7200 int fd;
7201
7202 fd = PyLong_AsInt(arg);
7203 if (fd == -1 && PyErr_Occurred()) {
7204 goto exit;
7205 }
7206 return_value = os_tcgetpgrp_impl(module, fd);
7207
7208 exit:
7209 return return_value;
7210 }
7211
7212 #endif /* defined(HAVE_TCGETPGRP) */
7213
7214 #if defined(HAVE_TCSETPGRP)
7215
7216 PyDoc_STRVAR(os_tcsetpgrp__doc__,
7217 "tcsetpgrp($module, fd, pgid, /)\n"
7218 "--\n"
7219 "\n"
7220 "Set the process group associated with the terminal specified by fd.");
7221
7222 #define OS_TCSETPGRP_METHODDEF \
7223 {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
7224
7225 static PyObject *
7226 os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
7227
7228 static PyObject *
7229 os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7230 {
7231 PyObject *return_value = NULL;
7232 int fd;
7233 pid_t pgid;
7234
7235 if (!_PyArg_CheckPositional("tcsetpgrp", nargs, 2, 2)) {
7236 goto exit;
7237 }
7238 fd = PyLong_AsInt(args[0]);
7239 if (fd == -1 && PyErr_Occurred()) {
7240 goto exit;
7241 }
7242 pgid = PyLong_AsPid(args[1]);
7243 if (pgid == (pid_t)(-1) && PyErr_Occurred()) {
7244 goto exit;
7245 }
7246 return_value = os_tcsetpgrp_impl(module, fd, pgid);
7247
7248 exit:
7249 return return_value;
7250 }
7251
7252 #endif /* defined(HAVE_TCSETPGRP) */
7253
7254 PyDoc_STRVAR(os_open__doc__,
7255 "open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
7256 "--\n"
7257 "\n"
7258 "Open a file for low level IO. Returns a file descriptor (integer).\n"
7259 "\n"
7260 "If dir_fd is not None, it should be a file descriptor open to\n"
7261 "a directory, and path should be relative; path will then be relative to\n"
7262 "that directory.\n"
7263 "dir_fd may not be implemented on your platform. If it is unavailable,\n"
7264 "using it will raise a NotImplementedError.");
7265
7266 #define OS_OPEN_METHODDEF \
7267 {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
7268
7269 static int
7270 os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
7271
7272 static PyObject *
7273 os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7274 {
7275 PyObject *return_value = NULL;
7276 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7277
7278 #define NUM_KEYWORDS 4
7279 static struct {
7280 PyGC_Head _this_is_not_used;
7281 PyObject_VAR_HEAD
7282 Py_hash_t ob_hash;
7283 PyObject *ob_item[NUM_KEYWORDS];
7284 } _kwtuple = {
7285 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7286 .ob_hash = -1,
7287 .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
7288 };
7289 #undef NUM_KEYWORDS
7290 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7291
7292 #else // !Py_BUILD_CORE
7293 # define KWTUPLE NULL
7294 #endif // !Py_BUILD_CORE
7295
7296 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
7297 static _PyArg_Parser _parser = {
7298 .keywords = _keywords,
7299 .fname = "open",
7300 .kwtuple = KWTUPLE,
7301 };
7302 #undef KWTUPLE
7303 PyObject *argsbuf[4];
7304 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7305 path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
7306 int flags;
7307 int mode = 511;
7308 int dir_fd = DEFAULT_DIR_FD;
7309 int _return_value;
7310
7311 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7312 /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7313 if (!args) {
7314 goto exit;
7315 }
7316 if (!path_converter(args[0], &path)) {
7317 goto exit;
7318 }
7319 flags = PyLong_AsInt(args[1]);
7320 if (flags == -1 && PyErr_Occurred()) {
7321 goto exit;
7322 }
7323 if (!noptargs) {
7324 goto skip_optional_pos;
7325 }
7326 if (args[2]) {
7327 mode = PyLong_AsInt(args[2]);
7328 if (mode == -1 && PyErr_Occurred()) {
7329 goto exit;
7330 }
7331 if (!--noptargs) {
7332 goto skip_optional_pos;
7333 }
7334 }
7335 skip_optional_pos:
7336 if (!noptargs) {
7337 goto skip_optional_kwonly;
7338 }
7339 if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
7340 goto exit;
7341 }
7342 skip_optional_kwonly:
7343 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
7344 if ((_return_value == -1) && PyErr_Occurred()) {
7345 goto exit;
7346 }
7347 return_value = PyLong_FromLong((long)_return_value);
7348
7349 exit:
7350 /* Cleanup for path */
7351 path_cleanup(&path);
7352
7353 return return_value;
7354 }
7355
7356 PyDoc_STRVAR(os_close__doc__,
7357 "close($module, /, fd)\n"
7358 "--\n"
7359 "\n"
7360 "Close a file descriptor.");
7361
7362 #define OS_CLOSE_METHODDEF \
7363 {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
7364
7365 static PyObject *
7366 os_close_impl(PyObject *module, int fd);
7367
7368 static PyObject *
7369 os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7370 {
7371 PyObject *return_value = NULL;
7372 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7373
7374 #define NUM_KEYWORDS 1
7375 static struct {
7376 PyGC_Head _this_is_not_used;
7377 PyObject_VAR_HEAD
7378 Py_hash_t ob_hash;
7379 PyObject *ob_item[NUM_KEYWORDS];
7380 } _kwtuple = {
7381 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7382 .ob_hash = -1,
7383 .ob_item = { &_Py_ID(fd), },
7384 };
7385 #undef NUM_KEYWORDS
7386 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7387
7388 #else // !Py_BUILD_CORE
7389 # define KWTUPLE NULL
7390 #endif // !Py_BUILD_CORE
7391
7392 static const char * const _keywords[] = {"fd", NULL};
7393 static _PyArg_Parser _parser = {
7394 .keywords = _keywords,
7395 .fname = "close",
7396 .kwtuple = KWTUPLE,
7397 };
7398 #undef KWTUPLE
7399 PyObject *argsbuf[1];
7400 int fd;
7401
7402 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7403 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7404 if (!args) {
7405 goto exit;
7406 }
7407 fd = PyLong_AsInt(args[0]);
7408 if (fd == -1 && PyErr_Occurred()) {
7409 goto exit;
7410 }
7411 return_value = os_close_impl(module, fd);
7412
7413 exit:
7414 return return_value;
7415 }
7416
7417 PyDoc_STRVAR(os_closerange__doc__,
7418 "closerange($module, fd_low, fd_high, /)\n"
7419 "--\n"
7420 "\n"
7421 "Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
7422
7423 #define OS_CLOSERANGE_METHODDEF \
7424 {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
7425
7426 static PyObject *
7427 os_closerange_impl(PyObject *module, int fd_low, int fd_high);
7428
7429 static PyObject *
7430 os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7431 {
7432 PyObject *return_value = NULL;
7433 int fd_low;
7434 int fd_high;
7435
7436 if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
7437 goto exit;
7438 }
7439 fd_low = PyLong_AsInt(args[0]);
7440 if (fd_low == -1 && PyErr_Occurred()) {
7441 goto exit;
7442 }
7443 fd_high = PyLong_AsInt(args[1]);
7444 if (fd_high == -1 && PyErr_Occurred()) {
7445 goto exit;
7446 }
7447 return_value = os_closerange_impl(module, fd_low, fd_high);
7448
7449 exit:
7450 return return_value;
7451 }
7452
7453 PyDoc_STRVAR(os_dup__doc__,
7454 "dup($module, fd, /)\n"
7455 "--\n"
7456 "\n"
7457 "Return a duplicate of a file descriptor.");
7458
7459 #define OS_DUP_METHODDEF \
7460 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
7461
7462 static int
7463 os_dup_impl(PyObject *module, int fd);
7464
7465 static PyObject *
7466 os_dup(PyObject *module, PyObject *arg)
7467 {
7468 PyObject *return_value = NULL;
7469 int fd;
7470 int _return_value;
7471
7472 fd = PyLong_AsInt(arg);
7473 if (fd == -1 && PyErr_Occurred()) {
7474 goto exit;
7475 }
7476 _return_value = os_dup_impl(module, fd);
7477 if ((_return_value == -1) && PyErr_Occurred()) {
7478 goto exit;
7479 }
7480 return_value = PyLong_FromLong((long)_return_value);
7481
7482 exit:
7483 return return_value;
7484 }
7485
7486 #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
7487
7488 PyDoc_STRVAR(os_dup2__doc__,
7489 "dup2($module, /, fd, fd2, inheritable=True)\n"
7490 "--\n"
7491 "\n"
7492 "Duplicate file descriptor.");
7493
7494 #define OS_DUP2_METHODDEF \
7495 {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
7496
7497 static int
7498 os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
7499
7500 static PyObject *
7501 os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7502 {
7503 PyObject *return_value = NULL;
7504 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7505
7506 #define NUM_KEYWORDS 3
7507 static struct {
7508 PyGC_Head _this_is_not_used;
7509 PyObject_VAR_HEAD
7510 Py_hash_t ob_hash;
7511 PyObject *ob_item[NUM_KEYWORDS];
7512 } _kwtuple = {
7513 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7514 .ob_hash = -1,
7515 .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
7516 };
7517 #undef NUM_KEYWORDS
7518 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7519
7520 #else // !Py_BUILD_CORE
7521 # define KWTUPLE NULL
7522 #endif // !Py_BUILD_CORE
7523
7524 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
7525 static _PyArg_Parser _parser = {
7526 .keywords = _keywords,
7527 .fname = "dup2",
7528 .kwtuple = KWTUPLE,
7529 };
7530 #undef KWTUPLE
7531 PyObject *argsbuf[3];
7532 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
7533 int fd;
7534 int fd2;
7535 int inheritable = 1;
7536 int _return_value;
7537
7538 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
7539 /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
7540 if (!args) {
7541 goto exit;
7542 }
7543 fd = PyLong_AsInt(args[0]);
7544 if (fd == -1 && PyErr_Occurred()) {
7545 goto exit;
7546 }
7547 fd2 = PyLong_AsInt(args[1]);
7548 if (fd2 == -1 && PyErr_Occurred()) {
7549 goto exit;
7550 }
7551 if (!noptargs) {
7552 goto skip_optional_pos;
7553 }
7554 inheritable = PyObject_IsTrue(args[2]);
7555 if (inheritable < 0) {
7556 goto exit;
7557 }
7558 skip_optional_pos:
7559 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
7560 if ((_return_value == -1) && PyErr_Occurred()) {
7561 goto exit;
7562 }
7563 return_value = PyLong_FromLong((long)_return_value);
7564
7565 exit:
7566 return return_value;
7567 }
7568
7569 #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
7570
7571 #if defined(HAVE_LOCKF)
7572
7573 PyDoc_STRVAR(os_lockf__doc__,
7574 "lockf($module, fd, command, length, /)\n"
7575 "--\n"
7576 "\n"
7577 "Apply, test or remove a POSIX lock on an open file descriptor.\n"
7578 "\n"
7579 " fd\n"
7580 " An open file descriptor.\n"
7581 " command\n"
7582 " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
7583 " length\n"
7584 " The number of bytes to lock, starting at the current position.");
7585
7586 #define OS_LOCKF_METHODDEF \
7587 {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
7588
7589 static PyObject *
7590 os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
7591
7592 static PyObject *
7593 os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7594 {
7595 PyObject *return_value = NULL;
7596 int fd;
7597 int command;
7598 Py_off_t length;
7599
7600 if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
7601 goto exit;
7602 }
7603 fd = PyLong_AsInt(args[0]);
7604 if (fd == -1 && PyErr_Occurred()) {
7605 goto exit;
7606 }
7607 command = PyLong_AsInt(args[1]);
7608 if (command == -1 && PyErr_Occurred()) {
7609 goto exit;
7610 }
7611 if (!Py_off_t_converter(args[2], &length)) {
7612 goto exit;
7613 }
7614 return_value = os_lockf_impl(module, fd, command, length);
7615
7616 exit:
7617 return return_value;
7618 }
7619
7620 #endif /* defined(HAVE_LOCKF) */
7621
7622 PyDoc_STRVAR(os_lseek__doc__,
7623 "lseek($module, fd, position, whence, /)\n"
7624 "--\n"
7625 "\n"
7626 "Set the position of a file descriptor. Return the new position.\n"
7627 "\n"
7628 " fd\n"
7629 " An open file descriptor, as returned by os.open().\n"
7630 " position\n"
7631 " Position, interpreted relative to \'whence\'.\n"
7632 " whence\n"
7633 " The relative position to seek from. Valid values are:\n"
7634 " - SEEK_SET: seek from the start of the file.\n"
7635 " - SEEK_CUR: seek from the current file position.\n"
7636 " - SEEK_END: seek from the end of the file.\n"
7637 "\n"
7638 "The return value is the number of bytes relative to the beginning of\n"
7639 "the file.");
7640
7641 #define OS_LSEEK_METHODDEF \
7642 {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
7643
7644 static Py_off_t
7645 os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
7646
7647 static PyObject *
7648 os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7649 {
7650 PyObject *return_value = NULL;
7651 int fd;
7652 Py_off_t position;
7653 int how;
7654 Py_off_t _return_value;
7655
7656 if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
7657 goto exit;
7658 }
7659 fd = PyLong_AsInt(args[0]);
7660 if (fd == -1 && PyErr_Occurred()) {
7661 goto exit;
7662 }
7663 if (!Py_off_t_converter(args[1], &position)) {
7664 goto exit;
7665 }
7666 how = PyLong_AsInt(args[2]);
7667 if (how == -1 && PyErr_Occurred()) {
7668 goto exit;
7669 }
7670 _return_value = os_lseek_impl(module, fd, position, how);
7671 if ((_return_value == -1) && PyErr_Occurred()) {
7672 goto exit;
7673 }
7674 return_value = PyLong_FromPy_off_t(_return_value);
7675
7676 exit:
7677 return return_value;
7678 }
7679
7680 PyDoc_STRVAR(os_read__doc__,
7681 "read($module, fd, length, /)\n"
7682 "--\n"
7683 "\n"
7684 "Read from a file descriptor. Returns a bytes object.");
7685
7686 #define OS_READ_METHODDEF \
7687 {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
7688
7689 static PyObject *
7690 os_read_impl(PyObject *module, int fd, Py_ssize_t length);
7691
7692 static PyObject *
7693 os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7694 {
7695 PyObject *return_value = NULL;
7696 int fd;
7697 Py_ssize_t length;
7698
7699 if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
7700 goto exit;
7701 }
7702 fd = PyLong_AsInt(args[0]);
7703 if (fd == -1 && PyErr_Occurred()) {
7704 goto exit;
7705 }
7706 {
7707 Py_ssize_t ival = -1;
7708 PyObject *iobj = _PyNumber_Index(args[1]);
7709 if (iobj != NULL) {
7710 ival = PyLong_AsSsize_t(iobj);
7711 Py_DECREF(iobj);
7712 }
7713 if (ival == -1 && PyErr_Occurred()) {
7714 goto exit;
7715 }
7716 length = ival;
7717 }
7718 return_value = os_read_impl(module, fd, length);
7719
7720 exit:
7721 return return_value;
7722 }
7723
7724 PyDoc_STRVAR(os_readinto__doc__,
7725 "readinto($module, fd, buffer, /)\n"
7726 "--\n"
7727 "\n"
7728 "Read into a buffer object from a file descriptor.\n"
7729 "\n"
7730 "The buffer should be mutable and bytes-like. On success, returns the\n"
7731 "number of bytes read. Less bytes may be read than the size of the\n"
7732 "buffer. The underlying system call will be retried when interrupted by\n"
7733 "a signal, unless the signal handler raises an exception. Other errors\n"
7734 "will not be retried and an error will be raised.\n"
7735 "\n"
7736 "Returns 0 if *fd* is at end of file or if the provided *buffer* has\n"
7737 "length 0 (which can be used to check for errors without reading data).\n"
7738 "Never returns negative.");
7739
7740 #define OS_READINTO_METHODDEF \
7741 {"readinto", _PyCFunction_CAST(os_readinto), METH_FASTCALL, os_readinto__doc__},
7742
7743 static Py_ssize_t
7744 os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer);
7745
7746 static PyObject *
7747 os_readinto(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7748 {
7749 PyObject *return_value = NULL;
7750 int fd;
7751 Py_buffer buffer = {NULL, NULL};
7752 Py_ssize_t _return_value;
7753
7754 if (!_PyArg_CheckPositional("readinto", nargs, 2, 2)) {
7755 goto exit;
7756 }
7757 fd = PyLong_AsInt(args[0]);
7758 if (fd == -1 && PyErr_Occurred()) {
7759 goto exit;
7760 }
7761 if (PyObject_GetBuffer(args[1], &buffer, PyBUF_WRITABLE) < 0) {
7762 _PyArg_BadArgument("readinto", "argument 2", "read-write bytes-like object", args[1]);
7763 goto exit;
7764 }
7765 _return_value = os_readinto_impl(module, fd, &buffer);
7766 if ((_return_value == -1) && PyErr_Occurred()) {
7767 goto exit;
7768 }
7769 return_value = PyLong_FromSsize_t(_return_value);
7770
7771 exit:
7772 /* Cleanup for buffer */
7773 if (buffer.obj) {
7774 PyBuffer_Release(&buffer);
7775 }
7776
7777 return return_value;
7778 }
7779
7780 #if defined(HAVE_READV)
7781
7782 PyDoc_STRVAR(os_readv__doc__,
7783 "readv($module, fd, buffers, /)\n"
7784 "--\n"
7785 "\n"
7786 "Read from a file descriptor fd into an iterable of buffers.\n"
7787 "\n"
7788 "The buffers should be mutable buffers accepting bytes.\n"
7789 "readv will transfer data into each buffer until it is full\n"
7790 "and then move on to the next buffer in the sequence to hold\n"
7791 "the rest of the data.\n"
7792 "\n"
7793 "readv returns the total number of bytes read,\n"
7794 "which may be less than the total capacity of all the buffers.");
7795
7796 #define OS_READV_METHODDEF \
7797 {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
7798
7799 static Py_ssize_t
7800 os_readv_impl(PyObject *module, int fd, PyObject *buffers);
7801
7802 static PyObject *
7803 os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7804 {
7805 PyObject *return_value = NULL;
7806 int fd;
7807 PyObject *buffers;
7808 Py_ssize_t _return_value;
7809
7810 if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
7811 goto exit;
7812 }
7813 fd = PyLong_AsInt(args[0]);
7814 if (fd == -1 && PyErr_Occurred()) {
7815 goto exit;
7816 }
7817 buffers = args[1];
7818 _return_value = os_readv_impl(module, fd, buffers);
7819 if ((_return_value == -1) && PyErr_Occurred()) {
7820 goto exit;
7821 }
7822 return_value = PyLong_FromSsize_t(_return_value);
7823
7824 exit:
7825 return return_value;
7826 }
7827
7828 #endif /* defined(HAVE_READV) */
7829
7830 #if defined(HAVE_PREAD)
7831
7832 PyDoc_STRVAR(os_pread__doc__,
7833 "pread($module, fd, length, offset, /)\n"
7834 "--\n"
7835 "\n"
7836 "Read a number of bytes from a file descriptor starting at a particular offset.\n"
7837 "\n"
7838 "Read length bytes from file descriptor fd, starting at offset bytes from\n"
7839 "the beginning of the file. The file offset remains unchanged.");
7840
7841 #define OS_PREAD_METHODDEF \
7842 {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
7843
7844 static PyObject *
7845 os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
7846
7847 static PyObject *
7848 os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7849 {
7850 PyObject *return_value = NULL;
7851 int fd;
7852 Py_ssize_t length;
7853 Py_off_t offset;
7854
7855 if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
7856 goto exit;
7857 }
7858 fd = PyLong_AsInt(args[0]);
7859 if (fd == -1 && PyErr_Occurred()) {
7860 goto exit;
7861 }
7862 {
7863 Py_ssize_t ival = -1;
7864 PyObject *iobj = _PyNumber_Index(args[1]);
7865 if (iobj != NULL) {
7866 ival = PyLong_AsSsize_t(iobj);
7867 Py_DECREF(iobj);
7868 }
7869 if (ival == -1 && PyErr_Occurred()) {
7870 goto exit;
7871 }
7872 length = ival;
7873 }
7874 if (!Py_off_t_converter(args[2], &offset)) {
7875 goto exit;
7876 }
7877 return_value = os_pread_impl(module, fd, length, offset);
7878
7879 exit:
7880 return return_value;
7881 }
7882
7883 #endif /* defined(HAVE_PREAD) */
7884
7885 #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
7886
7887 PyDoc_STRVAR(os_preadv__doc__,
7888 "preadv($module, fd, buffers, offset, flags=0, /)\n"
7889 "--\n"
7890 "\n"
7891 "Reads from a file descriptor into a number of mutable bytes-like objects.\n"
7892 "\n"
7893 "Combines the functionality of readv() and pread(). As readv(), it will\n"
7894 "transfer data into each buffer until it is full and then move on to the\n"
7895 "next buffer in the sequence to hold the rest of the data. Its fourth\n"
7896 "argument, specifies the file offset at which the input operation is to\n"
7897 "be performed. It will return the total number of bytes read (which can\n"
7898 "be less than the total capacity of all the objects).\n"
7899 "\n"
7900 "The flags argument contains a bitwise OR of zero or more of the\n"
7901 "following flags:\n"
7902 "\n"
7903 "- RWF_HIPRI\n"
7904 "- RWF_NOWAIT\n"
7905 "\n"
7906 "Using non-zero flags requires Linux 4.6 or newer.");
7907
7908 #define OS_PREADV_METHODDEF \
7909 {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
7910
7911 static Py_ssize_t
7912 os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
7913 int flags);
7914
7915 static PyObject *
7916 os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7917 {
7918 PyObject *return_value = NULL;
7919 int fd;
7920 PyObject *buffers;
7921 Py_off_t offset;
7922 int flags = 0;
7923 Py_ssize_t _return_value;
7924
7925 if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
7926 goto exit;
7927 }
7928 fd = PyLong_AsInt(args[0]);
7929 if (fd == -1 && PyErr_Occurred()) {
7930 goto exit;
7931 }
7932 buffers = args[1];
7933 if (!Py_off_t_converter(args[2], &offset)) {
7934 goto exit;
7935 }
7936 if (nargs < 4) {
7937 goto skip_optional;
7938 }
7939 flags = PyLong_AsInt(args[3]);
7940 if (flags == -1 && PyErr_Occurred()) {
7941 goto exit;
7942 }
7943 skip_optional:
7944 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
7945 if ((_return_value == -1) && PyErr_Occurred()) {
7946 goto exit;
7947 }
7948 return_value = PyLong_FromSsize_t(_return_value);
7949
7950 exit:
7951 return return_value;
7952 }
7953
7954 #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
7955
7956 PyDoc_STRVAR(os_write__doc__,
7957 "write($module, fd, data, /)\n"
7958 "--\n"
7959 "\n"
7960 "Write a bytes object to a file descriptor.");
7961
7962 #define OS_WRITE_METHODDEF \
7963 {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
7964
7965 static Py_ssize_t
7966 os_write_impl(PyObject *module, int fd, Py_buffer *data);
7967
7968 static PyObject *
7969 os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7970 {
7971 PyObject *return_value = NULL;
7972 int fd;
7973 Py_buffer data = {NULL, NULL};
7974 Py_ssize_t _return_value;
7975
7976 if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
7977 goto exit;
7978 }
7979 fd = PyLong_AsInt(args[0]);
7980 if (fd == -1 && PyErr_Occurred()) {
7981 goto exit;
7982 }
7983 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
7984 goto exit;
7985 }
7986 _return_value = os_write_impl(module, fd, &data);
7987 if ((_return_value == -1) && PyErr_Occurred()) {
7988 goto exit;
7989 }
7990 return_value = PyLong_FromSsize_t(_return_value);
7991
7992 exit:
7993 /* Cleanup for data */
7994 if (data.obj) {
7995 PyBuffer_Release(&data);
7996 }
7997
7998 return return_value;
7999 }
8000
8001 #if defined(HAVE_SENDFILE) && defined(__APPLE__)
8002
8003 PyDoc_STRVAR(os_sendfile__doc__,
8004 "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8005 " trailers=(), flags=0)\n"
8006 "--\n"
8007 "\n"
8008 "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8009
8010 #define OS_SENDFILE_METHODDEF \
8011 {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8012
8013 static PyObject *
8014 os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8015 Py_off_t sbytes, PyObject *headers, PyObject *trailers,
8016 int flags);
8017
8018 static PyObject *
8019 os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8020 {
8021 PyObject *return_value = NULL;
8022 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8023
8024 #define NUM_KEYWORDS 7
8025 static struct {
8026 PyGC_Head _this_is_not_used;
8027 PyObject_VAR_HEAD
8028 Py_hash_t ob_hash;
8029 PyObject *ob_item[NUM_KEYWORDS];
8030 } _kwtuple = {
8031 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8032 .ob_hash = -1,
8033 .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), },
8034 };
8035 #undef NUM_KEYWORDS
8036 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8037
8038 #else // !Py_BUILD_CORE
8039 # define KWTUPLE NULL
8040 #endif // !Py_BUILD_CORE
8041
8042 static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8043 static _PyArg_Parser _parser = {
8044 .keywords = _keywords,
8045 .fname = "sendfile",
8046 .kwtuple = KWTUPLE,
8047 };
8048 #undef KWTUPLE
8049 PyObject *argsbuf[7];
8050 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8051 int out_fd;
8052 int in_fd;
8053 Py_off_t offset;
8054 Py_off_t sbytes;
8055 PyObject *headers = NULL;
8056 PyObject *trailers = NULL;
8057 int flags = 0;
8058
8059 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8060 /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8061 if (!args) {
8062 goto exit;
8063 }
8064 out_fd = PyLong_AsInt(args[0]);
8065 if (out_fd == -1 && PyErr_Occurred()) {
8066 goto exit;
8067 }
8068 in_fd = PyLong_AsInt(args[1]);
8069 if (in_fd == -1 && PyErr_Occurred()) {
8070 goto exit;
8071 }
8072 if (!Py_off_t_converter(args[2], &offset)) {
8073 goto exit;
8074 }
8075 if (!Py_off_t_converter(args[3], &sbytes)) {
8076 goto exit;
8077 }
8078 if (!noptargs) {
8079 goto skip_optional_pos;
8080 }
8081 if (args[4]) {
8082 headers = args[4];
8083 if (!--noptargs) {
8084 goto skip_optional_pos;
8085 }
8086 }
8087 if (args[5]) {
8088 trailers = args[5];
8089 if (!--noptargs) {
8090 goto skip_optional_pos;
8091 }
8092 }
8093 flags = PyLong_AsInt(args[6]);
8094 if (flags == -1 && PyErr_Occurred()) {
8095 goto exit;
8096 }
8097 skip_optional_pos:
8098 return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
8099
8100 exit:
8101 return return_value;
8102 }
8103
8104 #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
8105
8106 #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
8107
8108 PyDoc_STRVAR(os_sendfile__doc__,
8109 "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
8110 " trailers=(), flags=0)\n"
8111 "--\n"
8112 "\n"
8113 "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8114
8115 #define OS_SENDFILE_METHODDEF \
8116 {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8117
8118 static PyObject *
8119 os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
8120 Py_ssize_t count, PyObject *headers, PyObject *trailers,
8121 int flags);
8122
8123 static PyObject *
8124 os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8125 {
8126 PyObject *return_value = NULL;
8127 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8128
8129 #define NUM_KEYWORDS 7
8130 static struct {
8131 PyGC_Head _this_is_not_used;
8132 PyObject_VAR_HEAD
8133 Py_hash_t ob_hash;
8134 PyObject *ob_item[NUM_KEYWORDS];
8135 } _kwtuple = {
8136 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8137 .ob_hash = -1,
8138 .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), },
8139 };
8140 #undef NUM_KEYWORDS
8141 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8142
8143 #else // !Py_BUILD_CORE
8144 # define KWTUPLE NULL
8145 #endif // !Py_BUILD_CORE
8146
8147 static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
8148 static _PyArg_Parser _parser = {
8149 .keywords = _keywords,
8150 .fname = "sendfile",
8151 .kwtuple = KWTUPLE,
8152 };
8153 #undef KWTUPLE
8154 PyObject *argsbuf[7];
8155 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
8156 int out_fd;
8157 int in_fd;
8158 Py_off_t offset;
8159 Py_ssize_t count;
8160 PyObject *headers = NULL;
8161 PyObject *trailers = NULL;
8162 int flags = 0;
8163
8164 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8165 /*minpos*/ 4, /*maxpos*/ 7, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8166 if (!args) {
8167 goto exit;
8168 }
8169 out_fd = PyLong_AsInt(args[0]);
8170 if (out_fd == -1 && PyErr_Occurred()) {
8171 goto exit;
8172 }
8173 in_fd = PyLong_AsInt(args[1]);
8174 if (in_fd == -1 && PyErr_Occurred()) {
8175 goto exit;
8176 }
8177 if (!Py_off_t_converter(args[2], &offset)) {
8178 goto exit;
8179 }
8180 {
8181 Py_ssize_t ival = -1;
8182 PyObject *iobj = _PyNumber_Index(args[3]);
8183 if (iobj != NULL) {
8184 ival = PyLong_AsSsize_t(iobj);
8185 Py_DECREF(iobj);
8186 }
8187 if (ival == -1 && PyErr_Occurred()) {
8188 goto exit;
8189 }
8190 count = ival;
8191 }
8192 if (!noptargs) {
8193 goto skip_optional_pos;
8194 }
8195 if (args[4]) {
8196 headers = args[4];
8197 if (!--noptargs) {
8198 goto skip_optional_pos;
8199 }
8200 }
8201 if (args[5]) {
8202 trailers = args[5];
8203 if (!--noptargs) {
8204 goto skip_optional_pos;
8205 }
8206 }
8207 flags = PyLong_AsInt(args[6]);
8208 if (flags == -1 && PyErr_Occurred()) {
8209 goto exit;
8210 }
8211 skip_optional_pos:
8212 return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
8213
8214 exit:
8215 return return_value;
8216 }
8217
8218 #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
8219
8220 #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
8221
8222 PyDoc_STRVAR(os_sendfile__doc__,
8223 "sendfile($module, /, out_fd, in_fd, offset, count)\n"
8224 "--\n"
8225 "\n"
8226 "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
8227
8228 #define OS_SENDFILE_METHODDEF \
8229 {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
8230
8231 static PyObject *
8232 os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
8233 Py_ssize_t count);
8234
8235 static PyObject *
8236 os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8237 {
8238 PyObject *return_value = NULL;
8239 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8240
8241 #define NUM_KEYWORDS 4
8242 static struct {
8243 PyGC_Head _this_is_not_used;
8244 PyObject_VAR_HEAD
8245 Py_hash_t ob_hash;
8246 PyObject *ob_item[NUM_KEYWORDS];
8247 } _kwtuple = {
8248 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8249 .ob_hash = -1,
8250 .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
8251 };
8252 #undef NUM_KEYWORDS
8253 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8254
8255 #else // !Py_BUILD_CORE
8256 # define KWTUPLE NULL
8257 #endif // !Py_BUILD_CORE
8258
8259 static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
8260 static _PyArg_Parser _parser = {
8261 .keywords = _keywords,
8262 .fname = "sendfile",
8263 .kwtuple = KWTUPLE,
8264 };
8265 #undef KWTUPLE
8266 PyObject *argsbuf[4];
8267 int out_fd;
8268 int in_fd;
8269 PyObject *offobj;
8270 Py_ssize_t count;
8271
8272 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8273 /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8274 if (!args) {
8275 goto exit;
8276 }
8277 out_fd = PyLong_AsInt(args[0]);
8278 if (out_fd == -1 && PyErr_Occurred()) {
8279 goto exit;
8280 }
8281 in_fd = PyLong_AsInt(args[1]);
8282 if (in_fd == -1 && PyErr_Occurred()) {
8283 goto exit;
8284 }
8285 offobj = args[2];
8286 {
8287 Py_ssize_t ival = -1;
8288 PyObject *iobj = _PyNumber_Index(args[3]);
8289 if (iobj != NULL) {
8290 ival = PyLong_AsSsize_t(iobj);
8291 Py_DECREF(iobj);
8292 }
8293 if (ival == -1 && PyErr_Occurred()) {
8294 goto exit;
8295 }
8296 count = ival;
8297 }
8298 return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
8299
8300 exit:
8301 return return_value;
8302 }
8303
8304 #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
8305
8306 #if defined(__APPLE__)
8307
8308 PyDoc_STRVAR(os__fcopyfile__doc__,
8309 "_fcopyfile($module, in_fd, out_fd, flags, /)\n"
8310 "--\n"
8311 "\n"
8312 "Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
8313
8314 #define OS__FCOPYFILE_METHODDEF \
8315 {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
8316
8317 static PyObject *
8318 os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
8319
8320 static PyObject *
8321 os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8322 {
8323 PyObject *return_value = NULL;
8324 int in_fd;
8325 int out_fd;
8326 int flags;
8327
8328 if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
8329 goto exit;
8330 }
8331 in_fd = PyLong_AsInt(args[0]);
8332 if (in_fd == -1 && PyErr_Occurred()) {
8333 goto exit;
8334 }
8335 out_fd = PyLong_AsInt(args[1]);
8336 if (out_fd == -1 && PyErr_Occurred()) {
8337 goto exit;
8338 }
8339 flags = PyLong_AsInt(args[2]);
8340 if (flags == -1 && PyErr_Occurred()) {
8341 goto exit;
8342 }
8343 return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
8344
8345 exit:
8346 return return_value;
8347 }
8348
8349 #endif /* defined(__APPLE__) */
8350
8351 PyDoc_STRVAR(os_fstat__doc__,
8352 "fstat($module, /, fd)\n"
8353 "--\n"
8354 "\n"
8355 "Perform a stat system call on the given file descriptor.\n"
8356 "\n"
8357 "Like stat(), but for an open file descriptor.\n"
8358 "Equivalent to os.stat(fd).");
8359
8360 #define OS_FSTAT_METHODDEF \
8361 {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
8362
8363 static PyObject *
8364 os_fstat_impl(PyObject *module, int fd);
8365
8366 static PyObject *
8367 os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8368 {
8369 PyObject *return_value = NULL;
8370 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8371
8372 #define NUM_KEYWORDS 1
8373 static struct {
8374 PyGC_Head _this_is_not_used;
8375 PyObject_VAR_HEAD
8376 Py_hash_t ob_hash;
8377 PyObject *ob_item[NUM_KEYWORDS];
8378 } _kwtuple = {
8379 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8380 .ob_hash = -1,
8381 .ob_item = { &_Py_ID(fd), },
8382 };
8383 #undef NUM_KEYWORDS
8384 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8385
8386 #else // !Py_BUILD_CORE
8387 # define KWTUPLE NULL
8388 #endif // !Py_BUILD_CORE
8389
8390 static const char * const _keywords[] = {"fd", NULL};
8391 static _PyArg_Parser _parser = {
8392 .keywords = _keywords,
8393 .fname = "fstat",
8394 .kwtuple = KWTUPLE,
8395 };
8396 #undef KWTUPLE
8397 PyObject *argsbuf[1];
8398 int fd;
8399
8400 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8401 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8402 if (!args) {
8403 goto exit;
8404 }
8405 fd = PyLong_AsInt(args[0]);
8406 if (fd == -1 && PyErr_Occurred()) {
8407 goto exit;
8408 }
8409 return_value = os_fstat_impl(module, fd);
8410
8411 exit:
8412 return return_value;
8413 }
8414
8415 PyDoc_STRVAR(os_isatty__doc__,
8416 "isatty($module, fd, /)\n"
8417 "--\n"
8418 "\n"
8419 "Return True if the fd is connected to a terminal.\n"
8420 "\n"
8421 "Return True if the file descriptor is an open file descriptor\n"
8422 "connected to the slave end of a terminal.");
8423
8424 #define OS_ISATTY_METHODDEF \
8425 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
8426
8427 static int
8428 os_isatty_impl(PyObject *module, int fd);
8429
8430 static PyObject *
8431 os_isatty(PyObject *module, PyObject *arg)
8432 {
8433 PyObject *return_value = NULL;
8434 int fd;
8435 int _return_value;
8436
8437 fd = PyLong_AsInt(arg);
8438 if (fd == -1 && PyErr_Occurred()) {
8439 goto exit;
8440 }
8441 _return_value = os_isatty_impl(module, fd);
8442 if ((_return_value == -1) && PyErr_Occurred()) {
8443 goto exit;
8444 }
8445 return_value = PyBool_FromLong((long)_return_value);
8446
8447 exit:
8448 return return_value;
8449 }
8450
8451 #if defined(HAVE_PIPE)
8452
8453 PyDoc_STRVAR(os_pipe__doc__,
8454 "pipe($module, /)\n"
8455 "--\n"
8456 "\n"
8457 "Create a pipe.\n"
8458 "\n"
8459 "Returns a tuple of two file descriptors:\n"
8460 " (read_fd, write_fd)");
8461
8462 #define OS_PIPE_METHODDEF \
8463 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
8464
8465 static PyObject *
8466 os_pipe_impl(PyObject *module);
8467
8468 static PyObject *
8469 os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
8470 {
8471 return os_pipe_impl(module);
8472 }
8473
8474 #endif /* defined(HAVE_PIPE) */
8475
8476 #if defined(HAVE_PIPE2)
8477
8478 PyDoc_STRVAR(os_pipe2__doc__,
8479 "pipe2($module, flags, /)\n"
8480 "--\n"
8481 "\n"
8482 "Create a pipe with flags set atomically.\n"
8483 "\n"
8484 "Returns a tuple of two file descriptors:\n"
8485 " (read_fd, write_fd)\n"
8486 "\n"
8487 "flags can be constructed by ORing together one or more of these values:\n"
8488 "O_NONBLOCK, O_CLOEXEC.");
8489
8490 #define OS_PIPE2_METHODDEF \
8491 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
8492
8493 static PyObject *
8494 os_pipe2_impl(PyObject *module, int flags);
8495
8496 static PyObject *
8497 os_pipe2(PyObject *module, PyObject *arg)
8498 {
8499 PyObject *return_value = NULL;
8500 int flags;
8501
8502 flags = PyLong_AsInt(arg);
8503 if (flags == -1 && PyErr_Occurred()) {
8504 goto exit;
8505 }
8506 return_value = os_pipe2_impl(module, flags);
8507
8508 exit:
8509 return return_value;
8510 }
8511
8512 #endif /* defined(HAVE_PIPE2) */
8513
8514 #if defined(HAVE_WRITEV)
8515
8516 PyDoc_STRVAR(os_writev__doc__,
8517 "writev($module, fd, buffers, /)\n"
8518 "--\n"
8519 "\n"
8520 "Iterate over buffers, and write the contents of each to a file descriptor.\n"
8521 "\n"
8522 "Returns the total number of bytes written.\n"
8523 "buffers must be a sequence of bytes-like objects.");
8524
8525 #define OS_WRITEV_METHODDEF \
8526 {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
8527
8528 static Py_ssize_t
8529 os_writev_impl(PyObject *module, int fd, PyObject *buffers);
8530
8531 static PyObject *
8532 os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8533 {
8534 PyObject *return_value = NULL;
8535 int fd;
8536 PyObject *buffers;
8537 Py_ssize_t _return_value;
8538
8539 if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
8540 goto exit;
8541 }
8542 fd = PyLong_AsInt(args[0]);
8543 if (fd == -1 && PyErr_Occurred()) {
8544 goto exit;
8545 }
8546 buffers = args[1];
8547 _return_value = os_writev_impl(module, fd, buffers);
8548 if ((_return_value == -1) && PyErr_Occurred()) {
8549 goto exit;
8550 }
8551 return_value = PyLong_FromSsize_t(_return_value);
8552
8553 exit:
8554 return return_value;
8555 }
8556
8557 #endif /* defined(HAVE_WRITEV) */
8558
8559 #if defined(HAVE_PWRITE)
8560
8561 PyDoc_STRVAR(os_pwrite__doc__,
8562 "pwrite($module, fd, buffer, offset, /)\n"
8563 "--\n"
8564 "\n"
8565 "Write bytes to a file descriptor starting at a particular offset.\n"
8566 "\n"
8567 "Write buffer to fd, starting at offset bytes from the beginning of\n"
8568 "the file. Returns the number of bytes written. Does not change the\n"
8569 "current file offset.");
8570
8571 #define OS_PWRITE_METHODDEF \
8572 {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
8573
8574 static Py_ssize_t
8575 os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
8576
8577 static PyObject *
8578 os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8579 {
8580 PyObject *return_value = NULL;
8581 int fd;
8582 Py_buffer buffer = {NULL, NULL};
8583 Py_off_t offset;
8584 Py_ssize_t _return_value;
8585
8586 if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
8587 goto exit;
8588 }
8589 fd = PyLong_AsInt(args[0]);
8590 if (fd == -1 && PyErr_Occurred()) {
8591 goto exit;
8592 }
8593 if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
8594 goto exit;
8595 }
8596 if (!Py_off_t_converter(args[2], &offset)) {
8597 goto exit;
8598 }
8599 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
8600 if ((_return_value == -1) && PyErr_Occurred()) {
8601 goto exit;
8602 }
8603 return_value = PyLong_FromSsize_t(_return_value);
8604
8605 exit:
8606 /* Cleanup for buffer */
8607 if (buffer.obj) {
8608 PyBuffer_Release(&buffer);
8609 }
8610
8611 return return_value;
8612 }
8613
8614 #endif /* defined(HAVE_PWRITE) */
8615
8616 #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
8617
8618 PyDoc_STRVAR(os_pwritev__doc__,
8619 "pwritev($module, fd, buffers, offset, flags=0, /)\n"
8620 "--\n"
8621 "\n"
8622 "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
8623 "\n"
8624 "Combines the functionality of writev() and pwrite(). All buffers must be\n"
8625 "a sequence of bytes-like objects. Buffers are processed in array order.\n"
8626 "Entire contents of first buffer is written before proceeding to second,\n"
8627 "and so on. The operating system may set a limit (sysconf() value\n"
8628 "SC_IOV_MAX) on the number of buffers that can be used.\n"
8629 "This function writes the contents of each object to the file descriptor\n"
8630 "and returns the total number of bytes written.\n"
8631 "\n"
8632 "The flags argument contains a bitwise OR of zero or more of the\n"
8633 "following flags:\n"
8634 "\n"
8635 "- RWF_DSYNC\n"
8636 "- RWF_SYNC\n"
8637 "- RWF_APPEND\n"
8638 "\n"
8639 "Using non-zero flags requires Linux 4.7 or newer.");
8640
8641 #define OS_PWRITEV_METHODDEF \
8642 {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
8643
8644 static Py_ssize_t
8645 os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
8646 int flags);
8647
8648 static PyObject *
8649 os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8650 {
8651 PyObject *return_value = NULL;
8652 int fd;
8653 PyObject *buffers;
8654 Py_off_t offset;
8655 int flags = 0;
8656 Py_ssize_t _return_value;
8657
8658 if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
8659 goto exit;
8660 }
8661 fd = PyLong_AsInt(args[0]);
8662 if (fd == -1 && PyErr_Occurred()) {
8663 goto exit;
8664 }
8665 buffers = args[1];
8666 if (!Py_off_t_converter(args[2], &offset)) {
8667 goto exit;
8668 }
8669 if (nargs < 4) {
8670 goto skip_optional;
8671 }
8672 flags = PyLong_AsInt(args[3]);
8673 if (flags == -1 && PyErr_Occurred()) {
8674 goto exit;
8675 }
8676 skip_optional:
8677 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
8678 if ((_return_value == -1) && PyErr_Occurred()) {
8679 goto exit;
8680 }
8681 return_value = PyLong_FromSsize_t(_return_value);
8682
8683 exit:
8684 return return_value;
8685 }
8686
8687 #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
8688
8689 #if defined(HAVE_COPY_FILE_RANGE)
8690
8691 PyDoc_STRVAR(os_copy_file_range__doc__,
8692 "copy_file_range($module, /, src, dst, count, offset_src=None,\n"
8693 " offset_dst=None)\n"
8694 "--\n"
8695 "\n"
8696 "Copy count bytes from one file descriptor to another.\n"
8697 "\n"
8698 " src\n"
8699 " Source file descriptor.\n"
8700 " dst\n"
8701 " Destination file descriptor.\n"
8702 " count\n"
8703 " Number of bytes to copy.\n"
8704 " offset_src\n"
8705 " Starting offset in src.\n"
8706 " offset_dst\n"
8707 " Starting offset in dst.\n"
8708 "\n"
8709 "If offset_src is None, then src is read from the current position;\n"
8710 "respectively for offset_dst.");
8711
8712 #define OS_COPY_FILE_RANGE_METHODDEF \
8713 {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
8714
8715 static PyObject *
8716 os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8717 PyObject *offset_src, PyObject *offset_dst);
8718
8719 static PyObject *
8720 os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8721 {
8722 PyObject *return_value = NULL;
8723 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8724
8725 #define NUM_KEYWORDS 5
8726 static struct {
8727 PyGC_Head _this_is_not_used;
8728 PyObject_VAR_HEAD
8729 Py_hash_t ob_hash;
8730 PyObject *ob_item[NUM_KEYWORDS];
8731 } _kwtuple = {
8732 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8733 .ob_hash = -1,
8734 .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
8735 };
8736 #undef NUM_KEYWORDS
8737 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8738
8739 #else // !Py_BUILD_CORE
8740 # define KWTUPLE NULL
8741 #endif // !Py_BUILD_CORE
8742
8743 static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
8744 static _PyArg_Parser _parser = {
8745 .keywords = _keywords,
8746 .fname = "copy_file_range",
8747 .kwtuple = KWTUPLE,
8748 };
8749 #undef KWTUPLE
8750 PyObject *argsbuf[5];
8751 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8752 int src;
8753 int dst;
8754 Py_ssize_t count;
8755 PyObject *offset_src = Py_None;
8756 PyObject *offset_dst = Py_None;
8757
8758 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8759 /*minpos*/ 3, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8760 if (!args) {
8761 goto exit;
8762 }
8763 src = PyLong_AsInt(args[0]);
8764 if (src == -1 && PyErr_Occurred()) {
8765 goto exit;
8766 }
8767 dst = PyLong_AsInt(args[1]);
8768 if (dst == -1 && PyErr_Occurred()) {
8769 goto exit;
8770 }
8771 {
8772 Py_ssize_t ival = -1;
8773 PyObject *iobj = _PyNumber_Index(args[2]);
8774 if (iobj != NULL) {
8775 ival = PyLong_AsSsize_t(iobj);
8776 Py_DECREF(iobj);
8777 }
8778 if (ival == -1 && PyErr_Occurred()) {
8779 goto exit;
8780 }
8781 count = ival;
8782 }
8783 if (!noptargs) {
8784 goto skip_optional_pos;
8785 }
8786 if (args[3]) {
8787 offset_src = args[3];
8788 if (!--noptargs) {
8789 goto skip_optional_pos;
8790 }
8791 }
8792 offset_dst = args[4];
8793 skip_optional_pos:
8794 return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
8795
8796 exit:
8797 return return_value;
8798 }
8799
8800 #endif /* defined(HAVE_COPY_FILE_RANGE) */
8801
8802 #if ((defined(HAVE_SPLICE) && !defined(_AIX)))
8803
8804 PyDoc_STRVAR(os_splice__doc__,
8805 "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
8806 " flags=0)\n"
8807 "--\n"
8808 "\n"
8809 "Transfer count bytes from one pipe to a descriptor or vice versa.\n"
8810 "\n"
8811 " src\n"
8812 " Source file descriptor.\n"
8813 " dst\n"
8814 " Destination file descriptor.\n"
8815 " count\n"
8816 " Number of bytes to copy.\n"
8817 " offset_src\n"
8818 " Starting offset in src.\n"
8819 " offset_dst\n"
8820 " Starting offset in dst.\n"
8821 " flags\n"
8822 " Flags to modify the semantics of the call.\n"
8823 "\n"
8824 "If offset_src is None, then src is read from the current position;\n"
8825 "respectively for offset_dst. The offset associated to the file\n"
8826 "descriptor that refers to a pipe must be None.");
8827
8828 #define OS_SPLICE_METHODDEF \
8829 {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
8830
8831 static PyObject *
8832 os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
8833 PyObject *offset_src, PyObject *offset_dst,
8834 unsigned int flags);
8835
8836 static PyObject *
8837 os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8838 {
8839 PyObject *return_value = NULL;
8840 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8841
8842 #define NUM_KEYWORDS 6
8843 static struct {
8844 PyGC_Head _this_is_not_used;
8845 PyObject_VAR_HEAD
8846 Py_hash_t ob_hash;
8847 PyObject *ob_item[NUM_KEYWORDS];
8848 } _kwtuple = {
8849 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8850 .ob_hash = -1,
8851 .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
8852 };
8853 #undef NUM_KEYWORDS
8854 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8855
8856 #else // !Py_BUILD_CORE
8857 # define KWTUPLE NULL
8858 #endif // !Py_BUILD_CORE
8859
8860 static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
8861 static _PyArg_Parser _parser = {
8862 .keywords = _keywords,
8863 .fname = "splice",
8864 .kwtuple = KWTUPLE,
8865 };
8866 #undef KWTUPLE
8867 PyObject *argsbuf[6];
8868 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
8869 int src;
8870 int dst;
8871 Py_ssize_t count;
8872 PyObject *offset_src = Py_None;
8873 PyObject *offset_dst = Py_None;
8874 unsigned int flags = 0;
8875
8876 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8877 /*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8878 if (!args) {
8879 goto exit;
8880 }
8881 src = PyLong_AsInt(args[0]);
8882 if (src == -1 && PyErr_Occurred()) {
8883 goto exit;
8884 }
8885 dst = PyLong_AsInt(args[1]);
8886 if (dst == -1 && PyErr_Occurred()) {
8887 goto exit;
8888 }
8889 {
8890 Py_ssize_t ival = -1;
8891 PyObject *iobj = _PyNumber_Index(args[2]);
8892 if (iobj != NULL) {
8893 ival = PyLong_AsSsize_t(iobj);
8894 Py_DECREF(iobj);
8895 }
8896 if (ival == -1 && PyErr_Occurred()) {
8897 goto exit;
8898 }
8899 count = ival;
8900 }
8901 if (!noptargs) {
8902 goto skip_optional_pos;
8903 }
8904 if (args[3]) {
8905 offset_src = args[3];
8906 if (!--noptargs) {
8907 goto skip_optional_pos;
8908 }
8909 }
8910 if (args[4]) {
8911 offset_dst = args[4];
8912 if (!--noptargs) {
8913 goto skip_optional_pos;
8914 }
8915 }
8916 if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
8917 goto exit;
8918 }
8919 skip_optional_pos:
8920 return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
8921
8922 exit:
8923 return return_value;
8924 }
8925
8926 #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
8927
8928 #if defined(HAVE_MKFIFO)
8929
8930 PyDoc_STRVAR(os_mkfifo__doc__,
8931 "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
8932 "--\n"
8933 "\n"
8934 "Create a \"fifo\" (a POSIX named pipe).\n"
8935 "\n"
8936 "If dir_fd is not None, it should be a file descriptor open to\n"
8937 "a directory, and path should be relative; path will then be relative to\n"
8938 "that directory.\n"
8939 "dir_fd may not be implemented on your platform. If it is unavailable,\n"
8940 "using it will raise a NotImplementedError.");
8941
8942 #define OS_MKFIFO_METHODDEF \
8943 {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
8944
8945 static PyObject *
8946 os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
8947
8948 static PyObject *
8949 os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8950 {
8951 PyObject *return_value = NULL;
8952 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8953
8954 #define NUM_KEYWORDS 3
8955 static struct {
8956 PyGC_Head _this_is_not_used;
8957 PyObject_VAR_HEAD
8958 Py_hash_t ob_hash;
8959 PyObject *ob_item[NUM_KEYWORDS];
8960 } _kwtuple = {
8961 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8962 .ob_hash = -1,
8963 .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
8964 };
8965 #undef NUM_KEYWORDS
8966 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8967
8968 #else // !Py_BUILD_CORE
8969 # define KWTUPLE NULL
8970 #endif // !Py_BUILD_CORE
8971
8972 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
8973 static _PyArg_Parser _parser = {
8974 .keywords = _keywords,
8975 .fname = "mkfifo",
8976 .kwtuple = KWTUPLE,
8977 };
8978 #undef KWTUPLE
8979 PyObject *argsbuf[3];
8980 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
8981 path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
8982 int mode = 438;
8983 int dir_fd = DEFAULT_DIR_FD;
8984
8985 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
8986 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
8987 if (!args) {
8988 goto exit;
8989 }
8990 if (!path_converter(args[0], &path)) {
8991 goto exit;
8992 }
8993 if (!noptargs) {
8994 goto skip_optional_pos;
8995 }
8996 if (args[1]) {
8997 mode = PyLong_AsInt(args[1]);
8998 if (mode == -1 && PyErr_Occurred()) {
8999 goto exit;
9000 }
9001 if (!--noptargs) {
9002 goto skip_optional_pos;
9003 }
9004 }
9005 skip_optional_pos:
9006 if (!noptargs) {
9007 goto skip_optional_kwonly;
9008 }
9009 if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
9010 goto exit;
9011 }
9012 skip_optional_kwonly:
9013 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
9014
9015 exit:
9016 /* Cleanup for path */
9017 path_cleanup(&path);
9018
9019 return return_value;
9020 }
9021
9022 #endif /* defined(HAVE_MKFIFO) */
9023
9024 #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
9025
9026 PyDoc_STRVAR(os_mknod__doc__,
9027 "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
9028 "--\n"
9029 "\n"
9030 "Create a node in the file system.\n"
9031 "\n"
9032 "Create a node in the file system (file, device special file or named\n"
9033 "pipe) at path. mode specifies both the permissions to use and the\n"
9034 "type of node to be created, being combined (bitwise OR) with one of\n"
9035 "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set\n"
9036 "on mode, device defines the newly created device special file (probably\n"
9037 "using os.makedev()). Otherwise device is ignored.\n"
9038 "\n"
9039 "If dir_fd is not None, it should be a file descriptor open to\n"
9040 "a directory, and path should be relative; path will then be relative\n"
9041 "to that directory.\n"
9042 "dir_fd may not be implemented on your platform. If it is unavailable,\n"
9043 "using it will raise a NotImplementedError.");
9044
9045 #define OS_MKNOD_METHODDEF \
9046 {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
9047
9048 static PyObject *
9049 os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
9050 int dir_fd);
9051
9052 static PyObject *
9053 os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9054 {
9055 PyObject *return_value = NULL;
9056 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9057
9058 #define NUM_KEYWORDS 4
9059 static struct {
9060 PyGC_Head _this_is_not_used;
9061 PyObject_VAR_HEAD
9062 Py_hash_t ob_hash;
9063 PyObject *ob_item[NUM_KEYWORDS];
9064 } _kwtuple = {
9065 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9066 .ob_hash = -1,
9067 .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
9068 };
9069 #undef NUM_KEYWORDS
9070 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9071
9072 #else // !Py_BUILD_CORE
9073 # define KWTUPLE NULL
9074 #endif // !Py_BUILD_CORE
9075
9076 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
9077 static _PyArg_Parser _parser = {
9078 .keywords = _keywords,
9079 .fname = "mknod",
9080 .kwtuple = KWTUPLE,
9081 };
9082 #undef KWTUPLE
9083 PyObject *argsbuf[4];
9084 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9085 path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
9086 int mode = 384;
9087 dev_t device = 0;
9088 int dir_fd = DEFAULT_DIR_FD;
9089
9090 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9091 /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9092 if (!args) {
9093 goto exit;
9094 }
9095 if (!path_converter(args[0], &path)) {
9096 goto exit;
9097 }
9098 if (!noptargs) {
9099 goto skip_optional_pos;
9100 }
9101 if (args[1]) {
9102 mode = PyLong_AsInt(args[1]);
9103 if (mode == -1 && PyErr_Occurred()) {
9104 goto exit;
9105 }
9106 if (!--noptargs) {
9107 goto skip_optional_pos;
9108 }
9109 }
9110 if (args[2]) {
9111 if (!_Py_Dev_Converter(args[2], &device)) {
9112 goto exit;
9113 }
9114 if (!--noptargs) {
9115 goto skip_optional_pos;
9116 }
9117 }
9118 skip_optional_pos:
9119 if (!noptargs) {
9120 goto skip_optional_kwonly;
9121 }
9122 if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
9123 goto exit;
9124 }
9125 skip_optional_kwonly:
9126 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
9127
9128 exit:
9129 /* Cleanup for path */
9130 path_cleanup(&path);
9131
9132 return return_value;
9133 }
9134
9135 #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
9136
9137 #if defined(HAVE_DEVICE_MACROS)
9138
9139 PyDoc_STRVAR(os_major__doc__,
9140 "major($module, device, /)\n"
9141 "--\n"
9142 "\n"
9143 "Extracts a device major number from a raw device number.");
9144
9145 #define OS_MAJOR_METHODDEF \
9146 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
9147
9148 static PyObject *
9149 os_major_impl(PyObject *module, dev_t device);
9150
9151 static PyObject *
9152 os_major(PyObject *module, PyObject *arg)
9153 {
9154 PyObject *return_value = NULL;
9155 dev_t device;
9156
9157 if (!_Py_Dev_Converter(arg, &device)) {
9158 goto exit;
9159 }
9160 return_value = os_major_impl(module, device);
9161
9162 exit:
9163 return return_value;
9164 }
9165
9166 #endif /* defined(HAVE_DEVICE_MACROS) */
9167
9168 #if defined(HAVE_DEVICE_MACROS)
9169
9170 PyDoc_STRVAR(os_minor__doc__,
9171 "minor($module, device, /)\n"
9172 "--\n"
9173 "\n"
9174 "Extracts a device minor number from a raw device number.");
9175
9176 #define OS_MINOR_METHODDEF \
9177 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
9178
9179 static PyObject *
9180 os_minor_impl(PyObject *module, dev_t device);
9181
9182 static PyObject *
9183 os_minor(PyObject *module, PyObject *arg)
9184 {
9185 PyObject *return_value = NULL;
9186 dev_t device;
9187
9188 if (!_Py_Dev_Converter(arg, &device)) {
9189 goto exit;
9190 }
9191 return_value = os_minor_impl(module, device);
9192
9193 exit:
9194 return return_value;
9195 }
9196
9197 #endif /* defined(HAVE_DEVICE_MACROS) */
9198
9199 #if defined(HAVE_DEVICE_MACROS)
9200
9201 PyDoc_STRVAR(os_makedev__doc__,
9202 "makedev($module, major, minor, /)\n"
9203 "--\n"
9204 "\n"
9205 "Composes a raw device number from the major and minor device numbers.");
9206
9207 #define OS_MAKEDEV_METHODDEF \
9208 {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
9209
9210 static dev_t
9211 os_makedev_impl(PyObject *module, dev_t major, dev_t minor);
9212
9213 static PyObject *
9214 os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9215 {
9216 PyObject *return_value = NULL;
9217 dev_t major;
9218 dev_t minor;
9219 dev_t _return_value;
9220
9221 if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
9222 goto exit;
9223 }
9224 if (!_Py_Dev_Converter(args[0], &major)) {
9225 goto exit;
9226 }
9227 if (!_Py_Dev_Converter(args[1], &minor)) {
9228 goto exit;
9229 }
9230 _return_value = os_makedev_impl(module, major, minor);
9231 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
9232 goto exit;
9233 }
9234 return_value = _PyLong_FromDev(_return_value);
9235
9236 exit:
9237 return return_value;
9238 }
9239
9240 #endif /* defined(HAVE_DEVICE_MACROS) */
9241
9242 #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
9243
9244 PyDoc_STRVAR(os_ftruncate__doc__,
9245 "ftruncate($module, fd, length, /)\n"
9246 "--\n"
9247 "\n"
9248 "Truncate a file, specified by file descriptor, to a specific length.");
9249
9250 #define OS_FTRUNCATE_METHODDEF \
9251 {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
9252
9253 static PyObject *
9254 os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
9255
9256 static PyObject *
9257 os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9258 {
9259 PyObject *return_value = NULL;
9260 int fd;
9261 Py_off_t length;
9262
9263 if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
9264 goto exit;
9265 }
9266 fd = PyLong_AsInt(args[0]);
9267 if (fd == -1 && PyErr_Occurred()) {
9268 goto exit;
9269 }
9270 if (!Py_off_t_converter(args[1], &length)) {
9271 goto exit;
9272 }
9273 return_value = os_ftruncate_impl(module, fd, length);
9274
9275 exit:
9276 return return_value;
9277 }
9278
9279 #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
9280
9281 #if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
9282
9283 PyDoc_STRVAR(os_truncate__doc__,
9284 "truncate($module, /, path, length)\n"
9285 "--\n"
9286 "\n"
9287 "Truncate a file, specified by path, to a specific length.\n"
9288 "\n"
9289 "On some platforms, path may also be specified as an open file\n"
9290 "descriptor. If this functionality is unavailable, using it raises\n"
9291 "an exception.");
9292
9293 #define OS_TRUNCATE_METHODDEF \
9294 {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
9295
9296 static PyObject *
9297 os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
9298
9299 static PyObject *
9300 os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9301 {
9302 PyObject *return_value = NULL;
9303 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9304
9305 #define NUM_KEYWORDS 2
9306 static struct {
9307 PyGC_Head _this_is_not_used;
9308 PyObject_VAR_HEAD
9309 Py_hash_t ob_hash;
9310 PyObject *ob_item[NUM_KEYWORDS];
9311 } _kwtuple = {
9312 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9313 .ob_hash = -1,
9314 .ob_item = { &_Py_ID(path), &_Py_ID(length), },
9315 };
9316 #undef NUM_KEYWORDS
9317 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9318
9319 #else // !Py_BUILD_CORE
9320 # define KWTUPLE NULL
9321 #endif // !Py_BUILD_CORE
9322
9323 static const char * const _keywords[] = {"path", "length", NULL};
9324 static _PyArg_Parser _parser = {
9325 .keywords = _keywords,
9326 .fname = "truncate",
9327 .kwtuple = KWTUPLE,
9328 };
9329 #undef KWTUPLE
9330 PyObject *argsbuf[2];
9331 path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
9332 Py_off_t length;
9333
9334 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9335 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9336 if (!args) {
9337 goto exit;
9338 }
9339 if (!path_converter(args[0], &path)) {
9340 goto exit;
9341 }
9342 if (!Py_off_t_converter(args[1], &length)) {
9343 goto exit;
9344 }
9345 return_value = os_truncate_impl(module, &path, length);
9346
9347 exit:
9348 /* Cleanup for path */
9349 path_cleanup(&path);
9350
9351 return return_value;
9352 }
9353
9354 #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
9355
9356 #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__))
9357
9358 PyDoc_STRVAR(os_posix_fallocate__doc__,
9359 "posix_fallocate($module, fd, offset, length, /)\n"
9360 "--\n"
9361 "\n"
9362 "Ensure a file has allocated at least a particular number of bytes on disk.\n"
9363 "\n"
9364 "Ensure that the file specified by fd encompasses a range of bytes\n"
9365 "starting at offset bytes from the beginning and continuing for length\n"
9366 "bytes.");
9367
9368 #define OS_POSIX_FALLOCATE_METHODDEF \
9369 {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
9370
9371 static PyObject *
9372 os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
9373 Py_off_t length);
9374
9375 static PyObject *
9376 os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9377 {
9378 PyObject *return_value = NULL;
9379 int fd;
9380 Py_off_t offset;
9381 Py_off_t length;
9382
9383 if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
9384 goto exit;
9385 }
9386 fd = PyLong_AsInt(args[0]);
9387 if (fd == -1 && PyErr_Occurred()) {
9388 goto exit;
9389 }
9390 if (!Py_off_t_converter(args[1], &offset)) {
9391 goto exit;
9392 }
9393 if (!Py_off_t_converter(args[2], &length)) {
9394 goto exit;
9395 }
9396 return_value = os_posix_fallocate_impl(module, fd, offset, length);
9397
9398 exit:
9399 return return_value;
9400 }
9401
9402 #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */
9403
9404 #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
9405
9406 PyDoc_STRVAR(os_posix_fadvise__doc__,
9407 "posix_fadvise($module, fd, offset, length, advice, /)\n"
9408 "--\n"
9409 "\n"
9410 "Announce an intention to access data in a specific pattern.\n"
9411 "\n"
9412 "Announce an intention to access data in a specific pattern, thus\n"
9413 "allowing the kernel to make optimizations.\n"
9414 "The advice applies to the region of the file specified by fd starting at\n"
9415 "offset and continuing for length bytes.\n"
9416 "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
9417 "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
9418 "POSIX_FADV_DONTNEED.");
9419
9420 #define OS_POSIX_FADVISE_METHODDEF \
9421 {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
9422
9423 static PyObject *
9424 os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
9425 Py_off_t length, int advice);
9426
9427 static PyObject *
9428 os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9429 {
9430 PyObject *return_value = NULL;
9431 int fd;
9432 Py_off_t offset;
9433 Py_off_t length;
9434 int advice;
9435
9436 if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
9437 goto exit;
9438 }
9439 fd = PyLong_AsInt(args[0]);
9440 if (fd == -1 && PyErr_Occurred()) {
9441 goto exit;
9442 }
9443 if (!Py_off_t_converter(args[1], &offset)) {
9444 goto exit;
9445 }
9446 if (!Py_off_t_converter(args[2], &length)) {
9447 goto exit;
9448 }
9449 advice = PyLong_AsInt(args[3]);
9450 if (advice == -1 && PyErr_Occurred()) {
9451 goto exit;
9452 }
9453 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
9454
9455 exit:
9456 return return_value;
9457 }
9458
9459 #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
9460
9461 #if defined(MS_WINDOWS)
9462
9463 PyDoc_STRVAR(os_putenv__doc__,
9464 "putenv($module, name, value, /)\n"
9465 "--\n"
9466 "\n"
9467 "Change or add an environment variable.");
9468
9469 #define OS_PUTENV_METHODDEF \
9470 {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9471
9472 static PyObject *
9473 os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9474
9475 static PyObject *
9476 os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9477 {
9478 PyObject *return_value = NULL;
9479 PyObject *name;
9480 PyObject *value;
9481
9482 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9483 goto exit;
9484 }
9485 if (!PyUnicode_Check(args[0])) {
9486 _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
9487 goto exit;
9488 }
9489 name = args[0];
9490 if (!PyUnicode_Check(args[1])) {
9491 _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
9492 goto exit;
9493 }
9494 value = args[1];
9495 return_value = os_putenv_impl(module, name, value);
9496
9497 exit:
9498 return return_value;
9499 }
9500
9501 #endif /* defined(MS_WINDOWS) */
9502
9503 #if !defined(MS_WINDOWS)
9504
9505 PyDoc_STRVAR(os_putenv__doc__,
9506 "putenv($module, name, value, /)\n"
9507 "--\n"
9508 "\n"
9509 "Change or add an environment variable.");
9510
9511 #define OS_PUTENV_METHODDEF \
9512 {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
9513
9514 static PyObject *
9515 os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
9516
9517 static PyObject *
9518 os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9519 {
9520 PyObject *return_value = NULL;
9521 PyObject *name = NULL;
9522 PyObject *value = NULL;
9523
9524 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
9525 goto exit;
9526 }
9527 if (!PyUnicode_FSConverter(args[0], &name)) {
9528 goto exit;
9529 }
9530 if (!PyUnicode_FSConverter(args[1], &value)) {
9531 goto exit;
9532 }
9533 return_value = os_putenv_impl(module, name, value);
9534
9535 exit:
9536 /* Cleanup for name */
9537 Py_XDECREF(name);
9538 /* Cleanup for value */
9539 Py_XDECREF(value);
9540
9541 return return_value;
9542 }
9543
9544 #endif /* !defined(MS_WINDOWS) */
9545
9546 #if defined(MS_WINDOWS)
9547
9548 PyDoc_STRVAR(os_unsetenv__doc__,
9549 "unsetenv($module, name, /)\n"
9550 "--\n"
9551 "\n"
9552 "Delete an environment variable.");
9553
9554 #define OS_UNSETENV_METHODDEF \
9555 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9556
9557 static PyObject *
9558 os_unsetenv_impl(PyObject *module, PyObject *name);
9559
9560 static PyObject *
9561 os_unsetenv(PyObject *module, PyObject *arg)
9562 {
9563 PyObject *return_value = NULL;
9564 PyObject *name;
9565
9566 if (!PyUnicode_Check(arg)) {
9567 _PyArg_BadArgument("unsetenv", "argument", "str", arg);
9568 goto exit;
9569 }
9570 name = arg;
9571 return_value = os_unsetenv_impl(module, name);
9572
9573 exit:
9574 return return_value;
9575 }
9576
9577 #endif /* defined(MS_WINDOWS) */
9578
9579 #if !defined(MS_WINDOWS)
9580
9581 PyDoc_STRVAR(os_unsetenv__doc__,
9582 "unsetenv($module, name, /)\n"
9583 "--\n"
9584 "\n"
9585 "Delete an environment variable.");
9586
9587 #define OS_UNSETENV_METHODDEF \
9588 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
9589
9590 static PyObject *
9591 os_unsetenv_impl(PyObject *module, PyObject *name);
9592
9593 static PyObject *
9594 os_unsetenv(PyObject *module, PyObject *arg)
9595 {
9596 PyObject *return_value = NULL;
9597 PyObject *name = NULL;
9598
9599 if (!PyUnicode_FSConverter(arg, &name)) {
9600 goto exit;
9601 }
9602 return_value = os_unsetenv_impl(module, name);
9603
9604 exit:
9605 /* Cleanup for name */
9606 Py_XDECREF(name);
9607
9608 return return_value;
9609 }
9610
9611 #endif /* !defined(MS_WINDOWS) */
9612
9613 PyDoc_STRVAR(os_strerror__doc__,
9614 "strerror($module, code, /)\n"
9615 "--\n"
9616 "\n"
9617 "Translate an error code to a message string.");
9618
9619 #define OS_STRERROR_METHODDEF \
9620 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
9621
9622 static PyObject *
9623 os_strerror_impl(PyObject *module, int code);
9624
9625 static PyObject *
9626 os_strerror(PyObject *module, PyObject *arg)
9627 {
9628 PyObject *return_value = NULL;
9629 int code;
9630
9631 code = PyLong_AsInt(arg);
9632 if (code == -1 && PyErr_Occurred()) {
9633 goto exit;
9634 }
9635 return_value = os_strerror_impl(module, code);
9636
9637 exit:
9638 return return_value;
9639 }
9640
9641 #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
9642
9643 PyDoc_STRVAR(os_WCOREDUMP__doc__,
9644 "WCOREDUMP($module, status, /)\n"
9645 "--\n"
9646 "\n"
9647 "Return True if the process returning status was dumped to a core file.");
9648
9649 #define OS_WCOREDUMP_METHODDEF \
9650 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
9651
9652 static int
9653 os_WCOREDUMP_impl(PyObject *module, int status);
9654
9655 static PyObject *
9656 os_WCOREDUMP(PyObject *module, PyObject *arg)
9657 {
9658 PyObject *return_value = NULL;
9659 int status;
9660 int _return_value;
9661
9662 status = PyLong_AsInt(arg);
9663 if (status == -1 && PyErr_Occurred()) {
9664 goto exit;
9665 }
9666 _return_value = os_WCOREDUMP_impl(module, status);
9667 if ((_return_value == -1) && PyErr_Occurred()) {
9668 goto exit;
9669 }
9670 return_value = PyBool_FromLong((long)_return_value);
9671
9672 exit:
9673 return return_value;
9674 }
9675
9676 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
9677
9678 #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
9679
9680 PyDoc_STRVAR(os_WIFCONTINUED__doc__,
9681 "WIFCONTINUED($module, /, status)\n"
9682 "--\n"
9683 "\n"
9684 "Return True if a particular process was continued from a job control stop.\n"
9685 "\n"
9686 "Return True if the process returning status was continued from a\n"
9687 "job control stop.");
9688
9689 #define OS_WIFCONTINUED_METHODDEF \
9690 {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
9691
9692 static int
9693 os_WIFCONTINUED_impl(PyObject *module, int status);
9694
9695 static PyObject *
9696 os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9697 {
9698 PyObject *return_value = NULL;
9699 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9700
9701 #define NUM_KEYWORDS 1
9702 static struct {
9703 PyGC_Head _this_is_not_used;
9704 PyObject_VAR_HEAD
9705 Py_hash_t ob_hash;
9706 PyObject *ob_item[NUM_KEYWORDS];
9707 } _kwtuple = {
9708 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9709 .ob_hash = -1,
9710 .ob_item = { &_Py_ID(status), },
9711 };
9712 #undef NUM_KEYWORDS
9713 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9714
9715 #else // !Py_BUILD_CORE
9716 # define KWTUPLE NULL
9717 #endif // !Py_BUILD_CORE
9718
9719 static const char * const _keywords[] = {"status", NULL};
9720 static _PyArg_Parser _parser = {
9721 .keywords = _keywords,
9722 .fname = "WIFCONTINUED",
9723 .kwtuple = KWTUPLE,
9724 };
9725 #undef KWTUPLE
9726 PyObject *argsbuf[1];
9727 int status;
9728 int _return_value;
9729
9730 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9731 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9732 if (!args) {
9733 goto exit;
9734 }
9735 status = PyLong_AsInt(args[0]);
9736 if (status == -1 && PyErr_Occurred()) {
9737 goto exit;
9738 }
9739 _return_value = os_WIFCONTINUED_impl(module, status);
9740 if ((_return_value == -1) && PyErr_Occurred()) {
9741 goto exit;
9742 }
9743 return_value = PyBool_FromLong((long)_return_value);
9744
9745 exit:
9746 return return_value;
9747 }
9748
9749 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
9750
9751 #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
9752
9753 PyDoc_STRVAR(os_WIFSTOPPED__doc__,
9754 "WIFSTOPPED($module, /, status)\n"
9755 "--\n"
9756 "\n"
9757 "Return True if the process returning status was stopped.");
9758
9759 #define OS_WIFSTOPPED_METHODDEF \
9760 {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
9761
9762 static int
9763 os_WIFSTOPPED_impl(PyObject *module, int status);
9764
9765 static PyObject *
9766 os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9767 {
9768 PyObject *return_value = NULL;
9769 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9770
9771 #define NUM_KEYWORDS 1
9772 static struct {
9773 PyGC_Head _this_is_not_used;
9774 PyObject_VAR_HEAD
9775 Py_hash_t ob_hash;
9776 PyObject *ob_item[NUM_KEYWORDS];
9777 } _kwtuple = {
9778 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9779 .ob_hash = -1,
9780 .ob_item = { &_Py_ID(status), },
9781 };
9782 #undef NUM_KEYWORDS
9783 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9784
9785 #else // !Py_BUILD_CORE
9786 # define KWTUPLE NULL
9787 #endif // !Py_BUILD_CORE
9788
9789 static const char * const _keywords[] = {"status", NULL};
9790 static _PyArg_Parser _parser = {
9791 .keywords = _keywords,
9792 .fname = "WIFSTOPPED",
9793 .kwtuple = KWTUPLE,
9794 };
9795 #undef KWTUPLE
9796 PyObject *argsbuf[1];
9797 int status;
9798 int _return_value;
9799
9800 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9801 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9802 if (!args) {
9803 goto exit;
9804 }
9805 status = PyLong_AsInt(args[0]);
9806 if (status == -1 && PyErr_Occurred()) {
9807 goto exit;
9808 }
9809 _return_value = os_WIFSTOPPED_impl(module, status);
9810 if ((_return_value == -1) && PyErr_Occurred()) {
9811 goto exit;
9812 }
9813 return_value = PyBool_FromLong((long)_return_value);
9814
9815 exit:
9816 return return_value;
9817 }
9818
9819 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
9820
9821 #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
9822
9823 PyDoc_STRVAR(os_WIFSIGNALED__doc__,
9824 "WIFSIGNALED($module, /, status)\n"
9825 "--\n"
9826 "\n"
9827 "Return True if the process returning status was terminated by a signal.");
9828
9829 #define OS_WIFSIGNALED_METHODDEF \
9830 {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
9831
9832 static int
9833 os_WIFSIGNALED_impl(PyObject *module, int status);
9834
9835 static PyObject *
9836 os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9837 {
9838 PyObject *return_value = NULL;
9839 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9840
9841 #define NUM_KEYWORDS 1
9842 static struct {
9843 PyGC_Head _this_is_not_used;
9844 PyObject_VAR_HEAD
9845 Py_hash_t ob_hash;
9846 PyObject *ob_item[NUM_KEYWORDS];
9847 } _kwtuple = {
9848 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9849 .ob_hash = -1,
9850 .ob_item = { &_Py_ID(status), },
9851 };
9852 #undef NUM_KEYWORDS
9853 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9854
9855 #else // !Py_BUILD_CORE
9856 # define KWTUPLE NULL
9857 #endif // !Py_BUILD_CORE
9858
9859 static const char * const _keywords[] = {"status", NULL};
9860 static _PyArg_Parser _parser = {
9861 .keywords = _keywords,
9862 .fname = "WIFSIGNALED",
9863 .kwtuple = KWTUPLE,
9864 };
9865 #undef KWTUPLE
9866 PyObject *argsbuf[1];
9867 int status;
9868 int _return_value;
9869
9870 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9871 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9872 if (!args) {
9873 goto exit;
9874 }
9875 status = PyLong_AsInt(args[0]);
9876 if (status == -1 && PyErr_Occurred()) {
9877 goto exit;
9878 }
9879 _return_value = os_WIFSIGNALED_impl(module, status);
9880 if ((_return_value == -1) && PyErr_Occurred()) {
9881 goto exit;
9882 }
9883 return_value = PyBool_FromLong((long)_return_value);
9884
9885 exit:
9886 return return_value;
9887 }
9888
9889 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
9890
9891 #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
9892
9893 PyDoc_STRVAR(os_WIFEXITED__doc__,
9894 "WIFEXITED($module, /, status)\n"
9895 "--\n"
9896 "\n"
9897 "Return True if the process returning status exited via the exit() system call.");
9898
9899 #define OS_WIFEXITED_METHODDEF \
9900 {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
9901
9902 static int
9903 os_WIFEXITED_impl(PyObject *module, int status);
9904
9905 static PyObject *
9906 os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9907 {
9908 PyObject *return_value = NULL;
9909 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9910
9911 #define NUM_KEYWORDS 1
9912 static struct {
9913 PyGC_Head _this_is_not_used;
9914 PyObject_VAR_HEAD
9915 Py_hash_t ob_hash;
9916 PyObject *ob_item[NUM_KEYWORDS];
9917 } _kwtuple = {
9918 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9919 .ob_hash = -1,
9920 .ob_item = { &_Py_ID(status), },
9921 };
9922 #undef NUM_KEYWORDS
9923 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9924
9925 #else // !Py_BUILD_CORE
9926 # define KWTUPLE NULL
9927 #endif // !Py_BUILD_CORE
9928
9929 static const char * const _keywords[] = {"status", NULL};
9930 static _PyArg_Parser _parser = {
9931 .keywords = _keywords,
9932 .fname = "WIFEXITED",
9933 .kwtuple = KWTUPLE,
9934 };
9935 #undef KWTUPLE
9936 PyObject *argsbuf[1];
9937 int status;
9938 int _return_value;
9939
9940 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
9941 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
9942 if (!args) {
9943 goto exit;
9944 }
9945 status = PyLong_AsInt(args[0]);
9946 if (status == -1 && PyErr_Occurred()) {
9947 goto exit;
9948 }
9949 _return_value = os_WIFEXITED_impl(module, status);
9950 if ((_return_value == -1) && PyErr_Occurred()) {
9951 goto exit;
9952 }
9953 return_value = PyBool_FromLong((long)_return_value);
9954
9955 exit:
9956 return return_value;
9957 }
9958
9959 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
9960
9961 #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
9962
9963 PyDoc_STRVAR(os_WEXITSTATUS__doc__,
9964 "WEXITSTATUS($module, /, status)\n"
9965 "--\n"
9966 "\n"
9967 "Return the process return code from status.");
9968
9969 #define OS_WEXITSTATUS_METHODDEF \
9970 {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
9971
9972 static int
9973 os_WEXITSTATUS_impl(PyObject *module, int status);
9974
9975 static PyObject *
9976 os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9977 {
9978 PyObject *return_value = NULL;
9979 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9980
9981 #define NUM_KEYWORDS 1
9982 static struct {
9983 PyGC_Head _this_is_not_used;
9984 PyObject_VAR_HEAD
9985 Py_hash_t ob_hash;
9986 PyObject *ob_item[NUM_KEYWORDS];
9987 } _kwtuple = {
9988 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9989 .ob_hash = -1,
9990 .ob_item = { &_Py_ID(status), },
9991 };
9992 #undef NUM_KEYWORDS
9993 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9994
9995 #else // !Py_BUILD_CORE
9996 # define KWTUPLE NULL
9997 #endif // !Py_BUILD_CORE
9998
9999 static const char * const _keywords[] = {"status", NULL};
10000 static _PyArg_Parser _parser = {
10001 .keywords = _keywords,
10002 .fname = "WEXITSTATUS",
10003 .kwtuple = KWTUPLE,
10004 };
10005 #undef KWTUPLE
10006 PyObject *argsbuf[1];
10007 int status;
10008 int _return_value;
10009
10010 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10011 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10012 if (!args) {
10013 goto exit;
10014 }
10015 status = PyLong_AsInt(args[0]);
10016 if (status == -1 && PyErr_Occurred()) {
10017 goto exit;
10018 }
10019 _return_value = os_WEXITSTATUS_impl(module, status);
10020 if ((_return_value == -1) && PyErr_Occurred()) {
10021 goto exit;
10022 }
10023 return_value = PyLong_FromLong((long)_return_value);
10024
10025 exit:
10026 return return_value;
10027 }
10028
10029 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
10030
10031 #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
10032
10033 PyDoc_STRVAR(os_WTERMSIG__doc__,
10034 "WTERMSIG($module, /, status)\n"
10035 "--\n"
10036 "\n"
10037 "Return the signal that terminated the process that provided the status value.");
10038
10039 #define OS_WTERMSIG_METHODDEF \
10040 {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
10041
10042 static int
10043 os_WTERMSIG_impl(PyObject *module, int status);
10044
10045 static PyObject *
10046 os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10047 {
10048 PyObject *return_value = NULL;
10049 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10050
10051 #define NUM_KEYWORDS 1
10052 static struct {
10053 PyGC_Head _this_is_not_used;
10054 PyObject_VAR_HEAD
10055 Py_hash_t ob_hash;
10056 PyObject *ob_item[NUM_KEYWORDS];
10057 } _kwtuple = {
10058 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10059 .ob_hash = -1,
10060 .ob_item = { &_Py_ID(status), },
10061 };
10062 #undef NUM_KEYWORDS
10063 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10064
10065 #else // !Py_BUILD_CORE
10066 # define KWTUPLE NULL
10067 #endif // !Py_BUILD_CORE
10068
10069 static const char * const _keywords[] = {"status", NULL};
10070 static _PyArg_Parser _parser = {
10071 .keywords = _keywords,
10072 .fname = "WTERMSIG",
10073 .kwtuple = KWTUPLE,
10074 };
10075 #undef KWTUPLE
10076 PyObject *argsbuf[1];
10077 int status;
10078 int _return_value;
10079
10080 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10081 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10082 if (!args) {
10083 goto exit;
10084 }
10085 status = PyLong_AsInt(args[0]);
10086 if (status == -1 && PyErr_Occurred()) {
10087 goto exit;
10088 }
10089 _return_value = os_WTERMSIG_impl(module, status);
10090 if ((_return_value == -1) && PyErr_Occurred()) {
10091 goto exit;
10092 }
10093 return_value = PyLong_FromLong((long)_return_value);
10094
10095 exit:
10096 return return_value;
10097 }
10098
10099 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
10100
10101 #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
10102
10103 PyDoc_STRVAR(os_WSTOPSIG__doc__,
10104 "WSTOPSIG($module, /, status)\n"
10105 "--\n"
10106 "\n"
10107 "Return the signal that stopped the process that provided the status value.");
10108
10109 #define OS_WSTOPSIG_METHODDEF \
10110 {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
10111
10112 static int
10113 os_WSTOPSIG_impl(PyObject *module, int status);
10114
10115 static PyObject *
10116 os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10117 {
10118 PyObject *return_value = NULL;
10119 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10120
10121 #define NUM_KEYWORDS 1
10122 static struct {
10123 PyGC_Head _this_is_not_used;
10124 PyObject_VAR_HEAD
10125 Py_hash_t ob_hash;
10126 PyObject *ob_item[NUM_KEYWORDS];
10127 } _kwtuple = {
10128 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10129 .ob_hash = -1,
10130 .ob_item = { &_Py_ID(status), },
10131 };
10132 #undef NUM_KEYWORDS
10133 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10134
10135 #else // !Py_BUILD_CORE
10136 # define KWTUPLE NULL
10137 #endif // !Py_BUILD_CORE
10138
10139 static const char * const _keywords[] = {"status", NULL};
10140 static _PyArg_Parser _parser = {
10141 .keywords = _keywords,
10142 .fname = "WSTOPSIG",
10143 .kwtuple = KWTUPLE,
10144 };
10145 #undef KWTUPLE
10146 PyObject *argsbuf[1];
10147 int status;
10148 int _return_value;
10149
10150 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10151 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10152 if (!args) {
10153 goto exit;
10154 }
10155 status = PyLong_AsInt(args[0]);
10156 if (status == -1 && PyErr_Occurred()) {
10157 goto exit;
10158 }
10159 _return_value = os_WSTOPSIG_impl(module, status);
10160 if ((_return_value == -1) && PyErr_Occurred()) {
10161 goto exit;
10162 }
10163 return_value = PyLong_FromLong((long)_return_value);
10164
10165 exit:
10166 return return_value;
10167 }
10168
10169 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
10170
10171 #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
10172
10173 PyDoc_STRVAR(os_fstatvfs__doc__,
10174 "fstatvfs($module, fd, /)\n"
10175 "--\n"
10176 "\n"
10177 "Perform an fstatvfs system call on the given fd.\n"
10178 "\n"
10179 "Equivalent to statvfs(fd).");
10180
10181 #define OS_FSTATVFS_METHODDEF \
10182 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
10183
10184 static PyObject *
10185 os_fstatvfs_impl(PyObject *module, int fd);
10186
10187 static PyObject *
10188 os_fstatvfs(PyObject *module, PyObject *arg)
10189 {
10190 PyObject *return_value = NULL;
10191 int fd;
10192
10193 fd = PyLong_AsInt(arg);
10194 if (fd == -1 && PyErr_Occurred()) {
10195 goto exit;
10196 }
10197 return_value = os_fstatvfs_impl(module, fd);
10198
10199 exit:
10200 return return_value;
10201 }
10202
10203 #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10204
10205 #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
10206
10207 PyDoc_STRVAR(os_statvfs__doc__,
10208 "statvfs($module, /, path)\n"
10209 "--\n"
10210 "\n"
10211 "Perform a statvfs system call on the given path.\n"
10212 "\n"
10213 "path may always be specified as a string.\n"
10214 "On some platforms, path may also be specified as an open file\n"
10215 "descriptor. If this functionality is unavailable, using it raises\n"
10216 "an exception.");
10217
10218 #define OS_STATVFS_METHODDEF \
10219 {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
10220
10221 static PyObject *
10222 os_statvfs_impl(PyObject *module, path_t *path);
10223
10224 static PyObject *
10225 os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10226 {
10227 PyObject *return_value = NULL;
10228 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10229
10230 #define NUM_KEYWORDS 1
10231 static struct {
10232 PyGC_Head _this_is_not_used;
10233 PyObject_VAR_HEAD
10234 Py_hash_t ob_hash;
10235 PyObject *ob_item[NUM_KEYWORDS];
10236 } _kwtuple = {
10237 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10238 .ob_hash = -1,
10239 .ob_item = { &_Py_ID(path), },
10240 };
10241 #undef NUM_KEYWORDS
10242 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10243
10244 #else // !Py_BUILD_CORE
10245 # define KWTUPLE NULL
10246 #endif // !Py_BUILD_CORE
10247
10248 static const char * const _keywords[] = {"path", NULL};
10249 static _PyArg_Parser _parser = {
10250 .keywords = _keywords,
10251 .fname = "statvfs",
10252 .kwtuple = KWTUPLE,
10253 };
10254 #undef KWTUPLE
10255 PyObject *argsbuf[1];
10256 path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
10257
10258 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10259 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10260 if (!args) {
10261 goto exit;
10262 }
10263 if (!path_converter(args[0], &path)) {
10264 goto exit;
10265 }
10266 return_value = os_statvfs_impl(module, &path);
10267
10268 exit:
10269 /* Cleanup for path */
10270 path_cleanup(&path);
10271
10272 return return_value;
10273 }
10274
10275 #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
10276
10277 #if defined(MS_WINDOWS)
10278
10279 PyDoc_STRVAR(os__getdiskusage__doc__,
10280 "_getdiskusage($module, /, path)\n"
10281 "--\n"
10282 "\n"
10283 "Return disk usage statistics about the given path as a (total, free) tuple.");
10284
10285 #define OS__GETDISKUSAGE_METHODDEF \
10286 {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
10287
10288 static PyObject *
10289 os__getdiskusage_impl(PyObject *module, path_t *path);
10290
10291 static PyObject *
10292 os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10293 {
10294 PyObject *return_value = NULL;
10295 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10296
10297 #define NUM_KEYWORDS 1
10298 static struct {
10299 PyGC_Head _this_is_not_used;
10300 PyObject_VAR_HEAD
10301 Py_hash_t ob_hash;
10302 PyObject *ob_item[NUM_KEYWORDS];
10303 } _kwtuple = {
10304 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10305 .ob_hash = -1,
10306 .ob_item = { &_Py_ID(path), },
10307 };
10308 #undef NUM_KEYWORDS
10309 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10310
10311 #else // !Py_BUILD_CORE
10312 # define KWTUPLE NULL
10313 #endif // !Py_BUILD_CORE
10314
10315 static const char * const _keywords[] = {"path", NULL};
10316 static _PyArg_Parser _parser = {
10317 .keywords = _keywords,
10318 .fname = "_getdiskusage",
10319 .kwtuple = KWTUPLE,
10320 };
10321 #undef KWTUPLE
10322 PyObject *argsbuf[1];
10323 path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
10324
10325 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10326 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10327 if (!args) {
10328 goto exit;
10329 }
10330 if (!path_converter(args[0], &path)) {
10331 goto exit;
10332 }
10333 return_value = os__getdiskusage_impl(module, &path);
10334
10335 exit:
10336 /* Cleanup for path */
10337 path_cleanup(&path);
10338
10339 return return_value;
10340 }
10341
10342 #endif /* defined(MS_WINDOWS) */
10343
10344 #if defined(HAVE_FPATHCONF)
10345
10346 PyDoc_STRVAR(os_fpathconf__doc__,
10347 "fpathconf($module, fd, name, /)\n"
10348 "--\n"
10349 "\n"
10350 "Return the configuration limit name for the file descriptor fd.\n"
10351 "\n"
10352 "If there is no limit, return -1.");
10353
10354 #define OS_FPATHCONF_METHODDEF \
10355 {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
10356
10357 static long
10358 os_fpathconf_impl(PyObject *module, int fd, int name);
10359
10360 static PyObject *
10361 os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10362 {
10363 PyObject *return_value = NULL;
10364 int fd;
10365 int name;
10366 long _return_value;
10367
10368 if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
10369 goto exit;
10370 }
10371 fd = PyObject_AsFileDescriptor(args[0]);
10372 if (fd < 0) {
10373 goto exit;
10374 }
10375 if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10376 goto exit;
10377 }
10378 _return_value = os_fpathconf_impl(module, fd, name);
10379 if ((_return_value == -1) && PyErr_Occurred()) {
10380 goto exit;
10381 }
10382 return_value = PyLong_FromLong(_return_value);
10383
10384 exit:
10385 return return_value;
10386 }
10387
10388 #endif /* defined(HAVE_FPATHCONF) */
10389
10390 #if defined(HAVE_PATHCONF)
10391
10392 PyDoc_STRVAR(os_pathconf__doc__,
10393 "pathconf($module, /, path, name)\n"
10394 "--\n"
10395 "\n"
10396 "Return the configuration limit name for the file or directory path.\n"
10397 "\n"
10398 "If there is no limit, return -1.\n"
10399 "On some platforms, path may also be specified as an open file\n"
10400 "descriptor. If this functionality is unavailable, using it raises\n"
10401 "an exception.");
10402
10403 #define OS_PATHCONF_METHODDEF \
10404 {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
10405
10406 static long
10407 os_pathconf_impl(PyObject *module, path_t *path, int name);
10408
10409 static PyObject *
10410 os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10411 {
10412 PyObject *return_value = NULL;
10413 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10414
10415 #define NUM_KEYWORDS 2
10416 static struct {
10417 PyGC_Head _this_is_not_used;
10418 PyObject_VAR_HEAD
10419 Py_hash_t ob_hash;
10420 PyObject *ob_item[NUM_KEYWORDS];
10421 } _kwtuple = {
10422 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10423 .ob_hash = -1,
10424 .ob_item = { &_Py_ID(path), &_Py_ID(name), },
10425 };
10426 #undef NUM_KEYWORDS
10427 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10428
10429 #else // !Py_BUILD_CORE
10430 # define KWTUPLE NULL
10431 #endif // !Py_BUILD_CORE
10432
10433 static const char * const _keywords[] = {"path", "name", NULL};
10434 static _PyArg_Parser _parser = {
10435 .keywords = _keywords,
10436 .fname = "pathconf",
10437 .kwtuple = KWTUPLE,
10438 };
10439 #undef KWTUPLE
10440 PyObject *argsbuf[2];
10441 path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
10442 int name;
10443 long _return_value;
10444
10445 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10446 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10447 if (!args) {
10448 goto exit;
10449 }
10450 if (!path_converter(args[0], &path)) {
10451 goto exit;
10452 }
10453 if (!conv_confname(module, args[1], &name, "pathconf_names")) {
10454 goto exit;
10455 }
10456 _return_value = os_pathconf_impl(module, &path, name);
10457 if ((_return_value == -1) && PyErr_Occurred()) {
10458 goto exit;
10459 }
10460 return_value = PyLong_FromLong(_return_value);
10461
10462 exit:
10463 /* Cleanup for path */
10464 path_cleanup(&path);
10465
10466 return return_value;
10467 }
10468
10469 #endif /* defined(HAVE_PATHCONF) */
10470
10471 #if defined(HAVE_CONFSTR)
10472
10473 PyDoc_STRVAR(os_confstr__doc__,
10474 "confstr($module, name, /)\n"
10475 "--\n"
10476 "\n"
10477 "Return a string-valued system configuration variable.");
10478
10479 #define OS_CONFSTR_METHODDEF \
10480 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
10481
10482 static PyObject *
10483 os_confstr_impl(PyObject *module, int name);
10484
10485 static PyObject *
10486 os_confstr(PyObject *module, PyObject *arg)
10487 {
10488 PyObject *return_value = NULL;
10489 int name;
10490
10491 if (!conv_confname(module, arg, &name, "confstr_names")) {
10492 goto exit;
10493 }
10494 return_value = os_confstr_impl(module, name);
10495
10496 exit:
10497 return return_value;
10498 }
10499
10500 #endif /* defined(HAVE_CONFSTR) */
10501
10502 #if defined(HAVE_SYSCONF)
10503
10504 PyDoc_STRVAR(os_sysconf__doc__,
10505 "sysconf($module, name, /)\n"
10506 "--\n"
10507 "\n"
10508 "Return an integer-valued system configuration variable.");
10509
10510 #define OS_SYSCONF_METHODDEF \
10511 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
10512
10513 static long
10514 os_sysconf_impl(PyObject *module, int name);
10515
10516 static PyObject *
10517 os_sysconf(PyObject *module, PyObject *arg)
10518 {
10519 PyObject *return_value = NULL;
10520 int name;
10521 long _return_value;
10522
10523 if (!conv_confname(module, arg, &name, "sysconf_names")) {
10524 goto exit;
10525 }
10526 _return_value = os_sysconf_impl(module, name);
10527 if ((_return_value == -1) && PyErr_Occurred()) {
10528 goto exit;
10529 }
10530 return_value = PyLong_FromLong(_return_value);
10531
10532 exit:
10533 return return_value;
10534 }
10535
10536 #endif /* defined(HAVE_SYSCONF) */
10537
10538 PyDoc_STRVAR(os_abort__doc__,
10539 "abort($module, /)\n"
10540 "--\n"
10541 "\n"
10542 "Abort the interpreter immediately.\n"
10543 "\n"
10544 "This function \'dumps core\' or otherwise fails in the hardest way\n"
10545 "possible on the hosting operating system. This function never returns.");
10546
10547 #define OS_ABORT_METHODDEF \
10548 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
10549
10550 static PyObject *
10551 os_abort_impl(PyObject *module);
10552
10553 static PyObject *
10554 os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
10555 {
10556 return os_abort_impl(module);
10557 }
10558
10559 #if defined(MS_WINDOWS)
10560
10561 PyDoc_STRVAR(os_startfile__doc__,
10562 "startfile($module, /, filepath, operation=<unrepresentable>,\n"
10563 " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
10564 "--\n"
10565 "\n"
10566 "Start a file with its associated application.\n"
10567 "\n"
10568 "When \"operation\" is not specified or \"open\", this acts like\n"
10569 "double-clicking the file in Explorer, or giving the file name as an\n"
10570 "argument to the DOS \"start\" command: the file is opened with whatever\n"
10571 "application (if any) its extension is associated.\n"
10572 "When another \"operation\" is given, it specifies what should be done with\n"
10573 "the file. A typical operation is \"print\".\n"
10574 "\n"
10575 "\"arguments\" is passed to the application, but should be omitted if the\n"
10576 "file is a document.\n"
10577 "\n"
10578 "\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
10579 "relative, it will be resolved against this directory. This argument\n"
10580 "should usually be an absolute path.\n"
10581 "\n"
10582 "\"show_cmd\" can be used to override the recommended visibility option.\n"
10583 "See the Windows ShellExecute documentation for values.\n"
10584 "\n"
10585 "startfile returns as soon as the associated application is launched.\n"
10586 "There is no option to wait for the application to close, and no way\n"
10587 "to retrieve the application\'s exit status.\n"
10588 "\n"
10589 "The filepath is relative to the current directory. If you want to use\n"
10590 "an absolute path, make sure the first character is not a slash (\"/\");\n"
10591 "the underlying Win32 ShellExecute function doesn\'t work if it is.");
10592
10593 #define OS_STARTFILE_METHODDEF \
10594 {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
10595
10596 static PyObject *
10597 os_startfile_impl(PyObject *module, path_t *filepath,
10598 const wchar_t *operation, const wchar_t *arguments,
10599 path_t *cwd, int show_cmd);
10600
10601 static PyObject *
10602 os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10603 {
10604 PyObject *return_value = NULL;
10605 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10606
10607 #define NUM_KEYWORDS 5
10608 static struct {
10609 PyGC_Head _this_is_not_used;
10610 PyObject_VAR_HEAD
10611 Py_hash_t ob_hash;
10612 PyObject *ob_item[NUM_KEYWORDS];
10613 } _kwtuple = {
10614 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10615 .ob_hash = -1,
10616 .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
10617 };
10618 #undef NUM_KEYWORDS
10619 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10620
10621 #else // !Py_BUILD_CORE
10622 # define KWTUPLE NULL
10623 #endif // !Py_BUILD_CORE
10624
10625 static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
10626 static _PyArg_Parser _parser = {
10627 .keywords = _keywords,
10628 .fname = "startfile",
10629 .kwtuple = KWTUPLE,
10630 };
10631 #undef KWTUPLE
10632 PyObject *argsbuf[5];
10633 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
10634 path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
10635 const wchar_t *operation = NULL;
10636 const wchar_t *arguments = NULL;
10637 path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
10638 int show_cmd = 1;
10639
10640 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10641 /*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10642 if (!args) {
10643 goto exit;
10644 }
10645 if (!path_converter(args[0], &filepath)) {
10646 goto exit;
10647 }
10648 if (!noptargs) {
10649 goto skip_optional_pos;
10650 }
10651 if (args[1]) {
10652 if (!PyUnicode_Check(args[1])) {
10653 _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
10654 goto exit;
10655 }
10656 operation = PyUnicode_AsWideCharString(args[1], NULL);
10657 if (operation == NULL) {
10658 goto exit;
10659 }
10660 if (!--noptargs) {
10661 goto skip_optional_pos;
10662 }
10663 }
10664 if (args[2]) {
10665 if (!PyUnicode_Check(args[2])) {
10666 _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
10667 goto exit;
10668 }
10669 arguments = PyUnicode_AsWideCharString(args[2], NULL);
10670 if (arguments == NULL) {
10671 goto exit;
10672 }
10673 if (!--noptargs) {
10674 goto skip_optional_pos;
10675 }
10676 }
10677 if (args[3]) {
10678 if (!path_converter(args[3], &cwd)) {
10679 goto exit;
10680 }
10681 if (!--noptargs) {
10682 goto skip_optional_pos;
10683 }
10684 }
10685 show_cmd = PyLong_AsInt(args[4]);
10686 if (show_cmd == -1 && PyErr_Occurred()) {
10687 goto exit;
10688 }
10689 skip_optional_pos:
10690 return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
10691
10692 exit:
10693 /* Cleanup for filepath */
10694 path_cleanup(&filepath);
10695 /* Cleanup for operation */
10696 PyMem_Free((void *)operation);
10697 /* Cleanup for arguments */
10698 PyMem_Free((void *)arguments);
10699 /* Cleanup for cwd */
10700 path_cleanup(&cwd);
10701
10702 return return_value;
10703 }
10704
10705 #endif /* defined(MS_WINDOWS) */
10706
10707 #if defined(HAVE_GETLOADAVG)
10708
10709 PyDoc_STRVAR(os_getloadavg__doc__,
10710 "getloadavg($module, /)\n"
10711 "--\n"
10712 "\n"
10713 "Return average recent system load information.\n"
10714 "\n"
10715 "Return the number of processes in the system run queue averaged over\n"
10716 "the last 1, 5, and 15 minutes as a tuple of three floats.\n"
10717 "Raises OSError if the load average was unobtainable.");
10718
10719 #define OS_GETLOADAVG_METHODDEF \
10720 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
10721
10722 static PyObject *
10723 os_getloadavg_impl(PyObject *module);
10724
10725 static PyObject *
10726 os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
10727 {
10728 return os_getloadavg_impl(module);
10729 }
10730
10731 #endif /* defined(HAVE_GETLOADAVG) */
10732
10733 PyDoc_STRVAR(os_device_encoding__doc__,
10734 "device_encoding($module, /, fd)\n"
10735 "--\n"
10736 "\n"
10737 "Return a string describing the encoding of a terminal\'s file descriptor.\n"
10738 "\n"
10739 "The file descriptor must be attached to a terminal.\n"
10740 "If the device is not a terminal, return None.");
10741
10742 #define OS_DEVICE_ENCODING_METHODDEF \
10743 {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
10744
10745 static PyObject *
10746 os_device_encoding_impl(PyObject *module, int fd);
10747
10748 static PyObject *
10749 os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10750 {
10751 PyObject *return_value = NULL;
10752 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10753
10754 #define NUM_KEYWORDS 1
10755 static struct {
10756 PyGC_Head _this_is_not_used;
10757 PyObject_VAR_HEAD
10758 Py_hash_t ob_hash;
10759 PyObject *ob_item[NUM_KEYWORDS];
10760 } _kwtuple = {
10761 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10762 .ob_hash = -1,
10763 .ob_item = { &_Py_ID(fd), },
10764 };
10765 #undef NUM_KEYWORDS
10766 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10767
10768 #else // !Py_BUILD_CORE
10769 # define KWTUPLE NULL
10770 #endif // !Py_BUILD_CORE
10771
10772 static const char * const _keywords[] = {"fd", NULL};
10773 static _PyArg_Parser _parser = {
10774 .keywords = _keywords,
10775 .fname = "device_encoding",
10776 .kwtuple = KWTUPLE,
10777 };
10778 #undef KWTUPLE
10779 PyObject *argsbuf[1];
10780 int fd;
10781
10782 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10783 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10784 if (!args) {
10785 goto exit;
10786 }
10787 fd = PyLong_AsInt(args[0]);
10788 if (fd == -1 && PyErr_Occurred()) {
10789 goto exit;
10790 }
10791 return_value = os_device_encoding_impl(module, fd);
10792
10793 exit:
10794 return return_value;
10795 }
10796
10797 #if defined(HAVE_SETRESUID)
10798
10799 PyDoc_STRVAR(os_setresuid__doc__,
10800 "setresuid($module, ruid, euid, suid, /)\n"
10801 "--\n"
10802 "\n"
10803 "Set the current process\'s real, effective, and saved user ids.");
10804
10805 #define OS_SETRESUID_METHODDEF \
10806 {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
10807
10808 static PyObject *
10809 os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
10810
10811 static PyObject *
10812 os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10813 {
10814 PyObject *return_value = NULL;
10815 uid_t ruid;
10816 uid_t euid;
10817 uid_t suid;
10818
10819 if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
10820 goto exit;
10821 }
10822 if (!_Py_Uid_Converter(args[0], &ruid)) {
10823 goto exit;
10824 }
10825 if (!_Py_Uid_Converter(args[1], &euid)) {
10826 goto exit;
10827 }
10828 if (!_Py_Uid_Converter(args[2], &suid)) {
10829 goto exit;
10830 }
10831 return_value = os_setresuid_impl(module, ruid, euid, suid);
10832
10833 exit:
10834 return return_value;
10835 }
10836
10837 #endif /* defined(HAVE_SETRESUID) */
10838
10839 #if defined(HAVE_SETRESGID)
10840
10841 PyDoc_STRVAR(os_setresgid__doc__,
10842 "setresgid($module, rgid, egid, sgid, /)\n"
10843 "--\n"
10844 "\n"
10845 "Set the current process\'s real, effective, and saved group ids.");
10846
10847 #define OS_SETRESGID_METHODDEF \
10848 {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
10849
10850 static PyObject *
10851 os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
10852
10853 static PyObject *
10854 os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10855 {
10856 PyObject *return_value = NULL;
10857 gid_t rgid;
10858 gid_t egid;
10859 gid_t sgid;
10860
10861 if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
10862 goto exit;
10863 }
10864 if (!_Py_Gid_Converter(args[0], &rgid)) {
10865 goto exit;
10866 }
10867 if (!_Py_Gid_Converter(args[1], &egid)) {
10868 goto exit;
10869 }
10870 if (!_Py_Gid_Converter(args[2], &sgid)) {
10871 goto exit;
10872 }
10873 return_value = os_setresgid_impl(module, rgid, egid, sgid);
10874
10875 exit:
10876 return return_value;
10877 }
10878
10879 #endif /* defined(HAVE_SETRESGID) */
10880
10881 #if defined(HAVE_GETRESUID)
10882
10883 PyDoc_STRVAR(os_getresuid__doc__,
10884 "getresuid($module, /)\n"
10885 "--\n"
10886 "\n"
10887 "Return a tuple of the current process\'s real, effective, and saved user ids.");
10888
10889 #define OS_GETRESUID_METHODDEF \
10890 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
10891
10892 static PyObject *
10893 os_getresuid_impl(PyObject *module);
10894
10895 static PyObject *
10896 os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
10897 {
10898 return os_getresuid_impl(module);
10899 }
10900
10901 #endif /* defined(HAVE_GETRESUID) */
10902
10903 #if defined(HAVE_GETRESGID)
10904
10905 PyDoc_STRVAR(os_getresgid__doc__,
10906 "getresgid($module, /)\n"
10907 "--\n"
10908 "\n"
10909 "Return a tuple of the current process\'s real, effective, and saved group ids.");
10910
10911 #define OS_GETRESGID_METHODDEF \
10912 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
10913
10914 static PyObject *
10915 os_getresgid_impl(PyObject *module);
10916
10917 static PyObject *
10918 os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
10919 {
10920 return os_getresgid_impl(module);
10921 }
10922
10923 #endif /* defined(HAVE_GETRESGID) */
10924
10925 #if defined(USE_XATTRS)
10926
10927 PyDoc_STRVAR(os_getxattr__doc__,
10928 "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
10929 "--\n"
10930 "\n"
10931 "Return the value of extended attribute attribute on path.\n"
10932 "\n"
10933 "path may be either a string, a path-like object, or an open file\n"
10934 "descriptor.\n"
10935 "If follow_symlinks is False, and the last element of the path is\n"
10936 "a symbolic link, getxattr will examine the symbolic link itself\n"
10937 "instead of the file the link points to.");
10938
10939 #define OS_GETXATTR_METHODDEF \
10940 {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
10941
10942 static PyObject *
10943 os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
10944 int follow_symlinks);
10945
10946 static PyObject *
10947 os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10948 {
10949 PyObject *return_value = NULL;
10950 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10951
10952 #define NUM_KEYWORDS 3
10953 static struct {
10954 PyGC_Head _this_is_not_used;
10955 PyObject_VAR_HEAD
10956 Py_hash_t ob_hash;
10957 PyObject *ob_item[NUM_KEYWORDS];
10958 } _kwtuple = {
10959 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10960 .ob_hash = -1,
10961 .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
10962 };
10963 #undef NUM_KEYWORDS
10964 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10965
10966 #else // !Py_BUILD_CORE
10967 # define KWTUPLE NULL
10968 #endif // !Py_BUILD_CORE
10969
10970 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
10971 static _PyArg_Parser _parser = {
10972 .keywords = _keywords,
10973 .fname = "getxattr",
10974 .kwtuple = KWTUPLE,
10975 };
10976 #undef KWTUPLE
10977 PyObject *argsbuf[3];
10978 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
10979 path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
10980 path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
10981 int follow_symlinks = 1;
10982
10983 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
10984 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
10985 if (!args) {
10986 goto exit;
10987 }
10988 if (!path_converter(args[0], &path)) {
10989 goto exit;
10990 }
10991 if (!path_converter(args[1], &attribute)) {
10992 goto exit;
10993 }
10994 if (!noptargs) {
10995 goto skip_optional_kwonly;
10996 }
10997 follow_symlinks = PyObject_IsTrue(args[2]);
10998 if (follow_symlinks < 0) {
10999 goto exit;
11000 }
11001 skip_optional_kwonly:
11002 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
11003
11004 exit:
11005 /* Cleanup for path */
11006 path_cleanup(&path);
11007 /* Cleanup for attribute */
11008 path_cleanup(&attribute);
11009
11010 return return_value;
11011 }
11012
11013 #endif /* defined(USE_XATTRS) */
11014
11015 #if defined(USE_XATTRS)
11016
11017 PyDoc_STRVAR(os_setxattr__doc__,
11018 "setxattr($module, /, path, attribute, value, flags=0, *,\n"
11019 " follow_symlinks=True)\n"
11020 "--\n"
11021 "\n"
11022 "Set extended attribute attribute on path to value.\n"
11023 "\n"
11024 "path may be either a string, a path-like object, or an open file\n"
11025 "descriptor.\n"
11026 "If follow_symlinks is False, and the last element of the path is\n"
11027 "a symbolic link, setxattr will modify the symbolic link itself instead\n"
11028 "of the file the link points to.");
11029
11030 #define OS_SETXATTR_METHODDEF \
11031 {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
11032
11033 static PyObject *
11034 os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
11035 Py_buffer *value, int flags, int follow_symlinks);
11036
11037 static PyObject *
11038 os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11039 {
11040 PyObject *return_value = NULL;
11041 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11042
11043 #define NUM_KEYWORDS 5
11044 static struct {
11045 PyGC_Head _this_is_not_used;
11046 PyObject_VAR_HEAD
11047 Py_hash_t ob_hash;
11048 PyObject *ob_item[NUM_KEYWORDS];
11049 } _kwtuple = {
11050 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11051 .ob_hash = -1,
11052 .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
11053 };
11054 #undef NUM_KEYWORDS
11055 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11056
11057 #else // !Py_BUILD_CORE
11058 # define KWTUPLE NULL
11059 #endif // !Py_BUILD_CORE
11060
11061 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
11062 static _PyArg_Parser _parser = {
11063 .keywords = _keywords,
11064 .fname = "setxattr",
11065 .kwtuple = KWTUPLE,
11066 };
11067 #undef KWTUPLE
11068 PyObject *argsbuf[5];
11069 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
11070 path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
11071 path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
11072 Py_buffer value = {NULL, NULL};
11073 int flags = 0;
11074 int follow_symlinks = 1;
11075
11076 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11077 /*minpos*/ 3, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11078 if (!args) {
11079 goto exit;
11080 }
11081 if (!path_converter(args[0], &path)) {
11082 goto exit;
11083 }
11084 if (!path_converter(args[1], &attribute)) {
11085 goto exit;
11086 }
11087 if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
11088 goto exit;
11089 }
11090 if (!noptargs) {
11091 goto skip_optional_pos;
11092 }
11093 if (args[3]) {
11094 flags = PyLong_AsInt(args[3]);
11095 if (flags == -1 && PyErr_Occurred()) {
11096 goto exit;
11097 }
11098 if (!--noptargs) {
11099 goto skip_optional_pos;
11100 }
11101 }
11102 skip_optional_pos:
11103 if (!noptargs) {
11104 goto skip_optional_kwonly;
11105 }
11106 follow_symlinks = PyObject_IsTrue(args[4]);
11107 if (follow_symlinks < 0) {
11108 goto exit;
11109 }
11110 skip_optional_kwonly:
11111 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
11112
11113 exit:
11114 /* Cleanup for path */
11115 path_cleanup(&path);
11116 /* Cleanup for attribute */
11117 path_cleanup(&attribute);
11118 /* Cleanup for value */
11119 if (value.obj) {
11120 PyBuffer_Release(&value);
11121 }
11122
11123 return return_value;
11124 }
11125
11126 #endif /* defined(USE_XATTRS) */
11127
11128 #if defined(USE_XATTRS)
11129
11130 PyDoc_STRVAR(os_removexattr__doc__,
11131 "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
11132 "--\n"
11133 "\n"
11134 "Remove extended attribute attribute on path.\n"
11135 "\n"
11136 "path may be either a string, a path-like object, or an open file\n"
11137 "descriptor.\n"
11138 "If follow_symlinks is False, and the last element of the path is\n"
11139 "a symbolic link, removexattr will modify the symbolic link itself\n"
11140 "instead of the file the link points to.");
11141
11142 #define OS_REMOVEXATTR_METHODDEF \
11143 {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
11144
11145 static PyObject *
11146 os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
11147 int follow_symlinks);
11148
11149 static PyObject *
11150 os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11151 {
11152 PyObject *return_value = NULL;
11153 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11154
11155 #define NUM_KEYWORDS 3
11156 static struct {
11157 PyGC_Head _this_is_not_used;
11158 PyObject_VAR_HEAD
11159 Py_hash_t ob_hash;
11160 PyObject *ob_item[NUM_KEYWORDS];
11161 } _kwtuple = {
11162 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11163 .ob_hash = -1,
11164 .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
11165 };
11166 #undef NUM_KEYWORDS
11167 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11168
11169 #else // !Py_BUILD_CORE
11170 # define KWTUPLE NULL
11171 #endif // !Py_BUILD_CORE
11172
11173 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
11174 static _PyArg_Parser _parser = {
11175 .keywords = _keywords,
11176 .fname = "removexattr",
11177 .kwtuple = KWTUPLE,
11178 };
11179 #undef KWTUPLE
11180 PyObject *argsbuf[3];
11181 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
11182 path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
11183 path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
11184 int follow_symlinks = 1;
11185
11186 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11187 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11188 if (!args) {
11189 goto exit;
11190 }
11191 if (!path_converter(args[0], &path)) {
11192 goto exit;
11193 }
11194 if (!path_converter(args[1], &attribute)) {
11195 goto exit;
11196 }
11197 if (!noptargs) {
11198 goto skip_optional_kwonly;
11199 }
11200 follow_symlinks = PyObject_IsTrue(args[2]);
11201 if (follow_symlinks < 0) {
11202 goto exit;
11203 }
11204 skip_optional_kwonly:
11205 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
11206
11207 exit:
11208 /* Cleanup for path */
11209 path_cleanup(&path);
11210 /* Cleanup for attribute */
11211 path_cleanup(&attribute);
11212
11213 return return_value;
11214 }
11215
11216 #endif /* defined(USE_XATTRS) */
11217
11218 #if defined(USE_XATTRS)
11219
11220 PyDoc_STRVAR(os_listxattr__doc__,
11221 "listxattr($module, /, path=None, *, follow_symlinks=True)\n"
11222 "--\n"
11223 "\n"
11224 "Return a list of extended attributes on path.\n"
11225 "\n"
11226 "path may be either None, a string, a path-like object, or an open file\n"
11227 "descriptor. If path is None, listxattr will examine the current\n"
11228 "directory.\n"
11229 "If follow_symlinks is False, and the last element of the path is\n"
11230 "a symbolic link, listxattr will examine the symbolic link itself instead\n"
11231 "of the file the link points to.");
11232
11233 #define OS_LISTXATTR_METHODDEF \
11234 {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
11235
11236 static PyObject *
11237 os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
11238
11239 static PyObject *
11240 os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11241 {
11242 PyObject *return_value = NULL;
11243 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11244
11245 #define NUM_KEYWORDS 2
11246 static struct {
11247 PyGC_Head _this_is_not_used;
11248 PyObject_VAR_HEAD
11249 Py_hash_t ob_hash;
11250 PyObject *ob_item[NUM_KEYWORDS];
11251 } _kwtuple = {
11252 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11253 .ob_hash = -1,
11254 .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
11255 };
11256 #undef NUM_KEYWORDS
11257 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11258
11259 #else // !Py_BUILD_CORE
11260 # define KWTUPLE NULL
11261 #endif // !Py_BUILD_CORE
11262
11263 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
11264 static _PyArg_Parser _parser = {
11265 .keywords = _keywords,
11266 .fname = "listxattr",
11267 .kwtuple = KWTUPLE,
11268 };
11269 #undef KWTUPLE
11270 PyObject *argsbuf[2];
11271 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11272 path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
11273 int follow_symlinks = 1;
11274
11275 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11276 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11277 if (!args) {
11278 goto exit;
11279 }
11280 if (!noptargs) {
11281 goto skip_optional_pos;
11282 }
11283 if (args[0]) {
11284 if (!path_converter(args[0], &path)) {
11285 goto exit;
11286 }
11287 if (!--noptargs) {
11288 goto skip_optional_pos;
11289 }
11290 }
11291 skip_optional_pos:
11292 if (!noptargs) {
11293 goto skip_optional_kwonly;
11294 }
11295 follow_symlinks = PyObject_IsTrue(args[1]);
11296 if (follow_symlinks < 0) {
11297 goto exit;
11298 }
11299 skip_optional_kwonly:
11300 return_value = os_listxattr_impl(module, &path, follow_symlinks);
11301
11302 exit:
11303 /* Cleanup for path */
11304 path_cleanup(&path);
11305
11306 return return_value;
11307 }
11308
11309 #endif /* defined(USE_XATTRS) */
11310
11311 PyDoc_STRVAR(os_urandom__doc__,
11312 "urandom($module, size, /)\n"
11313 "--\n"
11314 "\n"
11315 "Return a bytes object containing random bytes suitable for cryptographic use.");
11316
11317 #define OS_URANDOM_METHODDEF \
11318 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
11319
11320 static PyObject *
11321 os_urandom_impl(PyObject *module, Py_ssize_t size);
11322
11323 static PyObject *
11324 os_urandom(PyObject *module, PyObject *arg)
11325 {
11326 PyObject *return_value = NULL;
11327 Py_ssize_t size;
11328
11329 {
11330 Py_ssize_t ival = -1;
11331 PyObject *iobj = _PyNumber_Index(arg);
11332 if (iobj != NULL) {
11333 ival = PyLong_AsSsize_t(iobj);
11334 Py_DECREF(iobj);
11335 }
11336 if (ival == -1 && PyErr_Occurred()) {
11337 goto exit;
11338 }
11339 size = ival;
11340 }
11341 return_value = os_urandom_impl(module, size);
11342
11343 exit:
11344 return return_value;
11345 }
11346
11347 #if defined(HAVE_MEMFD_CREATE)
11348
11349 PyDoc_STRVAR(os_memfd_create__doc__,
11350 "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
11351 "--\n"
11352 "\n");
11353
11354 #define OS_MEMFD_CREATE_METHODDEF \
11355 {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
11356
11357 static PyObject *
11358 os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
11359
11360 static PyObject *
11361 os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11362 {
11363 PyObject *return_value = NULL;
11364 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11365
11366 #define NUM_KEYWORDS 2
11367 static struct {
11368 PyGC_Head _this_is_not_used;
11369 PyObject_VAR_HEAD
11370 Py_hash_t ob_hash;
11371 PyObject *ob_item[NUM_KEYWORDS];
11372 } _kwtuple = {
11373 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11374 .ob_hash = -1,
11375 .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
11376 };
11377 #undef NUM_KEYWORDS
11378 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11379
11380 #else // !Py_BUILD_CORE
11381 # define KWTUPLE NULL
11382 #endif // !Py_BUILD_CORE
11383
11384 static const char * const _keywords[] = {"name", "flags", NULL};
11385 static _PyArg_Parser _parser = {
11386 .keywords = _keywords,
11387 .fname = "memfd_create",
11388 .kwtuple = KWTUPLE,
11389 };
11390 #undef KWTUPLE
11391 PyObject *argsbuf[2];
11392 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11393 PyObject *name = NULL;
11394 unsigned int flags = MFD_CLOEXEC;
11395
11396 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11397 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11398 if (!args) {
11399 goto exit;
11400 }
11401 if (!PyUnicode_FSConverter(args[0], &name)) {
11402 goto exit;
11403 }
11404 if (!noptargs) {
11405 goto skip_optional_pos;
11406 }
11407 flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
11408 if (flags == (unsigned int)-1 && PyErr_Occurred()) {
11409 goto exit;
11410 }
11411 skip_optional_pos:
11412 return_value = os_memfd_create_impl(module, name, flags);
11413
11414 exit:
11415 /* Cleanup for name */
11416 Py_XDECREF(name);
11417
11418 return return_value;
11419 }
11420
11421 #endif /* defined(HAVE_MEMFD_CREATE) */
11422
11423 #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11424
11425 PyDoc_STRVAR(os_eventfd__doc__,
11426 "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
11427 "--\n"
11428 "\n"
11429 "Creates and returns an event notification file descriptor.");
11430
11431 #define OS_EVENTFD_METHODDEF \
11432 {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
11433
11434 static PyObject *
11435 os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
11436
11437 static PyObject *
11438 os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11439 {
11440 PyObject *return_value = NULL;
11441 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11442
11443 #define NUM_KEYWORDS 2
11444 static struct {
11445 PyGC_Head _this_is_not_used;
11446 PyObject_VAR_HEAD
11447 Py_hash_t ob_hash;
11448 PyObject *ob_item[NUM_KEYWORDS];
11449 } _kwtuple = {
11450 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11451 .ob_hash = -1,
11452 .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
11453 };
11454 #undef NUM_KEYWORDS
11455 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11456
11457 #else // !Py_BUILD_CORE
11458 # define KWTUPLE NULL
11459 #endif // !Py_BUILD_CORE
11460
11461 static const char * const _keywords[] = {"initval", "flags", NULL};
11462 static _PyArg_Parser _parser = {
11463 .keywords = _keywords,
11464 .fname = "eventfd",
11465 .kwtuple = KWTUPLE,
11466 };
11467 #undef KWTUPLE
11468 PyObject *argsbuf[2];
11469 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11470 unsigned int initval;
11471 int flags = EFD_CLOEXEC;
11472
11473 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11474 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11475 if (!args) {
11476 goto exit;
11477 }
11478 if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
11479 goto exit;
11480 }
11481 if (!noptargs) {
11482 goto skip_optional_pos;
11483 }
11484 flags = PyLong_AsInt(args[1]);
11485 if (flags == -1 && PyErr_Occurred()) {
11486 goto exit;
11487 }
11488 skip_optional_pos:
11489 return_value = os_eventfd_impl(module, initval, flags);
11490
11491 exit:
11492 return return_value;
11493 }
11494
11495 #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11496
11497 #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11498
11499 PyDoc_STRVAR(os_eventfd_read__doc__,
11500 "eventfd_read($module, /, fd)\n"
11501 "--\n"
11502 "\n"
11503 "Read eventfd value");
11504
11505 #define OS_EVENTFD_READ_METHODDEF \
11506 {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
11507
11508 static PyObject *
11509 os_eventfd_read_impl(PyObject *module, int fd);
11510
11511 static PyObject *
11512 os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11513 {
11514 PyObject *return_value = NULL;
11515 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11516
11517 #define NUM_KEYWORDS 1
11518 static struct {
11519 PyGC_Head _this_is_not_used;
11520 PyObject_VAR_HEAD
11521 Py_hash_t ob_hash;
11522 PyObject *ob_item[NUM_KEYWORDS];
11523 } _kwtuple = {
11524 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11525 .ob_hash = -1,
11526 .ob_item = { &_Py_ID(fd), },
11527 };
11528 #undef NUM_KEYWORDS
11529 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11530
11531 #else // !Py_BUILD_CORE
11532 # define KWTUPLE NULL
11533 #endif // !Py_BUILD_CORE
11534
11535 static const char * const _keywords[] = {"fd", NULL};
11536 static _PyArg_Parser _parser = {
11537 .keywords = _keywords,
11538 .fname = "eventfd_read",
11539 .kwtuple = KWTUPLE,
11540 };
11541 #undef KWTUPLE
11542 PyObject *argsbuf[1];
11543 int fd;
11544
11545 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11546 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11547 if (!args) {
11548 goto exit;
11549 }
11550 fd = PyObject_AsFileDescriptor(args[0]);
11551 if (fd < 0) {
11552 goto exit;
11553 }
11554 return_value = os_eventfd_read_impl(module, fd);
11555
11556 exit:
11557 return return_value;
11558 }
11559
11560 #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11561
11562 #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
11563
11564 PyDoc_STRVAR(os_eventfd_write__doc__,
11565 "eventfd_write($module, /, fd, value)\n"
11566 "--\n"
11567 "\n"
11568 "Write eventfd value.");
11569
11570 #define OS_EVENTFD_WRITE_METHODDEF \
11571 {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
11572
11573 static PyObject *
11574 os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
11575
11576 static PyObject *
11577 os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11578 {
11579 PyObject *return_value = NULL;
11580 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11581
11582 #define NUM_KEYWORDS 2
11583 static struct {
11584 PyGC_Head _this_is_not_used;
11585 PyObject_VAR_HEAD
11586 Py_hash_t ob_hash;
11587 PyObject *ob_item[NUM_KEYWORDS];
11588 } _kwtuple = {
11589 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11590 .ob_hash = -1,
11591 .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
11592 };
11593 #undef NUM_KEYWORDS
11594 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11595
11596 #else // !Py_BUILD_CORE
11597 # define KWTUPLE NULL
11598 #endif // !Py_BUILD_CORE
11599
11600 static const char * const _keywords[] = {"fd", "value", NULL};
11601 static _PyArg_Parser _parser = {
11602 .keywords = _keywords,
11603 .fname = "eventfd_write",
11604 .kwtuple = KWTUPLE,
11605 };
11606 #undef KWTUPLE
11607 PyObject *argsbuf[2];
11608 int fd;
11609 unsigned long long value;
11610
11611 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
11612 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
11613 if (!args) {
11614 goto exit;
11615 }
11616 fd = PyObject_AsFileDescriptor(args[0]);
11617 if (fd < 0) {
11618 goto exit;
11619 }
11620 if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
11621 goto exit;
11622 }
11623 return_value = os_eventfd_write_impl(module, fd, value);
11624
11625 exit:
11626 return return_value;
11627 }
11628
11629 #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
11630
11631 #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
11632
11633 PyDoc_STRVAR(os_get_terminal_size__doc__,
11634 "get_terminal_size($module, fd=<unrepresentable>, /)\n"
11635 "--\n"
11636 "\n"
11637 "Return the size of the terminal window as (columns, lines).\n"
11638 "\n"
11639 "The optional argument fd (default standard output) specifies\n"
11640 "which file descriptor should be queried.\n"
11641 "\n"
11642 "If the file descriptor is not connected to a terminal, an OSError\n"
11643 "is thrown.\n"
11644 "\n"
11645 "This function will only be defined if an implementation is\n"
11646 "available for this system.\n"
11647 "\n"
11648 "shutil.get_terminal_size is the high-level function which should\n"
11649 "normally be used, os.get_terminal_size is the low-level implementation.");
11650
11651 #define OS_GET_TERMINAL_SIZE_METHODDEF \
11652 {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
11653
11654 static PyObject *
11655 os_get_terminal_size_impl(PyObject *module, int fd);
11656
11657 static PyObject *
11658 os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11659 {
11660 PyObject *return_value = NULL;
11661 int fd = fileno(stdout);
11662
11663 if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
11664 goto exit;
11665 }
11666 if (nargs < 1) {
11667 goto skip_optional;
11668 }
11669 fd = PyLong_AsInt(args[0]);
11670 if (fd == -1 && PyErr_Occurred()) {
11671 goto exit;
11672 }
11673 skip_optional:
11674 return_value = os_get_terminal_size_impl(module, fd);
11675
11676 exit:
11677 return return_value;
11678 }
11679
11680 #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
11681
11682 PyDoc_STRVAR(os_cpu_count__doc__,
11683 "cpu_count($module, /)\n"
11684 "--\n"
11685 "\n"
11686 "Return the number of logical CPUs in the system.\n"
11687 "\n"
11688 "Return None if indeterminable.");
11689
11690 #define OS_CPU_COUNT_METHODDEF \
11691 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
11692
11693 static PyObject *
11694 os_cpu_count_impl(PyObject *module);
11695
11696 static PyObject *
11697 os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
11698 {
11699 return os_cpu_count_impl(module);
11700 }
11701
11702 PyDoc_STRVAR(os_get_inheritable__doc__,
11703 "get_inheritable($module, fd, /)\n"
11704 "--\n"
11705 "\n"
11706 "Get the close-on-exe flag of the specified file descriptor.");
11707
11708 #define OS_GET_INHERITABLE_METHODDEF \
11709 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
11710
11711 static int
11712 os_get_inheritable_impl(PyObject *module, int fd);
11713
11714 static PyObject *
11715 os_get_inheritable(PyObject *module, PyObject *arg)
11716 {
11717 PyObject *return_value = NULL;
11718 int fd;
11719 int _return_value;
11720
11721 fd = PyLong_AsInt(arg);
11722 if (fd == -1 && PyErr_Occurred()) {
11723 goto exit;
11724 }
11725 _return_value = os_get_inheritable_impl(module, fd);
11726 if ((_return_value == -1) && PyErr_Occurred()) {
11727 goto exit;
11728 }
11729 return_value = PyBool_FromLong((long)_return_value);
11730
11731 exit:
11732 return return_value;
11733 }
11734
11735 PyDoc_STRVAR(os_set_inheritable__doc__,
11736 "set_inheritable($module, fd, inheritable, /)\n"
11737 "--\n"
11738 "\n"
11739 "Set the inheritable flag of the specified file descriptor.");
11740
11741 #define OS_SET_INHERITABLE_METHODDEF \
11742 {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
11743
11744 static PyObject *
11745 os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
11746
11747 static PyObject *
11748 os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11749 {
11750 PyObject *return_value = NULL;
11751 int fd;
11752 int inheritable;
11753
11754 if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
11755 goto exit;
11756 }
11757 fd = PyLong_AsInt(args[0]);
11758 if (fd == -1 && PyErr_Occurred()) {
11759 goto exit;
11760 }
11761 inheritable = PyLong_AsInt(args[1]);
11762 if (inheritable == -1 && PyErr_Occurred()) {
11763 goto exit;
11764 }
11765 return_value = os_set_inheritable_impl(module, fd, inheritable);
11766
11767 exit:
11768 return return_value;
11769 }
11770
11771 #if defined(MS_WINDOWS)
11772
11773 PyDoc_STRVAR(os_get_handle_inheritable__doc__,
11774 "get_handle_inheritable($module, handle, /)\n"
11775 "--\n"
11776 "\n"
11777 "Get the close-on-exe flag of the specified file descriptor.");
11778
11779 #define OS_GET_HANDLE_INHERITABLE_METHODDEF \
11780 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
11781
11782 static int
11783 os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
11784
11785 static PyObject *
11786 os_get_handle_inheritable(PyObject *module, PyObject *arg)
11787 {
11788 PyObject *return_value = NULL;
11789 intptr_t handle;
11790 int _return_value;
11791
11792 handle = (intptr_t)PyLong_AsVoidPtr(arg);
11793 if (!handle && PyErr_Occurred()) {
11794 goto exit;
11795 }
11796 _return_value = os_get_handle_inheritable_impl(module, handle);
11797 if ((_return_value == -1) && PyErr_Occurred()) {
11798 goto exit;
11799 }
11800 return_value = PyBool_FromLong((long)_return_value);
11801
11802 exit:
11803 return return_value;
11804 }
11805
11806 #endif /* defined(MS_WINDOWS) */
11807
11808 #if defined(MS_WINDOWS)
11809
11810 PyDoc_STRVAR(os_set_handle_inheritable__doc__,
11811 "set_handle_inheritable($module, handle, inheritable, /)\n"
11812 "--\n"
11813 "\n"
11814 "Set the inheritable flag of the specified handle.");
11815
11816 #define OS_SET_HANDLE_INHERITABLE_METHODDEF \
11817 {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
11818
11819 static PyObject *
11820 os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
11821 int inheritable);
11822
11823 static PyObject *
11824 os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11825 {
11826 PyObject *return_value = NULL;
11827 intptr_t handle;
11828 int inheritable;
11829
11830 if (!_PyArg_CheckPositional("set_handle_inheritable", nargs, 2, 2)) {
11831 goto exit;
11832 }
11833 handle = (intptr_t)PyLong_AsVoidPtr(args[0]);
11834 if (!handle && PyErr_Occurred()) {
11835 goto exit;
11836 }
11837 inheritable = PyObject_IsTrue(args[1]);
11838 if (inheritable < 0) {
11839 goto exit;
11840 }
11841 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
11842
11843 exit:
11844 return return_value;
11845 }
11846
11847 #endif /* defined(MS_WINDOWS) */
11848
11849 PyDoc_STRVAR(os_get_blocking__doc__,
11850 "get_blocking($module, fd, /)\n"
11851 "--\n"
11852 "\n"
11853 "Get the blocking mode of the file descriptor.\n"
11854 "\n"
11855 "Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
11856
11857 #define OS_GET_BLOCKING_METHODDEF \
11858 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
11859
11860 static int
11861 os_get_blocking_impl(PyObject *module, int fd);
11862
11863 static PyObject *
11864 os_get_blocking(PyObject *module, PyObject *arg)
11865 {
11866 PyObject *return_value = NULL;
11867 int fd;
11868 int _return_value;
11869
11870 fd = PyLong_AsInt(arg);
11871 if (fd == -1 && PyErr_Occurred()) {
11872 goto exit;
11873 }
11874 _return_value = os_get_blocking_impl(module, fd);
11875 if ((_return_value == -1) && PyErr_Occurred()) {
11876 goto exit;
11877 }
11878 return_value = PyBool_FromLong((long)_return_value);
11879
11880 exit:
11881 return return_value;
11882 }
11883
11884 PyDoc_STRVAR(os_set_blocking__doc__,
11885 "set_blocking($module, fd, blocking, /)\n"
11886 "--\n"
11887 "\n"
11888 "Set the blocking mode of the specified file descriptor.\n"
11889 "\n"
11890 "Set the O_NONBLOCK flag if blocking is False,\n"
11891 "clear the O_NONBLOCK flag otherwise.");
11892
11893 #define OS_SET_BLOCKING_METHODDEF \
11894 {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
11895
11896 static PyObject *
11897 os_set_blocking_impl(PyObject *module, int fd, int blocking);
11898
11899 static PyObject *
11900 os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
11901 {
11902 PyObject *return_value = NULL;
11903 int fd;
11904 int blocking;
11905
11906 if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
11907 goto exit;
11908 }
11909 fd = PyLong_AsInt(args[0]);
11910 if (fd == -1 && PyErr_Occurred()) {
11911 goto exit;
11912 }
11913 blocking = PyObject_IsTrue(args[1]);
11914 if (blocking < 0) {
11915 goto exit;
11916 }
11917 return_value = os_set_blocking_impl(module, fd, blocking);
11918
11919 exit:
11920 return return_value;
11921 }
11922
11923 PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
11924 "is_symlink($self, /)\n"
11925 "--\n"
11926 "\n"
11927 "Return True if the entry is a symbolic link; cached per entry.");
11928
11929 #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
11930 {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
11931
11932 static int
11933 os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
11934
11935 static PyObject *
11936 os_DirEntry_is_symlink(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11937 {
11938 PyObject *return_value = NULL;
11939 int _return_value;
11940
11941 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
11942 PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
11943 goto exit;
11944 }
11945 _return_value = os_DirEntry_is_symlink_impl((DirEntry *)self, defining_class);
11946 if ((_return_value == -1) && PyErr_Occurred()) {
11947 goto exit;
11948 }
11949 return_value = PyBool_FromLong((long)_return_value);
11950
11951 exit:
11952 return return_value;
11953 }
11954
11955 PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
11956 "is_junction($self, /)\n"
11957 "--\n"
11958 "\n"
11959 "Return True if the entry is a junction; cached per entry.");
11960
11961 #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \
11962 {"is_junction", (PyCFunction)os_DirEntry_is_junction, METH_NOARGS, os_DirEntry_is_junction__doc__},
11963
11964 static int
11965 os_DirEntry_is_junction_impl(DirEntry *self);
11966
11967 static PyObject *
11968 os_DirEntry_is_junction(PyObject *self, PyObject *Py_UNUSED(ignored))
11969 {
11970 PyObject *return_value = NULL;
11971 int _return_value;
11972
11973 _return_value = os_DirEntry_is_junction_impl((DirEntry *)self);
11974 if ((_return_value == -1) && PyErr_Occurred()) {
11975 goto exit;
11976 }
11977 return_value = PyBool_FromLong((long)_return_value);
11978
11979 exit:
11980 return return_value;
11981 }
11982
11983 PyDoc_STRVAR(os_DirEntry_stat__doc__,
11984 "stat($self, /, *, follow_symlinks=True)\n"
11985 "--\n"
11986 "\n"
11987 "Return stat_result object for the entry; cached per entry.");
11988
11989 #define OS_DIRENTRY_STAT_METHODDEF \
11990 {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
11991
11992 static PyObject *
11993 os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
11994 int follow_symlinks);
11995
11996 static PyObject *
11997 os_DirEntry_stat(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11998 {
11999 PyObject *return_value = NULL;
12000 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12001
12002 #define NUM_KEYWORDS 1
12003 static struct {
12004 PyGC_Head _this_is_not_used;
12005 PyObject_VAR_HEAD
12006 Py_hash_t ob_hash;
12007 PyObject *ob_item[NUM_KEYWORDS];
12008 } _kwtuple = {
12009 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12010 .ob_hash = -1,
12011 .ob_item = { &_Py_ID(follow_symlinks), },
12012 };
12013 #undef NUM_KEYWORDS
12014 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12015
12016 #else // !Py_BUILD_CORE
12017 # define KWTUPLE NULL
12018 #endif // !Py_BUILD_CORE
12019
12020 static const char * const _keywords[] = {"follow_symlinks", NULL};
12021 static _PyArg_Parser _parser = {
12022 .keywords = _keywords,
12023 .fname = "stat",
12024 .kwtuple = KWTUPLE,
12025 };
12026 #undef KWTUPLE
12027 PyObject *argsbuf[1];
12028 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12029 int follow_symlinks = 1;
12030
12031 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12032 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12033 if (!args) {
12034 goto exit;
12035 }
12036 if (!noptargs) {
12037 goto skip_optional_kwonly;
12038 }
12039 follow_symlinks = PyObject_IsTrue(args[0]);
12040 if (follow_symlinks < 0) {
12041 goto exit;
12042 }
12043 skip_optional_kwonly:
12044 return_value = os_DirEntry_stat_impl((DirEntry *)self, defining_class, follow_symlinks);
12045
12046 exit:
12047 return return_value;
12048 }
12049
12050 PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
12051 "is_dir($self, /, *, follow_symlinks=True)\n"
12052 "--\n"
12053 "\n"
12054 "Return True if the entry is a directory; cached per entry.");
12055
12056 #define OS_DIRENTRY_IS_DIR_METHODDEF \
12057 {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
12058
12059 static int
12060 os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
12061 int follow_symlinks);
12062
12063 static PyObject *
12064 os_DirEntry_is_dir(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12065 {
12066 PyObject *return_value = NULL;
12067 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12068
12069 #define NUM_KEYWORDS 1
12070 static struct {
12071 PyGC_Head _this_is_not_used;
12072 PyObject_VAR_HEAD
12073 Py_hash_t ob_hash;
12074 PyObject *ob_item[NUM_KEYWORDS];
12075 } _kwtuple = {
12076 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12077 .ob_hash = -1,
12078 .ob_item = { &_Py_ID(follow_symlinks), },
12079 };
12080 #undef NUM_KEYWORDS
12081 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12082
12083 #else // !Py_BUILD_CORE
12084 # define KWTUPLE NULL
12085 #endif // !Py_BUILD_CORE
12086
12087 static const char * const _keywords[] = {"follow_symlinks", NULL};
12088 static _PyArg_Parser _parser = {
12089 .keywords = _keywords,
12090 .fname = "is_dir",
12091 .kwtuple = KWTUPLE,
12092 };
12093 #undef KWTUPLE
12094 PyObject *argsbuf[1];
12095 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12096 int follow_symlinks = 1;
12097 int _return_value;
12098
12099 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12100 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12101 if (!args) {
12102 goto exit;
12103 }
12104 if (!noptargs) {
12105 goto skip_optional_kwonly;
12106 }
12107 follow_symlinks = PyObject_IsTrue(args[0]);
12108 if (follow_symlinks < 0) {
12109 goto exit;
12110 }
12111 skip_optional_kwonly:
12112 _return_value = os_DirEntry_is_dir_impl((DirEntry *)self, defining_class, follow_symlinks);
12113 if ((_return_value == -1) && PyErr_Occurred()) {
12114 goto exit;
12115 }
12116 return_value = PyBool_FromLong((long)_return_value);
12117
12118 exit:
12119 return return_value;
12120 }
12121
12122 PyDoc_STRVAR(os_DirEntry_is_file__doc__,
12123 "is_file($self, /, *, follow_symlinks=True)\n"
12124 "--\n"
12125 "\n"
12126 "Return True if the entry is a file; cached per entry.");
12127
12128 #define OS_DIRENTRY_IS_FILE_METHODDEF \
12129 {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
12130
12131 static int
12132 os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
12133 int follow_symlinks);
12134
12135 static PyObject *
12136 os_DirEntry_is_file(PyObject *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12137 {
12138 PyObject *return_value = NULL;
12139 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12140
12141 #define NUM_KEYWORDS 1
12142 static struct {
12143 PyGC_Head _this_is_not_used;
12144 PyObject_VAR_HEAD
12145 Py_hash_t ob_hash;
12146 PyObject *ob_item[NUM_KEYWORDS];
12147 } _kwtuple = {
12148 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12149 .ob_hash = -1,
12150 .ob_item = { &_Py_ID(follow_symlinks), },
12151 };
12152 #undef NUM_KEYWORDS
12153 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12154
12155 #else // !Py_BUILD_CORE
12156 # define KWTUPLE NULL
12157 #endif // !Py_BUILD_CORE
12158
12159 static const char * const _keywords[] = {"follow_symlinks", NULL};
12160 static _PyArg_Parser _parser = {
12161 .keywords = _keywords,
12162 .fname = "is_file",
12163 .kwtuple = KWTUPLE,
12164 };
12165 #undef KWTUPLE
12166 PyObject *argsbuf[1];
12167 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12168 int follow_symlinks = 1;
12169 int _return_value;
12170
12171 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12172 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12173 if (!args) {
12174 goto exit;
12175 }
12176 if (!noptargs) {
12177 goto skip_optional_kwonly;
12178 }
12179 follow_symlinks = PyObject_IsTrue(args[0]);
12180 if (follow_symlinks < 0) {
12181 goto exit;
12182 }
12183 skip_optional_kwonly:
12184 _return_value = os_DirEntry_is_file_impl((DirEntry *)self, defining_class, follow_symlinks);
12185 if ((_return_value == -1) && PyErr_Occurred()) {
12186 goto exit;
12187 }
12188 return_value = PyBool_FromLong((long)_return_value);
12189
12190 exit:
12191 return return_value;
12192 }
12193
12194 PyDoc_STRVAR(os_DirEntry_inode__doc__,
12195 "inode($self, /)\n"
12196 "--\n"
12197 "\n"
12198 "Return inode of the entry; cached per entry.");
12199
12200 #define OS_DIRENTRY_INODE_METHODDEF \
12201 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
12202
12203 static PyObject *
12204 os_DirEntry_inode_impl(DirEntry *self);
12205
12206 static PyObject *
12207 os_DirEntry_inode(PyObject *self, PyObject *Py_UNUSED(ignored))
12208 {
12209 return os_DirEntry_inode_impl((DirEntry *)self);
12210 }
12211
12212 PyDoc_STRVAR(os_DirEntry___fspath____doc__,
12213 "__fspath__($self, /)\n"
12214 "--\n"
12215 "\n"
12216 "Returns the path for the entry.");
12217
12218 #define OS_DIRENTRY___FSPATH___METHODDEF \
12219 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
12220
12221 static PyObject *
12222 os_DirEntry___fspath___impl(DirEntry *self);
12223
12224 static PyObject *
12225 os_DirEntry___fspath__(PyObject *self, PyObject *Py_UNUSED(ignored))
12226 {
12227 return os_DirEntry___fspath___impl((DirEntry *)self);
12228 }
12229
12230 PyDoc_STRVAR(os_scandir__doc__,
12231 "scandir($module, /, path=None)\n"
12232 "--\n"
12233 "\n"
12234 "Return an iterator of DirEntry objects for given path.\n"
12235 "\n"
12236 "path can be specified as either str, bytes, or a path-like object. If\n"
12237 "path is bytes, the names of yielded DirEntry objects will also be bytes;\n"
12238 "in all other circumstances they will be str.\n"
12239 "\n"
12240 "If path is None, uses the path=\'.\'.");
12241
12242 #define OS_SCANDIR_METHODDEF \
12243 {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
12244
12245 static PyObject *
12246 os_scandir_impl(PyObject *module, path_t *path);
12247
12248 static PyObject *
12249 os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12250 {
12251 PyObject *return_value = NULL;
12252 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12253
12254 #define NUM_KEYWORDS 1
12255 static struct {
12256 PyGC_Head _this_is_not_used;
12257 PyObject_VAR_HEAD
12258 Py_hash_t ob_hash;
12259 PyObject *ob_item[NUM_KEYWORDS];
12260 } _kwtuple = {
12261 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12262 .ob_hash = -1,
12263 .ob_item = { &_Py_ID(path), },
12264 };
12265 #undef NUM_KEYWORDS
12266 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12267
12268 #else // !Py_BUILD_CORE
12269 # define KWTUPLE NULL
12270 #endif // !Py_BUILD_CORE
12271
12272 static const char * const _keywords[] = {"path", NULL};
12273 static _PyArg_Parser _parser = {
12274 .keywords = _keywords,
12275 .fname = "scandir",
12276 .kwtuple = KWTUPLE,
12277 };
12278 #undef KWTUPLE
12279 PyObject *argsbuf[1];
12280 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
12281 path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
12282
12283 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12284 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12285 if (!args) {
12286 goto exit;
12287 }
12288 if (!noptargs) {
12289 goto skip_optional_pos;
12290 }
12291 if (!path_converter(args[0], &path)) {
12292 goto exit;
12293 }
12294 skip_optional_pos:
12295 return_value = os_scandir_impl(module, &path);
12296
12297 exit:
12298 /* Cleanup for path */
12299 path_cleanup(&path);
12300
12301 return return_value;
12302 }
12303
12304 PyDoc_STRVAR(os_fspath__doc__,
12305 "fspath($module, /, path)\n"
12306 "--\n"
12307 "\n"
12308 "Return the file system path representation of the object.\n"
12309 "\n"
12310 "If the object is str or bytes, then allow it to pass through as-is. If\n"
12311 "the object defines __fspath__(), then return the result of that method.\n"
12312 "All other types raise a TypeError.");
12313
12314 #define OS_FSPATH_METHODDEF \
12315 {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
12316
12317 static PyObject *
12318 os_fspath_impl(PyObject *module, PyObject *path);
12319
12320 static PyObject *
12321 os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12322 {
12323 PyObject *return_value = NULL;
12324 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12325
12326 #define NUM_KEYWORDS 1
12327 static struct {
12328 PyGC_Head _this_is_not_used;
12329 PyObject_VAR_HEAD
12330 Py_hash_t ob_hash;
12331 PyObject *ob_item[NUM_KEYWORDS];
12332 } _kwtuple = {
12333 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12334 .ob_hash = -1,
12335 .ob_item = { &_Py_ID(path), },
12336 };
12337 #undef NUM_KEYWORDS
12338 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12339
12340 #else // !Py_BUILD_CORE
12341 # define KWTUPLE NULL
12342 #endif // !Py_BUILD_CORE
12343
12344 static const char * const _keywords[] = {"path", NULL};
12345 static _PyArg_Parser _parser = {
12346 .keywords = _keywords,
12347 .fname = "fspath",
12348 .kwtuple = KWTUPLE,
12349 };
12350 #undef KWTUPLE
12351 PyObject *argsbuf[1];
12352 PyObject *path;
12353
12354 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12355 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12356 if (!args) {
12357 goto exit;
12358 }
12359 path = args[0];
12360 return_value = os_fspath_impl(module, path);
12361
12362 exit:
12363 return return_value;
12364 }
12365
12366 #if defined(HAVE_GETRANDOM_SYSCALL)
12367
12368 PyDoc_STRVAR(os_getrandom__doc__,
12369 "getrandom($module, /, size, flags=0)\n"
12370 "--\n"
12371 "\n"
12372 "Obtain a series of random bytes.");
12373
12374 #define OS_GETRANDOM_METHODDEF \
12375 {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
12376
12377 static PyObject *
12378 os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
12379
12380 static PyObject *
12381 os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12382 {
12383 PyObject *return_value = NULL;
12384 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12385
12386 #define NUM_KEYWORDS 2
12387 static struct {
12388 PyGC_Head _this_is_not_used;
12389 PyObject_VAR_HEAD
12390 Py_hash_t ob_hash;
12391 PyObject *ob_item[NUM_KEYWORDS];
12392 } _kwtuple = {
12393 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12394 .ob_hash = -1,
12395 .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
12396 };
12397 #undef NUM_KEYWORDS
12398 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12399
12400 #else // !Py_BUILD_CORE
12401 # define KWTUPLE NULL
12402 #endif // !Py_BUILD_CORE
12403
12404 static const char * const _keywords[] = {"size", "flags", NULL};
12405 static _PyArg_Parser _parser = {
12406 .keywords = _keywords,
12407 .fname = "getrandom",
12408 .kwtuple = KWTUPLE,
12409 };
12410 #undef KWTUPLE
12411 PyObject *argsbuf[2];
12412 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
12413 Py_ssize_t size;
12414 int flags = 0;
12415
12416 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12417 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12418 if (!args) {
12419 goto exit;
12420 }
12421 {
12422 Py_ssize_t ival = -1;
12423 PyObject *iobj = _PyNumber_Index(args[0]);
12424 if (iobj != NULL) {
12425 ival = PyLong_AsSsize_t(iobj);
12426 Py_DECREF(iobj);
12427 }
12428 if (ival == -1 && PyErr_Occurred()) {
12429 goto exit;
12430 }
12431 size = ival;
12432 }
12433 if (!noptargs) {
12434 goto skip_optional_pos;
12435 }
12436 flags = PyLong_AsInt(args[1]);
12437 if (flags == -1 && PyErr_Occurred()) {
12438 goto exit;
12439 }
12440 skip_optional_pos:
12441 return_value = os_getrandom_impl(module, size, flags);
12442
12443 exit:
12444 return return_value;
12445 }
12446
12447 #endif /* defined(HAVE_GETRANDOM_SYSCALL) */
12448
12449 #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12450
12451 PyDoc_STRVAR(os__add_dll_directory__doc__,
12452 "_add_dll_directory($module, /, path)\n"
12453 "--\n"
12454 "\n"
12455 "Add a path to the DLL search path.\n"
12456 "\n"
12457 "This search path is used when resolving dependencies for imported\n"
12458 "extension modules (the module itself is resolved through sys.path),\n"
12459 "and also by ctypes.\n"
12460 "\n"
12461 "Returns an opaque value that may be passed to os.remove_dll_directory\n"
12462 "to remove this directory from the search path.");
12463
12464 #define OS__ADD_DLL_DIRECTORY_METHODDEF \
12465 {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
12466
12467 static PyObject *
12468 os__add_dll_directory_impl(PyObject *module, path_t *path);
12469
12470 static PyObject *
12471 os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12472 {
12473 PyObject *return_value = NULL;
12474 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12475
12476 #define NUM_KEYWORDS 1
12477 static struct {
12478 PyGC_Head _this_is_not_used;
12479 PyObject_VAR_HEAD
12480 Py_hash_t ob_hash;
12481 PyObject *ob_item[NUM_KEYWORDS];
12482 } _kwtuple = {
12483 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12484 .ob_hash = -1,
12485 .ob_item = { &_Py_ID(path), },
12486 };
12487 #undef NUM_KEYWORDS
12488 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12489
12490 #else // !Py_BUILD_CORE
12491 # define KWTUPLE NULL
12492 #endif // !Py_BUILD_CORE
12493
12494 static const char * const _keywords[] = {"path", NULL};
12495 static _PyArg_Parser _parser = {
12496 .keywords = _keywords,
12497 .fname = "_add_dll_directory",
12498 .kwtuple = KWTUPLE,
12499 };
12500 #undef KWTUPLE
12501 PyObject *argsbuf[1];
12502 path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
12503
12504 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12505 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12506 if (!args) {
12507 goto exit;
12508 }
12509 if (!path_converter(args[0], &path)) {
12510 goto exit;
12511 }
12512 return_value = os__add_dll_directory_impl(module, &path);
12513
12514 exit:
12515 /* Cleanup for path */
12516 path_cleanup(&path);
12517
12518 return return_value;
12519 }
12520
12521 #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12522
12523 #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
12524
12525 PyDoc_STRVAR(os__remove_dll_directory__doc__,
12526 "_remove_dll_directory($module, /, cookie)\n"
12527 "--\n"
12528 "\n"
12529 "Removes a path from the DLL search path.\n"
12530 "\n"
12531 "The parameter is an opaque value that was returned from\n"
12532 "os.add_dll_directory. You can only remove directories that you added\n"
12533 "yourself.");
12534
12535 #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \
12536 {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
12537
12538 static PyObject *
12539 os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
12540
12541 static PyObject *
12542 os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12543 {
12544 PyObject *return_value = NULL;
12545 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12546
12547 #define NUM_KEYWORDS 1
12548 static struct {
12549 PyGC_Head _this_is_not_used;
12550 PyObject_VAR_HEAD
12551 Py_hash_t ob_hash;
12552 PyObject *ob_item[NUM_KEYWORDS];
12553 } _kwtuple = {
12554 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12555 .ob_hash = -1,
12556 .ob_item = { &_Py_ID(cookie), },
12557 };
12558 #undef NUM_KEYWORDS
12559 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12560
12561 #else // !Py_BUILD_CORE
12562 # define KWTUPLE NULL
12563 #endif // !Py_BUILD_CORE
12564
12565 static const char * const _keywords[] = {"cookie", NULL};
12566 static _PyArg_Parser _parser = {
12567 .keywords = _keywords,
12568 .fname = "_remove_dll_directory",
12569 .kwtuple = KWTUPLE,
12570 };
12571 #undef KWTUPLE
12572 PyObject *argsbuf[1];
12573 PyObject *cookie;
12574
12575 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12576 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12577 if (!args) {
12578 goto exit;
12579 }
12580 cookie = args[0];
12581 return_value = os__remove_dll_directory_impl(module, cookie);
12582
12583 exit:
12584 return return_value;
12585 }
12586
12587 #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
12588
12589 #if (defined(WIFEXITED) || defined(MS_WINDOWS))
12590
12591 PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
12592 "waitstatus_to_exitcode($module, /, status)\n"
12593 "--\n"
12594 "\n"
12595 "Convert a wait status to an exit code.\n"
12596 "\n"
12597 "On Unix:\n"
12598 "\n"
12599 "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
12600 "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
12601 "* Otherwise, raise a ValueError.\n"
12602 "\n"
12603 "On Windows, return status shifted right by 8 bits.\n"
12604 "\n"
12605 "On Unix, if the process is being traced or if waitpid() was called with\n"
12606 "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is\n"
12607 "true. This function must not be called if WIFSTOPPED(status) is true.");
12608
12609 #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \
12610 {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
12611
12612 static PyObject *
12613 os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
12614
12615 static PyObject *
12616 os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12617 {
12618 PyObject *return_value = NULL;
12619 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12620
12621 #define NUM_KEYWORDS 1
12622 static struct {
12623 PyGC_Head _this_is_not_used;
12624 PyObject_VAR_HEAD
12625 Py_hash_t ob_hash;
12626 PyObject *ob_item[NUM_KEYWORDS];
12627 } _kwtuple = {
12628 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12629 .ob_hash = -1,
12630 .ob_item = { &_Py_ID(status), },
12631 };
12632 #undef NUM_KEYWORDS
12633 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12634
12635 #else // !Py_BUILD_CORE
12636 # define KWTUPLE NULL
12637 #endif // !Py_BUILD_CORE
12638
12639 static const char * const _keywords[] = {"status", NULL};
12640 static _PyArg_Parser _parser = {
12641 .keywords = _keywords,
12642 .fname = "waitstatus_to_exitcode",
12643 .kwtuple = KWTUPLE,
12644 };
12645 #undef KWTUPLE
12646 PyObject *argsbuf[1];
12647 PyObject *status_obj;
12648
12649 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12650 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12651 if (!args) {
12652 goto exit;
12653 }
12654 status_obj = args[0];
12655 return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
12656
12657 exit:
12658 return return_value;
12659 }
12660
12661 #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
12662
12663 #if defined(MS_WINDOWS)
12664
12665 PyDoc_STRVAR(os__supports_virtual_terminal__doc__,
12666 "_supports_virtual_terminal($module, /)\n"
12667 "--\n"
12668 "\n"
12669 "Checks if virtual terminal is supported in windows");
12670
12671 #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF \
12672 {"_supports_virtual_terminal", (PyCFunction)os__supports_virtual_terminal, METH_NOARGS, os__supports_virtual_terminal__doc__},
12673
12674 static PyObject *
12675 os__supports_virtual_terminal_impl(PyObject *module);
12676
12677 static PyObject *
12678 os__supports_virtual_terminal(PyObject *module, PyObject *Py_UNUSED(ignored))
12679 {
12680 return os__supports_virtual_terminal_impl(module);
12681 }
12682
12683 #endif /* defined(MS_WINDOWS) */
12684
12685 PyDoc_STRVAR(os__inputhook__doc__,
12686 "_inputhook($module, /)\n"
12687 "--\n"
12688 "\n"
12689 "Calls PyOS_CallInputHook droppong the GIL first");
12690
12691 #define OS__INPUTHOOK_METHODDEF \
12692 {"_inputhook", (PyCFunction)os__inputhook, METH_NOARGS, os__inputhook__doc__},
12693
12694 static PyObject *
12695 os__inputhook_impl(PyObject *module);
12696
12697 static PyObject *
12698 os__inputhook(PyObject *module, PyObject *Py_UNUSED(ignored))
12699 {
12700 return os__inputhook_impl(module);
12701 }
12702
12703 PyDoc_STRVAR(os__is_inputhook_installed__doc__,
12704 "_is_inputhook_installed($module, /)\n"
12705 "--\n"
12706 "\n"
12707 "Checks if PyOS_CallInputHook is set");
12708
12709 #define OS__IS_INPUTHOOK_INSTALLED_METHODDEF \
12710 {"_is_inputhook_installed", (PyCFunction)os__is_inputhook_installed, METH_NOARGS, os__is_inputhook_installed__doc__},
12711
12712 static PyObject *
12713 os__is_inputhook_installed_impl(PyObject *module);
12714
12715 static PyObject *
12716 os__is_inputhook_installed(PyObject *module, PyObject *Py_UNUSED(ignored))
12717 {
12718 return os__is_inputhook_installed_impl(module);
12719 }
12720
12721 PyDoc_STRVAR(os__create_environ__doc__,
12722 "_create_environ($module, /)\n"
12723 "--\n"
12724 "\n"
12725 "Create the environment dictionary.");
12726
12727 #define OS__CREATE_ENVIRON_METHODDEF \
12728 {"_create_environ", (PyCFunction)os__create_environ, METH_NOARGS, os__create_environ__doc__},
12729
12730 static PyObject *
12731 os__create_environ_impl(PyObject *module);
12732
12733 static PyObject *
12734 os__create_environ(PyObject *module, PyObject *Py_UNUSED(ignored))
12735 {
12736 return os__create_environ_impl(module);
12737 }
12738
12739 #if defined(__EMSCRIPTEN__)
12740
12741 PyDoc_STRVAR(os__emscripten_debugger__doc__,
12742 "_emscripten_debugger($module, /)\n"
12743 "--\n"
12744 "\n"
12745 "Create a breakpoint for the JavaScript debugger. Emscripten only.");
12746
12747 #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF \
12748 {"_emscripten_debugger", (PyCFunction)os__emscripten_debugger, METH_NOARGS, os__emscripten_debugger__doc__},
12749
12750 static PyObject *
12751 os__emscripten_debugger_impl(PyObject *module);
12752
12753 static PyObject *
12754 os__emscripten_debugger(PyObject *module, PyObject *Py_UNUSED(ignored))
12755 {
12756 return os__emscripten_debugger_impl(module);
12757 }
12758
12759 #endif /* defined(__EMSCRIPTEN__) */
12760
12761 #if defined(__EMSCRIPTEN__)
12762
12763 PyDoc_STRVAR(os__emscripten_log__doc__,
12764 "_emscripten_log($module, /, arg)\n"
12765 "--\n"
12766 "\n"
12767 "Log something to the JS console. Emscripten only.");
12768
12769 #define OS__EMSCRIPTEN_LOG_METHODDEF \
12770 {"_emscripten_log", _PyCFunction_CAST(os__emscripten_log), METH_FASTCALL|METH_KEYWORDS, os__emscripten_log__doc__},
12771
12772 static PyObject *
12773 os__emscripten_log_impl(PyObject *module, const char *arg);
12774
12775 static PyObject *
12776 os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
12777 {
12778 PyObject *return_value = NULL;
12779 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
12780
12781 #define NUM_KEYWORDS 1
12782 static struct {
12783 PyGC_Head _this_is_not_used;
12784 PyObject_VAR_HEAD
12785 Py_hash_t ob_hash;
12786 PyObject *ob_item[NUM_KEYWORDS];
12787 } _kwtuple = {
12788 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
12789 .ob_hash = -1,
12790 .ob_item = { &_Py_ID(arg), },
12791 };
12792 #undef NUM_KEYWORDS
12793 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
12794
12795 #else // !Py_BUILD_CORE
12796 # define KWTUPLE NULL
12797 #endif // !Py_BUILD_CORE
12798
12799 static const char * const _keywords[] = {"arg", NULL};
12800 static _PyArg_Parser _parser = {
12801 .keywords = _keywords,
12802 .fname = "_emscripten_log",
12803 .kwtuple = KWTUPLE,
12804 };
12805 #undef KWTUPLE
12806 PyObject *argsbuf[1];
12807 const char *arg;
12808
12809 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
12810 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
12811 if (!args) {
12812 goto exit;
12813 }
12814 if (!PyUnicode_Check(args[0])) {
12815 _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]);
12816 goto exit;
12817 }
12818 Py_ssize_t arg_length;
12819 arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length);
12820 if (arg == NULL) {
12821 goto exit;
12822 }
12823 if (strlen(arg) != (size_t)arg_length) {
12824 PyErr_SetString(PyExc_ValueError, "embedded null character");
12825 goto exit;
12826 }
12827 return_value = os__emscripten_log_impl(module, arg);
12828
12829 exit:
12830 return return_value;
12831 }
12832
12833 #endif /* defined(__EMSCRIPTEN__) */
12834
12835 #ifndef OS_TTYNAME_METHODDEF
12836 #define OS_TTYNAME_METHODDEF
12837 #endif /* !defined(OS_TTYNAME_METHODDEF) */
12838
12839 #ifndef OS_CTERMID_METHODDEF
12840 #define OS_CTERMID_METHODDEF
12841 #endif /* !defined(OS_CTERMID_METHODDEF) */
12842
12843 #ifndef OS_FCHDIR_METHODDEF
12844 #define OS_FCHDIR_METHODDEF
12845 #endif /* !defined(OS_FCHDIR_METHODDEF) */
12846
12847 #ifndef OS_FCHMOD_METHODDEF
12848 #define OS_FCHMOD_METHODDEF
12849 #endif /* !defined(OS_FCHMOD_METHODDEF) */
12850
12851 #ifndef OS_LCHMOD_METHODDEF
12852 #define OS_LCHMOD_METHODDEF
12853 #endif /* !defined(OS_LCHMOD_METHODDEF) */
12854
12855 #ifndef OS_CHFLAGS_METHODDEF
12856 #define OS_CHFLAGS_METHODDEF
12857 #endif /* !defined(OS_CHFLAGS_METHODDEF) */
12858
12859 #ifndef OS_LCHFLAGS_METHODDEF
12860 #define OS_LCHFLAGS_METHODDEF
12861 #endif /* !defined(OS_LCHFLAGS_METHODDEF) */
12862
12863 #ifndef OS_CHROOT_METHODDEF
12864 #define OS_CHROOT_METHODDEF
12865 #endif /* !defined(OS_CHROOT_METHODDEF) */
12866
12867 #ifndef OS_FSYNC_METHODDEF
12868 #define OS_FSYNC_METHODDEF
12869 #endif /* !defined(OS_FSYNC_METHODDEF) */
12870
12871 #ifndef OS_SYNC_METHODDEF
12872 #define OS_SYNC_METHODDEF
12873 #endif /* !defined(OS_SYNC_METHODDEF) */
12874
12875 #ifndef OS_FDATASYNC_METHODDEF
12876 #define OS_FDATASYNC_METHODDEF
12877 #endif /* !defined(OS_FDATASYNC_METHODDEF) */
12878
12879 #ifndef OS_CHOWN_METHODDEF
12880 #define OS_CHOWN_METHODDEF
12881 #endif /* !defined(OS_CHOWN_METHODDEF) */
12882
12883 #ifndef OS_FCHOWN_METHODDEF
12884 #define OS_FCHOWN_METHODDEF
12885 #endif /* !defined(OS_FCHOWN_METHODDEF) */
12886
12887 #ifndef OS_LCHOWN_METHODDEF
12888 #define OS_LCHOWN_METHODDEF
12889 #endif /* !defined(OS_LCHOWN_METHODDEF) */
12890
12891 #ifndef OS_LINK_METHODDEF
12892 #define OS_LINK_METHODDEF
12893 #endif /* !defined(OS_LINK_METHODDEF) */
12894
12895 #ifndef OS_LISTDRIVES_METHODDEF
12896 #define OS_LISTDRIVES_METHODDEF
12897 #endif /* !defined(OS_LISTDRIVES_METHODDEF) */
12898
12899 #ifndef OS_LISTVOLUMES_METHODDEF
12900 #define OS_LISTVOLUMES_METHODDEF
12901 #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
12902
12903 #ifndef OS_LISTMOUNTS_METHODDEF
12904 #define OS_LISTMOUNTS_METHODDEF
12905 #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
12906
12907 #ifndef OS__PATH_ISDEVDRIVE_METHODDEF
12908 #define OS__PATH_ISDEVDRIVE_METHODDEF
12909 #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */
12910
12911 #ifndef OS__GETFULLPATHNAME_METHODDEF
12912 #define OS__GETFULLPATHNAME_METHODDEF
12913 #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
12914
12915 #ifndef OS__GETFINALPATHNAME_METHODDEF
12916 #define OS__GETFINALPATHNAME_METHODDEF
12917 #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
12918
12919 #ifndef OS__FINDFIRSTFILE_METHODDEF
12920 #define OS__FINDFIRSTFILE_METHODDEF
12921 #endif /* !defined(OS__FINDFIRSTFILE_METHODDEF) */
12922
12923 #ifndef OS__GETVOLUMEPATHNAME_METHODDEF
12924 #define OS__GETVOLUMEPATHNAME_METHODDEF
12925 #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
12926
12927 #ifndef OS__PATH_SPLITROOT_METHODDEF
12928 #define OS__PATH_SPLITROOT_METHODDEF
12929 #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
12930
12931 #ifndef OS__PATH_EXISTS_METHODDEF
12932 #define OS__PATH_EXISTS_METHODDEF
12933 #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
12934
12935 #ifndef OS__PATH_LEXISTS_METHODDEF
12936 #define OS__PATH_LEXISTS_METHODDEF
12937 #endif /* !defined(OS__PATH_LEXISTS_METHODDEF) */
12938
12939 #ifndef OS__PATH_ISDIR_METHODDEF
12940 #define OS__PATH_ISDIR_METHODDEF
12941 #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
12942
12943 #ifndef OS__PATH_ISFILE_METHODDEF
12944 #define OS__PATH_ISFILE_METHODDEF
12945 #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
12946
12947 #ifndef OS__PATH_ISLINK_METHODDEF
12948 #define OS__PATH_ISLINK_METHODDEF
12949 #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
12950
12951 #ifndef OS__PATH_ISJUNCTION_METHODDEF
12952 #define OS__PATH_ISJUNCTION_METHODDEF
12953 #endif /* !defined(OS__PATH_ISJUNCTION_METHODDEF) */
12954
12955 #ifndef OS_NICE_METHODDEF
12956 #define OS_NICE_METHODDEF
12957 #endif /* !defined(OS_NICE_METHODDEF) */
12958
12959 #ifndef OS_GETPRIORITY_METHODDEF
12960 #define OS_GETPRIORITY_METHODDEF
12961 #endif /* !defined(OS_GETPRIORITY_METHODDEF) */
12962
12963 #ifndef OS_SETPRIORITY_METHODDEF
12964 #define OS_SETPRIORITY_METHODDEF
12965 #endif /* !defined(OS_SETPRIORITY_METHODDEF) */
12966
12967 #ifndef OS_SYSTEM_METHODDEF
12968 #define OS_SYSTEM_METHODDEF
12969 #endif /* !defined(OS_SYSTEM_METHODDEF) */
12970
12971 #ifndef OS_UMASK_METHODDEF
12972 #define OS_UMASK_METHODDEF
12973 #endif /* !defined(OS_UMASK_METHODDEF) */
12974
12975 #ifndef OS_UNAME_METHODDEF
12976 #define OS_UNAME_METHODDEF
12977 #endif /* !defined(OS_UNAME_METHODDEF) */
12978
12979 #ifndef OS_EXECV_METHODDEF
12980 #define OS_EXECV_METHODDEF
12981 #endif /* !defined(OS_EXECV_METHODDEF) */
12982
12983 #ifndef OS_EXECVE_METHODDEF
12984 #define OS_EXECVE_METHODDEF
12985 #endif /* !defined(OS_EXECVE_METHODDEF) */
12986
12987 #ifndef OS_POSIX_SPAWN_METHODDEF
12988 #define OS_POSIX_SPAWN_METHODDEF
12989 #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
12990
12991 #ifndef OS_POSIX_SPAWNP_METHODDEF
12992 #define OS_POSIX_SPAWNP_METHODDEF
12993 #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
12994
12995 #ifndef OS_SPAWNV_METHODDEF
12996 #define OS_SPAWNV_METHODDEF
12997 #endif /* !defined(OS_SPAWNV_METHODDEF) */
12998
12999 #ifndef OS_SPAWNVE_METHODDEF
13000 #define OS_SPAWNVE_METHODDEF
13001 #endif /* !defined(OS_SPAWNVE_METHODDEF) */
13002
13003 #ifndef OS_REGISTER_AT_FORK_METHODDEF
13004 #define OS_REGISTER_AT_FORK_METHODDEF
13005 #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
13006
13007 #ifndef OS_FORK1_METHODDEF
13008 #define OS_FORK1_METHODDEF
13009 #endif /* !defined(OS_FORK1_METHODDEF) */
13010
13011 #ifndef OS_FORK_METHODDEF
13012 #define OS_FORK_METHODDEF
13013 #endif /* !defined(OS_FORK_METHODDEF) */
13014
13015 #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
13016 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
13017 #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
13018
13019 #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
13020 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
13021 #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
13022
13023 #ifndef OS_SCHED_GETSCHEDULER_METHODDEF
13024 #define OS_SCHED_GETSCHEDULER_METHODDEF
13025 #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
13026
13027 #ifndef OS_SCHED_SETSCHEDULER_METHODDEF
13028 #define OS_SCHED_SETSCHEDULER_METHODDEF
13029 #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
13030
13031 #ifndef OS_SCHED_GETPARAM_METHODDEF
13032 #define OS_SCHED_GETPARAM_METHODDEF
13033 #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
13034
13035 #ifndef OS_SCHED_SETPARAM_METHODDEF
13036 #define OS_SCHED_SETPARAM_METHODDEF
13037 #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
13038
13039 #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
13040 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
13041 #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
13042
13043 #ifndef OS_SCHED_YIELD_METHODDEF
13044 #define OS_SCHED_YIELD_METHODDEF
13045 #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
13046
13047 #ifndef OS_SCHED_SETAFFINITY_METHODDEF
13048 #define OS_SCHED_SETAFFINITY_METHODDEF
13049 #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
13050
13051 #ifndef OS_SCHED_GETAFFINITY_METHODDEF
13052 #define OS_SCHED_GETAFFINITY_METHODDEF
13053 #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
13054
13055 #ifndef OS_POSIX_OPENPT_METHODDEF
13056 #define OS_POSIX_OPENPT_METHODDEF
13057 #endif /* !defined(OS_POSIX_OPENPT_METHODDEF) */
13058
13059 #ifndef OS_GRANTPT_METHODDEF
13060 #define OS_GRANTPT_METHODDEF
13061 #endif /* !defined(OS_GRANTPT_METHODDEF) */
13062
13063 #ifndef OS_UNLOCKPT_METHODDEF
13064 #define OS_UNLOCKPT_METHODDEF
13065 #endif /* !defined(OS_UNLOCKPT_METHODDEF) */
13066
13067 #ifndef OS_PTSNAME_METHODDEF
13068 #define OS_PTSNAME_METHODDEF
13069 #endif /* !defined(OS_PTSNAME_METHODDEF) */
13070
13071 #ifndef OS_OPENPTY_METHODDEF
13072 #define OS_OPENPTY_METHODDEF
13073 #endif /* !defined(OS_OPENPTY_METHODDEF) */
13074
13075 #ifndef OS_LOGIN_TTY_METHODDEF
13076 #define OS_LOGIN_TTY_METHODDEF
13077 #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
13078
13079 #ifndef OS_FORKPTY_METHODDEF
13080 #define OS_FORKPTY_METHODDEF
13081 #endif /* !defined(OS_FORKPTY_METHODDEF) */
13082
13083 #ifndef OS_GETEGID_METHODDEF
13084 #define OS_GETEGID_METHODDEF
13085 #endif /* !defined(OS_GETEGID_METHODDEF) */
13086
13087 #ifndef OS_GETEUID_METHODDEF
13088 #define OS_GETEUID_METHODDEF
13089 #endif /* !defined(OS_GETEUID_METHODDEF) */
13090
13091 #ifndef OS_GETGID_METHODDEF
13092 #define OS_GETGID_METHODDEF
13093 #endif /* !defined(OS_GETGID_METHODDEF) */
13094
13095 #ifndef OS_GETPID_METHODDEF
13096 #define OS_GETPID_METHODDEF
13097 #endif /* !defined(OS_GETPID_METHODDEF) */
13098
13099 #ifndef OS_GETGROUPLIST_METHODDEF
13100 #define OS_GETGROUPLIST_METHODDEF
13101 #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
13102
13103 #ifndef OS_GETGROUPS_METHODDEF
13104 #define OS_GETGROUPS_METHODDEF
13105 #endif /* !defined(OS_GETGROUPS_METHODDEF) */
13106
13107 #ifndef OS_INITGROUPS_METHODDEF
13108 #define OS_INITGROUPS_METHODDEF
13109 #endif /* !defined(OS_INITGROUPS_METHODDEF) */
13110
13111 #ifndef OS_GETPGID_METHODDEF
13112 #define OS_GETPGID_METHODDEF
13113 #endif /* !defined(OS_GETPGID_METHODDEF) */
13114
13115 #ifndef OS_GETPGRP_METHODDEF
13116 #define OS_GETPGRP_METHODDEF
13117 #endif /* !defined(OS_GETPGRP_METHODDEF) */
13118
13119 #ifndef OS_SETPGRP_METHODDEF
13120 #define OS_SETPGRP_METHODDEF
13121 #endif /* !defined(OS_SETPGRP_METHODDEF) */
13122
13123 #ifndef OS_GETPPID_METHODDEF
13124 #define OS_GETPPID_METHODDEF
13125 #endif /* !defined(OS_GETPPID_METHODDEF) */
13126
13127 #ifndef OS_GETLOGIN_METHODDEF
13128 #define OS_GETLOGIN_METHODDEF
13129 #endif /* !defined(OS_GETLOGIN_METHODDEF) */
13130
13131 #ifndef OS_GETUID_METHODDEF
13132 #define OS_GETUID_METHODDEF
13133 #endif /* !defined(OS_GETUID_METHODDEF) */
13134
13135 #ifndef OS_KILL_METHODDEF
13136 #define OS_KILL_METHODDEF
13137 #endif /* !defined(OS_KILL_METHODDEF) */
13138
13139 #ifndef OS_KILLPG_METHODDEF
13140 #define OS_KILLPG_METHODDEF
13141 #endif /* !defined(OS_KILLPG_METHODDEF) */
13142
13143 #ifndef OS_PLOCK_METHODDEF
13144 #define OS_PLOCK_METHODDEF
13145 #endif /* !defined(OS_PLOCK_METHODDEF) */
13146
13147 #ifndef OS_SETUID_METHODDEF
13148 #define OS_SETUID_METHODDEF
13149 #endif /* !defined(OS_SETUID_METHODDEF) */
13150
13151 #ifndef OS_SETEUID_METHODDEF
13152 #define OS_SETEUID_METHODDEF
13153 #endif /* !defined(OS_SETEUID_METHODDEF) */
13154
13155 #ifndef OS_SETEGID_METHODDEF
13156 #define OS_SETEGID_METHODDEF
13157 #endif /* !defined(OS_SETEGID_METHODDEF) */
13158
13159 #ifndef OS_SETREUID_METHODDEF
13160 #define OS_SETREUID_METHODDEF
13161 #endif /* !defined(OS_SETREUID_METHODDEF) */
13162
13163 #ifndef OS_SETREGID_METHODDEF
13164 #define OS_SETREGID_METHODDEF
13165 #endif /* !defined(OS_SETREGID_METHODDEF) */
13166
13167 #ifndef OS_SETGID_METHODDEF
13168 #define OS_SETGID_METHODDEF
13169 #endif /* !defined(OS_SETGID_METHODDEF) */
13170
13171 #ifndef OS_SETGROUPS_METHODDEF
13172 #define OS_SETGROUPS_METHODDEF
13173 #endif /* !defined(OS_SETGROUPS_METHODDEF) */
13174
13175 #ifndef OS_WAIT3_METHODDEF
13176 #define OS_WAIT3_METHODDEF
13177 #endif /* !defined(OS_WAIT3_METHODDEF) */
13178
13179 #ifndef OS_WAIT4_METHODDEF
13180 #define OS_WAIT4_METHODDEF
13181 #endif /* !defined(OS_WAIT4_METHODDEF) */
13182
13183 #ifndef OS_WAITID_METHODDEF
13184 #define OS_WAITID_METHODDEF
13185 #endif /* !defined(OS_WAITID_METHODDEF) */
13186
13187 #ifndef OS_WAITPID_METHODDEF
13188 #define OS_WAITPID_METHODDEF
13189 #endif /* !defined(OS_WAITPID_METHODDEF) */
13190
13191 #ifndef OS_WAIT_METHODDEF
13192 #define OS_WAIT_METHODDEF
13193 #endif /* !defined(OS_WAIT_METHODDEF) */
13194
13195 #ifndef OS_PIDFD_OPEN_METHODDEF
13196 #define OS_PIDFD_OPEN_METHODDEF
13197 #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
13198
13199 #ifndef OS_SETNS_METHODDEF
13200 #define OS_SETNS_METHODDEF
13201 #endif /* !defined(OS_SETNS_METHODDEF) */
13202
13203 #ifndef OS_UNSHARE_METHODDEF
13204 #define OS_UNSHARE_METHODDEF
13205 #endif /* !defined(OS_UNSHARE_METHODDEF) */
13206
13207 #ifndef OS_READLINK_METHODDEF
13208 #define OS_READLINK_METHODDEF
13209 #endif /* !defined(OS_READLINK_METHODDEF) */
13210
13211 #ifndef OS_SYMLINK_METHODDEF
13212 #define OS_SYMLINK_METHODDEF
13213 #endif /* !defined(OS_SYMLINK_METHODDEF) */
13214
13215 #ifndef OS_TIMERFD_CREATE_METHODDEF
13216 #define OS_TIMERFD_CREATE_METHODDEF
13217 #endif /* !defined(OS_TIMERFD_CREATE_METHODDEF) */
13218
13219 #ifndef OS_TIMERFD_SETTIME_METHODDEF
13220 #define OS_TIMERFD_SETTIME_METHODDEF
13221 #endif /* !defined(OS_TIMERFD_SETTIME_METHODDEF) */
13222
13223 #ifndef OS_TIMERFD_SETTIME_NS_METHODDEF
13224 #define OS_TIMERFD_SETTIME_NS_METHODDEF
13225 #endif /* !defined(OS_TIMERFD_SETTIME_NS_METHODDEF) */
13226
13227 #ifndef OS_TIMERFD_GETTIME_METHODDEF
13228 #define OS_TIMERFD_GETTIME_METHODDEF
13229 #endif /* !defined(OS_TIMERFD_GETTIME_METHODDEF) */
13230
13231 #ifndef OS_TIMERFD_GETTIME_NS_METHODDEF
13232 #define OS_TIMERFD_GETTIME_NS_METHODDEF
13233 #endif /* !defined(OS_TIMERFD_GETTIME_NS_METHODDEF) */
13234
13235 #ifndef OS_GETSID_METHODDEF
13236 #define OS_GETSID_METHODDEF
13237 #endif /* !defined(OS_GETSID_METHODDEF) */
13238
13239 #ifndef OS_SETSID_METHODDEF
13240 #define OS_SETSID_METHODDEF
13241 #endif /* !defined(OS_SETSID_METHODDEF) */
13242
13243 #ifndef OS_SETPGID_METHODDEF
13244 #define OS_SETPGID_METHODDEF
13245 #endif /* !defined(OS_SETPGID_METHODDEF) */
13246
13247 #ifndef OS_TCGETPGRP_METHODDEF
13248 #define OS_TCGETPGRP_METHODDEF
13249 #endif /* !defined(OS_TCGETPGRP_METHODDEF) */
13250
13251 #ifndef OS_TCSETPGRP_METHODDEF
13252 #define OS_TCSETPGRP_METHODDEF
13253 #endif /* !defined(OS_TCSETPGRP_METHODDEF) */
13254
13255 #ifndef OS_DUP2_METHODDEF
13256 #define OS_DUP2_METHODDEF
13257 #endif /* !defined(OS_DUP2_METHODDEF) */
13258
13259 #ifndef OS_LOCKF_METHODDEF
13260 #define OS_LOCKF_METHODDEF
13261 #endif /* !defined(OS_LOCKF_METHODDEF) */
13262
13263 #ifndef OS_READV_METHODDEF
13264 #define OS_READV_METHODDEF
13265 #endif /* !defined(OS_READV_METHODDEF) */
13266
13267 #ifndef OS_PREAD_METHODDEF
13268 #define OS_PREAD_METHODDEF
13269 #endif /* !defined(OS_PREAD_METHODDEF) */
13270
13271 #ifndef OS_PREADV_METHODDEF
13272 #define OS_PREADV_METHODDEF
13273 #endif /* !defined(OS_PREADV_METHODDEF) */
13274
13275 #ifndef OS_SENDFILE_METHODDEF
13276 #define OS_SENDFILE_METHODDEF
13277 #endif /* !defined(OS_SENDFILE_METHODDEF) */
13278
13279 #ifndef OS__FCOPYFILE_METHODDEF
13280 #define OS__FCOPYFILE_METHODDEF
13281 #endif /* !defined(OS__FCOPYFILE_METHODDEF) */
13282
13283 #ifndef OS_PIPE_METHODDEF
13284 #define OS_PIPE_METHODDEF
13285 #endif /* !defined(OS_PIPE_METHODDEF) */
13286
13287 #ifndef OS_PIPE2_METHODDEF
13288 #define OS_PIPE2_METHODDEF
13289 #endif /* !defined(OS_PIPE2_METHODDEF) */
13290
13291 #ifndef OS_WRITEV_METHODDEF
13292 #define OS_WRITEV_METHODDEF
13293 #endif /* !defined(OS_WRITEV_METHODDEF) */
13294
13295 #ifndef OS_PWRITE_METHODDEF
13296 #define OS_PWRITE_METHODDEF
13297 #endif /* !defined(OS_PWRITE_METHODDEF) */
13298
13299 #ifndef OS_PWRITEV_METHODDEF
13300 #define OS_PWRITEV_METHODDEF
13301 #endif /* !defined(OS_PWRITEV_METHODDEF) */
13302
13303 #ifndef OS_COPY_FILE_RANGE_METHODDEF
13304 #define OS_COPY_FILE_RANGE_METHODDEF
13305 #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
13306
13307 #ifndef OS_SPLICE_METHODDEF
13308 #define OS_SPLICE_METHODDEF
13309 #endif /* !defined(OS_SPLICE_METHODDEF) */
13310
13311 #ifndef OS_MKFIFO_METHODDEF
13312 #define OS_MKFIFO_METHODDEF
13313 #endif /* !defined(OS_MKFIFO_METHODDEF) */
13314
13315 #ifndef OS_MKNOD_METHODDEF
13316 #define OS_MKNOD_METHODDEF
13317 #endif /* !defined(OS_MKNOD_METHODDEF) */
13318
13319 #ifndef OS_MAJOR_METHODDEF
13320 #define OS_MAJOR_METHODDEF
13321 #endif /* !defined(OS_MAJOR_METHODDEF) */
13322
13323 #ifndef OS_MINOR_METHODDEF
13324 #define OS_MINOR_METHODDEF
13325 #endif /* !defined(OS_MINOR_METHODDEF) */
13326
13327 #ifndef OS_MAKEDEV_METHODDEF
13328 #define OS_MAKEDEV_METHODDEF
13329 #endif /* !defined(OS_MAKEDEV_METHODDEF) */
13330
13331 #ifndef OS_FTRUNCATE_METHODDEF
13332 #define OS_FTRUNCATE_METHODDEF
13333 #endif /* !defined(OS_FTRUNCATE_METHODDEF) */
13334
13335 #ifndef OS_TRUNCATE_METHODDEF
13336 #define OS_TRUNCATE_METHODDEF
13337 #endif /* !defined(OS_TRUNCATE_METHODDEF) */
13338
13339 #ifndef OS_POSIX_FALLOCATE_METHODDEF
13340 #define OS_POSIX_FALLOCATE_METHODDEF
13341 #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
13342
13343 #ifndef OS_POSIX_FADVISE_METHODDEF
13344 #define OS_POSIX_FADVISE_METHODDEF
13345 #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
13346
13347 #ifndef OS_PUTENV_METHODDEF
13348 #define OS_PUTENV_METHODDEF
13349 #endif /* !defined(OS_PUTENV_METHODDEF) */
13350
13351 #ifndef OS_UNSETENV_METHODDEF
13352 #define OS_UNSETENV_METHODDEF
13353 #endif /* !defined(OS_UNSETENV_METHODDEF) */
13354
13355 #ifndef OS_WCOREDUMP_METHODDEF
13356 #define OS_WCOREDUMP_METHODDEF
13357 #endif /* !defined(OS_WCOREDUMP_METHODDEF) */
13358
13359 #ifndef OS_WIFCONTINUED_METHODDEF
13360 #define OS_WIFCONTINUED_METHODDEF
13361 #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
13362
13363 #ifndef OS_WIFSTOPPED_METHODDEF
13364 #define OS_WIFSTOPPED_METHODDEF
13365 #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
13366
13367 #ifndef OS_WIFSIGNALED_METHODDEF
13368 #define OS_WIFSIGNALED_METHODDEF
13369 #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
13370
13371 #ifndef OS_WIFEXITED_METHODDEF
13372 #define OS_WIFEXITED_METHODDEF
13373 #endif /* !defined(OS_WIFEXITED_METHODDEF) */
13374
13375 #ifndef OS_WEXITSTATUS_METHODDEF
13376 #define OS_WEXITSTATUS_METHODDEF
13377 #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
13378
13379 #ifndef OS_WTERMSIG_METHODDEF
13380 #define OS_WTERMSIG_METHODDEF
13381 #endif /* !defined(OS_WTERMSIG_METHODDEF) */
13382
13383 #ifndef OS_WSTOPSIG_METHODDEF
13384 #define OS_WSTOPSIG_METHODDEF
13385 #endif /* !defined(OS_WSTOPSIG_METHODDEF) */
13386
13387 #ifndef OS_FSTATVFS_METHODDEF
13388 #define OS_FSTATVFS_METHODDEF
13389 #endif /* !defined(OS_FSTATVFS_METHODDEF) */
13390
13391 #ifndef OS_STATVFS_METHODDEF
13392 #define OS_STATVFS_METHODDEF
13393 #endif /* !defined(OS_STATVFS_METHODDEF) */
13394
13395 #ifndef OS__GETDISKUSAGE_METHODDEF
13396 #define OS__GETDISKUSAGE_METHODDEF
13397 #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
13398
13399 #ifndef OS_FPATHCONF_METHODDEF
13400 #define OS_FPATHCONF_METHODDEF
13401 #endif /* !defined(OS_FPATHCONF_METHODDEF) */
13402
13403 #ifndef OS_PATHCONF_METHODDEF
13404 #define OS_PATHCONF_METHODDEF
13405 #endif /* !defined(OS_PATHCONF_METHODDEF) */
13406
13407 #ifndef OS_CONFSTR_METHODDEF
13408 #define OS_CONFSTR_METHODDEF
13409 #endif /* !defined(OS_CONFSTR_METHODDEF) */
13410
13411 #ifndef OS_SYSCONF_METHODDEF
13412 #define OS_SYSCONF_METHODDEF
13413 #endif /* !defined(OS_SYSCONF_METHODDEF) */
13414
13415 #ifndef OS_STARTFILE_METHODDEF
13416 #define OS_STARTFILE_METHODDEF
13417 #endif /* !defined(OS_STARTFILE_METHODDEF) */
13418
13419 #ifndef OS_GETLOADAVG_METHODDEF
13420 #define OS_GETLOADAVG_METHODDEF
13421 #endif /* !defined(OS_GETLOADAVG_METHODDEF) */
13422
13423 #ifndef OS_SETRESUID_METHODDEF
13424 #define OS_SETRESUID_METHODDEF
13425 #endif /* !defined(OS_SETRESUID_METHODDEF) */
13426
13427 #ifndef OS_SETRESGID_METHODDEF
13428 #define OS_SETRESGID_METHODDEF
13429 #endif /* !defined(OS_SETRESGID_METHODDEF) */
13430
13431 #ifndef OS_GETRESUID_METHODDEF
13432 #define OS_GETRESUID_METHODDEF
13433 #endif /* !defined(OS_GETRESUID_METHODDEF) */
13434
13435 #ifndef OS_GETRESGID_METHODDEF
13436 #define OS_GETRESGID_METHODDEF
13437 #endif /* !defined(OS_GETRESGID_METHODDEF) */
13438
13439 #ifndef OS_GETXATTR_METHODDEF
13440 #define OS_GETXATTR_METHODDEF
13441 #endif /* !defined(OS_GETXATTR_METHODDEF) */
13442
13443 #ifndef OS_SETXATTR_METHODDEF
13444 #define OS_SETXATTR_METHODDEF
13445 #endif /* !defined(OS_SETXATTR_METHODDEF) */
13446
13447 #ifndef OS_REMOVEXATTR_METHODDEF
13448 #define OS_REMOVEXATTR_METHODDEF
13449 #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
13450
13451 #ifndef OS_LISTXATTR_METHODDEF
13452 #define OS_LISTXATTR_METHODDEF
13453 #endif /* !defined(OS_LISTXATTR_METHODDEF) */
13454
13455 #ifndef OS_MEMFD_CREATE_METHODDEF
13456 #define OS_MEMFD_CREATE_METHODDEF
13457 #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
13458
13459 #ifndef OS_EVENTFD_METHODDEF
13460 #define OS_EVENTFD_METHODDEF
13461 #endif /* !defined(OS_EVENTFD_METHODDEF) */
13462
13463 #ifndef OS_EVENTFD_READ_METHODDEF
13464 #define OS_EVENTFD_READ_METHODDEF
13465 #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
13466
13467 #ifndef OS_EVENTFD_WRITE_METHODDEF
13468 #define OS_EVENTFD_WRITE_METHODDEF
13469 #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
13470
13471 #ifndef OS_GET_TERMINAL_SIZE_METHODDEF
13472 #define OS_GET_TERMINAL_SIZE_METHODDEF
13473 #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
13474
13475 #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
13476 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
13477 #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
13478
13479 #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
13480 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
13481 #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
13482
13483 #ifndef OS_GETRANDOM_METHODDEF
13484 #define OS_GETRANDOM_METHODDEF
13485 #endif /* !defined(OS_GETRANDOM_METHODDEF) */
13486
13487 #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
13488 #define OS__ADD_DLL_DIRECTORY_METHODDEF
13489 #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
13490
13491 #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
13492 #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
13493 #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
13494
13495 #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13496 #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
13497 #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
13498
13499 #ifndef OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13500 #define OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF
13501 #endif /* !defined(OS__SUPPORTS_VIRTUAL_TERMINAL_METHODDEF) */
13502
13503 #ifndef OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13504 #define OS__EMSCRIPTEN_DEBUGGER_METHODDEF
13505 #endif /* !defined(OS__EMSCRIPTEN_DEBUGGER_METHODDEF) */
13506
13507 #ifndef OS__EMSCRIPTEN_LOG_METHODDEF
13508 #define OS__EMSCRIPTEN_LOG_METHODDEF
13509 #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */
13510 /*[clinic end generated code: output=37154d6d9778381e input=a9049054013a1b77]*/