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