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