blob: 33621d80d9f8404006805a5e6fcabf461c2084ce [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 Storchaka5dee6552016-06-09 16:16:06 +030046 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030047 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030048 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030049 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
50
51exit:
52 /* Cleanup for path */
53 path_cleanup(&path);
54
55 return return_value;
56}
57
58PyDoc_STRVAR(os_lstat__doc__,
59"lstat($module, /, path, *, dir_fd=None)\n"
60"--\n"
61"\n"
62"Perform a stat system call on the given path, without following symbolic links.\n"
63"\n"
64"Like stat(), but do not follow symbolic links.\n"
65"Equivalent to stat(path, follow_symlinks=False).");
66
67#define OS_LSTAT_METHODDEF \
68 {"lstat", (PyCFunction)os_lstat, METH_VARARGS|METH_KEYWORDS, os_lstat__doc__},
69
70static PyObject *
71os_lstat_impl(PyModuleDef *module, path_t *path, int dir_fd);
72
73static PyObject *
74os_lstat(PyModuleDef *module, PyObject *args, PyObject *kwargs)
75{
76 PyObject *return_value = NULL;
77 static char *_keywords[] = {"path", "dir_fd", NULL};
78 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
79 int dir_fd = DEFAULT_DIR_FD;
80
Serhiy Storchaka247789c2015-04-24 00:40:51 +030081 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:lstat", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030082 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030083 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030085 return_value = os_lstat_impl(module, &path, dir_fd);
86
87exit:
88 /* Cleanup for path */
89 path_cleanup(&path);
90
91 return return_value;
92}
93
94PyDoc_STRVAR(os_access__doc__,
95"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
96" follow_symlinks=True)\n"
97"--\n"
98"\n"
99"Use the real uid/gid to test for access to a path.\n"
100"\n"
101" path\n"
102" Path to be tested; can be string, bytes, or open-file-descriptor int.\n"
103" mode\n"
104" Operating-system mode bitfield. Can be F_OK to test existence,\n"
105" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
106" dir_fd\n"
107" If not None, it should be a file descriptor open to a directory,\n"
108" and path should be relative; path will then be relative to that\n"
109" directory.\n"
110" effective_ids\n"
111" If True, access will use the effective uid/gid instead of\n"
112" the real uid/gid.\n"
113" follow_symlinks\n"
114" If False, and the last element of the path is a symbolic link,\n"
115" access will examine the symbolic link itself instead of the file\n"
116" the link points to.\n"
117"\n"
118"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
119" on your platform. If they are unavailable, using them will raise a\n"
120" NotImplementedError.\n"
121"\n"
122"Note that most operations will use the effective uid/gid, therefore this\n"
123" routine can be used in a suid/sgid environment to test if the invoking user\n"
124" has the specified access to the path.");
125
126#define OS_ACCESS_METHODDEF \
127 {"access", (PyCFunction)os_access, METH_VARARGS|METH_KEYWORDS, os_access__doc__},
128
129static int
Larry Hastings89964c42015-04-14 18:07:59 -0400130os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd,
131 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300132
133static PyObject *
134os_access(PyModuleDef *module, PyObject *args, PyObject *kwargs)
135{
136 PyObject *return_value = NULL;
137 static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
138 path_t path = PATH_T_INITIALIZE("access", "path", 0, 1);
139 int mode;
140 int dir_fd = DEFAULT_DIR_FD;
141 int effective_ids = 0;
142 int follow_symlinks = 1;
143 int _return_value;
144
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300145 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|$O&pp:access", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300146 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300147 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300148 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300149 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300150 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300151 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300152 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300153 return_value = PyBool_FromLong((long)_return_value);
154
155exit:
156 /* Cleanup for path */
157 path_cleanup(&path);
158
159 return return_value;
160}
161
162#if defined(HAVE_TTYNAME)
163
164PyDoc_STRVAR(os_ttyname__doc__,
165"ttyname($module, fd, /)\n"
166"--\n"
167"\n"
168"Return the name of the terminal device connected to \'fd\'.\n"
169"\n"
170" fd\n"
171" Integer file descriptor handle.");
172
173#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300174 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300175
176static char *
177os_ttyname_impl(PyModuleDef *module, int fd);
178
179static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300180os_ttyname(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181{
182 PyObject *return_value = NULL;
183 int fd;
184 char *_return_value;
185
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300186 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300187 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300188 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300189 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300190 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300191 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300193 return_value = PyUnicode_DecodeFSDefault(_return_value);
194
195exit:
196 return return_value;
197}
198
199#endif /* defined(HAVE_TTYNAME) */
200
201#if defined(HAVE_CTERMID)
202
203PyDoc_STRVAR(os_ctermid__doc__,
204"ctermid($module, /)\n"
205"--\n"
206"\n"
207"Return the name of the controlling terminal for this process.");
208
209#define OS_CTERMID_METHODDEF \
210 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
211
212static PyObject *
213os_ctermid_impl(PyModuleDef *module);
214
215static PyObject *
216os_ctermid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
217{
218 return os_ctermid_impl(module);
219}
220
221#endif /* defined(HAVE_CTERMID) */
222
223PyDoc_STRVAR(os_chdir__doc__,
224"chdir($module, /, path)\n"
225"--\n"
226"\n"
227"Change the current working directory to the specified path.\n"
228"\n"
229"path may always be specified as a string.\n"
230"On some platforms, path may also be specified as an open file descriptor.\n"
231" If this functionality is unavailable, using it raises an exception.");
232
233#define OS_CHDIR_METHODDEF \
234 {"chdir", (PyCFunction)os_chdir, METH_VARARGS|METH_KEYWORDS, os_chdir__doc__},
235
236static PyObject *
237os_chdir_impl(PyModuleDef *module, path_t *path);
238
239static PyObject *
240os_chdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
241{
242 PyObject *return_value = NULL;
243 static char *_keywords[] = {"path", NULL};
244 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
245
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300246 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:chdir", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300247 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300248 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300249 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300250 return_value = os_chdir_impl(module, &path);
251
252exit:
253 /* Cleanup for path */
254 path_cleanup(&path);
255
256 return return_value;
257}
258
259#if defined(HAVE_FCHDIR)
260
261PyDoc_STRVAR(os_fchdir__doc__,
262"fchdir($module, /, fd)\n"
263"--\n"
264"\n"
265"Change to the directory of the given file descriptor.\n"
266"\n"
267"fd must be opened on a directory, not a file.\n"
268"Equivalent to os.chdir(fd).");
269
270#define OS_FCHDIR_METHODDEF \
271 {"fchdir", (PyCFunction)os_fchdir, METH_VARARGS|METH_KEYWORDS, os_fchdir__doc__},
272
273static PyObject *
274os_fchdir_impl(PyModuleDef *module, int fd);
275
276static PyObject *
277os_fchdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
278{
279 PyObject *return_value = NULL;
280 static char *_keywords[] = {"fd", NULL};
281 int fd;
282
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300283 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:fchdir", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300284 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300285 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300286 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300287 return_value = os_fchdir_impl(module, fd);
288
289exit:
290 return return_value;
291}
292
293#endif /* defined(HAVE_FCHDIR) */
294
295PyDoc_STRVAR(os_chmod__doc__,
296"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
297"--\n"
298"\n"
299"Change the access permissions of a file.\n"
300"\n"
301" path\n"
302" Path to be modified. May always be specified as a str or bytes.\n"
303" On some platforms, path may also be specified as an open file descriptor.\n"
304" If this functionality is unavailable, using it raises an exception.\n"
305" mode\n"
306" Operating-system mode bitfield.\n"
307" dir_fd\n"
308" If not None, it should be a file descriptor open to a directory,\n"
309" and path should be relative; path will then be relative to that\n"
310" directory.\n"
311" follow_symlinks\n"
312" If False, and the last element of the path is a symbolic link,\n"
313" chmod will modify the symbolic link itself instead of the file\n"
314" the link points to.\n"
315"\n"
316"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
317" an open file descriptor.\n"
318"dir_fd and follow_symlinks may not be implemented on your platform.\n"
319" If they are unavailable, using them will raise a NotImplementedError.");
320
321#define OS_CHMOD_METHODDEF \
322 {"chmod", (PyCFunction)os_chmod, METH_VARARGS|METH_KEYWORDS, os_chmod__doc__},
323
324static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400325os_chmod_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd,
326 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300327
328static PyObject *
329os_chmod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
330{
331 PyObject *return_value = NULL;
332 static char *_keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
333 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
334 int mode;
335 int dir_fd = DEFAULT_DIR_FD;
336 int follow_symlinks = 1;
337
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300338 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|$O&p:chmod", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300339 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300340 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300341 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300342 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
343
344exit:
345 /* Cleanup for path */
346 path_cleanup(&path);
347
348 return return_value;
349}
350
351#if defined(HAVE_FCHMOD)
352
353PyDoc_STRVAR(os_fchmod__doc__,
354"fchmod($module, /, fd, mode)\n"
355"--\n"
356"\n"
357"Change the access permissions of the file given by file descriptor fd.\n"
358"\n"
359"Equivalent to os.chmod(fd, mode).");
360
361#define OS_FCHMOD_METHODDEF \
362 {"fchmod", (PyCFunction)os_fchmod, METH_VARARGS|METH_KEYWORDS, os_fchmod__doc__},
363
364static PyObject *
365os_fchmod_impl(PyModuleDef *module, int fd, int mode);
366
367static PyObject *
368os_fchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
369{
370 PyObject *return_value = NULL;
371 static char *_keywords[] = {"fd", "mode", NULL};
372 int fd;
373 int mode;
374
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300375 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:fchmod", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300376 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300377 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300378 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 return_value = os_fchmod_impl(module, fd, mode);
380
381exit:
382 return return_value;
383}
384
385#endif /* defined(HAVE_FCHMOD) */
386
387#if defined(HAVE_LCHMOD)
388
389PyDoc_STRVAR(os_lchmod__doc__,
390"lchmod($module, /, path, mode)\n"
391"--\n"
392"\n"
393"Change the access permissions of a file, without following symbolic links.\n"
394"\n"
395"If path is a symlink, this affects the link itself rather than the target.\n"
396"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
397
398#define OS_LCHMOD_METHODDEF \
399 {"lchmod", (PyCFunction)os_lchmod, METH_VARARGS|METH_KEYWORDS, os_lchmod__doc__},
400
401static PyObject *
402os_lchmod_impl(PyModuleDef *module, path_t *path, int mode);
403
404static PyObject *
405os_lchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
406{
407 PyObject *return_value = NULL;
408 static char *_keywords[] = {"path", "mode", NULL};
409 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
410 int mode;
411
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300412 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i:lchmod", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300413 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300414 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300415 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300416 return_value = os_lchmod_impl(module, &path, mode);
417
418exit:
419 /* Cleanup for path */
420 path_cleanup(&path);
421
422 return return_value;
423}
424
425#endif /* defined(HAVE_LCHMOD) */
426
427#if defined(HAVE_CHFLAGS)
428
429PyDoc_STRVAR(os_chflags__doc__,
430"chflags($module, /, path, flags, follow_symlinks=True)\n"
431"--\n"
432"\n"
433"Set file flags.\n"
434"\n"
435"If follow_symlinks is False, and the last element of the path is a symbolic\n"
436" link, chflags will change flags on the symbolic link itself instead of the\n"
437" file the link points to.\n"
438"follow_symlinks may not be implemented on your platform. If it is\n"
439"unavailable, using it will raise a NotImplementedError.");
440
441#define OS_CHFLAGS_METHODDEF \
442 {"chflags", (PyCFunction)os_chflags, METH_VARARGS|METH_KEYWORDS, os_chflags__doc__},
443
444static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400445os_chflags_impl(PyModuleDef *module, path_t *path, unsigned long flags,
446 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300447
448static PyObject *
449os_chflags(PyModuleDef *module, PyObject *args, PyObject *kwargs)
450{
451 PyObject *return_value = NULL;
452 static char *_keywords[] = {"path", "flags", "follow_symlinks", NULL};
453 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
454 unsigned long flags;
455 int follow_symlinks = 1;
456
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300457 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&k|p:chflags", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300458 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300459 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300460 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300461 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
462
463exit:
464 /* Cleanup for path */
465 path_cleanup(&path);
466
467 return return_value;
468}
469
470#endif /* defined(HAVE_CHFLAGS) */
471
472#if defined(HAVE_LCHFLAGS)
473
474PyDoc_STRVAR(os_lchflags__doc__,
475"lchflags($module, /, path, flags)\n"
476"--\n"
477"\n"
478"Set file flags.\n"
479"\n"
480"This function will not follow symbolic links.\n"
481"Equivalent to chflags(path, flags, follow_symlinks=False).");
482
483#define OS_LCHFLAGS_METHODDEF \
484 {"lchflags", (PyCFunction)os_lchflags, METH_VARARGS|METH_KEYWORDS, os_lchflags__doc__},
485
486static PyObject *
487os_lchflags_impl(PyModuleDef *module, path_t *path, unsigned long flags);
488
489static PyObject *
490os_lchflags(PyModuleDef *module, PyObject *args, PyObject *kwargs)
491{
492 PyObject *return_value = NULL;
493 static char *_keywords[] = {"path", "flags", NULL};
494 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
495 unsigned long flags;
496
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300497 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&k:lchflags", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300498 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300499 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300500 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300501 return_value = os_lchflags_impl(module, &path, flags);
502
503exit:
504 /* Cleanup for path */
505 path_cleanup(&path);
506
507 return return_value;
508}
509
510#endif /* defined(HAVE_LCHFLAGS) */
511
512#if defined(HAVE_CHROOT)
513
514PyDoc_STRVAR(os_chroot__doc__,
515"chroot($module, /, path)\n"
516"--\n"
517"\n"
518"Change root directory to path.");
519
520#define OS_CHROOT_METHODDEF \
521 {"chroot", (PyCFunction)os_chroot, METH_VARARGS|METH_KEYWORDS, os_chroot__doc__},
522
523static PyObject *
524os_chroot_impl(PyModuleDef *module, path_t *path);
525
526static PyObject *
527os_chroot(PyModuleDef *module, PyObject *args, PyObject *kwargs)
528{
529 PyObject *return_value = NULL;
530 static char *_keywords[] = {"path", NULL};
531 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
532
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300533 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:chroot", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300534 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300536 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537 return_value = os_chroot_impl(module, &path);
538
539exit:
540 /* Cleanup for path */
541 path_cleanup(&path);
542
543 return return_value;
544}
545
546#endif /* defined(HAVE_CHROOT) */
547
548#if defined(HAVE_FSYNC)
549
550PyDoc_STRVAR(os_fsync__doc__,
551"fsync($module, /, fd)\n"
552"--\n"
553"\n"
554"Force write of fd to disk.");
555
556#define OS_FSYNC_METHODDEF \
557 {"fsync", (PyCFunction)os_fsync, METH_VARARGS|METH_KEYWORDS, os_fsync__doc__},
558
559static PyObject *
560os_fsync_impl(PyModuleDef *module, int fd);
561
562static PyObject *
563os_fsync(PyModuleDef *module, PyObject *args, PyObject *kwargs)
564{
565 PyObject *return_value = NULL;
566 static char *_keywords[] = {"fd", NULL};
567 int fd;
568
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300569 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:fsync", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300570 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300571 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300572 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300573 return_value = os_fsync_impl(module, fd);
574
575exit:
576 return return_value;
577}
578
579#endif /* defined(HAVE_FSYNC) */
580
581#if defined(HAVE_SYNC)
582
583PyDoc_STRVAR(os_sync__doc__,
584"sync($module, /)\n"
585"--\n"
586"\n"
587"Force write of everything to disk.");
588
589#define OS_SYNC_METHODDEF \
590 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
591
592static PyObject *
593os_sync_impl(PyModuleDef *module);
594
595static PyObject *
596os_sync(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
597{
598 return os_sync_impl(module);
599}
600
601#endif /* defined(HAVE_SYNC) */
602
603#if defined(HAVE_FDATASYNC)
604
605PyDoc_STRVAR(os_fdatasync__doc__,
606"fdatasync($module, /, fd)\n"
607"--\n"
608"\n"
609"Force write of fd to disk without forcing update of metadata.");
610
611#define OS_FDATASYNC_METHODDEF \
612 {"fdatasync", (PyCFunction)os_fdatasync, METH_VARARGS|METH_KEYWORDS, os_fdatasync__doc__},
613
614static PyObject *
615os_fdatasync_impl(PyModuleDef *module, int fd);
616
617static PyObject *
618os_fdatasync(PyModuleDef *module, PyObject *args, PyObject *kwargs)
619{
620 PyObject *return_value = NULL;
621 static char *_keywords[] = {"fd", NULL};
622 int fd;
623
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300624 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:fdatasync", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300625 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300626 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300627 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628 return_value = os_fdatasync_impl(module, fd);
629
630exit:
631 return return_value;
632}
633
634#endif /* defined(HAVE_FDATASYNC) */
635
636#if defined(HAVE_CHOWN)
637
638PyDoc_STRVAR(os_chown__doc__,
639"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
640"--\n"
641"\n"
642"Change the owner and group id of path to the numeric uid and gid.\\\n"
643"\n"
644" path\n"
645" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
646" dir_fd\n"
647" If not None, it should be a file descriptor open to a directory,\n"
648" and path should be relative; path will then be relative to that\n"
649" directory.\n"
650" follow_symlinks\n"
651" If False, and the last element of the path is a symbolic link,\n"
652" stat will examine the symbolic link itself instead of the file\n"
653" the link points to.\n"
654"\n"
655"path may always be specified as a string.\n"
656"On some platforms, path may also be specified as an open file descriptor.\n"
657" If this functionality is unavailable, using it raises an exception.\n"
658"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
659" and path should be relative; path will then be relative to that directory.\n"
660"If follow_symlinks is False, and the last element of the path is a symbolic\n"
661" link, chown will modify the symbolic link itself instead of the file the\n"
662" link points to.\n"
663"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
664" an open file descriptor.\n"
665"dir_fd and follow_symlinks may not be implemented on your platform.\n"
666" If they are unavailable, using them will raise a NotImplementedError.");
667
668#define OS_CHOWN_METHODDEF \
669 {"chown", (PyCFunction)os_chown, METH_VARARGS|METH_KEYWORDS, os_chown__doc__},
670
671static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400672os_chown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid,
673 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300674
675static PyObject *
676os_chown(PyModuleDef *module, PyObject *args, PyObject *kwargs)
677{
678 PyObject *return_value = NULL;
679 static char *_keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
680 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
681 uid_t uid;
682 gid_t gid;
683 int dir_fd = DEFAULT_DIR_FD;
684 int follow_symlinks = 1;
685
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300686 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&|$O&p:chown", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300687 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300688 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300689 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300690 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
691
692exit:
693 /* Cleanup for path */
694 path_cleanup(&path);
695
696 return return_value;
697}
698
699#endif /* defined(HAVE_CHOWN) */
700
701#if defined(HAVE_FCHOWN)
702
703PyDoc_STRVAR(os_fchown__doc__,
704"fchown($module, /, fd, uid, gid)\n"
705"--\n"
706"\n"
707"Change the owner and group id of the file specified by file descriptor.\n"
708"\n"
709"Equivalent to os.chown(fd, uid, gid).");
710
711#define OS_FCHOWN_METHODDEF \
712 {"fchown", (PyCFunction)os_fchown, METH_VARARGS|METH_KEYWORDS, os_fchown__doc__},
713
714static PyObject *
715os_fchown_impl(PyModuleDef *module, int fd, uid_t uid, gid_t gid);
716
717static PyObject *
718os_fchown(PyModuleDef *module, PyObject *args, PyObject *kwargs)
719{
720 PyObject *return_value = NULL;
721 static char *_keywords[] = {"fd", "uid", "gid", NULL};
722 int fd;
723 uid_t uid;
724 gid_t gid;
725
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300726 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO&O&:fchown", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300727 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300728 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300729 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300730 return_value = os_fchown_impl(module, fd, uid, gid);
731
732exit:
733 return return_value;
734}
735
736#endif /* defined(HAVE_FCHOWN) */
737
738#if defined(HAVE_LCHOWN)
739
740PyDoc_STRVAR(os_lchown__doc__,
741"lchown($module, /, path, uid, gid)\n"
742"--\n"
743"\n"
744"Change the owner and group id of path to the numeric uid and gid.\n"
745"\n"
746"This function will not follow symbolic links.\n"
747"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
748
749#define OS_LCHOWN_METHODDEF \
750 {"lchown", (PyCFunction)os_lchown, METH_VARARGS|METH_KEYWORDS, os_lchown__doc__},
751
752static PyObject *
753os_lchown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid);
754
755static PyObject *
756os_lchown(PyModuleDef *module, PyObject *args, PyObject *kwargs)
757{
758 PyObject *return_value = NULL;
759 static char *_keywords[] = {"path", "uid", "gid", NULL};
760 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
761 uid_t uid;
762 gid_t gid;
763
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300764 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&:lchown", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300765 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300766 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300767 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300768 return_value = os_lchown_impl(module, &path, uid, gid);
769
770exit:
771 /* Cleanup for path */
772 path_cleanup(&path);
773
774 return return_value;
775}
776
777#endif /* defined(HAVE_LCHOWN) */
778
779PyDoc_STRVAR(os_getcwd__doc__,
780"getcwd($module, /)\n"
781"--\n"
782"\n"
783"Return a unicode string representing the current working directory.");
784
785#define OS_GETCWD_METHODDEF \
786 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
787
788static PyObject *
789os_getcwd_impl(PyModuleDef *module);
790
791static PyObject *
792os_getcwd(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
793{
794 return os_getcwd_impl(module);
795}
796
797PyDoc_STRVAR(os_getcwdb__doc__,
798"getcwdb($module, /)\n"
799"--\n"
800"\n"
801"Return a bytes string representing the current working directory.");
802
803#define OS_GETCWDB_METHODDEF \
804 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
805
806static PyObject *
807os_getcwdb_impl(PyModuleDef *module);
808
809static PyObject *
810os_getcwdb(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
811{
812 return os_getcwdb_impl(module);
813}
814
815#if defined(HAVE_LINK)
816
817PyDoc_STRVAR(os_link__doc__,
818"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
819" follow_symlinks=True)\n"
820"--\n"
821"\n"
822"Create a hard link to a file.\n"
823"\n"
824"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
825" descriptor open to a directory, and the respective path string (src or dst)\n"
826" should be relative; the path will then be relative to that directory.\n"
827"If follow_symlinks is False, and the last element of src is a symbolic\n"
828" link, link will create a link to the symbolic link itself instead of the\n"
829" file the link points to.\n"
830"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
831" platform. If they are unavailable, using them will raise a\n"
832" NotImplementedError.");
833
834#define OS_LINK_METHODDEF \
835 {"link", (PyCFunction)os_link, METH_VARARGS|METH_KEYWORDS, os_link__doc__},
836
837static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400838os_link_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd,
839 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300840
841static PyObject *
842os_link(PyModuleDef *module, PyObject *args, PyObject *kwargs)
843{
844 PyObject *return_value = NULL;
845 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
846 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
847 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
848 int src_dir_fd = DEFAULT_DIR_FD;
849 int dst_dir_fd = DEFAULT_DIR_FD;
850 int follow_symlinks = 1;
851
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300852 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&p:link", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300853 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300854 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300855 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300856 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
857
858exit:
859 /* Cleanup for src */
860 path_cleanup(&src);
861 /* Cleanup for dst */
862 path_cleanup(&dst);
863
864 return return_value;
865}
866
867#endif /* defined(HAVE_LINK) */
868
869PyDoc_STRVAR(os_listdir__doc__,
870"listdir($module, /, path=None)\n"
871"--\n"
872"\n"
873"Return a list containing the names of the files in the directory.\n"
874"\n"
875"path can be specified as either str or bytes. If path is bytes,\n"
876" the filenames returned will also be bytes; in all other circumstances\n"
877" the filenames returned will be str.\n"
878"If path is None, uses the path=\'.\'.\n"
879"On some platforms, path may also be specified as an open file descriptor;\\\n"
880" the file descriptor must refer to a directory.\n"
881" If this functionality is unavailable, using it raises NotImplementedError.\n"
882"\n"
883"The list is in arbitrary order. It does not include the special\n"
884"entries \'.\' and \'..\' even if they are present in the directory.");
885
886#define OS_LISTDIR_METHODDEF \
887 {"listdir", (PyCFunction)os_listdir, METH_VARARGS|METH_KEYWORDS, os_listdir__doc__},
888
889static PyObject *
890os_listdir_impl(PyModuleDef *module, path_t *path);
891
892static PyObject *
893os_listdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
894{
895 PyObject *return_value = NULL;
896 static char *_keywords[] = {"path", NULL};
897 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
898
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300899 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:listdir", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300900 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300901 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300902 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300903 return_value = os_listdir_impl(module, &path);
904
905exit:
906 /* Cleanup for path */
907 path_cleanup(&path);
908
909 return return_value;
910}
911
912#if defined(MS_WINDOWS)
913
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300914PyDoc_STRVAR(os__getfullpathname__doc__,
915"_getfullpathname($module, path, /)\n"
916"--\n"
917"\n");
918
919#define OS__GETFULLPATHNAME_METHODDEF \
920 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
921
922static PyObject *
923os__getfullpathname_impl(PyModuleDef *module, path_t *path);
924
925static PyObject *
926os__getfullpathname(PyModuleDef *module, PyObject *arg)
927{
928 PyObject *return_value = NULL;
929 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
930
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300931 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300932 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300933 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300934 return_value = os__getfullpathname_impl(module, &path);
935
936exit:
937 /* Cleanup for path */
938 path_cleanup(&path);
939
940 return return_value;
941}
942
943#endif /* defined(MS_WINDOWS) */
944
945#if defined(MS_WINDOWS)
946
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300947PyDoc_STRVAR(os__getfinalpathname__doc__,
948"_getfinalpathname($module, path, /)\n"
949"--\n"
950"\n"
951"A helper function for samepath on windows.");
952
953#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300954 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300955
956static PyObject *
957os__getfinalpathname_impl(PyModuleDef *module, PyObject *path);
958
959static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300960os__getfinalpathname(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300961{
962 PyObject *return_value = NULL;
963 PyObject *path;
964
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300965 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300966 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300967 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300968 return_value = os__getfinalpathname_impl(module, path);
969
970exit:
971 return return_value;
972}
973
974#endif /* defined(MS_WINDOWS) */
975
976#if defined(MS_WINDOWS)
977
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300978PyDoc_STRVAR(os__isdir__doc__,
979"_isdir($module, path, /)\n"
980"--\n"
981"\n");
982
983#define OS__ISDIR_METHODDEF \
984 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
985
986static PyObject *
987os__isdir_impl(PyModuleDef *module, path_t *path);
988
989static PyObject *
990os__isdir(PyModuleDef *module, PyObject *arg)
991{
992 PyObject *return_value = NULL;
993 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
994
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300995 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300996 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300997 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300998 return_value = os__isdir_impl(module, &path);
999
1000exit:
1001 /* Cleanup for path */
1002 path_cleanup(&path);
1003
1004 return return_value;
1005}
1006
1007#endif /* defined(MS_WINDOWS) */
1008
1009#if defined(MS_WINDOWS)
1010
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001011PyDoc_STRVAR(os__getvolumepathname__doc__,
1012"_getvolumepathname($module, /, path)\n"
1013"--\n"
1014"\n"
1015"A helper function for ismount on Win32.");
1016
1017#define OS__GETVOLUMEPATHNAME_METHODDEF \
1018 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_VARARGS|METH_KEYWORDS, os__getvolumepathname__doc__},
1019
1020static PyObject *
1021os__getvolumepathname_impl(PyModuleDef *module, PyObject *path);
1022
1023static PyObject *
1024os__getvolumepathname(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1025{
1026 PyObject *return_value = NULL;
1027 static char *_keywords[] = {"path", NULL};
1028 PyObject *path;
1029
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001030 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U:_getvolumepathname", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001031 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001032 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001033 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001034 return_value = os__getvolumepathname_impl(module, path);
1035
1036exit:
1037 return return_value;
1038}
1039
1040#endif /* defined(MS_WINDOWS) */
1041
1042PyDoc_STRVAR(os_mkdir__doc__,
1043"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1044"--\n"
1045"\n"
1046"Create a directory.\n"
1047"\n"
1048"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1049" and path should be relative; path will then be relative to that directory.\n"
1050"dir_fd may not be implemented on your platform.\n"
1051" If it is unavailable, using it will raise a NotImplementedError.\n"
1052"\n"
1053"The mode argument is ignored on Windows.");
1054
1055#define OS_MKDIR_METHODDEF \
1056 {"mkdir", (PyCFunction)os_mkdir, METH_VARARGS|METH_KEYWORDS, os_mkdir__doc__},
1057
1058static PyObject *
1059os_mkdir_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd);
1060
1061static PyObject *
1062os_mkdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1063{
1064 PyObject *return_value = NULL;
1065 static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
1066 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1067 int mode = 511;
1068 int dir_fd = DEFAULT_DIR_FD;
1069
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001070 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkdir", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001071 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001072 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001073 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001074 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1075
1076exit:
1077 /* Cleanup for path */
1078 path_cleanup(&path);
1079
1080 return return_value;
1081}
1082
1083#if defined(HAVE_NICE)
1084
1085PyDoc_STRVAR(os_nice__doc__,
1086"nice($module, increment, /)\n"
1087"--\n"
1088"\n"
1089"Add increment to the priority of process and return the new priority.");
1090
1091#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001092 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093
1094static PyObject *
1095os_nice_impl(PyModuleDef *module, int increment);
1096
1097static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001098os_nice(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001099{
1100 PyObject *return_value = NULL;
1101 int increment;
1102
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001103 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001105 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001106 return_value = os_nice_impl(module, increment);
1107
1108exit:
1109 return return_value;
1110}
1111
1112#endif /* defined(HAVE_NICE) */
1113
1114#if defined(HAVE_GETPRIORITY)
1115
1116PyDoc_STRVAR(os_getpriority__doc__,
1117"getpriority($module, /, which, who)\n"
1118"--\n"
1119"\n"
1120"Return program scheduling priority.");
1121
1122#define OS_GETPRIORITY_METHODDEF \
1123 {"getpriority", (PyCFunction)os_getpriority, METH_VARARGS|METH_KEYWORDS, os_getpriority__doc__},
1124
1125static PyObject *
1126os_getpriority_impl(PyModuleDef *module, int which, int who);
1127
1128static PyObject *
1129os_getpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1130{
1131 PyObject *return_value = NULL;
1132 static char *_keywords[] = {"which", "who", NULL};
1133 int which;
1134 int who;
1135
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001136 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:getpriority", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001137 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001138 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001139 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001140 return_value = os_getpriority_impl(module, which, who);
1141
1142exit:
1143 return return_value;
1144}
1145
1146#endif /* defined(HAVE_GETPRIORITY) */
1147
1148#if defined(HAVE_SETPRIORITY)
1149
1150PyDoc_STRVAR(os_setpriority__doc__,
1151"setpriority($module, /, which, who, priority)\n"
1152"--\n"
1153"\n"
1154"Set program scheduling priority.");
1155
1156#define OS_SETPRIORITY_METHODDEF \
1157 {"setpriority", (PyCFunction)os_setpriority, METH_VARARGS|METH_KEYWORDS, os_setpriority__doc__},
1158
1159static PyObject *
1160os_setpriority_impl(PyModuleDef *module, int which, int who, int priority);
1161
1162static PyObject *
1163os_setpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1164{
1165 PyObject *return_value = NULL;
1166 static char *_keywords[] = {"which", "who", "priority", NULL};
1167 int which;
1168 int who;
1169 int priority;
1170
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001171 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii:setpriority", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001172 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001173 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001174 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001175 return_value = os_setpriority_impl(module, which, who, priority);
1176
1177exit:
1178 return return_value;
1179}
1180
1181#endif /* defined(HAVE_SETPRIORITY) */
1182
1183PyDoc_STRVAR(os_rename__doc__,
1184"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1185"--\n"
1186"\n"
1187"Rename a file or directory.\n"
1188"\n"
1189"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1190" descriptor open to a directory, and the respective path string (src or dst)\n"
1191" should be relative; the path will then be relative to that directory.\n"
1192"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1193" If they are unavailable, using them will raise a NotImplementedError.");
1194
1195#define OS_RENAME_METHODDEF \
1196 {"rename", (PyCFunction)os_rename, METH_VARARGS|METH_KEYWORDS, os_rename__doc__},
1197
1198static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04001199os_rename_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd,
1200 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001201
1202static PyObject *
1203os_rename(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1204{
1205 PyObject *return_value = NULL;
1206 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1207 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1208 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1209 int src_dir_fd = DEFAULT_DIR_FD;
1210 int dst_dir_fd = DEFAULT_DIR_FD;
1211
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001212 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&:rename", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001213 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001214 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001215 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001216 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1217
1218exit:
1219 /* Cleanup for src */
1220 path_cleanup(&src);
1221 /* Cleanup for dst */
1222 path_cleanup(&dst);
1223
1224 return return_value;
1225}
1226
1227PyDoc_STRVAR(os_replace__doc__,
1228"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1229"--\n"
1230"\n"
1231"Rename a file or directory, overwriting the destination.\n"
1232"\n"
1233"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1234" descriptor open to a directory, and the respective path string (src or dst)\n"
1235" should be relative; the path will then be relative to that directory.\n"
1236"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1237" If they are unavailable, using them will raise a NotImplementedError.\"");
1238
1239#define OS_REPLACE_METHODDEF \
1240 {"replace", (PyCFunction)os_replace, METH_VARARGS|METH_KEYWORDS, os_replace__doc__},
1241
1242static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04001243os_replace_impl(PyModuleDef *module, path_t *src, path_t *dst,
1244 int src_dir_fd, int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001245
1246static PyObject *
1247os_replace(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1248{
1249 PyObject *return_value = NULL;
1250 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1251 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1252 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1253 int src_dir_fd = DEFAULT_DIR_FD;
1254 int dst_dir_fd = DEFAULT_DIR_FD;
1255
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001256 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&:replace", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001257 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001258 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001259 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001260 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1261
1262exit:
1263 /* Cleanup for src */
1264 path_cleanup(&src);
1265 /* Cleanup for dst */
1266 path_cleanup(&dst);
1267
1268 return return_value;
1269}
1270
1271PyDoc_STRVAR(os_rmdir__doc__,
1272"rmdir($module, /, path, *, dir_fd=None)\n"
1273"--\n"
1274"\n"
1275"Remove a directory.\n"
1276"\n"
1277"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1278" and path should be relative; path will then be relative to that directory.\n"
1279"dir_fd may not be implemented on your platform.\n"
1280" If it is unavailable, using it will raise a NotImplementedError.");
1281
1282#define OS_RMDIR_METHODDEF \
1283 {"rmdir", (PyCFunction)os_rmdir, METH_VARARGS|METH_KEYWORDS, os_rmdir__doc__},
1284
1285static PyObject *
1286os_rmdir_impl(PyModuleDef *module, path_t *path, int dir_fd);
1287
1288static PyObject *
1289os_rmdir(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1290{
1291 PyObject *return_value = NULL;
1292 static char *_keywords[] = {"path", "dir_fd", NULL};
1293 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1294 int dir_fd = DEFAULT_DIR_FD;
1295
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001296 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:rmdir", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001297 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001298 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001299 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001300 return_value = os_rmdir_impl(module, &path, dir_fd);
1301
1302exit:
1303 /* Cleanup for path */
1304 path_cleanup(&path);
1305
1306 return return_value;
1307}
1308
1309#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1310
1311PyDoc_STRVAR(os_system__doc__,
1312"system($module, /, command)\n"
1313"--\n"
1314"\n"
1315"Execute the command in a subshell.");
1316
1317#define OS_SYSTEM_METHODDEF \
1318 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1319
1320static long
1321os_system_impl(PyModuleDef *module, Py_UNICODE *command);
1322
1323static PyObject *
1324os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1325{
1326 PyObject *return_value = NULL;
1327 static char *_keywords[] = {"command", NULL};
1328 Py_UNICODE *command;
1329 long _return_value;
1330
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001331 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "u:system", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001332 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001333 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001334 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001335 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001336 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001337 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001338 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001339 return_value = PyLong_FromLong(_return_value);
1340
1341exit:
1342 return return_value;
1343}
1344
1345#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1346
1347#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1348
1349PyDoc_STRVAR(os_system__doc__,
1350"system($module, /, command)\n"
1351"--\n"
1352"\n"
1353"Execute the command in a subshell.");
1354
1355#define OS_SYSTEM_METHODDEF \
1356 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1357
1358static long
1359os_system_impl(PyModuleDef *module, PyObject *command);
1360
1361static PyObject *
1362os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1363{
1364 PyObject *return_value = NULL;
1365 static char *_keywords[] = {"command", NULL};
1366 PyObject *command = NULL;
1367 long _return_value;
1368
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001369 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:system", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001370 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001371 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001372 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001373 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001374 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001375 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001376 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001377 return_value = PyLong_FromLong(_return_value);
1378
1379exit:
1380 /* Cleanup for command */
1381 Py_XDECREF(command);
1382
1383 return return_value;
1384}
1385
1386#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1387
1388PyDoc_STRVAR(os_umask__doc__,
1389"umask($module, mask, /)\n"
1390"--\n"
1391"\n"
1392"Set the current numeric umask and return the previous umask.");
1393
1394#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001395 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001396
1397static PyObject *
1398os_umask_impl(PyModuleDef *module, int mask);
1399
1400static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001401os_umask(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001402{
1403 PyObject *return_value = NULL;
1404 int mask;
1405
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001406 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001407 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001408 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001409 return_value = os_umask_impl(module, mask);
1410
1411exit:
1412 return return_value;
1413}
1414
1415PyDoc_STRVAR(os_unlink__doc__,
1416"unlink($module, /, path, *, dir_fd=None)\n"
1417"--\n"
1418"\n"
1419"Remove a file (same as remove()).\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_UNLINK_METHODDEF \
1427 {"unlink", (PyCFunction)os_unlink, METH_VARARGS|METH_KEYWORDS, os_unlink__doc__},
1428
1429static PyObject *
1430os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd);
1431
1432static PyObject *
1433os_unlink(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("unlink", "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&:unlink", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001441 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001442 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001443 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001444 return_value = os_unlink_impl(module, &path, dir_fd);
1445
1446exit:
1447 /* Cleanup for path */
1448 path_cleanup(&path);
1449
1450 return return_value;
1451}
1452
1453PyDoc_STRVAR(os_remove__doc__,
1454"remove($module, /, path, *, dir_fd=None)\n"
1455"--\n"
1456"\n"
1457"Remove a file (same as unlink()).\n"
1458"\n"
1459"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1460" and path should be relative; path will then be relative to that directory.\n"
1461"dir_fd may not be implemented on your platform.\n"
1462" If it is unavailable, using it will raise a NotImplementedError.");
1463
1464#define OS_REMOVE_METHODDEF \
1465 {"remove", (PyCFunction)os_remove, METH_VARARGS|METH_KEYWORDS, os_remove__doc__},
1466
1467static PyObject *
1468os_remove_impl(PyModuleDef *module, path_t *path, int dir_fd);
1469
1470static PyObject *
1471os_remove(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1472{
1473 PyObject *return_value = NULL;
1474 static char *_keywords[] = {"path", "dir_fd", NULL};
1475 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1476 int dir_fd = DEFAULT_DIR_FD;
1477
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001478 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:remove", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001479 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001480 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001481 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001482 return_value = os_remove_impl(module, &path, dir_fd);
1483
1484exit:
1485 /* Cleanup for path */
1486 path_cleanup(&path);
1487
1488 return return_value;
1489}
1490
1491#if defined(HAVE_UNAME)
1492
1493PyDoc_STRVAR(os_uname__doc__,
1494"uname($module, /)\n"
1495"--\n"
1496"\n"
1497"Return an object identifying the current operating system.\n"
1498"\n"
1499"The object behaves like a named tuple with the following fields:\n"
1500" (sysname, nodename, release, version, machine)");
1501
1502#define OS_UNAME_METHODDEF \
1503 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1504
1505static PyObject *
1506os_uname_impl(PyModuleDef *module);
1507
1508static PyObject *
1509os_uname(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
1510{
1511 return os_uname_impl(module);
1512}
1513
1514#endif /* defined(HAVE_UNAME) */
1515
1516PyDoc_STRVAR(os_utime__doc__,
1517"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1518" follow_symlinks=True)\n"
1519"--\n"
1520"\n"
1521"Set the access and modified time of path.\n"
1522"\n"
1523"path may always be specified as a string.\n"
1524"On some platforms, path may also be specified as an open file descriptor.\n"
1525" If this functionality is unavailable, using it raises an exception.\n"
1526"\n"
1527"If times is not None, it must be a tuple (atime, mtime);\n"
1528" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001529"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001530" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1531" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001532"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001533"Specifying tuples for both times and ns is an error.\n"
1534"\n"
1535"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1536" and path should be relative; path will then be relative to that directory.\n"
1537"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1538" link, utime will modify the symbolic link itself instead of the file the\n"
1539" link points to.\n"
1540"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1541" as an open file descriptor.\n"
1542"dir_fd and follow_symlinks may not be available on your platform.\n"
1543" If they are unavailable, using them will raise a NotImplementedError.");
1544
1545#define OS_UTIME_METHODDEF \
1546 {"utime", (PyCFunction)os_utime, METH_VARARGS|METH_KEYWORDS, os_utime__doc__},
1547
1548static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04001549os_utime_impl(PyModuleDef *module, path_t *path, PyObject *times,
1550 PyObject *ns, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001551
1552static PyObject *
1553os_utime(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1554{
1555 PyObject *return_value = NULL;
1556 static char *_keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1557 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1558 PyObject *times = NULL;
1559 PyObject *ns = NULL;
1560 int dir_fd = DEFAULT_DIR_FD;
1561 int follow_symlinks = 1;
1562
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001563 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|O$OO&p:utime", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001564 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001565 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001566 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001567 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1568
1569exit:
1570 /* Cleanup for path */
1571 path_cleanup(&path);
1572
1573 return return_value;
1574}
1575
1576PyDoc_STRVAR(os__exit__doc__,
1577"_exit($module, /, status)\n"
1578"--\n"
1579"\n"
1580"Exit to the system with specified status, without normal exit processing.");
1581
1582#define OS__EXIT_METHODDEF \
1583 {"_exit", (PyCFunction)os__exit, METH_VARARGS|METH_KEYWORDS, os__exit__doc__},
1584
1585static PyObject *
1586os__exit_impl(PyModuleDef *module, int status);
1587
1588static PyObject *
1589os__exit(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1590{
1591 PyObject *return_value = NULL;
1592 static char *_keywords[] = {"status", NULL};
1593 int status;
1594
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001595 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:_exit", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001596 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001597 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001598 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001599 return_value = os__exit_impl(module, status);
1600
1601exit:
1602 return return_value;
1603}
1604
1605#if defined(HAVE_EXECV)
1606
1607PyDoc_STRVAR(os_execv__doc__,
1608"execv($module, path, argv, /)\n"
1609"--\n"
1610"\n"
1611"Execute an executable path with arguments, replacing current process.\n"
1612"\n"
1613" path\n"
1614" Path of executable file.\n"
1615" argv\n"
1616" Tuple or list of strings.");
1617
1618#define OS_EXECV_METHODDEF \
1619 {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
1620
1621static PyObject *
1622os_execv_impl(PyModuleDef *module, PyObject *path, PyObject *argv);
1623
1624static PyObject *
1625os_execv(PyModuleDef *module, PyObject *args)
1626{
1627 PyObject *return_value = NULL;
1628 PyObject *path = NULL;
1629 PyObject *argv;
1630
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001631 if (!PyArg_ParseTuple(args, "O&O:execv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001632 PyUnicode_FSConverter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001633 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001634 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001635 return_value = os_execv_impl(module, path, argv);
1636
1637exit:
1638 /* Cleanup for path */
1639 Py_XDECREF(path);
1640
1641 return return_value;
1642}
1643
1644#endif /* defined(HAVE_EXECV) */
1645
1646#if defined(HAVE_EXECV)
1647
1648PyDoc_STRVAR(os_execve__doc__,
1649"execve($module, /, path, argv, env)\n"
1650"--\n"
1651"\n"
1652"Execute an executable path with arguments, replacing current process.\n"
1653"\n"
1654" path\n"
1655" Path of executable file.\n"
1656" argv\n"
1657" Tuple or list of strings.\n"
1658" env\n"
1659" Dictionary of strings mapping to strings.");
1660
1661#define OS_EXECVE_METHODDEF \
1662 {"execve", (PyCFunction)os_execve, METH_VARARGS|METH_KEYWORDS, os_execve__doc__},
1663
1664static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04001665os_execve_impl(PyModuleDef *module, path_t *path, PyObject *argv,
1666 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001667
1668static PyObject *
1669os_execve(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1670{
1671 PyObject *return_value = NULL;
1672 static char *_keywords[] = {"path", "argv", "env", NULL};
1673 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1674 PyObject *argv;
1675 PyObject *env;
1676
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001677 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&OO:execve", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001678 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001679 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001680 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001681 return_value = os_execve_impl(module, &path, argv, env);
1682
1683exit:
1684 /* Cleanup for path */
1685 path_cleanup(&path);
1686
1687 return return_value;
1688}
1689
1690#endif /* defined(HAVE_EXECV) */
1691
1692#if defined(HAVE_SPAWNV)
1693
1694PyDoc_STRVAR(os_spawnv__doc__,
1695"spawnv($module, mode, path, argv, /)\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.");
1706
1707#define OS_SPAWNV_METHODDEF \
1708 {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
1709
1710static PyObject *
1711os_spawnv_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv);
1712
1713static PyObject *
1714os_spawnv(PyModuleDef *module, PyObject *args)
1715{
1716 PyObject *return_value = NULL;
1717 int mode;
1718 PyObject *path = NULL;
1719 PyObject *argv;
1720
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001721 if (!PyArg_ParseTuple(args, "iO&O:spawnv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001722 &mode, PyUnicode_FSConverter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001723 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001724 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001725 return_value = os_spawnv_impl(module, mode, path, argv);
1726
1727exit:
1728 /* Cleanup for path */
1729 Py_XDECREF(path);
1730
1731 return return_value;
1732}
1733
1734#endif /* defined(HAVE_SPAWNV) */
1735
1736#if defined(HAVE_SPAWNV)
1737
1738PyDoc_STRVAR(os_spawnve__doc__,
1739"spawnve($module, mode, path, argv, env, /)\n"
1740"--\n"
1741"\n"
1742"Execute the program specified by path in a new process.\n"
1743"\n"
1744" mode\n"
1745" Mode of process creation.\n"
1746" path\n"
1747" Path of executable file.\n"
1748" argv\n"
1749" Tuple or list of strings.\n"
1750" env\n"
1751" Dictionary of strings mapping to strings.");
1752
1753#define OS_SPAWNVE_METHODDEF \
1754 {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
1755
1756static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04001757os_spawnve_impl(PyModuleDef *module, int mode, PyObject *path,
1758 PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001759
1760static PyObject *
1761os_spawnve(PyModuleDef *module, PyObject *args)
1762{
1763 PyObject *return_value = NULL;
1764 int mode;
1765 PyObject *path = NULL;
1766 PyObject *argv;
1767 PyObject *env;
1768
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001769 if (!PyArg_ParseTuple(args, "iO&OO:spawnve",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001770 &mode, PyUnicode_FSConverter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001771 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001772 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001773 return_value = os_spawnve_impl(module, mode, path, argv, env);
1774
1775exit:
1776 /* Cleanup for path */
1777 Py_XDECREF(path);
1778
1779 return return_value;
1780}
1781
1782#endif /* defined(HAVE_SPAWNV) */
1783
1784#if defined(HAVE_FORK1)
1785
1786PyDoc_STRVAR(os_fork1__doc__,
1787"fork1($module, /)\n"
1788"--\n"
1789"\n"
1790"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1791"\n"
1792"Return 0 to child process and PID of child to parent process.");
1793
1794#define OS_FORK1_METHODDEF \
1795 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1796
1797static PyObject *
1798os_fork1_impl(PyModuleDef *module);
1799
1800static PyObject *
1801os_fork1(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
1802{
1803 return os_fork1_impl(module);
1804}
1805
1806#endif /* defined(HAVE_FORK1) */
1807
1808#if defined(HAVE_FORK)
1809
1810PyDoc_STRVAR(os_fork__doc__,
1811"fork($module, /)\n"
1812"--\n"
1813"\n"
1814"Fork a child process.\n"
1815"\n"
1816"Return 0 to child process and PID of child to parent process.");
1817
1818#define OS_FORK_METHODDEF \
1819 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1820
1821static PyObject *
1822os_fork_impl(PyModuleDef *module);
1823
1824static PyObject *
1825os_fork(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
1826{
1827 return os_fork_impl(module);
1828}
1829
1830#endif /* defined(HAVE_FORK) */
1831
1832#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1833
1834PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1835"sched_get_priority_max($module, /, policy)\n"
1836"--\n"
1837"\n"
1838"Get the maximum scheduling priority for policy.");
1839
1840#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
1841 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_max__doc__},
1842
1843static PyObject *
1844os_sched_get_priority_max_impl(PyModuleDef *module, int policy);
1845
1846static PyObject *
1847os_sched_get_priority_max(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1848{
1849 PyObject *return_value = NULL;
1850 static char *_keywords[] = {"policy", NULL};
1851 int policy;
1852
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001853 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:sched_get_priority_max", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001854 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001855 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001856 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001857 return_value = os_sched_get_priority_max_impl(module, policy);
1858
1859exit:
1860 return return_value;
1861}
1862
1863#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1864
1865#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1866
1867PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1868"sched_get_priority_min($module, /, policy)\n"
1869"--\n"
1870"\n"
1871"Get the minimum scheduling priority for policy.");
1872
1873#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
1874 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_min__doc__},
1875
1876static PyObject *
1877os_sched_get_priority_min_impl(PyModuleDef *module, int policy);
1878
1879static PyObject *
1880os_sched_get_priority_min(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1881{
1882 PyObject *return_value = NULL;
1883 static char *_keywords[] = {"policy", NULL};
1884 int policy;
1885
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001886 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:sched_get_priority_min", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001887 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001888 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001889 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001890 return_value = os_sched_get_priority_min_impl(module, policy);
1891
1892exit:
1893 return return_value;
1894}
1895
1896#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1897
1898#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1899
1900PyDoc_STRVAR(os_sched_getscheduler__doc__,
1901"sched_getscheduler($module, pid, /)\n"
1902"--\n"
1903"\n"
1904"Get the scheduling policy for the process identifiedy by pid.\n"
1905"\n"
1906"Passing 0 for pid returns the scheduling policy for the calling process.");
1907
1908#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001909 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001910
1911static PyObject *
1912os_sched_getscheduler_impl(PyModuleDef *module, pid_t pid);
1913
1914static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001915os_sched_getscheduler(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001916{
1917 PyObject *return_value = NULL;
1918 pid_t pid;
1919
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001920 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001921 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001922 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001923 return_value = os_sched_getscheduler_impl(module, pid);
1924
1925exit:
1926 return return_value;
1927}
1928
1929#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1930
1931#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1932
1933PyDoc_STRVAR(os_sched_param__doc__,
1934"sched_param(sched_priority)\n"
1935"--\n"
1936"\n"
1937"Current has only one field: sched_priority\");\n"
1938"\n"
1939" sched_priority\n"
1940" A scheduling parameter.");
1941
1942static PyObject *
1943os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1944
1945static PyObject *
1946os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1947{
1948 PyObject *return_value = NULL;
1949 static char *_keywords[] = {"sched_priority", NULL};
1950 PyObject *sched_priority;
1951
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001952 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:sched_param", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001953 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001954 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001955 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001956 return_value = os_sched_param_impl(type, sched_priority);
1957
1958exit:
1959 return return_value;
1960}
1961
1962#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
1963
1964#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1965
1966PyDoc_STRVAR(os_sched_setscheduler__doc__,
1967"sched_setscheduler($module, pid, policy, param, /)\n"
1968"--\n"
1969"\n"
1970"Set the scheduling policy for the process identified by pid.\n"
1971"\n"
1972"If pid is 0, the calling process is changed.\n"
1973"param is an instance of sched_param.");
1974
1975#define OS_SCHED_SETSCHEDULER_METHODDEF \
1976 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
1977
1978static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04001979os_sched_setscheduler_impl(PyModuleDef *module, pid_t pid, int policy,
1980 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001981
1982static PyObject *
1983os_sched_setscheduler(PyModuleDef *module, PyObject *args)
1984{
1985 PyObject *return_value = NULL;
1986 pid_t pid;
1987 int policy;
1988 struct sched_param param;
1989
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001990 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001991 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001992 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001993 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001994 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
1995
1996exit:
1997 return return_value;
1998}
1999
2000#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2001
2002#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2003
2004PyDoc_STRVAR(os_sched_getparam__doc__,
2005"sched_getparam($module, pid, /)\n"
2006"--\n"
2007"\n"
2008"Returns scheduling parameters for the process identified by pid.\n"
2009"\n"
2010"If pid is 0, returns parameters for the calling process.\n"
2011"Return value is an instance of sched_param.");
2012
2013#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002014 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002015
2016static PyObject *
2017os_sched_getparam_impl(PyModuleDef *module, pid_t pid);
2018
2019static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002020os_sched_getparam(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002021{
2022 PyObject *return_value = NULL;
2023 pid_t pid;
2024
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002025 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002026 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002027 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002028 return_value = os_sched_getparam_impl(module, pid);
2029
2030exit:
2031 return return_value;
2032}
2033
2034#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2035
2036#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2037
2038PyDoc_STRVAR(os_sched_setparam__doc__,
2039"sched_setparam($module, pid, param, /)\n"
2040"--\n"
2041"\n"
2042"Set scheduling parameters for the process identified by pid.\n"
2043"\n"
2044"If pid is 0, sets parameters for the calling process.\n"
2045"param should be an instance of sched_param.");
2046
2047#define OS_SCHED_SETPARAM_METHODDEF \
2048 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
2049
2050static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04002051os_sched_setparam_impl(PyModuleDef *module, pid_t pid,
2052 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002053
2054static PyObject *
2055os_sched_setparam(PyModuleDef *module, PyObject *args)
2056{
2057 PyObject *return_value = NULL;
2058 pid_t pid;
2059 struct sched_param param;
2060
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002061 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002062 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002063 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002064 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002065 return_value = os_sched_setparam_impl(module, pid, &param);
2066
2067exit:
2068 return return_value;
2069}
2070
2071#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2072
2073#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2074
2075PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2076"sched_rr_get_interval($module, pid, /)\n"
2077"--\n"
2078"\n"
2079"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2080"\n"
2081"Value returned is a float.");
2082
2083#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002084 {"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 +03002085
2086static double
2087os_sched_rr_get_interval_impl(PyModuleDef *module, pid_t pid);
2088
2089static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002090os_sched_rr_get_interval(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002091{
2092 PyObject *return_value = NULL;
2093 pid_t pid;
2094 double _return_value;
2095
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002096 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002097 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002098 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002099 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002100 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002101 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002102 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002103 return_value = PyFloat_FromDouble(_return_value);
2104
2105exit:
2106 return return_value;
2107}
2108
2109#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2110
2111#if defined(HAVE_SCHED_H)
2112
2113PyDoc_STRVAR(os_sched_yield__doc__,
2114"sched_yield($module, /)\n"
2115"--\n"
2116"\n"
2117"Voluntarily relinquish the CPU.");
2118
2119#define OS_SCHED_YIELD_METHODDEF \
2120 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2121
2122static PyObject *
2123os_sched_yield_impl(PyModuleDef *module);
2124
2125static PyObject *
2126os_sched_yield(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2127{
2128 return os_sched_yield_impl(module);
2129}
2130
2131#endif /* defined(HAVE_SCHED_H) */
2132
2133#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2134
2135PyDoc_STRVAR(os_sched_setaffinity__doc__,
2136"sched_setaffinity($module, pid, mask, /)\n"
2137"--\n"
2138"\n"
2139"Set the CPU affinity of the process identified by pid to mask.\n"
2140"\n"
2141"mask should be an iterable of integers identifying CPUs.");
2142
2143#define OS_SCHED_SETAFFINITY_METHODDEF \
2144 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
2145
2146static PyObject *
2147os_sched_setaffinity_impl(PyModuleDef *module, pid_t pid, PyObject *mask);
2148
2149static PyObject *
2150os_sched_setaffinity(PyModuleDef *module, PyObject *args)
2151{
2152 PyObject *return_value = NULL;
2153 pid_t pid;
2154 PyObject *mask;
2155
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002156 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002157 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002159 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002160 return_value = os_sched_setaffinity_impl(module, pid, mask);
2161
2162exit:
2163 return return_value;
2164}
2165
2166#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2167
2168#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2169
2170PyDoc_STRVAR(os_sched_getaffinity__doc__,
2171"sched_getaffinity($module, pid, /)\n"
2172"--\n"
2173"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002174"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002175"\n"
2176"The affinity is returned as a set of CPU identifiers.");
2177
2178#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002179 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002180
2181static PyObject *
2182os_sched_getaffinity_impl(PyModuleDef *module, pid_t pid);
2183
2184static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002185os_sched_getaffinity(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186{
2187 PyObject *return_value = NULL;
2188 pid_t pid;
2189
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002190 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002191 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002193 return_value = os_sched_getaffinity_impl(module, pid);
2194
2195exit:
2196 return return_value;
2197}
2198
2199#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2200
2201#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2202
2203PyDoc_STRVAR(os_openpty__doc__,
2204"openpty($module, /)\n"
2205"--\n"
2206"\n"
2207"Open a pseudo-terminal.\n"
2208"\n"
2209"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2210"for both the master and slave ends.");
2211
2212#define OS_OPENPTY_METHODDEF \
2213 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2214
2215static PyObject *
2216os_openpty_impl(PyModuleDef *module);
2217
2218static PyObject *
2219os_openpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2220{
2221 return os_openpty_impl(module);
2222}
2223
2224#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2225
2226#if defined(HAVE_FORKPTY)
2227
2228PyDoc_STRVAR(os_forkpty__doc__,
2229"forkpty($module, /)\n"
2230"--\n"
2231"\n"
2232"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2233"\n"
2234"Returns a tuple of (pid, master_fd).\n"
2235"Like fork(), return pid of 0 to the child process,\n"
2236"and pid of child to the parent process.\n"
2237"To both, return fd of newly opened pseudo-terminal.");
2238
2239#define OS_FORKPTY_METHODDEF \
2240 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2241
2242static PyObject *
2243os_forkpty_impl(PyModuleDef *module);
2244
2245static PyObject *
2246os_forkpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2247{
2248 return os_forkpty_impl(module);
2249}
2250
2251#endif /* defined(HAVE_FORKPTY) */
2252
2253#if defined(HAVE_GETEGID)
2254
2255PyDoc_STRVAR(os_getegid__doc__,
2256"getegid($module, /)\n"
2257"--\n"
2258"\n"
2259"Return the current process\'s effective group id.");
2260
2261#define OS_GETEGID_METHODDEF \
2262 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2263
2264static PyObject *
2265os_getegid_impl(PyModuleDef *module);
2266
2267static PyObject *
2268os_getegid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2269{
2270 return os_getegid_impl(module);
2271}
2272
2273#endif /* defined(HAVE_GETEGID) */
2274
2275#if defined(HAVE_GETEUID)
2276
2277PyDoc_STRVAR(os_geteuid__doc__,
2278"geteuid($module, /)\n"
2279"--\n"
2280"\n"
2281"Return the current process\'s effective user id.");
2282
2283#define OS_GETEUID_METHODDEF \
2284 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2285
2286static PyObject *
2287os_geteuid_impl(PyModuleDef *module);
2288
2289static PyObject *
2290os_geteuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2291{
2292 return os_geteuid_impl(module);
2293}
2294
2295#endif /* defined(HAVE_GETEUID) */
2296
2297#if defined(HAVE_GETGID)
2298
2299PyDoc_STRVAR(os_getgid__doc__,
2300"getgid($module, /)\n"
2301"--\n"
2302"\n"
2303"Return the current process\'s group id.");
2304
2305#define OS_GETGID_METHODDEF \
2306 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2307
2308static PyObject *
2309os_getgid_impl(PyModuleDef *module);
2310
2311static PyObject *
2312os_getgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2313{
2314 return os_getgid_impl(module);
2315}
2316
2317#endif /* defined(HAVE_GETGID) */
2318
2319PyDoc_STRVAR(os_getpid__doc__,
2320"getpid($module, /)\n"
2321"--\n"
2322"\n"
2323"Return the current process id.");
2324
2325#define OS_GETPID_METHODDEF \
2326 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2327
2328static PyObject *
2329os_getpid_impl(PyModuleDef *module);
2330
2331static PyObject *
2332os_getpid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2333{
2334 return os_getpid_impl(module);
2335}
2336
2337#if defined(HAVE_GETGROUPS)
2338
2339PyDoc_STRVAR(os_getgroups__doc__,
2340"getgroups($module, /)\n"
2341"--\n"
2342"\n"
2343"Return list of supplemental group IDs for the process.");
2344
2345#define OS_GETGROUPS_METHODDEF \
2346 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2347
2348static PyObject *
2349os_getgroups_impl(PyModuleDef *module);
2350
2351static PyObject *
2352os_getgroups(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2353{
2354 return os_getgroups_impl(module);
2355}
2356
2357#endif /* defined(HAVE_GETGROUPS) */
2358
2359#if defined(HAVE_GETPGID)
2360
2361PyDoc_STRVAR(os_getpgid__doc__,
2362"getpgid($module, /, pid)\n"
2363"--\n"
2364"\n"
2365"Call the system call getpgid(), and return the result.");
2366
2367#define OS_GETPGID_METHODDEF \
2368 {"getpgid", (PyCFunction)os_getpgid, METH_VARARGS|METH_KEYWORDS, os_getpgid__doc__},
2369
2370static PyObject *
2371os_getpgid_impl(PyModuleDef *module, pid_t pid);
2372
2373static PyObject *
2374os_getpgid(PyModuleDef *module, PyObject *args, PyObject *kwargs)
2375{
2376 PyObject *return_value = NULL;
2377 static char *_keywords[] = {"pid", NULL};
2378 pid_t pid;
2379
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002380 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "" _Py_PARSE_PID ":getpgid", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002381 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002382 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002383 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002384 return_value = os_getpgid_impl(module, pid);
2385
2386exit:
2387 return return_value;
2388}
2389
2390#endif /* defined(HAVE_GETPGID) */
2391
2392#if defined(HAVE_GETPGRP)
2393
2394PyDoc_STRVAR(os_getpgrp__doc__,
2395"getpgrp($module, /)\n"
2396"--\n"
2397"\n"
2398"Return the current process group id.");
2399
2400#define OS_GETPGRP_METHODDEF \
2401 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2402
2403static PyObject *
2404os_getpgrp_impl(PyModuleDef *module);
2405
2406static PyObject *
2407os_getpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2408{
2409 return os_getpgrp_impl(module);
2410}
2411
2412#endif /* defined(HAVE_GETPGRP) */
2413
2414#if defined(HAVE_SETPGRP)
2415
2416PyDoc_STRVAR(os_setpgrp__doc__,
2417"setpgrp($module, /)\n"
2418"--\n"
2419"\n"
2420"Make the current process the leader of its process group.");
2421
2422#define OS_SETPGRP_METHODDEF \
2423 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2424
2425static PyObject *
2426os_setpgrp_impl(PyModuleDef *module);
2427
2428static PyObject *
2429os_setpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2430{
2431 return os_setpgrp_impl(module);
2432}
2433
2434#endif /* defined(HAVE_SETPGRP) */
2435
2436#if defined(HAVE_GETPPID)
2437
2438PyDoc_STRVAR(os_getppid__doc__,
2439"getppid($module, /)\n"
2440"--\n"
2441"\n"
2442"Return the parent\'s process id.\n"
2443"\n"
2444"If the parent process has already exited, Windows machines will still\n"
2445"return its id; others systems will return the id of the \'init\' process (1).");
2446
2447#define OS_GETPPID_METHODDEF \
2448 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2449
2450static PyObject *
2451os_getppid_impl(PyModuleDef *module);
2452
2453static PyObject *
2454os_getppid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2455{
2456 return os_getppid_impl(module);
2457}
2458
2459#endif /* defined(HAVE_GETPPID) */
2460
2461#if defined(HAVE_GETLOGIN)
2462
2463PyDoc_STRVAR(os_getlogin__doc__,
2464"getlogin($module, /)\n"
2465"--\n"
2466"\n"
2467"Return the actual login name.");
2468
2469#define OS_GETLOGIN_METHODDEF \
2470 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2471
2472static PyObject *
2473os_getlogin_impl(PyModuleDef *module);
2474
2475static PyObject *
2476os_getlogin(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2477{
2478 return os_getlogin_impl(module);
2479}
2480
2481#endif /* defined(HAVE_GETLOGIN) */
2482
2483#if defined(HAVE_GETUID)
2484
2485PyDoc_STRVAR(os_getuid__doc__,
2486"getuid($module, /)\n"
2487"--\n"
2488"\n"
2489"Return the current process\'s user id.");
2490
2491#define OS_GETUID_METHODDEF \
2492 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2493
2494static PyObject *
2495os_getuid_impl(PyModuleDef *module);
2496
2497static PyObject *
2498os_getuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
2499{
2500 return os_getuid_impl(module);
2501}
2502
2503#endif /* defined(HAVE_GETUID) */
2504
2505#if defined(HAVE_KILL)
2506
2507PyDoc_STRVAR(os_kill__doc__,
2508"kill($module, pid, signal, /)\n"
2509"--\n"
2510"\n"
2511"Kill a process with a signal.");
2512
2513#define OS_KILL_METHODDEF \
2514 {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
2515
2516static PyObject *
2517os_kill_impl(PyModuleDef *module, pid_t pid, Py_ssize_t signal);
2518
2519static PyObject *
2520os_kill(PyModuleDef *module, PyObject *args)
2521{
2522 PyObject *return_value = NULL;
2523 pid_t pid;
2524 Py_ssize_t signal;
2525
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002526 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002527 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002528 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002529 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002530 return_value = os_kill_impl(module, pid, signal);
2531
2532exit:
2533 return return_value;
2534}
2535
2536#endif /* defined(HAVE_KILL) */
2537
2538#if defined(HAVE_KILLPG)
2539
2540PyDoc_STRVAR(os_killpg__doc__,
2541"killpg($module, pgid, signal, /)\n"
2542"--\n"
2543"\n"
2544"Kill a process group with a signal.");
2545
2546#define OS_KILLPG_METHODDEF \
2547 {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
2548
2549static PyObject *
2550os_killpg_impl(PyModuleDef *module, pid_t pgid, int signal);
2551
2552static PyObject *
2553os_killpg(PyModuleDef *module, PyObject *args)
2554{
2555 PyObject *return_value = NULL;
2556 pid_t pgid;
2557 int signal;
2558
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002559 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002560 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002561 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002562 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002563 return_value = os_killpg_impl(module, pgid, signal);
2564
2565exit:
2566 return return_value;
2567}
2568
2569#endif /* defined(HAVE_KILLPG) */
2570
2571#if defined(HAVE_PLOCK)
2572
2573PyDoc_STRVAR(os_plock__doc__,
2574"plock($module, op, /)\n"
2575"--\n"
2576"\n"
2577"Lock program segments into memory.\");");
2578
2579#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002580 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002581
2582static PyObject *
2583os_plock_impl(PyModuleDef *module, int op);
2584
2585static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002586os_plock(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002587{
2588 PyObject *return_value = NULL;
2589 int op;
2590
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002591 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002592 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002593 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002594 return_value = os_plock_impl(module, op);
2595
2596exit:
2597 return return_value;
2598}
2599
2600#endif /* defined(HAVE_PLOCK) */
2601
2602#if defined(HAVE_SETUID)
2603
2604PyDoc_STRVAR(os_setuid__doc__,
2605"setuid($module, uid, /)\n"
2606"--\n"
2607"\n"
2608"Set the current process\'s user id.");
2609
2610#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002611 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002612
2613static PyObject *
2614os_setuid_impl(PyModuleDef *module, uid_t uid);
2615
2616static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002617os_setuid(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002618{
2619 PyObject *return_value = NULL;
2620 uid_t uid;
2621
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002622 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002623 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002624 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002625 return_value = os_setuid_impl(module, uid);
2626
2627exit:
2628 return return_value;
2629}
2630
2631#endif /* defined(HAVE_SETUID) */
2632
2633#if defined(HAVE_SETEUID)
2634
2635PyDoc_STRVAR(os_seteuid__doc__,
2636"seteuid($module, euid, /)\n"
2637"--\n"
2638"\n"
2639"Set the current process\'s effective user id.");
2640
2641#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002642 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002643
2644static PyObject *
2645os_seteuid_impl(PyModuleDef *module, uid_t euid);
2646
2647static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002648os_seteuid(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002649{
2650 PyObject *return_value = NULL;
2651 uid_t euid;
2652
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002653 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002654 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002655 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002656 return_value = os_seteuid_impl(module, euid);
2657
2658exit:
2659 return return_value;
2660}
2661
2662#endif /* defined(HAVE_SETEUID) */
2663
2664#if defined(HAVE_SETEGID)
2665
2666PyDoc_STRVAR(os_setegid__doc__,
2667"setegid($module, egid, /)\n"
2668"--\n"
2669"\n"
2670"Set the current process\'s effective group id.");
2671
2672#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002673 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002674
2675static PyObject *
2676os_setegid_impl(PyModuleDef *module, gid_t egid);
2677
2678static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002679os_setegid(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002680{
2681 PyObject *return_value = NULL;
2682 gid_t egid;
2683
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002684 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002685 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002686 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002687 return_value = os_setegid_impl(module, egid);
2688
2689exit:
2690 return return_value;
2691}
2692
2693#endif /* defined(HAVE_SETEGID) */
2694
2695#if defined(HAVE_SETREUID)
2696
2697PyDoc_STRVAR(os_setreuid__doc__,
2698"setreuid($module, ruid, euid, /)\n"
2699"--\n"
2700"\n"
2701"Set the current process\'s real and effective user ids.");
2702
2703#define OS_SETREUID_METHODDEF \
2704 {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
2705
2706static PyObject *
2707os_setreuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid);
2708
2709static PyObject *
2710os_setreuid(PyModuleDef *module, PyObject *args)
2711{
2712 PyObject *return_value = NULL;
2713 uid_t ruid;
2714 uid_t euid;
2715
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002716 if (!PyArg_ParseTuple(args, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002717 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002718 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002719 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002720 return_value = os_setreuid_impl(module, ruid, euid);
2721
2722exit:
2723 return return_value;
2724}
2725
2726#endif /* defined(HAVE_SETREUID) */
2727
2728#if defined(HAVE_SETREGID)
2729
2730PyDoc_STRVAR(os_setregid__doc__,
2731"setregid($module, rgid, egid, /)\n"
2732"--\n"
2733"\n"
2734"Set the current process\'s real and effective group ids.");
2735
2736#define OS_SETREGID_METHODDEF \
2737 {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
2738
2739static PyObject *
2740os_setregid_impl(PyModuleDef *module, gid_t rgid, gid_t egid);
2741
2742static PyObject *
2743os_setregid(PyModuleDef *module, PyObject *args)
2744{
2745 PyObject *return_value = NULL;
2746 gid_t rgid;
2747 gid_t egid;
2748
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002749 if (!PyArg_ParseTuple(args, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002750 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002751 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002752 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002753 return_value = os_setregid_impl(module, rgid, egid);
2754
2755exit:
2756 return return_value;
2757}
2758
2759#endif /* defined(HAVE_SETREGID) */
2760
2761#if defined(HAVE_SETGID)
2762
2763PyDoc_STRVAR(os_setgid__doc__,
2764"setgid($module, gid, /)\n"
2765"--\n"
2766"\n"
2767"Set the current process\'s group id.");
2768
2769#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002770 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002771
2772static PyObject *
2773os_setgid_impl(PyModuleDef *module, gid_t gid);
2774
2775static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002776os_setgid(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002777{
2778 PyObject *return_value = NULL;
2779 gid_t gid;
2780
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002781 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002782 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002783 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002784 return_value = os_setgid_impl(module, gid);
2785
2786exit:
2787 return return_value;
2788}
2789
2790#endif /* defined(HAVE_SETGID) */
2791
2792#if defined(HAVE_SETGROUPS)
2793
2794PyDoc_STRVAR(os_setgroups__doc__,
2795"setgroups($module, groups, /)\n"
2796"--\n"
2797"\n"
2798"Set the groups of the current process to list.");
2799
2800#define OS_SETGROUPS_METHODDEF \
2801 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2802
2803#endif /* defined(HAVE_SETGROUPS) */
2804
2805#if defined(HAVE_WAIT3)
2806
2807PyDoc_STRVAR(os_wait3__doc__,
2808"wait3($module, /, options)\n"
2809"--\n"
2810"\n"
2811"Wait for completion of a child process.\n"
2812"\n"
2813"Returns a tuple of information about the child process:\n"
2814" (pid, status, rusage)");
2815
2816#define OS_WAIT3_METHODDEF \
2817 {"wait3", (PyCFunction)os_wait3, METH_VARARGS|METH_KEYWORDS, os_wait3__doc__},
2818
2819static PyObject *
2820os_wait3_impl(PyModuleDef *module, int options);
2821
2822static PyObject *
2823os_wait3(PyModuleDef *module, PyObject *args, PyObject *kwargs)
2824{
2825 PyObject *return_value = NULL;
2826 static char *_keywords[] = {"options", NULL};
2827 int options;
2828
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002829 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:wait3", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002830 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002831 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002832 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002833 return_value = os_wait3_impl(module, options);
2834
2835exit:
2836 return return_value;
2837}
2838
2839#endif /* defined(HAVE_WAIT3) */
2840
2841#if defined(HAVE_WAIT4)
2842
2843PyDoc_STRVAR(os_wait4__doc__,
2844"wait4($module, /, pid, options)\n"
2845"--\n"
2846"\n"
2847"Wait for completion of a specific child process.\n"
2848"\n"
2849"Returns a tuple of information about the child process:\n"
2850" (pid, status, rusage)");
2851
2852#define OS_WAIT4_METHODDEF \
2853 {"wait4", (PyCFunction)os_wait4, METH_VARARGS|METH_KEYWORDS, os_wait4__doc__},
2854
2855static PyObject *
2856os_wait4_impl(PyModuleDef *module, pid_t pid, int options);
2857
2858static PyObject *
2859os_wait4(PyModuleDef *module, PyObject *args, PyObject *kwargs)
2860{
2861 PyObject *return_value = NULL;
2862 static char *_keywords[] = {"pid", "options", NULL};
2863 pid_t pid;
2864 int options;
2865
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002866 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "" _Py_PARSE_PID "i:wait4", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002867 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002868 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002869 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002870 return_value = os_wait4_impl(module, pid, options);
2871
2872exit:
2873 return return_value;
2874}
2875
2876#endif /* defined(HAVE_WAIT4) */
2877
2878#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2879
2880PyDoc_STRVAR(os_waitid__doc__,
2881"waitid($module, idtype, id, options, /)\n"
2882"--\n"
2883"\n"
2884"Returns the result of waiting for a process or processes.\n"
2885"\n"
2886" idtype\n"
2887" Must be one of be P_PID, P_PGID or P_ALL.\n"
2888" id\n"
2889" The id to wait on.\n"
2890" options\n"
2891" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2892" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2893"\n"
2894"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2895"no children in a waitable state.");
2896
2897#define OS_WAITID_METHODDEF \
2898 {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
2899
2900static PyObject *
2901os_waitid_impl(PyModuleDef *module, idtype_t idtype, id_t id, int options);
2902
2903static PyObject *
2904os_waitid(PyModuleDef *module, PyObject *args)
2905{
2906 PyObject *return_value = NULL;
2907 idtype_t idtype;
2908 id_t id;
2909 int options;
2910
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002911 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002912 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002913 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002914 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002915 return_value = os_waitid_impl(module, idtype, id, options);
2916
2917exit:
2918 return return_value;
2919}
2920
2921#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
2922
2923#if defined(HAVE_WAITPID)
2924
2925PyDoc_STRVAR(os_waitpid__doc__,
2926"waitpid($module, pid, options, /)\n"
2927"--\n"
2928"\n"
2929"Wait for completion of a given child process.\n"
2930"\n"
2931"Returns a tuple of information regarding the child process:\n"
2932" (pid, status)\n"
2933"\n"
2934"The options argument is ignored on Windows.");
2935
2936#define OS_WAITPID_METHODDEF \
2937 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2938
2939static PyObject *
2940os_waitpid_impl(PyModuleDef *module, pid_t pid, int options);
2941
2942static PyObject *
2943os_waitpid(PyModuleDef *module, PyObject *args)
2944{
2945 PyObject *return_value = NULL;
2946 pid_t pid;
2947 int options;
2948
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002949 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002950 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002951 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002952 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002953 return_value = os_waitpid_impl(module, pid, options);
2954
2955exit:
2956 return return_value;
2957}
2958
2959#endif /* defined(HAVE_WAITPID) */
2960
2961#if defined(HAVE_CWAIT)
2962
2963PyDoc_STRVAR(os_waitpid__doc__,
2964"waitpid($module, pid, options, /)\n"
2965"--\n"
2966"\n"
2967"Wait for completion of a given process.\n"
2968"\n"
2969"Returns a tuple of information regarding the process:\n"
2970" (pid, status << 8)\n"
2971"\n"
2972"The options argument is ignored on Windows.");
2973
2974#define OS_WAITPID_METHODDEF \
2975 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2976
2977static PyObject *
2978os_waitpid_impl(PyModuleDef *module, Py_intptr_t pid, int options);
2979
2980static PyObject *
2981os_waitpid(PyModuleDef *module, PyObject *args)
2982{
2983 PyObject *return_value = NULL;
2984 Py_intptr_t pid;
2985 int options;
2986
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002987 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002988 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002989 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002990 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002991 return_value = os_waitpid_impl(module, pid, options);
2992
2993exit:
2994 return return_value;
2995}
2996
2997#endif /* defined(HAVE_CWAIT) */
2998
2999#if defined(HAVE_WAIT)
3000
3001PyDoc_STRVAR(os_wait__doc__,
3002"wait($module, /)\n"
3003"--\n"
3004"\n"
3005"Wait for completion of a child process.\n"
3006"\n"
3007"Returns a tuple of information about the child process:\n"
3008" (pid, status)");
3009
3010#define OS_WAIT_METHODDEF \
3011 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3012
3013static PyObject *
3014os_wait_impl(PyModuleDef *module);
3015
3016static PyObject *
3017os_wait(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
3018{
3019 return os_wait_impl(module);
3020}
3021
3022#endif /* defined(HAVE_WAIT) */
3023
3024#if defined(HAVE_SYMLINK)
3025
3026PyDoc_STRVAR(os_symlink__doc__,
3027"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3028"--\n"
3029"\n"
3030"Create a symbolic link pointing to src named dst.\n"
3031"\n"
3032"target_is_directory is required on Windows if the target is to be\n"
3033" interpreted as a directory. (On Windows, symlink requires\n"
3034" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3035" target_is_directory is ignored on non-Windows platforms.\n"
3036"\n"
3037"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3038" and path should be relative; path will then be relative to that directory.\n"
3039"dir_fd may not be implemented on your platform.\n"
3040" If it is unavailable, using it will raise a NotImplementedError.");
3041
3042#define OS_SYMLINK_METHODDEF \
3043 {"symlink", (PyCFunction)os_symlink, METH_VARARGS|METH_KEYWORDS, os_symlink__doc__},
3044
3045static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04003046os_symlink_impl(PyModuleDef *module, path_t *src, path_t *dst,
3047 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003048
3049static PyObject *
3050os_symlink(PyModuleDef *module, PyObject *args, PyObject *kwargs)
3051{
3052 PyObject *return_value = NULL;
3053 static char *_keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3054 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3055 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3056 int target_is_directory = 0;
3057 int dir_fd = DEFAULT_DIR_FD;
3058
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003059 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|p$O&:symlink", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003060 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003061 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003062 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003063 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3064
3065exit:
3066 /* Cleanup for src */
3067 path_cleanup(&src);
3068 /* Cleanup for dst */
3069 path_cleanup(&dst);
3070
3071 return return_value;
3072}
3073
3074#endif /* defined(HAVE_SYMLINK) */
3075
3076#if defined(HAVE_TIMES)
3077
3078PyDoc_STRVAR(os_times__doc__,
3079"times($module, /)\n"
3080"--\n"
3081"\n"
3082"Return a collection containing process timing information.\n"
3083"\n"
3084"The object returned behaves like a named tuple with these fields:\n"
3085" (utime, stime, cutime, cstime, elapsed_time)\n"
3086"All fields are floating point numbers.");
3087
3088#define OS_TIMES_METHODDEF \
3089 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3090
3091static PyObject *
3092os_times_impl(PyModuleDef *module);
3093
3094static PyObject *
3095os_times(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
3096{
3097 return os_times_impl(module);
3098}
3099
3100#endif /* defined(HAVE_TIMES) */
3101
3102#if defined(HAVE_GETSID)
3103
3104PyDoc_STRVAR(os_getsid__doc__,
3105"getsid($module, pid, /)\n"
3106"--\n"
3107"\n"
3108"Call the system call getsid(pid) and return the result.");
3109
3110#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003111 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003112
3113static PyObject *
3114os_getsid_impl(PyModuleDef *module, pid_t pid);
3115
3116static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003117os_getsid(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003118{
3119 PyObject *return_value = NULL;
3120 pid_t pid;
3121
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003122 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003124 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003125 return_value = os_getsid_impl(module, pid);
3126
3127exit:
3128 return return_value;
3129}
3130
3131#endif /* defined(HAVE_GETSID) */
3132
3133#if defined(HAVE_SETSID)
3134
3135PyDoc_STRVAR(os_setsid__doc__,
3136"setsid($module, /)\n"
3137"--\n"
3138"\n"
3139"Call the system call setsid().");
3140
3141#define OS_SETSID_METHODDEF \
3142 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3143
3144static PyObject *
3145os_setsid_impl(PyModuleDef *module);
3146
3147static PyObject *
3148os_setsid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
3149{
3150 return os_setsid_impl(module);
3151}
3152
3153#endif /* defined(HAVE_SETSID) */
3154
3155#if defined(HAVE_SETPGID)
3156
3157PyDoc_STRVAR(os_setpgid__doc__,
3158"setpgid($module, pid, pgrp, /)\n"
3159"--\n"
3160"\n"
3161"Call the system call setpgid(pid, pgrp).");
3162
3163#define OS_SETPGID_METHODDEF \
3164 {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
3165
3166static PyObject *
3167os_setpgid_impl(PyModuleDef *module, pid_t pid, pid_t pgrp);
3168
3169static PyObject *
3170os_setpgid(PyModuleDef *module, PyObject *args)
3171{
3172 PyObject *return_value = NULL;
3173 pid_t pid;
3174 pid_t pgrp;
3175
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003176 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003177 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003178 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003179 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003180 return_value = os_setpgid_impl(module, pid, pgrp);
3181
3182exit:
3183 return return_value;
3184}
3185
3186#endif /* defined(HAVE_SETPGID) */
3187
3188#if defined(HAVE_TCGETPGRP)
3189
3190PyDoc_STRVAR(os_tcgetpgrp__doc__,
3191"tcgetpgrp($module, fd, /)\n"
3192"--\n"
3193"\n"
3194"Return the process group associated with the terminal specified by fd.");
3195
3196#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003197 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003198
3199static PyObject *
3200os_tcgetpgrp_impl(PyModuleDef *module, int fd);
3201
3202static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003203os_tcgetpgrp(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003204{
3205 PyObject *return_value = NULL;
3206 int fd;
3207
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003208 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003210 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003211 return_value = os_tcgetpgrp_impl(module, fd);
3212
3213exit:
3214 return return_value;
3215}
3216
3217#endif /* defined(HAVE_TCGETPGRP) */
3218
3219#if defined(HAVE_TCSETPGRP)
3220
3221PyDoc_STRVAR(os_tcsetpgrp__doc__,
3222"tcsetpgrp($module, fd, pgid, /)\n"
3223"--\n"
3224"\n"
3225"Set the process group associated with the terminal specified by fd.");
3226
3227#define OS_TCSETPGRP_METHODDEF \
3228 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
3229
3230static PyObject *
3231os_tcsetpgrp_impl(PyModuleDef *module, int fd, pid_t pgid);
3232
3233static PyObject *
3234os_tcsetpgrp(PyModuleDef *module, PyObject *args)
3235{
3236 PyObject *return_value = NULL;
3237 int fd;
3238 pid_t pgid;
3239
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003240 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003241 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003242 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003243 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003244 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3245
3246exit:
3247 return return_value;
3248}
3249
3250#endif /* defined(HAVE_TCSETPGRP) */
3251
3252PyDoc_STRVAR(os_open__doc__,
3253"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3254"--\n"
3255"\n"
3256"Open a file for low level IO. Returns a file descriptor (integer).\n"
3257"\n"
3258"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3259" and path should be relative; path will then be relative to that directory.\n"
3260"dir_fd may not be implemented on your platform.\n"
3261" If it is unavailable, using it will raise a NotImplementedError.");
3262
3263#define OS_OPEN_METHODDEF \
3264 {"open", (PyCFunction)os_open, METH_VARARGS|METH_KEYWORDS, os_open__doc__},
3265
3266static int
Larry Hastings89964c42015-04-14 18:07:59 -04003267os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode,
3268 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003269
3270static PyObject *
3271os_open(PyModuleDef *module, PyObject *args, PyObject *kwargs)
3272{
3273 PyObject *return_value = NULL;
3274 static char *_keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3275 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3276 int flags;
3277 int mode = 511;
3278 int dir_fd = DEFAULT_DIR_FD;
3279 int _return_value;
3280
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003281 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|i$O&:open", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003282 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003286 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003287 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003288 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003289 return_value = PyLong_FromLong((long)_return_value);
3290
3291exit:
3292 /* Cleanup for path */
3293 path_cleanup(&path);
3294
3295 return return_value;
3296}
3297
3298PyDoc_STRVAR(os_close__doc__,
3299"close($module, /, fd)\n"
3300"--\n"
3301"\n"
3302"Close a file descriptor.");
3303
3304#define OS_CLOSE_METHODDEF \
3305 {"close", (PyCFunction)os_close, METH_VARARGS|METH_KEYWORDS, os_close__doc__},
3306
3307static PyObject *
3308os_close_impl(PyModuleDef *module, int fd);
3309
3310static PyObject *
3311os_close(PyModuleDef *module, PyObject *args, PyObject *kwargs)
3312{
3313 PyObject *return_value = NULL;
3314 static char *_keywords[] = {"fd", NULL};
3315 int fd;
3316
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003317 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:close", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003318 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003319 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003320 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003321 return_value = os_close_impl(module, fd);
3322
3323exit:
3324 return return_value;
3325}
3326
3327PyDoc_STRVAR(os_closerange__doc__,
3328"closerange($module, fd_low, fd_high, /)\n"
3329"--\n"
3330"\n"
3331"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3332
3333#define OS_CLOSERANGE_METHODDEF \
3334 {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
3335
3336static PyObject *
3337os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high);
3338
3339static PyObject *
3340os_closerange(PyModuleDef *module, PyObject *args)
3341{
3342 PyObject *return_value = NULL;
3343 int fd_low;
3344 int fd_high;
3345
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003346 if (!PyArg_ParseTuple(args, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003347 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003348 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003349 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003350 return_value = os_closerange_impl(module, fd_low, fd_high);
3351
3352exit:
3353 return return_value;
3354}
3355
3356PyDoc_STRVAR(os_dup__doc__,
3357"dup($module, fd, /)\n"
3358"--\n"
3359"\n"
3360"Return a duplicate of a file descriptor.");
3361
3362#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003363 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003364
3365static int
3366os_dup_impl(PyModuleDef *module, int fd);
3367
3368static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003369os_dup(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003370{
3371 PyObject *return_value = NULL;
3372 int fd;
3373 int _return_value;
3374
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003375 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003376 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003377 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003379 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003380 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003381 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003382 return_value = PyLong_FromLong((long)_return_value);
3383
3384exit:
3385 return return_value;
3386}
3387
3388PyDoc_STRVAR(os_dup2__doc__,
3389"dup2($module, /, fd, fd2, inheritable=True)\n"
3390"--\n"
3391"\n"
3392"Duplicate file descriptor.");
3393
3394#define OS_DUP2_METHODDEF \
3395 {"dup2", (PyCFunction)os_dup2, METH_VARARGS|METH_KEYWORDS, os_dup2__doc__},
3396
3397static PyObject *
3398os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable);
3399
3400static PyObject *
3401os_dup2(PyModuleDef *module, PyObject *args, PyObject *kwargs)
3402{
3403 PyObject *return_value = NULL;
3404 static char *_keywords[] = {"fd", "fd2", "inheritable", NULL};
3405 int fd;
3406 int fd2;
3407 int inheritable = 1;
3408
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003409 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|p:dup2", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003410 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003412 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003413 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3414
3415exit:
3416 return return_value;
3417}
3418
3419#if defined(HAVE_LOCKF)
3420
3421PyDoc_STRVAR(os_lockf__doc__,
3422"lockf($module, fd, command, length, /)\n"
3423"--\n"
3424"\n"
3425"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3426"\n"
3427" fd\n"
3428" An open file descriptor.\n"
3429" command\n"
3430" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3431" length\n"
3432" The number of bytes to lock, starting at the current position.");
3433
3434#define OS_LOCKF_METHODDEF \
3435 {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
3436
3437static PyObject *
3438os_lockf_impl(PyModuleDef *module, int fd, int command, Py_off_t length);
3439
3440static PyObject *
3441os_lockf(PyModuleDef *module, PyObject *args)
3442{
3443 PyObject *return_value = NULL;
3444 int fd;
3445 int command;
3446 Py_off_t length;
3447
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003448 if (!PyArg_ParseTuple(args, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003449 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003450 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003451 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003452 return_value = os_lockf_impl(module, fd, command, length);
3453
3454exit:
3455 return return_value;
3456}
3457
3458#endif /* defined(HAVE_LOCKF) */
3459
3460PyDoc_STRVAR(os_lseek__doc__,
3461"lseek($module, fd, position, how, /)\n"
3462"--\n"
3463"\n"
3464"Set the position of a file descriptor. Return the new position.\n"
3465"\n"
3466"Return the new cursor position in number of bytes\n"
3467"relative to the beginning of the file.");
3468
3469#define OS_LSEEK_METHODDEF \
3470 {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
3471
3472static Py_off_t
3473os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how);
3474
3475static PyObject *
3476os_lseek(PyModuleDef *module, PyObject *args)
3477{
3478 PyObject *return_value = NULL;
3479 int fd;
3480 Py_off_t position;
3481 int how;
3482 Py_off_t _return_value;
3483
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003484 if (!PyArg_ParseTuple(args, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003485 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003486 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003487 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003488 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003489 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003490 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003491 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003492 return_value = PyLong_FromPy_off_t(_return_value);
3493
3494exit:
3495 return return_value;
3496}
3497
3498PyDoc_STRVAR(os_read__doc__,
3499"read($module, fd, length, /)\n"
3500"--\n"
3501"\n"
3502"Read from a file descriptor. Returns a bytes object.");
3503
3504#define OS_READ_METHODDEF \
3505 {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
3506
3507static PyObject *
3508os_read_impl(PyModuleDef *module, int fd, Py_ssize_t length);
3509
3510static PyObject *
3511os_read(PyModuleDef *module, PyObject *args)
3512{
3513 PyObject *return_value = NULL;
3514 int fd;
3515 Py_ssize_t length;
3516
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003517 if (!PyArg_ParseTuple(args, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003518 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003519 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003520 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003521 return_value = os_read_impl(module, fd, length);
3522
3523exit:
3524 return return_value;
3525}
3526
3527#if defined(HAVE_READV)
3528
3529PyDoc_STRVAR(os_readv__doc__,
3530"readv($module, fd, buffers, /)\n"
3531"--\n"
3532"\n"
3533"Read from a file descriptor fd into an iterable of buffers.\n"
3534"\n"
3535"The buffers should be mutable buffers accepting bytes.\n"
3536"readv will transfer data into each buffer until it is full\n"
3537"and then move on to the next buffer in the sequence to hold\n"
3538"the rest of the data.\n"
3539"\n"
3540"readv returns the total number of bytes read,\n"
3541"which may be less than the total capacity of all the buffers.");
3542
3543#define OS_READV_METHODDEF \
3544 {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
3545
3546static Py_ssize_t
3547os_readv_impl(PyModuleDef *module, int fd, PyObject *buffers);
3548
3549static PyObject *
3550os_readv(PyModuleDef *module, PyObject *args)
3551{
3552 PyObject *return_value = NULL;
3553 int fd;
3554 PyObject *buffers;
3555 Py_ssize_t _return_value;
3556
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003557 if (!PyArg_ParseTuple(args, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003558 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003559 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003560 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003561 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003562 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003563 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003564 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003565 return_value = PyLong_FromSsize_t(_return_value);
3566
3567exit:
3568 return return_value;
3569}
3570
3571#endif /* defined(HAVE_READV) */
3572
3573#if defined(HAVE_PREAD)
3574
3575PyDoc_STRVAR(os_pread__doc__,
3576"pread($module, fd, length, offset, /)\n"
3577"--\n"
3578"\n"
3579"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3580"\n"
3581"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3582"the beginning of the file. The file offset remains unchanged.");
3583
3584#define OS_PREAD_METHODDEF \
3585 {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
3586
3587static PyObject *
3588os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset);
3589
3590static PyObject *
3591os_pread(PyModuleDef *module, PyObject *args)
3592{
3593 PyObject *return_value = NULL;
3594 int fd;
3595 int length;
3596 Py_off_t offset;
3597
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003598 if (!PyArg_ParseTuple(args, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003599 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003600 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003601 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003602 return_value = os_pread_impl(module, fd, length, offset);
3603
3604exit:
3605 return return_value;
3606}
3607
3608#endif /* defined(HAVE_PREAD) */
3609
3610PyDoc_STRVAR(os_write__doc__,
3611"write($module, fd, data, /)\n"
3612"--\n"
3613"\n"
3614"Write a bytes object to a file descriptor.");
3615
3616#define OS_WRITE_METHODDEF \
3617 {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
3618
3619static Py_ssize_t
3620os_write_impl(PyModuleDef *module, int fd, Py_buffer *data);
3621
3622static PyObject *
3623os_write(PyModuleDef *module, PyObject *args)
3624{
3625 PyObject *return_value = NULL;
3626 int fd;
3627 Py_buffer data = {NULL, NULL};
3628 Py_ssize_t _return_value;
3629
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003630 if (!PyArg_ParseTuple(args, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003631 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003632 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003633 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003634 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003635 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003636 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003637 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003638 return_value = PyLong_FromSsize_t(_return_value);
3639
3640exit:
3641 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003642 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003643 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003644 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003645
3646 return return_value;
3647}
3648
3649PyDoc_STRVAR(os_fstat__doc__,
3650"fstat($module, /, fd)\n"
3651"--\n"
3652"\n"
3653"Perform a stat system call on the given file descriptor.\n"
3654"\n"
3655"Like stat(), but for an open file descriptor.\n"
3656"Equivalent to os.stat(fd).");
3657
3658#define OS_FSTAT_METHODDEF \
3659 {"fstat", (PyCFunction)os_fstat, METH_VARARGS|METH_KEYWORDS, os_fstat__doc__},
3660
3661static PyObject *
3662os_fstat_impl(PyModuleDef *module, int fd);
3663
3664static PyObject *
3665os_fstat(PyModuleDef *module, PyObject *args, PyObject *kwargs)
3666{
3667 PyObject *return_value = NULL;
3668 static char *_keywords[] = {"fd", NULL};
3669 int fd;
3670
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003671 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:fstat", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003672 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003673 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003674 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003675 return_value = os_fstat_impl(module, fd);
3676
3677exit:
3678 return return_value;
3679}
3680
3681PyDoc_STRVAR(os_isatty__doc__,
3682"isatty($module, fd, /)\n"
3683"--\n"
3684"\n"
3685"Return True if the fd is connected to a terminal.\n"
3686"\n"
3687"Return True if the file descriptor is an open file descriptor\n"
3688"connected to the slave end of a terminal.");
3689
3690#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003691 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003692
3693static int
3694os_isatty_impl(PyModuleDef *module, int fd);
3695
3696static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003697os_isatty(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003698{
3699 PyObject *return_value = NULL;
3700 int fd;
3701 int _return_value;
3702
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003703 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003704 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003705 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003706 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003707 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003708 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003709 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003710 return_value = PyBool_FromLong((long)_return_value);
3711
3712exit:
3713 return return_value;
3714}
3715
3716#if defined(HAVE_PIPE)
3717
3718PyDoc_STRVAR(os_pipe__doc__,
3719"pipe($module, /)\n"
3720"--\n"
3721"\n"
3722"Create a pipe.\n"
3723"\n"
3724"Returns a tuple of two file descriptors:\n"
3725" (read_fd, write_fd)");
3726
3727#define OS_PIPE_METHODDEF \
3728 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3729
3730static PyObject *
3731os_pipe_impl(PyModuleDef *module);
3732
3733static PyObject *
3734os_pipe(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
3735{
3736 return os_pipe_impl(module);
3737}
3738
3739#endif /* defined(HAVE_PIPE) */
3740
3741#if defined(HAVE_PIPE2)
3742
3743PyDoc_STRVAR(os_pipe2__doc__,
3744"pipe2($module, flags, /)\n"
3745"--\n"
3746"\n"
3747"Create a pipe with flags set atomically.\n"
3748"\n"
3749"Returns a tuple of two file descriptors:\n"
3750" (read_fd, write_fd)\n"
3751"\n"
3752"flags can be constructed by ORing together one or more of these values:\n"
3753"O_NONBLOCK, O_CLOEXEC.");
3754
3755#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003756 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003757
3758static PyObject *
3759os_pipe2_impl(PyModuleDef *module, int flags);
3760
3761static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003762os_pipe2(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003763{
3764 PyObject *return_value = NULL;
3765 int flags;
3766
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003767 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003768 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003769 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003770 return_value = os_pipe2_impl(module, flags);
3771
3772exit:
3773 return return_value;
3774}
3775
3776#endif /* defined(HAVE_PIPE2) */
3777
3778#if defined(HAVE_WRITEV)
3779
3780PyDoc_STRVAR(os_writev__doc__,
3781"writev($module, fd, buffers, /)\n"
3782"--\n"
3783"\n"
3784"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3785"\n"
3786"Returns the total number of bytes written.\n"
3787"buffers must be a sequence of bytes-like objects.");
3788
3789#define OS_WRITEV_METHODDEF \
3790 {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
3791
3792static Py_ssize_t
3793os_writev_impl(PyModuleDef *module, int fd, PyObject *buffers);
3794
3795static PyObject *
3796os_writev(PyModuleDef *module, PyObject *args)
3797{
3798 PyObject *return_value = NULL;
3799 int fd;
3800 PyObject *buffers;
3801 Py_ssize_t _return_value;
3802
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003803 if (!PyArg_ParseTuple(args, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003804 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003805 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003806 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003807 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003808 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003809 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003810 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003811 return_value = PyLong_FromSsize_t(_return_value);
3812
3813exit:
3814 return return_value;
3815}
3816
3817#endif /* defined(HAVE_WRITEV) */
3818
3819#if defined(HAVE_PWRITE)
3820
3821PyDoc_STRVAR(os_pwrite__doc__,
3822"pwrite($module, fd, buffer, offset, /)\n"
3823"--\n"
3824"\n"
3825"Write bytes to a file descriptor starting at a particular offset.\n"
3826"\n"
3827"Write buffer to fd, starting at offset bytes from the beginning of\n"
3828"the file. Returns the number of bytes writte. Does not change the\n"
3829"current file offset.");
3830
3831#define OS_PWRITE_METHODDEF \
3832 {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
3833
3834static Py_ssize_t
Larry Hastings89964c42015-04-14 18:07:59 -04003835os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer,
3836 Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003837
3838static PyObject *
3839os_pwrite(PyModuleDef *module, PyObject *args)
3840{
3841 PyObject *return_value = NULL;
3842 int fd;
3843 Py_buffer buffer = {NULL, NULL};
3844 Py_off_t offset;
3845 Py_ssize_t _return_value;
3846
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003847 if (!PyArg_ParseTuple(args, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003848 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003849 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003850 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003851 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003852 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003853 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003854 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003855 return_value = PyLong_FromSsize_t(_return_value);
3856
3857exit:
3858 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003859 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003860 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003861 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003862
3863 return return_value;
3864}
3865
3866#endif /* defined(HAVE_PWRITE) */
3867
3868#if defined(HAVE_MKFIFO)
3869
3870PyDoc_STRVAR(os_mkfifo__doc__,
3871"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3872"--\n"
3873"\n"
3874"Create a \"fifo\" (a POSIX named pipe).\n"
3875"\n"
3876"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3877" and path should be relative; path will then be relative to that directory.\n"
3878"dir_fd may not be implemented on your platform.\n"
3879" If it is unavailable, using it will raise a NotImplementedError.");
3880
3881#define OS_MKFIFO_METHODDEF \
3882 {"mkfifo", (PyCFunction)os_mkfifo, METH_VARARGS|METH_KEYWORDS, os_mkfifo__doc__},
3883
3884static PyObject *
3885os_mkfifo_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd);
3886
3887static PyObject *
3888os_mkfifo(PyModuleDef *module, PyObject *args, PyObject *kwargs)
3889{
3890 PyObject *return_value = NULL;
3891 static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
3892 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3893 int mode = 438;
3894 int dir_fd = DEFAULT_DIR_FD;
3895
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003896 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkfifo", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003897 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003898 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003899 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003900 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3901
3902exit:
3903 /* Cleanup for path */
3904 path_cleanup(&path);
3905
3906 return return_value;
3907}
3908
3909#endif /* defined(HAVE_MKFIFO) */
3910
3911#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
3912
3913PyDoc_STRVAR(os_mknod__doc__,
3914"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
3915"--\n"
3916"\n"
3917"Create a node in the file system.\n"
3918"\n"
3919"Create a node in the file system (file, device special file or named pipe)\n"
3920"at path. mode specifies both the permissions to use and the\n"
3921"type of node to be created, being combined (bitwise OR) with one of\n"
3922"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
3923"device defines the newly created device special file (probably using\n"
3924"os.makedev()). Otherwise device is ignored.\n"
3925"\n"
3926"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3927" and path should be relative; path will then be relative to that directory.\n"
3928"dir_fd may not be implemented on your platform.\n"
3929" If it is unavailable, using it will raise a NotImplementedError.");
3930
3931#define OS_MKNOD_METHODDEF \
3932 {"mknod", (PyCFunction)os_mknod, METH_VARARGS|METH_KEYWORDS, os_mknod__doc__},
3933
3934static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04003935os_mknod_impl(PyModuleDef *module, path_t *path, int mode, dev_t device,
3936 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003937
3938static PyObject *
3939os_mknod(PyModuleDef *module, PyObject *args, PyObject *kwargs)
3940{
3941 PyObject *return_value = NULL;
3942 static char *_keywords[] = {"path", "mode", "device", "dir_fd", NULL};
3943 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
3944 int mode = 384;
3945 dev_t device = 0;
3946 int dir_fd = DEFAULT_DIR_FD;
3947
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003948 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|iO&$O&:mknod", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003949 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003951 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003952 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
3953
3954exit:
3955 /* Cleanup for path */
3956 path_cleanup(&path);
3957
3958 return return_value;
3959}
3960
3961#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
3962
3963#if defined(HAVE_DEVICE_MACROS)
3964
3965PyDoc_STRVAR(os_major__doc__,
3966"major($module, device, /)\n"
3967"--\n"
3968"\n"
3969"Extracts a device major number from a raw device number.");
3970
3971#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003972 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003973
3974static unsigned int
3975os_major_impl(PyModuleDef *module, dev_t device);
3976
3977static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003978os_major(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003979{
3980 PyObject *return_value = NULL;
3981 dev_t device;
3982 unsigned int _return_value;
3983
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003984 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003985 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003986 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003987 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003988 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003989 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003990 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003991 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
3992
3993exit:
3994 return return_value;
3995}
3996
3997#endif /* defined(HAVE_DEVICE_MACROS) */
3998
3999#if defined(HAVE_DEVICE_MACROS)
4000
4001PyDoc_STRVAR(os_minor__doc__,
4002"minor($module, device, /)\n"
4003"--\n"
4004"\n"
4005"Extracts a device minor number from a raw device number.");
4006
4007#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004008 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004009
4010static unsigned int
4011os_minor_impl(PyModuleDef *module, dev_t device);
4012
4013static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004014os_minor(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004015{
4016 PyObject *return_value = NULL;
4017 dev_t device;
4018 unsigned int _return_value;
4019
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004020 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004021 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004022 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004023 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004024 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004026 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004027 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4028
4029exit:
4030 return return_value;
4031}
4032
4033#endif /* defined(HAVE_DEVICE_MACROS) */
4034
4035#if defined(HAVE_DEVICE_MACROS)
4036
4037PyDoc_STRVAR(os_makedev__doc__,
4038"makedev($module, major, minor, /)\n"
4039"--\n"
4040"\n"
4041"Composes a raw device number from the major and minor device numbers.");
4042
4043#define OS_MAKEDEV_METHODDEF \
4044 {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
4045
4046static dev_t
4047os_makedev_impl(PyModuleDef *module, int major, int minor);
4048
4049static PyObject *
4050os_makedev(PyModuleDef *module, PyObject *args)
4051{
4052 PyObject *return_value = NULL;
4053 int major;
4054 int minor;
4055 dev_t _return_value;
4056
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004057 if (!PyArg_ParseTuple(args, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004058 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004059 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004060 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004061 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004062 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004063 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004064 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004065 return_value = _PyLong_FromDev(_return_value);
4066
4067exit:
4068 return return_value;
4069}
4070
4071#endif /* defined(HAVE_DEVICE_MACROS) */
4072
Steve Dowerf7377032015-04-12 15:44:54 -04004073#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074
4075PyDoc_STRVAR(os_ftruncate__doc__,
4076"ftruncate($module, fd, length, /)\n"
4077"--\n"
4078"\n"
4079"Truncate a file, specified by file descriptor, to a specific length.");
4080
4081#define OS_FTRUNCATE_METHODDEF \
4082 {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
4083
4084static PyObject *
4085os_ftruncate_impl(PyModuleDef *module, int fd, Py_off_t length);
4086
4087static PyObject *
4088os_ftruncate(PyModuleDef *module, PyObject *args)
4089{
4090 PyObject *return_value = NULL;
4091 int fd;
4092 Py_off_t length;
4093
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004094 if (!PyArg_ParseTuple(args, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004095 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004096 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004097 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004098 return_value = os_ftruncate_impl(module, fd, length);
4099
4100exit:
4101 return return_value;
4102}
4103
Steve Dowerf7377032015-04-12 15:44:54 -04004104#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004105
Steve Dowerf7377032015-04-12 15:44:54 -04004106#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004107
4108PyDoc_STRVAR(os_truncate__doc__,
4109"truncate($module, /, path, length)\n"
4110"--\n"
4111"\n"
4112"Truncate a file, specified by path, to a specific length.\n"
4113"\n"
4114"On some platforms, path may also be specified as an open file descriptor.\n"
4115" If this functionality is unavailable, using it raises an exception.");
4116
4117#define OS_TRUNCATE_METHODDEF \
4118 {"truncate", (PyCFunction)os_truncate, METH_VARARGS|METH_KEYWORDS, os_truncate__doc__},
4119
4120static PyObject *
4121os_truncate_impl(PyModuleDef *module, path_t *path, Py_off_t length);
4122
4123static PyObject *
4124os_truncate(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4125{
4126 PyObject *return_value = NULL;
4127 static char *_keywords[] = {"path", "length", NULL};
4128 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4129 Py_off_t length;
4130
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004131 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:truncate", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004132 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004133 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004134 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004135 return_value = os_truncate_impl(module, &path, length);
4136
4137exit:
4138 /* Cleanup for path */
4139 path_cleanup(&path);
4140
4141 return return_value;
4142}
4143
Steve Dowerf7377032015-04-12 15:44:54 -04004144#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004145
4146#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4147
4148PyDoc_STRVAR(os_posix_fallocate__doc__,
4149"posix_fallocate($module, fd, offset, length, /)\n"
4150"--\n"
4151"\n"
4152"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4153"\n"
4154"Ensure that the file specified by fd encompasses a range of bytes\n"
4155"starting at offset bytes from the beginning and continuing for length bytes.");
4156
4157#define OS_POSIX_FALLOCATE_METHODDEF \
4158 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
4159
4160static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04004161os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset,
4162 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004163
4164static PyObject *
4165os_posix_fallocate(PyModuleDef *module, PyObject *args)
4166{
4167 PyObject *return_value = NULL;
4168 int fd;
4169 Py_off_t offset;
4170 Py_off_t length;
4171
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004172 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004173 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004174 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004175 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004176 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4177
4178exit:
4179 return return_value;
4180}
4181
4182#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4183
4184#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4185
4186PyDoc_STRVAR(os_posix_fadvise__doc__,
4187"posix_fadvise($module, fd, offset, length, advice, /)\n"
4188"--\n"
4189"\n"
4190"Announce an intention to access data in a specific pattern.\n"
4191"\n"
4192"Announce an intention to access data in a specific pattern, thus allowing\n"
4193"the kernel to make optimizations.\n"
4194"The advice applies to the region of the file specified by fd starting at\n"
4195"offset and continuing for length bytes.\n"
4196"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4197"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4198"POSIX_FADV_DONTNEED.");
4199
4200#define OS_POSIX_FADVISE_METHODDEF \
4201 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
4202
4203static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04004204os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset,
4205 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004206
4207static PyObject *
4208os_posix_fadvise(PyModuleDef *module, PyObject *args)
4209{
4210 PyObject *return_value = NULL;
4211 int fd;
4212 Py_off_t offset;
4213 Py_off_t length;
4214 int advice;
4215
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004216 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004217 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004218 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004219 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004220 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4221
4222exit:
4223 return return_value;
4224}
4225
4226#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4227
4228#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4229
4230PyDoc_STRVAR(os_putenv__doc__,
4231"putenv($module, name, value, /)\n"
4232"--\n"
4233"\n"
4234"Change or add an environment variable.");
4235
4236#define OS_PUTENV_METHODDEF \
4237 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4238
4239static PyObject *
4240os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value);
4241
4242static PyObject *
4243os_putenv(PyModuleDef *module, PyObject *args)
4244{
4245 PyObject *return_value = NULL;
4246 PyObject *name;
4247 PyObject *value;
4248
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004249 if (!PyArg_ParseTuple(args, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004250 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004251 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004252 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004253 return_value = os_putenv_impl(module, name, value);
4254
4255exit:
4256 return return_value;
4257}
4258
4259#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4260
4261#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4262
4263PyDoc_STRVAR(os_putenv__doc__,
4264"putenv($module, name, value, /)\n"
4265"--\n"
4266"\n"
4267"Change or add an environment variable.");
4268
4269#define OS_PUTENV_METHODDEF \
4270 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4271
4272static PyObject *
4273os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value);
4274
4275static PyObject *
4276os_putenv(PyModuleDef *module, PyObject *args)
4277{
4278 PyObject *return_value = NULL;
4279 PyObject *name = NULL;
4280 PyObject *value = NULL;
4281
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004282 if (!PyArg_ParseTuple(args, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004283 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004284 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004285 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004286 return_value = os_putenv_impl(module, name, value);
4287
4288exit:
4289 /* Cleanup for name */
4290 Py_XDECREF(name);
4291 /* Cleanup for value */
4292 Py_XDECREF(value);
4293
4294 return return_value;
4295}
4296
4297#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4298
4299#if defined(HAVE_UNSETENV)
4300
4301PyDoc_STRVAR(os_unsetenv__doc__,
4302"unsetenv($module, name, /)\n"
4303"--\n"
4304"\n"
4305"Delete an environment variable.");
4306
4307#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004308 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004309
4310static PyObject *
4311os_unsetenv_impl(PyModuleDef *module, PyObject *name);
4312
4313static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004314os_unsetenv(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004315{
4316 PyObject *return_value = NULL;
4317 PyObject *name = NULL;
4318
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004319 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004320 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004321 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004322 return_value = os_unsetenv_impl(module, name);
4323
4324exit:
4325 /* Cleanup for name */
4326 Py_XDECREF(name);
4327
4328 return return_value;
4329}
4330
4331#endif /* defined(HAVE_UNSETENV) */
4332
4333PyDoc_STRVAR(os_strerror__doc__,
4334"strerror($module, code, /)\n"
4335"--\n"
4336"\n"
4337"Translate an error code to a message string.");
4338
4339#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004340 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004341
4342static PyObject *
4343os_strerror_impl(PyModuleDef *module, int code);
4344
4345static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004346os_strerror(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004347{
4348 PyObject *return_value = NULL;
4349 int code;
4350
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004351 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004352 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004354 return_value = os_strerror_impl(module, code);
4355
4356exit:
4357 return return_value;
4358}
4359
4360#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4361
4362PyDoc_STRVAR(os_WCOREDUMP__doc__,
4363"WCOREDUMP($module, status, /)\n"
4364"--\n"
4365"\n"
4366"Return True if the process returning status was dumped to a core file.");
4367
4368#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004369 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370
4371static int
4372os_WCOREDUMP_impl(PyModuleDef *module, int status);
4373
4374static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004375os_WCOREDUMP(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004376{
4377 PyObject *return_value = NULL;
4378 int status;
4379 int _return_value;
4380
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004381 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004382 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004383 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004384 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004385 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004386 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004387 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004388 return_value = PyBool_FromLong((long)_return_value);
4389
4390exit:
4391 return return_value;
4392}
4393
4394#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4395
4396#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4397
4398PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4399"WIFCONTINUED($module, /, status)\n"
4400"--\n"
4401"\n"
4402"Return True if a particular process was continued from a job control stop.\n"
4403"\n"
4404"Return True if the process returning status was continued from a\n"
4405"job control stop.");
4406
4407#define OS_WIFCONTINUED_METHODDEF \
4408 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_VARARGS|METH_KEYWORDS, os_WIFCONTINUED__doc__},
4409
4410static int
4411os_WIFCONTINUED_impl(PyModuleDef *module, int status);
4412
4413static PyObject *
4414os_WIFCONTINUED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4415{
4416 PyObject *return_value = NULL;
4417 static char *_keywords[] = {"status", NULL};
4418 int status;
4419 int _return_value;
4420
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004421 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFCONTINUED", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004422 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004423 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004424 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004425 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004426 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004427 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004428 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004429 return_value = PyBool_FromLong((long)_return_value);
4430
4431exit:
4432 return return_value;
4433}
4434
4435#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4436
4437#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4438
4439PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4440"WIFSTOPPED($module, /, status)\n"
4441"--\n"
4442"\n"
4443"Return True if the process returning status was stopped.");
4444
4445#define OS_WIFSTOPPED_METHODDEF \
4446 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_VARARGS|METH_KEYWORDS, os_WIFSTOPPED__doc__},
4447
4448static int
4449os_WIFSTOPPED_impl(PyModuleDef *module, int status);
4450
4451static PyObject *
4452os_WIFSTOPPED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4453{
4454 PyObject *return_value = NULL;
4455 static char *_keywords[] = {"status", NULL};
4456 int status;
4457 int _return_value;
4458
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004459 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFSTOPPED", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004460 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004462 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004463 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004464 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004465 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004466 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004467 return_value = PyBool_FromLong((long)_return_value);
4468
4469exit:
4470 return return_value;
4471}
4472
4473#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4474
4475#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4476
4477PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4478"WIFSIGNALED($module, /, status)\n"
4479"--\n"
4480"\n"
4481"Return True if the process returning status was terminated by a signal.");
4482
4483#define OS_WIFSIGNALED_METHODDEF \
4484 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_VARARGS|METH_KEYWORDS, os_WIFSIGNALED__doc__},
4485
4486static int
4487os_WIFSIGNALED_impl(PyModuleDef *module, int status);
4488
4489static PyObject *
4490os_WIFSIGNALED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4491{
4492 PyObject *return_value = NULL;
4493 static char *_keywords[] = {"status", NULL};
4494 int status;
4495 int _return_value;
4496
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004497 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFSIGNALED", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004498 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004499 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004500 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004501 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004502 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004503 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004504 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004505 return_value = PyBool_FromLong((long)_return_value);
4506
4507exit:
4508 return return_value;
4509}
4510
4511#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4512
4513#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4514
4515PyDoc_STRVAR(os_WIFEXITED__doc__,
4516"WIFEXITED($module, /, status)\n"
4517"--\n"
4518"\n"
4519"Return True if the process returning status exited via the exit() system call.");
4520
4521#define OS_WIFEXITED_METHODDEF \
4522 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_VARARGS|METH_KEYWORDS, os_WIFEXITED__doc__},
4523
4524static int
4525os_WIFEXITED_impl(PyModuleDef *module, int status);
4526
4527static PyObject *
4528os_WIFEXITED(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4529{
4530 PyObject *return_value = NULL;
4531 static char *_keywords[] = {"status", NULL};
4532 int status;
4533 int _return_value;
4534
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004535 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFEXITED", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004536 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004537 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004538 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004539 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004540 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004541 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004542 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004543 return_value = PyBool_FromLong((long)_return_value);
4544
4545exit:
4546 return return_value;
4547}
4548
4549#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4550
4551#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4552
4553PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4554"WEXITSTATUS($module, /, status)\n"
4555"--\n"
4556"\n"
4557"Return the process return code from status.");
4558
4559#define OS_WEXITSTATUS_METHODDEF \
4560 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_VARARGS|METH_KEYWORDS, os_WEXITSTATUS__doc__},
4561
4562static int
4563os_WEXITSTATUS_impl(PyModuleDef *module, int status);
4564
4565static PyObject *
4566os_WEXITSTATUS(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4567{
4568 PyObject *return_value = NULL;
4569 static char *_keywords[] = {"status", NULL};
4570 int status;
4571 int _return_value;
4572
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004573 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WEXITSTATUS", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004574 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004575 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004576 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004577 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004578 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004579 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004580 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004581 return_value = PyLong_FromLong((long)_return_value);
4582
4583exit:
4584 return return_value;
4585}
4586
4587#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4588
4589#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4590
4591PyDoc_STRVAR(os_WTERMSIG__doc__,
4592"WTERMSIG($module, /, status)\n"
4593"--\n"
4594"\n"
4595"Return the signal that terminated the process that provided the status value.");
4596
4597#define OS_WTERMSIG_METHODDEF \
4598 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_VARARGS|METH_KEYWORDS, os_WTERMSIG__doc__},
4599
4600static int
4601os_WTERMSIG_impl(PyModuleDef *module, int status);
4602
4603static PyObject *
4604os_WTERMSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4605{
4606 PyObject *return_value = NULL;
4607 static char *_keywords[] = {"status", NULL};
4608 int status;
4609 int _return_value;
4610
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004611 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WTERMSIG", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004612 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004613 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004614 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004615 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004616 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004617 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004618 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004619 return_value = PyLong_FromLong((long)_return_value);
4620
4621exit:
4622 return return_value;
4623}
4624
4625#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4626
4627#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4628
4629PyDoc_STRVAR(os_WSTOPSIG__doc__,
4630"WSTOPSIG($module, /, status)\n"
4631"--\n"
4632"\n"
4633"Return the signal that stopped the process that provided the status value.");
4634
4635#define OS_WSTOPSIG_METHODDEF \
4636 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_VARARGS|METH_KEYWORDS, os_WSTOPSIG__doc__},
4637
4638static int
4639os_WSTOPSIG_impl(PyModuleDef *module, int status);
4640
4641static PyObject *
4642os_WSTOPSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4643{
4644 PyObject *return_value = NULL;
4645 static char *_keywords[] = {"status", NULL};
4646 int status;
4647 int _return_value;
4648
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004649 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WSTOPSIG", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004650 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004651 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004652 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004653 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004654 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004655 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004656 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004657 return_value = PyLong_FromLong((long)_return_value);
4658
4659exit:
4660 return return_value;
4661}
4662
4663#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4664
4665#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4666
4667PyDoc_STRVAR(os_fstatvfs__doc__,
4668"fstatvfs($module, fd, /)\n"
4669"--\n"
4670"\n"
4671"Perform an fstatvfs system call on the given fd.\n"
4672"\n"
4673"Equivalent to statvfs(fd).");
4674
4675#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004676 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004677
4678static PyObject *
4679os_fstatvfs_impl(PyModuleDef *module, int fd);
4680
4681static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004682os_fstatvfs(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004683{
4684 PyObject *return_value = NULL;
4685 int fd;
4686
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004687 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004688 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004689 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004690 return_value = os_fstatvfs_impl(module, fd);
4691
4692exit:
4693 return return_value;
4694}
4695
4696#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4697
4698#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4699
4700PyDoc_STRVAR(os_statvfs__doc__,
4701"statvfs($module, /, path)\n"
4702"--\n"
4703"\n"
4704"Perform a statvfs system call on the given path.\n"
4705"\n"
4706"path may always be specified as a string.\n"
4707"On some platforms, path may also be specified as an open file descriptor.\n"
4708" If this functionality is unavailable, using it raises an exception.");
4709
4710#define OS_STATVFS_METHODDEF \
4711 {"statvfs", (PyCFunction)os_statvfs, METH_VARARGS|METH_KEYWORDS, os_statvfs__doc__},
4712
4713static PyObject *
4714os_statvfs_impl(PyModuleDef *module, path_t *path);
4715
4716static PyObject *
4717os_statvfs(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4718{
4719 PyObject *return_value = NULL;
4720 static char *_keywords[] = {"path", NULL};
4721 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4722
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004723 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:statvfs", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004724 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004725 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004726 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004727 return_value = os_statvfs_impl(module, &path);
4728
4729exit:
4730 /* Cleanup for path */
4731 path_cleanup(&path);
4732
4733 return return_value;
4734}
4735
4736#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4737
4738#if defined(MS_WINDOWS)
4739
4740PyDoc_STRVAR(os__getdiskusage__doc__,
4741"_getdiskusage($module, /, path)\n"
4742"--\n"
4743"\n"
4744"Return disk usage statistics about the given path as a (total, free) tuple.");
4745
4746#define OS__GETDISKUSAGE_METHODDEF \
4747 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_VARARGS|METH_KEYWORDS, os__getdiskusage__doc__},
4748
4749static PyObject *
4750os__getdiskusage_impl(PyModuleDef *module, Py_UNICODE *path);
4751
4752static PyObject *
4753os__getdiskusage(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4754{
4755 PyObject *return_value = NULL;
4756 static char *_keywords[] = {"path", NULL};
4757 Py_UNICODE *path;
4758
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004759 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "u:_getdiskusage", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004760 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004761 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004762 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004763 return_value = os__getdiskusage_impl(module, path);
4764
4765exit:
4766 return return_value;
4767}
4768
4769#endif /* defined(MS_WINDOWS) */
4770
4771#if defined(HAVE_FPATHCONF)
4772
4773PyDoc_STRVAR(os_fpathconf__doc__,
4774"fpathconf($module, fd, name, /)\n"
4775"--\n"
4776"\n"
4777"Return the configuration limit name for the file descriptor fd.\n"
4778"\n"
4779"If there is no limit, return -1.");
4780
4781#define OS_FPATHCONF_METHODDEF \
4782 {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
4783
4784static long
4785os_fpathconf_impl(PyModuleDef *module, int fd, int name);
4786
4787static PyObject *
4788os_fpathconf(PyModuleDef *module, PyObject *args)
4789{
4790 PyObject *return_value = NULL;
4791 int fd;
4792 int name;
4793 long _return_value;
4794
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004795 if (!PyArg_ParseTuple(args, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004796 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004797 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004798 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004799 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004800 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004802 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004803 return_value = PyLong_FromLong(_return_value);
4804
4805exit:
4806 return return_value;
4807}
4808
4809#endif /* defined(HAVE_FPATHCONF) */
4810
4811#if defined(HAVE_PATHCONF)
4812
4813PyDoc_STRVAR(os_pathconf__doc__,
4814"pathconf($module, /, path, name)\n"
4815"--\n"
4816"\n"
4817"Return the configuration limit name for the file or directory path.\n"
4818"\n"
4819"If there is no limit, return -1.\n"
4820"On some platforms, path may also be specified as an open file descriptor.\n"
4821" If this functionality is unavailable, using it raises an exception.");
4822
4823#define OS_PATHCONF_METHODDEF \
4824 {"pathconf", (PyCFunction)os_pathconf, METH_VARARGS|METH_KEYWORDS, os_pathconf__doc__},
4825
4826static long
4827os_pathconf_impl(PyModuleDef *module, path_t *path, int name);
4828
4829static PyObject *
4830os_pathconf(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4831{
4832 PyObject *return_value = NULL;
4833 static char *_keywords[] = {"path", "name", NULL};
4834 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4835 int name;
4836 long _return_value;
4837
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004838 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:pathconf", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004839 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004841 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004842 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004843 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004844 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004845 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004846 return_value = PyLong_FromLong(_return_value);
4847
4848exit:
4849 /* Cleanup for path */
4850 path_cleanup(&path);
4851
4852 return return_value;
4853}
4854
4855#endif /* defined(HAVE_PATHCONF) */
4856
4857#if defined(HAVE_CONFSTR)
4858
4859PyDoc_STRVAR(os_confstr__doc__,
4860"confstr($module, name, /)\n"
4861"--\n"
4862"\n"
4863"Return a string-valued system configuration variable.");
4864
4865#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004866 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004867
4868static PyObject *
4869os_confstr_impl(PyModuleDef *module, int name);
4870
4871static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004872os_confstr(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004873{
4874 PyObject *return_value = NULL;
4875 int name;
4876
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004877 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004878 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004879 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004880 return_value = os_confstr_impl(module, name);
4881
4882exit:
4883 return return_value;
4884}
4885
4886#endif /* defined(HAVE_CONFSTR) */
4887
4888#if defined(HAVE_SYSCONF)
4889
4890PyDoc_STRVAR(os_sysconf__doc__,
4891"sysconf($module, name, /)\n"
4892"--\n"
4893"\n"
4894"Return an integer-valued system configuration variable.");
4895
4896#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004897 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004898
4899static long
4900os_sysconf_impl(PyModuleDef *module, int name);
4901
4902static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004903os_sysconf(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904{
4905 PyObject *return_value = NULL;
4906 int name;
4907 long _return_value;
4908
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004909 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004910 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004911 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004912 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004913 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004914 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004915 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004916 return_value = PyLong_FromLong(_return_value);
4917
4918exit:
4919 return return_value;
4920}
4921
4922#endif /* defined(HAVE_SYSCONF) */
4923
4924PyDoc_STRVAR(os_abort__doc__,
4925"abort($module, /)\n"
4926"--\n"
4927"\n"
4928"Abort the interpreter immediately.\n"
4929"\n"
4930"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
4931"on the hosting operating system. This function never returns.");
4932
4933#define OS_ABORT_METHODDEF \
4934 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
4935
4936static PyObject *
4937os_abort_impl(PyModuleDef *module);
4938
4939static PyObject *
4940os_abort(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
4941{
4942 return os_abort_impl(module);
4943}
4944
4945#if defined(HAVE_GETLOADAVG)
4946
4947PyDoc_STRVAR(os_getloadavg__doc__,
4948"getloadavg($module, /)\n"
4949"--\n"
4950"\n"
4951"Return average recent system load information.\n"
4952"\n"
4953"Return the number of processes in the system run queue averaged over\n"
4954"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
4955"Raises OSError if the load average was unobtainable.");
4956
4957#define OS_GETLOADAVG_METHODDEF \
4958 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
4959
4960static PyObject *
4961os_getloadavg_impl(PyModuleDef *module);
4962
4963static PyObject *
4964os_getloadavg(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
4965{
4966 return os_getloadavg_impl(module);
4967}
4968
4969#endif /* defined(HAVE_GETLOADAVG) */
4970
4971PyDoc_STRVAR(os_device_encoding__doc__,
4972"device_encoding($module, /, fd)\n"
4973"--\n"
4974"\n"
4975"Return a string describing the encoding of a terminal\'s file descriptor.\n"
4976"\n"
4977"The file descriptor must be attached to a terminal.\n"
4978"If the device is not a terminal, return None.");
4979
4980#define OS_DEVICE_ENCODING_METHODDEF \
4981 {"device_encoding", (PyCFunction)os_device_encoding, METH_VARARGS|METH_KEYWORDS, os_device_encoding__doc__},
4982
4983static PyObject *
4984os_device_encoding_impl(PyModuleDef *module, int fd);
4985
4986static PyObject *
4987os_device_encoding(PyModuleDef *module, PyObject *args, PyObject *kwargs)
4988{
4989 PyObject *return_value = NULL;
4990 static char *_keywords[] = {"fd", NULL};
4991 int fd;
4992
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004993 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:device_encoding", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004994 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004995 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004996 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004997 return_value = os_device_encoding_impl(module, fd);
4998
4999exit:
5000 return return_value;
5001}
5002
5003#if defined(HAVE_SETRESUID)
5004
5005PyDoc_STRVAR(os_setresuid__doc__,
5006"setresuid($module, ruid, euid, suid, /)\n"
5007"--\n"
5008"\n"
5009"Set the current process\'s real, effective, and saved user ids.");
5010
5011#define OS_SETRESUID_METHODDEF \
5012 {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
5013
5014static PyObject *
5015os_setresuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid, uid_t suid);
5016
5017static PyObject *
5018os_setresuid(PyModuleDef *module, PyObject *args)
5019{
5020 PyObject *return_value = NULL;
5021 uid_t ruid;
5022 uid_t euid;
5023 uid_t suid;
5024
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005025 if (!PyArg_ParseTuple(args, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005026 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005027 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005028 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005029 return_value = os_setresuid_impl(module, ruid, euid, suid);
5030
5031exit:
5032 return return_value;
5033}
5034
5035#endif /* defined(HAVE_SETRESUID) */
5036
5037#if defined(HAVE_SETRESGID)
5038
5039PyDoc_STRVAR(os_setresgid__doc__,
5040"setresgid($module, rgid, egid, sgid, /)\n"
5041"--\n"
5042"\n"
5043"Set the current process\'s real, effective, and saved group ids.");
5044
5045#define OS_SETRESGID_METHODDEF \
5046 {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
5047
5048static PyObject *
5049os_setresgid_impl(PyModuleDef *module, gid_t rgid, gid_t egid, gid_t sgid);
5050
5051static PyObject *
5052os_setresgid(PyModuleDef *module, PyObject *args)
5053{
5054 PyObject *return_value = NULL;
5055 gid_t rgid;
5056 gid_t egid;
5057 gid_t sgid;
5058
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005059 if (!PyArg_ParseTuple(args, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005060 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005061 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005062 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005063 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5064
5065exit:
5066 return return_value;
5067}
5068
5069#endif /* defined(HAVE_SETRESGID) */
5070
5071#if defined(HAVE_GETRESUID)
5072
5073PyDoc_STRVAR(os_getresuid__doc__,
5074"getresuid($module, /)\n"
5075"--\n"
5076"\n"
5077"Return a tuple of the current process\'s real, effective, and saved user ids.");
5078
5079#define OS_GETRESUID_METHODDEF \
5080 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5081
5082static PyObject *
5083os_getresuid_impl(PyModuleDef *module);
5084
5085static PyObject *
5086os_getresuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
5087{
5088 return os_getresuid_impl(module);
5089}
5090
5091#endif /* defined(HAVE_GETRESUID) */
5092
5093#if defined(HAVE_GETRESGID)
5094
5095PyDoc_STRVAR(os_getresgid__doc__,
5096"getresgid($module, /)\n"
5097"--\n"
5098"\n"
5099"Return a tuple of the current process\'s real, effective, and saved group ids.");
5100
5101#define OS_GETRESGID_METHODDEF \
5102 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5103
5104static PyObject *
5105os_getresgid_impl(PyModuleDef *module);
5106
5107static PyObject *
5108os_getresgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
5109{
5110 return os_getresgid_impl(module);
5111}
5112
5113#endif /* defined(HAVE_GETRESGID) */
5114
5115#if defined(USE_XATTRS)
5116
5117PyDoc_STRVAR(os_getxattr__doc__,
5118"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5119"--\n"
5120"\n"
5121"Return the value of extended attribute attribute on path.\n"
5122"\n"
5123"path may be either a string or an open file descriptor.\n"
5124"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5125" link, getxattr will examine the symbolic link itself instead of the file\n"
5126" the link points to.");
5127
5128#define OS_GETXATTR_METHODDEF \
5129 {"getxattr", (PyCFunction)os_getxattr, METH_VARARGS|METH_KEYWORDS, os_getxattr__doc__},
5130
5131static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04005132os_getxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute,
5133 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005134
5135static PyObject *
5136os_getxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
5137{
5138 PyObject *return_value = NULL;
5139 static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5140 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5141 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5142 int follow_symlinks = 1;
5143
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005144 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:getxattr", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005145 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005146 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005147 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005148 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5149
5150exit:
5151 /* Cleanup for path */
5152 path_cleanup(&path);
5153 /* Cleanup for attribute */
5154 path_cleanup(&attribute);
5155
5156 return return_value;
5157}
5158
5159#endif /* defined(USE_XATTRS) */
5160
5161#if defined(USE_XATTRS)
5162
5163PyDoc_STRVAR(os_setxattr__doc__,
5164"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5165" follow_symlinks=True)\n"
5166"--\n"
5167"\n"
5168"Set extended attribute attribute on path to value.\n"
5169"\n"
5170"path may be either a string or an open file descriptor.\n"
5171"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5172" link, setxattr will modify the symbolic link itself instead of the file\n"
5173" the link points to.");
5174
5175#define OS_SETXATTR_METHODDEF \
5176 {"setxattr", (PyCFunction)os_setxattr, METH_VARARGS|METH_KEYWORDS, os_setxattr__doc__},
5177
5178static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04005179os_setxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute,
5180 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005181
5182static PyObject *
5183os_setxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
5184{
5185 PyObject *return_value = NULL;
5186 static char *_keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5187 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5188 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5189 Py_buffer value = {NULL, NULL};
5190 int flags = 0;
5191 int follow_symlinks = 1;
5192
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005193 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&y*|i$p:setxattr", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005194 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005195 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005196 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005197 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5198
5199exit:
5200 /* Cleanup for path */
5201 path_cleanup(&path);
5202 /* Cleanup for attribute */
5203 path_cleanup(&attribute);
5204 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005205 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005206 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005207 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005208
5209 return return_value;
5210}
5211
5212#endif /* defined(USE_XATTRS) */
5213
5214#if defined(USE_XATTRS)
5215
5216PyDoc_STRVAR(os_removexattr__doc__,
5217"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5218"--\n"
5219"\n"
5220"Remove extended attribute attribute on path.\n"
5221"\n"
5222"path may be either a string or an open file descriptor.\n"
5223"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5224" link, removexattr will modify the symbolic link itself instead of the file\n"
5225" the link points to.");
5226
5227#define OS_REMOVEXATTR_METHODDEF \
5228 {"removexattr", (PyCFunction)os_removexattr, METH_VARARGS|METH_KEYWORDS, os_removexattr__doc__},
5229
5230static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04005231os_removexattr_impl(PyModuleDef *module, path_t *path, path_t *attribute,
5232 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005233
5234static PyObject *
5235os_removexattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
5236{
5237 PyObject *return_value = NULL;
5238 static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5239 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5240 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5241 int follow_symlinks = 1;
5242
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005243 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:removexattr", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005244 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005245 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005246 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5248
5249exit:
5250 /* Cleanup for path */
5251 path_cleanup(&path);
5252 /* Cleanup for attribute */
5253 path_cleanup(&attribute);
5254
5255 return return_value;
5256}
5257
5258#endif /* defined(USE_XATTRS) */
5259
5260#if defined(USE_XATTRS)
5261
5262PyDoc_STRVAR(os_listxattr__doc__,
5263"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5264"--\n"
5265"\n"
5266"Return a list of extended attributes on path.\n"
5267"\n"
5268"path may be either None, a string, or an open file descriptor.\n"
5269"if path is None, listxattr will examine the current directory.\n"
5270"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5271" link, listxattr will examine the symbolic link itself instead of the file\n"
5272" the link points to.");
5273
5274#define OS_LISTXATTR_METHODDEF \
5275 {"listxattr", (PyCFunction)os_listxattr, METH_VARARGS|METH_KEYWORDS, os_listxattr__doc__},
5276
5277static PyObject *
5278os_listxattr_impl(PyModuleDef *module, path_t *path, int follow_symlinks);
5279
5280static PyObject *
5281os_listxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs)
5282{
5283 PyObject *return_value = NULL;
5284 static char *_keywords[] = {"path", "follow_symlinks", NULL};
5285 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5286 int follow_symlinks = 1;
5287
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005288 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&$p:listxattr", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005289 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005292 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5293
5294exit:
5295 /* Cleanup for path */
5296 path_cleanup(&path);
5297
5298 return return_value;
5299}
5300
5301#endif /* defined(USE_XATTRS) */
5302
5303PyDoc_STRVAR(os_urandom__doc__,
5304"urandom($module, size, /)\n"
5305"--\n"
5306"\n"
5307"Return a bytes object containing random bytes suitable for cryptographic use.");
5308
5309#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005310 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005311
5312static PyObject *
5313os_urandom_impl(PyModuleDef *module, Py_ssize_t size);
5314
5315static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005316os_urandom(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005317{
5318 PyObject *return_value = NULL;
5319 Py_ssize_t size;
5320
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005321 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005322 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005323 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005324 return_value = os_urandom_impl(module, size);
5325
5326exit:
5327 return return_value;
5328}
5329
5330PyDoc_STRVAR(os_cpu_count__doc__,
5331"cpu_count($module, /)\n"
5332"--\n"
5333"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005334"Return the number of CPUs in the system; return None if indeterminable.\n"
5335"\n"
5336"This number is not equivalent to the number of CPUs the current process can\n"
5337"use. The number of usable CPUs can be obtained with\n"
5338"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005339
5340#define OS_CPU_COUNT_METHODDEF \
5341 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5342
5343static PyObject *
5344os_cpu_count_impl(PyModuleDef *module);
5345
5346static PyObject *
5347os_cpu_count(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
5348{
5349 return os_cpu_count_impl(module);
5350}
5351
5352PyDoc_STRVAR(os_get_inheritable__doc__,
5353"get_inheritable($module, fd, /)\n"
5354"--\n"
5355"\n"
5356"Get the close-on-exe flag of the specified file descriptor.");
5357
5358#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005359 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005360
5361static int
5362os_get_inheritable_impl(PyModuleDef *module, int fd);
5363
5364static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005365os_get_inheritable(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005366{
5367 PyObject *return_value = NULL;
5368 int fd;
5369 int _return_value;
5370
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005371 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005372 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005373 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005374 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005375 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005376 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005377 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005378 return_value = PyBool_FromLong((long)_return_value);
5379
5380exit:
5381 return return_value;
5382}
5383
5384PyDoc_STRVAR(os_set_inheritable__doc__,
5385"set_inheritable($module, fd, inheritable, /)\n"
5386"--\n"
5387"\n"
5388"Set the inheritable flag of the specified file descriptor.");
5389
5390#define OS_SET_INHERITABLE_METHODDEF \
5391 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
5392
5393static PyObject *
5394os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable);
5395
5396static PyObject *
5397os_set_inheritable(PyModuleDef *module, PyObject *args)
5398{
5399 PyObject *return_value = NULL;
5400 int fd;
5401 int inheritable;
5402
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005403 if (!PyArg_ParseTuple(args, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005404 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005405 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005406 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005407 return_value = os_set_inheritable_impl(module, fd, inheritable);
5408
5409exit:
5410 return return_value;
5411}
5412
5413#if defined(MS_WINDOWS)
5414
5415PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5416"get_handle_inheritable($module, handle, /)\n"
5417"--\n"
5418"\n"
5419"Get the close-on-exe flag of the specified file descriptor.");
5420
5421#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005422 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005423
5424static int
5425os_get_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle);
5426
5427static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005428os_get_handle_inheritable(PyModuleDef *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005429{
5430 PyObject *return_value = NULL;
5431 Py_intptr_t handle;
5432 int _return_value;
5433
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005434 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005435 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005437 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005438 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005439 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005440 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005441 return_value = PyBool_FromLong((long)_return_value);
5442
5443exit:
5444 return return_value;
5445}
5446
5447#endif /* defined(MS_WINDOWS) */
5448
5449#if defined(MS_WINDOWS)
5450
5451PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5452"set_handle_inheritable($module, handle, inheritable, /)\n"
5453"--\n"
5454"\n"
5455"Set the inheritable flag of the specified handle.");
5456
5457#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
5458 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
5459
5460static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -04005461os_set_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle,
5462 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005463
5464static PyObject *
5465os_set_handle_inheritable(PyModuleDef *module, PyObject *args)
5466{
5467 PyObject *return_value = NULL;
5468 Py_intptr_t handle;
5469 int inheritable;
5470
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005471 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005472 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005473 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005474 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005475 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5476
5477exit:
5478 return return_value;
5479}
5480
5481#endif /* defined(MS_WINDOWS) */
5482
Ethan Furman410ef8e2016-06-04 12:06:26 -07005483PyDoc_STRVAR(os_fspath__doc__,
5484"fspath($module, /, path)\n"
5485"--\n"
5486"\n"
5487"Return the file system path representation of the object.\n"
5488"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005489"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5490"object defines __fspath__(), then return the result of that method. All other\n"
5491"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005492
5493#define OS_FSPATH_METHODDEF \
5494 {"fspath", (PyCFunction)os_fspath, METH_VARARGS|METH_KEYWORDS, os_fspath__doc__},
5495
5496static PyObject *
5497os_fspath_impl(PyModuleDef *module, PyObject *path);
5498
5499static PyObject *
5500os_fspath(PyModuleDef *module, PyObject *args, PyObject *kwargs)
5501{
5502 PyObject *return_value = NULL;
5503 static char *_keywords[] = {"path", NULL};
5504 PyObject *path;
5505
5506 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:fspath", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005507 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005508 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005509 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005510 return_value = os_fspath_impl(module, path);
5511
5512exit:
5513 return return_value;
5514}
5515
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005516#ifndef OS_TTYNAME_METHODDEF
5517 #define OS_TTYNAME_METHODDEF
5518#endif /* !defined(OS_TTYNAME_METHODDEF) */
5519
5520#ifndef OS_CTERMID_METHODDEF
5521 #define OS_CTERMID_METHODDEF
5522#endif /* !defined(OS_CTERMID_METHODDEF) */
5523
5524#ifndef OS_FCHDIR_METHODDEF
5525 #define OS_FCHDIR_METHODDEF
5526#endif /* !defined(OS_FCHDIR_METHODDEF) */
5527
5528#ifndef OS_FCHMOD_METHODDEF
5529 #define OS_FCHMOD_METHODDEF
5530#endif /* !defined(OS_FCHMOD_METHODDEF) */
5531
5532#ifndef OS_LCHMOD_METHODDEF
5533 #define OS_LCHMOD_METHODDEF
5534#endif /* !defined(OS_LCHMOD_METHODDEF) */
5535
5536#ifndef OS_CHFLAGS_METHODDEF
5537 #define OS_CHFLAGS_METHODDEF
5538#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5539
5540#ifndef OS_LCHFLAGS_METHODDEF
5541 #define OS_LCHFLAGS_METHODDEF
5542#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5543
5544#ifndef OS_CHROOT_METHODDEF
5545 #define OS_CHROOT_METHODDEF
5546#endif /* !defined(OS_CHROOT_METHODDEF) */
5547
5548#ifndef OS_FSYNC_METHODDEF
5549 #define OS_FSYNC_METHODDEF
5550#endif /* !defined(OS_FSYNC_METHODDEF) */
5551
5552#ifndef OS_SYNC_METHODDEF
5553 #define OS_SYNC_METHODDEF
5554#endif /* !defined(OS_SYNC_METHODDEF) */
5555
5556#ifndef OS_FDATASYNC_METHODDEF
5557 #define OS_FDATASYNC_METHODDEF
5558#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5559
5560#ifndef OS_CHOWN_METHODDEF
5561 #define OS_CHOWN_METHODDEF
5562#endif /* !defined(OS_CHOWN_METHODDEF) */
5563
5564#ifndef OS_FCHOWN_METHODDEF
5565 #define OS_FCHOWN_METHODDEF
5566#endif /* !defined(OS_FCHOWN_METHODDEF) */
5567
5568#ifndef OS_LCHOWN_METHODDEF
5569 #define OS_LCHOWN_METHODDEF
5570#endif /* !defined(OS_LCHOWN_METHODDEF) */
5571
5572#ifndef OS_LINK_METHODDEF
5573 #define OS_LINK_METHODDEF
5574#endif /* !defined(OS_LINK_METHODDEF) */
5575
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005576#ifndef OS__GETFULLPATHNAME_METHODDEF
5577 #define OS__GETFULLPATHNAME_METHODDEF
5578#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5579
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005580#ifndef OS__GETFINALPATHNAME_METHODDEF
5581 #define OS__GETFINALPATHNAME_METHODDEF
5582#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5583
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005584#ifndef OS__ISDIR_METHODDEF
5585 #define OS__ISDIR_METHODDEF
5586#endif /* !defined(OS__ISDIR_METHODDEF) */
5587
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005588#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5589 #define OS__GETVOLUMEPATHNAME_METHODDEF
5590#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5591
5592#ifndef OS_NICE_METHODDEF
5593 #define OS_NICE_METHODDEF
5594#endif /* !defined(OS_NICE_METHODDEF) */
5595
5596#ifndef OS_GETPRIORITY_METHODDEF
5597 #define OS_GETPRIORITY_METHODDEF
5598#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
5599
5600#ifndef OS_SETPRIORITY_METHODDEF
5601 #define OS_SETPRIORITY_METHODDEF
5602#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
5603
5604#ifndef OS_SYSTEM_METHODDEF
5605 #define OS_SYSTEM_METHODDEF
5606#endif /* !defined(OS_SYSTEM_METHODDEF) */
5607
5608#ifndef OS_UNAME_METHODDEF
5609 #define OS_UNAME_METHODDEF
5610#endif /* !defined(OS_UNAME_METHODDEF) */
5611
5612#ifndef OS_EXECV_METHODDEF
5613 #define OS_EXECV_METHODDEF
5614#endif /* !defined(OS_EXECV_METHODDEF) */
5615
5616#ifndef OS_EXECVE_METHODDEF
5617 #define OS_EXECVE_METHODDEF
5618#endif /* !defined(OS_EXECVE_METHODDEF) */
5619
5620#ifndef OS_SPAWNV_METHODDEF
5621 #define OS_SPAWNV_METHODDEF
5622#endif /* !defined(OS_SPAWNV_METHODDEF) */
5623
5624#ifndef OS_SPAWNVE_METHODDEF
5625 #define OS_SPAWNVE_METHODDEF
5626#endif /* !defined(OS_SPAWNVE_METHODDEF) */
5627
5628#ifndef OS_FORK1_METHODDEF
5629 #define OS_FORK1_METHODDEF
5630#endif /* !defined(OS_FORK1_METHODDEF) */
5631
5632#ifndef OS_FORK_METHODDEF
5633 #define OS_FORK_METHODDEF
5634#endif /* !defined(OS_FORK_METHODDEF) */
5635
5636#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5637 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5638#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
5639
5640#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5641 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5642#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
5643
5644#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
5645 #define OS_SCHED_GETSCHEDULER_METHODDEF
5646#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
5647
5648#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
5649 #define OS_SCHED_SETSCHEDULER_METHODDEF
5650#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
5651
5652#ifndef OS_SCHED_GETPARAM_METHODDEF
5653 #define OS_SCHED_GETPARAM_METHODDEF
5654#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
5655
5656#ifndef OS_SCHED_SETPARAM_METHODDEF
5657 #define OS_SCHED_SETPARAM_METHODDEF
5658#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
5659
5660#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
5661 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
5662#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
5663
5664#ifndef OS_SCHED_YIELD_METHODDEF
5665 #define OS_SCHED_YIELD_METHODDEF
5666#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
5667
5668#ifndef OS_SCHED_SETAFFINITY_METHODDEF
5669 #define OS_SCHED_SETAFFINITY_METHODDEF
5670#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
5671
5672#ifndef OS_SCHED_GETAFFINITY_METHODDEF
5673 #define OS_SCHED_GETAFFINITY_METHODDEF
5674#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
5675
5676#ifndef OS_OPENPTY_METHODDEF
5677 #define OS_OPENPTY_METHODDEF
5678#endif /* !defined(OS_OPENPTY_METHODDEF) */
5679
5680#ifndef OS_FORKPTY_METHODDEF
5681 #define OS_FORKPTY_METHODDEF
5682#endif /* !defined(OS_FORKPTY_METHODDEF) */
5683
5684#ifndef OS_GETEGID_METHODDEF
5685 #define OS_GETEGID_METHODDEF
5686#endif /* !defined(OS_GETEGID_METHODDEF) */
5687
5688#ifndef OS_GETEUID_METHODDEF
5689 #define OS_GETEUID_METHODDEF
5690#endif /* !defined(OS_GETEUID_METHODDEF) */
5691
5692#ifndef OS_GETGID_METHODDEF
5693 #define OS_GETGID_METHODDEF
5694#endif /* !defined(OS_GETGID_METHODDEF) */
5695
5696#ifndef OS_GETGROUPS_METHODDEF
5697 #define OS_GETGROUPS_METHODDEF
5698#endif /* !defined(OS_GETGROUPS_METHODDEF) */
5699
5700#ifndef OS_GETPGID_METHODDEF
5701 #define OS_GETPGID_METHODDEF
5702#endif /* !defined(OS_GETPGID_METHODDEF) */
5703
5704#ifndef OS_GETPGRP_METHODDEF
5705 #define OS_GETPGRP_METHODDEF
5706#endif /* !defined(OS_GETPGRP_METHODDEF) */
5707
5708#ifndef OS_SETPGRP_METHODDEF
5709 #define OS_SETPGRP_METHODDEF
5710#endif /* !defined(OS_SETPGRP_METHODDEF) */
5711
5712#ifndef OS_GETPPID_METHODDEF
5713 #define OS_GETPPID_METHODDEF
5714#endif /* !defined(OS_GETPPID_METHODDEF) */
5715
5716#ifndef OS_GETLOGIN_METHODDEF
5717 #define OS_GETLOGIN_METHODDEF
5718#endif /* !defined(OS_GETLOGIN_METHODDEF) */
5719
5720#ifndef OS_GETUID_METHODDEF
5721 #define OS_GETUID_METHODDEF
5722#endif /* !defined(OS_GETUID_METHODDEF) */
5723
5724#ifndef OS_KILL_METHODDEF
5725 #define OS_KILL_METHODDEF
5726#endif /* !defined(OS_KILL_METHODDEF) */
5727
5728#ifndef OS_KILLPG_METHODDEF
5729 #define OS_KILLPG_METHODDEF
5730#endif /* !defined(OS_KILLPG_METHODDEF) */
5731
5732#ifndef OS_PLOCK_METHODDEF
5733 #define OS_PLOCK_METHODDEF
5734#endif /* !defined(OS_PLOCK_METHODDEF) */
5735
5736#ifndef OS_SETUID_METHODDEF
5737 #define OS_SETUID_METHODDEF
5738#endif /* !defined(OS_SETUID_METHODDEF) */
5739
5740#ifndef OS_SETEUID_METHODDEF
5741 #define OS_SETEUID_METHODDEF
5742#endif /* !defined(OS_SETEUID_METHODDEF) */
5743
5744#ifndef OS_SETEGID_METHODDEF
5745 #define OS_SETEGID_METHODDEF
5746#endif /* !defined(OS_SETEGID_METHODDEF) */
5747
5748#ifndef OS_SETREUID_METHODDEF
5749 #define OS_SETREUID_METHODDEF
5750#endif /* !defined(OS_SETREUID_METHODDEF) */
5751
5752#ifndef OS_SETREGID_METHODDEF
5753 #define OS_SETREGID_METHODDEF
5754#endif /* !defined(OS_SETREGID_METHODDEF) */
5755
5756#ifndef OS_SETGID_METHODDEF
5757 #define OS_SETGID_METHODDEF
5758#endif /* !defined(OS_SETGID_METHODDEF) */
5759
5760#ifndef OS_SETGROUPS_METHODDEF
5761 #define OS_SETGROUPS_METHODDEF
5762#endif /* !defined(OS_SETGROUPS_METHODDEF) */
5763
5764#ifndef OS_WAIT3_METHODDEF
5765 #define OS_WAIT3_METHODDEF
5766#endif /* !defined(OS_WAIT3_METHODDEF) */
5767
5768#ifndef OS_WAIT4_METHODDEF
5769 #define OS_WAIT4_METHODDEF
5770#endif /* !defined(OS_WAIT4_METHODDEF) */
5771
5772#ifndef OS_WAITID_METHODDEF
5773 #define OS_WAITID_METHODDEF
5774#endif /* !defined(OS_WAITID_METHODDEF) */
5775
5776#ifndef OS_WAITPID_METHODDEF
5777 #define OS_WAITPID_METHODDEF
5778#endif /* !defined(OS_WAITPID_METHODDEF) */
5779
5780#ifndef OS_WAIT_METHODDEF
5781 #define OS_WAIT_METHODDEF
5782#endif /* !defined(OS_WAIT_METHODDEF) */
5783
5784#ifndef OS_SYMLINK_METHODDEF
5785 #define OS_SYMLINK_METHODDEF
5786#endif /* !defined(OS_SYMLINK_METHODDEF) */
5787
5788#ifndef OS_TIMES_METHODDEF
5789 #define OS_TIMES_METHODDEF
5790#endif /* !defined(OS_TIMES_METHODDEF) */
5791
5792#ifndef OS_GETSID_METHODDEF
5793 #define OS_GETSID_METHODDEF
5794#endif /* !defined(OS_GETSID_METHODDEF) */
5795
5796#ifndef OS_SETSID_METHODDEF
5797 #define OS_SETSID_METHODDEF
5798#endif /* !defined(OS_SETSID_METHODDEF) */
5799
5800#ifndef OS_SETPGID_METHODDEF
5801 #define OS_SETPGID_METHODDEF
5802#endif /* !defined(OS_SETPGID_METHODDEF) */
5803
5804#ifndef OS_TCGETPGRP_METHODDEF
5805 #define OS_TCGETPGRP_METHODDEF
5806#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
5807
5808#ifndef OS_TCSETPGRP_METHODDEF
5809 #define OS_TCSETPGRP_METHODDEF
5810#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
5811
5812#ifndef OS_LOCKF_METHODDEF
5813 #define OS_LOCKF_METHODDEF
5814#endif /* !defined(OS_LOCKF_METHODDEF) */
5815
5816#ifndef OS_READV_METHODDEF
5817 #define OS_READV_METHODDEF
5818#endif /* !defined(OS_READV_METHODDEF) */
5819
5820#ifndef OS_PREAD_METHODDEF
5821 #define OS_PREAD_METHODDEF
5822#endif /* !defined(OS_PREAD_METHODDEF) */
5823
5824#ifndef OS_PIPE_METHODDEF
5825 #define OS_PIPE_METHODDEF
5826#endif /* !defined(OS_PIPE_METHODDEF) */
5827
5828#ifndef OS_PIPE2_METHODDEF
5829 #define OS_PIPE2_METHODDEF
5830#endif /* !defined(OS_PIPE2_METHODDEF) */
5831
5832#ifndef OS_WRITEV_METHODDEF
5833 #define OS_WRITEV_METHODDEF
5834#endif /* !defined(OS_WRITEV_METHODDEF) */
5835
5836#ifndef OS_PWRITE_METHODDEF
5837 #define OS_PWRITE_METHODDEF
5838#endif /* !defined(OS_PWRITE_METHODDEF) */
5839
5840#ifndef OS_MKFIFO_METHODDEF
5841 #define OS_MKFIFO_METHODDEF
5842#endif /* !defined(OS_MKFIFO_METHODDEF) */
5843
5844#ifndef OS_MKNOD_METHODDEF
5845 #define OS_MKNOD_METHODDEF
5846#endif /* !defined(OS_MKNOD_METHODDEF) */
5847
5848#ifndef OS_MAJOR_METHODDEF
5849 #define OS_MAJOR_METHODDEF
5850#endif /* !defined(OS_MAJOR_METHODDEF) */
5851
5852#ifndef OS_MINOR_METHODDEF
5853 #define OS_MINOR_METHODDEF
5854#endif /* !defined(OS_MINOR_METHODDEF) */
5855
5856#ifndef OS_MAKEDEV_METHODDEF
5857 #define OS_MAKEDEV_METHODDEF
5858#endif /* !defined(OS_MAKEDEV_METHODDEF) */
5859
5860#ifndef OS_FTRUNCATE_METHODDEF
5861 #define OS_FTRUNCATE_METHODDEF
5862#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
5863
5864#ifndef OS_TRUNCATE_METHODDEF
5865 #define OS_TRUNCATE_METHODDEF
5866#endif /* !defined(OS_TRUNCATE_METHODDEF) */
5867
5868#ifndef OS_POSIX_FALLOCATE_METHODDEF
5869 #define OS_POSIX_FALLOCATE_METHODDEF
5870#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
5871
5872#ifndef OS_POSIX_FADVISE_METHODDEF
5873 #define OS_POSIX_FADVISE_METHODDEF
5874#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
5875
5876#ifndef OS_PUTENV_METHODDEF
5877 #define OS_PUTENV_METHODDEF
5878#endif /* !defined(OS_PUTENV_METHODDEF) */
5879
5880#ifndef OS_UNSETENV_METHODDEF
5881 #define OS_UNSETENV_METHODDEF
5882#endif /* !defined(OS_UNSETENV_METHODDEF) */
5883
5884#ifndef OS_WCOREDUMP_METHODDEF
5885 #define OS_WCOREDUMP_METHODDEF
5886#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
5887
5888#ifndef OS_WIFCONTINUED_METHODDEF
5889 #define OS_WIFCONTINUED_METHODDEF
5890#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
5891
5892#ifndef OS_WIFSTOPPED_METHODDEF
5893 #define OS_WIFSTOPPED_METHODDEF
5894#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
5895
5896#ifndef OS_WIFSIGNALED_METHODDEF
5897 #define OS_WIFSIGNALED_METHODDEF
5898#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
5899
5900#ifndef OS_WIFEXITED_METHODDEF
5901 #define OS_WIFEXITED_METHODDEF
5902#endif /* !defined(OS_WIFEXITED_METHODDEF) */
5903
5904#ifndef OS_WEXITSTATUS_METHODDEF
5905 #define OS_WEXITSTATUS_METHODDEF
5906#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
5907
5908#ifndef OS_WTERMSIG_METHODDEF
5909 #define OS_WTERMSIG_METHODDEF
5910#endif /* !defined(OS_WTERMSIG_METHODDEF) */
5911
5912#ifndef OS_WSTOPSIG_METHODDEF
5913 #define OS_WSTOPSIG_METHODDEF
5914#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
5915
5916#ifndef OS_FSTATVFS_METHODDEF
5917 #define OS_FSTATVFS_METHODDEF
5918#endif /* !defined(OS_FSTATVFS_METHODDEF) */
5919
5920#ifndef OS_STATVFS_METHODDEF
5921 #define OS_STATVFS_METHODDEF
5922#endif /* !defined(OS_STATVFS_METHODDEF) */
5923
5924#ifndef OS__GETDISKUSAGE_METHODDEF
5925 #define OS__GETDISKUSAGE_METHODDEF
5926#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
5927
5928#ifndef OS_FPATHCONF_METHODDEF
5929 #define OS_FPATHCONF_METHODDEF
5930#endif /* !defined(OS_FPATHCONF_METHODDEF) */
5931
5932#ifndef OS_PATHCONF_METHODDEF
5933 #define OS_PATHCONF_METHODDEF
5934#endif /* !defined(OS_PATHCONF_METHODDEF) */
5935
5936#ifndef OS_CONFSTR_METHODDEF
5937 #define OS_CONFSTR_METHODDEF
5938#endif /* !defined(OS_CONFSTR_METHODDEF) */
5939
5940#ifndef OS_SYSCONF_METHODDEF
5941 #define OS_SYSCONF_METHODDEF
5942#endif /* !defined(OS_SYSCONF_METHODDEF) */
5943
5944#ifndef OS_GETLOADAVG_METHODDEF
5945 #define OS_GETLOADAVG_METHODDEF
5946#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
5947
5948#ifndef OS_SETRESUID_METHODDEF
5949 #define OS_SETRESUID_METHODDEF
5950#endif /* !defined(OS_SETRESUID_METHODDEF) */
5951
5952#ifndef OS_SETRESGID_METHODDEF
5953 #define OS_SETRESGID_METHODDEF
5954#endif /* !defined(OS_SETRESGID_METHODDEF) */
5955
5956#ifndef OS_GETRESUID_METHODDEF
5957 #define OS_GETRESUID_METHODDEF
5958#endif /* !defined(OS_GETRESUID_METHODDEF) */
5959
5960#ifndef OS_GETRESGID_METHODDEF
5961 #define OS_GETRESGID_METHODDEF
5962#endif /* !defined(OS_GETRESGID_METHODDEF) */
5963
5964#ifndef OS_GETXATTR_METHODDEF
5965 #define OS_GETXATTR_METHODDEF
5966#endif /* !defined(OS_GETXATTR_METHODDEF) */
5967
5968#ifndef OS_SETXATTR_METHODDEF
5969 #define OS_SETXATTR_METHODDEF
5970#endif /* !defined(OS_SETXATTR_METHODDEF) */
5971
5972#ifndef OS_REMOVEXATTR_METHODDEF
5973 #define OS_REMOVEXATTR_METHODDEF
5974#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
5975
5976#ifndef OS_LISTXATTR_METHODDEF
5977 #define OS_LISTXATTR_METHODDEF
5978#endif /* !defined(OS_LISTXATTR_METHODDEF) */
5979
5980#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
5981 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
5982#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
5983
5984#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
5985 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
5986#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Brett Cannonb4f43e92016-06-09 14:32:08 -07005987/*[clinic end generated code: output=1b91c3a100e75a4d input=a9049054013a1b77]*/