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