blob: 1bbfc062d8241e62f660d7f9cc2f04846ff26e88 [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 *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030033os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030034
35static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030036os_stat(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030037{
38 PyObject *return_value = NULL;
39 static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
40 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
41 int dir_fd = DEFAULT_DIR_FD;
42 int follow_symlinks = 1;
43
Serhiy Storchaka247789c2015-04-24 00:40:51 +030044 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&p:stat", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030045 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
46 goto exit;
47 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
48
49exit:
50 /* Cleanup for path */
51 path_cleanup(&path);
52
53 return return_value;
54}
55
56PyDoc_STRVAR(os_lstat__doc__,
57"lstat($module, /, path, *, dir_fd=None)\n"
58"--\n"
59"\n"
60"Perform a stat system call on the given path, without following symbolic links.\n"
61"\n"
62"Like stat(), but do not follow symbolic links.\n"
63"Equivalent to stat(path, follow_symlinks=False).");
64
65#define OS_LSTAT_METHODDEF \
66 {"lstat", (PyCFunction)os_lstat, METH_VARARGS|METH_KEYWORDS, os_lstat__doc__},
67
68static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030069os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070
71static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030072os_lstat(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030073{
74 PyObject *return_value = NULL;
75 static char *_keywords[] = {"path", "dir_fd", NULL};
76 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
77 int dir_fd = DEFAULT_DIR_FD;
78
Serhiy Storchaka247789c2015-04-24 00:40:51 +030079 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:lstat", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030080 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd))
81 goto exit;
82 return_value = os_lstat_impl(module, &path, dir_fd);
83
84exit:
85 /* Cleanup for path */
86 path_cleanup(&path);
87
88 return return_value;
89}
90
91PyDoc_STRVAR(os_access__doc__,
92"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
93" follow_symlinks=True)\n"
94"--\n"
95"\n"
96"Use the real uid/gid to test for access to a path.\n"
97"\n"
98" path\n"
Benjamin Peterson768f3b42016-09-05 15:29:33 -070099" Path to be tested; can be string or bytes\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300100" mode\n"
101" Operating-system mode bitfield. Can be F_OK to test existence,\n"
102" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
103" dir_fd\n"
104" If not None, it should be a file descriptor open to a directory,\n"
105" and path should be relative; path will then be relative to that\n"
106" directory.\n"
107" effective_ids\n"
108" If True, access will use the effective uid/gid instead of\n"
109" the real uid/gid.\n"
110" follow_symlinks\n"
111" If False, and the last element of the path is a symbolic link,\n"
112" access will examine the symbolic link itself instead of the file\n"
113" the link points to.\n"
114"\n"
115"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
116" on your platform. If they are unavailable, using them will raise a\n"
117" NotImplementedError.\n"
118"\n"
119"Note that most operations will use the effective uid/gid, therefore this\n"
120" routine can be used in a suid/sgid environment to test if the invoking user\n"
121" has the specified access to the path.");
122
123#define OS_ACCESS_METHODDEF \
124 {"access", (PyCFunction)os_access, METH_VARARGS|METH_KEYWORDS, os_access__doc__},
125
126static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300127os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400128 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300129
130static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300131os_access(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300132{
133 PyObject *return_value = NULL;
134 static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700135 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300136 int mode;
137 int dir_fd = DEFAULT_DIR_FD;
138 int effective_ids = 0;
139 int follow_symlinks = 1;
140 int _return_value;
141
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300142 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|$O&pp:access", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300143 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks))
144 goto exit;
145 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
146 if ((_return_value == -1) && PyErr_Occurred())
147 goto exit;
148 return_value = PyBool_FromLong((long)_return_value);
149
150exit:
151 /* Cleanup for path */
152 path_cleanup(&path);
153
154 return return_value;
155}
156
157#if defined(HAVE_TTYNAME)
158
159PyDoc_STRVAR(os_ttyname__doc__,
160"ttyname($module, fd, /)\n"
161"--\n"
162"\n"
163"Return the name of the terminal device connected to \'fd\'.\n"
164"\n"
165" fd\n"
166" Integer file descriptor handle.");
167
168#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300169 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300170
171static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300172os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300173
174static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300175os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300176{
177 PyObject *return_value = NULL;
178 int fd;
179 char *_return_value;
180
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300181 if (!PyArg_Parse(arg, "i:ttyname", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300182 goto exit;
183 _return_value = os_ttyname_impl(module, fd);
184 if (_return_value == NULL)
185 goto exit;
186 return_value = PyUnicode_DecodeFSDefault(_return_value);
187
188exit:
189 return return_value;
190}
191
192#endif /* defined(HAVE_TTYNAME) */
193
194#if defined(HAVE_CTERMID)
195
196PyDoc_STRVAR(os_ctermid__doc__,
197"ctermid($module, /)\n"
198"--\n"
199"\n"
200"Return the name of the controlling terminal for this process.");
201
202#define OS_CTERMID_METHODDEF \
203 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
204
205static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300206os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300207
208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300209os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300210{
211 return os_ctermid_impl(module);
212}
213
214#endif /* defined(HAVE_CTERMID) */
215
216PyDoc_STRVAR(os_chdir__doc__,
217"chdir($module, /, path)\n"
218"--\n"
219"\n"
220"Change the current working directory to the specified path.\n"
221"\n"
222"path may always be specified as a string.\n"
223"On some platforms, path may also be specified as an open file descriptor.\n"
224" If this functionality is unavailable, using it raises an exception.");
225
226#define OS_CHDIR_METHODDEF \
227 {"chdir", (PyCFunction)os_chdir, METH_VARARGS|METH_KEYWORDS, os_chdir__doc__},
228
229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300230os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300231
232static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300233os_chdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300234{
235 PyObject *return_value = NULL;
236 static char *_keywords[] = {"path", NULL};
237 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
238
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300239 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:chdir", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240 path_converter, &path))
241 goto exit;
242 return_value = os_chdir_impl(module, &path);
243
244exit:
245 /* Cleanup for path */
246 path_cleanup(&path);
247
248 return return_value;
249}
250
251#if defined(HAVE_FCHDIR)
252
253PyDoc_STRVAR(os_fchdir__doc__,
254"fchdir($module, /, fd)\n"
255"--\n"
256"\n"
257"Change to the directory of the given file descriptor.\n"
258"\n"
259"fd must be opened on a directory, not a file.\n"
260"Equivalent to os.chdir(fd).");
261
262#define OS_FCHDIR_METHODDEF \
263 {"fchdir", (PyCFunction)os_fchdir, METH_VARARGS|METH_KEYWORDS, os_fchdir__doc__},
264
265static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300266os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300267
268static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300269os_fchdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300270{
271 PyObject *return_value = NULL;
272 static char *_keywords[] = {"fd", NULL};
273 int fd;
274
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300275 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:fchdir", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300276 fildes_converter, &fd))
277 goto exit;
278 return_value = os_fchdir_impl(module, fd);
279
280exit:
281 return return_value;
282}
283
284#endif /* defined(HAVE_FCHDIR) */
285
286PyDoc_STRVAR(os_chmod__doc__,
287"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
288"--\n"
289"\n"
290"Change the access permissions of a file.\n"
291"\n"
292" path\n"
293" Path to be modified. May always be specified as a str or bytes.\n"
294" On some platforms, path may also be specified as an open file descriptor.\n"
295" If this functionality is unavailable, using it raises an exception.\n"
296" mode\n"
297" Operating-system mode bitfield.\n"
298" dir_fd\n"
299" If not None, it should be a file descriptor open to a directory,\n"
300" and path should be relative; path will then be relative to that\n"
301" directory.\n"
302" follow_symlinks\n"
303" If False, and the last element of the path is a symbolic link,\n"
304" chmod will modify the symbolic link itself instead of the file\n"
305" the link points to.\n"
306"\n"
307"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
308" an open file descriptor.\n"
309"dir_fd and follow_symlinks may not be implemented on your platform.\n"
310" If they are unavailable, using them will raise a NotImplementedError.");
311
312#define OS_CHMOD_METHODDEF \
313 {"chmod", (PyCFunction)os_chmod, METH_VARARGS|METH_KEYWORDS, os_chmod__doc__},
314
315static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300316os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400317 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300318
319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300320os_chmod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300321{
322 PyObject *return_value = NULL;
323 static char *_keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
324 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
325 int mode;
326 int dir_fd = DEFAULT_DIR_FD;
327 int follow_symlinks = 1;
328
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300329 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|$O&p:chmod", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300330 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
331 goto exit;
332 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
333
334exit:
335 /* Cleanup for path */
336 path_cleanup(&path);
337
338 return return_value;
339}
340
341#if defined(HAVE_FCHMOD)
342
343PyDoc_STRVAR(os_fchmod__doc__,
344"fchmod($module, /, fd, mode)\n"
345"--\n"
346"\n"
347"Change the access permissions of the file given by file descriptor fd.\n"
348"\n"
349"Equivalent to os.chmod(fd, mode).");
350
351#define OS_FCHMOD_METHODDEF \
352 {"fchmod", (PyCFunction)os_fchmod, METH_VARARGS|METH_KEYWORDS, os_fchmod__doc__},
353
354static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300355os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300356
357static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300358os_fchmod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300359{
360 PyObject *return_value = NULL;
361 static char *_keywords[] = {"fd", "mode", NULL};
362 int fd;
363 int mode;
364
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300365 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:fchmod", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300366 &fd, &mode))
367 goto exit;
368 return_value = os_fchmod_impl(module, fd, mode);
369
370exit:
371 return return_value;
372}
373
374#endif /* defined(HAVE_FCHMOD) */
375
376#if defined(HAVE_LCHMOD)
377
378PyDoc_STRVAR(os_lchmod__doc__,
379"lchmod($module, /, path, mode)\n"
380"--\n"
381"\n"
382"Change the access permissions of a file, without following symbolic links.\n"
383"\n"
384"If path is a symlink, this affects the link itself rather than the target.\n"
385"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
386
387#define OS_LCHMOD_METHODDEF \
388 {"lchmod", (PyCFunction)os_lchmod, METH_VARARGS|METH_KEYWORDS, os_lchmod__doc__},
389
390static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300391os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300392
393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300394os_lchmod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300395{
396 PyObject *return_value = NULL;
397 static char *_keywords[] = {"path", "mode", NULL};
398 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
399 int mode;
400
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300401 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i:lchmod", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300402 path_converter, &path, &mode))
403 goto exit;
404 return_value = os_lchmod_impl(module, &path, mode);
405
406exit:
407 /* Cleanup for path */
408 path_cleanup(&path);
409
410 return return_value;
411}
412
413#endif /* defined(HAVE_LCHMOD) */
414
415#if defined(HAVE_CHFLAGS)
416
417PyDoc_STRVAR(os_chflags__doc__,
418"chflags($module, /, path, flags, follow_symlinks=True)\n"
419"--\n"
420"\n"
421"Set file flags.\n"
422"\n"
423"If follow_symlinks is False, and the last element of the path is a symbolic\n"
424" link, chflags will change flags on the symbolic link itself instead of the\n"
425" file the link points to.\n"
426"follow_symlinks may not be implemented on your platform. If it is\n"
427"unavailable, using it will raise a NotImplementedError.");
428
429#define OS_CHFLAGS_METHODDEF \
430 {"chflags", (PyCFunction)os_chflags, METH_VARARGS|METH_KEYWORDS, os_chflags__doc__},
431
432static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300433os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400434 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300435
436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300437os_chflags(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300438{
439 PyObject *return_value = NULL;
440 static char *_keywords[] = {"path", "flags", "follow_symlinks", NULL};
441 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
442 unsigned long flags;
443 int follow_symlinks = 1;
444
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300445 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&k|p:chflags", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300446 path_converter, &path, &flags, &follow_symlinks))
447 goto exit;
448 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
449
450exit:
451 /* Cleanup for path */
452 path_cleanup(&path);
453
454 return return_value;
455}
456
457#endif /* defined(HAVE_CHFLAGS) */
458
459#if defined(HAVE_LCHFLAGS)
460
461PyDoc_STRVAR(os_lchflags__doc__,
462"lchflags($module, /, path, flags)\n"
463"--\n"
464"\n"
465"Set file flags.\n"
466"\n"
467"This function will not follow symbolic links.\n"
468"Equivalent to chflags(path, flags, follow_symlinks=False).");
469
470#define OS_LCHFLAGS_METHODDEF \
471 {"lchflags", (PyCFunction)os_lchflags, METH_VARARGS|METH_KEYWORDS, os_lchflags__doc__},
472
473static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300474os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300475
476static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300477os_lchflags(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300478{
479 PyObject *return_value = NULL;
480 static char *_keywords[] = {"path", "flags", NULL};
481 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
482 unsigned long flags;
483
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300484 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&k:lchflags", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300485 path_converter, &path, &flags))
486 goto exit;
487 return_value = os_lchflags_impl(module, &path, flags);
488
489exit:
490 /* Cleanup for path */
491 path_cleanup(&path);
492
493 return return_value;
494}
495
496#endif /* defined(HAVE_LCHFLAGS) */
497
498#if defined(HAVE_CHROOT)
499
500PyDoc_STRVAR(os_chroot__doc__,
501"chroot($module, /, path)\n"
502"--\n"
503"\n"
504"Change root directory to path.");
505
506#define OS_CHROOT_METHODDEF \
507 {"chroot", (PyCFunction)os_chroot, METH_VARARGS|METH_KEYWORDS, os_chroot__doc__},
508
509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300510os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511
512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300513os_chroot(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300514{
515 PyObject *return_value = NULL;
516 static char *_keywords[] = {"path", NULL};
517 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
518
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300519 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:chroot", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300520 path_converter, &path))
521 goto exit;
522 return_value = os_chroot_impl(module, &path);
523
524exit:
525 /* Cleanup for path */
526 path_cleanup(&path);
527
528 return return_value;
529}
530
531#endif /* defined(HAVE_CHROOT) */
532
533#if defined(HAVE_FSYNC)
534
535PyDoc_STRVAR(os_fsync__doc__,
536"fsync($module, /, fd)\n"
537"--\n"
538"\n"
539"Force write of fd to disk.");
540
541#define OS_FSYNC_METHODDEF \
542 {"fsync", (PyCFunction)os_fsync, METH_VARARGS|METH_KEYWORDS, os_fsync__doc__},
543
544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300545os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546
547static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300548os_fsync(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300549{
550 PyObject *return_value = NULL;
551 static char *_keywords[] = {"fd", NULL};
552 int fd;
553
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300554 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:fsync", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300555 fildes_converter, &fd))
556 goto exit;
557 return_value = os_fsync_impl(module, fd);
558
559exit:
560 return return_value;
561}
562
563#endif /* defined(HAVE_FSYNC) */
564
565#if defined(HAVE_SYNC)
566
567PyDoc_STRVAR(os_sync__doc__,
568"sync($module, /)\n"
569"--\n"
570"\n"
571"Force write of everything to disk.");
572
573#define OS_SYNC_METHODDEF \
574 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
575
576static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300577os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300578
579static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300580os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300581{
582 return os_sync_impl(module);
583}
584
585#endif /* defined(HAVE_SYNC) */
586
587#if defined(HAVE_FDATASYNC)
588
589PyDoc_STRVAR(os_fdatasync__doc__,
590"fdatasync($module, /, fd)\n"
591"--\n"
592"\n"
593"Force write of fd to disk without forcing update of metadata.");
594
595#define OS_FDATASYNC_METHODDEF \
596 {"fdatasync", (PyCFunction)os_fdatasync, METH_VARARGS|METH_KEYWORDS, os_fdatasync__doc__},
597
598static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300599os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300600
601static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300602os_fdatasync(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300603{
604 PyObject *return_value = NULL;
605 static char *_keywords[] = {"fd", NULL};
606 int fd;
607
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300608 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:fdatasync", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300609 fildes_converter, &fd))
610 goto exit;
611 return_value = os_fdatasync_impl(module, fd);
612
613exit:
614 return return_value;
615}
616
617#endif /* defined(HAVE_FDATASYNC) */
618
619#if defined(HAVE_CHOWN)
620
621PyDoc_STRVAR(os_chown__doc__,
622"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
623"--\n"
624"\n"
625"Change the owner and group id of path to the numeric uid and gid.\\\n"
626"\n"
627" path\n"
628" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
629" dir_fd\n"
630" If not None, it should be a file descriptor open to a directory,\n"
631" and path should be relative; path will then be relative to that\n"
632" directory.\n"
633" follow_symlinks\n"
634" If False, and the last element of the path is a symbolic link,\n"
635" stat will examine the symbolic link itself instead of the file\n"
636" the link points to.\n"
637"\n"
638"path may always be specified as a string.\n"
639"On some platforms, path may also be specified as an open file descriptor.\n"
640" If this functionality is unavailable, using it raises an exception.\n"
641"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
642" and path should be relative; path will then be relative to that directory.\n"
643"If follow_symlinks is False, and the last element of the path is a symbolic\n"
644" link, chown will modify the symbolic link itself instead of the file the\n"
645" link points to.\n"
646"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
647" an open file descriptor.\n"
648"dir_fd and follow_symlinks may not be implemented on your platform.\n"
649" If they are unavailable, using them will raise a NotImplementedError.");
650
651#define OS_CHOWN_METHODDEF \
652 {"chown", (PyCFunction)os_chown, METH_VARARGS|METH_KEYWORDS, os_chown__doc__},
653
654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300655os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400656 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300657
658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300659os_chown(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300660{
661 PyObject *return_value = NULL;
662 static char *_keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
663 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
664 uid_t uid;
665 gid_t gid;
666 int dir_fd = DEFAULT_DIR_FD;
667 int follow_symlinks = 1;
668
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300669 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&|$O&p:chown", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300670 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
671 goto exit;
672 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
673
674exit:
675 /* Cleanup for path */
676 path_cleanup(&path);
677
678 return return_value;
679}
680
681#endif /* defined(HAVE_CHOWN) */
682
683#if defined(HAVE_FCHOWN)
684
685PyDoc_STRVAR(os_fchown__doc__,
686"fchown($module, /, fd, uid, gid)\n"
687"--\n"
688"\n"
689"Change the owner and group id of the file specified by file descriptor.\n"
690"\n"
691"Equivalent to os.chown(fd, uid, gid).");
692
693#define OS_FCHOWN_METHODDEF \
694 {"fchown", (PyCFunction)os_fchown, METH_VARARGS|METH_KEYWORDS, os_fchown__doc__},
695
696static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300697os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300698
699static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300700os_fchown(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300701{
702 PyObject *return_value = NULL;
703 static char *_keywords[] = {"fd", "uid", "gid", NULL};
704 int fd;
705 uid_t uid;
706 gid_t gid;
707
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300708 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO&O&:fchown", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300709 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid))
710 goto exit;
711 return_value = os_fchown_impl(module, fd, uid, gid);
712
713exit:
714 return return_value;
715}
716
717#endif /* defined(HAVE_FCHOWN) */
718
719#if defined(HAVE_LCHOWN)
720
721PyDoc_STRVAR(os_lchown__doc__,
722"lchown($module, /, path, uid, gid)\n"
723"--\n"
724"\n"
725"Change the owner and group id of path to the numeric uid and gid.\n"
726"\n"
727"This function will not follow symbolic links.\n"
728"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
729
730#define OS_LCHOWN_METHODDEF \
731 {"lchown", (PyCFunction)os_lchown, METH_VARARGS|METH_KEYWORDS, os_lchown__doc__},
732
733static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300734os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300735
736static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300737os_lchown(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300738{
739 PyObject *return_value = NULL;
740 static char *_keywords[] = {"path", "uid", "gid", NULL};
741 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
742 uid_t uid;
743 gid_t gid;
744
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300745 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&:lchown", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300746 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid))
747 goto exit;
748 return_value = os_lchown_impl(module, &path, uid, gid);
749
750exit:
751 /* Cleanup for path */
752 path_cleanup(&path);
753
754 return return_value;
755}
756
757#endif /* defined(HAVE_LCHOWN) */
758
759PyDoc_STRVAR(os_getcwd__doc__,
760"getcwd($module, /)\n"
761"--\n"
762"\n"
763"Return a unicode string representing the current working directory.");
764
765#define OS_GETCWD_METHODDEF \
766 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
767
768static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300769os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300770
771static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300772os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300773{
774 return os_getcwd_impl(module);
775}
776
777PyDoc_STRVAR(os_getcwdb__doc__,
778"getcwdb($module, /)\n"
779"--\n"
780"\n"
781"Return a bytes string representing the current working directory.");
782
783#define OS_GETCWDB_METHODDEF \
784 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
785
786static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300787os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300788
789static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300790os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300791{
792 return os_getcwdb_impl(module);
793}
794
795#if defined(HAVE_LINK)
796
797PyDoc_STRVAR(os_link__doc__,
798"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
799" follow_symlinks=True)\n"
800"--\n"
801"\n"
802"Create a hard link to a file.\n"
803"\n"
804"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
805" descriptor open to a directory, and the respective path string (src or dst)\n"
806" should be relative; the path will then be relative to that directory.\n"
807"If follow_symlinks is False, and the last element of src is a symbolic\n"
808" link, link will create a link to the symbolic link itself instead of the\n"
809" file the link points to.\n"
810"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
811" platform. If they are unavailable, using them will raise a\n"
812" NotImplementedError.");
813
814#define OS_LINK_METHODDEF \
815 {"link", (PyCFunction)os_link, METH_VARARGS|METH_KEYWORDS, os_link__doc__},
816
817static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300818os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400819 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300820
821static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300822os_link(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300823{
824 PyObject *return_value = NULL;
825 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
826 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
827 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
828 int src_dir_fd = DEFAULT_DIR_FD;
829 int dst_dir_fd = DEFAULT_DIR_FD;
830 int follow_symlinks = 1;
831
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300832 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&p:link", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300833 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks))
834 goto exit;
835 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
836
837exit:
838 /* Cleanup for src */
839 path_cleanup(&src);
840 /* Cleanup for dst */
841 path_cleanup(&dst);
842
843 return return_value;
844}
845
846#endif /* defined(HAVE_LINK) */
847
848PyDoc_STRVAR(os_listdir__doc__,
849"listdir($module, /, path=None)\n"
850"--\n"
851"\n"
852"Return a list containing the names of the files in the directory.\n"
853"\n"
854"path can be specified as either str or bytes. If path is bytes,\n"
855" the filenames returned will also be bytes; in all other circumstances\n"
856" the filenames returned will be str.\n"
857"If path is None, uses the path=\'.\'.\n"
858"On some platforms, path may also be specified as an open file descriptor;\\\n"
859" the file descriptor must refer to a directory.\n"
860" If this functionality is unavailable, using it raises NotImplementedError.\n"
861"\n"
862"The list is in arbitrary order. It does not include the special\n"
863"entries \'.\' and \'..\' even if they are present in the directory.");
864
865#define OS_LISTDIR_METHODDEF \
866 {"listdir", (PyCFunction)os_listdir, METH_VARARGS|METH_KEYWORDS, os_listdir__doc__},
867
868static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300869os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300870
871static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300872os_listdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300873{
874 PyObject *return_value = NULL;
875 static char *_keywords[] = {"path", NULL};
876 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
877
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300878 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:listdir", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300879 path_converter, &path))
880 goto exit;
881 return_value = os_listdir_impl(module, &path);
882
883exit:
884 /* Cleanup for path */
885 path_cleanup(&path);
886
887 return return_value;
888}
889
890#if defined(MS_WINDOWS)
891
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300892PyDoc_STRVAR(os__getfullpathname__doc__,
893"_getfullpathname($module, path, /)\n"
894"--\n"
895"\n");
896
897#define OS__GETFULLPATHNAME_METHODDEF \
898 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
899
900static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300901os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300902
903static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300904os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300905{
906 PyObject *return_value = NULL;
907 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
908
909 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path))
910 goto exit;
911 return_value = os__getfullpathname_impl(module, &path);
912
913exit:
914 /* Cleanup for path */
915 path_cleanup(&path);
916
917 return return_value;
918}
919
920#endif /* defined(MS_WINDOWS) */
921
922#if defined(MS_WINDOWS)
923
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300924PyDoc_STRVAR(os__getfinalpathname__doc__,
925"_getfinalpathname($module, path, /)\n"
926"--\n"
927"\n"
928"A helper function for samepath on windows.");
929
930#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300931 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300932
933static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300934os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300935
936static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300937os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300938{
939 PyObject *return_value = NULL;
940 PyObject *path;
941
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300942 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300943 goto exit;
944 return_value = os__getfinalpathname_impl(module, path);
945
946exit:
947 return return_value;
948}
949
950#endif /* defined(MS_WINDOWS) */
951
952#if defined(MS_WINDOWS)
953
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300954PyDoc_STRVAR(os__isdir__doc__,
955"_isdir($module, path, /)\n"
956"--\n"
957"\n");
958
959#define OS__ISDIR_METHODDEF \
960 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
961
962static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300963os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300964
965static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300966os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300967{
968 PyObject *return_value = NULL;
969 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
970
971 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path))
972 goto exit;
973 return_value = os__isdir_impl(module, &path);
974
975exit:
976 /* Cleanup for path */
977 path_cleanup(&path);
978
979 return return_value;
980}
981
982#endif /* defined(MS_WINDOWS) */
983
984#if defined(MS_WINDOWS)
985
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300986PyDoc_STRVAR(os__getvolumepathname__doc__,
987"_getvolumepathname($module, /, path)\n"
988"--\n"
989"\n"
990"A helper function for ismount on Win32.");
991
992#define OS__GETVOLUMEPATHNAME_METHODDEF \
993 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_VARARGS|METH_KEYWORDS, os__getvolumepathname__doc__},
994
995static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300996os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300997
998static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300999os__getvolumepathname(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001000{
1001 PyObject *return_value = NULL;
1002 static char *_keywords[] = {"path", NULL};
1003 PyObject *path;
1004
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001005 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U:_getvolumepathname", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001006 &path))
1007 goto exit;
1008 return_value = os__getvolumepathname_impl(module, path);
1009
1010exit:
1011 return return_value;
1012}
1013
1014#endif /* defined(MS_WINDOWS) */
1015
1016PyDoc_STRVAR(os_mkdir__doc__,
1017"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1018"--\n"
1019"\n"
1020"Create a directory.\n"
1021"\n"
1022"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1023" and path should be relative; path will then be relative to that directory.\n"
1024"dir_fd may not be implemented on your platform.\n"
1025" If it is unavailable, using it will raise a NotImplementedError.\n"
1026"\n"
1027"The mode argument is ignored on Windows.");
1028
1029#define OS_MKDIR_METHODDEF \
1030 {"mkdir", (PyCFunction)os_mkdir, METH_VARARGS|METH_KEYWORDS, os_mkdir__doc__},
1031
1032static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001033os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001034
1035static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001036os_mkdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001037{
1038 PyObject *return_value = NULL;
1039 static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
1040 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1041 int mode = 511;
1042 int dir_fd = DEFAULT_DIR_FD;
1043
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001044 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkdir", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001045 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd))
1046 goto exit;
1047 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1048
1049exit:
1050 /* Cleanup for path */
1051 path_cleanup(&path);
1052
1053 return return_value;
1054}
1055
1056#if defined(HAVE_NICE)
1057
1058PyDoc_STRVAR(os_nice__doc__,
1059"nice($module, increment, /)\n"
1060"--\n"
1061"\n"
1062"Add increment to the priority of process and return the new priority.");
1063
1064#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001065 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001066
1067static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001068os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001069
1070static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001071os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001072{
1073 PyObject *return_value = NULL;
1074 int increment;
1075
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001076 if (!PyArg_Parse(arg, "i:nice", &increment))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001077 goto exit;
1078 return_value = os_nice_impl(module, increment);
1079
1080exit:
1081 return return_value;
1082}
1083
1084#endif /* defined(HAVE_NICE) */
1085
1086#if defined(HAVE_GETPRIORITY)
1087
1088PyDoc_STRVAR(os_getpriority__doc__,
1089"getpriority($module, /, which, who)\n"
1090"--\n"
1091"\n"
1092"Return program scheduling priority.");
1093
1094#define OS_GETPRIORITY_METHODDEF \
1095 {"getpriority", (PyCFunction)os_getpriority, METH_VARARGS|METH_KEYWORDS, os_getpriority__doc__},
1096
1097static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001098os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001099
1100static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001101os_getpriority(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001102{
1103 PyObject *return_value = NULL;
1104 static char *_keywords[] = {"which", "who", NULL};
1105 int which;
1106 int who;
1107
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001108 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:getpriority", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001109 &which, &who))
1110 goto exit;
1111 return_value = os_getpriority_impl(module, which, who);
1112
1113exit:
1114 return return_value;
1115}
1116
1117#endif /* defined(HAVE_GETPRIORITY) */
1118
1119#if defined(HAVE_SETPRIORITY)
1120
1121PyDoc_STRVAR(os_setpriority__doc__,
1122"setpriority($module, /, which, who, priority)\n"
1123"--\n"
1124"\n"
1125"Set program scheduling priority.");
1126
1127#define OS_SETPRIORITY_METHODDEF \
1128 {"setpriority", (PyCFunction)os_setpriority, METH_VARARGS|METH_KEYWORDS, os_setpriority__doc__},
1129
1130static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001131os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001132
1133static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001134os_setpriority(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001135{
1136 PyObject *return_value = NULL;
1137 static char *_keywords[] = {"which", "who", "priority", NULL};
1138 int which;
1139 int who;
1140 int priority;
1141
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001142 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii:setpriority", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001143 &which, &who, &priority))
1144 goto exit;
1145 return_value = os_setpriority_impl(module, which, who, priority);
1146
1147exit:
1148 return return_value;
1149}
1150
1151#endif /* defined(HAVE_SETPRIORITY) */
1152
1153PyDoc_STRVAR(os_rename__doc__,
1154"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1155"--\n"
1156"\n"
1157"Rename a file or directory.\n"
1158"\n"
1159"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1160" descriptor open to a directory, and the respective path string (src or dst)\n"
1161" should be relative; the path will then be relative to that directory.\n"
1162"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1163" If they are unavailable, using them will raise a NotImplementedError.");
1164
1165#define OS_RENAME_METHODDEF \
1166 {"rename", (PyCFunction)os_rename, METH_VARARGS|METH_KEYWORDS, os_rename__doc__},
1167
1168static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001169os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001170 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001171
1172static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001173os_rename(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001174{
1175 PyObject *return_value = NULL;
1176 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1177 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1178 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1179 int src_dir_fd = DEFAULT_DIR_FD;
1180 int dst_dir_fd = DEFAULT_DIR_FD;
1181
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001182 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&:rename", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001183 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd))
1184 goto exit;
1185 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1186
1187exit:
1188 /* Cleanup for src */
1189 path_cleanup(&src);
1190 /* Cleanup for dst */
1191 path_cleanup(&dst);
1192
1193 return return_value;
1194}
1195
1196PyDoc_STRVAR(os_replace__doc__,
1197"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1198"--\n"
1199"\n"
1200"Rename a file or directory, overwriting the destination.\n"
1201"\n"
1202"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1203" descriptor open to a directory, and the respective path string (src or dst)\n"
1204" should be relative; the path will then be relative to that directory.\n"
1205"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1206" If they are unavailable, using them will raise a NotImplementedError.\"");
1207
1208#define OS_REPLACE_METHODDEF \
1209 {"replace", (PyCFunction)os_replace, METH_VARARGS|METH_KEYWORDS, os_replace__doc__},
1210
1211static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001212os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1213 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001214
1215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001216os_replace(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001217{
1218 PyObject *return_value = NULL;
1219 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1220 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1221 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1222 int src_dir_fd = DEFAULT_DIR_FD;
1223 int dst_dir_fd = DEFAULT_DIR_FD;
1224
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001225 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&:replace", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001226 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd))
1227 goto exit;
1228 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1229
1230exit:
1231 /* Cleanup for src */
1232 path_cleanup(&src);
1233 /* Cleanup for dst */
1234 path_cleanup(&dst);
1235
1236 return return_value;
1237}
1238
1239PyDoc_STRVAR(os_rmdir__doc__,
1240"rmdir($module, /, path, *, dir_fd=None)\n"
1241"--\n"
1242"\n"
1243"Remove a directory.\n"
1244"\n"
1245"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1246" and path should be relative; path will then be relative to that directory.\n"
1247"dir_fd may not be implemented on your platform.\n"
1248" If it is unavailable, using it will raise a NotImplementedError.");
1249
1250#define OS_RMDIR_METHODDEF \
1251 {"rmdir", (PyCFunction)os_rmdir, METH_VARARGS|METH_KEYWORDS, os_rmdir__doc__},
1252
1253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001254os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001255
1256static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001257os_rmdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001258{
1259 PyObject *return_value = NULL;
1260 static char *_keywords[] = {"path", "dir_fd", NULL};
1261 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1262 int dir_fd = DEFAULT_DIR_FD;
1263
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001264 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:rmdir", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001265 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
1266 goto exit;
1267 return_value = os_rmdir_impl(module, &path, dir_fd);
1268
1269exit:
1270 /* Cleanup for path */
1271 path_cleanup(&path);
1272
1273 return return_value;
1274}
1275
1276#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1277
1278PyDoc_STRVAR(os_system__doc__,
1279"system($module, /, command)\n"
1280"--\n"
1281"\n"
1282"Execute the command in a subshell.");
1283
1284#define OS_SYSTEM_METHODDEF \
1285 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1286
1287static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001288os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001289
1290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001291os_system(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001292{
1293 PyObject *return_value = NULL;
1294 static char *_keywords[] = {"command", NULL};
1295 Py_UNICODE *command;
1296 long _return_value;
1297
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001298 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "u:system", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001299 &command))
1300 goto exit;
1301 _return_value = os_system_impl(module, command);
1302 if ((_return_value == -1) && PyErr_Occurred())
1303 goto exit;
1304 return_value = PyLong_FromLong(_return_value);
1305
1306exit:
1307 return return_value;
1308}
1309
1310#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1311
1312#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1313
1314PyDoc_STRVAR(os_system__doc__,
1315"system($module, /, command)\n"
1316"--\n"
1317"\n"
1318"Execute the command in a subshell.");
1319
1320#define OS_SYSTEM_METHODDEF \
1321 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1322
1323static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001324os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001325
1326static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001327os_system(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001328{
1329 PyObject *return_value = NULL;
1330 static char *_keywords[] = {"command", NULL};
1331 PyObject *command = NULL;
1332 long _return_value;
1333
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001334 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:system", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001335 PyUnicode_FSConverter, &command))
1336 goto exit;
1337 _return_value = os_system_impl(module, command);
1338 if ((_return_value == -1) && PyErr_Occurred())
1339 goto exit;
1340 return_value = PyLong_FromLong(_return_value);
1341
1342exit:
1343 /* Cleanup for command */
1344 Py_XDECREF(command);
1345
1346 return return_value;
1347}
1348
1349#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1350
1351PyDoc_STRVAR(os_umask__doc__,
1352"umask($module, mask, /)\n"
1353"--\n"
1354"\n"
1355"Set the current numeric umask and return the previous umask.");
1356
1357#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001358 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001359
1360static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001361os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362
1363static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001364os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001365{
1366 PyObject *return_value = NULL;
1367 int mask;
1368
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001369 if (!PyArg_Parse(arg, "i:umask", &mask))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001370 goto exit;
1371 return_value = os_umask_impl(module, mask);
1372
1373exit:
1374 return return_value;
1375}
1376
1377PyDoc_STRVAR(os_unlink__doc__,
1378"unlink($module, /, path, *, dir_fd=None)\n"
1379"--\n"
1380"\n"
1381"Remove a file (same as remove()).\n"
1382"\n"
1383"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1384" and path should be relative; path will then be relative to that directory.\n"
1385"dir_fd may not be implemented on your platform.\n"
1386" If it is unavailable, using it will raise a NotImplementedError.");
1387
1388#define OS_UNLINK_METHODDEF \
1389 {"unlink", (PyCFunction)os_unlink, METH_VARARGS|METH_KEYWORDS, os_unlink__doc__},
1390
1391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001392os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393
1394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001395os_unlink(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001396{
1397 PyObject *return_value = NULL;
1398 static char *_keywords[] = {"path", "dir_fd", NULL};
1399 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1400 int dir_fd = DEFAULT_DIR_FD;
1401
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001402 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:unlink", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
1404 goto exit;
1405 return_value = os_unlink_impl(module, &path, dir_fd);
1406
1407exit:
1408 /* Cleanup for path */
1409 path_cleanup(&path);
1410
1411 return return_value;
1412}
1413
1414PyDoc_STRVAR(os_remove__doc__,
1415"remove($module, /, path, *, dir_fd=None)\n"
1416"--\n"
1417"\n"
1418"Remove a file (same as unlink()).\n"
1419"\n"
1420"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1421" and path should be relative; path will then be relative to that directory.\n"
1422"dir_fd may not be implemented on your platform.\n"
1423" If it is unavailable, using it will raise a NotImplementedError.");
1424
1425#define OS_REMOVE_METHODDEF \
1426 {"remove", (PyCFunction)os_remove, METH_VARARGS|METH_KEYWORDS, os_remove__doc__},
1427
1428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001429os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430
1431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001432os_remove(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433{
1434 PyObject *return_value = NULL;
1435 static char *_keywords[] = {"path", "dir_fd", NULL};
1436 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1437 int dir_fd = DEFAULT_DIR_FD;
1438
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001439 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:remove", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001440 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
1441 goto exit;
1442 return_value = os_remove_impl(module, &path, dir_fd);
1443
1444exit:
1445 /* Cleanup for path */
1446 path_cleanup(&path);
1447
1448 return return_value;
1449}
1450
1451#if defined(HAVE_UNAME)
1452
1453PyDoc_STRVAR(os_uname__doc__,
1454"uname($module, /)\n"
1455"--\n"
1456"\n"
1457"Return an object identifying the current operating system.\n"
1458"\n"
1459"The object behaves like a named tuple with the following fields:\n"
1460" (sysname, nodename, release, version, machine)");
1461
1462#define OS_UNAME_METHODDEF \
1463 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1464
1465static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001466os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001467
1468static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001469os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001470{
1471 return os_uname_impl(module);
1472}
1473
1474#endif /* defined(HAVE_UNAME) */
1475
1476PyDoc_STRVAR(os_utime__doc__,
1477"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1478" follow_symlinks=True)\n"
1479"--\n"
1480"\n"
1481"Set the access and modified time of path.\n"
1482"\n"
1483"path may always be specified as a string.\n"
1484"On some platforms, path may also be specified as an open file descriptor.\n"
1485" If this functionality is unavailable, using it raises an exception.\n"
1486"\n"
1487"If times is not None, it must be a tuple (atime, mtime);\n"
1488" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001489"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001490" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1491" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001492"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001493"Specifying tuples for both times and ns is an error.\n"
1494"\n"
1495"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1496" and path should be relative; path will then be relative to that directory.\n"
1497"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1498" link, utime will modify the symbolic link itself instead of the file the\n"
1499" link points to.\n"
1500"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1501" as an open file descriptor.\n"
1502"dir_fd and follow_symlinks may not be available on your platform.\n"
1503" If they are unavailable, using them will raise a NotImplementedError.");
1504
1505#define OS_UTIME_METHODDEF \
1506 {"utime", (PyCFunction)os_utime, METH_VARARGS|METH_KEYWORDS, os_utime__doc__},
1507
1508static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001509os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1510 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001511
1512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001513os_utime(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001514{
1515 PyObject *return_value = NULL;
1516 static char *_keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1517 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1518 PyObject *times = NULL;
1519 PyObject *ns = NULL;
1520 int dir_fd = DEFAULT_DIR_FD;
1521 int follow_symlinks = 1;
1522
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001523 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|O$OO&p:utime", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001524 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
1525 goto exit;
1526 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1527
1528exit:
1529 /* Cleanup for path */
1530 path_cleanup(&path);
1531
1532 return return_value;
1533}
1534
1535PyDoc_STRVAR(os__exit__doc__,
1536"_exit($module, /, status)\n"
1537"--\n"
1538"\n"
1539"Exit to the system with specified status, without normal exit processing.");
1540
1541#define OS__EXIT_METHODDEF \
1542 {"_exit", (PyCFunction)os__exit, METH_VARARGS|METH_KEYWORDS, os__exit__doc__},
1543
1544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001545os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001546
1547static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001548os__exit(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001549{
1550 PyObject *return_value = NULL;
1551 static char *_keywords[] = {"status", NULL};
1552 int status;
1553
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001554 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:_exit", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001555 &status))
1556 goto exit;
1557 return_value = os__exit_impl(module, status);
1558
1559exit:
1560 return return_value;
1561}
1562
1563#if defined(HAVE_EXECV)
1564
1565PyDoc_STRVAR(os_execv__doc__,
1566"execv($module, path, argv, /)\n"
1567"--\n"
1568"\n"
1569"Execute an executable path with arguments, replacing current process.\n"
1570"\n"
1571" path\n"
1572" Path of executable file.\n"
1573" argv\n"
1574" Tuple or list of strings.");
1575
1576#define OS_EXECV_METHODDEF \
1577 {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
1578
1579static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001580os_execv_impl(PyObject *module, PyObject *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581
1582static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001583os_execv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001584{
1585 PyObject *return_value = NULL;
1586 PyObject *path = NULL;
1587 PyObject *argv;
1588
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001589 if (!PyArg_ParseTuple(args, "O&O:execv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001590 PyUnicode_FSConverter, &path, &argv))
1591 goto exit;
1592 return_value = os_execv_impl(module, path, argv);
1593
1594exit:
1595 /* Cleanup for path */
1596 Py_XDECREF(path);
1597
1598 return return_value;
1599}
1600
1601#endif /* defined(HAVE_EXECV) */
1602
1603#if defined(HAVE_EXECV)
1604
1605PyDoc_STRVAR(os_execve__doc__,
1606"execve($module, /, path, argv, env)\n"
1607"--\n"
1608"\n"
1609"Execute an executable path with arguments, replacing current process.\n"
1610"\n"
1611" path\n"
1612" Path of executable file.\n"
1613" argv\n"
1614" Tuple or list of strings.\n"
1615" env\n"
1616" Dictionary of strings mapping to strings.");
1617
1618#define OS_EXECVE_METHODDEF \
1619 {"execve", (PyCFunction)os_execve, METH_VARARGS|METH_KEYWORDS, os_execve__doc__},
1620
1621static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001622os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001623
1624static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001625os_execve(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001626{
1627 PyObject *return_value = NULL;
1628 static char *_keywords[] = {"path", "argv", "env", NULL};
1629 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1630 PyObject *argv;
1631 PyObject *env;
1632
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001633 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&OO:execve", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001634 path_converter, &path, &argv, &env))
1635 goto exit;
1636 return_value = os_execve_impl(module, &path, argv, env);
1637
1638exit:
1639 /* Cleanup for path */
1640 path_cleanup(&path);
1641
1642 return return_value;
1643}
1644
1645#endif /* defined(HAVE_EXECV) */
1646
1647#if defined(HAVE_SPAWNV)
1648
1649PyDoc_STRVAR(os_spawnv__doc__,
1650"spawnv($module, mode, path, argv, /)\n"
1651"--\n"
1652"\n"
1653"Execute the program specified by path in a new process.\n"
1654"\n"
1655" mode\n"
1656" Mode of process creation.\n"
1657" path\n"
1658" Path of executable file.\n"
1659" argv\n"
1660" Tuple or list of strings.");
1661
1662#define OS_SPAWNV_METHODDEF \
1663 {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
1664
1665static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001666os_spawnv_impl(PyObject *module, int mode, PyObject *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001667
1668static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001669os_spawnv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001670{
1671 PyObject *return_value = NULL;
1672 int mode;
1673 PyObject *path = NULL;
1674 PyObject *argv;
1675
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001676 if (!PyArg_ParseTuple(args, "iO&O:spawnv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001677 &mode, PyUnicode_FSConverter, &path, &argv))
1678 goto exit;
1679 return_value = os_spawnv_impl(module, mode, path, argv);
1680
1681exit:
1682 /* Cleanup for path */
1683 Py_XDECREF(path);
1684
1685 return return_value;
1686}
1687
1688#endif /* defined(HAVE_SPAWNV) */
1689
1690#if defined(HAVE_SPAWNV)
1691
1692PyDoc_STRVAR(os_spawnve__doc__,
1693"spawnve($module, mode, path, argv, env, /)\n"
1694"--\n"
1695"\n"
1696"Execute the program specified by path in a new process.\n"
1697"\n"
1698" mode\n"
1699" Mode of process creation.\n"
1700" path\n"
1701" Path of executable file.\n"
1702" argv\n"
1703" Tuple or list of strings.\n"
1704" env\n"
1705" Dictionary of strings mapping to strings.");
1706
1707#define OS_SPAWNVE_METHODDEF \
1708 {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
1709
1710static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001711os_spawnve_impl(PyObject *module, int mode, PyObject *path, PyObject *argv,
1712 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001713
1714static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001715os_spawnve(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001716{
1717 PyObject *return_value = NULL;
1718 int mode;
1719 PyObject *path = NULL;
1720 PyObject *argv;
1721 PyObject *env;
1722
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001723 if (!PyArg_ParseTuple(args, "iO&OO:spawnve",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001724 &mode, PyUnicode_FSConverter, &path, &argv, &env))
1725 goto exit;
1726 return_value = os_spawnve_impl(module, mode, path, argv, env);
1727
1728exit:
1729 /* Cleanup for path */
1730 Py_XDECREF(path);
1731
1732 return return_value;
1733}
1734
1735#endif /* defined(HAVE_SPAWNV) */
1736
1737#if defined(HAVE_FORK1)
1738
1739PyDoc_STRVAR(os_fork1__doc__,
1740"fork1($module, /)\n"
1741"--\n"
1742"\n"
1743"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1744"\n"
1745"Return 0 to child process and PID of child to parent process.");
1746
1747#define OS_FORK1_METHODDEF \
1748 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1749
1750static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001751os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001752
1753static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001754os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001755{
1756 return os_fork1_impl(module);
1757}
1758
1759#endif /* defined(HAVE_FORK1) */
1760
1761#if defined(HAVE_FORK)
1762
1763PyDoc_STRVAR(os_fork__doc__,
1764"fork($module, /)\n"
1765"--\n"
1766"\n"
1767"Fork a child process.\n"
1768"\n"
1769"Return 0 to child process and PID of child to parent process.");
1770
1771#define OS_FORK_METHODDEF \
1772 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1773
1774static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001775os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001776
1777static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001778os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001779{
1780 return os_fork_impl(module);
1781}
1782
1783#endif /* defined(HAVE_FORK) */
1784
1785#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1786
1787PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1788"sched_get_priority_max($module, /, policy)\n"
1789"--\n"
1790"\n"
1791"Get the maximum scheduling priority for policy.");
1792
1793#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
1794 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_max__doc__},
1795
1796static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001797os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001798
1799static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001800os_sched_get_priority_max(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001801{
1802 PyObject *return_value = NULL;
1803 static char *_keywords[] = {"policy", NULL};
1804 int policy;
1805
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001806 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:sched_get_priority_max", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001807 &policy))
1808 goto exit;
1809 return_value = os_sched_get_priority_max_impl(module, policy);
1810
1811exit:
1812 return return_value;
1813}
1814
1815#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1816
1817#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1818
1819PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1820"sched_get_priority_min($module, /, policy)\n"
1821"--\n"
1822"\n"
1823"Get the minimum scheduling priority for policy.");
1824
1825#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
1826 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_min__doc__},
1827
1828static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001829os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001830
1831static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001832os_sched_get_priority_min(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001833{
1834 PyObject *return_value = NULL;
1835 static char *_keywords[] = {"policy", NULL};
1836 int policy;
1837
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001838 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:sched_get_priority_min", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001839 &policy))
1840 goto exit;
1841 return_value = os_sched_get_priority_min_impl(module, policy);
1842
1843exit:
1844 return return_value;
1845}
1846
1847#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1848
1849#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1850
1851PyDoc_STRVAR(os_sched_getscheduler__doc__,
1852"sched_getscheduler($module, pid, /)\n"
1853"--\n"
1854"\n"
1855"Get the scheduling policy for the process identifiedy by pid.\n"
1856"\n"
1857"Passing 0 for pid returns the scheduling policy for the calling process.");
1858
1859#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001860 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001861
1862static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001863os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001864
1865static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001866os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001867{
1868 PyObject *return_value = NULL;
1869 pid_t pid;
1870
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001871 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001872 goto exit;
1873 return_value = os_sched_getscheduler_impl(module, pid);
1874
1875exit:
1876 return return_value;
1877}
1878
1879#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1880
1881#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1882
1883PyDoc_STRVAR(os_sched_param__doc__,
1884"sched_param(sched_priority)\n"
1885"--\n"
1886"\n"
1887"Current has only one field: sched_priority\");\n"
1888"\n"
1889" sched_priority\n"
1890" A scheduling parameter.");
1891
1892static PyObject *
1893os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1894
1895static PyObject *
1896os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1897{
1898 PyObject *return_value = NULL;
1899 static char *_keywords[] = {"sched_priority", NULL};
1900 PyObject *sched_priority;
1901
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001902 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:sched_param", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001903 &sched_priority))
1904 goto exit;
1905 return_value = os_sched_param_impl(type, sched_priority);
1906
1907exit:
1908 return return_value;
1909}
1910
1911#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
1912
1913#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1914
1915PyDoc_STRVAR(os_sched_setscheduler__doc__,
1916"sched_setscheduler($module, pid, policy, param, /)\n"
1917"--\n"
1918"\n"
1919"Set the scheduling policy for the process identified by pid.\n"
1920"\n"
1921"If pid is 0, the calling process is changed.\n"
1922"param is an instance of sched_param.");
1923
1924#define OS_SCHED_SETSCHEDULER_METHODDEF \
1925 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
1926
1927static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001928os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04001929 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001930
1931static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001932os_sched_setscheduler(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001933{
1934 PyObject *return_value = NULL;
1935 pid_t pid;
1936 int policy;
1937 struct sched_param param;
1938
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001939 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001940 &pid, &policy, convert_sched_param, &param))
1941 goto exit;
1942 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
1943
1944exit:
1945 return return_value;
1946}
1947
1948#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1949
1950#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
1951
1952PyDoc_STRVAR(os_sched_getparam__doc__,
1953"sched_getparam($module, pid, /)\n"
1954"--\n"
1955"\n"
1956"Returns scheduling parameters for the process identified by pid.\n"
1957"\n"
1958"If pid is 0, returns parameters for the calling process.\n"
1959"Return value is an instance of sched_param.");
1960
1961#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001962 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001963
1964static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001965os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001966
1967static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001968os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001969{
1970 PyObject *return_value = NULL;
1971 pid_t pid;
1972
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001973 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001974 goto exit;
1975 return_value = os_sched_getparam_impl(module, pid);
1976
1977exit:
1978 return return_value;
1979}
1980
1981#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
1982
1983#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
1984
1985PyDoc_STRVAR(os_sched_setparam__doc__,
1986"sched_setparam($module, pid, param, /)\n"
1987"--\n"
1988"\n"
1989"Set scheduling parameters for the process identified by pid.\n"
1990"\n"
1991"If pid is 0, sets parameters for the calling process.\n"
1992"param should be an instance of sched_param.");
1993
1994#define OS_SCHED_SETPARAM_METHODDEF \
1995 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
1996
1997static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001998os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04001999 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002000
2001static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002002os_sched_setparam(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003{
2004 PyObject *return_value = NULL;
2005 pid_t pid;
2006 struct sched_param param;
2007
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002008 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002009 &pid, convert_sched_param, &param))
2010 goto exit;
2011 return_value = os_sched_setparam_impl(module, pid, &param);
2012
2013exit:
2014 return return_value;
2015}
2016
2017#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2018
2019#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2020
2021PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2022"sched_rr_get_interval($module, pid, /)\n"
2023"--\n"
2024"\n"
2025"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2026"\n"
2027"Value returned is a float.");
2028
2029#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002030 {"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 +03002031
2032static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002033os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002034
2035static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002036os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002037{
2038 PyObject *return_value = NULL;
2039 pid_t pid;
2040 double _return_value;
2041
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002042 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002043 goto exit;
2044 _return_value = os_sched_rr_get_interval_impl(module, pid);
2045 if ((_return_value == -1.0) && PyErr_Occurred())
2046 goto exit;
2047 return_value = PyFloat_FromDouble(_return_value);
2048
2049exit:
2050 return return_value;
2051}
2052
2053#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2054
2055#if defined(HAVE_SCHED_H)
2056
2057PyDoc_STRVAR(os_sched_yield__doc__,
2058"sched_yield($module, /)\n"
2059"--\n"
2060"\n"
2061"Voluntarily relinquish the CPU.");
2062
2063#define OS_SCHED_YIELD_METHODDEF \
2064 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2065
2066static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002067os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002068
2069static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002070os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002071{
2072 return os_sched_yield_impl(module);
2073}
2074
2075#endif /* defined(HAVE_SCHED_H) */
2076
2077#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2078
2079PyDoc_STRVAR(os_sched_setaffinity__doc__,
2080"sched_setaffinity($module, pid, mask, /)\n"
2081"--\n"
2082"\n"
2083"Set the CPU affinity of the process identified by pid to mask.\n"
2084"\n"
2085"mask should be an iterable of integers identifying CPUs.");
2086
2087#define OS_SCHED_SETAFFINITY_METHODDEF \
2088 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
2089
2090static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002091os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002092
2093static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002094os_sched_setaffinity(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002095{
2096 PyObject *return_value = NULL;
2097 pid_t pid;
2098 PyObject *mask;
2099
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002100 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002101 &pid, &mask))
2102 goto exit;
2103 return_value = os_sched_setaffinity_impl(module, pid, mask);
2104
2105exit:
2106 return return_value;
2107}
2108
2109#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2110
2111#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2112
2113PyDoc_STRVAR(os_sched_getaffinity__doc__,
2114"sched_getaffinity($module, pid, /)\n"
2115"--\n"
2116"\n"
2117"Return the affinity of the process identified by pid.\n"
2118"\n"
2119"The affinity is returned as a set of CPU identifiers.");
2120
2121#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002122 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002123
2124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002125os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002126
2127static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002128os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002129{
2130 PyObject *return_value = NULL;
2131 pid_t pid;
2132
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002133 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134 goto exit;
2135 return_value = os_sched_getaffinity_impl(module, pid);
2136
2137exit:
2138 return return_value;
2139}
2140
2141#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2142
2143#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2144
2145PyDoc_STRVAR(os_openpty__doc__,
2146"openpty($module, /)\n"
2147"--\n"
2148"\n"
2149"Open a pseudo-terminal.\n"
2150"\n"
2151"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2152"for both the master and slave ends.");
2153
2154#define OS_OPENPTY_METHODDEF \
2155 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2156
2157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002158os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002159
2160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002161os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002162{
2163 return os_openpty_impl(module);
2164}
2165
2166#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2167
2168#if defined(HAVE_FORKPTY)
2169
2170PyDoc_STRVAR(os_forkpty__doc__,
2171"forkpty($module, /)\n"
2172"--\n"
2173"\n"
2174"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2175"\n"
2176"Returns a tuple of (pid, master_fd).\n"
2177"Like fork(), return pid of 0 to the child process,\n"
2178"and pid of child to the parent process.\n"
2179"To both, return fd of newly opened pseudo-terminal.");
2180
2181#define OS_FORKPTY_METHODDEF \
2182 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2183
2184static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002185os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186
2187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002188os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002189{
2190 return os_forkpty_impl(module);
2191}
2192
2193#endif /* defined(HAVE_FORKPTY) */
2194
2195#if defined(HAVE_GETEGID)
2196
2197PyDoc_STRVAR(os_getegid__doc__,
2198"getegid($module, /)\n"
2199"--\n"
2200"\n"
2201"Return the current process\'s effective group id.");
2202
2203#define OS_GETEGID_METHODDEF \
2204 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2205
2206static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002207os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002208
2209static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002210os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002211{
2212 return os_getegid_impl(module);
2213}
2214
2215#endif /* defined(HAVE_GETEGID) */
2216
2217#if defined(HAVE_GETEUID)
2218
2219PyDoc_STRVAR(os_geteuid__doc__,
2220"geteuid($module, /)\n"
2221"--\n"
2222"\n"
2223"Return the current process\'s effective user id.");
2224
2225#define OS_GETEUID_METHODDEF \
2226 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2227
2228static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002229os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002230
2231static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002232os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002233{
2234 return os_geteuid_impl(module);
2235}
2236
2237#endif /* defined(HAVE_GETEUID) */
2238
2239#if defined(HAVE_GETGID)
2240
2241PyDoc_STRVAR(os_getgid__doc__,
2242"getgid($module, /)\n"
2243"--\n"
2244"\n"
2245"Return the current process\'s group id.");
2246
2247#define OS_GETGID_METHODDEF \
2248 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2249
2250static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002251os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002252
2253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002254os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002255{
2256 return os_getgid_impl(module);
2257}
2258
2259#endif /* defined(HAVE_GETGID) */
2260
2261PyDoc_STRVAR(os_getpid__doc__,
2262"getpid($module, /)\n"
2263"--\n"
2264"\n"
2265"Return the current process id.");
2266
2267#define OS_GETPID_METHODDEF \
2268 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2269
2270static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002271os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002272
2273static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002274os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002275{
2276 return os_getpid_impl(module);
2277}
2278
2279#if defined(HAVE_GETGROUPS)
2280
2281PyDoc_STRVAR(os_getgroups__doc__,
2282"getgroups($module, /)\n"
2283"--\n"
2284"\n"
2285"Return list of supplemental group IDs for the process.");
2286
2287#define OS_GETGROUPS_METHODDEF \
2288 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2289
2290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002291os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002292
2293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002294os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002295{
2296 return os_getgroups_impl(module);
2297}
2298
2299#endif /* defined(HAVE_GETGROUPS) */
2300
2301#if defined(HAVE_GETPGID)
2302
2303PyDoc_STRVAR(os_getpgid__doc__,
2304"getpgid($module, /, pid)\n"
2305"--\n"
2306"\n"
2307"Call the system call getpgid(), and return the result.");
2308
2309#define OS_GETPGID_METHODDEF \
2310 {"getpgid", (PyCFunction)os_getpgid, METH_VARARGS|METH_KEYWORDS, os_getpgid__doc__},
2311
2312static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002313os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002314
2315static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002316os_getpgid(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002317{
2318 PyObject *return_value = NULL;
2319 static char *_keywords[] = {"pid", NULL};
2320 pid_t pid;
2321
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002322 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "" _Py_PARSE_PID ":getpgid", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002323 &pid))
2324 goto exit;
2325 return_value = os_getpgid_impl(module, pid);
2326
2327exit:
2328 return return_value;
2329}
2330
2331#endif /* defined(HAVE_GETPGID) */
2332
2333#if defined(HAVE_GETPGRP)
2334
2335PyDoc_STRVAR(os_getpgrp__doc__,
2336"getpgrp($module, /)\n"
2337"--\n"
2338"\n"
2339"Return the current process group id.");
2340
2341#define OS_GETPGRP_METHODDEF \
2342 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2343
2344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002345os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002346
2347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002348os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002349{
2350 return os_getpgrp_impl(module);
2351}
2352
2353#endif /* defined(HAVE_GETPGRP) */
2354
2355#if defined(HAVE_SETPGRP)
2356
2357PyDoc_STRVAR(os_setpgrp__doc__,
2358"setpgrp($module, /)\n"
2359"--\n"
2360"\n"
2361"Make the current process the leader of its process group.");
2362
2363#define OS_SETPGRP_METHODDEF \
2364 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2365
2366static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002367os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002368
2369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002370os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002371{
2372 return os_setpgrp_impl(module);
2373}
2374
2375#endif /* defined(HAVE_SETPGRP) */
2376
2377#if defined(HAVE_GETPPID)
2378
2379PyDoc_STRVAR(os_getppid__doc__,
2380"getppid($module, /)\n"
2381"--\n"
2382"\n"
2383"Return the parent\'s process id.\n"
2384"\n"
2385"If the parent process has already exited, Windows machines will still\n"
2386"return its id; others systems will return the id of the \'init\' process (1).");
2387
2388#define OS_GETPPID_METHODDEF \
2389 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2390
2391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002392os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002393
2394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002395os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002396{
2397 return os_getppid_impl(module);
2398}
2399
2400#endif /* defined(HAVE_GETPPID) */
2401
2402#if defined(HAVE_GETLOGIN)
2403
2404PyDoc_STRVAR(os_getlogin__doc__,
2405"getlogin($module, /)\n"
2406"--\n"
2407"\n"
2408"Return the actual login name.");
2409
2410#define OS_GETLOGIN_METHODDEF \
2411 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2412
2413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002414os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002415
2416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002417os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002418{
2419 return os_getlogin_impl(module);
2420}
2421
2422#endif /* defined(HAVE_GETLOGIN) */
2423
2424#if defined(HAVE_GETUID)
2425
2426PyDoc_STRVAR(os_getuid__doc__,
2427"getuid($module, /)\n"
2428"--\n"
2429"\n"
2430"Return the current process\'s user id.");
2431
2432#define OS_GETUID_METHODDEF \
2433 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2434
2435static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002436os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002437
2438static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002439os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002440{
2441 return os_getuid_impl(module);
2442}
2443
2444#endif /* defined(HAVE_GETUID) */
2445
2446#if defined(HAVE_KILL)
2447
2448PyDoc_STRVAR(os_kill__doc__,
2449"kill($module, pid, signal, /)\n"
2450"--\n"
2451"\n"
2452"Kill a process with a signal.");
2453
2454#define OS_KILL_METHODDEF \
2455 {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
2456
2457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002458os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002459
2460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002461os_kill(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002462{
2463 PyObject *return_value = NULL;
2464 pid_t pid;
2465 Py_ssize_t signal;
2466
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002467 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002468 &pid, &signal))
2469 goto exit;
2470 return_value = os_kill_impl(module, pid, signal);
2471
2472exit:
2473 return return_value;
2474}
2475
2476#endif /* defined(HAVE_KILL) */
2477
2478#if defined(HAVE_KILLPG)
2479
2480PyDoc_STRVAR(os_killpg__doc__,
2481"killpg($module, pgid, signal, /)\n"
2482"--\n"
2483"\n"
2484"Kill a process group with a signal.");
2485
2486#define OS_KILLPG_METHODDEF \
2487 {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
2488
2489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002490os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491
2492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002493os_killpg(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002494{
2495 PyObject *return_value = NULL;
2496 pid_t pgid;
2497 int signal;
2498
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002499 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002500 &pgid, &signal))
2501 goto exit;
2502 return_value = os_killpg_impl(module, pgid, signal);
2503
2504exit:
2505 return return_value;
2506}
2507
2508#endif /* defined(HAVE_KILLPG) */
2509
2510#if defined(HAVE_PLOCK)
2511
2512PyDoc_STRVAR(os_plock__doc__,
2513"plock($module, op, /)\n"
2514"--\n"
2515"\n"
2516"Lock program segments into memory.\");");
2517
2518#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002519 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002520
2521static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002522os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002523
2524static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002525os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002526{
2527 PyObject *return_value = NULL;
2528 int op;
2529
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002530 if (!PyArg_Parse(arg, "i:plock", &op))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002531 goto exit;
2532 return_value = os_plock_impl(module, op);
2533
2534exit:
2535 return return_value;
2536}
2537
2538#endif /* defined(HAVE_PLOCK) */
2539
2540#if defined(HAVE_SETUID)
2541
2542PyDoc_STRVAR(os_setuid__doc__,
2543"setuid($module, uid, /)\n"
2544"--\n"
2545"\n"
2546"Set the current process\'s user id.");
2547
2548#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002549 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002550
2551static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002552os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002553
2554static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002555os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002556{
2557 PyObject *return_value = NULL;
2558 uid_t uid;
2559
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002560 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002561 goto exit;
2562 return_value = os_setuid_impl(module, uid);
2563
2564exit:
2565 return return_value;
2566}
2567
2568#endif /* defined(HAVE_SETUID) */
2569
2570#if defined(HAVE_SETEUID)
2571
2572PyDoc_STRVAR(os_seteuid__doc__,
2573"seteuid($module, euid, /)\n"
2574"--\n"
2575"\n"
2576"Set the current process\'s effective user id.");
2577
2578#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002579 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002580
2581static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002582os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002583
2584static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002585os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002586{
2587 PyObject *return_value = NULL;
2588 uid_t euid;
2589
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002590 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002591 goto exit;
2592 return_value = os_seteuid_impl(module, euid);
2593
2594exit:
2595 return return_value;
2596}
2597
2598#endif /* defined(HAVE_SETEUID) */
2599
2600#if defined(HAVE_SETEGID)
2601
2602PyDoc_STRVAR(os_setegid__doc__,
2603"setegid($module, egid, /)\n"
2604"--\n"
2605"\n"
2606"Set the current process\'s effective group id.");
2607
2608#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002609 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002610
2611static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002612os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002613
2614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002615os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002616{
2617 PyObject *return_value = NULL;
2618 gid_t egid;
2619
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002620 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002621 goto exit;
2622 return_value = os_setegid_impl(module, egid);
2623
2624exit:
2625 return return_value;
2626}
2627
2628#endif /* defined(HAVE_SETEGID) */
2629
2630#if defined(HAVE_SETREUID)
2631
2632PyDoc_STRVAR(os_setreuid__doc__,
2633"setreuid($module, ruid, euid, /)\n"
2634"--\n"
2635"\n"
2636"Set the current process\'s real and effective user ids.");
2637
2638#define OS_SETREUID_METHODDEF \
2639 {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
2640
2641static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002642os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002643
2644static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002645os_setreuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002646{
2647 PyObject *return_value = NULL;
2648 uid_t ruid;
2649 uid_t euid;
2650
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002651 if (!PyArg_ParseTuple(args, "O&O&:setreuid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002652 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid))
2653 goto exit;
2654 return_value = os_setreuid_impl(module, ruid, euid);
2655
2656exit:
2657 return return_value;
2658}
2659
2660#endif /* defined(HAVE_SETREUID) */
2661
2662#if defined(HAVE_SETREGID)
2663
2664PyDoc_STRVAR(os_setregid__doc__,
2665"setregid($module, rgid, egid, /)\n"
2666"--\n"
2667"\n"
2668"Set the current process\'s real and effective group ids.");
2669
2670#define OS_SETREGID_METHODDEF \
2671 {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
2672
2673static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002674os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002675
2676static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002677os_setregid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002678{
2679 PyObject *return_value = NULL;
2680 gid_t rgid;
2681 gid_t egid;
2682
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002683 if (!PyArg_ParseTuple(args, "O&O&:setregid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002684 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid))
2685 goto exit;
2686 return_value = os_setregid_impl(module, rgid, egid);
2687
2688exit:
2689 return return_value;
2690}
2691
2692#endif /* defined(HAVE_SETREGID) */
2693
2694#if defined(HAVE_SETGID)
2695
2696PyDoc_STRVAR(os_setgid__doc__,
2697"setgid($module, gid, /)\n"
2698"--\n"
2699"\n"
2700"Set the current process\'s group id.");
2701
2702#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002703 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002704
2705static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002706os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002707
2708static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002709os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002710{
2711 PyObject *return_value = NULL;
2712 gid_t gid;
2713
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002714 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002715 goto exit;
2716 return_value = os_setgid_impl(module, gid);
2717
2718exit:
2719 return return_value;
2720}
2721
2722#endif /* defined(HAVE_SETGID) */
2723
2724#if defined(HAVE_SETGROUPS)
2725
2726PyDoc_STRVAR(os_setgroups__doc__,
2727"setgroups($module, groups, /)\n"
2728"--\n"
2729"\n"
2730"Set the groups of the current process to list.");
2731
2732#define OS_SETGROUPS_METHODDEF \
2733 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2734
2735#endif /* defined(HAVE_SETGROUPS) */
2736
2737#if defined(HAVE_WAIT3)
2738
2739PyDoc_STRVAR(os_wait3__doc__,
2740"wait3($module, /, options)\n"
2741"--\n"
2742"\n"
2743"Wait for completion of a child process.\n"
2744"\n"
2745"Returns a tuple of information about the child process:\n"
2746" (pid, status, rusage)");
2747
2748#define OS_WAIT3_METHODDEF \
2749 {"wait3", (PyCFunction)os_wait3, METH_VARARGS|METH_KEYWORDS, os_wait3__doc__},
2750
2751static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002752os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002753
2754static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002755os_wait3(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002756{
2757 PyObject *return_value = NULL;
2758 static char *_keywords[] = {"options", NULL};
2759 int options;
2760
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002761 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:wait3", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002762 &options))
2763 goto exit;
2764 return_value = os_wait3_impl(module, options);
2765
2766exit:
2767 return return_value;
2768}
2769
2770#endif /* defined(HAVE_WAIT3) */
2771
2772#if defined(HAVE_WAIT4)
2773
2774PyDoc_STRVAR(os_wait4__doc__,
2775"wait4($module, /, pid, options)\n"
2776"--\n"
2777"\n"
2778"Wait for completion of a specific child process.\n"
2779"\n"
2780"Returns a tuple of information about the child process:\n"
2781" (pid, status, rusage)");
2782
2783#define OS_WAIT4_METHODDEF \
2784 {"wait4", (PyCFunction)os_wait4, METH_VARARGS|METH_KEYWORDS, os_wait4__doc__},
2785
2786static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002787os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002788
2789static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002790os_wait4(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002791{
2792 PyObject *return_value = NULL;
2793 static char *_keywords[] = {"pid", "options", NULL};
2794 pid_t pid;
2795 int options;
2796
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002797 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "" _Py_PARSE_PID "i:wait4", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002798 &pid, &options))
2799 goto exit;
2800 return_value = os_wait4_impl(module, pid, options);
2801
2802exit:
2803 return return_value;
2804}
2805
2806#endif /* defined(HAVE_WAIT4) */
2807
2808#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2809
2810PyDoc_STRVAR(os_waitid__doc__,
2811"waitid($module, idtype, id, options, /)\n"
2812"--\n"
2813"\n"
2814"Returns the result of waiting for a process or processes.\n"
2815"\n"
2816" idtype\n"
2817" Must be one of be P_PID, P_PGID or P_ALL.\n"
2818" id\n"
2819" The id to wait on.\n"
2820" options\n"
2821" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2822" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2823"\n"
2824"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2825"no children in a waitable state.");
2826
2827#define OS_WAITID_METHODDEF \
2828 {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
2829
2830static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002831os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002832
2833static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002834os_waitid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002835{
2836 PyObject *return_value = NULL;
2837 idtype_t idtype;
2838 id_t id;
2839 int options;
2840
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002841 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002842 &idtype, &id, &options))
2843 goto exit;
2844 return_value = os_waitid_impl(module, idtype, id, options);
2845
2846exit:
2847 return return_value;
2848}
2849
2850#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
2851
2852#if defined(HAVE_WAITPID)
2853
2854PyDoc_STRVAR(os_waitpid__doc__,
2855"waitpid($module, pid, options, /)\n"
2856"--\n"
2857"\n"
2858"Wait for completion of a given child process.\n"
2859"\n"
2860"Returns a tuple of information regarding the child process:\n"
2861" (pid, status)\n"
2862"\n"
2863"The options argument is ignored on Windows.");
2864
2865#define OS_WAITPID_METHODDEF \
2866 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2867
2868static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002869os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002870
2871static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002872os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002873{
2874 PyObject *return_value = NULL;
2875 pid_t pid;
2876 int options;
2877
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002878 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002879 &pid, &options))
2880 goto exit;
2881 return_value = os_waitpid_impl(module, pid, options);
2882
2883exit:
2884 return return_value;
2885}
2886
2887#endif /* defined(HAVE_WAITPID) */
2888
2889#if defined(HAVE_CWAIT)
2890
2891PyDoc_STRVAR(os_waitpid__doc__,
2892"waitpid($module, pid, options, /)\n"
2893"--\n"
2894"\n"
2895"Wait for completion of a given process.\n"
2896"\n"
2897"Returns a tuple of information regarding the process:\n"
2898" (pid, status << 8)\n"
2899"\n"
2900"The options argument is ignored on Windows.");
2901
2902#define OS_WAITPID_METHODDEF \
2903 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2904
2905static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002906os_waitpid_impl(PyObject *module, Py_intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002907
2908static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002909os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002910{
2911 PyObject *return_value = NULL;
2912 Py_intptr_t pid;
2913 int options;
2914
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002915 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002916 &pid, &options))
2917 goto exit;
2918 return_value = os_waitpid_impl(module, pid, options);
2919
2920exit:
2921 return return_value;
2922}
2923
2924#endif /* defined(HAVE_CWAIT) */
2925
2926#if defined(HAVE_WAIT)
2927
2928PyDoc_STRVAR(os_wait__doc__,
2929"wait($module, /)\n"
2930"--\n"
2931"\n"
2932"Wait for completion of a child process.\n"
2933"\n"
2934"Returns a tuple of information about the child process:\n"
2935" (pid, status)");
2936
2937#define OS_WAIT_METHODDEF \
2938 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
2939
2940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002941os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002942
2943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002944os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002945{
2946 return os_wait_impl(module);
2947}
2948
2949#endif /* defined(HAVE_WAIT) */
2950
2951#if defined(HAVE_SYMLINK)
2952
2953PyDoc_STRVAR(os_symlink__doc__,
2954"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
2955"--\n"
2956"\n"
2957"Create a symbolic link pointing to src named dst.\n"
2958"\n"
2959"target_is_directory is required on Windows if the target is to be\n"
2960" interpreted as a directory. (On Windows, symlink requires\n"
2961" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
2962" target_is_directory is ignored on non-Windows platforms.\n"
2963"\n"
2964"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2965" and path should be relative; path will then be relative to that directory.\n"
2966"dir_fd may not be implemented on your platform.\n"
2967" If it is unavailable, using it will raise a NotImplementedError.");
2968
2969#define OS_SYMLINK_METHODDEF \
2970 {"symlink", (PyCFunction)os_symlink, METH_VARARGS|METH_KEYWORDS, os_symlink__doc__},
2971
2972static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002973os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04002974 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002975
2976static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002977os_symlink(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002978{
2979 PyObject *return_value = NULL;
2980 static char *_keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
2981 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
2982 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
2983 int target_is_directory = 0;
2984 int dir_fd = DEFAULT_DIR_FD;
2985
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002986 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|p$O&:symlink", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002987 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd))
2988 goto exit;
2989 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
2990
2991exit:
2992 /* Cleanup for src */
2993 path_cleanup(&src);
2994 /* Cleanup for dst */
2995 path_cleanup(&dst);
2996
2997 return return_value;
2998}
2999
3000#endif /* defined(HAVE_SYMLINK) */
3001
3002#if defined(HAVE_TIMES)
3003
3004PyDoc_STRVAR(os_times__doc__,
3005"times($module, /)\n"
3006"--\n"
3007"\n"
3008"Return a collection containing process timing information.\n"
3009"\n"
3010"The object returned behaves like a named tuple with these fields:\n"
3011" (utime, stime, cutime, cstime, elapsed_time)\n"
3012"All fields are floating point numbers.");
3013
3014#define OS_TIMES_METHODDEF \
3015 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3016
3017static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003018os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003019
3020static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003021os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003022{
3023 return os_times_impl(module);
3024}
3025
3026#endif /* defined(HAVE_TIMES) */
3027
3028#if defined(HAVE_GETSID)
3029
3030PyDoc_STRVAR(os_getsid__doc__,
3031"getsid($module, pid, /)\n"
3032"--\n"
3033"\n"
3034"Call the system call getsid(pid) and return the result.");
3035
3036#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003037 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003038
3039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003040os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003041
3042static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003043os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003044{
3045 PyObject *return_value = NULL;
3046 pid_t pid;
3047
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003048 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003049 goto exit;
3050 return_value = os_getsid_impl(module, pid);
3051
3052exit:
3053 return return_value;
3054}
3055
3056#endif /* defined(HAVE_GETSID) */
3057
3058#if defined(HAVE_SETSID)
3059
3060PyDoc_STRVAR(os_setsid__doc__,
3061"setsid($module, /)\n"
3062"--\n"
3063"\n"
3064"Call the system call setsid().");
3065
3066#define OS_SETSID_METHODDEF \
3067 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3068
3069static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003070os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003071
3072static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003073os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003074{
3075 return os_setsid_impl(module);
3076}
3077
3078#endif /* defined(HAVE_SETSID) */
3079
3080#if defined(HAVE_SETPGID)
3081
3082PyDoc_STRVAR(os_setpgid__doc__,
3083"setpgid($module, pid, pgrp, /)\n"
3084"--\n"
3085"\n"
3086"Call the system call setpgid(pid, pgrp).");
3087
3088#define OS_SETPGID_METHODDEF \
3089 {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
3090
3091static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003092os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003093
3094static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003095os_setpgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003096{
3097 PyObject *return_value = NULL;
3098 pid_t pid;
3099 pid_t pgrp;
3100
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003101 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003102 &pid, &pgrp))
3103 goto exit;
3104 return_value = os_setpgid_impl(module, pid, pgrp);
3105
3106exit:
3107 return return_value;
3108}
3109
3110#endif /* defined(HAVE_SETPGID) */
3111
3112#if defined(HAVE_TCGETPGRP)
3113
3114PyDoc_STRVAR(os_tcgetpgrp__doc__,
3115"tcgetpgrp($module, fd, /)\n"
3116"--\n"
3117"\n"
3118"Return the process group associated with the terminal specified by fd.");
3119
3120#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003121 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003122
3123static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003124os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003125
3126static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003127os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003128{
3129 PyObject *return_value = NULL;
3130 int fd;
3131
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003132 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003133 goto exit;
3134 return_value = os_tcgetpgrp_impl(module, fd);
3135
3136exit:
3137 return return_value;
3138}
3139
3140#endif /* defined(HAVE_TCGETPGRP) */
3141
3142#if defined(HAVE_TCSETPGRP)
3143
3144PyDoc_STRVAR(os_tcsetpgrp__doc__,
3145"tcsetpgrp($module, fd, pgid, /)\n"
3146"--\n"
3147"\n"
3148"Set the process group associated with the terminal specified by fd.");
3149
3150#define OS_TCSETPGRP_METHODDEF \
3151 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
3152
3153static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003154os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003155
3156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003157os_tcsetpgrp(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003158{
3159 PyObject *return_value = NULL;
3160 int fd;
3161 pid_t pgid;
3162
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003163 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003164 &fd, &pgid))
3165 goto exit;
3166 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3167
3168exit:
3169 return return_value;
3170}
3171
3172#endif /* defined(HAVE_TCSETPGRP) */
3173
3174PyDoc_STRVAR(os_open__doc__,
3175"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3176"--\n"
3177"\n"
3178"Open a file for low level IO. Returns a file descriptor (integer).\n"
3179"\n"
3180"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3181" and path should be relative; path will then be relative to that directory.\n"
3182"dir_fd may not be implemented on your platform.\n"
3183" If it is unavailable, using it will raise a NotImplementedError.");
3184
3185#define OS_OPEN_METHODDEF \
3186 {"open", (PyCFunction)os_open, METH_VARARGS|METH_KEYWORDS, os_open__doc__},
3187
3188static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003189os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003190
3191static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003192os_open(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003193{
3194 PyObject *return_value = NULL;
3195 static char *_keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3196 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3197 int flags;
3198 int mode = 511;
3199 int dir_fd = DEFAULT_DIR_FD;
3200 int _return_value;
3201
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003202 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|i$O&:open", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003203 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd))
3204 goto exit;
3205 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
3206 if ((_return_value == -1) && PyErr_Occurred())
3207 goto exit;
3208 return_value = PyLong_FromLong((long)_return_value);
3209
3210exit:
3211 /* Cleanup for path */
3212 path_cleanup(&path);
3213
3214 return return_value;
3215}
3216
3217PyDoc_STRVAR(os_close__doc__,
3218"close($module, /, fd)\n"
3219"--\n"
3220"\n"
3221"Close a file descriptor.");
3222
3223#define OS_CLOSE_METHODDEF \
3224 {"close", (PyCFunction)os_close, METH_VARARGS|METH_KEYWORDS, os_close__doc__},
3225
3226static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003227os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003228
3229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003230os_close(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003231{
3232 PyObject *return_value = NULL;
3233 static char *_keywords[] = {"fd", NULL};
3234 int fd;
3235
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003236 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:close", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003237 &fd))
3238 goto exit;
3239 return_value = os_close_impl(module, fd);
3240
3241exit:
3242 return return_value;
3243}
3244
3245PyDoc_STRVAR(os_closerange__doc__,
3246"closerange($module, fd_low, fd_high, /)\n"
3247"--\n"
3248"\n"
3249"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3250
3251#define OS_CLOSERANGE_METHODDEF \
3252 {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
3253
3254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003255os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003256
3257static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003258os_closerange(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003259{
3260 PyObject *return_value = NULL;
3261 int fd_low;
3262 int fd_high;
3263
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003264 if (!PyArg_ParseTuple(args, "ii:closerange",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003265 &fd_low, &fd_high))
3266 goto exit;
3267 return_value = os_closerange_impl(module, fd_low, fd_high);
3268
3269exit:
3270 return return_value;
3271}
3272
3273PyDoc_STRVAR(os_dup__doc__,
3274"dup($module, fd, /)\n"
3275"--\n"
3276"\n"
3277"Return a duplicate of a file descriptor.");
3278
3279#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003280 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003281
3282static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003283os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003284
3285static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003286os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003287{
3288 PyObject *return_value = NULL;
3289 int fd;
3290 int _return_value;
3291
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003292 if (!PyArg_Parse(arg, "i:dup", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003293 goto exit;
3294 _return_value = os_dup_impl(module, fd);
3295 if ((_return_value == -1) && PyErr_Occurred())
3296 goto exit;
3297 return_value = PyLong_FromLong((long)_return_value);
3298
3299exit:
3300 return return_value;
3301}
3302
3303PyDoc_STRVAR(os_dup2__doc__,
3304"dup2($module, /, fd, fd2, inheritable=True)\n"
3305"--\n"
3306"\n"
3307"Duplicate file descriptor.");
3308
3309#define OS_DUP2_METHODDEF \
3310 {"dup2", (PyCFunction)os_dup2, METH_VARARGS|METH_KEYWORDS, os_dup2__doc__},
3311
3312static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003313os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003314
3315static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003316os_dup2(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003317{
3318 PyObject *return_value = NULL;
3319 static char *_keywords[] = {"fd", "fd2", "inheritable", NULL};
3320 int fd;
3321 int fd2;
3322 int inheritable = 1;
3323
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003324 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|p:dup2", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003325 &fd, &fd2, &inheritable))
3326 goto exit;
3327 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3328
3329exit:
3330 return return_value;
3331}
3332
3333#if defined(HAVE_LOCKF)
3334
3335PyDoc_STRVAR(os_lockf__doc__,
3336"lockf($module, fd, command, length, /)\n"
3337"--\n"
3338"\n"
3339"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3340"\n"
3341" fd\n"
3342" An open file descriptor.\n"
3343" command\n"
3344" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3345" length\n"
3346" The number of bytes to lock, starting at the current position.");
3347
3348#define OS_LOCKF_METHODDEF \
3349 {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
3350
3351static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003352os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003353
3354static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003355os_lockf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003356{
3357 PyObject *return_value = NULL;
3358 int fd;
3359 int command;
3360 Py_off_t length;
3361
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003362 if (!PyArg_ParseTuple(args, "iiO&:lockf",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003363 &fd, &command, Py_off_t_converter, &length))
3364 goto exit;
3365 return_value = os_lockf_impl(module, fd, command, length);
3366
3367exit:
3368 return return_value;
3369}
3370
3371#endif /* defined(HAVE_LOCKF) */
3372
3373PyDoc_STRVAR(os_lseek__doc__,
3374"lseek($module, fd, position, how, /)\n"
3375"--\n"
3376"\n"
3377"Set the position of a file descriptor. Return the new position.\n"
3378"\n"
3379"Return the new cursor position in number of bytes\n"
3380"relative to the beginning of the file.");
3381
3382#define OS_LSEEK_METHODDEF \
3383 {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
3384
3385static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003386os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003387
3388static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003389os_lseek(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003390{
3391 PyObject *return_value = NULL;
3392 int fd;
3393 Py_off_t position;
3394 int how;
3395 Py_off_t _return_value;
3396
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003397 if (!PyArg_ParseTuple(args, "iO&i:lseek",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003398 &fd, Py_off_t_converter, &position, &how))
3399 goto exit;
3400 _return_value = os_lseek_impl(module, fd, position, how);
3401 if ((_return_value == -1) && PyErr_Occurred())
3402 goto exit;
3403 return_value = PyLong_FromPy_off_t(_return_value);
3404
3405exit:
3406 return return_value;
3407}
3408
3409PyDoc_STRVAR(os_read__doc__,
3410"read($module, fd, length, /)\n"
3411"--\n"
3412"\n"
3413"Read from a file descriptor. Returns a bytes object.");
3414
3415#define OS_READ_METHODDEF \
3416 {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
3417
3418static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003419os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003420
3421static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003422os_read(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003423{
3424 PyObject *return_value = NULL;
3425 int fd;
3426 Py_ssize_t length;
3427
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003428 if (!PyArg_ParseTuple(args, "in:read",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003429 &fd, &length))
3430 goto exit;
3431 return_value = os_read_impl(module, fd, length);
3432
3433exit:
3434 return return_value;
3435}
3436
3437#if defined(HAVE_READV)
3438
3439PyDoc_STRVAR(os_readv__doc__,
3440"readv($module, fd, buffers, /)\n"
3441"--\n"
3442"\n"
3443"Read from a file descriptor fd into an iterable of buffers.\n"
3444"\n"
3445"The buffers should be mutable buffers accepting bytes.\n"
3446"readv will transfer data into each buffer until it is full\n"
3447"and then move on to the next buffer in the sequence to hold\n"
3448"the rest of the data.\n"
3449"\n"
3450"readv returns the total number of bytes read,\n"
3451"which may be less than the total capacity of all the buffers.");
3452
3453#define OS_READV_METHODDEF \
3454 {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
3455
3456static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003457os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003458
3459static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003460os_readv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003461{
3462 PyObject *return_value = NULL;
3463 int fd;
3464 PyObject *buffers;
3465 Py_ssize_t _return_value;
3466
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003467 if (!PyArg_ParseTuple(args, "iO:readv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003468 &fd, &buffers))
3469 goto exit;
3470 _return_value = os_readv_impl(module, fd, buffers);
3471 if ((_return_value == -1) && PyErr_Occurred())
3472 goto exit;
3473 return_value = PyLong_FromSsize_t(_return_value);
3474
3475exit:
3476 return return_value;
3477}
3478
3479#endif /* defined(HAVE_READV) */
3480
3481#if defined(HAVE_PREAD)
3482
3483PyDoc_STRVAR(os_pread__doc__,
3484"pread($module, fd, length, offset, /)\n"
3485"--\n"
3486"\n"
3487"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3488"\n"
3489"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3490"the beginning of the file. The file offset remains unchanged.");
3491
3492#define OS_PREAD_METHODDEF \
3493 {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
3494
3495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003496os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003497
3498static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003499os_pread(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003500{
3501 PyObject *return_value = NULL;
3502 int fd;
3503 int length;
3504 Py_off_t offset;
3505
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003506 if (!PyArg_ParseTuple(args, "iiO&:pread",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003507 &fd, &length, Py_off_t_converter, &offset))
3508 goto exit;
3509 return_value = os_pread_impl(module, fd, length, offset);
3510
3511exit:
3512 return return_value;
3513}
3514
3515#endif /* defined(HAVE_PREAD) */
3516
3517PyDoc_STRVAR(os_write__doc__,
3518"write($module, fd, data, /)\n"
3519"--\n"
3520"\n"
3521"Write a bytes object to a file descriptor.");
3522
3523#define OS_WRITE_METHODDEF \
3524 {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
3525
3526static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003527os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003528
3529static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003530os_write(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003531{
3532 PyObject *return_value = NULL;
3533 int fd;
3534 Py_buffer data = {NULL, NULL};
3535 Py_ssize_t _return_value;
3536
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003537 if (!PyArg_ParseTuple(args, "iy*:write",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003538 &fd, &data))
3539 goto exit;
3540 _return_value = os_write_impl(module, fd, &data);
3541 if ((_return_value == -1) && PyErr_Occurred())
3542 goto exit;
3543 return_value = PyLong_FromSsize_t(_return_value);
3544
3545exit:
3546 /* Cleanup for data */
3547 if (data.obj)
3548 PyBuffer_Release(&data);
3549
3550 return return_value;
3551}
3552
3553PyDoc_STRVAR(os_fstat__doc__,
3554"fstat($module, /, fd)\n"
3555"--\n"
3556"\n"
3557"Perform a stat system call on the given file descriptor.\n"
3558"\n"
3559"Like stat(), but for an open file descriptor.\n"
3560"Equivalent to os.stat(fd).");
3561
3562#define OS_FSTAT_METHODDEF \
3563 {"fstat", (PyCFunction)os_fstat, METH_VARARGS|METH_KEYWORDS, os_fstat__doc__},
3564
3565static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003566os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003567
3568static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003569os_fstat(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003570{
3571 PyObject *return_value = NULL;
3572 static char *_keywords[] = {"fd", NULL};
3573 int fd;
3574
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003575 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:fstat", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003576 &fd))
3577 goto exit;
3578 return_value = os_fstat_impl(module, fd);
3579
3580exit:
3581 return return_value;
3582}
3583
3584PyDoc_STRVAR(os_isatty__doc__,
3585"isatty($module, fd, /)\n"
3586"--\n"
3587"\n"
3588"Return True if the fd is connected to a terminal.\n"
3589"\n"
3590"Return True if the file descriptor is an open file descriptor\n"
3591"connected to the slave end of a terminal.");
3592
3593#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003594 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003595
3596static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003597os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003598
3599static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003600os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003601{
3602 PyObject *return_value = NULL;
3603 int fd;
3604 int _return_value;
3605
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003606 if (!PyArg_Parse(arg, "i:isatty", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003607 goto exit;
3608 _return_value = os_isatty_impl(module, fd);
3609 if ((_return_value == -1) && PyErr_Occurred())
3610 goto exit;
3611 return_value = PyBool_FromLong((long)_return_value);
3612
3613exit:
3614 return return_value;
3615}
3616
3617#if defined(HAVE_PIPE)
3618
3619PyDoc_STRVAR(os_pipe__doc__,
3620"pipe($module, /)\n"
3621"--\n"
3622"\n"
3623"Create a pipe.\n"
3624"\n"
3625"Returns a tuple of two file descriptors:\n"
3626" (read_fd, write_fd)");
3627
3628#define OS_PIPE_METHODDEF \
3629 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3630
3631static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003632os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003633
3634static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003635os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003636{
3637 return os_pipe_impl(module);
3638}
3639
3640#endif /* defined(HAVE_PIPE) */
3641
3642#if defined(HAVE_PIPE2)
3643
3644PyDoc_STRVAR(os_pipe2__doc__,
3645"pipe2($module, flags, /)\n"
3646"--\n"
3647"\n"
3648"Create a pipe with flags set atomically.\n"
3649"\n"
3650"Returns a tuple of two file descriptors:\n"
3651" (read_fd, write_fd)\n"
3652"\n"
3653"flags can be constructed by ORing together one or more of these values:\n"
3654"O_NONBLOCK, O_CLOEXEC.");
3655
3656#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003657 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003658
3659static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003660os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003661
3662static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003663os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003664{
3665 PyObject *return_value = NULL;
3666 int flags;
3667
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003668 if (!PyArg_Parse(arg, "i:pipe2", &flags))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003669 goto exit;
3670 return_value = os_pipe2_impl(module, flags);
3671
3672exit:
3673 return return_value;
3674}
3675
3676#endif /* defined(HAVE_PIPE2) */
3677
3678#if defined(HAVE_WRITEV)
3679
3680PyDoc_STRVAR(os_writev__doc__,
3681"writev($module, fd, buffers, /)\n"
3682"--\n"
3683"\n"
3684"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3685"\n"
3686"Returns the total number of bytes written.\n"
3687"buffers must be a sequence of bytes-like objects.");
3688
3689#define OS_WRITEV_METHODDEF \
3690 {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
3691
3692static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003693os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003694
3695static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003696os_writev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003697{
3698 PyObject *return_value = NULL;
3699 int fd;
3700 PyObject *buffers;
3701 Py_ssize_t _return_value;
3702
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003703 if (!PyArg_ParseTuple(args, "iO:writev",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003704 &fd, &buffers))
3705 goto exit;
3706 _return_value = os_writev_impl(module, fd, buffers);
3707 if ((_return_value == -1) && PyErr_Occurred())
3708 goto exit;
3709 return_value = PyLong_FromSsize_t(_return_value);
3710
3711exit:
3712 return return_value;
3713}
3714
3715#endif /* defined(HAVE_WRITEV) */
3716
3717#if defined(HAVE_PWRITE)
3718
3719PyDoc_STRVAR(os_pwrite__doc__,
3720"pwrite($module, fd, buffer, offset, /)\n"
3721"--\n"
3722"\n"
3723"Write bytes to a file descriptor starting at a particular offset.\n"
3724"\n"
3725"Write buffer to fd, starting at offset bytes from the beginning of\n"
3726"the file. Returns the number of bytes writte. Does not change the\n"
3727"current file offset.");
3728
3729#define OS_PWRITE_METHODDEF \
3730 {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
3731
3732static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003733os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003734
3735static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003736os_pwrite(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003737{
3738 PyObject *return_value = NULL;
3739 int fd;
3740 Py_buffer buffer = {NULL, NULL};
3741 Py_off_t offset;
3742 Py_ssize_t _return_value;
3743
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003744 if (!PyArg_ParseTuple(args, "iy*O&:pwrite",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003745 &fd, &buffer, Py_off_t_converter, &offset))
3746 goto exit;
3747 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
3748 if ((_return_value == -1) && PyErr_Occurred())
3749 goto exit;
3750 return_value = PyLong_FromSsize_t(_return_value);
3751
3752exit:
3753 /* Cleanup for buffer */
3754 if (buffer.obj)
3755 PyBuffer_Release(&buffer);
3756
3757 return return_value;
3758}
3759
3760#endif /* defined(HAVE_PWRITE) */
3761
3762#if defined(HAVE_MKFIFO)
3763
3764PyDoc_STRVAR(os_mkfifo__doc__,
3765"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3766"--\n"
3767"\n"
3768"Create a \"fifo\" (a POSIX named pipe).\n"
3769"\n"
3770"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3771" and path should be relative; path will then be relative to that directory.\n"
3772"dir_fd may not be implemented on your platform.\n"
3773" If it is unavailable, using it will raise a NotImplementedError.");
3774
3775#define OS_MKFIFO_METHODDEF \
3776 {"mkfifo", (PyCFunction)os_mkfifo, METH_VARARGS|METH_KEYWORDS, os_mkfifo__doc__},
3777
3778static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003779os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003780
3781static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003782os_mkfifo(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003783{
3784 PyObject *return_value = NULL;
3785 static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
3786 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3787 int mode = 438;
3788 int dir_fd = DEFAULT_DIR_FD;
3789
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003790 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkfifo", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003791 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd))
3792 goto exit;
3793 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3794
3795exit:
3796 /* Cleanup for path */
3797 path_cleanup(&path);
3798
3799 return return_value;
3800}
3801
3802#endif /* defined(HAVE_MKFIFO) */
3803
3804#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
3805
3806PyDoc_STRVAR(os_mknod__doc__,
3807"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
3808"--\n"
3809"\n"
3810"Create a node in the file system.\n"
3811"\n"
3812"Create a node in the file system (file, device special file or named pipe)\n"
3813"at path. mode specifies both the permissions to use and the\n"
3814"type of node to be created, being combined (bitwise OR) with one of\n"
3815"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
3816"device defines the newly created device special file (probably using\n"
3817"os.makedev()). Otherwise device is ignored.\n"
3818"\n"
3819"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3820" and path should be relative; path will then be relative to that directory.\n"
3821"dir_fd may not be implemented on your platform.\n"
3822" If it is unavailable, using it will raise a NotImplementedError.");
3823
3824#define OS_MKNOD_METHODDEF \
3825 {"mknod", (PyCFunction)os_mknod, METH_VARARGS|METH_KEYWORDS, os_mknod__doc__},
3826
3827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003828os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04003829 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003830
3831static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003832os_mknod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003833{
3834 PyObject *return_value = NULL;
3835 static char *_keywords[] = {"path", "mode", "device", "dir_fd", NULL};
3836 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
3837 int mode = 384;
3838 dev_t device = 0;
3839 int dir_fd = DEFAULT_DIR_FD;
3840
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003841 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|iO&$O&:mknod", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003842 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd))
3843 goto exit;
3844 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
3845
3846exit:
3847 /* Cleanup for path */
3848 path_cleanup(&path);
3849
3850 return return_value;
3851}
3852
3853#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
3854
3855#if defined(HAVE_DEVICE_MACROS)
3856
3857PyDoc_STRVAR(os_major__doc__,
3858"major($module, device, /)\n"
3859"--\n"
3860"\n"
3861"Extracts a device major number from a raw device number.");
3862
3863#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003864 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003865
3866static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003867os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003868
3869static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003870os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003871{
3872 PyObject *return_value = NULL;
3873 dev_t device;
3874 unsigned int _return_value;
3875
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003876 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003877 goto exit;
3878 _return_value = os_major_impl(module, device);
3879 if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
3880 goto exit;
3881 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
3882
3883exit:
3884 return return_value;
3885}
3886
3887#endif /* defined(HAVE_DEVICE_MACROS) */
3888
3889#if defined(HAVE_DEVICE_MACROS)
3890
3891PyDoc_STRVAR(os_minor__doc__,
3892"minor($module, device, /)\n"
3893"--\n"
3894"\n"
3895"Extracts a device minor number from a raw device number.");
3896
3897#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003898 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003899
3900static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003901os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003902
3903static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003904os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003905{
3906 PyObject *return_value = NULL;
3907 dev_t device;
3908 unsigned int _return_value;
3909
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003910 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003911 goto exit;
3912 _return_value = os_minor_impl(module, device);
3913 if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
3914 goto exit;
3915 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
3916
3917exit:
3918 return return_value;
3919}
3920
3921#endif /* defined(HAVE_DEVICE_MACROS) */
3922
3923#if defined(HAVE_DEVICE_MACROS)
3924
3925PyDoc_STRVAR(os_makedev__doc__,
3926"makedev($module, major, minor, /)\n"
3927"--\n"
3928"\n"
3929"Composes a raw device number from the major and minor device numbers.");
3930
3931#define OS_MAKEDEV_METHODDEF \
3932 {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
3933
3934static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003935os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003936
3937static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003938os_makedev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003939{
3940 PyObject *return_value = NULL;
3941 int major;
3942 int minor;
3943 dev_t _return_value;
3944
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003945 if (!PyArg_ParseTuple(args, "ii:makedev",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003946 &major, &minor))
3947 goto exit;
3948 _return_value = os_makedev_impl(module, major, minor);
3949 if ((_return_value == (dev_t)-1) && PyErr_Occurred())
3950 goto exit;
3951 return_value = _PyLong_FromDev(_return_value);
3952
3953exit:
3954 return return_value;
3955}
3956
3957#endif /* defined(HAVE_DEVICE_MACROS) */
3958
Steve Dowerf7377032015-04-12 15:44:54 -04003959#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003960
3961PyDoc_STRVAR(os_ftruncate__doc__,
3962"ftruncate($module, fd, length, /)\n"
3963"--\n"
3964"\n"
3965"Truncate a file, specified by file descriptor, to a specific length.");
3966
3967#define OS_FTRUNCATE_METHODDEF \
3968 {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
3969
3970static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003971os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003972
3973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003974os_ftruncate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003975{
3976 PyObject *return_value = NULL;
3977 int fd;
3978 Py_off_t length;
3979
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003980 if (!PyArg_ParseTuple(args, "iO&:ftruncate",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003981 &fd, Py_off_t_converter, &length))
3982 goto exit;
3983 return_value = os_ftruncate_impl(module, fd, length);
3984
3985exit:
3986 return return_value;
3987}
3988
Steve Dowerf7377032015-04-12 15:44:54 -04003989#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003990
Steve Dowerf7377032015-04-12 15:44:54 -04003991#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003992
3993PyDoc_STRVAR(os_truncate__doc__,
3994"truncate($module, /, path, length)\n"
3995"--\n"
3996"\n"
3997"Truncate a file, specified by path, to a specific length.\n"
3998"\n"
3999"On some platforms, path may also be specified as an open file descriptor.\n"
4000" If this functionality is unavailable, using it raises an exception.");
4001
4002#define OS_TRUNCATE_METHODDEF \
4003 {"truncate", (PyCFunction)os_truncate, METH_VARARGS|METH_KEYWORDS, os_truncate__doc__},
4004
4005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004006os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004007
4008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004009os_truncate(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004010{
4011 PyObject *return_value = NULL;
4012 static char *_keywords[] = {"path", "length", NULL};
4013 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4014 Py_off_t length;
4015
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004016 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:truncate", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004017 path_converter, &path, Py_off_t_converter, &length))
4018 goto exit;
4019 return_value = os_truncate_impl(module, &path, length);
4020
4021exit:
4022 /* Cleanup for path */
4023 path_cleanup(&path);
4024
4025 return return_value;
4026}
4027
Steve Dowerf7377032015-04-12 15:44:54 -04004028#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004029
4030#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4031
4032PyDoc_STRVAR(os_posix_fallocate__doc__,
4033"posix_fallocate($module, fd, offset, length, /)\n"
4034"--\n"
4035"\n"
4036"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4037"\n"
4038"Ensure that the file specified by fd encompasses a range of bytes\n"
4039"starting at offset bytes from the beginning and continuing for length bytes.");
4040
4041#define OS_POSIX_FALLOCATE_METHODDEF \
4042 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
4043
4044static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004045os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004046 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004047
4048static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004049os_posix_fallocate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004050{
4051 PyObject *return_value = NULL;
4052 int fd;
4053 Py_off_t offset;
4054 Py_off_t length;
4055
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004056 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004057 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length))
4058 goto exit;
4059 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4060
4061exit:
4062 return return_value;
4063}
4064
4065#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4066
4067#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4068
4069PyDoc_STRVAR(os_posix_fadvise__doc__,
4070"posix_fadvise($module, fd, offset, length, advice, /)\n"
4071"--\n"
4072"\n"
4073"Announce an intention to access data in a specific pattern.\n"
4074"\n"
4075"Announce an intention to access data in a specific pattern, thus allowing\n"
4076"the kernel to make optimizations.\n"
4077"The advice applies to the region of the file specified by fd starting at\n"
4078"offset and continuing for length bytes.\n"
4079"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4080"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4081"POSIX_FADV_DONTNEED.");
4082
4083#define OS_POSIX_FADVISE_METHODDEF \
4084 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
4085
4086static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004087os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004088 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004089
4090static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004091os_posix_fadvise(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004092{
4093 PyObject *return_value = NULL;
4094 int fd;
4095 Py_off_t offset;
4096 Py_off_t length;
4097 int advice;
4098
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004099 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004100 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice))
4101 goto exit;
4102 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4103
4104exit:
4105 return return_value;
4106}
4107
4108#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4109
4110#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4111
4112PyDoc_STRVAR(os_putenv__doc__,
4113"putenv($module, name, value, /)\n"
4114"--\n"
4115"\n"
4116"Change or add an environment variable.");
4117
4118#define OS_PUTENV_METHODDEF \
4119 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4120
4121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004122os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004123
4124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004125os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004126{
4127 PyObject *return_value = NULL;
4128 PyObject *name;
4129 PyObject *value;
4130
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004131 if (!PyArg_ParseTuple(args, "UU:putenv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004132 &name, &value))
4133 goto exit;
4134 return_value = os_putenv_impl(module, name, value);
4135
4136exit:
4137 return return_value;
4138}
4139
4140#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4141
4142#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4143
4144PyDoc_STRVAR(os_putenv__doc__,
4145"putenv($module, name, value, /)\n"
4146"--\n"
4147"\n"
4148"Change or add an environment variable.");
4149
4150#define OS_PUTENV_METHODDEF \
4151 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4152
4153static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004154os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004155
4156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004157os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004158{
4159 PyObject *return_value = NULL;
4160 PyObject *name = NULL;
4161 PyObject *value = NULL;
4162
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004163 if (!PyArg_ParseTuple(args, "O&O&:putenv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004164 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value))
4165 goto exit;
4166 return_value = os_putenv_impl(module, name, value);
4167
4168exit:
4169 /* Cleanup for name */
4170 Py_XDECREF(name);
4171 /* Cleanup for value */
4172 Py_XDECREF(value);
4173
4174 return return_value;
4175}
4176
4177#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4178
4179#if defined(HAVE_UNSETENV)
4180
4181PyDoc_STRVAR(os_unsetenv__doc__,
4182"unsetenv($module, name, /)\n"
4183"--\n"
4184"\n"
4185"Delete an environment variable.");
4186
4187#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004188 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004189
4190static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004191os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004192
4193static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004194os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004195{
4196 PyObject *return_value = NULL;
4197 PyObject *name = NULL;
4198
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004199 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004200 goto exit;
4201 return_value = os_unsetenv_impl(module, name);
4202
4203exit:
4204 /* Cleanup for name */
4205 Py_XDECREF(name);
4206
4207 return return_value;
4208}
4209
4210#endif /* defined(HAVE_UNSETENV) */
4211
4212PyDoc_STRVAR(os_strerror__doc__,
4213"strerror($module, code, /)\n"
4214"--\n"
4215"\n"
4216"Translate an error code to a message string.");
4217
4218#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004219 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004220
4221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004222os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004223
4224static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004225os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004226{
4227 PyObject *return_value = NULL;
4228 int code;
4229
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004230 if (!PyArg_Parse(arg, "i:strerror", &code))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004231 goto exit;
4232 return_value = os_strerror_impl(module, code);
4233
4234exit:
4235 return return_value;
4236}
4237
4238#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4239
4240PyDoc_STRVAR(os_WCOREDUMP__doc__,
4241"WCOREDUMP($module, status, /)\n"
4242"--\n"
4243"\n"
4244"Return True if the process returning status was dumped to a core file.");
4245
4246#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004247 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004248
4249static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004250os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004251
4252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004253os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004254{
4255 PyObject *return_value = NULL;
4256 int status;
4257 int _return_value;
4258
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004259 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004260 goto exit;
4261 _return_value = os_WCOREDUMP_impl(module, status);
4262 if ((_return_value == -1) && PyErr_Occurred())
4263 goto exit;
4264 return_value = PyBool_FromLong((long)_return_value);
4265
4266exit:
4267 return return_value;
4268}
4269
4270#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4271
4272#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4273
4274PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4275"WIFCONTINUED($module, /, status)\n"
4276"--\n"
4277"\n"
4278"Return True if a particular process was continued from a job control stop.\n"
4279"\n"
4280"Return True if the process returning status was continued from a\n"
4281"job control stop.");
4282
4283#define OS_WIFCONTINUED_METHODDEF \
4284 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_VARARGS|METH_KEYWORDS, os_WIFCONTINUED__doc__},
4285
4286static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004287os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004288
4289static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004290os_WIFCONTINUED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004291{
4292 PyObject *return_value = NULL;
4293 static char *_keywords[] = {"status", NULL};
4294 int status;
4295 int _return_value;
4296
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004297 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFCONTINUED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004298 &status))
4299 goto exit;
4300 _return_value = os_WIFCONTINUED_impl(module, status);
4301 if ((_return_value == -1) && PyErr_Occurred())
4302 goto exit;
4303 return_value = PyBool_FromLong((long)_return_value);
4304
4305exit:
4306 return return_value;
4307}
4308
4309#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4310
4311#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4312
4313PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4314"WIFSTOPPED($module, /, status)\n"
4315"--\n"
4316"\n"
4317"Return True if the process returning status was stopped.");
4318
4319#define OS_WIFSTOPPED_METHODDEF \
4320 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_VARARGS|METH_KEYWORDS, os_WIFSTOPPED__doc__},
4321
4322static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004323os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004324
4325static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004326os_WIFSTOPPED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004327{
4328 PyObject *return_value = NULL;
4329 static char *_keywords[] = {"status", NULL};
4330 int status;
4331 int _return_value;
4332
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004333 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFSTOPPED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004334 &status))
4335 goto exit;
4336 _return_value = os_WIFSTOPPED_impl(module, status);
4337 if ((_return_value == -1) && PyErr_Occurred())
4338 goto exit;
4339 return_value = PyBool_FromLong((long)_return_value);
4340
4341exit:
4342 return return_value;
4343}
4344
4345#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4346
4347#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4348
4349PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4350"WIFSIGNALED($module, /, status)\n"
4351"--\n"
4352"\n"
4353"Return True if the process returning status was terminated by a signal.");
4354
4355#define OS_WIFSIGNALED_METHODDEF \
4356 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_VARARGS|METH_KEYWORDS, os_WIFSIGNALED__doc__},
4357
4358static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004359os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004360
4361static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004362os_WIFSIGNALED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004363{
4364 PyObject *return_value = NULL;
4365 static char *_keywords[] = {"status", NULL};
4366 int status;
4367 int _return_value;
4368
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004369 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFSIGNALED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370 &status))
4371 goto exit;
4372 _return_value = os_WIFSIGNALED_impl(module, status);
4373 if ((_return_value == -1) && PyErr_Occurred())
4374 goto exit;
4375 return_value = PyBool_FromLong((long)_return_value);
4376
4377exit:
4378 return return_value;
4379}
4380
4381#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4382
4383#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4384
4385PyDoc_STRVAR(os_WIFEXITED__doc__,
4386"WIFEXITED($module, /, status)\n"
4387"--\n"
4388"\n"
4389"Return True if the process returning status exited via the exit() system call.");
4390
4391#define OS_WIFEXITED_METHODDEF \
4392 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_VARARGS|METH_KEYWORDS, os_WIFEXITED__doc__},
4393
4394static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004395os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004396
4397static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004398os_WIFEXITED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004399{
4400 PyObject *return_value = NULL;
4401 static char *_keywords[] = {"status", NULL};
4402 int status;
4403 int _return_value;
4404
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004405 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFEXITED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004406 &status))
4407 goto exit;
4408 _return_value = os_WIFEXITED_impl(module, status);
4409 if ((_return_value == -1) && PyErr_Occurred())
4410 goto exit;
4411 return_value = PyBool_FromLong((long)_return_value);
4412
4413exit:
4414 return return_value;
4415}
4416
4417#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4418
4419#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4420
4421PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4422"WEXITSTATUS($module, /, status)\n"
4423"--\n"
4424"\n"
4425"Return the process return code from status.");
4426
4427#define OS_WEXITSTATUS_METHODDEF \
4428 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_VARARGS|METH_KEYWORDS, os_WEXITSTATUS__doc__},
4429
4430static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004431os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004432
4433static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004434os_WEXITSTATUS(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004435{
4436 PyObject *return_value = NULL;
4437 static char *_keywords[] = {"status", NULL};
4438 int status;
4439 int _return_value;
4440
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004441 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WEXITSTATUS", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004442 &status))
4443 goto exit;
4444 _return_value = os_WEXITSTATUS_impl(module, status);
4445 if ((_return_value == -1) && PyErr_Occurred())
4446 goto exit;
4447 return_value = PyLong_FromLong((long)_return_value);
4448
4449exit:
4450 return return_value;
4451}
4452
4453#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4454
4455#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4456
4457PyDoc_STRVAR(os_WTERMSIG__doc__,
4458"WTERMSIG($module, /, status)\n"
4459"--\n"
4460"\n"
4461"Return the signal that terminated the process that provided the status value.");
4462
4463#define OS_WTERMSIG_METHODDEF \
4464 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_VARARGS|METH_KEYWORDS, os_WTERMSIG__doc__},
4465
4466static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004467os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004468
4469static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004470os_WTERMSIG(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004471{
4472 PyObject *return_value = NULL;
4473 static char *_keywords[] = {"status", NULL};
4474 int status;
4475 int _return_value;
4476
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004477 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WTERMSIG", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004478 &status))
4479 goto exit;
4480 _return_value = os_WTERMSIG_impl(module, status);
4481 if ((_return_value == -1) && PyErr_Occurred())
4482 goto exit;
4483 return_value = PyLong_FromLong((long)_return_value);
4484
4485exit:
4486 return return_value;
4487}
4488
4489#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4490
4491#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4492
4493PyDoc_STRVAR(os_WSTOPSIG__doc__,
4494"WSTOPSIG($module, /, status)\n"
4495"--\n"
4496"\n"
4497"Return the signal that stopped the process that provided the status value.");
4498
4499#define OS_WSTOPSIG_METHODDEF \
4500 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_VARARGS|METH_KEYWORDS, os_WSTOPSIG__doc__},
4501
4502static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004503os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004504
4505static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004506os_WSTOPSIG(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004507{
4508 PyObject *return_value = NULL;
4509 static char *_keywords[] = {"status", NULL};
4510 int status;
4511 int _return_value;
4512
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004513 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WSTOPSIG", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004514 &status))
4515 goto exit;
4516 _return_value = os_WSTOPSIG_impl(module, status);
4517 if ((_return_value == -1) && PyErr_Occurred())
4518 goto exit;
4519 return_value = PyLong_FromLong((long)_return_value);
4520
4521exit:
4522 return return_value;
4523}
4524
4525#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4526
4527#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4528
4529PyDoc_STRVAR(os_fstatvfs__doc__,
4530"fstatvfs($module, fd, /)\n"
4531"--\n"
4532"\n"
4533"Perform an fstatvfs system call on the given fd.\n"
4534"\n"
4535"Equivalent to statvfs(fd).");
4536
4537#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004538 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004539
4540static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004541os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004542
4543static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004544os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004545{
4546 PyObject *return_value = NULL;
4547 int fd;
4548
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004549 if (!PyArg_Parse(arg, "i:fstatvfs", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004550 goto exit;
4551 return_value = os_fstatvfs_impl(module, fd);
4552
4553exit:
4554 return return_value;
4555}
4556
4557#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4558
4559#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4560
4561PyDoc_STRVAR(os_statvfs__doc__,
4562"statvfs($module, /, path)\n"
4563"--\n"
4564"\n"
4565"Perform a statvfs system call on the given path.\n"
4566"\n"
4567"path may always be specified as a string.\n"
4568"On some platforms, path may also be specified as an open file descriptor.\n"
4569" If this functionality is unavailable, using it raises an exception.");
4570
4571#define OS_STATVFS_METHODDEF \
4572 {"statvfs", (PyCFunction)os_statvfs, METH_VARARGS|METH_KEYWORDS, os_statvfs__doc__},
4573
4574static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004575os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004576
4577static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004578os_statvfs(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004579{
4580 PyObject *return_value = NULL;
4581 static char *_keywords[] = {"path", NULL};
4582 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4583
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004584 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:statvfs", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004585 path_converter, &path))
4586 goto exit;
4587 return_value = os_statvfs_impl(module, &path);
4588
4589exit:
4590 /* Cleanup for path */
4591 path_cleanup(&path);
4592
4593 return return_value;
4594}
4595
4596#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4597
4598#if defined(MS_WINDOWS)
4599
4600PyDoc_STRVAR(os__getdiskusage__doc__,
4601"_getdiskusage($module, /, path)\n"
4602"--\n"
4603"\n"
4604"Return disk usage statistics about the given path as a (total, free) tuple.");
4605
4606#define OS__GETDISKUSAGE_METHODDEF \
4607 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_VARARGS|METH_KEYWORDS, os__getdiskusage__doc__},
4608
4609static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004610os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004611
4612static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004613os__getdiskusage(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004614{
4615 PyObject *return_value = NULL;
4616 static char *_keywords[] = {"path", NULL};
4617 Py_UNICODE *path;
4618
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004619 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "u:_getdiskusage", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004620 &path))
4621 goto exit;
4622 return_value = os__getdiskusage_impl(module, path);
4623
4624exit:
4625 return return_value;
4626}
4627
4628#endif /* defined(MS_WINDOWS) */
4629
4630#if defined(HAVE_FPATHCONF)
4631
4632PyDoc_STRVAR(os_fpathconf__doc__,
4633"fpathconf($module, fd, name, /)\n"
4634"--\n"
4635"\n"
4636"Return the configuration limit name for the file descriptor fd.\n"
4637"\n"
4638"If there is no limit, return -1.");
4639
4640#define OS_FPATHCONF_METHODDEF \
4641 {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
4642
4643static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004644os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004645
4646static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004647os_fpathconf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004648{
4649 PyObject *return_value = NULL;
4650 int fd;
4651 int name;
4652 long _return_value;
4653
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004654 if (!PyArg_ParseTuple(args, "iO&:fpathconf",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004655 &fd, conv_path_confname, &name))
4656 goto exit;
4657 _return_value = os_fpathconf_impl(module, fd, name);
4658 if ((_return_value == -1) && PyErr_Occurred())
4659 goto exit;
4660 return_value = PyLong_FromLong(_return_value);
4661
4662exit:
4663 return return_value;
4664}
4665
4666#endif /* defined(HAVE_FPATHCONF) */
4667
4668#if defined(HAVE_PATHCONF)
4669
4670PyDoc_STRVAR(os_pathconf__doc__,
4671"pathconf($module, /, path, name)\n"
4672"--\n"
4673"\n"
4674"Return the configuration limit name for the file or directory path.\n"
4675"\n"
4676"If there is no limit, return -1.\n"
4677"On some platforms, path may also be specified as an open file descriptor.\n"
4678" If this functionality is unavailable, using it raises an exception.");
4679
4680#define OS_PATHCONF_METHODDEF \
4681 {"pathconf", (PyCFunction)os_pathconf, METH_VARARGS|METH_KEYWORDS, os_pathconf__doc__},
4682
4683static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004684os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004685
4686static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004687os_pathconf(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004688{
4689 PyObject *return_value = NULL;
4690 static char *_keywords[] = {"path", "name", NULL};
4691 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4692 int name;
4693 long _return_value;
4694
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004695 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:pathconf", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004696 path_converter, &path, conv_path_confname, &name))
4697 goto exit;
4698 _return_value = os_pathconf_impl(module, &path, name);
4699 if ((_return_value == -1) && PyErr_Occurred())
4700 goto exit;
4701 return_value = PyLong_FromLong(_return_value);
4702
4703exit:
4704 /* Cleanup for path */
4705 path_cleanup(&path);
4706
4707 return return_value;
4708}
4709
4710#endif /* defined(HAVE_PATHCONF) */
4711
4712#if defined(HAVE_CONFSTR)
4713
4714PyDoc_STRVAR(os_confstr__doc__,
4715"confstr($module, name, /)\n"
4716"--\n"
4717"\n"
4718"Return a string-valued system configuration variable.");
4719
4720#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004721 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004722
4723static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004724os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004725
4726static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004727os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004728{
4729 PyObject *return_value = NULL;
4730 int name;
4731
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004732 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004733 goto exit;
4734 return_value = os_confstr_impl(module, name);
4735
4736exit:
4737 return return_value;
4738}
4739
4740#endif /* defined(HAVE_CONFSTR) */
4741
4742#if defined(HAVE_SYSCONF)
4743
4744PyDoc_STRVAR(os_sysconf__doc__,
4745"sysconf($module, name, /)\n"
4746"--\n"
4747"\n"
4748"Return an integer-valued system configuration variable.");
4749
4750#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004751 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752
4753static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004754os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004755
4756static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004757os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004758{
4759 PyObject *return_value = NULL;
4760 int name;
4761 long _return_value;
4762
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004763 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004764 goto exit;
4765 _return_value = os_sysconf_impl(module, name);
4766 if ((_return_value == -1) && PyErr_Occurred())
4767 goto exit;
4768 return_value = PyLong_FromLong(_return_value);
4769
4770exit:
4771 return return_value;
4772}
4773
4774#endif /* defined(HAVE_SYSCONF) */
4775
4776PyDoc_STRVAR(os_abort__doc__,
4777"abort($module, /)\n"
4778"--\n"
4779"\n"
4780"Abort the interpreter immediately.\n"
4781"\n"
4782"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
4783"on the hosting operating system. This function never returns.");
4784
4785#define OS_ABORT_METHODDEF \
4786 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
4787
4788static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004789os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004790
4791static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004792os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004793{
4794 return os_abort_impl(module);
4795}
4796
4797#if defined(HAVE_GETLOADAVG)
4798
4799PyDoc_STRVAR(os_getloadavg__doc__,
4800"getloadavg($module, /)\n"
4801"--\n"
4802"\n"
4803"Return average recent system load information.\n"
4804"\n"
4805"Return the number of processes in the system run queue averaged over\n"
4806"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
4807"Raises OSError if the load average was unobtainable.");
4808
4809#define OS_GETLOADAVG_METHODDEF \
4810 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
4811
4812static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004813os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004814
4815static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004816os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004817{
4818 return os_getloadavg_impl(module);
4819}
4820
4821#endif /* defined(HAVE_GETLOADAVG) */
4822
4823PyDoc_STRVAR(os_device_encoding__doc__,
4824"device_encoding($module, /, fd)\n"
4825"--\n"
4826"\n"
4827"Return a string describing the encoding of a terminal\'s file descriptor.\n"
4828"\n"
4829"The file descriptor must be attached to a terminal.\n"
4830"If the device is not a terminal, return None.");
4831
4832#define OS_DEVICE_ENCODING_METHODDEF \
4833 {"device_encoding", (PyCFunction)os_device_encoding, METH_VARARGS|METH_KEYWORDS, os_device_encoding__doc__},
4834
4835static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004836os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004837
4838static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004839os_device_encoding(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840{
4841 PyObject *return_value = NULL;
4842 static char *_keywords[] = {"fd", NULL};
4843 int fd;
4844
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004845 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:device_encoding", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004846 &fd))
4847 goto exit;
4848 return_value = os_device_encoding_impl(module, fd);
4849
4850exit:
4851 return return_value;
4852}
4853
4854#if defined(HAVE_SETRESUID)
4855
4856PyDoc_STRVAR(os_setresuid__doc__,
4857"setresuid($module, ruid, euid, suid, /)\n"
4858"--\n"
4859"\n"
4860"Set the current process\'s real, effective, and saved user ids.");
4861
4862#define OS_SETRESUID_METHODDEF \
4863 {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
4864
4865static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004866os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004867
4868static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004869os_setresuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004870{
4871 PyObject *return_value = NULL;
4872 uid_t ruid;
4873 uid_t euid;
4874 uid_t suid;
4875
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004876 if (!PyArg_ParseTuple(args, "O&O&O&:setresuid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004877 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid))
4878 goto exit;
4879 return_value = os_setresuid_impl(module, ruid, euid, suid);
4880
4881exit:
4882 return return_value;
4883}
4884
4885#endif /* defined(HAVE_SETRESUID) */
4886
4887#if defined(HAVE_SETRESGID)
4888
4889PyDoc_STRVAR(os_setresgid__doc__,
4890"setresgid($module, rgid, egid, sgid, /)\n"
4891"--\n"
4892"\n"
4893"Set the current process\'s real, effective, and saved group ids.");
4894
4895#define OS_SETRESGID_METHODDEF \
4896 {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
4897
4898static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004899os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004900
4901static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004902os_setresgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004903{
4904 PyObject *return_value = NULL;
4905 gid_t rgid;
4906 gid_t egid;
4907 gid_t sgid;
4908
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004909 if (!PyArg_ParseTuple(args, "O&O&O&:setresgid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004910 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid))
4911 goto exit;
4912 return_value = os_setresgid_impl(module, rgid, egid, sgid);
4913
4914exit:
4915 return return_value;
4916}
4917
4918#endif /* defined(HAVE_SETRESGID) */
4919
4920#if defined(HAVE_GETRESUID)
4921
4922PyDoc_STRVAR(os_getresuid__doc__,
4923"getresuid($module, /)\n"
4924"--\n"
4925"\n"
4926"Return a tuple of the current process\'s real, effective, and saved user ids.");
4927
4928#define OS_GETRESUID_METHODDEF \
4929 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
4930
4931static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004932os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004933
4934static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004935os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004936{
4937 return os_getresuid_impl(module);
4938}
4939
4940#endif /* defined(HAVE_GETRESUID) */
4941
4942#if defined(HAVE_GETRESGID)
4943
4944PyDoc_STRVAR(os_getresgid__doc__,
4945"getresgid($module, /)\n"
4946"--\n"
4947"\n"
4948"Return a tuple of the current process\'s real, effective, and saved group ids.");
4949
4950#define OS_GETRESGID_METHODDEF \
4951 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
4952
4953static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004954os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004955
4956static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004957os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004958{
4959 return os_getresgid_impl(module);
4960}
4961
4962#endif /* defined(HAVE_GETRESGID) */
4963
4964#if defined(USE_XATTRS)
4965
4966PyDoc_STRVAR(os_getxattr__doc__,
4967"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
4968"--\n"
4969"\n"
4970"Return the value of extended attribute attribute on path.\n"
4971"\n"
4972"path may be either a string or an open file descriptor.\n"
4973"If follow_symlinks is False, and the last element of the path is a symbolic\n"
4974" link, getxattr will examine the symbolic link itself instead of the file\n"
4975" the link points to.");
4976
4977#define OS_GETXATTR_METHODDEF \
4978 {"getxattr", (PyCFunction)os_getxattr, METH_VARARGS|METH_KEYWORDS, os_getxattr__doc__},
4979
4980static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004981os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04004982 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004983
4984static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004985os_getxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004986{
4987 PyObject *return_value = NULL;
4988 static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
4989 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
4990 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
4991 int follow_symlinks = 1;
4992
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004993 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:getxattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004994 path_converter, &path, path_converter, &attribute, &follow_symlinks))
4995 goto exit;
4996 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
4997
4998exit:
4999 /* Cleanup for path */
5000 path_cleanup(&path);
5001 /* Cleanup for attribute */
5002 path_cleanup(&attribute);
5003
5004 return return_value;
5005}
5006
5007#endif /* defined(USE_XATTRS) */
5008
5009#if defined(USE_XATTRS)
5010
5011PyDoc_STRVAR(os_setxattr__doc__,
5012"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5013" follow_symlinks=True)\n"
5014"--\n"
5015"\n"
5016"Set extended attribute attribute on path to value.\n"
5017"\n"
5018"path may be either a string or an open file descriptor.\n"
5019"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5020" link, setxattr will modify the symbolic link itself instead of the file\n"
5021" the link points to.");
5022
5023#define OS_SETXATTR_METHODDEF \
5024 {"setxattr", (PyCFunction)os_setxattr, METH_VARARGS|METH_KEYWORDS, os_setxattr__doc__},
5025
5026static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005027os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005028 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005029
5030static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005031os_setxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005032{
5033 PyObject *return_value = NULL;
5034 static char *_keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5035 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5036 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5037 Py_buffer value = {NULL, NULL};
5038 int flags = 0;
5039 int follow_symlinks = 1;
5040
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005041 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&y*|i$p:setxattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005042 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks))
5043 goto exit;
5044 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5045
5046exit:
5047 /* Cleanup for path */
5048 path_cleanup(&path);
5049 /* Cleanup for attribute */
5050 path_cleanup(&attribute);
5051 /* Cleanup for value */
5052 if (value.obj)
5053 PyBuffer_Release(&value);
5054
5055 return return_value;
5056}
5057
5058#endif /* defined(USE_XATTRS) */
5059
5060#if defined(USE_XATTRS)
5061
5062PyDoc_STRVAR(os_removexattr__doc__,
5063"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5064"--\n"
5065"\n"
5066"Remove extended attribute attribute on path.\n"
5067"\n"
5068"path may be either a string or an open file descriptor.\n"
5069"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5070" link, removexattr will modify the symbolic link itself instead of the file\n"
5071" the link points to.");
5072
5073#define OS_REMOVEXATTR_METHODDEF \
5074 {"removexattr", (PyCFunction)os_removexattr, METH_VARARGS|METH_KEYWORDS, os_removexattr__doc__},
5075
5076static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005077os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005078 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005079
5080static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005081os_removexattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005082{
5083 PyObject *return_value = NULL;
5084 static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5085 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5086 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5087 int follow_symlinks = 1;
5088
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005089 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:removexattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005090 path_converter, &path, path_converter, &attribute, &follow_symlinks))
5091 goto exit;
5092 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5093
5094exit:
5095 /* Cleanup for path */
5096 path_cleanup(&path);
5097 /* Cleanup for attribute */
5098 path_cleanup(&attribute);
5099
5100 return return_value;
5101}
5102
5103#endif /* defined(USE_XATTRS) */
5104
5105#if defined(USE_XATTRS)
5106
5107PyDoc_STRVAR(os_listxattr__doc__,
5108"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5109"--\n"
5110"\n"
5111"Return a list of extended attributes on path.\n"
5112"\n"
5113"path may be either None, a string, or an open file descriptor.\n"
5114"if path is None, listxattr will examine the current directory.\n"
5115"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5116" link, listxattr will examine the symbolic link itself instead of the file\n"
5117" the link points to.");
5118
5119#define OS_LISTXATTR_METHODDEF \
5120 {"listxattr", (PyCFunction)os_listxattr, METH_VARARGS|METH_KEYWORDS, os_listxattr__doc__},
5121
5122static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005123os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005124
5125static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005126os_listxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005127{
5128 PyObject *return_value = NULL;
5129 static char *_keywords[] = {"path", "follow_symlinks", NULL};
5130 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5131 int follow_symlinks = 1;
5132
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005133 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&$p:listxattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005134 path_converter, &path, &follow_symlinks))
5135 goto exit;
5136 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5137
5138exit:
5139 /* Cleanup for path */
5140 path_cleanup(&path);
5141
5142 return return_value;
5143}
5144
5145#endif /* defined(USE_XATTRS) */
5146
5147PyDoc_STRVAR(os_urandom__doc__,
5148"urandom($module, size, /)\n"
5149"--\n"
5150"\n"
5151"Return a bytes object containing random bytes suitable for cryptographic use.");
5152
5153#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005154 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005155
5156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005157os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005158
5159static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005160os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005161{
5162 PyObject *return_value = NULL;
5163 Py_ssize_t size;
5164
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005165 if (!PyArg_Parse(arg, "n:urandom", &size))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005166 goto exit;
5167 return_value = os_urandom_impl(module, size);
5168
5169exit:
5170 return return_value;
5171}
5172
5173PyDoc_STRVAR(os_cpu_count__doc__,
5174"cpu_count($module, /)\n"
5175"--\n"
5176"\n"
5177"Return the number of CPUs in the system; return None if indeterminable.");
5178
5179#define OS_CPU_COUNT_METHODDEF \
5180 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5181
5182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005183os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005184
5185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005186os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005187{
5188 return os_cpu_count_impl(module);
5189}
5190
5191PyDoc_STRVAR(os_get_inheritable__doc__,
5192"get_inheritable($module, fd, /)\n"
5193"--\n"
5194"\n"
5195"Get the close-on-exe flag of the specified file descriptor.");
5196
5197#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005198 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005199
5200static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005201os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005202
5203static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005204os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005205{
5206 PyObject *return_value = NULL;
5207 int fd;
5208 int _return_value;
5209
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005210 if (!PyArg_Parse(arg, "i:get_inheritable", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005211 goto exit;
5212 _return_value = os_get_inheritable_impl(module, fd);
5213 if ((_return_value == -1) && PyErr_Occurred())
5214 goto exit;
5215 return_value = PyBool_FromLong((long)_return_value);
5216
5217exit:
5218 return return_value;
5219}
5220
5221PyDoc_STRVAR(os_set_inheritable__doc__,
5222"set_inheritable($module, fd, inheritable, /)\n"
5223"--\n"
5224"\n"
5225"Set the inheritable flag of the specified file descriptor.");
5226
5227#define OS_SET_INHERITABLE_METHODDEF \
5228 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
5229
5230static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005231os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005232
5233static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005234os_set_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005235{
5236 PyObject *return_value = NULL;
5237 int fd;
5238 int inheritable;
5239
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005240 if (!PyArg_ParseTuple(args, "ii:set_inheritable",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005241 &fd, &inheritable))
5242 goto exit;
5243 return_value = os_set_inheritable_impl(module, fd, inheritable);
5244
5245exit:
5246 return return_value;
5247}
5248
5249#if defined(MS_WINDOWS)
5250
5251PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5252"get_handle_inheritable($module, handle, /)\n"
5253"--\n"
5254"\n"
5255"Get the close-on-exe flag of the specified file descriptor.");
5256
5257#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005258 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005259
5260static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005261os_get_handle_inheritable_impl(PyObject *module, Py_intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005262
5263static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005264os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005265{
5266 PyObject *return_value = NULL;
5267 Py_intptr_t handle;
5268 int _return_value;
5269
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005270 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005271 goto exit;
5272 _return_value = os_get_handle_inheritable_impl(module, handle);
5273 if ((_return_value == -1) && PyErr_Occurred())
5274 goto exit;
5275 return_value = PyBool_FromLong((long)_return_value);
5276
5277exit:
5278 return return_value;
5279}
5280
5281#endif /* defined(MS_WINDOWS) */
5282
5283#if defined(MS_WINDOWS)
5284
5285PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5286"set_handle_inheritable($module, handle, inheritable, /)\n"
5287"--\n"
5288"\n"
5289"Set the inheritable flag of the specified handle.");
5290
5291#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
5292 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
5293
5294static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005295os_set_handle_inheritable_impl(PyObject *module, Py_intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005296 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005297
5298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005299os_set_handle_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005300{
5301 PyObject *return_value = NULL;
5302 Py_intptr_t handle;
5303 int inheritable;
5304
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005305 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005306 &handle, &inheritable))
5307 goto exit;
5308 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5309
5310exit:
5311 return return_value;
5312}
5313
5314#endif /* defined(MS_WINDOWS) */
5315
5316#ifndef OS_TTYNAME_METHODDEF
5317 #define OS_TTYNAME_METHODDEF
5318#endif /* !defined(OS_TTYNAME_METHODDEF) */
5319
5320#ifndef OS_CTERMID_METHODDEF
5321 #define OS_CTERMID_METHODDEF
5322#endif /* !defined(OS_CTERMID_METHODDEF) */
5323
5324#ifndef OS_FCHDIR_METHODDEF
5325 #define OS_FCHDIR_METHODDEF
5326#endif /* !defined(OS_FCHDIR_METHODDEF) */
5327
5328#ifndef OS_FCHMOD_METHODDEF
5329 #define OS_FCHMOD_METHODDEF
5330#endif /* !defined(OS_FCHMOD_METHODDEF) */
5331
5332#ifndef OS_LCHMOD_METHODDEF
5333 #define OS_LCHMOD_METHODDEF
5334#endif /* !defined(OS_LCHMOD_METHODDEF) */
5335
5336#ifndef OS_CHFLAGS_METHODDEF
5337 #define OS_CHFLAGS_METHODDEF
5338#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5339
5340#ifndef OS_LCHFLAGS_METHODDEF
5341 #define OS_LCHFLAGS_METHODDEF
5342#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5343
5344#ifndef OS_CHROOT_METHODDEF
5345 #define OS_CHROOT_METHODDEF
5346#endif /* !defined(OS_CHROOT_METHODDEF) */
5347
5348#ifndef OS_FSYNC_METHODDEF
5349 #define OS_FSYNC_METHODDEF
5350#endif /* !defined(OS_FSYNC_METHODDEF) */
5351
5352#ifndef OS_SYNC_METHODDEF
5353 #define OS_SYNC_METHODDEF
5354#endif /* !defined(OS_SYNC_METHODDEF) */
5355
5356#ifndef OS_FDATASYNC_METHODDEF
5357 #define OS_FDATASYNC_METHODDEF
5358#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5359
5360#ifndef OS_CHOWN_METHODDEF
5361 #define OS_CHOWN_METHODDEF
5362#endif /* !defined(OS_CHOWN_METHODDEF) */
5363
5364#ifndef OS_FCHOWN_METHODDEF
5365 #define OS_FCHOWN_METHODDEF
5366#endif /* !defined(OS_FCHOWN_METHODDEF) */
5367
5368#ifndef OS_LCHOWN_METHODDEF
5369 #define OS_LCHOWN_METHODDEF
5370#endif /* !defined(OS_LCHOWN_METHODDEF) */
5371
5372#ifndef OS_LINK_METHODDEF
5373 #define OS_LINK_METHODDEF
5374#endif /* !defined(OS_LINK_METHODDEF) */
5375
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005376#ifndef OS__GETFULLPATHNAME_METHODDEF
5377 #define OS__GETFULLPATHNAME_METHODDEF
5378#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5379
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005380#ifndef OS__GETFINALPATHNAME_METHODDEF
5381 #define OS__GETFINALPATHNAME_METHODDEF
5382#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5383
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005384#ifndef OS__ISDIR_METHODDEF
5385 #define OS__ISDIR_METHODDEF
5386#endif /* !defined(OS__ISDIR_METHODDEF) */
5387
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005388#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5389 #define OS__GETVOLUMEPATHNAME_METHODDEF
5390#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5391
5392#ifndef OS_NICE_METHODDEF
5393 #define OS_NICE_METHODDEF
5394#endif /* !defined(OS_NICE_METHODDEF) */
5395
5396#ifndef OS_GETPRIORITY_METHODDEF
5397 #define OS_GETPRIORITY_METHODDEF
5398#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
5399
5400#ifndef OS_SETPRIORITY_METHODDEF
5401 #define OS_SETPRIORITY_METHODDEF
5402#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
5403
5404#ifndef OS_SYSTEM_METHODDEF
5405 #define OS_SYSTEM_METHODDEF
5406#endif /* !defined(OS_SYSTEM_METHODDEF) */
5407
5408#ifndef OS_UNAME_METHODDEF
5409 #define OS_UNAME_METHODDEF
5410#endif /* !defined(OS_UNAME_METHODDEF) */
5411
5412#ifndef OS_EXECV_METHODDEF
5413 #define OS_EXECV_METHODDEF
5414#endif /* !defined(OS_EXECV_METHODDEF) */
5415
5416#ifndef OS_EXECVE_METHODDEF
5417 #define OS_EXECVE_METHODDEF
5418#endif /* !defined(OS_EXECVE_METHODDEF) */
5419
5420#ifndef OS_SPAWNV_METHODDEF
5421 #define OS_SPAWNV_METHODDEF
5422#endif /* !defined(OS_SPAWNV_METHODDEF) */
5423
5424#ifndef OS_SPAWNVE_METHODDEF
5425 #define OS_SPAWNVE_METHODDEF
5426#endif /* !defined(OS_SPAWNVE_METHODDEF) */
5427
5428#ifndef OS_FORK1_METHODDEF
5429 #define OS_FORK1_METHODDEF
5430#endif /* !defined(OS_FORK1_METHODDEF) */
5431
5432#ifndef OS_FORK_METHODDEF
5433 #define OS_FORK_METHODDEF
5434#endif /* !defined(OS_FORK_METHODDEF) */
5435
5436#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5437 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5438#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
5439
5440#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5441 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5442#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
5443
5444#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
5445 #define OS_SCHED_GETSCHEDULER_METHODDEF
5446#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
5447
5448#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
5449 #define OS_SCHED_SETSCHEDULER_METHODDEF
5450#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
5451
5452#ifndef OS_SCHED_GETPARAM_METHODDEF
5453 #define OS_SCHED_GETPARAM_METHODDEF
5454#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
5455
5456#ifndef OS_SCHED_SETPARAM_METHODDEF
5457 #define OS_SCHED_SETPARAM_METHODDEF
5458#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
5459
5460#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
5461 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
5462#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
5463
5464#ifndef OS_SCHED_YIELD_METHODDEF
5465 #define OS_SCHED_YIELD_METHODDEF
5466#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
5467
5468#ifndef OS_SCHED_SETAFFINITY_METHODDEF
5469 #define OS_SCHED_SETAFFINITY_METHODDEF
5470#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
5471
5472#ifndef OS_SCHED_GETAFFINITY_METHODDEF
5473 #define OS_SCHED_GETAFFINITY_METHODDEF
5474#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
5475
5476#ifndef OS_OPENPTY_METHODDEF
5477 #define OS_OPENPTY_METHODDEF
5478#endif /* !defined(OS_OPENPTY_METHODDEF) */
5479
5480#ifndef OS_FORKPTY_METHODDEF
5481 #define OS_FORKPTY_METHODDEF
5482#endif /* !defined(OS_FORKPTY_METHODDEF) */
5483
5484#ifndef OS_GETEGID_METHODDEF
5485 #define OS_GETEGID_METHODDEF
5486#endif /* !defined(OS_GETEGID_METHODDEF) */
5487
5488#ifndef OS_GETEUID_METHODDEF
5489 #define OS_GETEUID_METHODDEF
5490#endif /* !defined(OS_GETEUID_METHODDEF) */
5491
5492#ifndef OS_GETGID_METHODDEF
5493 #define OS_GETGID_METHODDEF
5494#endif /* !defined(OS_GETGID_METHODDEF) */
5495
5496#ifndef OS_GETGROUPS_METHODDEF
5497 #define OS_GETGROUPS_METHODDEF
5498#endif /* !defined(OS_GETGROUPS_METHODDEF) */
5499
5500#ifndef OS_GETPGID_METHODDEF
5501 #define OS_GETPGID_METHODDEF
5502#endif /* !defined(OS_GETPGID_METHODDEF) */
5503
5504#ifndef OS_GETPGRP_METHODDEF
5505 #define OS_GETPGRP_METHODDEF
5506#endif /* !defined(OS_GETPGRP_METHODDEF) */
5507
5508#ifndef OS_SETPGRP_METHODDEF
5509 #define OS_SETPGRP_METHODDEF
5510#endif /* !defined(OS_SETPGRP_METHODDEF) */
5511
5512#ifndef OS_GETPPID_METHODDEF
5513 #define OS_GETPPID_METHODDEF
5514#endif /* !defined(OS_GETPPID_METHODDEF) */
5515
5516#ifndef OS_GETLOGIN_METHODDEF
5517 #define OS_GETLOGIN_METHODDEF
5518#endif /* !defined(OS_GETLOGIN_METHODDEF) */
5519
5520#ifndef OS_GETUID_METHODDEF
5521 #define OS_GETUID_METHODDEF
5522#endif /* !defined(OS_GETUID_METHODDEF) */
5523
5524#ifndef OS_KILL_METHODDEF
5525 #define OS_KILL_METHODDEF
5526#endif /* !defined(OS_KILL_METHODDEF) */
5527
5528#ifndef OS_KILLPG_METHODDEF
5529 #define OS_KILLPG_METHODDEF
5530#endif /* !defined(OS_KILLPG_METHODDEF) */
5531
5532#ifndef OS_PLOCK_METHODDEF
5533 #define OS_PLOCK_METHODDEF
5534#endif /* !defined(OS_PLOCK_METHODDEF) */
5535
5536#ifndef OS_SETUID_METHODDEF
5537 #define OS_SETUID_METHODDEF
5538#endif /* !defined(OS_SETUID_METHODDEF) */
5539
5540#ifndef OS_SETEUID_METHODDEF
5541 #define OS_SETEUID_METHODDEF
5542#endif /* !defined(OS_SETEUID_METHODDEF) */
5543
5544#ifndef OS_SETEGID_METHODDEF
5545 #define OS_SETEGID_METHODDEF
5546#endif /* !defined(OS_SETEGID_METHODDEF) */
5547
5548#ifndef OS_SETREUID_METHODDEF
5549 #define OS_SETREUID_METHODDEF
5550#endif /* !defined(OS_SETREUID_METHODDEF) */
5551
5552#ifndef OS_SETREGID_METHODDEF
5553 #define OS_SETREGID_METHODDEF
5554#endif /* !defined(OS_SETREGID_METHODDEF) */
5555
5556#ifndef OS_SETGID_METHODDEF
5557 #define OS_SETGID_METHODDEF
5558#endif /* !defined(OS_SETGID_METHODDEF) */
5559
5560#ifndef OS_SETGROUPS_METHODDEF
5561 #define OS_SETGROUPS_METHODDEF
5562#endif /* !defined(OS_SETGROUPS_METHODDEF) */
5563
5564#ifndef OS_WAIT3_METHODDEF
5565 #define OS_WAIT3_METHODDEF
5566#endif /* !defined(OS_WAIT3_METHODDEF) */
5567
5568#ifndef OS_WAIT4_METHODDEF
5569 #define OS_WAIT4_METHODDEF
5570#endif /* !defined(OS_WAIT4_METHODDEF) */
5571
5572#ifndef OS_WAITID_METHODDEF
5573 #define OS_WAITID_METHODDEF
5574#endif /* !defined(OS_WAITID_METHODDEF) */
5575
5576#ifndef OS_WAITPID_METHODDEF
5577 #define OS_WAITPID_METHODDEF
5578#endif /* !defined(OS_WAITPID_METHODDEF) */
5579
5580#ifndef OS_WAIT_METHODDEF
5581 #define OS_WAIT_METHODDEF
5582#endif /* !defined(OS_WAIT_METHODDEF) */
5583
5584#ifndef OS_SYMLINK_METHODDEF
5585 #define OS_SYMLINK_METHODDEF
5586#endif /* !defined(OS_SYMLINK_METHODDEF) */
5587
5588#ifndef OS_TIMES_METHODDEF
5589 #define OS_TIMES_METHODDEF
5590#endif /* !defined(OS_TIMES_METHODDEF) */
5591
5592#ifndef OS_GETSID_METHODDEF
5593 #define OS_GETSID_METHODDEF
5594#endif /* !defined(OS_GETSID_METHODDEF) */
5595
5596#ifndef OS_SETSID_METHODDEF
5597 #define OS_SETSID_METHODDEF
5598#endif /* !defined(OS_SETSID_METHODDEF) */
5599
5600#ifndef OS_SETPGID_METHODDEF
5601 #define OS_SETPGID_METHODDEF
5602#endif /* !defined(OS_SETPGID_METHODDEF) */
5603
5604#ifndef OS_TCGETPGRP_METHODDEF
5605 #define OS_TCGETPGRP_METHODDEF
5606#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
5607
5608#ifndef OS_TCSETPGRP_METHODDEF
5609 #define OS_TCSETPGRP_METHODDEF
5610#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
5611
5612#ifndef OS_LOCKF_METHODDEF
5613 #define OS_LOCKF_METHODDEF
5614#endif /* !defined(OS_LOCKF_METHODDEF) */
5615
5616#ifndef OS_READV_METHODDEF
5617 #define OS_READV_METHODDEF
5618#endif /* !defined(OS_READV_METHODDEF) */
5619
5620#ifndef OS_PREAD_METHODDEF
5621 #define OS_PREAD_METHODDEF
5622#endif /* !defined(OS_PREAD_METHODDEF) */
5623
5624#ifndef OS_PIPE_METHODDEF
5625 #define OS_PIPE_METHODDEF
5626#endif /* !defined(OS_PIPE_METHODDEF) */
5627
5628#ifndef OS_PIPE2_METHODDEF
5629 #define OS_PIPE2_METHODDEF
5630#endif /* !defined(OS_PIPE2_METHODDEF) */
5631
5632#ifndef OS_WRITEV_METHODDEF
5633 #define OS_WRITEV_METHODDEF
5634#endif /* !defined(OS_WRITEV_METHODDEF) */
5635
5636#ifndef OS_PWRITE_METHODDEF
5637 #define OS_PWRITE_METHODDEF
5638#endif /* !defined(OS_PWRITE_METHODDEF) */
5639
5640#ifndef OS_MKFIFO_METHODDEF
5641 #define OS_MKFIFO_METHODDEF
5642#endif /* !defined(OS_MKFIFO_METHODDEF) */
5643
5644#ifndef OS_MKNOD_METHODDEF
5645 #define OS_MKNOD_METHODDEF
5646#endif /* !defined(OS_MKNOD_METHODDEF) */
5647
5648#ifndef OS_MAJOR_METHODDEF
5649 #define OS_MAJOR_METHODDEF
5650#endif /* !defined(OS_MAJOR_METHODDEF) */
5651
5652#ifndef OS_MINOR_METHODDEF
5653 #define OS_MINOR_METHODDEF
5654#endif /* !defined(OS_MINOR_METHODDEF) */
5655
5656#ifndef OS_MAKEDEV_METHODDEF
5657 #define OS_MAKEDEV_METHODDEF
5658#endif /* !defined(OS_MAKEDEV_METHODDEF) */
5659
5660#ifndef OS_FTRUNCATE_METHODDEF
5661 #define OS_FTRUNCATE_METHODDEF
5662#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
5663
5664#ifndef OS_TRUNCATE_METHODDEF
5665 #define OS_TRUNCATE_METHODDEF
5666#endif /* !defined(OS_TRUNCATE_METHODDEF) */
5667
5668#ifndef OS_POSIX_FALLOCATE_METHODDEF
5669 #define OS_POSIX_FALLOCATE_METHODDEF
5670#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
5671
5672#ifndef OS_POSIX_FADVISE_METHODDEF
5673 #define OS_POSIX_FADVISE_METHODDEF
5674#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
5675
5676#ifndef OS_PUTENV_METHODDEF
5677 #define OS_PUTENV_METHODDEF
5678#endif /* !defined(OS_PUTENV_METHODDEF) */
5679
5680#ifndef OS_UNSETENV_METHODDEF
5681 #define OS_UNSETENV_METHODDEF
5682#endif /* !defined(OS_UNSETENV_METHODDEF) */
5683
5684#ifndef OS_WCOREDUMP_METHODDEF
5685 #define OS_WCOREDUMP_METHODDEF
5686#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
5687
5688#ifndef OS_WIFCONTINUED_METHODDEF
5689 #define OS_WIFCONTINUED_METHODDEF
5690#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
5691
5692#ifndef OS_WIFSTOPPED_METHODDEF
5693 #define OS_WIFSTOPPED_METHODDEF
5694#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
5695
5696#ifndef OS_WIFSIGNALED_METHODDEF
5697 #define OS_WIFSIGNALED_METHODDEF
5698#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
5699
5700#ifndef OS_WIFEXITED_METHODDEF
5701 #define OS_WIFEXITED_METHODDEF
5702#endif /* !defined(OS_WIFEXITED_METHODDEF) */
5703
5704#ifndef OS_WEXITSTATUS_METHODDEF
5705 #define OS_WEXITSTATUS_METHODDEF
5706#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
5707
5708#ifndef OS_WTERMSIG_METHODDEF
5709 #define OS_WTERMSIG_METHODDEF
5710#endif /* !defined(OS_WTERMSIG_METHODDEF) */
5711
5712#ifndef OS_WSTOPSIG_METHODDEF
5713 #define OS_WSTOPSIG_METHODDEF
5714#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
5715
5716#ifndef OS_FSTATVFS_METHODDEF
5717 #define OS_FSTATVFS_METHODDEF
5718#endif /* !defined(OS_FSTATVFS_METHODDEF) */
5719
5720#ifndef OS_STATVFS_METHODDEF
5721 #define OS_STATVFS_METHODDEF
5722#endif /* !defined(OS_STATVFS_METHODDEF) */
5723
5724#ifndef OS__GETDISKUSAGE_METHODDEF
5725 #define OS__GETDISKUSAGE_METHODDEF
5726#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
5727
5728#ifndef OS_FPATHCONF_METHODDEF
5729 #define OS_FPATHCONF_METHODDEF
5730#endif /* !defined(OS_FPATHCONF_METHODDEF) */
5731
5732#ifndef OS_PATHCONF_METHODDEF
5733 #define OS_PATHCONF_METHODDEF
5734#endif /* !defined(OS_PATHCONF_METHODDEF) */
5735
5736#ifndef OS_CONFSTR_METHODDEF
5737 #define OS_CONFSTR_METHODDEF
5738#endif /* !defined(OS_CONFSTR_METHODDEF) */
5739
5740#ifndef OS_SYSCONF_METHODDEF
5741 #define OS_SYSCONF_METHODDEF
5742#endif /* !defined(OS_SYSCONF_METHODDEF) */
5743
5744#ifndef OS_GETLOADAVG_METHODDEF
5745 #define OS_GETLOADAVG_METHODDEF
5746#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
5747
5748#ifndef OS_SETRESUID_METHODDEF
5749 #define OS_SETRESUID_METHODDEF
5750#endif /* !defined(OS_SETRESUID_METHODDEF) */
5751
5752#ifndef OS_SETRESGID_METHODDEF
5753 #define OS_SETRESGID_METHODDEF
5754#endif /* !defined(OS_SETRESGID_METHODDEF) */
5755
5756#ifndef OS_GETRESUID_METHODDEF
5757 #define OS_GETRESUID_METHODDEF
5758#endif /* !defined(OS_GETRESUID_METHODDEF) */
5759
5760#ifndef OS_GETRESGID_METHODDEF
5761 #define OS_GETRESGID_METHODDEF
5762#endif /* !defined(OS_GETRESGID_METHODDEF) */
5763
5764#ifndef OS_GETXATTR_METHODDEF
5765 #define OS_GETXATTR_METHODDEF
5766#endif /* !defined(OS_GETXATTR_METHODDEF) */
5767
5768#ifndef OS_SETXATTR_METHODDEF
5769 #define OS_SETXATTR_METHODDEF
5770#endif /* !defined(OS_SETXATTR_METHODDEF) */
5771
5772#ifndef OS_REMOVEXATTR_METHODDEF
5773 #define OS_REMOVEXATTR_METHODDEF
5774#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
5775
5776#ifndef OS_LISTXATTR_METHODDEF
5777 #define OS_LISTXATTR_METHODDEF
5778#endif /* !defined(OS_LISTXATTR_METHODDEF) */
5779
5780#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
5781 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
5782#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
5783
5784#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
5785 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
5786#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Benjamin Peterson768f3b42016-09-05 15:29:33 -07005787/*[clinic end generated code: output=9d5f831b23145d1e input=a9049054013a1b77]*/