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