• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)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 = {"O&|$O&p:stat", _keywords, 0};
42     path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
43     int dir_fd = DEFAULT_DIR_FD;
44     int follow_symlinks = 1;
45 
46     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
47         path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
48         goto exit;
49     }
50     return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
51 
52 exit:
53     /* Cleanup for path */
54     path_cleanup(&path);
55 
56     return return_value;
57 }
58 
59 PyDoc_STRVAR(os_lstat__doc__,
60 "lstat($module, /, path, *, dir_fd=None)\n"
61 "--\n"
62 "\n"
63 "Perform a stat system call on the given path, without following symbolic links.\n"
64 "\n"
65 "Like stat(), but do not follow symbolic links.\n"
66 "Equivalent to stat(path, follow_symlinks=False).");
67 
68 #define OS_LSTAT_METHODDEF    \
69     {"lstat", (PyCFunction)os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
70 
71 static PyObject *
72 os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
73 
74 static PyObject *
os_lstat(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)75 os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
76 {
77     PyObject *return_value = NULL;
78     static const char * const _keywords[] = {"path", "dir_fd", NULL};
79     static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
80     path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
81     int dir_fd = DEFAULT_DIR_FD;
82 
83     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
84         path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
85         goto exit;
86     }
87     return_value = os_lstat_impl(module, &path, dir_fd);
88 
89 exit:
90     /* Cleanup for path */
91     path_cleanup(&path);
92 
93     return return_value;
94 }
95 
96 PyDoc_STRVAR(os_access__doc__,
97 "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
98 "       follow_symlinks=True)\n"
99 "--\n"
100 "\n"
101 "Use the real uid/gid to test for access to a path.\n"
102 "\n"
103 "  path\n"
104 "    Path to be tested; can be string, bytes, or a path-like object.\n"
105 "  mode\n"
106 "    Operating-system mode bitfield.  Can be F_OK to test existence,\n"
107 "    or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
108 "  dir_fd\n"
109 "    If not None, it should be a file descriptor open to a directory,\n"
110 "    and path should be relative; path will then be relative to that\n"
111 "    directory.\n"
112 "  effective_ids\n"
113 "    If True, access will use the effective uid/gid instead of\n"
114 "    the real uid/gid.\n"
115 "  follow_symlinks\n"
116 "    If False, and the last element of the path is a symbolic link,\n"
117 "    access will examine the symbolic link itself instead of the file\n"
118 "    the link points to.\n"
119 "\n"
120 "dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
121 "  on your platform.  If they are unavailable, using them will raise a\n"
122 "  NotImplementedError.\n"
123 "\n"
124 "Note that most operations will use the effective uid/gid, therefore this\n"
125 "  routine can be used in a suid/sgid environment to test if the invoking user\n"
126 "  has the specified access to the path.");
127 
128 #define OS_ACCESS_METHODDEF    \
129     {"access", (PyCFunction)os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
130 
131 static int
132 os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
133                int effective_ids, int follow_symlinks);
134 
135 static PyObject *
os_access(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)136 os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
137 {
138     PyObject *return_value = NULL;
139     static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
140     static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
141     path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
142     int mode;
143     int dir_fd = DEFAULT_DIR_FD;
144     int effective_ids = 0;
145     int follow_symlinks = 1;
146     int _return_value;
147 
148     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
149         path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
150         goto exit;
151     }
152     _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
153     if ((_return_value == -1) && PyErr_Occurred()) {
154         goto exit;
155     }
156     return_value = PyBool_FromLong((long)_return_value);
157 
158 exit:
159     /* Cleanup for path */
160     path_cleanup(&path);
161 
162     return return_value;
163 }
164 
165 #if defined(HAVE_TTYNAME)
166 
167 PyDoc_STRVAR(os_ttyname__doc__,
168 "ttyname($module, fd, /)\n"
169 "--\n"
170 "\n"
171 "Return the name of the terminal device connected to \'fd\'.\n"
172 "\n"
173 "  fd\n"
174 "    Integer file descriptor handle.");
175 
176 #define OS_TTYNAME_METHODDEF    \
177     {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
178 
179 static char *
180 os_ttyname_impl(PyObject *module, int fd);
181 
182 static PyObject *
os_ttyname(PyObject * module,PyObject * arg)183 os_ttyname(PyObject *module, PyObject *arg)
184 {
185     PyObject *return_value = NULL;
186     int fd;
187     char *_return_value;
188 
189     if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
190         goto exit;
191     }
192     _return_value = os_ttyname_impl(module, fd);
193     if (_return_value == NULL) {
194         goto exit;
195     }
196     return_value = PyUnicode_DecodeFSDefault(_return_value);
197 
198 exit:
199     return return_value;
200 }
201 
202 #endif /* defined(HAVE_TTYNAME) */
203 
204 #if defined(HAVE_CTERMID)
205 
206 PyDoc_STRVAR(os_ctermid__doc__,
207 "ctermid($module, /)\n"
208 "--\n"
209 "\n"
210 "Return the name of the controlling terminal for this process.");
211 
212 #define OS_CTERMID_METHODDEF    \
213     {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
214 
215 static PyObject *
216 os_ctermid_impl(PyObject *module);
217 
218 static PyObject *
os_ctermid(PyObject * module,PyObject * Py_UNUSED (ignored))219 os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
220 {
221     return os_ctermid_impl(module);
222 }
223 
224 #endif /* defined(HAVE_CTERMID) */
225 
226 PyDoc_STRVAR(os_chdir__doc__,
227 "chdir($module, /, path)\n"
228 "--\n"
229 "\n"
230 "Change the current working directory to the specified path.\n"
231 "\n"
232 "path may always be specified as a string.\n"
233 "On some platforms, path may also be specified as an open file descriptor.\n"
234 "  If this functionality is unavailable, using it raises an exception.");
235 
236 #define OS_CHDIR_METHODDEF    \
237     {"chdir", (PyCFunction)os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
238 
239 static PyObject *
240 os_chdir_impl(PyObject *module, path_t *path);
241 
242 static PyObject *
os_chdir(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)243 os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
244 {
245     PyObject *return_value = NULL;
246     static const char * const _keywords[] = {"path", NULL};
247     static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
248     path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
249 
250     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
251         path_converter, &path)) {
252         goto exit;
253     }
254     return_value = os_chdir_impl(module, &path);
255 
256 exit:
257     /* Cleanup for path */
258     path_cleanup(&path);
259 
260     return return_value;
261 }
262 
263 #if defined(HAVE_FCHDIR)
264 
265 PyDoc_STRVAR(os_fchdir__doc__,
266 "fchdir($module, /, fd)\n"
267 "--\n"
268 "\n"
269 "Change to the directory of the given file descriptor.\n"
270 "\n"
271 "fd must be opened on a directory, not a file.\n"
272 "Equivalent to os.chdir(fd).");
273 
274 #define OS_FCHDIR_METHODDEF    \
275     {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
276 
277 static PyObject *
278 os_fchdir_impl(PyObject *module, int fd);
279 
280 static PyObject *
os_fchdir(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)281 os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
282 {
283     PyObject *return_value = NULL;
284     static const char * const _keywords[] = {"fd", NULL};
285     static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
286     int fd;
287 
288     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
289         fildes_converter, &fd)) {
290         goto exit;
291     }
292     return_value = os_fchdir_impl(module, fd);
293 
294 exit:
295     return return_value;
296 }
297 
298 #endif /* defined(HAVE_FCHDIR) */
299 
300 PyDoc_STRVAR(os_chmod__doc__,
301 "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
302 "--\n"
303 "\n"
304 "Change the access permissions of a file.\n"
305 "\n"
306 "  path\n"
307 "    Path to be modified.  May always be specified as a str, bytes, or a path-like object.\n"
308 "    On some platforms, path may also be specified as an open file descriptor.\n"
309 "    If this functionality is unavailable, using it raises an exception.\n"
310 "  mode\n"
311 "    Operating-system mode bitfield.\n"
312 "  dir_fd\n"
313 "    If not None, it should be a file descriptor open to a directory,\n"
314 "    and path should be relative; path will then be relative to that\n"
315 "    directory.\n"
316 "  follow_symlinks\n"
317 "    If False, and the last element of the path is a symbolic link,\n"
318 "    chmod will modify the symbolic link itself instead of the file\n"
319 "    the link points to.\n"
320 "\n"
321 "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
322 "  an open file descriptor.\n"
323 "dir_fd and follow_symlinks may not be implemented on your platform.\n"
324 "  If they are unavailable, using them will raise a NotImplementedError.");
325 
326 #define OS_CHMOD_METHODDEF    \
327     {"chmod", (PyCFunction)os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
328 
329 static PyObject *
330 os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
331               int follow_symlinks);
332 
333 static PyObject *
os_chmod(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)334 os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
335 {
336     PyObject *return_value = NULL;
337     static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
338     static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
339     path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
340     int mode;
341     int dir_fd = DEFAULT_DIR_FD;
342     int follow_symlinks = 1;
343 
344     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
345         path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
346         goto exit;
347     }
348     return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
349 
350 exit:
351     /* Cleanup for path */
352     path_cleanup(&path);
353 
354     return return_value;
355 }
356 
357 #if defined(HAVE_FCHMOD)
358 
359 PyDoc_STRVAR(os_fchmod__doc__,
360 "fchmod($module, /, fd, mode)\n"
361 "--\n"
362 "\n"
363 "Change the access permissions of the file given by file descriptor fd.\n"
364 "\n"
365 "Equivalent to os.chmod(fd, mode).");
366 
367 #define OS_FCHMOD_METHODDEF    \
368     {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
369 
370 static PyObject *
371 os_fchmod_impl(PyObject *module, int fd, int mode);
372 
373 static PyObject *
os_fchmod(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)374 os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
375 {
376     PyObject *return_value = NULL;
377     static const char * const _keywords[] = {"fd", "mode", NULL};
378     static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
379     int fd;
380     int mode;
381 
382     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
383         &fd, &mode)) {
384         goto exit;
385     }
386     return_value = os_fchmod_impl(module, fd, mode);
387 
388 exit:
389     return return_value;
390 }
391 
392 #endif /* defined(HAVE_FCHMOD) */
393 
394 #if defined(HAVE_LCHMOD)
395 
396 PyDoc_STRVAR(os_lchmod__doc__,
397 "lchmod($module, /, path, mode)\n"
398 "--\n"
399 "\n"
400 "Change the access permissions of a file, without following symbolic links.\n"
401 "\n"
402 "If path is a symlink, this affects the link itself rather than the target.\n"
403 "Equivalent to chmod(path, mode, follow_symlinks=False).\"");
404 
405 #define OS_LCHMOD_METHODDEF    \
406     {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
407 
408 static PyObject *
409 os_lchmod_impl(PyObject *module, path_t *path, int mode);
410 
411 static PyObject *
os_lchmod(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)412 os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
413 {
414     PyObject *return_value = NULL;
415     static const char * const _keywords[] = {"path", "mode", NULL};
416     static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
417     path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
418     int mode;
419 
420     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
421         path_converter, &path, &mode)) {
422         goto exit;
423     }
424     return_value = os_lchmod_impl(module, &path, mode);
425 
426 exit:
427     /* Cleanup for path */
428     path_cleanup(&path);
429 
430     return return_value;
431 }
432 
433 #endif /* defined(HAVE_LCHMOD) */
434 
435 #if defined(HAVE_CHFLAGS)
436 
437 PyDoc_STRVAR(os_chflags__doc__,
438 "chflags($module, /, path, flags, follow_symlinks=True)\n"
439 "--\n"
440 "\n"
441 "Set file flags.\n"
442 "\n"
443 "If follow_symlinks is False, and the last element of the path is a symbolic\n"
444 "  link, chflags will change flags on the symbolic link itself instead of the\n"
445 "  file the link points to.\n"
446 "follow_symlinks may not be implemented on your platform.  If it is\n"
447 "unavailable, using it will raise a NotImplementedError.");
448 
449 #define OS_CHFLAGS_METHODDEF    \
450     {"chflags", (PyCFunction)os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
451 
452 static PyObject *
453 os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
454                 int follow_symlinks);
455 
456 static PyObject *
os_chflags(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)457 os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
458 {
459     PyObject *return_value = NULL;
460     static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
461     static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
462     path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
463     unsigned long flags;
464     int follow_symlinks = 1;
465 
466     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
467         path_converter, &path, &flags, &follow_symlinks)) {
468         goto exit;
469     }
470     return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
471 
472 exit:
473     /* Cleanup for path */
474     path_cleanup(&path);
475 
476     return return_value;
477 }
478 
479 #endif /* defined(HAVE_CHFLAGS) */
480 
481 #if defined(HAVE_LCHFLAGS)
482 
483 PyDoc_STRVAR(os_lchflags__doc__,
484 "lchflags($module, /, path, flags)\n"
485 "--\n"
486 "\n"
487 "Set file flags.\n"
488 "\n"
489 "This function will not follow symbolic links.\n"
490 "Equivalent to chflags(path, flags, follow_symlinks=False).");
491 
492 #define OS_LCHFLAGS_METHODDEF    \
493     {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
494 
495 static PyObject *
496 os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
497 
498 static PyObject *
os_lchflags(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)499 os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
500 {
501     PyObject *return_value = NULL;
502     static const char * const _keywords[] = {"path", "flags", NULL};
503     static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
504     path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
505     unsigned long flags;
506 
507     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
508         path_converter, &path, &flags)) {
509         goto exit;
510     }
511     return_value = os_lchflags_impl(module, &path, flags);
512 
513 exit:
514     /* Cleanup for path */
515     path_cleanup(&path);
516 
517     return return_value;
518 }
519 
520 #endif /* defined(HAVE_LCHFLAGS) */
521 
522 #if defined(HAVE_CHROOT)
523 
524 PyDoc_STRVAR(os_chroot__doc__,
525 "chroot($module, /, path)\n"
526 "--\n"
527 "\n"
528 "Change root directory to path.");
529 
530 #define OS_CHROOT_METHODDEF    \
531     {"chroot", (PyCFunction)os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
532 
533 static PyObject *
534 os_chroot_impl(PyObject *module, path_t *path);
535 
536 static PyObject *
os_chroot(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)537 os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
538 {
539     PyObject *return_value = NULL;
540     static const char * const _keywords[] = {"path", NULL};
541     static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
542     path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
543 
544     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
545         path_converter, &path)) {
546         goto exit;
547     }
548     return_value = os_chroot_impl(module, &path);
549 
550 exit:
551     /* Cleanup for path */
552     path_cleanup(&path);
553 
554     return return_value;
555 }
556 
557 #endif /* defined(HAVE_CHROOT) */
558 
559 #if defined(HAVE_FSYNC)
560 
561 PyDoc_STRVAR(os_fsync__doc__,
562 "fsync($module, /, fd)\n"
563 "--\n"
564 "\n"
565 "Force write of fd to disk.");
566 
567 #define OS_FSYNC_METHODDEF    \
568     {"fsync", (PyCFunction)os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
569 
570 static PyObject *
571 os_fsync_impl(PyObject *module, int fd);
572 
573 static PyObject *
os_fsync(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)574 os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
575 {
576     PyObject *return_value = NULL;
577     static const char * const _keywords[] = {"fd", NULL};
578     static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
579     int fd;
580 
581     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
582         fildes_converter, &fd)) {
583         goto exit;
584     }
585     return_value = os_fsync_impl(module, fd);
586 
587 exit:
588     return return_value;
589 }
590 
591 #endif /* defined(HAVE_FSYNC) */
592 
593 #if defined(HAVE_SYNC)
594 
595 PyDoc_STRVAR(os_sync__doc__,
596 "sync($module, /)\n"
597 "--\n"
598 "\n"
599 "Force write of everything to disk.");
600 
601 #define OS_SYNC_METHODDEF    \
602     {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
603 
604 static PyObject *
605 os_sync_impl(PyObject *module);
606 
607 static PyObject *
os_sync(PyObject * module,PyObject * Py_UNUSED (ignored))608 os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
609 {
610     return os_sync_impl(module);
611 }
612 
613 #endif /* defined(HAVE_SYNC) */
614 
615 #if defined(HAVE_FDATASYNC)
616 
617 PyDoc_STRVAR(os_fdatasync__doc__,
618 "fdatasync($module, /, fd)\n"
619 "--\n"
620 "\n"
621 "Force write of fd to disk without forcing update of metadata.");
622 
623 #define OS_FDATASYNC_METHODDEF    \
624     {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
625 
626 static PyObject *
627 os_fdatasync_impl(PyObject *module, int fd);
628 
629 static PyObject *
os_fdatasync(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)630 os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
631 {
632     PyObject *return_value = NULL;
633     static const char * const _keywords[] = {"fd", NULL};
634     static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
635     int fd;
636 
637     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
638         fildes_converter, &fd)) {
639         goto exit;
640     }
641     return_value = os_fdatasync_impl(module, fd);
642 
643 exit:
644     return return_value;
645 }
646 
647 #endif /* defined(HAVE_FDATASYNC) */
648 
649 #if defined(HAVE_CHOWN)
650 
651 PyDoc_STRVAR(os_chown__doc__,
652 "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
653 "--\n"
654 "\n"
655 "Change the owner and group id of path to the numeric uid and gid.\\\n"
656 "\n"
657 "  path\n"
658 "    Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
659 "  dir_fd\n"
660 "    If not None, it should be a file descriptor open to a directory,\n"
661 "    and path should be relative; path will then be relative to that\n"
662 "    directory.\n"
663 "  follow_symlinks\n"
664 "    If False, and the last element of the path is a symbolic link,\n"
665 "    stat will examine the symbolic link itself instead of the file\n"
666 "    the link points to.\n"
667 "\n"
668 "path may always be specified as a string.\n"
669 "On some platforms, path may also be specified as an open file descriptor.\n"
670 "  If this functionality is unavailable, using it raises an exception.\n"
671 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
672 "  and path should be relative; path will then be relative to that directory.\n"
673 "If follow_symlinks is False, and the last element of the path is a symbolic\n"
674 "  link, chown will modify the symbolic link itself instead of the file the\n"
675 "  link points to.\n"
676 "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
677 "  an open file descriptor.\n"
678 "dir_fd and follow_symlinks may not be implemented on your platform.\n"
679 "  If they are unavailable, using them will raise a NotImplementedError.");
680 
681 #define OS_CHOWN_METHODDEF    \
682     {"chown", (PyCFunction)os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
683 
684 static PyObject *
685 os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
686               int dir_fd, int follow_symlinks);
687 
688 static PyObject *
os_chown(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)689 os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
690 {
691     PyObject *return_value = NULL;
692     static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
693     static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
694     path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
695     uid_t uid;
696     gid_t gid;
697     int dir_fd = DEFAULT_DIR_FD;
698     int follow_symlinks = 1;
699 
700     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
701         path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
702         goto exit;
703     }
704     return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
705 
706 exit:
707     /* Cleanup for path */
708     path_cleanup(&path);
709 
710     return return_value;
711 }
712 
713 #endif /* defined(HAVE_CHOWN) */
714 
715 #if defined(HAVE_FCHOWN)
716 
717 PyDoc_STRVAR(os_fchown__doc__,
718 "fchown($module, /, fd, uid, gid)\n"
719 "--\n"
720 "\n"
721 "Change the owner and group id of the file specified by file descriptor.\n"
722 "\n"
723 "Equivalent to os.chown(fd, uid, gid).");
724 
725 #define OS_FCHOWN_METHODDEF    \
726     {"fchown", (PyCFunction)os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
727 
728 static PyObject *
729 os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
730 
731 static PyObject *
os_fchown(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)732 os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
733 {
734     PyObject *return_value = NULL;
735     static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
736     static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
737     int fd;
738     uid_t uid;
739     gid_t gid;
740 
741     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
742         &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
743         goto exit;
744     }
745     return_value = os_fchown_impl(module, fd, uid, gid);
746 
747 exit:
748     return return_value;
749 }
750 
751 #endif /* defined(HAVE_FCHOWN) */
752 
753 #if defined(HAVE_LCHOWN)
754 
755 PyDoc_STRVAR(os_lchown__doc__,
756 "lchown($module, /, path, uid, gid)\n"
757 "--\n"
758 "\n"
759 "Change the owner and group id of path to the numeric uid and gid.\n"
760 "\n"
761 "This function will not follow symbolic links.\n"
762 "Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
763 
764 #define OS_LCHOWN_METHODDEF    \
765     {"lchown", (PyCFunction)os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
766 
767 static PyObject *
768 os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
769 
770 static PyObject *
os_lchown(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)771 os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
772 {
773     PyObject *return_value = NULL;
774     static const char * const _keywords[] = {"path", "uid", "gid", NULL};
775     static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
776     path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
777     uid_t uid;
778     gid_t gid;
779 
780     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
781         path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
782         goto exit;
783     }
784     return_value = os_lchown_impl(module, &path, uid, gid);
785 
786 exit:
787     /* Cleanup for path */
788     path_cleanup(&path);
789 
790     return return_value;
791 }
792 
793 #endif /* defined(HAVE_LCHOWN) */
794 
795 PyDoc_STRVAR(os_getcwd__doc__,
796 "getcwd($module, /)\n"
797 "--\n"
798 "\n"
799 "Return a unicode string representing the current working directory.");
800 
801 #define OS_GETCWD_METHODDEF    \
802     {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
803 
804 static PyObject *
805 os_getcwd_impl(PyObject *module);
806 
807 static PyObject *
os_getcwd(PyObject * module,PyObject * Py_UNUSED (ignored))808 os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
809 {
810     return os_getcwd_impl(module);
811 }
812 
813 PyDoc_STRVAR(os_getcwdb__doc__,
814 "getcwdb($module, /)\n"
815 "--\n"
816 "\n"
817 "Return a bytes string representing the current working directory.");
818 
819 #define OS_GETCWDB_METHODDEF    \
820     {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
821 
822 static PyObject *
823 os_getcwdb_impl(PyObject *module);
824 
825 static PyObject *
os_getcwdb(PyObject * module,PyObject * Py_UNUSED (ignored))826 os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
827 {
828     return os_getcwdb_impl(module);
829 }
830 
831 #if defined(HAVE_LINK)
832 
833 PyDoc_STRVAR(os_link__doc__,
834 "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
835 "     follow_symlinks=True)\n"
836 "--\n"
837 "\n"
838 "Create a hard link to a file.\n"
839 "\n"
840 "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
841 "  descriptor open to a directory, and the respective path string (src or dst)\n"
842 "  should be relative; the path will then be relative to that directory.\n"
843 "If follow_symlinks is False, and the last element of src is a symbolic\n"
844 "  link, link will create a link to the symbolic link itself instead of the\n"
845 "  file the link points to.\n"
846 "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
847 "  platform.  If they are unavailable, using them will raise a\n"
848 "  NotImplementedError.");
849 
850 #define OS_LINK_METHODDEF    \
851     {"link", (PyCFunction)os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
852 
853 static PyObject *
854 os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
855              int dst_dir_fd, int follow_symlinks);
856 
857 static PyObject *
os_link(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)858 os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
859 {
860     PyObject *return_value = NULL;
861     static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
862     static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
863     path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
864     path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
865     int src_dir_fd = DEFAULT_DIR_FD;
866     int dst_dir_fd = DEFAULT_DIR_FD;
867     int follow_symlinks = 1;
868 
869     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
870         path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
871         goto exit;
872     }
873     return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
874 
875 exit:
876     /* Cleanup for src */
877     path_cleanup(&src);
878     /* Cleanup for dst */
879     path_cleanup(&dst);
880 
881     return return_value;
882 }
883 
884 #endif /* defined(HAVE_LINK) */
885 
886 PyDoc_STRVAR(os_listdir__doc__,
887 "listdir($module, /, path=None)\n"
888 "--\n"
889 "\n"
890 "Return a list containing the names of the files in the directory.\n"
891 "\n"
892 "path can be specified as either str, bytes, or a path-like object.  If path is bytes,\n"
893 "  the filenames returned will also be bytes; in all other circumstances\n"
894 "  the filenames returned will be str.\n"
895 "If path is None, uses the path=\'.\'.\n"
896 "On some platforms, path may also be specified as an open file descriptor;\\\n"
897 "  the file descriptor must refer to a directory.\n"
898 "  If this functionality is unavailable, using it raises NotImplementedError.\n"
899 "\n"
900 "The list is in arbitrary order.  It does not include the special\n"
901 "entries \'.\' and \'..\' even if they are present in the directory.");
902 
903 #define OS_LISTDIR_METHODDEF    \
904     {"listdir", (PyCFunction)os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
905 
906 static PyObject *
907 os_listdir_impl(PyObject *module, path_t *path);
908 
909 static PyObject *
os_listdir(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)910 os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
911 {
912     PyObject *return_value = NULL;
913     static const char * const _keywords[] = {"path", NULL};
914     static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
915     path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
916 
917     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
918         path_converter, &path)) {
919         goto exit;
920     }
921     return_value = os_listdir_impl(module, &path);
922 
923 exit:
924     /* Cleanup for path */
925     path_cleanup(&path);
926 
927     return return_value;
928 }
929 
930 #if defined(MS_WINDOWS)
931 
932 PyDoc_STRVAR(os__getfullpathname__doc__,
933 "_getfullpathname($module, path, /)\n"
934 "--\n"
935 "\n");
936 
937 #define OS__GETFULLPATHNAME_METHODDEF    \
938     {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
939 
940 static PyObject *
941 os__getfullpathname_impl(PyObject *module, path_t *path);
942 
943 static PyObject *
os__getfullpathname(PyObject * module,PyObject * arg)944 os__getfullpathname(PyObject *module, PyObject *arg)
945 {
946     PyObject *return_value = NULL;
947     path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
948 
949     if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
950         goto exit;
951     }
952     return_value = os__getfullpathname_impl(module, &path);
953 
954 exit:
955     /* Cleanup for path */
956     path_cleanup(&path);
957 
958     return return_value;
959 }
960 
961 #endif /* defined(MS_WINDOWS) */
962 
963 #if defined(MS_WINDOWS)
964 
965 PyDoc_STRVAR(os__getfinalpathname__doc__,
966 "_getfinalpathname($module, path, /)\n"
967 "--\n"
968 "\n"
969 "A helper function for samepath on windows.");
970 
971 #define OS__GETFINALPATHNAME_METHODDEF    \
972     {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
973 
974 static PyObject *
975 os__getfinalpathname_impl(PyObject *module, path_t *path);
976 
977 static PyObject *
os__getfinalpathname(PyObject * module,PyObject * arg)978 os__getfinalpathname(PyObject *module, PyObject *arg)
979 {
980     PyObject *return_value = NULL;
981     path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
982 
983     if (!PyArg_Parse(arg, "O&:_getfinalpathname", path_converter, &path)) {
984         goto exit;
985     }
986     return_value = os__getfinalpathname_impl(module, &path);
987 
988 exit:
989     /* Cleanup for path */
990     path_cleanup(&path);
991 
992     return return_value;
993 }
994 
995 #endif /* defined(MS_WINDOWS) */
996 
997 #if defined(MS_WINDOWS)
998 
999 PyDoc_STRVAR(os__isdir__doc__,
1000 "_isdir($module, path, /)\n"
1001 "--\n"
1002 "\n"
1003 "Return true if the pathname refers to an existing directory.");
1004 
1005 #define OS__ISDIR_METHODDEF    \
1006     {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1007 
1008 static PyObject *
1009 os__isdir_impl(PyObject *module, path_t *path);
1010 
1011 static PyObject *
os__isdir(PyObject * module,PyObject * arg)1012 os__isdir(PyObject *module, PyObject *arg)
1013 {
1014     PyObject *return_value = NULL;
1015     path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1016 
1017     if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
1018         goto exit;
1019     }
1020     return_value = os__isdir_impl(module, &path);
1021 
1022 exit:
1023     /* Cleanup for path */
1024     path_cleanup(&path);
1025 
1026     return return_value;
1027 }
1028 
1029 #endif /* defined(MS_WINDOWS) */
1030 
1031 #if defined(MS_WINDOWS)
1032 
1033 PyDoc_STRVAR(os__getvolumepathname__doc__,
1034 "_getvolumepathname($module, /, path)\n"
1035 "--\n"
1036 "\n"
1037 "A helper function for ismount on Win32.");
1038 
1039 #define OS__GETVOLUMEPATHNAME_METHODDEF    \
1040     {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
1041 
1042 static PyObject *
1043 os__getvolumepathname_impl(PyObject *module, path_t *path);
1044 
1045 static PyObject *
os__getvolumepathname(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1046 os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1047 {
1048     PyObject *return_value = NULL;
1049     static const char * const _keywords[] = {"path", NULL};
1050     static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1051     path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
1052 
1053     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1054         path_converter, &path)) {
1055         goto exit;
1056     }
1057     return_value = os__getvolumepathname_impl(module, &path);
1058 
1059 exit:
1060     /* Cleanup for path */
1061     path_cleanup(&path);
1062 
1063     return return_value;
1064 }
1065 
1066 #endif /* defined(MS_WINDOWS) */
1067 
1068 PyDoc_STRVAR(os_mkdir__doc__,
1069 "mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1070 "--\n"
1071 "\n"
1072 "Create a directory.\n"
1073 "\n"
1074 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1075 "  and path should be relative; path will then be relative to that directory.\n"
1076 "dir_fd may not be implemented on your platform.\n"
1077 "  If it is unavailable, using it will raise a NotImplementedError.\n"
1078 "\n"
1079 "The mode argument is ignored on Windows.");
1080 
1081 #define OS_MKDIR_METHODDEF    \
1082     {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
1083 
1084 static PyObject *
1085 os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
1086 
1087 static PyObject *
os_mkdir(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1088 os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1089 {
1090     PyObject *return_value = NULL;
1091     static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1092     static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
1093     path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1094     int mode = 511;
1095     int dir_fd = DEFAULT_DIR_FD;
1096 
1097     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1098         path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
1099         goto exit;
1100     }
1101     return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1102 
1103 exit:
1104     /* Cleanup for path */
1105     path_cleanup(&path);
1106 
1107     return return_value;
1108 }
1109 
1110 #if defined(HAVE_NICE)
1111 
1112 PyDoc_STRVAR(os_nice__doc__,
1113 "nice($module, increment, /)\n"
1114 "--\n"
1115 "\n"
1116 "Add increment to the priority of process and return the new priority.");
1117 
1118 #define OS_NICE_METHODDEF    \
1119     {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
1120 
1121 static PyObject *
1122 os_nice_impl(PyObject *module, int increment);
1123 
1124 static PyObject *
os_nice(PyObject * module,PyObject * arg)1125 os_nice(PyObject *module, PyObject *arg)
1126 {
1127     PyObject *return_value = NULL;
1128     int increment;
1129 
1130     if (!PyArg_Parse(arg, "i:nice", &increment)) {
1131         goto exit;
1132     }
1133     return_value = os_nice_impl(module, increment);
1134 
1135 exit:
1136     return return_value;
1137 }
1138 
1139 #endif /* defined(HAVE_NICE) */
1140 
1141 #if defined(HAVE_GETPRIORITY)
1142 
1143 PyDoc_STRVAR(os_getpriority__doc__,
1144 "getpriority($module, /, which, who)\n"
1145 "--\n"
1146 "\n"
1147 "Return program scheduling priority.");
1148 
1149 #define OS_GETPRIORITY_METHODDEF    \
1150     {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
1151 
1152 static PyObject *
1153 os_getpriority_impl(PyObject *module, int which, int who);
1154 
1155 static PyObject *
os_getpriority(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1156 os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1157 {
1158     PyObject *return_value = NULL;
1159     static const char * const _keywords[] = {"which", "who", NULL};
1160     static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
1161     int which;
1162     int who;
1163 
1164     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1165         &which, &who)) {
1166         goto exit;
1167     }
1168     return_value = os_getpriority_impl(module, which, who);
1169 
1170 exit:
1171     return return_value;
1172 }
1173 
1174 #endif /* defined(HAVE_GETPRIORITY) */
1175 
1176 #if defined(HAVE_SETPRIORITY)
1177 
1178 PyDoc_STRVAR(os_setpriority__doc__,
1179 "setpriority($module, /, which, who, priority)\n"
1180 "--\n"
1181 "\n"
1182 "Set program scheduling priority.");
1183 
1184 #define OS_SETPRIORITY_METHODDEF    \
1185     {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
1186 
1187 static PyObject *
1188 os_setpriority_impl(PyObject *module, int which, int who, int priority);
1189 
1190 static PyObject *
os_setpriority(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1191 os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1192 {
1193     PyObject *return_value = NULL;
1194     static const char * const _keywords[] = {"which", "who", "priority", NULL};
1195     static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
1196     int which;
1197     int who;
1198     int priority;
1199 
1200     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1201         &which, &who, &priority)) {
1202         goto exit;
1203     }
1204     return_value = os_setpriority_impl(module, which, who, priority);
1205 
1206 exit:
1207     return return_value;
1208 }
1209 
1210 #endif /* defined(HAVE_SETPRIORITY) */
1211 
1212 PyDoc_STRVAR(os_rename__doc__,
1213 "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1214 "--\n"
1215 "\n"
1216 "Rename a file or directory.\n"
1217 "\n"
1218 "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1219 "  descriptor open to a directory, and the respective path string (src or dst)\n"
1220 "  should be relative; the path will then be relative to that directory.\n"
1221 "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1222 "  If they are unavailable, using them will raise a NotImplementedError.");
1223 
1224 #define OS_RENAME_METHODDEF    \
1225     {"rename", (PyCFunction)os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
1226 
1227 static PyObject *
1228 os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1229                int dst_dir_fd);
1230 
1231 static PyObject *
os_rename(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1232 os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1233 {
1234     PyObject *return_value = NULL;
1235     static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1236     static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
1237     path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1238     path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1239     int src_dir_fd = DEFAULT_DIR_FD;
1240     int dst_dir_fd = DEFAULT_DIR_FD;
1241 
1242     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1243         path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
1244         goto exit;
1245     }
1246     return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1247 
1248 exit:
1249     /* Cleanup for src */
1250     path_cleanup(&src);
1251     /* Cleanup for dst */
1252     path_cleanup(&dst);
1253 
1254     return return_value;
1255 }
1256 
1257 PyDoc_STRVAR(os_replace__doc__,
1258 "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1259 "--\n"
1260 "\n"
1261 "Rename a file or directory, overwriting the destination.\n"
1262 "\n"
1263 "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1264 "  descriptor open to a directory, and the respective path string (src or dst)\n"
1265 "  should be relative; the path will then be relative to that directory.\n"
1266 "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1267 "  If they are unavailable, using them will raise a NotImplementedError.");
1268 
1269 #define OS_REPLACE_METHODDEF    \
1270     {"replace", (PyCFunction)os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
1271 
1272 static PyObject *
1273 os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1274                 int dst_dir_fd);
1275 
1276 static PyObject *
os_replace(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1277 os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1278 {
1279     PyObject *return_value = NULL;
1280     static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1281     static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
1282     path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1283     path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1284     int src_dir_fd = DEFAULT_DIR_FD;
1285     int dst_dir_fd = DEFAULT_DIR_FD;
1286 
1287     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1288         path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
1289         goto exit;
1290     }
1291     return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1292 
1293 exit:
1294     /* Cleanup for src */
1295     path_cleanup(&src);
1296     /* Cleanup for dst */
1297     path_cleanup(&dst);
1298 
1299     return return_value;
1300 }
1301 
1302 PyDoc_STRVAR(os_rmdir__doc__,
1303 "rmdir($module, /, path, *, dir_fd=None)\n"
1304 "--\n"
1305 "\n"
1306 "Remove a directory.\n"
1307 "\n"
1308 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1309 "  and path should be relative; path will then be relative to that directory.\n"
1310 "dir_fd may not be implemented on your platform.\n"
1311 "  If it is unavailable, using it will raise a NotImplementedError.");
1312 
1313 #define OS_RMDIR_METHODDEF    \
1314     {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
1315 
1316 static PyObject *
1317 os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
1318 
1319 static PyObject *
os_rmdir(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1320 os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1321 {
1322     PyObject *return_value = NULL;
1323     static const char * const _keywords[] = {"path", "dir_fd", NULL};
1324     static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
1325     path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1326     int dir_fd = DEFAULT_DIR_FD;
1327 
1328     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1329         path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
1330         goto exit;
1331     }
1332     return_value = os_rmdir_impl(module, &path, dir_fd);
1333 
1334 exit:
1335     /* Cleanup for path */
1336     path_cleanup(&path);
1337 
1338     return return_value;
1339 }
1340 
1341 #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1342 
1343 PyDoc_STRVAR(os_system__doc__,
1344 "system($module, /, command)\n"
1345 "--\n"
1346 "\n"
1347 "Execute the command in a subshell.");
1348 
1349 #define OS_SYSTEM_METHODDEF    \
1350     {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
1351 
1352 static long
1353 os_system_impl(PyObject *module, const Py_UNICODE *command);
1354 
1355 static PyObject *
os_system(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1356 os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1357 {
1358     PyObject *return_value = NULL;
1359     static const char * const _keywords[] = {"command", NULL};
1360     static _PyArg_Parser _parser = {"u:system", _keywords, 0};
1361     const Py_UNICODE *command;
1362     long _return_value;
1363 
1364     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1365         &command)) {
1366         goto exit;
1367     }
1368     _return_value = os_system_impl(module, command);
1369     if ((_return_value == -1) && PyErr_Occurred()) {
1370         goto exit;
1371     }
1372     return_value = PyLong_FromLong(_return_value);
1373 
1374 exit:
1375     return return_value;
1376 }
1377 
1378 #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1379 
1380 #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1381 
1382 PyDoc_STRVAR(os_system__doc__,
1383 "system($module, /, command)\n"
1384 "--\n"
1385 "\n"
1386 "Execute the command in a subshell.");
1387 
1388 #define OS_SYSTEM_METHODDEF    \
1389     {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
1390 
1391 static long
1392 os_system_impl(PyObject *module, PyObject *command);
1393 
1394 static PyObject *
os_system(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1395 os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1396 {
1397     PyObject *return_value = NULL;
1398     static const char * const _keywords[] = {"command", NULL};
1399     static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
1400     PyObject *command = NULL;
1401     long _return_value;
1402 
1403     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1404         PyUnicode_FSConverter, &command)) {
1405         goto exit;
1406     }
1407     _return_value = os_system_impl(module, command);
1408     if ((_return_value == -1) && PyErr_Occurred()) {
1409         goto exit;
1410     }
1411     return_value = PyLong_FromLong(_return_value);
1412 
1413 exit:
1414     /* Cleanup for command */
1415     Py_XDECREF(command);
1416 
1417     return return_value;
1418 }
1419 
1420 #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1421 
1422 PyDoc_STRVAR(os_umask__doc__,
1423 "umask($module, mask, /)\n"
1424 "--\n"
1425 "\n"
1426 "Set the current numeric umask and return the previous umask.");
1427 
1428 #define OS_UMASK_METHODDEF    \
1429     {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
1430 
1431 static PyObject *
1432 os_umask_impl(PyObject *module, int mask);
1433 
1434 static PyObject *
os_umask(PyObject * module,PyObject * arg)1435 os_umask(PyObject *module, PyObject *arg)
1436 {
1437     PyObject *return_value = NULL;
1438     int mask;
1439 
1440     if (!PyArg_Parse(arg, "i:umask", &mask)) {
1441         goto exit;
1442     }
1443     return_value = os_umask_impl(module, mask);
1444 
1445 exit:
1446     return return_value;
1447 }
1448 
1449 PyDoc_STRVAR(os_unlink__doc__,
1450 "unlink($module, /, path, *, dir_fd=None)\n"
1451 "--\n"
1452 "\n"
1453 "Remove a file (same as remove()).\n"
1454 "\n"
1455 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1456 "  and path should be relative; path will then be relative to that directory.\n"
1457 "dir_fd may not be implemented on your platform.\n"
1458 "  If it is unavailable, using it will raise a NotImplementedError.");
1459 
1460 #define OS_UNLINK_METHODDEF    \
1461     {"unlink", (PyCFunction)os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
1462 
1463 static PyObject *
1464 os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
1465 
1466 static PyObject *
os_unlink(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1467 os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1468 {
1469     PyObject *return_value = NULL;
1470     static const char * const _keywords[] = {"path", "dir_fd", NULL};
1471     static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
1472     path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1473     int dir_fd = DEFAULT_DIR_FD;
1474 
1475     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1476         path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
1477         goto exit;
1478     }
1479     return_value = os_unlink_impl(module, &path, dir_fd);
1480 
1481 exit:
1482     /* Cleanup for path */
1483     path_cleanup(&path);
1484 
1485     return return_value;
1486 }
1487 
1488 PyDoc_STRVAR(os_remove__doc__,
1489 "remove($module, /, path, *, dir_fd=None)\n"
1490 "--\n"
1491 "\n"
1492 "Remove a file (same as unlink()).\n"
1493 "\n"
1494 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1495 "  and path should be relative; path will then be relative to that directory.\n"
1496 "dir_fd may not be implemented on your platform.\n"
1497 "  If it is unavailable, using it will raise a NotImplementedError.");
1498 
1499 #define OS_REMOVE_METHODDEF    \
1500     {"remove", (PyCFunction)os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
1501 
1502 static PyObject *
1503 os_remove_impl(PyObject *module, path_t *path, int dir_fd);
1504 
1505 static PyObject *
os_remove(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1506 os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1507 {
1508     PyObject *return_value = NULL;
1509     static const char * const _keywords[] = {"path", "dir_fd", NULL};
1510     static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
1511     path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1512     int dir_fd = DEFAULT_DIR_FD;
1513 
1514     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1515         path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
1516         goto exit;
1517     }
1518     return_value = os_remove_impl(module, &path, dir_fd);
1519 
1520 exit:
1521     /* Cleanup for path */
1522     path_cleanup(&path);
1523 
1524     return return_value;
1525 }
1526 
1527 #if defined(HAVE_UNAME)
1528 
1529 PyDoc_STRVAR(os_uname__doc__,
1530 "uname($module, /)\n"
1531 "--\n"
1532 "\n"
1533 "Return an object identifying the current operating system.\n"
1534 "\n"
1535 "The object behaves like a named tuple with the following fields:\n"
1536 "  (sysname, nodename, release, version, machine)");
1537 
1538 #define OS_UNAME_METHODDEF    \
1539     {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1540 
1541 static PyObject *
1542 os_uname_impl(PyObject *module);
1543 
1544 static PyObject *
os_uname(PyObject * module,PyObject * Py_UNUSED (ignored))1545 os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
1546 {
1547     return os_uname_impl(module);
1548 }
1549 
1550 #endif /* defined(HAVE_UNAME) */
1551 
1552 PyDoc_STRVAR(os_utime__doc__,
1553 "utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1554 "      follow_symlinks=True)\n"
1555 "--\n"
1556 "\n"
1557 "Set the access and modified time of path.\n"
1558 "\n"
1559 "path may always be specified as a string.\n"
1560 "On some platforms, path may also be specified as an open file descriptor.\n"
1561 "  If this functionality is unavailable, using it raises an exception.\n"
1562 "\n"
1563 "If times is not None, it must be a tuple (atime, mtime);\n"
1564 "    atime and mtime should be expressed as float seconds since the epoch.\n"
1565 "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
1566 "    atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1567 "    since the epoch.\n"
1568 "If times is None and ns is unspecified, utime uses the current time.\n"
1569 "Specifying tuples for both times and ns is an error.\n"
1570 "\n"
1571 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1572 "  and path should be relative; path will then be relative to that directory.\n"
1573 "If follow_symlinks is False, and the last element of the path is a symbolic\n"
1574 "  link, utime will modify the symbolic link itself instead of the file the\n"
1575 "  link points to.\n"
1576 "It is an error to use dir_fd or follow_symlinks when specifying path\n"
1577 "  as an open file descriptor.\n"
1578 "dir_fd and follow_symlinks may not be available on your platform.\n"
1579 "  If they are unavailable, using them will raise a NotImplementedError.");
1580 
1581 #define OS_UTIME_METHODDEF    \
1582     {"utime", (PyCFunction)os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
1583 
1584 static PyObject *
1585 os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1586               int dir_fd, int follow_symlinks);
1587 
1588 static PyObject *
os_utime(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1589 os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1590 {
1591     PyObject *return_value = NULL;
1592     static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1593     static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
1594     path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1595     PyObject *times = NULL;
1596     PyObject *ns = NULL;
1597     int dir_fd = DEFAULT_DIR_FD;
1598     int follow_symlinks = 1;
1599 
1600     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1601         path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
1602         goto exit;
1603     }
1604     return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1605 
1606 exit:
1607     /* Cleanup for path */
1608     path_cleanup(&path);
1609 
1610     return return_value;
1611 }
1612 
1613 PyDoc_STRVAR(os__exit__doc__,
1614 "_exit($module, /, status)\n"
1615 "--\n"
1616 "\n"
1617 "Exit to the system with specified status, without normal exit processing.");
1618 
1619 #define OS__EXIT_METHODDEF    \
1620     {"_exit", (PyCFunction)os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
1621 
1622 static PyObject *
1623 os__exit_impl(PyObject *module, int status);
1624 
1625 static PyObject *
os__exit(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1626 os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1627 {
1628     PyObject *return_value = NULL;
1629     static const char * const _keywords[] = {"status", NULL};
1630     static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
1631     int status;
1632 
1633     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1634         &status)) {
1635         goto exit;
1636     }
1637     return_value = os__exit_impl(module, status);
1638 
1639 exit:
1640     return return_value;
1641 }
1642 
1643 #if defined(HAVE_EXECV)
1644 
1645 PyDoc_STRVAR(os_execv__doc__,
1646 "execv($module, path, argv, /)\n"
1647 "--\n"
1648 "\n"
1649 "Execute an executable path with arguments, replacing current process.\n"
1650 "\n"
1651 "  path\n"
1652 "    Path of executable file.\n"
1653 "  argv\n"
1654 "    Tuple or list of strings.");
1655 
1656 #define OS_EXECV_METHODDEF    \
1657     {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
1658 
1659 static PyObject *
1660 os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
1661 
1662 static PyObject *
os_execv(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1663 os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1664 {
1665     PyObject *return_value = NULL;
1666     path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
1667     PyObject *argv;
1668 
1669     if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1670         path_converter, &path, &argv)) {
1671         goto exit;
1672     }
1673     return_value = os_execv_impl(module, &path, argv);
1674 
1675 exit:
1676     /* Cleanup for path */
1677     path_cleanup(&path);
1678 
1679     return return_value;
1680 }
1681 
1682 #endif /* defined(HAVE_EXECV) */
1683 
1684 #if defined(HAVE_EXECV)
1685 
1686 PyDoc_STRVAR(os_execve__doc__,
1687 "execve($module, /, path, argv, env)\n"
1688 "--\n"
1689 "\n"
1690 "Execute an executable path with arguments, replacing current process.\n"
1691 "\n"
1692 "  path\n"
1693 "    Path of executable file.\n"
1694 "  argv\n"
1695 "    Tuple or list of strings.\n"
1696 "  env\n"
1697 "    Dictionary of strings mapping to strings.");
1698 
1699 #define OS_EXECVE_METHODDEF    \
1700     {"execve", (PyCFunction)os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
1701 
1702 static PyObject *
1703 os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
1704 
1705 static PyObject *
os_execve(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1706 os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1707 {
1708     PyObject *return_value = NULL;
1709     static const char * const _keywords[] = {"path", "argv", "env", NULL};
1710     static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
1711     path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1712     PyObject *argv;
1713     PyObject *env;
1714 
1715     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1716         path_converter, &path, &argv, &env)) {
1717         goto exit;
1718     }
1719     return_value = os_execve_impl(module, &path, argv, env);
1720 
1721 exit:
1722     /* Cleanup for path */
1723     path_cleanup(&path);
1724 
1725     return return_value;
1726 }
1727 
1728 #endif /* defined(HAVE_EXECV) */
1729 
1730 #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
1731 
1732 PyDoc_STRVAR(os_spawnv__doc__,
1733 "spawnv($module, mode, path, argv, /)\n"
1734 "--\n"
1735 "\n"
1736 "Execute the program specified by path in a new process.\n"
1737 "\n"
1738 "  mode\n"
1739 "    Mode of process creation.\n"
1740 "  path\n"
1741 "    Path of executable file.\n"
1742 "  argv\n"
1743 "    Tuple or list of strings.");
1744 
1745 #define OS_SPAWNV_METHODDEF    \
1746     {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
1747 
1748 static PyObject *
1749 os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
1750 
1751 static PyObject *
os_spawnv(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1752 os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1753 {
1754     PyObject *return_value = NULL;
1755     int mode;
1756     path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
1757     PyObject *argv;
1758 
1759     if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1760         &mode, path_converter, &path, &argv)) {
1761         goto exit;
1762     }
1763     return_value = os_spawnv_impl(module, mode, &path, argv);
1764 
1765 exit:
1766     /* Cleanup for path */
1767     path_cleanup(&path);
1768 
1769     return return_value;
1770 }
1771 
1772 #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
1773 
1774 #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
1775 
1776 PyDoc_STRVAR(os_spawnve__doc__,
1777 "spawnve($module, mode, path, argv, env, /)\n"
1778 "--\n"
1779 "\n"
1780 "Execute the program specified by path in a new process.\n"
1781 "\n"
1782 "  mode\n"
1783 "    Mode of process creation.\n"
1784 "  path\n"
1785 "    Path of executable file.\n"
1786 "  argv\n"
1787 "    Tuple or list of strings.\n"
1788 "  env\n"
1789 "    Dictionary of strings mapping to strings.");
1790 
1791 #define OS_SPAWNVE_METHODDEF    \
1792     {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
1793 
1794 static PyObject *
1795 os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
1796                 PyObject *env);
1797 
1798 static PyObject *
os_spawnve(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1799 os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1800 {
1801     PyObject *return_value = NULL;
1802     int mode;
1803     path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
1804     PyObject *argv;
1805     PyObject *env;
1806 
1807     if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1808         &mode, path_converter, &path, &argv, &env)) {
1809         goto exit;
1810     }
1811     return_value = os_spawnve_impl(module, mode, &path, argv, env);
1812 
1813 exit:
1814     /* Cleanup for path */
1815     path_cleanup(&path);
1816 
1817     return return_value;
1818 }
1819 
1820 #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
1821 
1822 #if defined(HAVE_FORK)
1823 
1824 PyDoc_STRVAR(os_register_at_fork__doc__,
1825 "register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1826 "                 after_in_parent=None)\n"
1827 "--\n"
1828 "\n"
1829 "Register callables to be called when forking a new process.\n"
1830 "\n"
1831 "  before\n"
1832 "    A callable to be called in the parent before the fork() syscall.\n"
1833 "  after_in_child\n"
1834 "    A callable to be called in the child after fork().\n"
1835 "  after_in_parent\n"
1836 "    A callable to be called in the parent after fork().\n"
1837 "\n"
1838 "\'before\' callbacks are called in reverse order.\n"
1839 "\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
1840 
1841 #define OS_REGISTER_AT_FORK_METHODDEF    \
1842     {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
1843 
1844 static PyObject *
1845 os_register_at_fork_impl(PyObject *module, PyObject *before,
1846                          PyObject *after_in_child, PyObject *after_in_parent);
1847 
1848 static PyObject *
os_register_at_fork(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1849 os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1850 {
1851     PyObject *return_value = NULL;
1852     static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1853     static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1854     PyObject *before = NULL;
1855     PyObject *after_in_child = NULL;
1856     PyObject *after_in_parent = NULL;
1857 
1858     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1859         &before, &after_in_child, &after_in_parent)) {
1860         goto exit;
1861     }
1862     return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
1863 
1864 exit:
1865     return return_value;
1866 }
1867 
1868 #endif /* defined(HAVE_FORK) */
1869 
1870 #if defined(HAVE_FORK1)
1871 
1872 PyDoc_STRVAR(os_fork1__doc__,
1873 "fork1($module, /)\n"
1874 "--\n"
1875 "\n"
1876 "Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1877 "\n"
1878 "Return 0 to child process and PID of child to parent process.");
1879 
1880 #define OS_FORK1_METHODDEF    \
1881     {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1882 
1883 static PyObject *
1884 os_fork1_impl(PyObject *module);
1885 
1886 static PyObject *
os_fork1(PyObject * module,PyObject * Py_UNUSED (ignored))1887 os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
1888 {
1889     return os_fork1_impl(module);
1890 }
1891 
1892 #endif /* defined(HAVE_FORK1) */
1893 
1894 #if defined(HAVE_FORK)
1895 
1896 PyDoc_STRVAR(os_fork__doc__,
1897 "fork($module, /)\n"
1898 "--\n"
1899 "\n"
1900 "Fork a child process.\n"
1901 "\n"
1902 "Return 0 to child process and PID of child to parent process.");
1903 
1904 #define OS_FORK_METHODDEF    \
1905     {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1906 
1907 static PyObject *
1908 os_fork_impl(PyObject *module);
1909 
1910 static PyObject *
os_fork(PyObject * module,PyObject * Py_UNUSED (ignored))1911 os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
1912 {
1913     return os_fork_impl(module);
1914 }
1915 
1916 #endif /* defined(HAVE_FORK) */
1917 
1918 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1919 
1920 PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1921 "sched_get_priority_max($module, /, policy)\n"
1922 "--\n"
1923 "\n"
1924 "Get the maximum scheduling priority for policy.");
1925 
1926 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF    \
1927     {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
1928 
1929 static PyObject *
1930 os_sched_get_priority_max_impl(PyObject *module, int policy);
1931 
1932 static PyObject *
os_sched_get_priority_max(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1933 os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1934 {
1935     PyObject *return_value = NULL;
1936     static const char * const _keywords[] = {"policy", NULL};
1937     static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
1938     int policy;
1939 
1940     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1941         &policy)) {
1942         goto exit;
1943     }
1944     return_value = os_sched_get_priority_max_impl(module, policy);
1945 
1946 exit:
1947     return return_value;
1948 }
1949 
1950 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1951 
1952 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1953 
1954 PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1955 "sched_get_priority_min($module, /, policy)\n"
1956 "--\n"
1957 "\n"
1958 "Get the minimum scheduling priority for policy.");
1959 
1960 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF    \
1961     {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
1962 
1963 static PyObject *
1964 os_sched_get_priority_min_impl(PyObject *module, int policy);
1965 
1966 static PyObject *
os_sched_get_priority_min(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1967 os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1968 {
1969     PyObject *return_value = NULL;
1970     static const char * const _keywords[] = {"policy", NULL};
1971     static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
1972     int policy;
1973 
1974     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1975         &policy)) {
1976         goto exit;
1977     }
1978     return_value = os_sched_get_priority_min_impl(module, policy);
1979 
1980 exit:
1981     return return_value;
1982 }
1983 
1984 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1985 
1986 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1987 
1988 PyDoc_STRVAR(os_sched_getscheduler__doc__,
1989 "sched_getscheduler($module, pid, /)\n"
1990 "--\n"
1991 "\n"
1992 "Get the scheduling policy for the process identifiedy by pid.\n"
1993 "\n"
1994 "Passing 0 for pid returns the scheduling policy for the calling process.");
1995 
1996 #define OS_SCHED_GETSCHEDULER_METHODDEF    \
1997     {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
1998 
1999 static PyObject *
2000 os_sched_getscheduler_impl(PyObject *module, pid_t pid);
2001 
2002 static PyObject *
os_sched_getscheduler(PyObject * module,PyObject * arg)2003 os_sched_getscheduler(PyObject *module, PyObject *arg)
2004 {
2005     PyObject *return_value = NULL;
2006     pid_t pid;
2007 
2008     if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
2009         goto exit;
2010     }
2011     return_value = os_sched_getscheduler_impl(module, pid);
2012 
2013 exit:
2014     return return_value;
2015 }
2016 
2017 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2018 
2019 #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2020 
2021 PyDoc_STRVAR(os_sched_param__doc__,
2022 "sched_param(sched_priority)\n"
2023 "--\n"
2024 "\n"
2025 "Current has only one field: sched_priority\");\n"
2026 "\n"
2027 "  sched_priority\n"
2028 "    A scheduling parameter.");
2029 
2030 static PyObject *
2031 os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2032 
2033 static PyObject *
os_sched_param(PyTypeObject * type,PyObject * args,PyObject * kwargs)2034 os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2035 {
2036     PyObject *return_value = NULL;
2037     static const char * const _keywords[] = {"sched_priority", NULL};
2038     static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
2039     PyObject *sched_priority;
2040 
2041     if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
2042         &sched_priority)) {
2043         goto exit;
2044     }
2045     return_value = os_sched_param_impl(type, sched_priority);
2046 
2047 exit:
2048     return return_value;
2049 }
2050 
2051 #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2052 
2053 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2054 
2055 PyDoc_STRVAR(os_sched_setscheduler__doc__,
2056 "sched_setscheduler($module, pid, policy, param, /)\n"
2057 "--\n"
2058 "\n"
2059 "Set the scheduling policy for the process identified by pid.\n"
2060 "\n"
2061 "If pid is 0, the calling process is changed.\n"
2062 "param is an instance of sched_param.");
2063 
2064 #define OS_SCHED_SETSCHEDULER_METHODDEF    \
2065     {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
2066 
2067 static PyObject *
2068 os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
2069                            struct sched_param *param);
2070 
2071 static PyObject *
os_sched_setscheduler(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2072 os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2073 {
2074     PyObject *return_value = NULL;
2075     pid_t pid;
2076     int policy;
2077     struct sched_param param;
2078 
2079     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2080         &pid, &policy, convert_sched_param, &param)) {
2081         goto exit;
2082     }
2083     return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2084 
2085 exit:
2086     return return_value;
2087 }
2088 
2089 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2090 
2091 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2092 
2093 PyDoc_STRVAR(os_sched_getparam__doc__,
2094 "sched_getparam($module, pid, /)\n"
2095 "--\n"
2096 "\n"
2097 "Returns scheduling parameters for the process identified by pid.\n"
2098 "\n"
2099 "If pid is 0, returns parameters for the calling process.\n"
2100 "Return value is an instance of sched_param.");
2101 
2102 #define OS_SCHED_GETPARAM_METHODDEF    \
2103     {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
2104 
2105 static PyObject *
2106 os_sched_getparam_impl(PyObject *module, pid_t pid);
2107 
2108 static PyObject *
os_sched_getparam(PyObject * module,PyObject * arg)2109 os_sched_getparam(PyObject *module, PyObject *arg)
2110 {
2111     PyObject *return_value = NULL;
2112     pid_t pid;
2113 
2114     if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
2115         goto exit;
2116     }
2117     return_value = os_sched_getparam_impl(module, pid);
2118 
2119 exit:
2120     return return_value;
2121 }
2122 
2123 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2124 
2125 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2126 
2127 PyDoc_STRVAR(os_sched_setparam__doc__,
2128 "sched_setparam($module, pid, param, /)\n"
2129 "--\n"
2130 "\n"
2131 "Set scheduling parameters for the process identified by pid.\n"
2132 "\n"
2133 "If pid is 0, sets parameters for the calling process.\n"
2134 "param should be an instance of sched_param.");
2135 
2136 #define OS_SCHED_SETPARAM_METHODDEF    \
2137     {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
2138 
2139 static PyObject *
2140 os_sched_setparam_impl(PyObject *module, pid_t pid,
2141                        struct sched_param *param);
2142 
2143 static PyObject *
os_sched_setparam(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2144 os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2145 {
2146     PyObject *return_value = NULL;
2147     pid_t pid;
2148     struct sched_param param;
2149 
2150     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2151         &pid, convert_sched_param, &param)) {
2152         goto exit;
2153     }
2154     return_value = os_sched_setparam_impl(module, pid, &param);
2155 
2156 exit:
2157     return return_value;
2158 }
2159 
2160 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2161 
2162 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2163 
2164 PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2165 "sched_rr_get_interval($module, pid, /)\n"
2166 "--\n"
2167 "\n"
2168 "Return the round-robin quantum for the process identified by pid, in seconds.\n"
2169 "\n"
2170 "Value returned is a float.");
2171 
2172 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF    \
2173     {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
2174 
2175 static double
2176 os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
2177 
2178 static PyObject *
os_sched_rr_get_interval(PyObject * module,PyObject * arg)2179 os_sched_rr_get_interval(PyObject *module, PyObject *arg)
2180 {
2181     PyObject *return_value = NULL;
2182     pid_t pid;
2183     double _return_value;
2184 
2185     if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
2186         goto exit;
2187     }
2188     _return_value = os_sched_rr_get_interval_impl(module, pid);
2189     if ((_return_value == -1.0) && PyErr_Occurred()) {
2190         goto exit;
2191     }
2192     return_value = PyFloat_FromDouble(_return_value);
2193 
2194 exit:
2195     return return_value;
2196 }
2197 
2198 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2199 
2200 #if defined(HAVE_SCHED_H)
2201 
2202 PyDoc_STRVAR(os_sched_yield__doc__,
2203 "sched_yield($module, /)\n"
2204 "--\n"
2205 "\n"
2206 "Voluntarily relinquish the CPU.");
2207 
2208 #define OS_SCHED_YIELD_METHODDEF    \
2209     {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2210 
2211 static PyObject *
2212 os_sched_yield_impl(PyObject *module);
2213 
2214 static PyObject *
os_sched_yield(PyObject * module,PyObject * Py_UNUSED (ignored))2215 os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
2216 {
2217     return os_sched_yield_impl(module);
2218 }
2219 
2220 #endif /* defined(HAVE_SCHED_H) */
2221 
2222 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2223 
2224 PyDoc_STRVAR(os_sched_setaffinity__doc__,
2225 "sched_setaffinity($module, pid, mask, /)\n"
2226 "--\n"
2227 "\n"
2228 "Set the CPU affinity of the process identified by pid to mask.\n"
2229 "\n"
2230 "mask should be an iterable of integers identifying CPUs.");
2231 
2232 #define OS_SCHED_SETAFFINITY_METHODDEF    \
2233     {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
2234 
2235 static PyObject *
2236 os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
2237 
2238 static PyObject *
os_sched_setaffinity(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2239 os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2240 {
2241     PyObject *return_value = NULL;
2242     pid_t pid;
2243     PyObject *mask;
2244 
2245     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2246         &pid, &mask)) {
2247         goto exit;
2248     }
2249     return_value = os_sched_setaffinity_impl(module, pid, mask);
2250 
2251 exit:
2252     return return_value;
2253 }
2254 
2255 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2256 
2257 #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2258 
2259 PyDoc_STRVAR(os_sched_getaffinity__doc__,
2260 "sched_getaffinity($module, pid, /)\n"
2261 "--\n"
2262 "\n"
2263 "Return the affinity of the process identified by pid (or the current process if zero).\n"
2264 "\n"
2265 "The affinity is returned as a set of CPU identifiers.");
2266 
2267 #define OS_SCHED_GETAFFINITY_METHODDEF    \
2268     {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
2269 
2270 static PyObject *
2271 os_sched_getaffinity_impl(PyObject *module, pid_t pid);
2272 
2273 static PyObject *
os_sched_getaffinity(PyObject * module,PyObject * arg)2274 os_sched_getaffinity(PyObject *module, PyObject *arg)
2275 {
2276     PyObject *return_value = NULL;
2277     pid_t pid;
2278 
2279     if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
2280         goto exit;
2281     }
2282     return_value = os_sched_getaffinity_impl(module, pid);
2283 
2284 exit:
2285     return return_value;
2286 }
2287 
2288 #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2289 
2290 #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2291 
2292 PyDoc_STRVAR(os_openpty__doc__,
2293 "openpty($module, /)\n"
2294 "--\n"
2295 "\n"
2296 "Open a pseudo-terminal.\n"
2297 "\n"
2298 "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2299 "for both the master and slave ends.");
2300 
2301 #define OS_OPENPTY_METHODDEF    \
2302     {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2303 
2304 static PyObject *
2305 os_openpty_impl(PyObject *module);
2306 
2307 static PyObject *
os_openpty(PyObject * module,PyObject * Py_UNUSED (ignored))2308 os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
2309 {
2310     return os_openpty_impl(module);
2311 }
2312 
2313 #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2314 
2315 #if defined(HAVE_FORKPTY)
2316 
2317 PyDoc_STRVAR(os_forkpty__doc__,
2318 "forkpty($module, /)\n"
2319 "--\n"
2320 "\n"
2321 "Fork a new process with a new pseudo-terminal as controlling tty.\n"
2322 "\n"
2323 "Returns a tuple of (pid, master_fd).\n"
2324 "Like fork(), return pid of 0 to the child process,\n"
2325 "and pid of child to the parent process.\n"
2326 "To both, return fd of newly opened pseudo-terminal.");
2327 
2328 #define OS_FORKPTY_METHODDEF    \
2329     {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2330 
2331 static PyObject *
2332 os_forkpty_impl(PyObject *module);
2333 
2334 static PyObject *
os_forkpty(PyObject * module,PyObject * Py_UNUSED (ignored))2335 os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
2336 {
2337     return os_forkpty_impl(module);
2338 }
2339 
2340 #endif /* defined(HAVE_FORKPTY) */
2341 
2342 #if defined(HAVE_GETEGID)
2343 
2344 PyDoc_STRVAR(os_getegid__doc__,
2345 "getegid($module, /)\n"
2346 "--\n"
2347 "\n"
2348 "Return the current process\'s effective group id.");
2349 
2350 #define OS_GETEGID_METHODDEF    \
2351     {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2352 
2353 static PyObject *
2354 os_getegid_impl(PyObject *module);
2355 
2356 static PyObject *
os_getegid(PyObject * module,PyObject * Py_UNUSED (ignored))2357 os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
2358 {
2359     return os_getegid_impl(module);
2360 }
2361 
2362 #endif /* defined(HAVE_GETEGID) */
2363 
2364 #if defined(HAVE_GETEUID)
2365 
2366 PyDoc_STRVAR(os_geteuid__doc__,
2367 "geteuid($module, /)\n"
2368 "--\n"
2369 "\n"
2370 "Return the current process\'s effective user id.");
2371 
2372 #define OS_GETEUID_METHODDEF    \
2373     {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2374 
2375 static PyObject *
2376 os_geteuid_impl(PyObject *module);
2377 
2378 static PyObject *
os_geteuid(PyObject * module,PyObject * Py_UNUSED (ignored))2379 os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
2380 {
2381     return os_geteuid_impl(module);
2382 }
2383 
2384 #endif /* defined(HAVE_GETEUID) */
2385 
2386 #if defined(HAVE_GETGID)
2387 
2388 PyDoc_STRVAR(os_getgid__doc__,
2389 "getgid($module, /)\n"
2390 "--\n"
2391 "\n"
2392 "Return the current process\'s group id.");
2393 
2394 #define OS_GETGID_METHODDEF    \
2395     {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2396 
2397 static PyObject *
2398 os_getgid_impl(PyObject *module);
2399 
2400 static PyObject *
os_getgid(PyObject * module,PyObject * Py_UNUSED (ignored))2401 os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
2402 {
2403     return os_getgid_impl(module);
2404 }
2405 
2406 #endif /* defined(HAVE_GETGID) */
2407 
2408 #if defined(HAVE_GETPID)
2409 
2410 PyDoc_STRVAR(os_getpid__doc__,
2411 "getpid($module, /)\n"
2412 "--\n"
2413 "\n"
2414 "Return the current process id.");
2415 
2416 #define OS_GETPID_METHODDEF    \
2417     {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2418 
2419 static PyObject *
2420 os_getpid_impl(PyObject *module);
2421 
2422 static PyObject *
os_getpid(PyObject * module,PyObject * Py_UNUSED (ignored))2423 os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
2424 {
2425     return os_getpid_impl(module);
2426 }
2427 
2428 #endif /* defined(HAVE_GETPID) */
2429 
2430 #if defined(HAVE_GETGROUPS)
2431 
2432 PyDoc_STRVAR(os_getgroups__doc__,
2433 "getgroups($module, /)\n"
2434 "--\n"
2435 "\n"
2436 "Return list of supplemental group IDs for the process.");
2437 
2438 #define OS_GETGROUPS_METHODDEF    \
2439     {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2440 
2441 static PyObject *
2442 os_getgroups_impl(PyObject *module);
2443 
2444 static PyObject *
os_getgroups(PyObject * module,PyObject * Py_UNUSED (ignored))2445 os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
2446 {
2447     return os_getgroups_impl(module);
2448 }
2449 
2450 #endif /* defined(HAVE_GETGROUPS) */
2451 
2452 #if defined(HAVE_GETPGID)
2453 
2454 PyDoc_STRVAR(os_getpgid__doc__,
2455 "getpgid($module, /, pid)\n"
2456 "--\n"
2457 "\n"
2458 "Call the system call getpgid(), and return the result.");
2459 
2460 #define OS_GETPGID_METHODDEF    \
2461     {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
2462 
2463 static PyObject *
2464 os_getpgid_impl(PyObject *module, pid_t pid);
2465 
2466 static PyObject *
os_getpgid(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)2467 os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2468 {
2469     PyObject *return_value = NULL;
2470     static const char * const _keywords[] = {"pid", NULL};
2471     static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
2472     pid_t pid;
2473 
2474     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
2475         &pid)) {
2476         goto exit;
2477     }
2478     return_value = os_getpgid_impl(module, pid);
2479 
2480 exit:
2481     return return_value;
2482 }
2483 
2484 #endif /* defined(HAVE_GETPGID) */
2485 
2486 #if defined(HAVE_GETPGRP)
2487 
2488 PyDoc_STRVAR(os_getpgrp__doc__,
2489 "getpgrp($module, /)\n"
2490 "--\n"
2491 "\n"
2492 "Return the current process group id.");
2493 
2494 #define OS_GETPGRP_METHODDEF    \
2495     {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2496 
2497 static PyObject *
2498 os_getpgrp_impl(PyObject *module);
2499 
2500 static PyObject *
os_getpgrp(PyObject * module,PyObject * Py_UNUSED (ignored))2501 os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
2502 {
2503     return os_getpgrp_impl(module);
2504 }
2505 
2506 #endif /* defined(HAVE_GETPGRP) */
2507 
2508 #if defined(HAVE_SETPGRP)
2509 
2510 PyDoc_STRVAR(os_setpgrp__doc__,
2511 "setpgrp($module, /)\n"
2512 "--\n"
2513 "\n"
2514 "Make the current process the leader of its process group.");
2515 
2516 #define OS_SETPGRP_METHODDEF    \
2517     {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2518 
2519 static PyObject *
2520 os_setpgrp_impl(PyObject *module);
2521 
2522 static PyObject *
os_setpgrp(PyObject * module,PyObject * Py_UNUSED (ignored))2523 os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
2524 {
2525     return os_setpgrp_impl(module);
2526 }
2527 
2528 #endif /* defined(HAVE_SETPGRP) */
2529 
2530 #if defined(HAVE_GETPPID)
2531 
2532 PyDoc_STRVAR(os_getppid__doc__,
2533 "getppid($module, /)\n"
2534 "--\n"
2535 "\n"
2536 "Return the parent\'s process id.\n"
2537 "\n"
2538 "If the parent process has already exited, Windows machines will still\n"
2539 "return its id; others systems will return the id of the \'init\' process (1).");
2540 
2541 #define OS_GETPPID_METHODDEF    \
2542     {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2543 
2544 static PyObject *
2545 os_getppid_impl(PyObject *module);
2546 
2547 static PyObject *
os_getppid(PyObject * module,PyObject * Py_UNUSED (ignored))2548 os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
2549 {
2550     return os_getppid_impl(module);
2551 }
2552 
2553 #endif /* defined(HAVE_GETPPID) */
2554 
2555 #if defined(HAVE_GETLOGIN)
2556 
2557 PyDoc_STRVAR(os_getlogin__doc__,
2558 "getlogin($module, /)\n"
2559 "--\n"
2560 "\n"
2561 "Return the actual login name.");
2562 
2563 #define OS_GETLOGIN_METHODDEF    \
2564     {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2565 
2566 static PyObject *
2567 os_getlogin_impl(PyObject *module);
2568 
2569 static PyObject *
os_getlogin(PyObject * module,PyObject * Py_UNUSED (ignored))2570 os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
2571 {
2572     return os_getlogin_impl(module);
2573 }
2574 
2575 #endif /* defined(HAVE_GETLOGIN) */
2576 
2577 #if defined(HAVE_GETUID)
2578 
2579 PyDoc_STRVAR(os_getuid__doc__,
2580 "getuid($module, /)\n"
2581 "--\n"
2582 "\n"
2583 "Return the current process\'s user id.");
2584 
2585 #define OS_GETUID_METHODDEF    \
2586     {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2587 
2588 static PyObject *
2589 os_getuid_impl(PyObject *module);
2590 
2591 static PyObject *
os_getuid(PyObject * module,PyObject * Py_UNUSED (ignored))2592 os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
2593 {
2594     return os_getuid_impl(module);
2595 }
2596 
2597 #endif /* defined(HAVE_GETUID) */
2598 
2599 #if defined(HAVE_KILL)
2600 
2601 PyDoc_STRVAR(os_kill__doc__,
2602 "kill($module, pid, signal, /)\n"
2603 "--\n"
2604 "\n"
2605 "Kill a process with a signal.");
2606 
2607 #define OS_KILL_METHODDEF    \
2608     {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
2609 
2610 static PyObject *
2611 os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
2612 
2613 static PyObject *
os_kill(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2614 os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2615 {
2616     PyObject *return_value = NULL;
2617     pid_t pid;
2618     Py_ssize_t signal;
2619 
2620     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2621         &pid, &signal)) {
2622         goto exit;
2623     }
2624     return_value = os_kill_impl(module, pid, signal);
2625 
2626 exit:
2627     return return_value;
2628 }
2629 
2630 #endif /* defined(HAVE_KILL) */
2631 
2632 #if defined(HAVE_KILLPG)
2633 
2634 PyDoc_STRVAR(os_killpg__doc__,
2635 "killpg($module, pgid, signal, /)\n"
2636 "--\n"
2637 "\n"
2638 "Kill a process group with a signal.");
2639 
2640 #define OS_KILLPG_METHODDEF    \
2641     {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
2642 
2643 static PyObject *
2644 os_killpg_impl(PyObject *module, pid_t pgid, int signal);
2645 
2646 static PyObject *
os_killpg(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2647 os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2648 {
2649     PyObject *return_value = NULL;
2650     pid_t pgid;
2651     int signal;
2652 
2653     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2654         &pgid, &signal)) {
2655         goto exit;
2656     }
2657     return_value = os_killpg_impl(module, pgid, signal);
2658 
2659 exit:
2660     return return_value;
2661 }
2662 
2663 #endif /* defined(HAVE_KILLPG) */
2664 
2665 #if defined(HAVE_PLOCK)
2666 
2667 PyDoc_STRVAR(os_plock__doc__,
2668 "plock($module, op, /)\n"
2669 "--\n"
2670 "\n"
2671 "Lock program segments into memory.\");");
2672 
2673 #define OS_PLOCK_METHODDEF    \
2674     {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
2675 
2676 static PyObject *
2677 os_plock_impl(PyObject *module, int op);
2678 
2679 static PyObject *
os_plock(PyObject * module,PyObject * arg)2680 os_plock(PyObject *module, PyObject *arg)
2681 {
2682     PyObject *return_value = NULL;
2683     int op;
2684 
2685     if (!PyArg_Parse(arg, "i:plock", &op)) {
2686         goto exit;
2687     }
2688     return_value = os_plock_impl(module, op);
2689 
2690 exit:
2691     return return_value;
2692 }
2693 
2694 #endif /* defined(HAVE_PLOCK) */
2695 
2696 #if defined(HAVE_SETUID)
2697 
2698 PyDoc_STRVAR(os_setuid__doc__,
2699 "setuid($module, uid, /)\n"
2700 "--\n"
2701 "\n"
2702 "Set the current process\'s user id.");
2703 
2704 #define OS_SETUID_METHODDEF    \
2705     {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
2706 
2707 static PyObject *
2708 os_setuid_impl(PyObject *module, uid_t uid);
2709 
2710 static PyObject *
os_setuid(PyObject * module,PyObject * arg)2711 os_setuid(PyObject *module, PyObject *arg)
2712 {
2713     PyObject *return_value = NULL;
2714     uid_t uid;
2715 
2716     if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
2717         goto exit;
2718     }
2719     return_value = os_setuid_impl(module, uid);
2720 
2721 exit:
2722     return return_value;
2723 }
2724 
2725 #endif /* defined(HAVE_SETUID) */
2726 
2727 #if defined(HAVE_SETEUID)
2728 
2729 PyDoc_STRVAR(os_seteuid__doc__,
2730 "seteuid($module, euid, /)\n"
2731 "--\n"
2732 "\n"
2733 "Set the current process\'s effective user id.");
2734 
2735 #define OS_SETEUID_METHODDEF    \
2736     {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
2737 
2738 static PyObject *
2739 os_seteuid_impl(PyObject *module, uid_t euid);
2740 
2741 static PyObject *
os_seteuid(PyObject * module,PyObject * arg)2742 os_seteuid(PyObject *module, PyObject *arg)
2743 {
2744     PyObject *return_value = NULL;
2745     uid_t euid;
2746 
2747     if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
2748         goto exit;
2749     }
2750     return_value = os_seteuid_impl(module, euid);
2751 
2752 exit:
2753     return return_value;
2754 }
2755 
2756 #endif /* defined(HAVE_SETEUID) */
2757 
2758 #if defined(HAVE_SETEGID)
2759 
2760 PyDoc_STRVAR(os_setegid__doc__,
2761 "setegid($module, egid, /)\n"
2762 "--\n"
2763 "\n"
2764 "Set the current process\'s effective group id.");
2765 
2766 #define OS_SETEGID_METHODDEF    \
2767     {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
2768 
2769 static PyObject *
2770 os_setegid_impl(PyObject *module, gid_t egid);
2771 
2772 static PyObject *
os_setegid(PyObject * module,PyObject * arg)2773 os_setegid(PyObject *module, PyObject *arg)
2774 {
2775     PyObject *return_value = NULL;
2776     gid_t egid;
2777 
2778     if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
2779         goto exit;
2780     }
2781     return_value = os_setegid_impl(module, egid);
2782 
2783 exit:
2784     return return_value;
2785 }
2786 
2787 #endif /* defined(HAVE_SETEGID) */
2788 
2789 #if defined(HAVE_SETREUID)
2790 
2791 PyDoc_STRVAR(os_setreuid__doc__,
2792 "setreuid($module, ruid, euid, /)\n"
2793 "--\n"
2794 "\n"
2795 "Set the current process\'s real and effective user ids.");
2796 
2797 #define OS_SETREUID_METHODDEF    \
2798     {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
2799 
2800 static PyObject *
2801 os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
2802 
2803 static PyObject *
os_setreuid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2804 os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2805 {
2806     PyObject *return_value = NULL;
2807     uid_t ruid;
2808     uid_t euid;
2809 
2810     if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2811         _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
2812         goto exit;
2813     }
2814     return_value = os_setreuid_impl(module, ruid, euid);
2815 
2816 exit:
2817     return return_value;
2818 }
2819 
2820 #endif /* defined(HAVE_SETREUID) */
2821 
2822 #if defined(HAVE_SETREGID)
2823 
2824 PyDoc_STRVAR(os_setregid__doc__,
2825 "setregid($module, rgid, egid, /)\n"
2826 "--\n"
2827 "\n"
2828 "Set the current process\'s real and effective group ids.");
2829 
2830 #define OS_SETREGID_METHODDEF    \
2831     {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
2832 
2833 static PyObject *
2834 os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
2835 
2836 static PyObject *
os_setregid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2837 os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2838 {
2839     PyObject *return_value = NULL;
2840     gid_t rgid;
2841     gid_t egid;
2842 
2843     if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2844         _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
2845         goto exit;
2846     }
2847     return_value = os_setregid_impl(module, rgid, egid);
2848 
2849 exit:
2850     return return_value;
2851 }
2852 
2853 #endif /* defined(HAVE_SETREGID) */
2854 
2855 #if defined(HAVE_SETGID)
2856 
2857 PyDoc_STRVAR(os_setgid__doc__,
2858 "setgid($module, gid, /)\n"
2859 "--\n"
2860 "\n"
2861 "Set the current process\'s group id.");
2862 
2863 #define OS_SETGID_METHODDEF    \
2864     {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
2865 
2866 static PyObject *
2867 os_setgid_impl(PyObject *module, gid_t gid);
2868 
2869 static PyObject *
os_setgid(PyObject * module,PyObject * arg)2870 os_setgid(PyObject *module, PyObject *arg)
2871 {
2872     PyObject *return_value = NULL;
2873     gid_t gid;
2874 
2875     if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
2876         goto exit;
2877     }
2878     return_value = os_setgid_impl(module, gid);
2879 
2880 exit:
2881     return return_value;
2882 }
2883 
2884 #endif /* defined(HAVE_SETGID) */
2885 
2886 #if defined(HAVE_SETGROUPS)
2887 
2888 PyDoc_STRVAR(os_setgroups__doc__,
2889 "setgroups($module, groups, /)\n"
2890 "--\n"
2891 "\n"
2892 "Set the groups of the current process to list.");
2893 
2894 #define OS_SETGROUPS_METHODDEF    \
2895     {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2896 
2897 #endif /* defined(HAVE_SETGROUPS) */
2898 
2899 #if defined(HAVE_WAIT3)
2900 
2901 PyDoc_STRVAR(os_wait3__doc__,
2902 "wait3($module, /, options)\n"
2903 "--\n"
2904 "\n"
2905 "Wait for completion of a child process.\n"
2906 "\n"
2907 "Returns a tuple of information about the child process:\n"
2908 "  (pid, status, rusage)");
2909 
2910 #define OS_WAIT3_METHODDEF    \
2911     {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
2912 
2913 static PyObject *
2914 os_wait3_impl(PyObject *module, int options);
2915 
2916 static PyObject *
os_wait3(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)2917 os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2918 {
2919     PyObject *return_value = NULL;
2920     static const char * const _keywords[] = {"options", NULL};
2921     static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
2922     int options;
2923 
2924     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
2925         &options)) {
2926         goto exit;
2927     }
2928     return_value = os_wait3_impl(module, options);
2929 
2930 exit:
2931     return return_value;
2932 }
2933 
2934 #endif /* defined(HAVE_WAIT3) */
2935 
2936 #if defined(HAVE_WAIT4)
2937 
2938 PyDoc_STRVAR(os_wait4__doc__,
2939 "wait4($module, /, pid, options)\n"
2940 "--\n"
2941 "\n"
2942 "Wait for completion of a specific child process.\n"
2943 "\n"
2944 "Returns a tuple of information about the child process:\n"
2945 "  (pid, status, rusage)");
2946 
2947 #define OS_WAIT4_METHODDEF    \
2948     {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
2949 
2950 static PyObject *
2951 os_wait4_impl(PyObject *module, pid_t pid, int options);
2952 
2953 static PyObject *
os_wait4(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)2954 os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2955 {
2956     PyObject *return_value = NULL;
2957     static const char * const _keywords[] = {"pid", "options", NULL};
2958     static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
2959     pid_t pid;
2960     int options;
2961 
2962     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
2963         &pid, &options)) {
2964         goto exit;
2965     }
2966     return_value = os_wait4_impl(module, pid, options);
2967 
2968 exit:
2969     return return_value;
2970 }
2971 
2972 #endif /* defined(HAVE_WAIT4) */
2973 
2974 #if (defined(HAVE_WAITID) && !defined(__APPLE__))
2975 
2976 PyDoc_STRVAR(os_waitid__doc__,
2977 "waitid($module, idtype, id, options, /)\n"
2978 "--\n"
2979 "\n"
2980 "Returns the result of waiting for a process or processes.\n"
2981 "\n"
2982 "  idtype\n"
2983 "    Must be one of be P_PID, P_PGID or P_ALL.\n"
2984 "  id\n"
2985 "    The id to wait on.\n"
2986 "  options\n"
2987 "    Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2988 "    or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2989 "\n"
2990 "Returns either waitid_result or None if WNOHANG is specified and there are\n"
2991 "no children in a waitable state.");
2992 
2993 #define OS_WAITID_METHODDEF    \
2994     {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
2995 
2996 static PyObject *
2997 os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
2998 
2999 static PyObject *
os_waitid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3000 os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3001 {
3002     PyObject *return_value = NULL;
3003     idtype_t idtype;
3004     id_t id;
3005     int options;
3006 
3007     if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3008         &idtype, &id, &options)) {
3009         goto exit;
3010     }
3011     return_value = os_waitid_impl(module, idtype, id, options);
3012 
3013 exit:
3014     return return_value;
3015 }
3016 
3017 #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3018 
3019 #if defined(HAVE_WAITPID)
3020 
3021 PyDoc_STRVAR(os_waitpid__doc__,
3022 "waitpid($module, pid, options, /)\n"
3023 "--\n"
3024 "\n"
3025 "Wait for completion of a given child process.\n"
3026 "\n"
3027 "Returns a tuple of information regarding the child process:\n"
3028 "    (pid, status)\n"
3029 "\n"
3030 "The options argument is ignored on Windows.");
3031 
3032 #define OS_WAITPID_METHODDEF    \
3033     {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
3034 
3035 static PyObject *
3036 os_waitpid_impl(PyObject *module, pid_t pid, int options);
3037 
3038 static PyObject *
os_waitpid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3039 os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3040 {
3041     PyObject *return_value = NULL;
3042     pid_t pid;
3043     int options;
3044 
3045     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3046         &pid, &options)) {
3047         goto exit;
3048     }
3049     return_value = os_waitpid_impl(module, pid, options);
3050 
3051 exit:
3052     return return_value;
3053 }
3054 
3055 #endif /* defined(HAVE_WAITPID) */
3056 
3057 #if defined(HAVE_CWAIT)
3058 
3059 PyDoc_STRVAR(os_waitpid__doc__,
3060 "waitpid($module, pid, options, /)\n"
3061 "--\n"
3062 "\n"
3063 "Wait for completion of a given process.\n"
3064 "\n"
3065 "Returns a tuple of information regarding the process:\n"
3066 "    (pid, status << 8)\n"
3067 "\n"
3068 "The options argument is ignored on Windows.");
3069 
3070 #define OS_WAITPID_METHODDEF    \
3071     {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
3072 
3073 static PyObject *
3074 os_waitpid_impl(PyObject *module, intptr_t pid, int options);
3075 
3076 static PyObject *
os_waitpid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3077 os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3078 {
3079     PyObject *return_value = NULL;
3080     intptr_t pid;
3081     int options;
3082 
3083     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3084         &pid, &options)) {
3085         goto exit;
3086     }
3087     return_value = os_waitpid_impl(module, pid, options);
3088 
3089 exit:
3090     return return_value;
3091 }
3092 
3093 #endif /* defined(HAVE_CWAIT) */
3094 
3095 #if defined(HAVE_WAIT)
3096 
3097 PyDoc_STRVAR(os_wait__doc__,
3098 "wait($module, /)\n"
3099 "--\n"
3100 "\n"
3101 "Wait for completion of a child process.\n"
3102 "\n"
3103 "Returns a tuple of information about the child process:\n"
3104 "    (pid, status)");
3105 
3106 #define OS_WAIT_METHODDEF    \
3107     {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3108 
3109 static PyObject *
3110 os_wait_impl(PyObject *module);
3111 
3112 static PyObject *
os_wait(PyObject * module,PyObject * Py_UNUSED (ignored))3113 os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
3114 {
3115     return os_wait_impl(module);
3116 }
3117 
3118 #endif /* defined(HAVE_WAIT) */
3119 
3120 #if defined(HAVE_SYMLINK)
3121 
3122 PyDoc_STRVAR(os_symlink__doc__,
3123 "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3124 "--\n"
3125 "\n"
3126 "Create a symbolic link pointing to src named dst.\n"
3127 "\n"
3128 "target_is_directory is required on Windows if the target is to be\n"
3129 "  interpreted as a directory.  (On Windows, symlink requires\n"
3130 "  Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3131 "  target_is_directory is ignored on non-Windows platforms.\n"
3132 "\n"
3133 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3134 "  and path should be relative; path will then be relative to that directory.\n"
3135 "dir_fd may not be implemented on your platform.\n"
3136 "  If it is unavailable, using it will raise a NotImplementedError.");
3137 
3138 #define OS_SYMLINK_METHODDEF    \
3139     {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
3140 
3141 static PyObject *
3142 os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
3143                 int target_is_directory, int dir_fd);
3144 
3145 static PyObject *
os_symlink(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)3146 os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3147 {
3148     PyObject *return_value = NULL;
3149     static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3150     static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
3151     path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3152     path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3153     int target_is_directory = 0;
3154     int dir_fd = DEFAULT_DIR_FD;
3155 
3156     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3157         path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3158         goto exit;
3159     }
3160     return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3161 
3162 exit:
3163     /* Cleanup for src */
3164     path_cleanup(&src);
3165     /* Cleanup for dst */
3166     path_cleanup(&dst);
3167 
3168     return return_value;
3169 }
3170 
3171 #endif /* defined(HAVE_SYMLINK) */
3172 
3173 #if defined(HAVE_TIMES)
3174 
3175 PyDoc_STRVAR(os_times__doc__,
3176 "times($module, /)\n"
3177 "--\n"
3178 "\n"
3179 "Return a collection containing process timing information.\n"
3180 "\n"
3181 "The object returned behaves like a named tuple with these fields:\n"
3182 "  (utime, stime, cutime, cstime, elapsed_time)\n"
3183 "All fields are floating point numbers.");
3184 
3185 #define OS_TIMES_METHODDEF    \
3186     {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3187 
3188 static PyObject *
3189 os_times_impl(PyObject *module);
3190 
3191 static PyObject *
os_times(PyObject * module,PyObject * Py_UNUSED (ignored))3192 os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
3193 {
3194     return os_times_impl(module);
3195 }
3196 
3197 #endif /* defined(HAVE_TIMES) */
3198 
3199 #if defined(HAVE_GETSID)
3200 
3201 PyDoc_STRVAR(os_getsid__doc__,
3202 "getsid($module, pid, /)\n"
3203 "--\n"
3204 "\n"
3205 "Call the system call getsid(pid) and return the result.");
3206 
3207 #define OS_GETSID_METHODDEF    \
3208     {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
3209 
3210 static PyObject *
3211 os_getsid_impl(PyObject *module, pid_t pid);
3212 
3213 static PyObject *
os_getsid(PyObject * module,PyObject * arg)3214 os_getsid(PyObject *module, PyObject *arg)
3215 {
3216     PyObject *return_value = NULL;
3217     pid_t pid;
3218 
3219     if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
3220         goto exit;
3221     }
3222     return_value = os_getsid_impl(module, pid);
3223 
3224 exit:
3225     return return_value;
3226 }
3227 
3228 #endif /* defined(HAVE_GETSID) */
3229 
3230 #if defined(HAVE_SETSID)
3231 
3232 PyDoc_STRVAR(os_setsid__doc__,
3233 "setsid($module, /)\n"
3234 "--\n"
3235 "\n"
3236 "Call the system call setsid().");
3237 
3238 #define OS_SETSID_METHODDEF    \
3239     {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3240 
3241 static PyObject *
3242 os_setsid_impl(PyObject *module);
3243 
3244 static PyObject *
os_setsid(PyObject * module,PyObject * Py_UNUSED (ignored))3245 os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
3246 {
3247     return os_setsid_impl(module);
3248 }
3249 
3250 #endif /* defined(HAVE_SETSID) */
3251 
3252 #if defined(HAVE_SETPGID)
3253 
3254 PyDoc_STRVAR(os_setpgid__doc__,
3255 "setpgid($module, pid, pgrp, /)\n"
3256 "--\n"
3257 "\n"
3258 "Call the system call setpgid(pid, pgrp).");
3259 
3260 #define OS_SETPGID_METHODDEF    \
3261     {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
3262 
3263 static PyObject *
3264 os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
3265 
3266 static PyObject *
os_setpgid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3267 os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3268 {
3269     PyObject *return_value = NULL;
3270     pid_t pid;
3271     pid_t pgrp;
3272 
3273     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3274         &pid, &pgrp)) {
3275         goto exit;
3276     }
3277     return_value = os_setpgid_impl(module, pid, pgrp);
3278 
3279 exit:
3280     return return_value;
3281 }
3282 
3283 #endif /* defined(HAVE_SETPGID) */
3284 
3285 #if defined(HAVE_TCGETPGRP)
3286 
3287 PyDoc_STRVAR(os_tcgetpgrp__doc__,
3288 "tcgetpgrp($module, fd, /)\n"
3289 "--\n"
3290 "\n"
3291 "Return the process group associated with the terminal specified by fd.");
3292 
3293 #define OS_TCGETPGRP_METHODDEF    \
3294     {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
3295 
3296 static PyObject *
3297 os_tcgetpgrp_impl(PyObject *module, int fd);
3298 
3299 static PyObject *
os_tcgetpgrp(PyObject * module,PyObject * arg)3300 os_tcgetpgrp(PyObject *module, PyObject *arg)
3301 {
3302     PyObject *return_value = NULL;
3303     int fd;
3304 
3305     if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
3306         goto exit;
3307     }
3308     return_value = os_tcgetpgrp_impl(module, fd);
3309 
3310 exit:
3311     return return_value;
3312 }
3313 
3314 #endif /* defined(HAVE_TCGETPGRP) */
3315 
3316 #if defined(HAVE_TCSETPGRP)
3317 
3318 PyDoc_STRVAR(os_tcsetpgrp__doc__,
3319 "tcsetpgrp($module, fd, pgid, /)\n"
3320 "--\n"
3321 "\n"
3322 "Set the process group associated with the terminal specified by fd.");
3323 
3324 #define OS_TCSETPGRP_METHODDEF    \
3325     {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
3326 
3327 static PyObject *
3328 os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
3329 
3330 static PyObject *
os_tcsetpgrp(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3331 os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3332 {
3333     PyObject *return_value = NULL;
3334     int fd;
3335     pid_t pgid;
3336 
3337     if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3338         &fd, &pgid)) {
3339         goto exit;
3340     }
3341     return_value = os_tcsetpgrp_impl(module, fd, pgid);
3342 
3343 exit:
3344     return return_value;
3345 }
3346 
3347 #endif /* defined(HAVE_TCSETPGRP) */
3348 
3349 PyDoc_STRVAR(os_open__doc__,
3350 "open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3351 "--\n"
3352 "\n"
3353 "Open a file for low level IO.  Returns a file descriptor (integer).\n"
3354 "\n"
3355 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3356 "  and path should be relative; path will then be relative to that directory.\n"
3357 "dir_fd may not be implemented on your platform.\n"
3358 "  If it is unavailable, using it will raise a NotImplementedError.");
3359 
3360 #define OS_OPEN_METHODDEF    \
3361     {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
3362 
3363 static int
3364 os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
3365 
3366 static PyObject *
os_open(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)3367 os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3368 {
3369     PyObject *return_value = NULL;
3370     static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3371     static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
3372     path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3373     int flags;
3374     int mode = 511;
3375     int dir_fd = DEFAULT_DIR_FD;
3376     int _return_value;
3377 
3378     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3379         path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
3380         goto exit;
3381     }
3382     _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
3383     if ((_return_value == -1) && PyErr_Occurred()) {
3384         goto exit;
3385     }
3386     return_value = PyLong_FromLong((long)_return_value);
3387 
3388 exit:
3389     /* Cleanup for path */
3390     path_cleanup(&path);
3391 
3392     return return_value;
3393 }
3394 
3395 PyDoc_STRVAR(os_close__doc__,
3396 "close($module, /, fd)\n"
3397 "--\n"
3398 "\n"
3399 "Close a file descriptor.");
3400 
3401 #define OS_CLOSE_METHODDEF    \
3402     {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
3403 
3404 static PyObject *
3405 os_close_impl(PyObject *module, int fd);
3406 
3407 static PyObject *
os_close(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)3408 os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3409 {
3410     PyObject *return_value = NULL;
3411     static const char * const _keywords[] = {"fd", NULL};
3412     static _PyArg_Parser _parser = {"i:close", _keywords, 0};
3413     int fd;
3414 
3415     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3416         &fd)) {
3417         goto exit;
3418     }
3419     return_value = os_close_impl(module, fd);
3420 
3421 exit:
3422     return return_value;
3423 }
3424 
3425 PyDoc_STRVAR(os_closerange__doc__,
3426 "closerange($module, fd_low, fd_high, /)\n"
3427 "--\n"
3428 "\n"
3429 "Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3430 
3431 #define OS_CLOSERANGE_METHODDEF    \
3432     {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
3433 
3434 static PyObject *
3435 os_closerange_impl(PyObject *module, int fd_low, int fd_high);
3436 
3437 static PyObject *
os_closerange(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3438 os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3439 {
3440     PyObject *return_value = NULL;
3441     int fd_low;
3442     int fd_high;
3443 
3444     if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3445         &fd_low, &fd_high)) {
3446         goto exit;
3447     }
3448     return_value = os_closerange_impl(module, fd_low, fd_high);
3449 
3450 exit:
3451     return return_value;
3452 }
3453 
3454 PyDoc_STRVAR(os_dup__doc__,
3455 "dup($module, fd, /)\n"
3456 "--\n"
3457 "\n"
3458 "Return a duplicate of a file descriptor.");
3459 
3460 #define OS_DUP_METHODDEF    \
3461     {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
3462 
3463 static int
3464 os_dup_impl(PyObject *module, int fd);
3465 
3466 static PyObject *
os_dup(PyObject * module,PyObject * arg)3467 os_dup(PyObject *module, PyObject *arg)
3468 {
3469     PyObject *return_value = NULL;
3470     int fd;
3471     int _return_value;
3472 
3473     if (!PyArg_Parse(arg, "i:dup", &fd)) {
3474         goto exit;
3475     }
3476     _return_value = os_dup_impl(module, fd);
3477     if ((_return_value == -1) && PyErr_Occurred()) {
3478         goto exit;
3479     }
3480     return_value = PyLong_FromLong((long)_return_value);
3481 
3482 exit:
3483     return return_value;
3484 }
3485 
3486 PyDoc_STRVAR(os_dup2__doc__,
3487 "dup2($module, /, fd, fd2, inheritable=True)\n"
3488 "--\n"
3489 "\n"
3490 "Duplicate file descriptor.");
3491 
3492 #define OS_DUP2_METHODDEF    \
3493     {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
3494 
3495 static int
3496 os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
3497 
3498 static PyObject *
os_dup2(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)3499 os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3500 {
3501     PyObject *return_value = NULL;
3502     static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3503     static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
3504     int fd;
3505     int fd2;
3506     int inheritable = 1;
3507     int _return_value;
3508 
3509     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3510         &fd, &fd2, &inheritable)) {
3511         goto exit;
3512     }
3513     _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3514     if ((_return_value == -1) && PyErr_Occurred()) {
3515         goto exit;
3516     }
3517     return_value = PyLong_FromLong((long)_return_value);
3518 
3519 exit:
3520     return return_value;
3521 }
3522 
3523 #if defined(HAVE_LOCKF)
3524 
3525 PyDoc_STRVAR(os_lockf__doc__,
3526 "lockf($module, fd, command, length, /)\n"
3527 "--\n"
3528 "\n"
3529 "Apply, test or remove a POSIX lock on an open file descriptor.\n"
3530 "\n"
3531 "  fd\n"
3532 "    An open file descriptor.\n"
3533 "  command\n"
3534 "    One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3535 "  length\n"
3536 "    The number of bytes to lock, starting at the current position.");
3537 
3538 #define OS_LOCKF_METHODDEF    \
3539     {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
3540 
3541 static PyObject *
3542 os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
3543 
3544 static PyObject *
os_lockf(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3545 os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3546 {
3547     PyObject *return_value = NULL;
3548     int fd;
3549     int command;
3550     Py_off_t length;
3551 
3552     if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3553         &fd, &command, Py_off_t_converter, &length)) {
3554         goto exit;
3555     }
3556     return_value = os_lockf_impl(module, fd, command, length);
3557 
3558 exit:
3559     return return_value;
3560 }
3561 
3562 #endif /* defined(HAVE_LOCKF) */
3563 
3564 PyDoc_STRVAR(os_lseek__doc__,
3565 "lseek($module, fd, position, how, /)\n"
3566 "--\n"
3567 "\n"
3568 "Set the position of a file descriptor.  Return the new position.\n"
3569 "\n"
3570 "Return the new cursor position in number of bytes\n"
3571 "relative to the beginning of the file.");
3572 
3573 #define OS_LSEEK_METHODDEF    \
3574     {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
3575 
3576 static Py_off_t
3577 os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
3578 
3579 static PyObject *
os_lseek(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3580 os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3581 {
3582     PyObject *return_value = NULL;
3583     int fd;
3584     Py_off_t position;
3585     int how;
3586     Py_off_t _return_value;
3587 
3588     if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3589         &fd, Py_off_t_converter, &position, &how)) {
3590         goto exit;
3591     }
3592     _return_value = os_lseek_impl(module, fd, position, how);
3593     if ((_return_value == -1) && PyErr_Occurred()) {
3594         goto exit;
3595     }
3596     return_value = PyLong_FromPy_off_t(_return_value);
3597 
3598 exit:
3599     return return_value;
3600 }
3601 
3602 PyDoc_STRVAR(os_read__doc__,
3603 "read($module, fd, length, /)\n"
3604 "--\n"
3605 "\n"
3606 "Read from a file descriptor.  Returns a bytes object.");
3607 
3608 #define OS_READ_METHODDEF    \
3609     {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
3610 
3611 static PyObject *
3612 os_read_impl(PyObject *module, int fd, Py_ssize_t length);
3613 
3614 static PyObject *
os_read(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3615 os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3616 {
3617     PyObject *return_value = NULL;
3618     int fd;
3619     Py_ssize_t length;
3620 
3621     if (!_PyArg_ParseStack(args, nargs, "in:read",
3622         &fd, &length)) {
3623         goto exit;
3624     }
3625     return_value = os_read_impl(module, fd, length);
3626 
3627 exit:
3628     return return_value;
3629 }
3630 
3631 #if defined(HAVE_READV)
3632 
3633 PyDoc_STRVAR(os_readv__doc__,
3634 "readv($module, fd, buffers, /)\n"
3635 "--\n"
3636 "\n"
3637 "Read from a file descriptor fd into an iterable of buffers.\n"
3638 "\n"
3639 "The buffers should be mutable buffers accepting bytes.\n"
3640 "readv will transfer data into each buffer until it is full\n"
3641 "and then move on to the next buffer in the sequence to hold\n"
3642 "the rest of the data.\n"
3643 "\n"
3644 "readv returns the total number of bytes read,\n"
3645 "which may be less than the total capacity of all the buffers.");
3646 
3647 #define OS_READV_METHODDEF    \
3648     {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
3649 
3650 static Py_ssize_t
3651 os_readv_impl(PyObject *module, int fd, PyObject *buffers);
3652 
3653 static PyObject *
os_readv(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3654 os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3655 {
3656     PyObject *return_value = NULL;
3657     int fd;
3658     PyObject *buffers;
3659     Py_ssize_t _return_value;
3660 
3661     if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3662         &fd, &buffers)) {
3663         goto exit;
3664     }
3665     _return_value = os_readv_impl(module, fd, buffers);
3666     if ((_return_value == -1) && PyErr_Occurred()) {
3667         goto exit;
3668     }
3669     return_value = PyLong_FromSsize_t(_return_value);
3670 
3671 exit:
3672     return return_value;
3673 }
3674 
3675 #endif /* defined(HAVE_READV) */
3676 
3677 #if defined(HAVE_PREAD)
3678 
3679 PyDoc_STRVAR(os_pread__doc__,
3680 "pread($module, fd, length, offset, /)\n"
3681 "--\n"
3682 "\n"
3683 "Read a number of bytes from a file descriptor starting at a particular offset.\n"
3684 "\n"
3685 "Read length bytes from file descriptor fd, starting at offset bytes from\n"
3686 "the beginning of the file.  The file offset remains unchanged.");
3687 
3688 #define OS_PREAD_METHODDEF    \
3689     {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
3690 
3691 static PyObject *
3692 os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
3693 
3694 static PyObject *
os_pread(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3695 os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3696 {
3697     PyObject *return_value = NULL;
3698     int fd;
3699     int length;
3700     Py_off_t offset;
3701 
3702     if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3703         &fd, &length, Py_off_t_converter, &offset)) {
3704         goto exit;
3705     }
3706     return_value = os_pread_impl(module, fd, length, offset);
3707 
3708 exit:
3709     return return_value;
3710 }
3711 
3712 #endif /* defined(HAVE_PREAD) */
3713 
3714 #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3715 
3716 PyDoc_STRVAR(os_preadv__doc__,
3717 "preadv($module, fd, buffers, offset, flags=0, /)\n"
3718 "--\n"
3719 "\n"
3720 "Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3721 "\n"
3722 "Combines the functionality of readv() and pread(). As readv(), it will\n"
3723 "transfer data into each buffer until it is full and then move on to the next\n"
3724 "buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3725 "specifies the file offset at which the input operation is to be performed. It\n"
3726 "will return the total number of bytes read (which can be less than the total\n"
3727 "capacity of all the objects).\n"
3728 "\n"
3729 "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3730 "\n"
3731 "- RWF_HIPRI\n"
3732 "- RWF_NOWAIT\n"
3733 "\n"
3734 "Using non-zero flags requires Linux 4.6 or newer.");
3735 
3736 #define OS_PREADV_METHODDEF    \
3737     {"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
3738 
3739 static Py_ssize_t
3740 os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3741                int flags);
3742 
3743 static PyObject *
os_preadv(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3744 os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3745 {
3746     PyObject *return_value = NULL;
3747     int fd;
3748     PyObject *buffers;
3749     Py_off_t offset;
3750     int flags = 0;
3751     Py_ssize_t _return_value;
3752 
3753     if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3754         &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3755         goto exit;
3756     }
3757     _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3758     if ((_return_value == -1) && PyErr_Occurred()) {
3759         goto exit;
3760     }
3761     return_value = PyLong_FromSsize_t(_return_value);
3762 
3763 exit:
3764     return return_value;
3765 }
3766 
3767 #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3768 
3769 PyDoc_STRVAR(os_write__doc__,
3770 "write($module, fd, data, /)\n"
3771 "--\n"
3772 "\n"
3773 "Write a bytes object to a file descriptor.");
3774 
3775 #define OS_WRITE_METHODDEF    \
3776     {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
3777 
3778 static Py_ssize_t
3779 os_write_impl(PyObject *module, int fd, Py_buffer *data);
3780 
3781 static PyObject *
os_write(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3782 os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3783 {
3784     PyObject *return_value = NULL;
3785     int fd;
3786     Py_buffer data = {NULL, NULL};
3787     Py_ssize_t _return_value;
3788 
3789     if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3790         &fd, &data)) {
3791         goto exit;
3792     }
3793     _return_value = os_write_impl(module, fd, &data);
3794     if ((_return_value == -1) && PyErr_Occurred()) {
3795         goto exit;
3796     }
3797     return_value = PyLong_FromSsize_t(_return_value);
3798 
3799 exit:
3800     /* Cleanup for data */
3801     if (data.obj) {
3802        PyBuffer_Release(&data);
3803     }
3804 
3805     return return_value;
3806 }
3807 
3808 PyDoc_STRVAR(os_fstat__doc__,
3809 "fstat($module, /, fd)\n"
3810 "--\n"
3811 "\n"
3812 "Perform a stat system call on the given file descriptor.\n"
3813 "\n"
3814 "Like stat(), but for an open file descriptor.\n"
3815 "Equivalent to os.stat(fd).");
3816 
3817 #define OS_FSTAT_METHODDEF    \
3818     {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
3819 
3820 static PyObject *
3821 os_fstat_impl(PyObject *module, int fd);
3822 
3823 static PyObject *
os_fstat(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)3824 os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3825 {
3826     PyObject *return_value = NULL;
3827     static const char * const _keywords[] = {"fd", NULL};
3828     static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
3829     int fd;
3830 
3831     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3832         &fd)) {
3833         goto exit;
3834     }
3835     return_value = os_fstat_impl(module, fd);
3836 
3837 exit:
3838     return return_value;
3839 }
3840 
3841 PyDoc_STRVAR(os_isatty__doc__,
3842 "isatty($module, fd, /)\n"
3843 "--\n"
3844 "\n"
3845 "Return True if the fd is connected to a terminal.\n"
3846 "\n"
3847 "Return True if the file descriptor is an open file descriptor\n"
3848 "connected to the slave end of a terminal.");
3849 
3850 #define OS_ISATTY_METHODDEF    \
3851     {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
3852 
3853 static int
3854 os_isatty_impl(PyObject *module, int fd);
3855 
3856 static PyObject *
os_isatty(PyObject * module,PyObject * arg)3857 os_isatty(PyObject *module, PyObject *arg)
3858 {
3859     PyObject *return_value = NULL;
3860     int fd;
3861     int _return_value;
3862 
3863     if (!PyArg_Parse(arg, "i:isatty", &fd)) {
3864         goto exit;
3865     }
3866     _return_value = os_isatty_impl(module, fd);
3867     if ((_return_value == -1) && PyErr_Occurred()) {
3868         goto exit;
3869     }
3870     return_value = PyBool_FromLong((long)_return_value);
3871 
3872 exit:
3873     return return_value;
3874 }
3875 
3876 #if defined(HAVE_PIPE)
3877 
3878 PyDoc_STRVAR(os_pipe__doc__,
3879 "pipe($module, /)\n"
3880 "--\n"
3881 "\n"
3882 "Create a pipe.\n"
3883 "\n"
3884 "Returns a tuple of two file descriptors:\n"
3885 "  (read_fd, write_fd)");
3886 
3887 #define OS_PIPE_METHODDEF    \
3888     {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3889 
3890 static PyObject *
3891 os_pipe_impl(PyObject *module);
3892 
3893 static PyObject *
os_pipe(PyObject * module,PyObject * Py_UNUSED (ignored))3894 os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
3895 {
3896     return os_pipe_impl(module);
3897 }
3898 
3899 #endif /* defined(HAVE_PIPE) */
3900 
3901 #if defined(HAVE_PIPE2)
3902 
3903 PyDoc_STRVAR(os_pipe2__doc__,
3904 "pipe2($module, flags, /)\n"
3905 "--\n"
3906 "\n"
3907 "Create a pipe with flags set atomically.\n"
3908 "\n"
3909 "Returns a tuple of two file descriptors:\n"
3910 "  (read_fd, write_fd)\n"
3911 "\n"
3912 "flags can be constructed by ORing together one or more of these values:\n"
3913 "O_NONBLOCK, O_CLOEXEC.");
3914 
3915 #define OS_PIPE2_METHODDEF    \
3916     {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
3917 
3918 static PyObject *
3919 os_pipe2_impl(PyObject *module, int flags);
3920 
3921 static PyObject *
os_pipe2(PyObject * module,PyObject * arg)3922 os_pipe2(PyObject *module, PyObject *arg)
3923 {
3924     PyObject *return_value = NULL;
3925     int flags;
3926 
3927     if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
3928         goto exit;
3929     }
3930     return_value = os_pipe2_impl(module, flags);
3931 
3932 exit:
3933     return return_value;
3934 }
3935 
3936 #endif /* defined(HAVE_PIPE2) */
3937 
3938 #if defined(HAVE_WRITEV)
3939 
3940 PyDoc_STRVAR(os_writev__doc__,
3941 "writev($module, fd, buffers, /)\n"
3942 "--\n"
3943 "\n"
3944 "Iterate over buffers, and write the contents of each to a file descriptor.\n"
3945 "\n"
3946 "Returns the total number of bytes written.\n"
3947 "buffers must be a sequence of bytes-like objects.");
3948 
3949 #define OS_WRITEV_METHODDEF    \
3950     {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
3951 
3952 static Py_ssize_t
3953 os_writev_impl(PyObject *module, int fd, PyObject *buffers);
3954 
3955 static PyObject *
os_writev(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3956 os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3957 {
3958     PyObject *return_value = NULL;
3959     int fd;
3960     PyObject *buffers;
3961     Py_ssize_t _return_value;
3962 
3963     if (!_PyArg_ParseStack(args, nargs, "iO:writev",
3964         &fd, &buffers)) {
3965         goto exit;
3966     }
3967     _return_value = os_writev_impl(module, fd, buffers);
3968     if ((_return_value == -1) && PyErr_Occurred()) {
3969         goto exit;
3970     }
3971     return_value = PyLong_FromSsize_t(_return_value);
3972 
3973 exit:
3974     return return_value;
3975 }
3976 
3977 #endif /* defined(HAVE_WRITEV) */
3978 
3979 #if defined(HAVE_PWRITE)
3980 
3981 PyDoc_STRVAR(os_pwrite__doc__,
3982 "pwrite($module, fd, buffer, offset, /)\n"
3983 "--\n"
3984 "\n"
3985 "Write bytes to a file descriptor starting at a particular offset.\n"
3986 "\n"
3987 "Write buffer to fd, starting at offset bytes from the beginning of\n"
3988 "the file.  Returns the number of bytes writte.  Does not change the\n"
3989 "current file offset.");
3990 
3991 #define OS_PWRITE_METHODDEF    \
3992     {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
3993 
3994 static Py_ssize_t
3995 os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
3996 
3997 static PyObject *
os_pwrite(PyObject * module,PyObject * const * args,Py_ssize_t nargs)3998 os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3999 {
4000     PyObject *return_value = NULL;
4001     int fd;
4002     Py_buffer buffer = {NULL, NULL};
4003     Py_off_t offset;
4004     Py_ssize_t _return_value;
4005 
4006     if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4007         &fd, &buffer, Py_off_t_converter, &offset)) {
4008         goto exit;
4009     }
4010     _return_value = os_pwrite_impl(module, fd, &buffer, offset);
4011     if ((_return_value == -1) && PyErr_Occurred()) {
4012         goto exit;
4013     }
4014     return_value = PyLong_FromSsize_t(_return_value);
4015 
4016 exit:
4017     /* Cleanup for buffer */
4018     if (buffer.obj) {
4019        PyBuffer_Release(&buffer);
4020     }
4021 
4022     return return_value;
4023 }
4024 
4025 #endif /* defined(HAVE_PWRITE) */
4026 
4027 #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4028 
4029 PyDoc_STRVAR(os_pwritev__doc__,
4030 "pwritev($module, fd, buffers, offset, flags=0, /)\n"
4031 "--\n"
4032 "\n"
4033 "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4034 "\n"
4035 "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4036 "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4037 "buffer is written before proceeding to second, and so on. The operating system may\n"
4038 "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4039 "This function writes the contents of each object to the file descriptor and returns\n"
4040 "the total number of bytes written.\n"
4041 "\n"
4042 "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4043 "\n"
4044 "- RWF_DSYNC\n"
4045 "- RWF_SYNC\n"
4046 "\n"
4047 "Using non-zero flags requires Linux 4.7 or newer.");
4048 
4049 #define OS_PWRITEV_METHODDEF    \
4050     {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4051 
4052 static Py_ssize_t
4053 os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4054                 int flags);
4055 
4056 static PyObject *
os_pwritev(PyObject * module,PyObject * const * args,Py_ssize_t nargs)4057 os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4058 {
4059     PyObject *return_value = NULL;
4060     int fd;
4061     PyObject *buffers;
4062     Py_off_t offset;
4063     int flags = 0;
4064     Py_ssize_t _return_value;
4065 
4066     if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4067         &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4068         goto exit;
4069     }
4070     _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4071     if ((_return_value == -1) && PyErr_Occurred()) {
4072         goto exit;
4073     }
4074     return_value = PyLong_FromSsize_t(_return_value);
4075 
4076 exit:
4077     return return_value;
4078 }
4079 
4080 #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4081 
4082 #if defined(HAVE_MKFIFO)
4083 
4084 PyDoc_STRVAR(os_mkfifo__doc__,
4085 "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4086 "--\n"
4087 "\n"
4088 "Create a \"fifo\" (a POSIX named pipe).\n"
4089 "\n"
4090 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4091 "  and path should be relative; path will then be relative to that directory.\n"
4092 "dir_fd may not be implemented on your platform.\n"
4093 "  If it is unavailable, using it will raise a NotImplementedError.");
4094 
4095 #define OS_MKFIFO_METHODDEF    \
4096     {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
4097 
4098 static PyObject *
4099 os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
4100 
4101 static PyObject *
os_mkfifo(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4102 os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4103 {
4104     PyObject *return_value = NULL;
4105     static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4106     static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
4107     path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4108     int mode = 438;
4109     int dir_fd = DEFAULT_DIR_FD;
4110 
4111     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4112         path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
4113         goto exit;
4114     }
4115     return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4116 
4117 exit:
4118     /* Cleanup for path */
4119     path_cleanup(&path);
4120 
4121     return return_value;
4122 }
4123 
4124 #endif /* defined(HAVE_MKFIFO) */
4125 
4126 #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4127 
4128 PyDoc_STRVAR(os_mknod__doc__,
4129 "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4130 "--\n"
4131 "\n"
4132 "Create a node in the file system.\n"
4133 "\n"
4134 "Create a node in the file system (file, device special file or named pipe)\n"
4135 "at path.  mode specifies both the permissions to use and the\n"
4136 "type of node to be created, being combined (bitwise OR) with one of\n"
4137 "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO.  If S_IFCHR or S_IFBLK is set on mode,\n"
4138 "device defines the newly created device special file (probably using\n"
4139 "os.makedev()).  Otherwise device is ignored.\n"
4140 "\n"
4141 "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4142 "  and path should be relative; path will then be relative to that directory.\n"
4143 "dir_fd may not be implemented on your platform.\n"
4144 "  If it is unavailable, using it will raise a NotImplementedError.");
4145 
4146 #define OS_MKNOD_METHODDEF    \
4147     {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
4148 
4149 static PyObject *
4150 os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
4151               int dir_fd);
4152 
4153 static PyObject *
os_mknod(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4154 os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4155 {
4156     PyObject *return_value = NULL;
4157     static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4158     static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
4159     path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4160     int mode = 384;
4161     dev_t device = 0;
4162     int dir_fd = DEFAULT_DIR_FD;
4163 
4164     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4165         path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
4166         goto exit;
4167     }
4168     return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4169 
4170 exit:
4171     /* Cleanup for path */
4172     path_cleanup(&path);
4173 
4174     return return_value;
4175 }
4176 
4177 #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4178 
4179 #if defined(HAVE_DEVICE_MACROS)
4180 
4181 PyDoc_STRVAR(os_major__doc__,
4182 "major($module, device, /)\n"
4183 "--\n"
4184 "\n"
4185 "Extracts a device major number from a raw device number.");
4186 
4187 #define OS_MAJOR_METHODDEF    \
4188     {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
4189 
4190 static unsigned int
4191 os_major_impl(PyObject *module, dev_t device);
4192 
4193 static PyObject *
os_major(PyObject * module,PyObject * arg)4194 os_major(PyObject *module, PyObject *arg)
4195 {
4196     PyObject *return_value = NULL;
4197     dev_t device;
4198     unsigned int _return_value;
4199 
4200     if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
4201         goto exit;
4202     }
4203     _return_value = os_major_impl(module, device);
4204     if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
4205         goto exit;
4206     }
4207     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4208 
4209 exit:
4210     return return_value;
4211 }
4212 
4213 #endif /* defined(HAVE_DEVICE_MACROS) */
4214 
4215 #if defined(HAVE_DEVICE_MACROS)
4216 
4217 PyDoc_STRVAR(os_minor__doc__,
4218 "minor($module, device, /)\n"
4219 "--\n"
4220 "\n"
4221 "Extracts a device minor number from a raw device number.");
4222 
4223 #define OS_MINOR_METHODDEF    \
4224     {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
4225 
4226 static unsigned int
4227 os_minor_impl(PyObject *module, dev_t device);
4228 
4229 static PyObject *
os_minor(PyObject * module,PyObject * arg)4230 os_minor(PyObject *module, PyObject *arg)
4231 {
4232     PyObject *return_value = NULL;
4233     dev_t device;
4234     unsigned int _return_value;
4235 
4236     if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
4237         goto exit;
4238     }
4239     _return_value = os_minor_impl(module, device);
4240     if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
4241         goto exit;
4242     }
4243     return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4244 
4245 exit:
4246     return return_value;
4247 }
4248 
4249 #endif /* defined(HAVE_DEVICE_MACROS) */
4250 
4251 #if defined(HAVE_DEVICE_MACROS)
4252 
4253 PyDoc_STRVAR(os_makedev__doc__,
4254 "makedev($module, major, minor, /)\n"
4255 "--\n"
4256 "\n"
4257 "Composes a raw device number from the major and minor device numbers.");
4258 
4259 #define OS_MAKEDEV_METHODDEF    \
4260     {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
4261 
4262 static dev_t
4263 os_makedev_impl(PyObject *module, int major, int minor);
4264 
4265 static PyObject *
os_makedev(PyObject * module,PyObject * const * args,Py_ssize_t nargs)4266 os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4267 {
4268     PyObject *return_value = NULL;
4269     int major;
4270     int minor;
4271     dev_t _return_value;
4272 
4273     if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4274         &major, &minor)) {
4275         goto exit;
4276     }
4277     _return_value = os_makedev_impl(module, major, minor);
4278     if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
4279         goto exit;
4280     }
4281     return_value = _PyLong_FromDev(_return_value);
4282 
4283 exit:
4284     return return_value;
4285 }
4286 
4287 #endif /* defined(HAVE_DEVICE_MACROS) */
4288 
4289 #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
4290 
4291 PyDoc_STRVAR(os_ftruncate__doc__,
4292 "ftruncate($module, fd, length, /)\n"
4293 "--\n"
4294 "\n"
4295 "Truncate a file, specified by file descriptor, to a specific length.");
4296 
4297 #define OS_FTRUNCATE_METHODDEF    \
4298     {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
4299 
4300 static PyObject *
4301 os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
4302 
4303 static PyObject *
os_ftruncate(PyObject * module,PyObject * const * args,Py_ssize_t nargs)4304 os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4305 {
4306     PyObject *return_value = NULL;
4307     int fd;
4308     Py_off_t length;
4309 
4310     if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4311         &fd, Py_off_t_converter, &length)) {
4312         goto exit;
4313     }
4314     return_value = os_ftruncate_impl(module, fd, length);
4315 
4316 exit:
4317     return return_value;
4318 }
4319 
4320 #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
4321 
4322 #if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
4323 
4324 PyDoc_STRVAR(os_truncate__doc__,
4325 "truncate($module, /, path, length)\n"
4326 "--\n"
4327 "\n"
4328 "Truncate a file, specified by path, to a specific length.\n"
4329 "\n"
4330 "On some platforms, path may also be specified as an open file descriptor.\n"
4331 "  If this functionality is unavailable, using it raises an exception.");
4332 
4333 #define OS_TRUNCATE_METHODDEF    \
4334     {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
4335 
4336 static PyObject *
4337 os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
4338 
4339 static PyObject *
os_truncate(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4340 os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4341 {
4342     PyObject *return_value = NULL;
4343     static const char * const _keywords[] = {"path", "length", NULL};
4344     static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
4345     path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4346     Py_off_t length;
4347 
4348     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4349         path_converter, &path, Py_off_t_converter, &length)) {
4350         goto exit;
4351     }
4352     return_value = os_truncate_impl(module, &path, length);
4353 
4354 exit:
4355     /* Cleanup for path */
4356     path_cleanup(&path);
4357 
4358     return return_value;
4359 }
4360 
4361 #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
4362 
4363 #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4364 
4365 PyDoc_STRVAR(os_posix_fallocate__doc__,
4366 "posix_fallocate($module, fd, offset, length, /)\n"
4367 "--\n"
4368 "\n"
4369 "Ensure a file has allocated at least a particular number of bytes on disk.\n"
4370 "\n"
4371 "Ensure that the file specified by fd encompasses a range of bytes\n"
4372 "starting at offset bytes from the beginning and continuing for length bytes.");
4373 
4374 #define OS_POSIX_FALLOCATE_METHODDEF    \
4375     {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
4376 
4377 static PyObject *
4378 os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
4379                         Py_off_t length);
4380 
4381 static PyObject *
os_posix_fallocate(PyObject * module,PyObject * const * args,Py_ssize_t nargs)4382 os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4383 {
4384     PyObject *return_value = NULL;
4385     int fd;
4386     Py_off_t offset;
4387     Py_off_t length;
4388 
4389     if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4390         &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
4391         goto exit;
4392     }
4393     return_value = os_posix_fallocate_impl(module, fd, offset, length);
4394 
4395 exit:
4396     return return_value;
4397 }
4398 
4399 #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4400 
4401 #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4402 
4403 PyDoc_STRVAR(os_posix_fadvise__doc__,
4404 "posix_fadvise($module, fd, offset, length, advice, /)\n"
4405 "--\n"
4406 "\n"
4407 "Announce an intention to access data in a specific pattern.\n"
4408 "\n"
4409 "Announce an intention to access data in a specific pattern, thus allowing\n"
4410 "the kernel to make optimizations.\n"
4411 "The advice applies to the region of the file specified by fd starting at\n"
4412 "offset and continuing for length bytes.\n"
4413 "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4414 "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4415 "POSIX_FADV_DONTNEED.");
4416 
4417 #define OS_POSIX_FADVISE_METHODDEF    \
4418     {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
4419 
4420 static PyObject *
4421 os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
4422                       Py_off_t length, int advice);
4423 
4424 static PyObject *
os_posix_fadvise(PyObject * module,PyObject * const * args,Py_ssize_t nargs)4425 os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4426 {
4427     PyObject *return_value = NULL;
4428     int fd;
4429     Py_off_t offset;
4430     Py_off_t length;
4431     int advice;
4432 
4433     if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4434         &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
4435         goto exit;
4436     }
4437     return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4438 
4439 exit:
4440     return return_value;
4441 }
4442 
4443 #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4444 
4445 #if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4446 
4447 PyDoc_STRVAR(os_putenv__doc__,
4448 "putenv($module, name, value, /)\n"
4449 "--\n"
4450 "\n"
4451 "Change or add an environment variable.");
4452 
4453 #define OS_PUTENV_METHODDEF    \
4454     {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
4455 
4456 static PyObject *
4457 os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
4458 
4459 static PyObject *
os_putenv(PyObject * module,PyObject * const * args,Py_ssize_t nargs)4460 os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4461 {
4462     PyObject *return_value = NULL;
4463     PyObject *name;
4464     PyObject *value;
4465 
4466     if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4467         &name, &value)) {
4468         goto exit;
4469     }
4470     return_value = os_putenv_impl(module, name, value);
4471 
4472 exit:
4473     return return_value;
4474 }
4475 
4476 #endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4477 
4478 #if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4479 
4480 PyDoc_STRVAR(os_putenv__doc__,
4481 "putenv($module, name, value, /)\n"
4482 "--\n"
4483 "\n"
4484 "Change or add an environment variable.");
4485 
4486 #define OS_PUTENV_METHODDEF    \
4487     {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
4488 
4489 static PyObject *
4490 os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
4491 
4492 static PyObject *
os_putenv(PyObject * module,PyObject * const * args,Py_ssize_t nargs)4493 os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4494 {
4495     PyObject *return_value = NULL;
4496     PyObject *name = NULL;
4497     PyObject *value = NULL;
4498 
4499     if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4500         PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
4501         goto exit;
4502     }
4503     return_value = os_putenv_impl(module, name, value);
4504 
4505 exit:
4506     /* Cleanup for name */
4507     Py_XDECREF(name);
4508     /* Cleanup for value */
4509     Py_XDECREF(value);
4510 
4511     return return_value;
4512 }
4513 
4514 #endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4515 
4516 #if defined(HAVE_UNSETENV)
4517 
4518 PyDoc_STRVAR(os_unsetenv__doc__,
4519 "unsetenv($module, name, /)\n"
4520 "--\n"
4521 "\n"
4522 "Delete an environment variable.");
4523 
4524 #define OS_UNSETENV_METHODDEF    \
4525     {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
4526 
4527 static PyObject *
4528 os_unsetenv_impl(PyObject *module, PyObject *name);
4529 
4530 static PyObject *
os_unsetenv(PyObject * module,PyObject * arg)4531 os_unsetenv(PyObject *module, PyObject *arg)
4532 {
4533     PyObject *return_value = NULL;
4534     PyObject *name = NULL;
4535 
4536     if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
4537         goto exit;
4538     }
4539     return_value = os_unsetenv_impl(module, name);
4540 
4541 exit:
4542     /* Cleanup for name */
4543     Py_XDECREF(name);
4544 
4545     return return_value;
4546 }
4547 
4548 #endif /* defined(HAVE_UNSETENV) */
4549 
4550 PyDoc_STRVAR(os_strerror__doc__,
4551 "strerror($module, code, /)\n"
4552 "--\n"
4553 "\n"
4554 "Translate an error code to a message string.");
4555 
4556 #define OS_STRERROR_METHODDEF    \
4557     {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
4558 
4559 static PyObject *
4560 os_strerror_impl(PyObject *module, int code);
4561 
4562 static PyObject *
os_strerror(PyObject * module,PyObject * arg)4563 os_strerror(PyObject *module, PyObject *arg)
4564 {
4565     PyObject *return_value = NULL;
4566     int code;
4567 
4568     if (!PyArg_Parse(arg, "i:strerror", &code)) {
4569         goto exit;
4570     }
4571     return_value = os_strerror_impl(module, code);
4572 
4573 exit:
4574     return return_value;
4575 }
4576 
4577 #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4578 
4579 PyDoc_STRVAR(os_WCOREDUMP__doc__,
4580 "WCOREDUMP($module, status, /)\n"
4581 "--\n"
4582 "\n"
4583 "Return True if the process returning status was dumped to a core file.");
4584 
4585 #define OS_WCOREDUMP_METHODDEF    \
4586     {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
4587 
4588 static int
4589 os_WCOREDUMP_impl(PyObject *module, int status);
4590 
4591 static PyObject *
os_WCOREDUMP(PyObject * module,PyObject * arg)4592 os_WCOREDUMP(PyObject *module, PyObject *arg)
4593 {
4594     PyObject *return_value = NULL;
4595     int status;
4596     int _return_value;
4597 
4598     if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
4599         goto exit;
4600     }
4601     _return_value = os_WCOREDUMP_impl(module, status);
4602     if ((_return_value == -1) && PyErr_Occurred()) {
4603         goto exit;
4604     }
4605     return_value = PyBool_FromLong((long)_return_value);
4606 
4607 exit:
4608     return return_value;
4609 }
4610 
4611 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4612 
4613 #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4614 
4615 PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4616 "WIFCONTINUED($module, /, status)\n"
4617 "--\n"
4618 "\n"
4619 "Return True if a particular process was continued from a job control stop.\n"
4620 "\n"
4621 "Return True if the process returning status was continued from a\n"
4622 "job control stop.");
4623 
4624 #define OS_WIFCONTINUED_METHODDEF    \
4625     {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
4626 
4627 static int
4628 os_WIFCONTINUED_impl(PyObject *module, int status);
4629 
4630 static PyObject *
os_WIFCONTINUED(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4631 os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4632 {
4633     PyObject *return_value = NULL;
4634     static const char * const _keywords[] = {"status", NULL};
4635     static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
4636     int status;
4637     int _return_value;
4638 
4639     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4640         &status)) {
4641         goto exit;
4642     }
4643     _return_value = os_WIFCONTINUED_impl(module, status);
4644     if ((_return_value == -1) && PyErr_Occurred()) {
4645         goto exit;
4646     }
4647     return_value = PyBool_FromLong((long)_return_value);
4648 
4649 exit:
4650     return return_value;
4651 }
4652 
4653 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4654 
4655 #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4656 
4657 PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4658 "WIFSTOPPED($module, /, status)\n"
4659 "--\n"
4660 "\n"
4661 "Return True if the process returning status was stopped.");
4662 
4663 #define OS_WIFSTOPPED_METHODDEF    \
4664     {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
4665 
4666 static int
4667 os_WIFSTOPPED_impl(PyObject *module, int status);
4668 
4669 static PyObject *
os_WIFSTOPPED(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4670 os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4671 {
4672     PyObject *return_value = NULL;
4673     static const char * const _keywords[] = {"status", NULL};
4674     static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
4675     int status;
4676     int _return_value;
4677 
4678     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4679         &status)) {
4680         goto exit;
4681     }
4682     _return_value = os_WIFSTOPPED_impl(module, status);
4683     if ((_return_value == -1) && PyErr_Occurred()) {
4684         goto exit;
4685     }
4686     return_value = PyBool_FromLong((long)_return_value);
4687 
4688 exit:
4689     return return_value;
4690 }
4691 
4692 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4693 
4694 #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4695 
4696 PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4697 "WIFSIGNALED($module, /, status)\n"
4698 "--\n"
4699 "\n"
4700 "Return True if the process returning status was terminated by a signal.");
4701 
4702 #define OS_WIFSIGNALED_METHODDEF    \
4703     {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
4704 
4705 static int
4706 os_WIFSIGNALED_impl(PyObject *module, int status);
4707 
4708 static PyObject *
os_WIFSIGNALED(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4709 os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4710 {
4711     PyObject *return_value = NULL;
4712     static const char * const _keywords[] = {"status", NULL};
4713     static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
4714     int status;
4715     int _return_value;
4716 
4717     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4718         &status)) {
4719         goto exit;
4720     }
4721     _return_value = os_WIFSIGNALED_impl(module, status);
4722     if ((_return_value == -1) && PyErr_Occurred()) {
4723         goto exit;
4724     }
4725     return_value = PyBool_FromLong((long)_return_value);
4726 
4727 exit:
4728     return return_value;
4729 }
4730 
4731 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4732 
4733 #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4734 
4735 PyDoc_STRVAR(os_WIFEXITED__doc__,
4736 "WIFEXITED($module, /, status)\n"
4737 "--\n"
4738 "\n"
4739 "Return True if the process returning status exited via the exit() system call.");
4740 
4741 #define OS_WIFEXITED_METHODDEF    \
4742     {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
4743 
4744 static int
4745 os_WIFEXITED_impl(PyObject *module, int status);
4746 
4747 static PyObject *
os_WIFEXITED(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4748 os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4749 {
4750     PyObject *return_value = NULL;
4751     static const char * const _keywords[] = {"status", NULL};
4752     static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
4753     int status;
4754     int _return_value;
4755 
4756     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4757         &status)) {
4758         goto exit;
4759     }
4760     _return_value = os_WIFEXITED_impl(module, status);
4761     if ((_return_value == -1) && PyErr_Occurred()) {
4762         goto exit;
4763     }
4764     return_value = PyBool_FromLong((long)_return_value);
4765 
4766 exit:
4767     return return_value;
4768 }
4769 
4770 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4771 
4772 #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4773 
4774 PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4775 "WEXITSTATUS($module, /, status)\n"
4776 "--\n"
4777 "\n"
4778 "Return the process return code from status.");
4779 
4780 #define OS_WEXITSTATUS_METHODDEF    \
4781     {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
4782 
4783 static int
4784 os_WEXITSTATUS_impl(PyObject *module, int status);
4785 
4786 static PyObject *
os_WEXITSTATUS(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4787 os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4788 {
4789     PyObject *return_value = NULL;
4790     static const char * const _keywords[] = {"status", NULL};
4791     static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
4792     int status;
4793     int _return_value;
4794 
4795     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4796         &status)) {
4797         goto exit;
4798     }
4799     _return_value = os_WEXITSTATUS_impl(module, status);
4800     if ((_return_value == -1) && PyErr_Occurred()) {
4801         goto exit;
4802     }
4803     return_value = PyLong_FromLong((long)_return_value);
4804 
4805 exit:
4806     return return_value;
4807 }
4808 
4809 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4810 
4811 #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4812 
4813 PyDoc_STRVAR(os_WTERMSIG__doc__,
4814 "WTERMSIG($module, /, status)\n"
4815 "--\n"
4816 "\n"
4817 "Return the signal that terminated the process that provided the status value.");
4818 
4819 #define OS_WTERMSIG_METHODDEF    \
4820     {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
4821 
4822 static int
4823 os_WTERMSIG_impl(PyObject *module, int status);
4824 
4825 static PyObject *
os_WTERMSIG(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4826 os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4827 {
4828     PyObject *return_value = NULL;
4829     static const char * const _keywords[] = {"status", NULL};
4830     static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
4831     int status;
4832     int _return_value;
4833 
4834     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4835         &status)) {
4836         goto exit;
4837     }
4838     _return_value = os_WTERMSIG_impl(module, status);
4839     if ((_return_value == -1) && PyErr_Occurred()) {
4840         goto exit;
4841     }
4842     return_value = PyLong_FromLong((long)_return_value);
4843 
4844 exit:
4845     return return_value;
4846 }
4847 
4848 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4849 
4850 #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4851 
4852 PyDoc_STRVAR(os_WSTOPSIG__doc__,
4853 "WSTOPSIG($module, /, status)\n"
4854 "--\n"
4855 "\n"
4856 "Return the signal that stopped the process that provided the status value.");
4857 
4858 #define OS_WSTOPSIG_METHODDEF    \
4859     {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
4860 
4861 static int
4862 os_WSTOPSIG_impl(PyObject *module, int status);
4863 
4864 static PyObject *
os_WSTOPSIG(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4865 os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4866 {
4867     PyObject *return_value = NULL;
4868     static const char * const _keywords[] = {"status", NULL};
4869     static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
4870     int status;
4871     int _return_value;
4872 
4873     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4874         &status)) {
4875         goto exit;
4876     }
4877     _return_value = os_WSTOPSIG_impl(module, status);
4878     if ((_return_value == -1) && PyErr_Occurred()) {
4879         goto exit;
4880     }
4881     return_value = PyLong_FromLong((long)_return_value);
4882 
4883 exit:
4884     return return_value;
4885 }
4886 
4887 #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4888 
4889 #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4890 
4891 PyDoc_STRVAR(os_fstatvfs__doc__,
4892 "fstatvfs($module, fd, /)\n"
4893 "--\n"
4894 "\n"
4895 "Perform an fstatvfs system call on the given fd.\n"
4896 "\n"
4897 "Equivalent to statvfs(fd).");
4898 
4899 #define OS_FSTATVFS_METHODDEF    \
4900     {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
4901 
4902 static PyObject *
4903 os_fstatvfs_impl(PyObject *module, int fd);
4904 
4905 static PyObject *
os_fstatvfs(PyObject * module,PyObject * arg)4906 os_fstatvfs(PyObject *module, PyObject *arg)
4907 {
4908     PyObject *return_value = NULL;
4909     int fd;
4910 
4911     if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
4912         goto exit;
4913     }
4914     return_value = os_fstatvfs_impl(module, fd);
4915 
4916 exit:
4917     return return_value;
4918 }
4919 
4920 #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4921 
4922 #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4923 
4924 PyDoc_STRVAR(os_statvfs__doc__,
4925 "statvfs($module, /, path)\n"
4926 "--\n"
4927 "\n"
4928 "Perform a statvfs system call on the given path.\n"
4929 "\n"
4930 "path may always be specified as a string.\n"
4931 "On some platforms, path may also be specified as an open file descriptor.\n"
4932 "  If this functionality is unavailable, using it raises an exception.");
4933 
4934 #define OS_STATVFS_METHODDEF    \
4935     {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
4936 
4937 static PyObject *
4938 os_statvfs_impl(PyObject *module, path_t *path);
4939 
4940 static PyObject *
os_statvfs(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4941 os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4942 {
4943     PyObject *return_value = NULL;
4944     static const char * const _keywords[] = {"path", NULL};
4945     static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
4946     path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4947 
4948     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4949         path_converter, &path)) {
4950         goto exit;
4951     }
4952     return_value = os_statvfs_impl(module, &path);
4953 
4954 exit:
4955     /* Cleanup for path */
4956     path_cleanup(&path);
4957 
4958     return return_value;
4959 }
4960 
4961 #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4962 
4963 #if defined(MS_WINDOWS)
4964 
4965 PyDoc_STRVAR(os__getdiskusage__doc__,
4966 "_getdiskusage($module, /, path)\n"
4967 "--\n"
4968 "\n"
4969 "Return disk usage statistics about the given path as a (total, free) tuple.");
4970 
4971 #define OS__GETDISKUSAGE_METHODDEF    \
4972     {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
4973 
4974 static PyObject *
4975 os__getdiskusage_impl(PyObject *module, path_t *path);
4976 
4977 static PyObject *
os__getdiskusage(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)4978 os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4979 {
4980     PyObject *return_value = NULL;
4981     static const char * const _keywords[] = {"path", NULL};
4982     static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
4983     path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
4984 
4985     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4986         path_converter, &path)) {
4987         goto exit;
4988     }
4989     return_value = os__getdiskusage_impl(module, &path);
4990 
4991 exit:
4992     /* Cleanup for path */
4993     path_cleanup(&path);
4994 
4995     return return_value;
4996 }
4997 
4998 #endif /* defined(MS_WINDOWS) */
4999 
5000 #if defined(HAVE_FPATHCONF)
5001 
5002 PyDoc_STRVAR(os_fpathconf__doc__,
5003 "fpathconf($module, fd, name, /)\n"
5004 "--\n"
5005 "\n"
5006 "Return the configuration limit name for the file descriptor fd.\n"
5007 "\n"
5008 "If there is no limit, return -1.");
5009 
5010 #define OS_FPATHCONF_METHODDEF    \
5011     {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
5012 
5013 static long
5014 os_fpathconf_impl(PyObject *module, int fd, int name);
5015 
5016 static PyObject *
os_fpathconf(PyObject * module,PyObject * const * args,Py_ssize_t nargs)5017 os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5018 {
5019     PyObject *return_value = NULL;
5020     int fd;
5021     int name;
5022     long _return_value;
5023 
5024     if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5025         &fd, conv_path_confname, &name)) {
5026         goto exit;
5027     }
5028     _return_value = os_fpathconf_impl(module, fd, name);
5029     if ((_return_value == -1) && PyErr_Occurred()) {
5030         goto exit;
5031     }
5032     return_value = PyLong_FromLong(_return_value);
5033 
5034 exit:
5035     return return_value;
5036 }
5037 
5038 #endif /* defined(HAVE_FPATHCONF) */
5039 
5040 #if defined(HAVE_PATHCONF)
5041 
5042 PyDoc_STRVAR(os_pathconf__doc__,
5043 "pathconf($module, /, path, name)\n"
5044 "--\n"
5045 "\n"
5046 "Return the configuration limit name for the file or directory path.\n"
5047 "\n"
5048 "If there is no limit, return -1.\n"
5049 "On some platforms, path may also be specified as an open file descriptor.\n"
5050 "  If this functionality is unavailable, using it raises an exception.");
5051 
5052 #define OS_PATHCONF_METHODDEF    \
5053     {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
5054 
5055 static long
5056 os_pathconf_impl(PyObject *module, path_t *path, int name);
5057 
5058 static PyObject *
os_pathconf(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5059 os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5060 {
5061     PyObject *return_value = NULL;
5062     static const char * const _keywords[] = {"path", "name", NULL};
5063     static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
5064     path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5065     int name;
5066     long _return_value;
5067 
5068     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5069         path_converter, &path, conv_path_confname, &name)) {
5070         goto exit;
5071     }
5072     _return_value = os_pathconf_impl(module, &path, name);
5073     if ((_return_value == -1) && PyErr_Occurred()) {
5074         goto exit;
5075     }
5076     return_value = PyLong_FromLong(_return_value);
5077 
5078 exit:
5079     /* Cleanup for path */
5080     path_cleanup(&path);
5081 
5082     return return_value;
5083 }
5084 
5085 #endif /* defined(HAVE_PATHCONF) */
5086 
5087 #if defined(HAVE_CONFSTR)
5088 
5089 PyDoc_STRVAR(os_confstr__doc__,
5090 "confstr($module, name, /)\n"
5091 "--\n"
5092 "\n"
5093 "Return a string-valued system configuration variable.");
5094 
5095 #define OS_CONFSTR_METHODDEF    \
5096     {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
5097 
5098 static PyObject *
5099 os_confstr_impl(PyObject *module, int name);
5100 
5101 static PyObject *
os_confstr(PyObject * module,PyObject * arg)5102 os_confstr(PyObject *module, PyObject *arg)
5103 {
5104     PyObject *return_value = NULL;
5105     int name;
5106 
5107     if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
5108         goto exit;
5109     }
5110     return_value = os_confstr_impl(module, name);
5111 
5112 exit:
5113     return return_value;
5114 }
5115 
5116 #endif /* defined(HAVE_CONFSTR) */
5117 
5118 #if defined(HAVE_SYSCONF)
5119 
5120 PyDoc_STRVAR(os_sysconf__doc__,
5121 "sysconf($module, name, /)\n"
5122 "--\n"
5123 "\n"
5124 "Return an integer-valued system configuration variable.");
5125 
5126 #define OS_SYSCONF_METHODDEF    \
5127     {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
5128 
5129 static long
5130 os_sysconf_impl(PyObject *module, int name);
5131 
5132 static PyObject *
os_sysconf(PyObject * module,PyObject * arg)5133 os_sysconf(PyObject *module, PyObject *arg)
5134 {
5135     PyObject *return_value = NULL;
5136     int name;
5137     long _return_value;
5138 
5139     if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
5140         goto exit;
5141     }
5142     _return_value = os_sysconf_impl(module, name);
5143     if ((_return_value == -1) && PyErr_Occurred()) {
5144         goto exit;
5145     }
5146     return_value = PyLong_FromLong(_return_value);
5147 
5148 exit:
5149     return return_value;
5150 }
5151 
5152 #endif /* defined(HAVE_SYSCONF) */
5153 
5154 PyDoc_STRVAR(os_abort__doc__,
5155 "abort($module, /)\n"
5156 "--\n"
5157 "\n"
5158 "Abort the interpreter immediately.\n"
5159 "\n"
5160 "This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5161 "on the hosting operating system.  This function never returns.");
5162 
5163 #define OS_ABORT_METHODDEF    \
5164     {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5165 
5166 static PyObject *
5167 os_abort_impl(PyObject *module);
5168 
5169 static PyObject *
os_abort(PyObject * module,PyObject * Py_UNUSED (ignored))5170 os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
5171 {
5172     return os_abort_impl(module);
5173 }
5174 
5175 #if defined(MS_WINDOWS)
5176 
5177 PyDoc_STRVAR(os_startfile__doc__,
5178 "startfile($module, /, filepath, operation=None)\n"
5179 "--\n"
5180 "\n"
5181 "startfile(filepath [, operation])\n"
5182 "\n"
5183 "Start a file with its associated application.\n"
5184 "\n"
5185 "When \"operation\" is not specified or \"open\", this acts like\n"
5186 "double-clicking the file in Explorer, or giving the file name as an\n"
5187 "argument to the DOS \"start\" command: the file is opened with whatever\n"
5188 "application (if any) its extension is associated.\n"
5189 "When another \"operation\" is given, it specifies what should be done with\n"
5190 "the file.  A typical operation is \"print\".\n"
5191 "\n"
5192 "startfile returns as soon as the associated application is launched.\n"
5193 "There is no option to wait for the application to close, and no way\n"
5194 "to retrieve the application\'s exit status.\n"
5195 "\n"
5196 "The filepath is relative to the current directory.  If you want to use\n"
5197 "an absolute path, make sure the first character is not a slash (\"/\");\n"
5198 "the underlying Win32 ShellExecute function doesn\'t work if it is.");
5199 
5200 #define OS_STARTFILE_METHODDEF    \
5201     {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
5202 
5203 static PyObject *
5204 os_startfile_impl(PyObject *module, path_t *filepath,
5205                   const Py_UNICODE *operation);
5206 
5207 static PyObject *
os_startfile(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5208 os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5209 {
5210     PyObject *return_value = NULL;
5211     static const char * const _keywords[] = {"filepath", "operation", NULL};
5212     static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
5213     path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5214     const Py_UNICODE *operation = NULL;
5215 
5216     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5217         path_converter, &filepath, &operation)) {
5218         goto exit;
5219     }
5220     return_value = os_startfile_impl(module, &filepath, operation);
5221 
5222 exit:
5223     /* Cleanup for filepath */
5224     path_cleanup(&filepath);
5225 
5226     return return_value;
5227 }
5228 
5229 #endif /* defined(MS_WINDOWS) */
5230 
5231 #if defined(HAVE_GETLOADAVG)
5232 
5233 PyDoc_STRVAR(os_getloadavg__doc__,
5234 "getloadavg($module, /)\n"
5235 "--\n"
5236 "\n"
5237 "Return average recent system load information.\n"
5238 "\n"
5239 "Return the number of processes in the system run queue averaged over\n"
5240 "the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5241 "Raises OSError if the load average was unobtainable.");
5242 
5243 #define OS_GETLOADAVG_METHODDEF    \
5244     {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5245 
5246 static PyObject *
5247 os_getloadavg_impl(PyObject *module);
5248 
5249 static PyObject *
os_getloadavg(PyObject * module,PyObject * Py_UNUSED (ignored))5250 os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
5251 {
5252     return os_getloadavg_impl(module);
5253 }
5254 
5255 #endif /* defined(HAVE_GETLOADAVG) */
5256 
5257 PyDoc_STRVAR(os_device_encoding__doc__,
5258 "device_encoding($module, /, fd)\n"
5259 "--\n"
5260 "\n"
5261 "Return a string describing the encoding of a terminal\'s file descriptor.\n"
5262 "\n"
5263 "The file descriptor must be attached to a terminal.\n"
5264 "If the device is not a terminal, return None.");
5265 
5266 #define OS_DEVICE_ENCODING_METHODDEF    \
5267     {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
5268 
5269 static PyObject *
5270 os_device_encoding_impl(PyObject *module, int fd);
5271 
5272 static PyObject *
os_device_encoding(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5273 os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5274 {
5275     PyObject *return_value = NULL;
5276     static const char * const _keywords[] = {"fd", NULL};
5277     static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
5278     int fd;
5279 
5280     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5281         &fd)) {
5282         goto exit;
5283     }
5284     return_value = os_device_encoding_impl(module, fd);
5285 
5286 exit:
5287     return return_value;
5288 }
5289 
5290 #if defined(HAVE_SETRESUID)
5291 
5292 PyDoc_STRVAR(os_setresuid__doc__,
5293 "setresuid($module, ruid, euid, suid, /)\n"
5294 "--\n"
5295 "\n"
5296 "Set the current process\'s real, effective, and saved user ids.");
5297 
5298 #define OS_SETRESUID_METHODDEF    \
5299     {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
5300 
5301 static PyObject *
5302 os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
5303 
5304 static PyObject *
os_setresuid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)5305 os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5306 {
5307     PyObject *return_value = NULL;
5308     uid_t ruid;
5309     uid_t euid;
5310     uid_t suid;
5311 
5312     if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5313         _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
5314         goto exit;
5315     }
5316     return_value = os_setresuid_impl(module, ruid, euid, suid);
5317 
5318 exit:
5319     return return_value;
5320 }
5321 
5322 #endif /* defined(HAVE_SETRESUID) */
5323 
5324 #if defined(HAVE_SETRESGID)
5325 
5326 PyDoc_STRVAR(os_setresgid__doc__,
5327 "setresgid($module, rgid, egid, sgid, /)\n"
5328 "--\n"
5329 "\n"
5330 "Set the current process\'s real, effective, and saved group ids.");
5331 
5332 #define OS_SETRESGID_METHODDEF    \
5333     {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
5334 
5335 static PyObject *
5336 os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
5337 
5338 static PyObject *
os_setresgid(PyObject * module,PyObject * const * args,Py_ssize_t nargs)5339 os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5340 {
5341     PyObject *return_value = NULL;
5342     gid_t rgid;
5343     gid_t egid;
5344     gid_t sgid;
5345 
5346     if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5347         _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
5348         goto exit;
5349     }
5350     return_value = os_setresgid_impl(module, rgid, egid, sgid);
5351 
5352 exit:
5353     return return_value;
5354 }
5355 
5356 #endif /* defined(HAVE_SETRESGID) */
5357 
5358 #if defined(HAVE_GETRESUID)
5359 
5360 PyDoc_STRVAR(os_getresuid__doc__,
5361 "getresuid($module, /)\n"
5362 "--\n"
5363 "\n"
5364 "Return a tuple of the current process\'s real, effective, and saved user ids.");
5365 
5366 #define OS_GETRESUID_METHODDEF    \
5367     {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5368 
5369 static PyObject *
5370 os_getresuid_impl(PyObject *module);
5371 
5372 static PyObject *
os_getresuid(PyObject * module,PyObject * Py_UNUSED (ignored))5373 os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
5374 {
5375     return os_getresuid_impl(module);
5376 }
5377 
5378 #endif /* defined(HAVE_GETRESUID) */
5379 
5380 #if defined(HAVE_GETRESGID)
5381 
5382 PyDoc_STRVAR(os_getresgid__doc__,
5383 "getresgid($module, /)\n"
5384 "--\n"
5385 "\n"
5386 "Return a tuple of the current process\'s real, effective, and saved group ids.");
5387 
5388 #define OS_GETRESGID_METHODDEF    \
5389     {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5390 
5391 static PyObject *
5392 os_getresgid_impl(PyObject *module);
5393 
5394 static PyObject *
os_getresgid(PyObject * module,PyObject * Py_UNUSED (ignored))5395 os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
5396 {
5397     return os_getresgid_impl(module);
5398 }
5399 
5400 #endif /* defined(HAVE_GETRESGID) */
5401 
5402 #if defined(USE_XATTRS)
5403 
5404 PyDoc_STRVAR(os_getxattr__doc__,
5405 "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5406 "--\n"
5407 "\n"
5408 "Return the value of extended attribute attribute on path.\n"
5409 "\n"
5410 "path may be either a string, a path-like object, or an open file descriptor.\n"
5411 "If follow_symlinks is False, and the last element of the path is a symbolic\n"
5412 "  link, getxattr will examine the symbolic link itself instead of the file\n"
5413 "  the link points to.");
5414 
5415 #define OS_GETXATTR_METHODDEF    \
5416     {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
5417 
5418 static PyObject *
5419 os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
5420                  int follow_symlinks);
5421 
5422 static PyObject *
os_getxattr(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5423 os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5424 {
5425     PyObject *return_value = NULL;
5426     static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5427     static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
5428     path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5429     path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5430     int follow_symlinks = 1;
5431 
5432     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5433         path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
5434         goto exit;
5435     }
5436     return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5437 
5438 exit:
5439     /* Cleanup for path */
5440     path_cleanup(&path);
5441     /* Cleanup for attribute */
5442     path_cleanup(&attribute);
5443 
5444     return return_value;
5445 }
5446 
5447 #endif /* defined(USE_XATTRS) */
5448 
5449 #if defined(USE_XATTRS)
5450 
5451 PyDoc_STRVAR(os_setxattr__doc__,
5452 "setxattr($module, /, path, attribute, value, flags=0, *,\n"
5453 "         follow_symlinks=True)\n"
5454 "--\n"
5455 "\n"
5456 "Set extended attribute attribute on path to value.\n"
5457 "\n"
5458 "path may be either a string, a path-like object,  or an open file descriptor.\n"
5459 "If follow_symlinks is False, and the last element of the path is a symbolic\n"
5460 "  link, setxattr will modify the symbolic link itself instead of the file\n"
5461 "  the link points to.");
5462 
5463 #define OS_SETXATTR_METHODDEF    \
5464     {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
5465 
5466 static PyObject *
5467 os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
5468                  Py_buffer *value, int flags, int follow_symlinks);
5469 
5470 static PyObject *
os_setxattr(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5471 os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5472 {
5473     PyObject *return_value = NULL;
5474     static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5475     static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
5476     path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5477     path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5478     Py_buffer value = {NULL, NULL};
5479     int flags = 0;
5480     int follow_symlinks = 1;
5481 
5482     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5483         path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
5484         goto exit;
5485     }
5486     return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5487 
5488 exit:
5489     /* Cleanup for path */
5490     path_cleanup(&path);
5491     /* Cleanup for attribute */
5492     path_cleanup(&attribute);
5493     /* Cleanup for value */
5494     if (value.obj) {
5495        PyBuffer_Release(&value);
5496     }
5497 
5498     return return_value;
5499 }
5500 
5501 #endif /* defined(USE_XATTRS) */
5502 
5503 #if defined(USE_XATTRS)
5504 
5505 PyDoc_STRVAR(os_removexattr__doc__,
5506 "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5507 "--\n"
5508 "\n"
5509 "Remove extended attribute attribute on path.\n"
5510 "\n"
5511 "path may be either a string, a path-like object, or an open file descriptor.\n"
5512 "If follow_symlinks is False, and the last element of the path is a symbolic\n"
5513 "  link, removexattr will modify the symbolic link itself instead of the file\n"
5514 "  the link points to.");
5515 
5516 #define OS_REMOVEXATTR_METHODDEF    \
5517     {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
5518 
5519 static PyObject *
5520 os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
5521                     int follow_symlinks);
5522 
5523 static PyObject *
os_removexattr(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5524 os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5525 {
5526     PyObject *return_value = NULL;
5527     static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5528     static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
5529     path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5530     path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5531     int follow_symlinks = 1;
5532 
5533     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5534         path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
5535         goto exit;
5536     }
5537     return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5538 
5539 exit:
5540     /* Cleanup for path */
5541     path_cleanup(&path);
5542     /* Cleanup for attribute */
5543     path_cleanup(&attribute);
5544 
5545     return return_value;
5546 }
5547 
5548 #endif /* defined(USE_XATTRS) */
5549 
5550 #if defined(USE_XATTRS)
5551 
5552 PyDoc_STRVAR(os_listxattr__doc__,
5553 "listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5554 "--\n"
5555 "\n"
5556 "Return a list of extended attributes on path.\n"
5557 "\n"
5558 "path may be either None, a string, a path-like object, or an open file descriptor.\n"
5559 "if path is None, listxattr will examine the current directory.\n"
5560 "If follow_symlinks is False, and the last element of the path is a symbolic\n"
5561 "  link, listxattr will examine the symbolic link itself instead of the file\n"
5562 "  the link points to.");
5563 
5564 #define OS_LISTXATTR_METHODDEF    \
5565     {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
5566 
5567 static PyObject *
5568 os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
5569 
5570 static PyObject *
os_listxattr(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5571 os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5572 {
5573     PyObject *return_value = NULL;
5574     static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5575     static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
5576     path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5577     int follow_symlinks = 1;
5578 
5579     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5580         path_converter, &path, &follow_symlinks)) {
5581         goto exit;
5582     }
5583     return_value = os_listxattr_impl(module, &path, follow_symlinks);
5584 
5585 exit:
5586     /* Cleanup for path */
5587     path_cleanup(&path);
5588 
5589     return return_value;
5590 }
5591 
5592 #endif /* defined(USE_XATTRS) */
5593 
5594 PyDoc_STRVAR(os_urandom__doc__,
5595 "urandom($module, size, /)\n"
5596 "--\n"
5597 "\n"
5598 "Return a bytes object containing random bytes suitable for cryptographic use.");
5599 
5600 #define OS_URANDOM_METHODDEF    \
5601     {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
5602 
5603 static PyObject *
5604 os_urandom_impl(PyObject *module, Py_ssize_t size);
5605 
5606 static PyObject *
os_urandom(PyObject * module,PyObject * arg)5607 os_urandom(PyObject *module, PyObject *arg)
5608 {
5609     PyObject *return_value = NULL;
5610     Py_ssize_t size;
5611 
5612     if (!PyArg_Parse(arg, "n:urandom", &size)) {
5613         goto exit;
5614     }
5615     return_value = os_urandom_impl(module, size);
5616 
5617 exit:
5618     return return_value;
5619 }
5620 
5621 PyDoc_STRVAR(os_cpu_count__doc__,
5622 "cpu_count($module, /)\n"
5623 "--\n"
5624 "\n"
5625 "Return the number of CPUs in the system; return None if indeterminable.\n"
5626 "\n"
5627 "This number is not equivalent to the number of CPUs the current process can\n"
5628 "use.  The number of usable CPUs can be obtained with\n"
5629 "``len(os.sched_getaffinity(0))``");
5630 
5631 #define OS_CPU_COUNT_METHODDEF    \
5632     {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5633 
5634 static PyObject *
5635 os_cpu_count_impl(PyObject *module);
5636 
5637 static PyObject *
os_cpu_count(PyObject * module,PyObject * Py_UNUSED (ignored))5638 os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
5639 {
5640     return os_cpu_count_impl(module);
5641 }
5642 
5643 PyDoc_STRVAR(os_get_inheritable__doc__,
5644 "get_inheritable($module, fd, /)\n"
5645 "--\n"
5646 "\n"
5647 "Get the close-on-exe flag of the specified file descriptor.");
5648 
5649 #define OS_GET_INHERITABLE_METHODDEF    \
5650     {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
5651 
5652 static int
5653 os_get_inheritable_impl(PyObject *module, int fd);
5654 
5655 static PyObject *
os_get_inheritable(PyObject * module,PyObject * arg)5656 os_get_inheritable(PyObject *module, PyObject *arg)
5657 {
5658     PyObject *return_value = NULL;
5659     int fd;
5660     int _return_value;
5661 
5662     if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
5663         goto exit;
5664     }
5665     _return_value = os_get_inheritable_impl(module, fd);
5666     if ((_return_value == -1) && PyErr_Occurred()) {
5667         goto exit;
5668     }
5669     return_value = PyBool_FromLong((long)_return_value);
5670 
5671 exit:
5672     return return_value;
5673 }
5674 
5675 PyDoc_STRVAR(os_set_inheritable__doc__,
5676 "set_inheritable($module, fd, inheritable, /)\n"
5677 "--\n"
5678 "\n"
5679 "Set the inheritable flag of the specified file descriptor.");
5680 
5681 #define OS_SET_INHERITABLE_METHODDEF    \
5682     {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
5683 
5684 static PyObject *
5685 os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
5686 
5687 static PyObject *
os_set_inheritable(PyObject * module,PyObject * const * args,Py_ssize_t nargs)5688 os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5689 {
5690     PyObject *return_value = NULL;
5691     int fd;
5692     int inheritable;
5693 
5694     if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5695         &fd, &inheritable)) {
5696         goto exit;
5697     }
5698     return_value = os_set_inheritable_impl(module, fd, inheritable);
5699 
5700 exit:
5701     return return_value;
5702 }
5703 
5704 #if defined(MS_WINDOWS)
5705 
5706 PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5707 "get_handle_inheritable($module, handle, /)\n"
5708 "--\n"
5709 "\n"
5710 "Get the close-on-exe flag of the specified file descriptor.");
5711 
5712 #define OS_GET_HANDLE_INHERITABLE_METHODDEF    \
5713     {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
5714 
5715 static int
5716 os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
5717 
5718 static PyObject *
os_get_handle_inheritable(PyObject * module,PyObject * arg)5719 os_get_handle_inheritable(PyObject *module, PyObject *arg)
5720 {
5721     PyObject *return_value = NULL;
5722     intptr_t handle;
5723     int _return_value;
5724 
5725     if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
5726         goto exit;
5727     }
5728     _return_value = os_get_handle_inheritable_impl(module, handle);
5729     if ((_return_value == -1) && PyErr_Occurred()) {
5730         goto exit;
5731     }
5732     return_value = PyBool_FromLong((long)_return_value);
5733 
5734 exit:
5735     return return_value;
5736 }
5737 
5738 #endif /* defined(MS_WINDOWS) */
5739 
5740 #if defined(MS_WINDOWS)
5741 
5742 PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5743 "set_handle_inheritable($module, handle, inheritable, /)\n"
5744 "--\n"
5745 "\n"
5746 "Set the inheritable flag of the specified handle.");
5747 
5748 #define OS_SET_HANDLE_INHERITABLE_METHODDEF    \
5749     {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
5750 
5751 static PyObject *
5752 os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
5753                                int inheritable);
5754 
5755 static PyObject *
os_set_handle_inheritable(PyObject * module,PyObject * const * args,Py_ssize_t nargs)5756 os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5757 {
5758     PyObject *return_value = NULL;
5759     intptr_t handle;
5760     int inheritable;
5761 
5762     if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5763         &handle, &inheritable)) {
5764         goto exit;
5765     }
5766     return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5767 
5768 exit:
5769     return return_value;
5770 }
5771 
5772 #endif /* defined(MS_WINDOWS) */
5773 
5774 PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5775 "is_symlink($self, /)\n"
5776 "--\n"
5777 "\n"
5778 "Return True if the entry is a symbolic link; cached per entry.");
5779 
5780 #define OS_DIRENTRY_IS_SYMLINK_METHODDEF    \
5781     {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5782 
5783 static int
5784 os_DirEntry_is_symlink_impl(DirEntry *self);
5785 
5786 static PyObject *
os_DirEntry_is_symlink(DirEntry * self,PyObject * Py_UNUSED (ignored))5787 os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5788 {
5789     PyObject *return_value = NULL;
5790     int _return_value;
5791 
5792     _return_value = os_DirEntry_is_symlink_impl(self);
5793     if ((_return_value == -1) && PyErr_Occurred()) {
5794         goto exit;
5795     }
5796     return_value = PyBool_FromLong((long)_return_value);
5797 
5798 exit:
5799     return return_value;
5800 }
5801 
5802 PyDoc_STRVAR(os_DirEntry_stat__doc__,
5803 "stat($self, /, *, follow_symlinks=True)\n"
5804 "--\n"
5805 "\n"
5806 "Return stat_result object for the entry; cached per entry.");
5807 
5808 #define OS_DIRENTRY_STAT_METHODDEF    \
5809     {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
5810 
5811 static PyObject *
5812 os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5813 
5814 static PyObject *
os_DirEntry_stat(DirEntry * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5815 os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5816 {
5817     PyObject *return_value = NULL;
5818     static const char * const _keywords[] = {"follow_symlinks", NULL};
5819     static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5820     int follow_symlinks = 1;
5821 
5822     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5823         &follow_symlinks)) {
5824         goto exit;
5825     }
5826     return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5827 
5828 exit:
5829     return return_value;
5830 }
5831 
5832 PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5833 "is_dir($self, /, *, follow_symlinks=True)\n"
5834 "--\n"
5835 "\n"
5836 "Return True if the entry is a directory; cached per entry.");
5837 
5838 #define OS_DIRENTRY_IS_DIR_METHODDEF    \
5839     {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
5840 
5841 static int
5842 os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5843 
5844 static PyObject *
os_DirEntry_is_dir(DirEntry * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5845 os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5846 {
5847     PyObject *return_value = NULL;
5848     static const char * const _keywords[] = {"follow_symlinks", NULL};
5849     static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5850     int follow_symlinks = 1;
5851     int _return_value;
5852 
5853     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5854         &follow_symlinks)) {
5855         goto exit;
5856     }
5857     _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5858     if ((_return_value == -1) && PyErr_Occurred()) {
5859         goto exit;
5860     }
5861     return_value = PyBool_FromLong((long)_return_value);
5862 
5863 exit:
5864     return return_value;
5865 }
5866 
5867 PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5868 "is_file($self, /, *, follow_symlinks=True)\n"
5869 "--\n"
5870 "\n"
5871 "Return True if the entry is a file; cached per entry.");
5872 
5873 #define OS_DIRENTRY_IS_FILE_METHODDEF    \
5874     {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
5875 
5876 static int
5877 os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5878 
5879 static PyObject *
os_DirEntry_is_file(DirEntry * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5880 os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5881 {
5882     PyObject *return_value = NULL;
5883     static const char * const _keywords[] = {"follow_symlinks", NULL};
5884     static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5885     int follow_symlinks = 1;
5886     int _return_value;
5887 
5888     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5889         &follow_symlinks)) {
5890         goto exit;
5891     }
5892     _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5893     if ((_return_value == -1) && PyErr_Occurred()) {
5894         goto exit;
5895     }
5896     return_value = PyBool_FromLong((long)_return_value);
5897 
5898 exit:
5899     return return_value;
5900 }
5901 
5902 PyDoc_STRVAR(os_DirEntry_inode__doc__,
5903 "inode($self, /)\n"
5904 "--\n"
5905 "\n"
5906 "Return inode of the entry; cached per entry.");
5907 
5908 #define OS_DIRENTRY_INODE_METHODDEF    \
5909     {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5910 
5911 static PyObject *
5912 os_DirEntry_inode_impl(DirEntry *self);
5913 
5914 static PyObject *
os_DirEntry_inode(DirEntry * self,PyObject * Py_UNUSED (ignored))5915 os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5916 {
5917     return os_DirEntry_inode_impl(self);
5918 }
5919 
5920 PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5921 "__fspath__($self, /)\n"
5922 "--\n"
5923 "\n"
5924 "Returns the path for the entry.");
5925 
5926 #define OS_DIRENTRY___FSPATH___METHODDEF    \
5927     {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5928 
5929 static PyObject *
5930 os_DirEntry___fspath___impl(DirEntry *self);
5931 
5932 static PyObject *
os_DirEntry___fspath__(DirEntry * self,PyObject * Py_UNUSED (ignored))5933 os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5934 {
5935     return os_DirEntry___fspath___impl(self);
5936 }
5937 
5938 PyDoc_STRVAR(os_scandir__doc__,
5939 "scandir($module, /, path=None)\n"
5940 "--\n"
5941 "\n"
5942 "Return an iterator of DirEntry objects for given path.\n"
5943 "\n"
5944 "path can be specified as either str, bytes, or a path-like object.  If path\n"
5945 "is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5946 "all other circumstances they will be str.\n"
5947 "\n"
5948 "If path is None, uses the path=\'.\'.");
5949 
5950 #define OS_SCANDIR_METHODDEF    \
5951     {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
5952 
5953 static PyObject *
5954 os_scandir_impl(PyObject *module, path_t *path);
5955 
5956 static PyObject *
os_scandir(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5957 os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5958 {
5959     PyObject *return_value = NULL;
5960     static const char * const _keywords[] = {"path", NULL};
5961     static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
5962     path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
5963 
5964     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5965         path_converter, &path)) {
5966         goto exit;
5967     }
5968     return_value = os_scandir_impl(module, &path);
5969 
5970 exit:
5971     /* Cleanup for path */
5972     path_cleanup(&path);
5973 
5974     return return_value;
5975 }
5976 
5977 PyDoc_STRVAR(os_fspath__doc__,
5978 "fspath($module, /, path)\n"
5979 "--\n"
5980 "\n"
5981 "Return the file system path representation of the object.\n"
5982 "\n"
5983 "If the object is str or bytes, then allow it to pass through as-is. If the\n"
5984 "object defines __fspath__(), then return the result of that method. All other\n"
5985 "types raise a TypeError.");
5986 
5987 #define OS_FSPATH_METHODDEF    \
5988     {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
5989 
5990 static PyObject *
5991 os_fspath_impl(PyObject *module, PyObject *path);
5992 
5993 static PyObject *
os_fspath(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)5994 os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5995 {
5996     PyObject *return_value = NULL;
5997     static const char * const _keywords[] = {"path", NULL};
5998     static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
5999     PyObject *path;
6000 
6001     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
6002         &path)) {
6003         goto exit;
6004     }
6005     return_value = os_fspath_impl(module, path);
6006 
6007 exit:
6008     return return_value;
6009 }
6010 
6011 #if defined(HAVE_GETRANDOM_SYSCALL)
6012 
6013 PyDoc_STRVAR(os_getrandom__doc__,
6014 "getrandom($module, /, size, flags=0)\n"
6015 "--\n"
6016 "\n"
6017 "Obtain a series of random bytes.");
6018 
6019 #define OS_GETRANDOM_METHODDEF    \
6020     {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
6021 
6022 static PyObject *
6023 os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6024 
6025 static PyObject *
os_getrandom(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)6026 os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6027 {
6028     PyObject *return_value = NULL;
6029     static const char * const _keywords[] = {"size", "flags", NULL};
6030     static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6031     Py_ssize_t size;
6032     int flags = 0;
6033 
6034     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
6035         &size, &flags)) {
6036         goto exit;
6037     }
6038     return_value = os_getrandom_impl(module, size, flags);
6039 
6040 exit:
6041     return return_value;
6042 }
6043 
6044 #endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6045 
6046 #ifndef OS_TTYNAME_METHODDEF
6047     #define OS_TTYNAME_METHODDEF
6048 #endif /* !defined(OS_TTYNAME_METHODDEF) */
6049 
6050 #ifndef OS_CTERMID_METHODDEF
6051     #define OS_CTERMID_METHODDEF
6052 #endif /* !defined(OS_CTERMID_METHODDEF) */
6053 
6054 #ifndef OS_FCHDIR_METHODDEF
6055     #define OS_FCHDIR_METHODDEF
6056 #endif /* !defined(OS_FCHDIR_METHODDEF) */
6057 
6058 #ifndef OS_FCHMOD_METHODDEF
6059     #define OS_FCHMOD_METHODDEF
6060 #endif /* !defined(OS_FCHMOD_METHODDEF) */
6061 
6062 #ifndef OS_LCHMOD_METHODDEF
6063     #define OS_LCHMOD_METHODDEF
6064 #endif /* !defined(OS_LCHMOD_METHODDEF) */
6065 
6066 #ifndef OS_CHFLAGS_METHODDEF
6067     #define OS_CHFLAGS_METHODDEF
6068 #endif /* !defined(OS_CHFLAGS_METHODDEF) */
6069 
6070 #ifndef OS_LCHFLAGS_METHODDEF
6071     #define OS_LCHFLAGS_METHODDEF
6072 #endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6073 
6074 #ifndef OS_CHROOT_METHODDEF
6075     #define OS_CHROOT_METHODDEF
6076 #endif /* !defined(OS_CHROOT_METHODDEF) */
6077 
6078 #ifndef OS_FSYNC_METHODDEF
6079     #define OS_FSYNC_METHODDEF
6080 #endif /* !defined(OS_FSYNC_METHODDEF) */
6081 
6082 #ifndef OS_SYNC_METHODDEF
6083     #define OS_SYNC_METHODDEF
6084 #endif /* !defined(OS_SYNC_METHODDEF) */
6085 
6086 #ifndef OS_FDATASYNC_METHODDEF
6087     #define OS_FDATASYNC_METHODDEF
6088 #endif /* !defined(OS_FDATASYNC_METHODDEF) */
6089 
6090 #ifndef OS_CHOWN_METHODDEF
6091     #define OS_CHOWN_METHODDEF
6092 #endif /* !defined(OS_CHOWN_METHODDEF) */
6093 
6094 #ifndef OS_FCHOWN_METHODDEF
6095     #define OS_FCHOWN_METHODDEF
6096 #endif /* !defined(OS_FCHOWN_METHODDEF) */
6097 
6098 #ifndef OS_LCHOWN_METHODDEF
6099     #define OS_LCHOWN_METHODDEF
6100 #endif /* !defined(OS_LCHOWN_METHODDEF) */
6101 
6102 #ifndef OS_LINK_METHODDEF
6103     #define OS_LINK_METHODDEF
6104 #endif /* !defined(OS_LINK_METHODDEF) */
6105 
6106 #ifndef OS__GETFULLPATHNAME_METHODDEF
6107     #define OS__GETFULLPATHNAME_METHODDEF
6108 #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6109 
6110 #ifndef OS__GETFINALPATHNAME_METHODDEF
6111     #define OS__GETFINALPATHNAME_METHODDEF
6112 #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6113 
6114 #ifndef OS__ISDIR_METHODDEF
6115     #define OS__ISDIR_METHODDEF
6116 #endif /* !defined(OS__ISDIR_METHODDEF) */
6117 
6118 #ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6119     #define OS__GETVOLUMEPATHNAME_METHODDEF
6120 #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6121 
6122 #ifndef OS_NICE_METHODDEF
6123     #define OS_NICE_METHODDEF
6124 #endif /* !defined(OS_NICE_METHODDEF) */
6125 
6126 #ifndef OS_GETPRIORITY_METHODDEF
6127     #define OS_GETPRIORITY_METHODDEF
6128 #endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6129 
6130 #ifndef OS_SETPRIORITY_METHODDEF
6131     #define OS_SETPRIORITY_METHODDEF
6132 #endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6133 
6134 #ifndef OS_SYSTEM_METHODDEF
6135     #define OS_SYSTEM_METHODDEF
6136 #endif /* !defined(OS_SYSTEM_METHODDEF) */
6137 
6138 #ifndef OS_UNAME_METHODDEF
6139     #define OS_UNAME_METHODDEF
6140 #endif /* !defined(OS_UNAME_METHODDEF) */
6141 
6142 #ifndef OS_EXECV_METHODDEF
6143     #define OS_EXECV_METHODDEF
6144 #endif /* !defined(OS_EXECV_METHODDEF) */
6145 
6146 #ifndef OS_EXECVE_METHODDEF
6147     #define OS_EXECVE_METHODDEF
6148 #endif /* !defined(OS_EXECVE_METHODDEF) */
6149 
6150 #ifndef OS_SPAWNV_METHODDEF
6151     #define OS_SPAWNV_METHODDEF
6152 #endif /* !defined(OS_SPAWNV_METHODDEF) */
6153 
6154 #ifndef OS_SPAWNVE_METHODDEF
6155     #define OS_SPAWNVE_METHODDEF
6156 #endif /* !defined(OS_SPAWNVE_METHODDEF) */
6157 
6158 #ifndef OS_REGISTER_AT_FORK_METHODDEF
6159     #define OS_REGISTER_AT_FORK_METHODDEF
6160 #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6161 
6162 #ifndef OS_FORK1_METHODDEF
6163     #define OS_FORK1_METHODDEF
6164 #endif /* !defined(OS_FORK1_METHODDEF) */
6165 
6166 #ifndef OS_FORK_METHODDEF
6167     #define OS_FORK_METHODDEF
6168 #endif /* !defined(OS_FORK_METHODDEF) */
6169 
6170 #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6171     #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6172 #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6173 
6174 #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6175     #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6176 #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6177 
6178 #ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6179     #define OS_SCHED_GETSCHEDULER_METHODDEF
6180 #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6181 
6182 #ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6183     #define OS_SCHED_SETSCHEDULER_METHODDEF
6184 #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6185 
6186 #ifndef OS_SCHED_GETPARAM_METHODDEF
6187     #define OS_SCHED_GETPARAM_METHODDEF
6188 #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6189 
6190 #ifndef OS_SCHED_SETPARAM_METHODDEF
6191     #define OS_SCHED_SETPARAM_METHODDEF
6192 #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6193 
6194 #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6195     #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6196 #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6197 
6198 #ifndef OS_SCHED_YIELD_METHODDEF
6199     #define OS_SCHED_YIELD_METHODDEF
6200 #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6201 
6202 #ifndef OS_SCHED_SETAFFINITY_METHODDEF
6203     #define OS_SCHED_SETAFFINITY_METHODDEF
6204 #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6205 
6206 #ifndef OS_SCHED_GETAFFINITY_METHODDEF
6207     #define OS_SCHED_GETAFFINITY_METHODDEF
6208 #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6209 
6210 #ifndef OS_OPENPTY_METHODDEF
6211     #define OS_OPENPTY_METHODDEF
6212 #endif /* !defined(OS_OPENPTY_METHODDEF) */
6213 
6214 #ifndef OS_FORKPTY_METHODDEF
6215     #define OS_FORKPTY_METHODDEF
6216 #endif /* !defined(OS_FORKPTY_METHODDEF) */
6217 
6218 #ifndef OS_GETEGID_METHODDEF
6219     #define OS_GETEGID_METHODDEF
6220 #endif /* !defined(OS_GETEGID_METHODDEF) */
6221 
6222 #ifndef OS_GETEUID_METHODDEF
6223     #define OS_GETEUID_METHODDEF
6224 #endif /* !defined(OS_GETEUID_METHODDEF) */
6225 
6226 #ifndef OS_GETGID_METHODDEF
6227     #define OS_GETGID_METHODDEF
6228 #endif /* !defined(OS_GETGID_METHODDEF) */
6229 
6230 #ifndef OS_GETPID_METHODDEF
6231     #define OS_GETPID_METHODDEF
6232 #endif /* !defined(OS_GETPID_METHODDEF) */
6233 
6234 #ifndef OS_GETGROUPS_METHODDEF
6235     #define OS_GETGROUPS_METHODDEF
6236 #endif /* !defined(OS_GETGROUPS_METHODDEF) */
6237 
6238 #ifndef OS_GETPGID_METHODDEF
6239     #define OS_GETPGID_METHODDEF
6240 #endif /* !defined(OS_GETPGID_METHODDEF) */
6241 
6242 #ifndef OS_GETPGRP_METHODDEF
6243     #define OS_GETPGRP_METHODDEF
6244 #endif /* !defined(OS_GETPGRP_METHODDEF) */
6245 
6246 #ifndef OS_SETPGRP_METHODDEF
6247     #define OS_SETPGRP_METHODDEF
6248 #endif /* !defined(OS_SETPGRP_METHODDEF) */
6249 
6250 #ifndef OS_GETPPID_METHODDEF
6251     #define OS_GETPPID_METHODDEF
6252 #endif /* !defined(OS_GETPPID_METHODDEF) */
6253 
6254 #ifndef OS_GETLOGIN_METHODDEF
6255     #define OS_GETLOGIN_METHODDEF
6256 #endif /* !defined(OS_GETLOGIN_METHODDEF) */
6257 
6258 #ifndef OS_GETUID_METHODDEF
6259     #define OS_GETUID_METHODDEF
6260 #endif /* !defined(OS_GETUID_METHODDEF) */
6261 
6262 #ifndef OS_KILL_METHODDEF
6263     #define OS_KILL_METHODDEF
6264 #endif /* !defined(OS_KILL_METHODDEF) */
6265 
6266 #ifndef OS_KILLPG_METHODDEF
6267     #define OS_KILLPG_METHODDEF
6268 #endif /* !defined(OS_KILLPG_METHODDEF) */
6269 
6270 #ifndef OS_PLOCK_METHODDEF
6271     #define OS_PLOCK_METHODDEF
6272 #endif /* !defined(OS_PLOCK_METHODDEF) */
6273 
6274 #ifndef OS_SETUID_METHODDEF
6275     #define OS_SETUID_METHODDEF
6276 #endif /* !defined(OS_SETUID_METHODDEF) */
6277 
6278 #ifndef OS_SETEUID_METHODDEF
6279     #define OS_SETEUID_METHODDEF
6280 #endif /* !defined(OS_SETEUID_METHODDEF) */
6281 
6282 #ifndef OS_SETEGID_METHODDEF
6283     #define OS_SETEGID_METHODDEF
6284 #endif /* !defined(OS_SETEGID_METHODDEF) */
6285 
6286 #ifndef OS_SETREUID_METHODDEF
6287     #define OS_SETREUID_METHODDEF
6288 #endif /* !defined(OS_SETREUID_METHODDEF) */
6289 
6290 #ifndef OS_SETREGID_METHODDEF
6291     #define OS_SETREGID_METHODDEF
6292 #endif /* !defined(OS_SETREGID_METHODDEF) */
6293 
6294 #ifndef OS_SETGID_METHODDEF
6295     #define OS_SETGID_METHODDEF
6296 #endif /* !defined(OS_SETGID_METHODDEF) */
6297 
6298 #ifndef OS_SETGROUPS_METHODDEF
6299     #define OS_SETGROUPS_METHODDEF
6300 #endif /* !defined(OS_SETGROUPS_METHODDEF) */
6301 
6302 #ifndef OS_WAIT3_METHODDEF
6303     #define OS_WAIT3_METHODDEF
6304 #endif /* !defined(OS_WAIT3_METHODDEF) */
6305 
6306 #ifndef OS_WAIT4_METHODDEF
6307     #define OS_WAIT4_METHODDEF
6308 #endif /* !defined(OS_WAIT4_METHODDEF) */
6309 
6310 #ifndef OS_WAITID_METHODDEF
6311     #define OS_WAITID_METHODDEF
6312 #endif /* !defined(OS_WAITID_METHODDEF) */
6313 
6314 #ifndef OS_WAITPID_METHODDEF
6315     #define OS_WAITPID_METHODDEF
6316 #endif /* !defined(OS_WAITPID_METHODDEF) */
6317 
6318 #ifndef OS_WAIT_METHODDEF
6319     #define OS_WAIT_METHODDEF
6320 #endif /* !defined(OS_WAIT_METHODDEF) */
6321 
6322 #ifndef OS_SYMLINK_METHODDEF
6323     #define OS_SYMLINK_METHODDEF
6324 #endif /* !defined(OS_SYMLINK_METHODDEF) */
6325 
6326 #ifndef OS_TIMES_METHODDEF
6327     #define OS_TIMES_METHODDEF
6328 #endif /* !defined(OS_TIMES_METHODDEF) */
6329 
6330 #ifndef OS_GETSID_METHODDEF
6331     #define OS_GETSID_METHODDEF
6332 #endif /* !defined(OS_GETSID_METHODDEF) */
6333 
6334 #ifndef OS_SETSID_METHODDEF
6335     #define OS_SETSID_METHODDEF
6336 #endif /* !defined(OS_SETSID_METHODDEF) */
6337 
6338 #ifndef OS_SETPGID_METHODDEF
6339     #define OS_SETPGID_METHODDEF
6340 #endif /* !defined(OS_SETPGID_METHODDEF) */
6341 
6342 #ifndef OS_TCGETPGRP_METHODDEF
6343     #define OS_TCGETPGRP_METHODDEF
6344 #endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6345 
6346 #ifndef OS_TCSETPGRP_METHODDEF
6347     #define OS_TCSETPGRP_METHODDEF
6348 #endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6349 
6350 #ifndef OS_LOCKF_METHODDEF
6351     #define OS_LOCKF_METHODDEF
6352 #endif /* !defined(OS_LOCKF_METHODDEF) */
6353 
6354 #ifndef OS_READV_METHODDEF
6355     #define OS_READV_METHODDEF
6356 #endif /* !defined(OS_READV_METHODDEF) */
6357 
6358 #ifndef OS_PREAD_METHODDEF
6359     #define OS_PREAD_METHODDEF
6360 #endif /* !defined(OS_PREAD_METHODDEF) */
6361 
6362 #ifndef OS_PREADV_METHODDEF
6363     #define OS_PREADV_METHODDEF
6364 #endif /* !defined(OS_PREADV_METHODDEF) */
6365 
6366 #ifndef OS_PIPE_METHODDEF
6367     #define OS_PIPE_METHODDEF
6368 #endif /* !defined(OS_PIPE_METHODDEF) */
6369 
6370 #ifndef OS_PIPE2_METHODDEF
6371     #define OS_PIPE2_METHODDEF
6372 #endif /* !defined(OS_PIPE2_METHODDEF) */
6373 
6374 #ifndef OS_WRITEV_METHODDEF
6375     #define OS_WRITEV_METHODDEF
6376 #endif /* !defined(OS_WRITEV_METHODDEF) */
6377 
6378 #ifndef OS_PWRITE_METHODDEF
6379     #define OS_PWRITE_METHODDEF
6380 #endif /* !defined(OS_PWRITE_METHODDEF) */
6381 
6382 #ifndef OS_PWRITEV_METHODDEF
6383     #define OS_PWRITEV_METHODDEF
6384 #endif /* !defined(OS_PWRITEV_METHODDEF) */
6385 
6386 #ifndef OS_MKFIFO_METHODDEF
6387     #define OS_MKFIFO_METHODDEF
6388 #endif /* !defined(OS_MKFIFO_METHODDEF) */
6389 
6390 #ifndef OS_MKNOD_METHODDEF
6391     #define OS_MKNOD_METHODDEF
6392 #endif /* !defined(OS_MKNOD_METHODDEF) */
6393 
6394 #ifndef OS_MAJOR_METHODDEF
6395     #define OS_MAJOR_METHODDEF
6396 #endif /* !defined(OS_MAJOR_METHODDEF) */
6397 
6398 #ifndef OS_MINOR_METHODDEF
6399     #define OS_MINOR_METHODDEF
6400 #endif /* !defined(OS_MINOR_METHODDEF) */
6401 
6402 #ifndef OS_MAKEDEV_METHODDEF
6403     #define OS_MAKEDEV_METHODDEF
6404 #endif /* !defined(OS_MAKEDEV_METHODDEF) */
6405 
6406 #ifndef OS_FTRUNCATE_METHODDEF
6407     #define OS_FTRUNCATE_METHODDEF
6408 #endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6409 
6410 #ifndef OS_TRUNCATE_METHODDEF
6411     #define OS_TRUNCATE_METHODDEF
6412 #endif /* !defined(OS_TRUNCATE_METHODDEF) */
6413 
6414 #ifndef OS_POSIX_FALLOCATE_METHODDEF
6415     #define OS_POSIX_FALLOCATE_METHODDEF
6416 #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6417 
6418 #ifndef OS_POSIX_FADVISE_METHODDEF
6419     #define OS_POSIX_FADVISE_METHODDEF
6420 #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6421 
6422 #ifndef OS_PUTENV_METHODDEF
6423     #define OS_PUTENV_METHODDEF
6424 #endif /* !defined(OS_PUTENV_METHODDEF) */
6425 
6426 #ifndef OS_UNSETENV_METHODDEF
6427     #define OS_UNSETENV_METHODDEF
6428 #endif /* !defined(OS_UNSETENV_METHODDEF) */
6429 
6430 #ifndef OS_WCOREDUMP_METHODDEF
6431     #define OS_WCOREDUMP_METHODDEF
6432 #endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6433 
6434 #ifndef OS_WIFCONTINUED_METHODDEF
6435     #define OS_WIFCONTINUED_METHODDEF
6436 #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6437 
6438 #ifndef OS_WIFSTOPPED_METHODDEF
6439     #define OS_WIFSTOPPED_METHODDEF
6440 #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6441 
6442 #ifndef OS_WIFSIGNALED_METHODDEF
6443     #define OS_WIFSIGNALED_METHODDEF
6444 #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6445 
6446 #ifndef OS_WIFEXITED_METHODDEF
6447     #define OS_WIFEXITED_METHODDEF
6448 #endif /* !defined(OS_WIFEXITED_METHODDEF) */
6449 
6450 #ifndef OS_WEXITSTATUS_METHODDEF
6451     #define OS_WEXITSTATUS_METHODDEF
6452 #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6453 
6454 #ifndef OS_WTERMSIG_METHODDEF
6455     #define OS_WTERMSIG_METHODDEF
6456 #endif /* !defined(OS_WTERMSIG_METHODDEF) */
6457 
6458 #ifndef OS_WSTOPSIG_METHODDEF
6459     #define OS_WSTOPSIG_METHODDEF
6460 #endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6461 
6462 #ifndef OS_FSTATVFS_METHODDEF
6463     #define OS_FSTATVFS_METHODDEF
6464 #endif /* !defined(OS_FSTATVFS_METHODDEF) */
6465 
6466 #ifndef OS_STATVFS_METHODDEF
6467     #define OS_STATVFS_METHODDEF
6468 #endif /* !defined(OS_STATVFS_METHODDEF) */
6469 
6470 #ifndef OS__GETDISKUSAGE_METHODDEF
6471     #define OS__GETDISKUSAGE_METHODDEF
6472 #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6473 
6474 #ifndef OS_FPATHCONF_METHODDEF
6475     #define OS_FPATHCONF_METHODDEF
6476 #endif /* !defined(OS_FPATHCONF_METHODDEF) */
6477 
6478 #ifndef OS_PATHCONF_METHODDEF
6479     #define OS_PATHCONF_METHODDEF
6480 #endif /* !defined(OS_PATHCONF_METHODDEF) */
6481 
6482 #ifndef OS_CONFSTR_METHODDEF
6483     #define OS_CONFSTR_METHODDEF
6484 #endif /* !defined(OS_CONFSTR_METHODDEF) */
6485 
6486 #ifndef OS_SYSCONF_METHODDEF
6487     #define OS_SYSCONF_METHODDEF
6488 #endif /* !defined(OS_SYSCONF_METHODDEF) */
6489 
6490 #ifndef OS_STARTFILE_METHODDEF
6491     #define OS_STARTFILE_METHODDEF
6492 #endif /* !defined(OS_STARTFILE_METHODDEF) */
6493 
6494 #ifndef OS_GETLOADAVG_METHODDEF
6495     #define OS_GETLOADAVG_METHODDEF
6496 #endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6497 
6498 #ifndef OS_SETRESUID_METHODDEF
6499     #define OS_SETRESUID_METHODDEF
6500 #endif /* !defined(OS_SETRESUID_METHODDEF) */
6501 
6502 #ifndef OS_SETRESGID_METHODDEF
6503     #define OS_SETRESGID_METHODDEF
6504 #endif /* !defined(OS_SETRESGID_METHODDEF) */
6505 
6506 #ifndef OS_GETRESUID_METHODDEF
6507     #define OS_GETRESUID_METHODDEF
6508 #endif /* !defined(OS_GETRESUID_METHODDEF) */
6509 
6510 #ifndef OS_GETRESGID_METHODDEF
6511     #define OS_GETRESGID_METHODDEF
6512 #endif /* !defined(OS_GETRESGID_METHODDEF) */
6513 
6514 #ifndef OS_GETXATTR_METHODDEF
6515     #define OS_GETXATTR_METHODDEF
6516 #endif /* !defined(OS_GETXATTR_METHODDEF) */
6517 
6518 #ifndef OS_SETXATTR_METHODDEF
6519     #define OS_SETXATTR_METHODDEF
6520 #endif /* !defined(OS_SETXATTR_METHODDEF) */
6521 
6522 #ifndef OS_REMOVEXATTR_METHODDEF
6523     #define OS_REMOVEXATTR_METHODDEF
6524 #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6525 
6526 #ifndef OS_LISTXATTR_METHODDEF
6527     #define OS_LISTXATTR_METHODDEF
6528 #endif /* !defined(OS_LISTXATTR_METHODDEF) */
6529 
6530 #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6531     #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6532 #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6533 
6534 #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6535     #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6536 #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
6537 
6538 #ifndef OS_GETRANDOM_METHODDEF
6539     #define OS_GETRANDOM_METHODDEF
6540 #endif /* !defined(OS_GETRANDOM_METHODDEF) */
6541 /*[clinic end generated code: output=32c935671ee020d5 input=a9049054013a1b77]*/
6542