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