blob: b3521d81c6aae2765ccacec258d351d881ab8311 [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"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200957"\n"
958"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300959
960#define OS__ISDIR_METHODDEF \
961 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
962
963static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300964os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300965
966static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300967os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300968{
969 PyObject *return_value = NULL;
970 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
971
972 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path))
973 goto exit;
974 return_value = os__isdir_impl(module, &path);
975
976exit:
977 /* Cleanup for path */
978 path_cleanup(&path);
979
980 return return_value;
981}
982
983#endif /* defined(MS_WINDOWS) */
984
985#if defined(MS_WINDOWS)
986
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300987PyDoc_STRVAR(os__getvolumepathname__doc__,
988"_getvolumepathname($module, /, path)\n"
989"--\n"
990"\n"
991"A helper function for ismount on Win32.");
992
993#define OS__GETVOLUMEPATHNAME_METHODDEF \
994 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_VARARGS|METH_KEYWORDS, os__getvolumepathname__doc__},
995
996static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300997os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300998
999static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001000os__getvolumepathname(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001001{
1002 PyObject *return_value = NULL;
1003 static char *_keywords[] = {"path", NULL};
1004 PyObject *path;
1005
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001006 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U:_getvolumepathname", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001007 &path))
1008 goto exit;
1009 return_value = os__getvolumepathname_impl(module, path);
1010
1011exit:
1012 return return_value;
1013}
1014
1015#endif /* defined(MS_WINDOWS) */
1016
1017PyDoc_STRVAR(os_mkdir__doc__,
1018"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1019"--\n"
1020"\n"
1021"Create a directory.\n"
1022"\n"
1023"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1024" and path should be relative; path will then be relative to that directory.\n"
1025"dir_fd may not be implemented on your platform.\n"
1026" If it is unavailable, using it will raise a NotImplementedError.\n"
1027"\n"
1028"The mode argument is ignored on Windows.");
1029
1030#define OS_MKDIR_METHODDEF \
1031 {"mkdir", (PyCFunction)os_mkdir, METH_VARARGS|METH_KEYWORDS, os_mkdir__doc__},
1032
1033static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001034os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001035
1036static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001037os_mkdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038{
1039 PyObject *return_value = NULL;
1040 static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
1041 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1042 int mode = 511;
1043 int dir_fd = DEFAULT_DIR_FD;
1044
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001045 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkdir", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001046 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd))
1047 goto exit;
1048 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1049
1050exit:
1051 /* Cleanup for path */
1052 path_cleanup(&path);
1053
1054 return return_value;
1055}
1056
1057#if defined(HAVE_NICE)
1058
1059PyDoc_STRVAR(os_nice__doc__,
1060"nice($module, increment, /)\n"
1061"--\n"
1062"\n"
1063"Add increment to the priority of process and return the new priority.");
1064
1065#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001066 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001067
1068static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001069os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001070
1071static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001072os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001073{
1074 PyObject *return_value = NULL;
1075 int increment;
1076
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001077 if (!PyArg_Parse(arg, "i:nice", &increment))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001078 goto exit;
1079 return_value = os_nice_impl(module, increment);
1080
1081exit:
1082 return return_value;
1083}
1084
1085#endif /* defined(HAVE_NICE) */
1086
1087#if defined(HAVE_GETPRIORITY)
1088
1089PyDoc_STRVAR(os_getpriority__doc__,
1090"getpriority($module, /, which, who)\n"
1091"--\n"
1092"\n"
1093"Return program scheduling priority.");
1094
1095#define OS_GETPRIORITY_METHODDEF \
1096 {"getpriority", (PyCFunction)os_getpriority, METH_VARARGS|METH_KEYWORDS, os_getpriority__doc__},
1097
1098static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001099os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001100
1101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001102os_getpriority(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001103{
1104 PyObject *return_value = NULL;
1105 static char *_keywords[] = {"which", "who", NULL};
1106 int which;
1107 int who;
1108
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001109 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:getpriority", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001110 &which, &who))
1111 goto exit;
1112 return_value = os_getpriority_impl(module, which, who);
1113
1114exit:
1115 return return_value;
1116}
1117
1118#endif /* defined(HAVE_GETPRIORITY) */
1119
1120#if defined(HAVE_SETPRIORITY)
1121
1122PyDoc_STRVAR(os_setpriority__doc__,
1123"setpriority($module, /, which, who, priority)\n"
1124"--\n"
1125"\n"
1126"Set program scheduling priority.");
1127
1128#define OS_SETPRIORITY_METHODDEF \
1129 {"setpriority", (PyCFunction)os_setpriority, METH_VARARGS|METH_KEYWORDS, os_setpriority__doc__},
1130
1131static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001132os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001133
1134static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001135os_setpriority(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001136{
1137 PyObject *return_value = NULL;
1138 static char *_keywords[] = {"which", "who", "priority", NULL};
1139 int which;
1140 int who;
1141 int priority;
1142
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001143 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii:setpriority", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001144 &which, &who, &priority))
1145 goto exit;
1146 return_value = os_setpriority_impl(module, which, who, priority);
1147
1148exit:
1149 return return_value;
1150}
1151
1152#endif /* defined(HAVE_SETPRIORITY) */
1153
1154PyDoc_STRVAR(os_rename__doc__,
1155"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1156"--\n"
1157"\n"
1158"Rename a file or directory.\n"
1159"\n"
1160"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1161" descriptor open to a directory, and the respective path string (src or dst)\n"
1162" should be relative; the path will then be relative to that directory.\n"
1163"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1164" If they are unavailable, using them will raise a NotImplementedError.");
1165
1166#define OS_RENAME_METHODDEF \
1167 {"rename", (PyCFunction)os_rename, METH_VARARGS|METH_KEYWORDS, os_rename__doc__},
1168
1169static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001170os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001171 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001172
1173static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001174os_rename(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001175{
1176 PyObject *return_value = NULL;
1177 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1178 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1179 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1180 int src_dir_fd = DEFAULT_DIR_FD;
1181 int dst_dir_fd = DEFAULT_DIR_FD;
1182
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001183 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&:rename", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001184 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd))
1185 goto exit;
1186 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1187
1188exit:
1189 /* Cleanup for src */
1190 path_cleanup(&src);
1191 /* Cleanup for dst */
1192 path_cleanup(&dst);
1193
1194 return return_value;
1195}
1196
1197PyDoc_STRVAR(os_replace__doc__,
1198"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1199"--\n"
1200"\n"
1201"Rename a file or directory, overwriting the destination.\n"
1202"\n"
1203"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1204" descriptor open to a directory, and the respective path string (src or dst)\n"
1205" should be relative; the path will then be relative to that directory.\n"
1206"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1207" If they are unavailable, using them will raise a NotImplementedError.\"");
1208
1209#define OS_REPLACE_METHODDEF \
1210 {"replace", (PyCFunction)os_replace, METH_VARARGS|METH_KEYWORDS, os_replace__doc__},
1211
1212static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001213os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1214 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001215
1216static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001217os_replace(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001218{
1219 PyObject *return_value = NULL;
1220 static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1221 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1222 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1223 int src_dir_fd = DEFAULT_DIR_FD;
1224 int dst_dir_fd = DEFAULT_DIR_FD;
1225
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001226 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$O&O&:replace", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001227 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd))
1228 goto exit;
1229 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1230
1231exit:
1232 /* Cleanup for src */
1233 path_cleanup(&src);
1234 /* Cleanup for dst */
1235 path_cleanup(&dst);
1236
1237 return return_value;
1238}
1239
1240PyDoc_STRVAR(os_rmdir__doc__,
1241"rmdir($module, /, path, *, dir_fd=None)\n"
1242"--\n"
1243"\n"
1244"Remove a directory.\n"
1245"\n"
1246"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1247" and path should be relative; path will then be relative to that directory.\n"
1248"dir_fd may not be implemented on your platform.\n"
1249" If it is unavailable, using it will raise a NotImplementedError.");
1250
1251#define OS_RMDIR_METHODDEF \
1252 {"rmdir", (PyCFunction)os_rmdir, METH_VARARGS|METH_KEYWORDS, os_rmdir__doc__},
1253
1254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001255os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001256
1257static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001258os_rmdir(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001259{
1260 PyObject *return_value = NULL;
1261 static char *_keywords[] = {"path", "dir_fd", NULL};
1262 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1263 int dir_fd = DEFAULT_DIR_FD;
1264
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001265 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:rmdir", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001266 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
1267 goto exit;
1268 return_value = os_rmdir_impl(module, &path, dir_fd);
1269
1270exit:
1271 /* Cleanup for path */
1272 path_cleanup(&path);
1273
1274 return return_value;
1275}
1276
1277#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1278
1279PyDoc_STRVAR(os_system__doc__,
1280"system($module, /, command)\n"
1281"--\n"
1282"\n"
1283"Execute the command in a subshell.");
1284
1285#define OS_SYSTEM_METHODDEF \
1286 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1287
1288static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001289os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001290
1291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001292os_system(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001293{
1294 PyObject *return_value = NULL;
1295 static char *_keywords[] = {"command", NULL};
1296 Py_UNICODE *command;
1297 long _return_value;
1298
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001299 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "u:system", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001300 &command))
1301 goto exit;
1302 _return_value = os_system_impl(module, command);
1303 if ((_return_value == -1) && PyErr_Occurred())
1304 goto exit;
1305 return_value = PyLong_FromLong(_return_value);
1306
1307exit:
1308 return return_value;
1309}
1310
1311#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1312
1313#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1314
1315PyDoc_STRVAR(os_system__doc__,
1316"system($module, /, command)\n"
1317"--\n"
1318"\n"
1319"Execute the command in a subshell.");
1320
1321#define OS_SYSTEM_METHODDEF \
1322 {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__},
1323
1324static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001325os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001326
1327static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001328os_system(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001329{
1330 PyObject *return_value = NULL;
1331 static char *_keywords[] = {"command", NULL};
1332 PyObject *command = NULL;
1333 long _return_value;
1334
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001335 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:system", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001336 PyUnicode_FSConverter, &command))
1337 goto exit;
1338 _return_value = os_system_impl(module, command);
1339 if ((_return_value == -1) && PyErr_Occurred())
1340 goto exit;
1341 return_value = PyLong_FromLong(_return_value);
1342
1343exit:
1344 /* Cleanup for command */
1345 Py_XDECREF(command);
1346
1347 return return_value;
1348}
1349
1350#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1351
1352PyDoc_STRVAR(os_umask__doc__,
1353"umask($module, mask, /)\n"
1354"--\n"
1355"\n"
1356"Set the current numeric umask and return the previous umask.");
1357
1358#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001359 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360
1361static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001362os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001363
1364static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001365os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366{
1367 PyObject *return_value = NULL;
1368 int mask;
1369
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001370 if (!PyArg_Parse(arg, "i:umask", &mask))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001371 goto exit;
1372 return_value = os_umask_impl(module, mask);
1373
1374exit:
1375 return return_value;
1376}
1377
1378PyDoc_STRVAR(os_unlink__doc__,
1379"unlink($module, /, path, *, dir_fd=None)\n"
1380"--\n"
1381"\n"
1382"Remove a file (same as remove()).\n"
1383"\n"
1384"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1385" and path should be relative; path will then be relative to that directory.\n"
1386"dir_fd may not be implemented on your platform.\n"
1387" If it is unavailable, using it will raise a NotImplementedError.");
1388
1389#define OS_UNLINK_METHODDEF \
1390 {"unlink", (PyCFunction)os_unlink, METH_VARARGS|METH_KEYWORDS, os_unlink__doc__},
1391
1392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001393os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001394
1395static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001396os_unlink(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001397{
1398 PyObject *return_value = NULL;
1399 static char *_keywords[] = {"path", "dir_fd", NULL};
1400 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1401 int dir_fd = DEFAULT_DIR_FD;
1402
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001403 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:unlink", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001404 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
1405 goto exit;
1406 return_value = os_unlink_impl(module, &path, dir_fd);
1407
1408exit:
1409 /* Cleanup for path */
1410 path_cleanup(&path);
1411
1412 return return_value;
1413}
1414
1415PyDoc_STRVAR(os_remove__doc__,
1416"remove($module, /, path, *, dir_fd=None)\n"
1417"--\n"
1418"\n"
1419"Remove a file (same as unlink()).\n"
1420"\n"
1421"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1422" and path should be relative; path will then be relative to that directory.\n"
1423"dir_fd may not be implemented on your platform.\n"
1424" If it is unavailable, using it will raise a NotImplementedError.");
1425
1426#define OS_REMOVE_METHODDEF \
1427 {"remove", (PyCFunction)os_remove, METH_VARARGS|METH_KEYWORDS, os_remove__doc__},
1428
1429static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001430os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001431
1432static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001433os_remove(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001434{
1435 PyObject *return_value = NULL;
1436 static char *_keywords[] = {"path", "dir_fd", NULL};
1437 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1438 int dir_fd = DEFAULT_DIR_FD;
1439
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001440 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:remove", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001441 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd))
1442 goto exit;
1443 return_value = os_remove_impl(module, &path, dir_fd);
1444
1445exit:
1446 /* Cleanup for path */
1447 path_cleanup(&path);
1448
1449 return return_value;
1450}
1451
1452#if defined(HAVE_UNAME)
1453
1454PyDoc_STRVAR(os_uname__doc__,
1455"uname($module, /)\n"
1456"--\n"
1457"\n"
1458"Return an object identifying the current operating system.\n"
1459"\n"
1460"The object behaves like a named tuple with the following fields:\n"
1461" (sysname, nodename, release, version, machine)");
1462
1463#define OS_UNAME_METHODDEF \
1464 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1465
1466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001467os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001468
1469static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001470os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471{
1472 return os_uname_impl(module);
1473}
1474
1475#endif /* defined(HAVE_UNAME) */
1476
1477PyDoc_STRVAR(os_utime__doc__,
1478"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1479" follow_symlinks=True)\n"
1480"--\n"
1481"\n"
1482"Set the access and modified time of path.\n"
1483"\n"
1484"path may always be specified as a string.\n"
1485"On some platforms, path may also be specified as an open file descriptor.\n"
1486" If this functionality is unavailable, using it raises an exception.\n"
1487"\n"
1488"If times is not None, it must be a tuple (atime, mtime);\n"
1489" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001490"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001491" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1492" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001493"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001494"Specifying tuples for both times and ns is an error.\n"
1495"\n"
1496"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1497" and path should be relative; path will then be relative to that directory.\n"
1498"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1499" link, utime will modify the symbolic link itself instead of the file the\n"
1500" link points to.\n"
1501"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1502" as an open file descriptor.\n"
1503"dir_fd and follow_symlinks may not be available on your platform.\n"
1504" If they are unavailable, using them will raise a NotImplementedError.");
1505
1506#define OS_UTIME_METHODDEF \
1507 {"utime", (PyCFunction)os_utime, METH_VARARGS|METH_KEYWORDS, os_utime__doc__},
1508
1509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001510os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1511 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001512
1513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001514os_utime(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001515{
1516 PyObject *return_value = NULL;
1517 static char *_keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1518 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1519 PyObject *times = NULL;
1520 PyObject *ns = NULL;
1521 int dir_fd = DEFAULT_DIR_FD;
1522 int follow_symlinks = 1;
1523
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001524 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|O$OO&p:utime", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001525 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
1526 goto exit;
1527 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1528
1529exit:
1530 /* Cleanup for path */
1531 path_cleanup(&path);
1532
1533 return return_value;
1534}
1535
1536PyDoc_STRVAR(os__exit__doc__,
1537"_exit($module, /, status)\n"
1538"--\n"
1539"\n"
1540"Exit to the system with specified status, without normal exit processing.");
1541
1542#define OS__EXIT_METHODDEF \
1543 {"_exit", (PyCFunction)os__exit, METH_VARARGS|METH_KEYWORDS, os__exit__doc__},
1544
1545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001546os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001547
1548static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001549os__exit(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001550{
1551 PyObject *return_value = NULL;
1552 static char *_keywords[] = {"status", NULL};
1553 int status;
1554
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001555 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:_exit", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001556 &status))
1557 goto exit;
1558 return_value = os__exit_impl(module, status);
1559
1560exit:
1561 return return_value;
1562}
1563
1564#if defined(HAVE_EXECV)
1565
1566PyDoc_STRVAR(os_execv__doc__,
1567"execv($module, path, argv, /)\n"
1568"--\n"
1569"\n"
1570"Execute an executable path with arguments, replacing current process.\n"
1571"\n"
1572" path\n"
1573" Path of executable file.\n"
1574" argv\n"
1575" Tuple or list of strings.");
1576
1577#define OS_EXECV_METHODDEF \
1578 {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
1579
1580static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001581os_execv_impl(PyObject *module, PyObject *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001582
1583static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001584os_execv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001585{
1586 PyObject *return_value = NULL;
1587 PyObject *path = NULL;
1588 PyObject *argv;
1589
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001590 if (!PyArg_ParseTuple(args, "O&O:execv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001591 PyUnicode_FSConverter, &path, &argv))
1592 goto exit;
1593 return_value = os_execv_impl(module, path, argv);
1594
1595exit:
1596 /* Cleanup for path */
1597 Py_XDECREF(path);
1598
1599 return return_value;
1600}
1601
1602#endif /* defined(HAVE_EXECV) */
1603
1604#if defined(HAVE_EXECV)
1605
1606PyDoc_STRVAR(os_execve__doc__,
1607"execve($module, /, path, argv, env)\n"
1608"--\n"
1609"\n"
1610"Execute an executable path with arguments, replacing current process.\n"
1611"\n"
1612" path\n"
1613" Path of executable file.\n"
1614" argv\n"
1615" Tuple or list of strings.\n"
1616" env\n"
1617" Dictionary of strings mapping to strings.");
1618
1619#define OS_EXECVE_METHODDEF \
1620 {"execve", (PyCFunction)os_execve, METH_VARARGS|METH_KEYWORDS, os_execve__doc__},
1621
1622static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001623os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001624
1625static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001626os_execve(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627{
1628 PyObject *return_value = NULL;
1629 static char *_keywords[] = {"path", "argv", "env", NULL};
1630 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1631 PyObject *argv;
1632 PyObject *env;
1633
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001634 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&OO:execve", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001635 path_converter, &path, &argv, &env))
1636 goto exit;
1637 return_value = os_execve_impl(module, &path, argv, env);
1638
1639exit:
1640 /* Cleanup for path */
1641 path_cleanup(&path);
1642
1643 return return_value;
1644}
1645
1646#endif /* defined(HAVE_EXECV) */
1647
1648#if defined(HAVE_SPAWNV)
1649
1650PyDoc_STRVAR(os_spawnv__doc__,
1651"spawnv($module, mode, path, argv, /)\n"
1652"--\n"
1653"\n"
1654"Execute the program specified by path in a new process.\n"
1655"\n"
1656" mode\n"
1657" Mode of process creation.\n"
1658" path\n"
1659" Path of executable file.\n"
1660" argv\n"
1661" Tuple or list of strings.");
1662
1663#define OS_SPAWNV_METHODDEF \
1664 {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
1665
1666static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001667os_spawnv_impl(PyObject *module, int mode, PyObject *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001668
1669static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001670os_spawnv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001671{
1672 PyObject *return_value = NULL;
1673 int mode;
1674 PyObject *path = NULL;
1675 PyObject *argv;
1676
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001677 if (!PyArg_ParseTuple(args, "iO&O:spawnv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001678 &mode, PyUnicode_FSConverter, &path, &argv))
1679 goto exit;
1680 return_value = os_spawnv_impl(module, mode, path, argv);
1681
1682exit:
1683 /* Cleanup for path */
1684 Py_XDECREF(path);
1685
1686 return return_value;
1687}
1688
1689#endif /* defined(HAVE_SPAWNV) */
1690
1691#if defined(HAVE_SPAWNV)
1692
1693PyDoc_STRVAR(os_spawnve__doc__,
1694"spawnve($module, mode, path, argv, env, /)\n"
1695"--\n"
1696"\n"
1697"Execute the program specified by path in a new process.\n"
1698"\n"
1699" mode\n"
1700" Mode of process creation.\n"
1701" path\n"
1702" Path of executable file.\n"
1703" argv\n"
1704" Tuple or list of strings.\n"
1705" env\n"
1706" Dictionary of strings mapping to strings.");
1707
1708#define OS_SPAWNVE_METHODDEF \
1709 {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
1710
1711static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001712os_spawnve_impl(PyObject *module, int mode, PyObject *path, PyObject *argv,
1713 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001714
1715static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001716os_spawnve(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001717{
1718 PyObject *return_value = NULL;
1719 int mode;
1720 PyObject *path = NULL;
1721 PyObject *argv;
1722 PyObject *env;
1723
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001724 if (!PyArg_ParseTuple(args, "iO&OO:spawnve",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001725 &mode, PyUnicode_FSConverter, &path, &argv, &env))
1726 goto exit;
1727 return_value = os_spawnve_impl(module, mode, path, argv, env);
1728
1729exit:
1730 /* Cleanup for path */
1731 Py_XDECREF(path);
1732
1733 return return_value;
1734}
1735
1736#endif /* defined(HAVE_SPAWNV) */
1737
1738#if defined(HAVE_FORK1)
1739
1740PyDoc_STRVAR(os_fork1__doc__,
1741"fork1($module, /)\n"
1742"--\n"
1743"\n"
1744"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1745"\n"
1746"Return 0 to child process and PID of child to parent process.");
1747
1748#define OS_FORK1_METHODDEF \
1749 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1750
1751static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001752os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001753
1754static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001755os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001756{
1757 return os_fork1_impl(module);
1758}
1759
1760#endif /* defined(HAVE_FORK1) */
1761
1762#if defined(HAVE_FORK)
1763
1764PyDoc_STRVAR(os_fork__doc__,
1765"fork($module, /)\n"
1766"--\n"
1767"\n"
1768"Fork a child process.\n"
1769"\n"
1770"Return 0 to child process and PID of child to parent process.");
1771
1772#define OS_FORK_METHODDEF \
1773 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1774
1775static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001776os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001777
1778static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001779os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001780{
1781 return os_fork_impl(module);
1782}
1783
1784#endif /* defined(HAVE_FORK) */
1785
1786#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1787
1788PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1789"sched_get_priority_max($module, /, policy)\n"
1790"--\n"
1791"\n"
1792"Get the maximum scheduling priority for policy.");
1793
1794#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
1795 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_max__doc__},
1796
1797static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001798os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001799
1800static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001801os_sched_get_priority_max(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001802{
1803 PyObject *return_value = NULL;
1804 static char *_keywords[] = {"policy", NULL};
1805 int policy;
1806
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001807 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:sched_get_priority_max", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001808 &policy))
1809 goto exit;
1810 return_value = os_sched_get_priority_max_impl(module, policy);
1811
1812exit:
1813 return return_value;
1814}
1815
1816#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1817
1818#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1819
1820PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1821"sched_get_priority_min($module, /, policy)\n"
1822"--\n"
1823"\n"
1824"Get the minimum scheduling priority for policy.");
1825
1826#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
1827 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_min__doc__},
1828
1829static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001830os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001831
1832static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001833os_sched_get_priority_min(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001834{
1835 PyObject *return_value = NULL;
1836 static char *_keywords[] = {"policy", NULL};
1837 int policy;
1838
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001839 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:sched_get_priority_min", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001840 &policy))
1841 goto exit;
1842 return_value = os_sched_get_priority_min_impl(module, policy);
1843
1844exit:
1845 return return_value;
1846}
1847
1848#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1849
1850#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1851
1852PyDoc_STRVAR(os_sched_getscheduler__doc__,
1853"sched_getscheduler($module, pid, /)\n"
1854"--\n"
1855"\n"
1856"Get the scheduling policy for the process identifiedy by pid.\n"
1857"\n"
1858"Passing 0 for pid returns the scheduling policy for the calling process.");
1859
1860#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001861 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001862
1863static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001864os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001865
1866static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001867os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001868{
1869 PyObject *return_value = NULL;
1870 pid_t pid;
1871
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001872 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001873 goto exit;
1874 return_value = os_sched_getscheduler_impl(module, pid);
1875
1876exit:
1877 return return_value;
1878}
1879
1880#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1881
1882#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1883
1884PyDoc_STRVAR(os_sched_param__doc__,
1885"sched_param(sched_priority)\n"
1886"--\n"
1887"\n"
1888"Current has only one field: sched_priority\");\n"
1889"\n"
1890" sched_priority\n"
1891" A scheduling parameter.");
1892
1893static PyObject *
1894os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1895
1896static PyObject *
1897os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1898{
1899 PyObject *return_value = NULL;
1900 static char *_keywords[] = {"sched_priority", NULL};
1901 PyObject *sched_priority;
1902
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001903 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:sched_param", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001904 &sched_priority))
1905 goto exit;
1906 return_value = os_sched_param_impl(type, sched_priority);
1907
1908exit:
1909 return return_value;
1910}
1911
1912#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
1913
1914#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1915
1916PyDoc_STRVAR(os_sched_setscheduler__doc__,
1917"sched_setscheduler($module, pid, policy, param, /)\n"
1918"--\n"
1919"\n"
1920"Set the scheduling policy for the process identified by pid.\n"
1921"\n"
1922"If pid is 0, the calling process is changed.\n"
1923"param is an instance of sched_param.");
1924
1925#define OS_SCHED_SETSCHEDULER_METHODDEF \
1926 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
1927
1928static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001929os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04001930 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001931
1932static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001933os_sched_setscheduler(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001934{
1935 PyObject *return_value = NULL;
1936 pid_t pid;
1937 int policy;
1938 struct sched_param param;
1939
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001940 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001941 &pid, &policy, convert_sched_param, &param))
1942 goto exit;
1943 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
1944
1945exit:
1946 return return_value;
1947}
1948
1949#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1950
1951#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
1952
1953PyDoc_STRVAR(os_sched_getparam__doc__,
1954"sched_getparam($module, pid, /)\n"
1955"--\n"
1956"\n"
1957"Returns scheduling parameters for the process identified by pid.\n"
1958"\n"
1959"If pid is 0, returns parameters for the calling process.\n"
1960"Return value is an instance of sched_param.");
1961
1962#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001963 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001964
1965static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001966os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001967
1968static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001969os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001970{
1971 PyObject *return_value = NULL;
1972 pid_t pid;
1973
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001974 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001975 goto exit;
1976 return_value = os_sched_getparam_impl(module, pid);
1977
1978exit:
1979 return return_value;
1980}
1981
1982#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
1983
1984#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
1985
1986PyDoc_STRVAR(os_sched_setparam__doc__,
1987"sched_setparam($module, pid, param, /)\n"
1988"--\n"
1989"\n"
1990"Set scheduling parameters for the process identified by pid.\n"
1991"\n"
1992"If pid is 0, sets parameters for the calling process.\n"
1993"param should be an instance of sched_param.");
1994
1995#define OS_SCHED_SETPARAM_METHODDEF \
1996 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
1997
1998static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001999os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002000 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002001
2002static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002003os_sched_setparam(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002004{
2005 PyObject *return_value = NULL;
2006 pid_t pid;
2007 struct sched_param param;
2008
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002009 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002010 &pid, convert_sched_param, &param))
2011 goto exit;
2012 return_value = os_sched_setparam_impl(module, pid, &param);
2013
2014exit:
2015 return return_value;
2016}
2017
2018#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2019
2020#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2021
2022PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2023"sched_rr_get_interval($module, pid, /)\n"
2024"--\n"
2025"\n"
2026"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2027"\n"
2028"Value returned is a float.");
2029
2030#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002031 {"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 +03002032
2033static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002034os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002035
2036static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002037os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002038{
2039 PyObject *return_value = NULL;
2040 pid_t pid;
2041 double _return_value;
2042
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002043 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002044 goto exit;
2045 _return_value = os_sched_rr_get_interval_impl(module, pid);
2046 if ((_return_value == -1.0) && PyErr_Occurred())
2047 goto exit;
2048 return_value = PyFloat_FromDouble(_return_value);
2049
2050exit:
2051 return return_value;
2052}
2053
2054#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2055
2056#if defined(HAVE_SCHED_H)
2057
2058PyDoc_STRVAR(os_sched_yield__doc__,
2059"sched_yield($module, /)\n"
2060"--\n"
2061"\n"
2062"Voluntarily relinquish the CPU.");
2063
2064#define OS_SCHED_YIELD_METHODDEF \
2065 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2066
2067static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002068os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002069
2070static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002071os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002072{
2073 return os_sched_yield_impl(module);
2074}
2075
2076#endif /* defined(HAVE_SCHED_H) */
2077
2078#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2079
2080PyDoc_STRVAR(os_sched_setaffinity__doc__,
2081"sched_setaffinity($module, pid, mask, /)\n"
2082"--\n"
2083"\n"
2084"Set the CPU affinity of the process identified by pid to mask.\n"
2085"\n"
2086"mask should be an iterable of integers identifying CPUs.");
2087
2088#define OS_SCHED_SETAFFINITY_METHODDEF \
2089 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
2090
2091static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002092os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002093
2094static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002095os_sched_setaffinity(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002096{
2097 PyObject *return_value = NULL;
2098 pid_t pid;
2099 PyObject *mask;
2100
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002101 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002102 &pid, &mask))
2103 goto exit;
2104 return_value = os_sched_setaffinity_impl(module, pid, mask);
2105
2106exit:
2107 return return_value;
2108}
2109
2110#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2111
2112#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2113
2114PyDoc_STRVAR(os_sched_getaffinity__doc__,
2115"sched_getaffinity($module, pid, /)\n"
2116"--\n"
2117"\n"
2118"Return the affinity of the process identified by pid.\n"
2119"\n"
2120"The affinity is returned as a set of CPU identifiers.");
2121
2122#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002123 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002124
2125static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002126os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002127
2128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002129os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002130{
2131 PyObject *return_value = NULL;
2132 pid_t pid;
2133
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002134 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002135 goto exit;
2136 return_value = os_sched_getaffinity_impl(module, pid);
2137
2138exit:
2139 return return_value;
2140}
2141
2142#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2143
2144#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2145
2146PyDoc_STRVAR(os_openpty__doc__,
2147"openpty($module, /)\n"
2148"--\n"
2149"\n"
2150"Open a pseudo-terminal.\n"
2151"\n"
2152"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2153"for both the master and slave ends.");
2154
2155#define OS_OPENPTY_METHODDEF \
2156 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2157
2158static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002159os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002160
2161static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002162os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002163{
2164 return os_openpty_impl(module);
2165}
2166
2167#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2168
2169#if defined(HAVE_FORKPTY)
2170
2171PyDoc_STRVAR(os_forkpty__doc__,
2172"forkpty($module, /)\n"
2173"--\n"
2174"\n"
2175"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2176"\n"
2177"Returns a tuple of (pid, master_fd).\n"
2178"Like fork(), return pid of 0 to the child process,\n"
2179"and pid of child to the parent process.\n"
2180"To both, return fd of newly opened pseudo-terminal.");
2181
2182#define OS_FORKPTY_METHODDEF \
2183 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2184
2185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002186os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002187
2188static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002189os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002190{
2191 return os_forkpty_impl(module);
2192}
2193
2194#endif /* defined(HAVE_FORKPTY) */
2195
2196#if defined(HAVE_GETEGID)
2197
2198PyDoc_STRVAR(os_getegid__doc__,
2199"getegid($module, /)\n"
2200"--\n"
2201"\n"
2202"Return the current process\'s effective group id.");
2203
2204#define OS_GETEGID_METHODDEF \
2205 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2206
2207static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002208os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002209
2210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002211os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002212{
2213 return os_getegid_impl(module);
2214}
2215
2216#endif /* defined(HAVE_GETEGID) */
2217
2218#if defined(HAVE_GETEUID)
2219
2220PyDoc_STRVAR(os_geteuid__doc__,
2221"geteuid($module, /)\n"
2222"--\n"
2223"\n"
2224"Return the current process\'s effective user id.");
2225
2226#define OS_GETEUID_METHODDEF \
2227 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2228
2229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002230os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002231
2232static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002233os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234{
2235 return os_geteuid_impl(module);
2236}
2237
2238#endif /* defined(HAVE_GETEUID) */
2239
2240#if defined(HAVE_GETGID)
2241
2242PyDoc_STRVAR(os_getgid__doc__,
2243"getgid($module, /)\n"
2244"--\n"
2245"\n"
2246"Return the current process\'s group id.");
2247
2248#define OS_GETGID_METHODDEF \
2249 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2250
2251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002252os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002253
2254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002255os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002256{
2257 return os_getgid_impl(module);
2258}
2259
2260#endif /* defined(HAVE_GETGID) */
2261
2262PyDoc_STRVAR(os_getpid__doc__,
2263"getpid($module, /)\n"
2264"--\n"
2265"\n"
2266"Return the current process id.");
2267
2268#define OS_GETPID_METHODDEF \
2269 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2270
2271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002272os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002273
2274static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002275os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002276{
2277 return os_getpid_impl(module);
2278}
2279
2280#if defined(HAVE_GETGROUPS)
2281
2282PyDoc_STRVAR(os_getgroups__doc__,
2283"getgroups($module, /)\n"
2284"--\n"
2285"\n"
2286"Return list of supplemental group IDs for the process.");
2287
2288#define OS_GETGROUPS_METHODDEF \
2289 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2290
2291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002292os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002293
2294static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002295os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002296{
2297 return os_getgroups_impl(module);
2298}
2299
2300#endif /* defined(HAVE_GETGROUPS) */
2301
2302#if defined(HAVE_GETPGID)
2303
2304PyDoc_STRVAR(os_getpgid__doc__,
2305"getpgid($module, /, pid)\n"
2306"--\n"
2307"\n"
2308"Call the system call getpgid(), and return the result.");
2309
2310#define OS_GETPGID_METHODDEF \
2311 {"getpgid", (PyCFunction)os_getpgid, METH_VARARGS|METH_KEYWORDS, os_getpgid__doc__},
2312
2313static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002314os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002315
2316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002317os_getpgid(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002318{
2319 PyObject *return_value = NULL;
2320 static char *_keywords[] = {"pid", NULL};
2321 pid_t pid;
2322
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002323 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "" _Py_PARSE_PID ":getpgid", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002324 &pid))
2325 goto exit;
2326 return_value = os_getpgid_impl(module, pid);
2327
2328exit:
2329 return return_value;
2330}
2331
2332#endif /* defined(HAVE_GETPGID) */
2333
2334#if defined(HAVE_GETPGRP)
2335
2336PyDoc_STRVAR(os_getpgrp__doc__,
2337"getpgrp($module, /)\n"
2338"--\n"
2339"\n"
2340"Return the current process group id.");
2341
2342#define OS_GETPGRP_METHODDEF \
2343 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2344
2345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002346os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002347
2348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002349os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002350{
2351 return os_getpgrp_impl(module);
2352}
2353
2354#endif /* defined(HAVE_GETPGRP) */
2355
2356#if defined(HAVE_SETPGRP)
2357
2358PyDoc_STRVAR(os_setpgrp__doc__,
2359"setpgrp($module, /)\n"
2360"--\n"
2361"\n"
2362"Make the current process the leader of its process group.");
2363
2364#define OS_SETPGRP_METHODDEF \
2365 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2366
2367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002368os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002369
2370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002371os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002372{
2373 return os_setpgrp_impl(module);
2374}
2375
2376#endif /* defined(HAVE_SETPGRP) */
2377
2378#if defined(HAVE_GETPPID)
2379
2380PyDoc_STRVAR(os_getppid__doc__,
2381"getppid($module, /)\n"
2382"--\n"
2383"\n"
2384"Return the parent\'s process id.\n"
2385"\n"
2386"If the parent process has already exited, Windows machines will still\n"
2387"return its id; others systems will return the id of the \'init\' process (1).");
2388
2389#define OS_GETPPID_METHODDEF \
2390 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2391
2392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002393os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002394
2395static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002396os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002397{
2398 return os_getppid_impl(module);
2399}
2400
2401#endif /* defined(HAVE_GETPPID) */
2402
2403#if defined(HAVE_GETLOGIN)
2404
2405PyDoc_STRVAR(os_getlogin__doc__,
2406"getlogin($module, /)\n"
2407"--\n"
2408"\n"
2409"Return the actual login name.");
2410
2411#define OS_GETLOGIN_METHODDEF \
2412 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2413
2414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002415os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002416
2417static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002418os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002419{
2420 return os_getlogin_impl(module);
2421}
2422
2423#endif /* defined(HAVE_GETLOGIN) */
2424
2425#if defined(HAVE_GETUID)
2426
2427PyDoc_STRVAR(os_getuid__doc__,
2428"getuid($module, /)\n"
2429"--\n"
2430"\n"
2431"Return the current process\'s user id.");
2432
2433#define OS_GETUID_METHODDEF \
2434 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2435
2436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002437os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002438
2439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002440os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002441{
2442 return os_getuid_impl(module);
2443}
2444
2445#endif /* defined(HAVE_GETUID) */
2446
2447#if defined(HAVE_KILL)
2448
2449PyDoc_STRVAR(os_kill__doc__,
2450"kill($module, pid, signal, /)\n"
2451"--\n"
2452"\n"
2453"Kill a process with a signal.");
2454
2455#define OS_KILL_METHODDEF \
2456 {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
2457
2458static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002459os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002460
2461static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002462os_kill(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002463{
2464 PyObject *return_value = NULL;
2465 pid_t pid;
2466 Py_ssize_t signal;
2467
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002468 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002469 &pid, &signal))
2470 goto exit;
2471 return_value = os_kill_impl(module, pid, signal);
2472
2473exit:
2474 return return_value;
2475}
2476
2477#endif /* defined(HAVE_KILL) */
2478
2479#if defined(HAVE_KILLPG)
2480
2481PyDoc_STRVAR(os_killpg__doc__,
2482"killpg($module, pgid, signal, /)\n"
2483"--\n"
2484"\n"
2485"Kill a process group with a signal.");
2486
2487#define OS_KILLPG_METHODDEF \
2488 {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
2489
2490static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002491os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002492
2493static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002494os_killpg(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002495{
2496 PyObject *return_value = NULL;
2497 pid_t pgid;
2498 int signal;
2499
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002500 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002501 &pgid, &signal))
2502 goto exit;
2503 return_value = os_killpg_impl(module, pgid, signal);
2504
2505exit:
2506 return return_value;
2507}
2508
2509#endif /* defined(HAVE_KILLPG) */
2510
2511#if defined(HAVE_PLOCK)
2512
2513PyDoc_STRVAR(os_plock__doc__,
2514"plock($module, op, /)\n"
2515"--\n"
2516"\n"
2517"Lock program segments into memory.\");");
2518
2519#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002520 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002521
2522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002523os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002524
2525static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002526os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002527{
2528 PyObject *return_value = NULL;
2529 int op;
2530
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002531 if (!PyArg_Parse(arg, "i:plock", &op))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002532 goto exit;
2533 return_value = os_plock_impl(module, op);
2534
2535exit:
2536 return return_value;
2537}
2538
2539#endif /* defined(HAVE_PLOCK) */
2540
2541#if defined(HAVE_SETUID)
2542
2543PyDoc_STRVAR(os_setuid__doc__,
2544"setuid($module, uid, /)\n"
2545"--\n"
2546"\n"
2547"Set the current process\'s user id.");
2548
2549#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002550 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002551
2552static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002553os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002554
2555static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002556os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002557{
2558 PyObject *return_value = NULL;
2559 uid_t uid;
2560
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002561 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002562 goto exit;
2563 return_value = os_setuid_impl(module, uid);
2564
2565exit:
2566 return return_value;
2567}
2568
2569#endif /* defined(HAVE_SETUID) */
2570
2571#if defined(HAVE_SETEUID)
2572
2573PyDoc_STRVAR(os_seteuid__doc__,
2574"seteuid($module, euid, /)\n"
2575"--\n"
2576"\n"
2577"Set the current process\'s effective user id.");
2578
2579#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002580 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002581
2582static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002583os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002584
2585static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002586os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002587{
2588 PyObject *return_value = NULL;
2589 uid_t euid;
2590
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002591 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002592 goto exit;
2593 return_value = os_seteuid_impl(module, euid);
2594
2595exit:
2596 return return_value;
2597}
2598
2599#endif /* defined(HAVE_SETEUID) */
2600
2601#if defined(HAVE_SETEGID)
2602
2603PyDoc_STRVAR(os_setegid__doc__,
2604"setegid($module, egid, /)\n"
2605"--\n"
2606"\n"
2607"Set the current process\'s effective group id.");
2608
2609#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002610 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002611
2612static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002613os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002614
2615static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002616os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002617{
2618 PyObject *return_value = NULL;
2619 gid_t egid;
2620
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002621 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002622 goto exit;
2623 return_value = os_setegid_impl(module, egid);
2624
2625exit:
2626 return return_value;
2627}
2628
2629#endif /* defined(HAVE_SETEGID) */
2630
2631#if defined(HAVE_SETREUID)
2632
2633PyDoc_STRVAR(os_setreuid__doc__,
2634"setreuid($module, ruid, euid, /)\n"
2635"--\n"
2636"\n"
2637"Set the current process\'s real and effective user ids.");
2638
2639#define OS_SETREUID_METHODDEF \
2640 {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
2641
2642static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002643os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002644
2645static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002646os_setreuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002647{
2648 PyObject *return_value = NULL;
2649 uid_t ruid;
2650 uid_t euid;
2651
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002652 if (!PyArg_ParseTuple(args, "O&O&:setreuid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002653 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid))
2654 goto exit;
2655 return_value = os_setreuid_impl(module, ruid, euid);
2656
2657exit:
2658 return return_value;
2659}
2660
2661#endif /* defined(HAVE_SETREUID) */
2662
2663#if defined(HAVE_SETREGID)
2664
2665PyDoc_STRVAR(os_setregid__doc__,
2666"setregid($module, rgid, egid, /)\n"
2667"--\n"
2668"\n"
2669"Set the current process\'s real and effective group ids.");
2670
2671#define OS_SETREGID_METHODDEF \
2672 {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
2673
2674static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002675os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002676
2677static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002678os_setregid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002679{
2680 PyObject *return_value = NULL;
2681 gid_t rgid;
2682 gid_t egid;
2683
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002684 if (!PyArg_ParseTuple(args, "O&O&:setregid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002685 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid))
2686 goto exit;
2687 return_value = os_setregid_impl(module, rgid, egid);
2688
2689exit:
2690 return return_value;
2691}
2692
2693#endif /* defined(HAVE_SETREGID) */
2694
2695#if defined(HAVE_SETGID)
2696
2697PyDoc_STRVAR(os_setgid__doc__,
2698"setgid($module, gid, /)\n"
2699"--\n"
2700"\n"
2701"Set the current process\'s group id.");
2702
2703#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002704 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002705
2706static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002707os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002708
2709static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002710os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002711{
2712 PyObject *return_value = NULL;
2713 gid_t gid;
2714
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002715 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002716 goto exit;
2717 return_value = os_setgid_impl(module, gid);
2718
2719exit:
2720 return return_value;
2721}
2722
2723#endif /* defined(HAVE_SETGID) */
2724
2725#if defined(HAVE_SETGROUPS)
2726
2727PyDoc_STRVAR(os_setgroups__doc__,
2728"setgroups($module, groups, /)\n"
2729"--\n"
2730"\n"
2731"Set the groups of the current process to list.");
2732
2733#define OS_SETGROUPS_METHODDEF \
2734 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2735
2736#endif /* defined(HAVE_SETGROUPS) */
2737
2738#if defined(HAVE_WAIT3)
2739
2740PyDoc_STRVAR(os_wait3__doc__,
2741"wait3($module, /, options)\n"
2742"--\n"
2743"\n"
2744"Wait for completion of a child process.\n"
2745"\n"
2746"Returns a tuple of information about the child process:\n"
2747" (pid, status, rusage)");
2748
2749#define OS_WAIT3_METHODDEF \
2750 {"wait3", (PyCFunction)os_wait3, METH_VARARGS|METH_KEYWORDS, os_wait3__doc__},
2751
2752static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002753os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002754
2755static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002756os_wait3(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002757{
2758 PyObject *return_value = NULL;
2759 static char *_keywords[] = {"options", NULL};
2760 int options;
2761
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002762 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:wait3", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002763 &options))
2764 goto exit;
2765 return_value = os_wait3_impl(module, options);
2766
2767exit:
2768 return return_value;
2769}
2770
2771#endif /* defined(HAVE_WAIT3) */
2772
2773#if defined(HAVE_WAIT4)
2774
2775PyDoc_STRVAR(os_wait4__doc__,
2776"wait4($module, /, pid, options)\n"
2777"--\n"
2778"\n"
2779"Wait for completion of a specific child process.\n"
2780"\n"
2781"Returns a tuple of information about the child process:\n"
2782" (pid, status, rusage)");
2783
2784#define OS_WAIT4_METHODDEF \
2785 {"wait4", (PyCFunction)os_wait4, METH_VARARGS|METH_KEYWORDS, os_wait4__doc__},
2786
2787static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002788os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002789
2790static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002791os_wait4(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002792{
2793 PyObject *return_value = NULL;
2794 static char *_keywords[] = {"pid", "options", NULL};
2795 pid_t pid;
2796 int options;
2797
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002798 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "" _Py_PARSE_PID "i:wait4", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002799 &pid, &options))
2800 goto exit;
2801 return_value = os_wait4_impl(module, pid, options);
2802
2803exit:
2804 return return_value;
2805}
2806
2807#endif /* defined(HAVE_WAIT4) */
2808
2809#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2810
2811PyDoc_STRVAR(os_waitid__doc__,
2812"waitid($module, idtype, id, options, /)\n"
2813"--\n"
2814"\n"
2815"Returns the result of waiting for a process or processes.\n"
2816"\n"
2817" idtype\n"
2818" Must be one of be P_PID, P_PGID or P_ALL.\n"
2819" id\n"
2820" The id to wait on.\n"
2821" options\n"
2822" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2823" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2824"\n"
2825"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2826"no children in a waitable state.");
2827
2828#define OS_WAITID_METHODDEF \
2829 {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
2830
2831static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002832os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002833
2834static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002835os_waitid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002836{
2837 PyObject *return_value = NULL;
2838 idtype_t idtype;
2839 id_t id;
2840 int options;
2841
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002842 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002843 &idtype, &id, &options))
2844 goto exit;
2845 return_value = os_waitid_impl(module, idtype, id, options);
2846
2847exit:
2848 return return_value;
2849}
2850
2851#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
2852
2853#if defined(HAVE_WAITPID)
2854
2855PyDoc_STRVAR(os_waitpid__doc__,
2856"waitpid($module, pid, options, /)\n"
2857"--\n"
2858"\n"
2859"Wait for completion of a given child process.\n"
2860"\n"
2861"Returns a tuple of information regarding the child process:\n"
2862" (pid, status)\n"
2863"\n"
2864"The options argument is ignored on Windows.");
2865
2866#define OS_WAITPID_METHODDEF \
2867 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2868
2869static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002870os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002871
2872static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002873os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002874{
2875 PyObject *return_value = NULL;
2876 pid_t pid;
2877 int options;
2878
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002879 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002880 &pid, &options))
2881 goto exit;
2882 return_value = os_waitpid_impl(module, pid, options);
2883
2884exit:
2885 return return_value;
2886}
2887
2888#endif /* defined(HAVE_WAITPID) */
2889
2890#if defined(HAVE_CWAIT)
2891
2892PyDoc_STRVAR(os_waitpid__doc__,
2893"waitpid($module, pid, options, /)\n"
2894"--\n"
2895"\n"
2896"Wait for completion of a given process.\n"
2897"\n"
2898"Returns a tuple of information regarding the process:\n"
2899" (pid, status << 8)\n"
2900"\n"
2901"The options argument is ignored on Windows.");
2902
2903#define OS_WAITPID_METHODDEF \
2904 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2905
2906static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002907os_waitpid_impl(PyObject *module, Py_intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002908
2909static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002910os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002911{
2912 PyObject *return_value = NULL;
2913 Py_intptr_t pid;
2914 int options;
2915
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002916 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002917 &pid, &options))
2918 goto exit;
2919 return_value = os_waitpid_impl(module, pid, options);
2920
2921exit:
2922 return return_value;
2923}
2924
2925#endif /* defined(HAVE_CWAIT) */
2926
2927#if defined(HAVE_WAIT)
2928
2929PyDoc_STRVAR(os_wait__doc__,
2930"wait($module, /)\n"
2931"--\n"
2932"\n"
2933"Wait for completion of a child process.\n"
2934"\n"
2935"Returns a tuple of information about the child process:\n"
2936" (pid, status)");
2937
2938#define OS_WAIT_METHODDEF \
2939 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
2940
2941static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002942os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002943
2944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002945os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002946{
2947 return os_wait_impl(module);
2948}
2949
2950#endif /* defined(HAVE_WAIT) */
2951
2952#if defined(HAVE_SYMLINK)
2953
2954PyDoc_STRVAR(os_symlink__doc__,
2955"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
2956"--\n"
2957"\n"
2958"Create a symbolic link pointing to src named dst.\n"
2959"\n"
2960"target_is_directory is required on Windows if the target is to be\n"
2961" interpreted as a directory. (On Windows, symlink requires\n"
2962" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
2963" target_is_directory is ignored on non-Windows platforms.\n"
2964"\n"
2965"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2966" and path should be relative; path will then be relative to that directory.\n"
2967"dir_fd may not be implemented on your platform.\n"
2968" If it is unavailable, using it will raise a NotImplementedError.");
2969
2970#define OS_SYMLINK_METHODDEF \
2971 {"symlink", (PyCFunction)os_symlink, METH_VARARGS|METH_KEYWORDS, os_symlink__doc__},
2972
2973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002974os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04002975 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002976
2977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002978os_symlink(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002979{
2980 PyObject *return_value = NULL;
2981 static char *_keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
2982 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
2983 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
2984 int target_is_directory = 0;
2985 int dir_fd = DEFAULT_DIR_FD;
2986
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002987 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|p$O&:symlink", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002988 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd))
2989 goto exit;
2990 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
2991
2992exit:
2993 /* Cleanup for src */
2994 path_cleanup(&src);
2995 /* Cleanup for dst */
2996 path_cleanup(&dst);
2997
2998 return return_value;
2999}
3000
3001#endif /* defined(HAVE_SYMLINK) */
3002
3003#if defined(HAVE_TIMES)
3004
3005PyDoc_STRVAR(os_times__doc__,
3006"times($module, /)\n"
3007"--\n"
3008"\n"
3009"Return a collection containing process timing information.\n"
3010"\n"
3011"The object returned behaves like a named tuple with these fields:\n"
3012" (utime, stime, cutime, cstime, elapsed_time)\n"
3013"All fields are floating point numbers.");
3014
3015#define OS_TIMES_METHODDEF \
3016 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3017
3018static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003019os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003020
3021static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003022os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003023{
3024 return os_times_impl(module);
3025}
3026
3027#endif /* defined(HAVE_TIMES) */
3028
3029#if defined(HAVE_GETSID)
3030
3031PyDoc_STRVAR(os_getsid__doc__,
3032"getsid($module, pid, /)\n"
3033"--\n"
3034"\n"
3035"Call the system call getsid(pid) and return the result.");
3036
3037#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003038 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003039
3040static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003041os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003042
3043static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003044os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003045{
3046 PyObject *return_value = NULL;
3047 pid_t pid;
3048
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003049 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003050 goto exit;
3051 return_value = os_getsid_impl(module, pid);
3052
3053exit:
3054 return return_value;
3055}
3056
3057#endif /* defined(HAVE_GETSID) */
3058
3059#if defined(HAVE_SETSID)
3060
3061PyDoc_STRVAR(os_setsid__doc__,
3062"setsid($module, /)\n"
3063"--\n"
3064"\n"
3065"Call the system call setsid().");
3066
3067#define OS_SETSID_METHODDEF \
3068 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3069
3070static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003071os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003072
3073static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003074os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003075{
3076 return os_setsid_impl(module);
3077}
3078
3079#endif /* defined(HAVE_SETSID) */
3080
3081#if defined(HAVE_SETPGID)
3082
3083PyDoc_STRVAR(os_setpgid__doc__,
3084"setpgid($module, pid, pgrp, /)\n"
3085"--\n"
3086"\n"
3087"Call the system call setpgid(pid, pgrp).");
3088
3089#define OS_SETPGID_METHODDEF \
3090 {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
3091
3092static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003093os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003094
3095static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003096os_setpgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003097{
3098 PyObject *return_value = NULL;
3099 pid_t pid;
3100 pid_t pgrp;
3101
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003102 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003103 &pid, &pgrp))
3104 goto exit;
3105 return_value = os_setpgid_impl(module, pid, pgrp);
3106
3107exit:
3108 return return_value;
3109}
3110
3111#endif /* defined(HAVE_SETPGID) */
3112
3113#if defined(HAVE_TCGETPGRP)
3114
3115PyDoc_STRVAR(os_tcgetpgrp__doc__,
3116"tcgetpgrp($module, fd, /)\n"
3117"--\n"
3118"\n"
3119"Return the process group associated with the terminal specified by fd.");
3120
3121#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003122 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123
3124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003125os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003126
3127static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003128os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003129{
3130 PyObject *return_value = NULL;
3131 int fd;
3132
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003133 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003134 goto exit;
3135 return_value = os_tcgetpgrp_impl(module, fd);
3136
3137exit:
3138 return return_value;
3139}
3140
3141#endif /* defined(HAVE_TCGETPGRP) */
3142
3143#if defined(HAVE_TCSETPGRP)
3144
3145PyDoc_STRVAR(os_tcsetpgrp__doc__,
3146"tcsetpgrp($module, fd, pgid, /)\n"
3147"--\n"
3148"\n"
3149"Set the process group associated with the terminal specified by fd.");
3150
3151#define OS_TCSETPGRP_METHODDEF \
3152 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
3153
3154static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003155os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003156
3157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003158os_tcsetpgrp(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003159{
3160 PyObject *return_value = NULL;
3161 int fd;
3162 pid_t pgid;
3163
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003164 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003165 &fd, &pgid))
3166 goto exit;
3167 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3168
3169exit:
3170 return return_value;
3171}
3172
3173#endif /* defined(HAVE_TCSETPGRP) */
3174
3175PyDoc_STRVAR(os_open__doc__,
3176"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3177"--\n"
3178"\n"
3179"Open a file for low level IO. Returns a file descriptor (integer).\n"
3180"\n"
3181"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3182" and path should be relative; path will then be relative to that directory.\n"
3183"dir_fd may not be implemented on your platform.\n"
3184" If it is unavailable, using it will raise a NotImplementedError.");
3185
3186#define OS_OPEN_METHODDEF \
3187 {"open", (PyCFunction)os_open, METH_VARARGS|METH_KEYWORDS, os_open__doc__},
3188
3189static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003190os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003191
3192static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003193os_open(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003194{
3195 PyObject *return_value = NULL;
3196 static char *_keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3197 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3198 int flags;
3199 int mode = 511;
3200 int dir_fd = DEFAULT_DIR_FD;
3201 int _return_value;
3202
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003203 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|i$O&:open", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003204 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd))
3205 goto exit;
3206 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
3207 if ((_return_value == -1) && PyErr_Occurred())
3208 goto exit;
3209 return_value = PyLong_FromLong((long)_return_value);
3210
3211exit:
3212 /* Cleanup for path */
3213 path_cleanup(&path);
3214
3215 return return_value;
3216}
3217
3218PyDoc_STRVAR(os_close__doc__,
3219"close($module, /, fd)\n"
3220"--\n"
3221"\n"
3222"Close a file descriptor.");
3223
3224#define OS_CLOSE_METHODDEF \
3225 {"close", (PyCFunction)os_close, METH_VARARGS|METH_KEYWORDS, os_close__doc__},
3226
3227static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003228os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003229
3230static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003231os_close(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003232{
3233 PyObject *return_value = NULL;
3234 static char *_keywords[] = {"fd", NULL};
3235 int fd;
3236
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003237 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:close", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003238 &fd))
3239 goto exit;
3240 return_value = os_close_impl(module, fd);
3241
3242exit:
3243 return return_value;
3244}
3245
3246PyDoc_STRVAR(os_closerange__doc__,
3247"closerange($module, fd_low, fd_high, /)\n"
3248"--\n"
3249"\n"
3250"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3251
3252#define OS_CLOSERANGE_METHODDEF \
3253 {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
3254
3255static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003256os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003257
3258static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003259os_closerange(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003260{
3261 PyObject *return_value = NULL;
3262 int fd_low;
3263 int fd_high;
3264
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003265 if (!PyArg_ParseTuple(args, "ii:closerange",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003266 &fd_low, &fd_high))
3267 goto exit;
3268 return_value = os_closerange_impl(module, fd_low, fd_high);
3269
3270exit:
3271 return return_value;
3272}
3273
3274PyDoc_STRVAR(os_dup__doc__,
3275"dup($module, fd, /)\n"
3276"--\n"
3277"\n"
3278"Return a duplicate of a file descriptor.");
3279
3280#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003281 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003282
3283static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003284os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285
3286static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003287os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003288{
3289 PyObject *return_value = NULL;
3290 int fd;
3291 int _return_value;
3292
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003293 if (!PyArg_Parse(arg, "i:dup", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003294 goto exit;
3295 _return_value = os_dup_impl(module, fd);
3296 if ((_return_value == -1) && PyErr_Occurred())
3297 goto exit;
3298 return_value = PyLong_FromLong((long)_return_value);
3299
3300exit:
3301 return return_value;
3302}
3303
3304PyDoc_STRVAR(os_dup2__doc__,
3305"dup2($module, /, fd, fd2, inheritable=True)\n"
3306"--\n"
3307"\n"
3308"Duplicate file descriptor.");
3309
3310#define OS_DUP2_METHODDEF \
3311 {"dup2", (PyCFunction)os_dup2, METH_VARARGS|METH_KEYWORDS, os_dup2__doc__},
3312
3313static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003314os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003315
3316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003317os_dup2(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003318{
3319 PyObject *return_value = NULL;
3320 static char *_keywords[] = {"fd", "fd2", "inheritable", NULL};
3321 int fd;
3322 int fd2;
3323 int inheritable = 1;
3324
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003325 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|p:dup2", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326 &fd, &fd2, &inheritable))
3327 goto exit;
3328 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3329
3330exit:
3331 return return_value;
3332}
3333
3334#if defined(HAVE_LOCKF)
3335
3336PyDoc_STRVAR(os_lockf__doc__,
3337"lockf($module, fd, command, length, /)\n"
3338"--\n"
3339"\n"
3340"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3341"\n"
3342" fd\n"
3343" An open file descriptor.\n"
3344" command\n"
3345" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3346" length\n"
3347" The number of bytes to lock, starting at the current position.");
3348
3349#define OS_LOCKF_METHODDEF \
3350 {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
3351
3352static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003353os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003354
3355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003356os_lockf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003357{
3358 PyObject *return_value = NULL;
3359 int fd;
3360 int command;
3361 Py_off_t length;
3362
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003363 if (!PyArg_ParseTuple(args, "iiO&:lockf",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003364 &fd, &command, Py_off_t_converter, &length))
3365 goto exit;
3366 return_value = os_lockf_impl(module, fd, command, length);
3367
3368exit:
3369 return return_value;
3370}
3371
3372#endif /* defined(HAVE_LOCKF) */
3373
3374PyDoc_STRVAR(os_lseek__doc__,
3375"lseek($module, fd, position, how, /)\n"
3376"--\n"
3377"\n"
3378"Set the position of a file descriptor. Return the new position.\n"
3379"\n"
3380"Return the new cursor position in number of bytes\n"
3381"relative to the beginning of the file.");
3382
3383#define OS_LSEEK_METHODDEF \
3384 {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
3385
3386static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003387os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003388
3389static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003390os_lseek(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003391{
3392 PyObject *return_value = NULL;
3393 int fd;
3394 Py_off_t position;
3395 int how;
3396 Py_off_t _return_value;
3397
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003398 if (!PyArg_ParseTuple(args, "iO&i:lseek",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003399 &fd, Py_off_t_converter, &position, &how))
3400 goto exit;
3401 _return_value = os_lseek_impl(module, fd, position, how);
3402 if ((_return_value == -1) && PyErr_Occurred())
3403 goto exit;
3404 return_value = PyLong_FromPy_off_t(_return_value);
3405
3406exit:
3407 return return_value;
3408}
3409
3410PyDoc_STRVAR(os_read__doc__,
3411"read($module, fd, length, /)\n"
3412"--\n"
3413"\n"
3414"Read from a file descriptor. Returns a bytes object.");
3415
3416#define OS_READ_METHODDEF \
3417 {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
3418
3419static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003420os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003421
3422static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003423os_read(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003424{
3425 PyObject *return_value = NULL;
3426 int fd;
3427 Py_ssize_t length;
3428
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003429 if (!PyArg_ParseTuple(args, "in:read",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003430 &fd, &length))
3431 goto exit;
3432 return_value = os_read_impl(module, fd, length);
3433
3434exit:
3435 return return_value;
3436}
3437
3438#if defined(HAVE_READV)
3439
3440PyDoc_STRVAR(os_readv__doc__,
3441"readv($module, fd, buffers, /)\n"
3442"--\n"
3443"\n"
3444"Read from a file descriptor fd into an iterable of buffers.\n"
3445"\n"
3446"The buffers should be mutable buffers accepting bytes.\n"
3447"readv will transfer data into each buffer until it is full\n"
3448"and then move on to the next buffer in the sequence to hold\n"
3449"the rest of the data.\n"
3450"\n"
3451"readv returns the total number of bytes read,\n"
3452"which may be less than the total capacity of all the buffers.");
3453
3454#define OS_READV_METHODDEF \
3455 {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
3456
3457static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003458os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003459
3460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003461os_readv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003462{
3463 PyObject *return_value = NULL;
3464 int fd;
3465 PyObject *buffers;
3466 Py_ssize_t _return_value;
3467
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003468 if (!PyArg_ParseTuple(args, "iO:readv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003469 &fd, &buffers))
3470 goto exit;
3471 _return_value = os_readv_impl(module, fd, buffers);
3472 if ((_return_value == -1) && PyErr_Occurred())
3473 goto exit;
3474 return_value = PyLong_FromSsize_t(_return_value);
3475
3476exit:
3477 return return_value;
3478}
3479
3480#endif /* defined(HAVE_READV) */
3481
3482#if defined(HAVE_PREAD)
3483
3484PyDoc_STRVAR(os_pread__doc__,
3485"pread($module, fd, length, offset, /)\n"
3486"--\n"
3487"\n"
3488"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3489"\n"
3490"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3491"the beginning of the file. The file offset remains unchanged.");
3492
3493#define OS_PREAD_METHODDEF \
3494 {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
3495
3496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003497os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003498
3499static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003500os_pread(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003501{
3502 PyObject *return_value = NULL;
3503 int fd;
3504 int length;
3505 Py_off_t offset;
3506
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003507 if (!PyArg_ParseTuple(args, "iiO&:pread",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003508 &fd, &length, Py_off_t_converter, &offset))
3509 goto exit;
3510 return_value = os_pread_impl(module, fd, length, offset);
3511
3512exit:
3513 return return_value;
3514}
3515
3516#endif /* defined(HAVE_PREAD) */
3517
3518PyDoc_STRVAR(os_write__doc__,
3519"write($module, fd, data, /)\n"
3520"--\n"
3521"\n"
3522"Write a bytes object to a file descriptor.");
3523
3524#define OS_WRITE_METHODDEF \
3525 {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
3526
3527static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003528os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003529
3530static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003531os_write(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003532{
3533 PyObject *return_value = NULL;
3534 int fd;
3535 Py_buffer data = {NULL, NULL};
3536 Py_ssize_t _return_value;
3537
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003538 if (!PyArg_ParseTuple(args, "iy*:write",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003539 &fd, &data))
3540 goto exit;
3541 _return_value = os_write_impl(module, fd, &data);
3542 if ((_return_value == -1) && PyErr_Occurred())
3543 goto exit;
3544 return_value = PyLong_FromSsize_t(_return_value);
3545
3546exit:
3547 /* Cleanup for data */
3548 if (data.obj)
3549 PyBuffer_Release(&data);
3550
3551 return return_value;
3552}
3553
3554PyDoc_STRVAR(os_fstat__doc__,
3555"fstat($module, /, fd)\n"
3556"--\n"
3557"\n"
3558"Perform a stat system call on the given file descriptor.\n"
3559"\n"
3560"Like stat(), but for an open file descriptor.\n"
3561"Equivalent to os.stat(fd).");
3562
3563#define OS_FSTAT_METHODDEF \
3564 {"fstat", (PyCFunction)os_fstat, METH_VARARGS|METH_KEYWORDS, os_fstat__doc__},
3565
3566static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003567os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003568
3569static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003570os_fstat(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003571{
3572 PyObject *return_value = NULL;
3573 static char *_keywords[] = {"fd", NULL};
3574 int fd;
3575
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003576 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:fstat", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003577 &fd))
3578 goto exit;
3579 return_value = os_fstat_impl(module, fd);
3580
3581exit:
3582 return return_value;
3583}
3584
3585PyDoc_STRVAR(os_isatty__doc__,
3586"isatty($module, fd, /)\n"
3587"--\n"
3588"\n"
3589"Return True if the fd is connected to a terminal.\n"
3590"\n"
3591"Return True if the file descriptor is an open file descriptor\n"
3592"connected to the slave end of a terminal.");
3593
3594#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003595 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003596
3597static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003598os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003599
3600static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003601os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003602{
3603 PyObject *return_value = NULL;
3604 int fd;
3605 int _return_value;
3606
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003607 if (!PyArg_Parse(arg, "i:isatty", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003608 goto exit;
3609 _return_value = os_isatty_impl(module, fd);
3610 if ((_return_value == -1) && PyErr_Occurred())
3611 goto exit;
3612 return_value = PyBool_FromLong((long)_return_value);
3613
3614exit:
3615 return return_value;
3616}
3617
3618#if defined(HAVE_PIPE)
3619
3620PyDoc_STRVAR(os_pipe__doc__,
3621"pipe($module, /)\n"
3622"--\n"
3623"\n"
3624"Create a pipe.\n"
3625"\n"
3626"Returns a tuple of two file descriptors:\n"
3627" (read_fd, write_fd)");
3628
3629#define OS_PIPE_METHODDEF \
3630 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3631
3632static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003633os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003634
3635static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003636os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003637{
3638 return os_pipe_impl(module);
3639}
3640
3641#endif /* defined(HAVE_PIPE) */
3642
3643#if defined(HAVE_PIPE2)
3644
3645PyDoc_STRVAR(os_pipe2__doc__,
3646"pipe2($module, flags, /)\n"
3647"--\n"
3648"\n"
3649"Create a pipe with flags set atomically.\n"
3650"\n"
3651"Returns a tuple of two file descriptors:\n"
3652" (read_fd, write_fd)\n"
3653"\n"
3654"flags can be constructed by ORing together one or more of these values:\n"
3655"O_NONBLOCK, O_CLOEXEC.");
3656
3657#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003658 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003659
3660static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003661os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003662
3663static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003664os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003665{
3666 PyObject *return_value = NULL;
3667 int flags;
3668
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003669 if (!PyArg_Parse(arg, "i:pipe2", &flags))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003670 goto exit;
3671 return_value = os_pipe2_impl(module, flags);
3672
3673exit:
3674 return return_value;
3675}
3676
3677#endif /* defined(HAVE_PIPE2) */
3678
3679#if defined(HAVE_WRITEV)
3680
3681PyDoc_STRVAR(os_writev__doc__,
3682"writev($module, fd, buffers, /)\n"
3683"--\n"
3684"\n"
3685"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3686"\n"
3687"Returns the total number of bytes written.\n"
3688"buffers must be a sequence of bytes-like objects.");
3689
3690#define OS_WRITEV_METHODDEF \
3691 {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
3692
3693static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003694os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003695
3696static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003697os_writev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003698{
3699 PyObject *return_value = NULL;
3700 int fd;
3701 PyObject *buffers;
3702 Py_ssize_t _return_value;
3703
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003704 if (!PyArg_ParseTuple(args, "iO:writev",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003705 &fd, &buffers))
3706 goto exit;
3707 _return_value = os_writev_impl(module, fd, buffers);
3708 if ((_return_value == -1) && PyErr_Occurred())
3709 goto exit;
3710 return_value = PyLong_FromSsize_t(_return_value);
3711
3712exit:
3713 return return_value;
3714}
3715
3716#endif /* defined(HAVE_WRITEV) */
3717
3718#if defined(HAVE_PWRITE)
3719
3720PyDoc_STRVAR(os_pwrite__doc__,
3721"pwrite($module, fd, buffer, offset, /)\n"
3722"--\n"
3723"\n"
3724"Write bytes to a file descriptor starting at a particular offset.\n"
3725"\n"
3726"Write buffer to fd, starting at offset bytes from the beginning of\n"
3727"the file. Returns the number of bytes writte. Does not change the\n"
3728"current file offset.");
3729
3730#define OS_PWRITE_METHODDEF \
3731 {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
3732
3733static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003734os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003735
3736static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003737os_pwrite(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738{
3739 PyObject *return_value = NULL;
3740 int fd;
3741 Py_buffer buffer = {NULL, NULL};
3742 Py_off_t offset;
3743 Py_ssize_t _return_value;
3744
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003745 if (!PyArg_ParseTuple(args, "iy*O&:pwrite",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003746 &fd, &buffer, Py_off_t_converter, &offset))
3747 goto exit;
3748 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
3749 if ((_return_value == -1) && PyErr_Occurred())
3750 goto exit;
3751 return_value = PyLong_FromSsize_t(_return_value);
3752
3753exit:
3754 /* Cleanup for buffer */
3755 if (buffer.obj)
3756 PyBuffer_Release(&buffer);
3757
3758 return return_value;
3759}
3760
3761#endif /* defined(HAVE_PWRITE) */
3762
3763#if defined(HAVE_MKFIFO)
3764
3765PyDoc_STRVAR(os_mkfifo__doc__,
3766"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3767"--\n"
3768"\n"
3769"Create a \"fifo\" (a POSIX named pipe).\n"
3770"\n"
3771"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3772" and path should be relative; path will then be relative to that directory.\n"
3773"dir_fd may not be implemented on your platform.\n"
3774" If it is unavailable, using it will raise a NotImplementedError.");
3775
3776#define OS_MKFIFO_METHODDEF \
3777 {"mkfifo", (PyCFunction)os_mkfifo, METH_VARARGS|METH_KEYWORDS, os_mkfifo__doc__},
3778
3779static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003780os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003781
3782static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003783os_mkfifo(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003784{
3785 PyObject *return_value = NULL;
3786 static char *_keywords[] = {"path", "mode", "dir_fd", NULL};
3787 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3788 int mode = 438;
3789 int dir_fd = DEFAULT_DIR_FD;
3790
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003791 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkfifo", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003792 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd))
3793 goto exit;
3794 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3795
3796exit:
3797 /* Cleanup for path */
3798 path_cleanup(&path);
3799
3800 return return_value;
3801}
3802
3803#endif /* defined(HAVE_MKFIFO) */
3804
3805#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
3806
3807PyDoc_STRVAR(os_mknod__doc__,
3808"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
3809"--\n"
3810"\n"
3811"Create a node in the file system.\n"
3812"\n"
3813"Create a node in the file system (file, device special file or named pipe)\n"
3814"at path. mode specifies both the permissions to use and the\n"
3815"type of node to be created, being combined (bitwise OR) with one of\n"
3816"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
3817"device defines the newly created device special file (probably using\n"
3818"os.makedev()). Otherwise device is ignored.\n"
3819"\n"
3820"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3821" and path should be relative; path will then be relative to that directory.\n"
3822"dir_fd may not be implemented on your platform.\n"
3823" If it is unavailable, using it will raise a NotImplementedError.");
3824
3825#define OS_MKNOD_METHODDEF \
3826 {"mknod", (PyCFunction)os_mknod, METH_VARARGS|METH_KEYWORDS, os_mknod__doc__},
3827
3828static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003829os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04003830 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003831
3832static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003833os_mknod(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003834{
3835 PyObject *return_value = NULL;
3836 static char *_keywords[] = {"path", "mode", "device", "dir_fd", NULL};
3837 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
3838 int mode = 384;
3839 dev_t device = 0;
3840 int dir_fd = DEFAULT_DIR_FD;
3841
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003842 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|iO&$O&:mknod", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003843 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd))
3844 goto exit;
3845 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
3846
3847exit:
3848 /* Cleanup for path */
3849 path_cleanup(&path);
3850
3851 return return_value;
3852}
3853
3854#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
3855
3856#if defined(HAVE_DEVICE_MACROS)
3857
3858PyDoc_STRVAR(os_major__doc__,
3859"major($module, device, /)\n"
3860"--\n"
3861"\n"
3862"Extracts a device major number from a raw device number.");
3863
3864#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003865 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003866
3867static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003868os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003869
3870static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003871os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003872{
3873 PyObject *return_value = NULL;
3874 dev_t device;
3875 unsigned int _return_value;
3876
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003877 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003878 goto exit;
3879 _return_value = os_major_impl(module, device);
3880 if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
3881 goto exit;
3882 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
3883
3884exit:
3885 return return_value;
3886}
3887
3888#endif /* defined(HAVE_DEVICE_MACROS) */
3889
3890#if defined(HAVE_DEVICE_MACROS)
3891
3892PyDoc_STRVAR(os_minor__doc__,
3893"minor($module, device, /)\n"
3894"--\n"
3895"\n"
3896"Extracts a device minor number from a raw device number.");
3897
3898#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003899 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003900
3901static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003902os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003903
3904static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003905os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003906{
3907 PyObject *return_value = NULL;
3908 dev_t device;
3909 unsigned int _return_value;
3910
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003911 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003912 goto exit;
3913 _return_value = os_minor_impl(module, device);
3914 if ((_return_value == (unsigned int)-1) && PyErr_Occurred())
3915 goto exit;
3916 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
3917
3918exit:
3919 return return_value;
3920}
3921
3922#endif /* defined(HAVE_DEVICE_MACROS) */
3923
3924#if defined(HAVE_DEVICE_MACROS)
3925
3926PyDoc_STRVAR(os_makedev__doc__,
3927"makedev($module, major, minor, /)\n"
3928"--\n"
3929"\n"
3930"Composes a raw device number from the major and minor device numbers.");
3931
3932#define OS_MAKEDEV_METHODDEF \
3933 {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
3934
3935static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003936os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003937
3938static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003939os_makedev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003940{
3941 PyObject *return_value = NULL;
3942 int major;
3943 int minor;
3944 dev_t _return_value;
3945
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003946 if (!PyArg_ParseTuple(args, "ii:makedev",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003947 &major, &minor))
3948 goto exit;
3949 _return_value = os_makedev_impl(module, major, minor);
3950 if ((_return_value == (dev_t)-1) && PyErr_Occurred())
3951 goto exit;
3952 return_value = _PyLong_FromDev(_return_value);
3953
3954exit:
3955 return return_value;
3956}
3957
3958#endif /* defined(HAVE_DEVICE_MACROS) */
3959
Steve Dowerf7377032015-04-12 15:44:54 -04003960#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003961
3962PyDoc_STRVAR(os_ftruncate__doc__,
3963"ftruncate($module, fd, length, /)\n"
3964"--\n"
3965"\n"
3966"Truncate a file, specified by file descriptor, to a specific length.");
3967
3968#define OS_FTRUNCATE_METHODDEF \
3969 {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
3970
3971static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003972os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003973
3974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003975os_ftruncate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976{
3977 PyObject *return_value = NULL;
3978 int fd;
3979 Py_off_t length;
3980
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003981 if (!PyArg_ParseTuple(args, "iO&:ftruncate",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003982 &fd, Py_off_t_converter, &length))
3983 goto exit;
3984 return_value = os_ftruncate_impl(module, fd, length);
3985
3986exit:
3987 return return_value;
3988}
3989
Steve Dowerf7377032015-04-12 15:44:54 -04003990#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003991
Steve Dowerf7377032015-04-12 15:44:54 -04003992#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003993
3994PyDoc_STRVAR(os_truncate__doc__,
3995"truncate($module, /, path, length)\n"
3996"--\n"
3997"\n"
3998"Truncate a file, specified by path, to a specific length.\n"
3999"\n"
4000"On some platforms, path may also be specified as an open file descriptor.\n"
4001" If this functionality is unavailable, using it raises an exception.");
4002
4003#define OS_TRUNCATE_METHODDEF \
4004 {"truncate", (PyCFunction)os_truncate, METH_VARARGS|METH_KEYWORDS, os_truncate__doc__},
4005
4006static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004007os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004008
4009static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004010os_truncate(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004011{
4012 PyObject *return_value = NULL;
4013 static char *_keywords[] = {"path", "length", NULL};
4014 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4015 Py_off_t length;
4016
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004017 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:truncate", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004018 path_converter, &path, Py_off_t_converter, &length))
4019 goto exit;
4020 return_value = os_truncate_impl(module, &path, length);
4021
4022exit:
4023 /* Cleanup for path */
4024 path_cleanup(&path);
4025
4026 return return_value;
4027}
4028
Steve Dowerf7377032015-04-12 15:44:54 -04004029#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004030
4031#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4032
4033PyDoc_STRVAR(os_posix_fallocate__doc__,
4034"posix_fallocate($module, fd, offset, length, /)\n"
4035"--\n"
4036"\n"
4037"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4038"\n"
4039"Ensure that the file specified by fd encompasses a range of bytes\n"
4040"starting at offset bytes from the beginning and continuing for length bytes.");
4041
4042#define OS_POSIX_FALLOCATE_METHODDEF \
4043 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
4044
4045static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004046os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004047 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004048
4049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004050os_posix_fallocate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004051{
4052 PyObject *return_value = NULL;
4053 int fd;
4054 Py_off_t offset;
4055 Py_off_t length;
4056
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004057 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004058 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length))
4059 goto exit;
4060 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4061
4062exit:
4063 return return_value;
4064}
4065
4066#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4067
4068#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4069
4070PyDoc_STRVAR(os_posix_fadvise__doc__,
4071"posix_fadvise($module, fd, offset, length, advice, /)\n"
4072"--\n"
4073"\n"
4074"Announce an intention to access data in a specific pattern.\n"
4075"\n"
4076"Announce an intention to access data in a specific pattern, thus allowing\n"
4077"the kernel to make optimizations.\n"
4078"The advice applies to the region of the file specified by fd starting at\n"
4079"offset and continuing for length bytes.\n"
4080"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4081"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4082"POSIX_FADV_DONTNEED.");
4083
4084#define OS_POSIX_FADVISE_METHODDEF \
4085 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
4086
4087static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004088os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004089 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004090
4091static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004092os_posix_fadvise(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004093{
4094 PyObject *return_value = NULL;
4095 int fd;
4096 Py_off_t offset;
4097 Py_off_t length;
4098 int advice;
4099
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004100 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004101 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice))
4102 goto exit;
4103 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4104
4105exit:
4106 return return_value;
4107}
4108
4109#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4110
4111#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4112
4113PyDoc_STRVAR(os_putenv__doc__,
4114"putenv($module, name, value, /)\n"
4115"--\n"
4116"\n"
4117"Change or add an environment variable.");
4118
4119#define OS_PUTENV_METHODDEF \
4120 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4121
4122static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004123os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004124
4125static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004126os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004127{
4128 PyObject *return_value = NULL;
4129 PyObject *name;
4130 PyObject *value;
4131
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004132 if (!PyArg_ParseTuple(args, "UU:putenv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004133 &name, &value))
4134 goto exit;
4135 return_value = os_putenv_impl(module, name, value);
4136
4137exit:
4138 return return_value;
4139}
4140
4141#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4142
4143#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4144
4145PyDoc_STRVAR(os_putenv__doc__,
4146"putenv($module, name, value, /)\n"
4147"--\n"
4148"\n"
4149"Change or add an environment variable.");
4150
4151#define OS_PUTENV_METHODDEF \
4152 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4153
4154static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004155os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004156
4157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004158os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004159{
4160 PyObject *return_value = NULL;
4161 PyObject *name = NULL;
4162 PyObject *value = NULL;
4163
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004164 if (!PyArg_ParseTuple(args, "O&O&:putenv",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004165 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value))
4166 goto exit;
4167 return_value = os_putenv_impl(module, name, value);
4168
4169exit:
4170 /* Cleanup for name */
4171 Py_XDECREF(name);
4172 /* Cleanup for value */
4173 Py_XDECREF(value);
4174
4175 return return_value;
4176}
4177
4178#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4179
4180#if defined(HAVE_UNSETENV)
4181
4182PyDoc_STRVAR(os_unsetenv__doc__,
4183"unsetenv($module, name, /)\n"
4184"--\n"
4185"\n"
4186"Delete an environment variable.");
4187
4188#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004189 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004190
4191static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004192os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004193
4194static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004195os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004196{
4197 PyObject *return_value = NULL;
4198 PyObject *name = NULL;
4199
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004200 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004201 goto exit;
4202 return_value = os_unsetenv_impl(module, name);
4203
4204exit:
4205 /* Cleanup for name */
4206 Py_XDECREF(name);
4207
4208 return return_value;
4209}
4210
4211#endif /* defined(HAVE_UNSETENV) */
4212
4213PyDoc_STRVAR(os_strerror__doc__,
4214"strerror($module, code, /)\n"
4215"--\n"
4216"\n"
4217"Translate an error code to a message string.");
4218
4219#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004220 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004221
4222static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004223os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004224
4225static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004226os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004227{
4228 PyObject *return_value = NULL;
4229 int code;
4230
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004231 if (!PyArg_Parse(arg, "i:strerror", &code))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004232 goto exit;
4233 return_value = os_strerror_impl(module, code);
4234
4235exit:
4236 return return_value;
4237}
4238
4239#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4240
4241PyDoc_STRVAR(os_WCOREDUMP__doc__,
4242"WCOREDUMP($module, status, /)\n"
4243"--\n"
4244"\n"
4245"Return True if the process returning status was dumped to a core file.");
4246
4247#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004248 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004249
4250static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004251os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004252
4253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004254os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004255{
4256 PyObject *return_value = NULL;
4257 int status;
4258 int _return_value;
4259
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004260 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004261 goto exit;
4262 _return_value = os_WCOREDUMP_impl(module, status);
4263 if ((_return_value == -1) && PyErr_Occurred())
4264 goto exit;
4265 return_value = PyBool_FromLong((long)_return_value);
4266
4267exit:
4268 return return_value;
4269}
4270
4271#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4272
4273#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4274
4275PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4276"WIFCONTINUED($module, /, status)\n"
4277"--\n"
4278"\n"
4279"Return True if a particular process was continued from a job control stop.\n"
4280"\n"
4281"Return True if the process returning status was continued from a\n"
4282"job control stop.");
4283
4284#define OS_WIFCONTINUED_METHODDEF \
4285 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_VARARGS|METH_KEYWORDS, os_WIFCONTINUED__doc__},
4286
4287static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004288os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004289
4290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004291os_WIFCONTINUED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004292{
4293 PyObject *return_value = NULL;
4294 static char *_keywords[] = {"status", NULL};
4295 int status;
4296 int _return_value;
4297
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004298 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFCONTINUED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004299 &status))
4300 goto exit;
4301 _return_value = os_WIFCONTINUED_impl(module, status);
4302 if ((_return_value == -1) && PyErr_Occurred())
4303 goto exit;
4304 return_value = PyBool_FromLong((long)_return_value);
4305
4306exit:
4307 return return_value;
4308}
4309
4310#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4311
4312#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4313
4314PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4315"WIFSTOPPED($module, /, status)\n"
4316"--\n"
4317"\n"
4318"Return True if the process returning status was stopped.");
4319
4320#define OS_WIFSTOPPED_METHODDEF \
4321 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_VARARGS|METH_KEYWORDS, os_WIFSTOPPED__doc__},
4322
4323static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004324os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004325
4326static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004327os_WIFSTOPPED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004328{
4329 PyObject *return_value = NULL;
4330 static char *_keywords[] = {"status", NULL};
4331 int status;
4332 int _return_value;
4333
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004334 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFSTOPPED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004335 &status))
4336 goto exit;
4337 _return_value = os_WIFSTOPPED_impl(module, status);
4338 if ((_return_value == -1) && PyErr_Occurred())
4339 goto exit;
4340 return_value = PyBool_FromLong((long)_return_value);
4341
4342exit:
4343 return return_value;
4344}
4345
4346#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4347
4348#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4349
4350PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4351"WIFSIGNALED($module, /, status)\n"
4352"--\n"
4353"\n"
4354"Return True if the process returning status was terminated by a signal.");
4355
4356#define OS_WIFSIGNALED_METHODDEF \
4357 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_VARARGS|METH_KEYWORDS, os_WIFSIGNALED__doc__},
4358
4359static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004360os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004361
4362static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004363os_WIFSIGNALED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364{
4365 PyObject *return_value = NULL;
4366 static char *_keywords[] = {"status", NULL};
4367 int status;
4368 int _return_value;
4369
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004370 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFSIGNALED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004371 &status))
4372 goto exit;
4373 _return_value = os_WIFSIGNALED_impl(module, status);
4374 if ((_return_value == -1) && PyErr_Occurred())
4375 goto exit;
4376 return_value = PyBool_FromLong((long)_return_value);
4377
4378exit:
4379 return return_value;
4380}
4381
4382#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4383
4384#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4385
4386PyDoc_STRVAR(os_WIFEXITED__doc__,
4387"WIFEXITED($module, /, status)\n"
4388"--\n"
4389"\n"
4390"Return True if the process returning status exited via the exit() system call.");
4391
4392#define OS_WIFEXITED_METHODDEF \
4393 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_VARARGS|METH_KEYWORDS, os_WIFEXITED__doc__},
4394
4395static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004396os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004397
4398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004399os_WIFEXITED(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004400{
4401 PyObject *return_value = NULL;
4402 static char *_keywords[] = {"status", NULL};
4403 int status;
4404 int _return_value;
4405
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004406 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WIFEXITED", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004407 &status))
4408 goto exit;
4409 _return_value = os_WIFEXITED_impl(module, status);
4410 if ((_return_value == -1) && PyErr_Occurred())
4411 goto exit;
4412 return_value = PyBool_FromLong((long)_return_value);
4413
4414exit:
4415 return return_value;
4416}
4417
4418#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4419
4420#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4421
4422PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4423"WEXITSTATUS($module, /, status)\n"
4424"--\n"
4425"\n"
4426"Return the process return code from status.");
4427
4428#define OS_WEXITSTATUS_METHODDEF \
4429 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_VARARGS|METH_KEYWORDS, os_WEXITSTATUS__doc__},
4430
4431static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004432os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004433
4434static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004435os_WEXITSTATUS(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004436{
4437 PyObject *return_value = NULL;
4438 static char *_keywords[] = {"status", NULL};
4439 int status;
4440 int _return_value;
4441
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004442 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WEXITSTATUS", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004443 &status))
4444 goto exit;
4445 _return_value = os_WEXITSTATUS_impl(module, status);
4446 if ((_return_value == -1) && PyErr_Occurred())
4447 goto exit;
4448 return_value = PyLong_FromLong((long)_return_value);
4449
4450exit:
4451 return return_value;
4452}
4453
4454#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4455
4456#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4457
4458PyDoc_STRVAR(os_WTERMSIG__doc__,
4459"WTERMSIG($module, /, status)\n"
4460"--\n"
4461"\n"
4462"Return the signal that terminated the process that provided the status value.");
4463
4464#define OS_WTERMSIG_METHODDEF \
4465 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_VARARGS|METH_KEYWORDS, os_WTERMSIG__doc__},
4466
4467static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004468os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004469
4470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004471os_WTERMSIG(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004472{
4473 PyObject *return_value = NULL;
4474 static char *_keywords[] = {"status", NULL};
4475 int status;
4476 int _return_value;
4477
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004478 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WTERMSIG", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004479 &status))
4480 goto exit;
4481 _return_value = os_WTERMSIG_impl(module, status);
4482 if ((_return_value == -1) && PyErr_Occurred())
4483 goto exit;
4484 return_value = PyLong_FromLong((long)_return_value);
4485
4486exit:
4487 return return_value;
4488}
4489
4490#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4491
4492#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4493
4494PyDoc_STRVAR(os_WSTOPSIG__doc__,
4495"WSTOPSIG($module, /, status)\n"
4496"--\n"
4497"\n"
4498"Return the signal that stopped the process that provided the status value.");
4499
4500#define OS_WSTOPSIG_METHODDEF \
4501 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_VARARGS|METH_KEYWORDS, os_WSTOPSIG__doc__},
4502
4503static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004504os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004505
4506static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004507os_WSTOPSIG(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004508{
4509 PyObject *return_value = NULL;
4510 static char *_keywords[] = {"status", NULL};
4511 int status;
4512 int _return_value;
4513
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004514 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:WSTOPSIG", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004515 &status))
4516 goto exit;
4517 _return_value = os_WSTOPSIG_impl(module, status);
4518 if ((_return_value == -1) && PyErr_Occurred())
4519 goto exit;
4520 return_value = PyLong_FromLong((long)_return_value);
4521
4522exit:
4523 return return_value;
4524}
4525
4526#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4527
4528#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4529
4530PyDoc_STRVAR(os_fstatvfs__doc__,
4531"fstatvfs($module, fd, /)\n"
4532"--\n"
4533"\n"
4534"Perform an fstatvfs system call on the given fd.\n"
4535"\n"
4536"Equivalent to statvfs(fd).");
4537
4538#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004539 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004540
4541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004542os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004543
4544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004545os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004546{
4547 PyObject *return_value = NULL;
4548 int fd;
4549
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004550 if (!PyArg_Parse(arg, "i:fstatvfs", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004551 goto exit;
4552 return_value = os_fstatvfs_impl(module, fd);
4553
4554exit:
4555 return return_value;
4556}
4557
4558#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4559
4560#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4561
4562PyDoc_STRVAR(os_statvfs__doc__,
4563"statvfs($module, /, path)\n"
4564"--\n"
4565"\n"
4566"Perform a statvfs system call on the given path.\n"
4567"\n"
4568"path may always be specified as a string.\n"
4569"On some platforms, path may also be specified as an open file descriptor.\n"
4570" If this functionality is unavailable, using it raises an exception.");
4571
4572#define OS_STATVFS_METHODDEF \
4573 {"statvfs", (PyCFunction)os_statvfs, METH_VARARGS|METH_KEYWORDS, os_statvfs__doc__},
4574
4575static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004576os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004577
4578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004579os_statvfs(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004580{
4581 PyObject *return_value = NULL;
4582 static char *_keywords[] = {"path", NULL};
4583 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4584
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004585 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:statvfs", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004586 path_converter, &path))
4587 goto exit;
4588 return_value = os_statvfs_impl(module, &path);
4589
4590exit:
4591 /* Cleanup for path */
4592 path_cleanup(&path);
4593
4594 return return_value;
4595}
4596
4597#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4598
4599#if defined(MS_WINDOWS)
4600
4601PyDoc_STRVAR(os__getdiskusage__doc__,
4602"_getdiskusage($module, /, path)\n"
4603"--\n"
4604"\n"
4605"Return disk usage statistics about the given path as a (total, free) tuple.");
4606
4607#define OS__GETDISKUSAGE_METHODDEF \
4608 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_VARARGS|METH_KEYWORDS, os__getdiskusage__doc__},
4609
4610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004611os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004612
4613static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004614os__getdiskusage(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004615{
4616 PyObject *return_value = NULL;
4617 static char *_keywords[] = {"path", NULL};
4618 Py_UNICODE *path;
4619
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004620 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "u:_getdiskusage", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004621 &path))
4622 goto exit;
4623 return_value = os__getdiskusage_impl(module, path);
4624
4625exit:
4626 return return_value;
4627}
4628
4629#endif /* defined(MS_WINDOWS) */
4630
4631#if defined(HAVE_FPATHCONF)
4632
4633PyDoc_STRVAR(os_fpathconf__doc__,
4634"fpathconf($module, fd, name, /)\n"
4635"--\n"
4636"\n"
4637"Return the configuration limit name for the file descriptor fd.\n"
4638"\n"
4639"If there is no limit, return -1.");
4640
4641#define OS_FPATHCONF_METHODDEF \
4642 {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
4643
4644static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004645os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004646
4647static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004648os_fpathconf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004649{
4650 PyObject *return_value = NULL;
4651 int fd;
4652 int name;
4653 long _return_value;
4654
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004655 if (!PyArg_ParseTuple(args, "iO&:fpathconf",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004656 &fd, conv_path_confname, &name))
4657 goto exit;
4658 _return_value = os_fpathconf_impl(module, fd, name);
4659 if ((_return_value == -1) && PyErr_Occurred())
4660 goto exit;
4661 return_value = PyLong_FromLong(_return_value);
4662
4663exit:
4664 return return_value;
4665}
4666
4667#endif /* defined(HAVE_FPATHCONF) */
4668
4669#if defined(HAVE_PATHCONF)
4670
4671PyDoc_STRVAR(os_pathconf__doc__,
4672"pathconf($module, /, path, name)\n"
4673"--\n"
4674"\n"
4675"Return the configuration limit name for the file or directory path.\n"
4676"\n"
4677"If there is no limit, return -1.\n"
4678"On some platforms, path may also be specified as an open file descriptor.\n"
4679" If this functionality is unavailable, using it raises an exception.");
4680
4681#define OS_PATHCONF_METHODDEF \
4682 {"pathconf", (PyCFunction)os_pathconf, METH_VARARGS|METH_KEYWORDS, os_pathconf__doc__},
4683
4684static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004685os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004686
4687static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004688os_pathconf(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004689{
4690 PyObject *return_value = NULL;
4691 static char *_keywords[] = {"path", "name", NULL};
4692 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4693 int name;
4694 long _return_value;
4695
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004696 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:pathconf", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004697 path_converter, &path, conv_path_confname, &name))
4698 goto exit;
4699 _return_value = os_pathconf_impl(module, &path, name);
4700 if ((_return_value == -1) && PyErr_Occurred())
4701 goto exit;
4702 return_value = PyLong_FromLong(_return_value);
4703
4704exit:
4705 /* Cleanup for path */
4706 path_cleanup(&path);
4707
4708 return return_value;
4709}
4710
4711#endif /* defined(HAVE_PATHCONF) */
4712
4713#if defined(HAVE_CONFSTR)
4714
4715PyDoc_STRVAR(os_confstr__doc__,
4716"confstr($module, name, /)\n"
4717"--\n"
4718"\n"
4719"Return a string-valued system configuration variable.");
4720
4721#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004722 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004723
4724static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004725os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004726
4727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004728os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004729{
4730 PyObject *return_value = NULL;
4731 int name;
4732
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004733 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004734 goto exit;
4735 return_value = os_confstr_impl(module, name);
4736
4737exit:
4738 return return_value;
4739}
4740
4741#endif /* defined(HAVE_CONFSTR) */
4742
4743#if defined(HAVE_SYSCONF)
4744
4745PyDoc_STRVAR(os_sysconf__doc__,
4746"sysconf($module, name, /)\n"
4747"--\n"
4748"\n"
4749"Return an integer-valued system configuration variable.");
4750
4751#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004752 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004753
4754static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004755os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004756
4757static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004758os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004759{
4760 PyObject *return_value = NULL;
4761 int name;
4762 long _return_value;
4763
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004764 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004765 goto exit;
4766 _return_value = os_sysconf_impl(module, name);
4767 if ((_return_value == -1) && PyErr_Occurred())
4768 goto exit;
4769 return_value = PyLong_FromLong(_return_value);
4770
4771exit:
4772 return return_value;
4773}
4774
4775#endif /* defined(HAVE_SYSCONF) */
4776
4777PyDoc_STRVAR(os_abort__doc__,
4778"abort($module, /)\n"
4779"--\n"
4780"\n"
4781"Abort the interpreter immediately.\n"
4782"\n"
4783"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
4784"on the hosting operating system. This function never returns.");
4785
4786#define OS_ABORT_METHODDEF \
4787 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
4788
4789static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004790os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791
4792static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004793os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004794{
4795 return os_abort_impl(module);
4796}
4797
4798#if defined(HAVE_GETLOADAVG)
4799
4800PyDoc_STRVAR(os_getloadavg__doc__,
4801"getloadavg($module, /)\n"
4802"--\n"
4803"\n"
4804"Return average recent system load information.\n"
4805"\n"
4806"Return the number of processes in the system run queue averaged over\n"
4807"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
4808"Raises OSError if the load average was unobtainable.");
4809
4810#define OS_GETLOADAVG_METHODDEF \
4811 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
4812
4813static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004814os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004815
4816static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004817os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004818{
4819 return os_getloadavg_impl(module);
4820}
4821
4822#endif /* defined(HAVE_GETLOADAVG) */
4823
4824PyDoc_STRVAR(os_device_encoding__doc__,
4825"device_encoding($module, /, fd)\n"
4826"--\n"
4827"\n"
4828"Return a string describing the encoding of a terminal\'s file descriptor.\n"
4829"\n"
4830"The file descriptor must be attached to a terminal.\n"
4831"If the device is not a terminal, return None.");
4832
4833#define OS_DEVICE_ENCODING_METHODDEF \
4834 {"device_encoding", (PyCFunction)os_device_encoding, METH_VARARGS|METH_KEYWORDS, os_device_encoding__doc__},
4835
4836static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004837os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004838
4839static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004840os_device_encoding(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004841{
4842 PyObject *return_value = NULL;
4843 static char *_keywords[] = {"fd", NULL};
4844 int fd;
4845
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004846 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:device_encoding", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004847 &fd))
4848 goto exit;
4849 return_value = os_device_encoding_impl(module, fd);
4850
4851exit:
4852 return return_value;
4853}
4854
4855#if defined(HAVE_SETRESUID)
4856
4857PyDoc_STRVAR(os_setresuid__doc__,
4858"setresuid($module, ruid, euid, suid, /)\n"
4859"--\n"
4860"\n"
4861"Set the current process\'s real, effective, and saved user ids.");
4862
4863#define OS_SETRESUID_METHODDEF \
4864 {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
4865
4866static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004867os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004868
4869static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004870os_setresuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004871{
4872 PyObject *return_value = NULL;
4873 uid_t ruid;
4874 uid_t euid;
4875 uid_t suid;
4876
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004877 if (!PyArg_ParseTuple(args, "O&O&O&:setresuid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004878 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid))
4879 goto exit;
4880 return_value = os_setresuid_impl(module, ruid, euid, suid);
4881
4882exit:
4883 return return_value;
4884}
4885
4886#endif /* defined(HAVE_SETRESUID) */
4887
4888#if defined(HAVE_SETRESGID)
4889
4890PyDoc_STRVAR(os_setresgid__doc__,
4891"setresgid($module, rgid, egid, sgid, /)\n"
4892"--\n"
4893"\n"
4894"Set the current process\'s real, effective, and saved group ids.");
4895
4896#define OS_SETRESGID_METHODDEF \
4897 {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
4898
4899static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004900os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004901
4902static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004903os_setresgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904{
4905 PyObject *return_value = NULL;
4906 gid_t rgid;
4907 gid_t egid;
4908 gid_t sgid;
4909
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004910 if (!PyArg_ParseTuple(args, "O&O&O&:setresgid",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004911 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid))
4912 goto exit;
4913 return_value = os_setresgid_impl(module, rgid, egid, sgid);
4914
4915exit:
4916 return return_value;
4917}
4918
4919#endif /* defined(HAVE_SETRESGID) */
4920
4921#if defined(HAVE_GETRESUID)
4922
4923PyDoc_STRVAR(os_getresuid__doc__,
4924"getresuid($module, /)\n"
4925"--\n"
4926"\n"
4927"Return a tuple of the current process\'s real, effective, and saved user ids.");
4928
4929#define OS_GETRESUID_METHODDEF \
4930 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
4931
4932static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004933os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004934
4935static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004936os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004937{
4938 return os_getresuid_impl(module);
4939}
4940
4941#endif /* defined(HAVE_GETRESUID) */
4942
4943#if defined(HAVE_GETRESGID)
4944
4945PyDoc_STRVAR(os_getresgid__doc__,
4946"getresgid($module, /)\n"
4947"--\n"
4948"\n"
4949"Return a tuple of the current process\'s real, effective, and saved group ids.");
4950
4951#define OS_GETRESGID_METHODDEF \
4952 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
4953
4954static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004955os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004956
4957static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004958os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004959{
4960 return os_getresgid_impl(module);
4961}
4962
4963#endif /* defined(HAVE_GETRESGID) */
4964
4965#if defined(USE_XATTRS)
4966
4967PyDoc_STRVAR(os_getxattr__doc__,
4968"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
4969"--\n"
4970"\n"
4971"Return the value of extended attribute attribute on path.\n"
4972"\n"
4973"path may be either a string or an open file descriptor.\n"
4974"If follow_symlinks is False, and the last element of the path is a symbolic\n"
4975" link, getxattr will examine the symbolic link itself instead of the file\n"
4976" the link points to.");
4977
4978#define OS_GETXATTR_METHODDEF \
4979 {"getxattr", (PyCFunction)os_getxattr, METH_VARARGS|METH_KEYWORDS, os_getxattr__doc__},
4980
4981static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004982os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04004983 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984
4985static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004986os_getxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004987{
4988 PyObject *return_value = NULL;
4989 static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
4990 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
4991 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
4992 int follow_symlinks = 1;
4993
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004994 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:getxattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004995 path_converter, &path, path_converter, &attribute, &follow_symlinks))
4996 goto exit;
4997 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
4998
4999exit:
5000 /* Cleanup for path */
5001 path_cleanup(&path);
5002 /* Cleanup for attribute */
5003 path_cleanup(&attribute);
5004
5005 return return_value;
5006}
5007
5008#endif /* defined(USE_XATTRS) */
5009
5010#if defined(USE_XATTRS)
5011
5012PyDoc_STRVAR(os_setxattr__doc__,
5013"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5014" follow_symlinks=True)\n"
5015"--\n"
5016"\n"
5017"Set extended attribute attribute on path to value.\n"
5018"\n"
5019"path may be either a string or an open file descriptor.\n"
5020"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5021" link, setxattr will modify the symbolic link itself instead of the file\n"
5022" the link points to.");
5023
5024#define OS_SETXATTR_METHODDEF \
5025 {"setxattr", (PyCFunction)os_setxattr, METH_VARARGS|METH_KEYWORDS, os_setxattr__doc__},
5026
5027static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005028os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005029 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005030
5031static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005032os_setxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005033{
5034 PyObject *return_value = NULL;
5035 static char *_keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5036 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5037 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5038 Py_buffer value = {NULL, NULL};
5039 int flags = 0;
5040 int follow_symlinks = 1;
5041
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005042 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&y*|i$p:setxattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005043 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks))
5044 goto exit;
5045 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5046
5047exit:
5048 /* Cleanup for path */
5049 path_cleanup(&path);
5050 /* Cleanup for attribute */
5051 path_cleanup(&attribute);
5052 /* Cleanup for value */
5053 if (value.obj)
5054 PyBuffer_Release(&value);
5055
5056 return return_value;
5057}
5058
5059#endif /* defined(USE_XATTRS) */
5060
5061#if defined(USE_XATTRS)
5062
5063PyDoc_STRVAR(os_removexattr__doc__,
5064"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5065"--\n"
5066"\n"
5067"Remove extended attribute attribute on path.\n"
5068"\n"
5069"path may be either a string or an open file descriptor.\n"
5070"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5071" link, removexattr will modify the symbolic link itself instead of the file\n"
5072" the link points to.");
5073
5074#define OS_REMOVEXATTR_METHODDEF \
5075 {"removexattr", (PyCFunction)os_removexattr, METH_VARARGS|METH_KEYWORDS, os_removexattr__doc__},
5076
5077static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005078os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005079 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005080
5081static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005082os_removexattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005083{
5084 PyObject *return_value = NULL;
5085 static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5086 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5087 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5088 int follow_symlinks = 1;
5089
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005090 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:removexattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005091 path_converter, &path, path_converter, &attribute, &follow_symlinks))
5092 goto exit;
5093 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5094
5095exit:
5096 /* Cleanup for path */
5097 path_cleanup(&path);
5098 /* Cleanup for attribute */
5099 path_cleanup(&attribute);
5100
5101 return return_value;
5102}
5103
5104#endif /* defined(USE_XATTRS) */
5105
5106#if defined(USE_XATTRS)
5107
5108PyDoc_STRVAR(os_listxattr__doc__,
5109"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5110"--\n"
5111"\n"
5112"Return a list of extended attributes on path.\n"
5113"\n"
5114"path may be either None, a string, or an open file descriptor.\n"
5115"if path is None, listxattr will examine the current directory.\n"
5116"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5117" link, listxattr will examine the symbolic link itself instead of the file\n"
5118" the link points to.");
5119
5120#define OS_LISTXATTR_METHODDEF \
5121 {"listxattr", (PyCFunction)os_listxattr, METH_VARARGS|METH_KEYWORDS, os_listxattr__doc__},
5122
5123static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005124os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005125
5126static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005127os_listxattr(PyObject *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005128{
5129 PyObject *return_value = NULL;
5130 static char *_keywords[] = {"path", "follow_symlinks", NULL};
5131 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5132 int follow_symlinks = 1;
5133
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005134 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&$p:listxattr", _keywords,
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005135 path_converter, &path, &follow_symlinks))
5136 goto exit;
5137 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5138
5139exit:
5140 /* Cleanup for path */
5141 path_cleanup(&path);
5142
5143 return return_value;
5144}
5145
5146#endif /* defined(USE_XATTRS) */
5147
5148PyDoc_STRVAR(os_urandom__doc__,
5149"urandom($module, size, /)\n"
5150"--\n"
5151"\n"
5152"Return a bytes object containing random bytes suitable for cryptographic use.");
5153
5154#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005155 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005156
5157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005158os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005159
5160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005161os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005162{
5163 PyObject *return_value = NULL;
5164 Py_ssize_t size;
5165
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005166 if (!PyArg_Parse(arg, "n:urandom", &size))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005167 goto exit;
5168 return_value = os_urandom_impl(module, size);
5169
5170exit:
5171 return return_value;
5172}
5173
5174PyDoc_STRVAR(os_cpu_count__doc__,
5175"cpu_count($module, /)\n"
5176"--\n"
5177"\n"
5178"Return the number of CPUs in the system; return None if indeterminable.");
5179
5180#define OS_CPU_COUNT_METHODDEF \
5181 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5182
5183static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005184os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005185
5186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005187os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005188{
5189 return os_cpu_count_impl(module);
5190}
5191
5192PyDoc_STRVAR(os_get_inheritable__doc__,
5193"get_inheritable($module, fd, /)\n"
5194"--\n"
5195"\n"
5196"Get the close-on-exe flag of the specified file descriptor.");
5197
5198#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005199 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005200
5201static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005202os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005203
5204static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005205os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005206{
5207 PyObject *return_value = NULL;
5208 int fd;
5209 int _return_value;
5210
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005211 if (!PyArg_Parse(arg, "i:get_inheritable", &fd))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005212 goto exit;
5213 _return_value = os_get_inheritable_impl(module, fd);
5214 if ((_return_value == -1) && PyErr_Occurred())
5215 goto exit;
5216 return_value = PyBool_FromLong((long)_return_value);
5217
5218exit:
5219 return return_value;
5220}
5221
5222PyDoc_STRVAR(os_set_inheritable__doc__,
5223"set_inheritable($module, fd, inheritable, /)\n"
5224"--\n"
5225"\n"
5226"Set the inheritable flag of the specified file descriptor.");
5227
5228#define OS_SET_INHERITABLE_METHODDEF \
5229 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
5230
5231static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005232os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005233
5234static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005235os_set_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005236{
5237 PyObject *return_value = NULL;
5238 int fd;
5239 int inheritable;
5240
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005241 if (!PyArg_ParseTuple(args, "ii:set_inheritable",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005242 &fd, &inheritable))
5243 goto exit;
5244 return_value = os_set_inheritable_impl(module, fd, inheritable);
5245
5246exit:
5247 return return_value;
5248}
5249
5250#if defined(MS_WINDOWS)
5251
5252PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5253"get_handle_inheritable($module, handle, /)\n"
5254"--\n"
5255"\n"
5256"Get the close-on-exe flag of the specified file descriptor.");
5257
5258#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005259 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005260
5261static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005262os_get_handle_inheritable_impl(PyObject *module, Py_intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005263
5264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005265os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005266{
5267 PyObject *return_value = NULL;
5268 Py_intptr_t handle;
5269 int _return_value;
5270
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005271 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005272 goto exit;
5273 _return_value = os_get_handle_inheritable_impl(module, handle);
5274 if ((_return_value == -1) && PyErr_Occurred())
5275 goto exit;
5276 return_value = PyBool_FromLong((long)_return_value);
5277
5278exit:
5279 return return_value;
5280}
5281
5282#endif /* defined(MS_WINDOWS) */
5283
5284#if defined(MS_WINDOWS)
5285
5286PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5287"set_handle_inheritable($module, handle, inheritable, /)\n"
5288"--\n"
5289"\n"
5290"Set the inheritable flag of the specified handle.");
5291
5292#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
5293 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
5294
5295static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005296os_set_handle_inheritable_impl(PyObject *module, Py_intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005297 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005298
5299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005300os_set_handle_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005301{
5302 PyObject *return_value = NULL;
5303 Py_intptr_t handle;
5304 int inheritable;
5305
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005306 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005307 &handle, &inheritable))
5308 goto exit;
5309 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5310
5311exit:
5312 return return_value;
5313}
5314
5315#endif /* defined(MS_WINDOWS) */
5316
5317#ifndef OS_TTYNAME_METHODDEF
5318 #define OS_TTYNAME_METHODDEF
5319#endif /* !defined(OS_TTYNAME_METHODDEF) */
5320
5321#ifndef OS_CTERMID_METHODDEF
5322 #define OS_CTERMID_METHODDEF
5323#endif /* !defined(OS_CTERMID_METHODDEF) */
5324
5325#ifndef OS_FCHDIR_METHODDEF
5326 #define OS_FCHDIR_METHODDEF
5327#endif /* !defined(OS_FCHDIR_METHODDEF) */
5328
5329#ifndef OS_FCHMOD_METHODDEF
5330 #define OS_FCHMOD_METHODDEF
5331#endif /* !defined(OS_FCHMOD_METHODDEF) */
5332
5333#ifndef OS_LCHMOD_METHODDEF
5334 #define OS_LCHMOD_METHODDEF
5335#endif /* !defined(OS_LCHMOD_METHODDEF) */
5336
5337#ifndef OS_CHFLAGS_METHODDEF
5338 #define OS_CHFLAGS_METHODDEF
5339#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5340
5341#ifndef OS_LCHFLAGS_METHODDEF
5342 #define OS_LCHFLAGS_METHODDEF
5343#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5344
5345#ifndef OS_CHROOT_METHODDEF
5346 #define OS_CHROOT_METHODDEF
5347#endif /* !defined(OS_CHROOT_METHODDEF) */
5348
5349#ifndef OS_FSYNC_METHODDEF
5350 #define OS_FSYNC_METHODDEF
5351#endif /* !defined(OS_FSYNC_METHODDEF) */
5352
5353#ifndef OS_SYNC_METHODDEF
5354 #define OS_SYNC_METHODDEF
5355#endif /* !defined(OS_SYNC_METHODDEF) */
5356
5357#ifndef OS_FDATASYNC_METHODDEF
5358 #define OS_FDATASYNC_METHODDEF
5359#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5360
5361#ifndef OS_CHOWN_METHODDEF
5362 #define OS_CHOWN_METHODDEF
5363#endif /* !defined(OS_CHOWN_METHODDEF) */
5364
5365#ifndef OS_FCHOWN_METHODDEF
5366 #define OS_FCHOWN_METHODDEF
5367#endif /* !defined(OS_FCHOWN_METHODDEF) */
5368
5369#ifndef OS_LCHOWN_METHODDEF
5370 #define OS_LCHOWN_METHODDEF
5371#endif /* !defined(OS_LCHOWN_METHODDEF) */
5372
5373#ifndef OS_LINK_METHODDEF
5374 #define OS_LINK_METHODDEF
5375#endif /* !defined(OS_LINK_METHODDEF) */
5376
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005377#ifndef OS__GETFULLPATHNAME_METHODDEF
5378 #define OS__GETFULLPATHNAME_METHODDEF
5379#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5380
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005381#ifndef OS__GETFINALPATHNAME_METHODDEF
5382 #define OS__GETFINALPATHNAME_METHODDEF
5383#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5384
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005385#ifndef OS__ISDIR_METHODDEF
5386 #define OS__ISDIR_METHODDEF
5387#endif /* !defined(OS__ISDIR_METHODDEF) */
5388
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005389#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5390 #define OS__GETVOLUMEPATHNAME_METHODDEF
5391#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5392
5393#ifndef OS_NICE_METHODDEF
5394 #define OS_NICE_METHODDEF
5395#endif /* !defined(OS_NICE_METHODDEF) */
5396
5397#ifndef OS_GETPRIORITY_METHODDEF
5398 #define OS_GETPRIORITY_METHODDEF
5399#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
5400
5401#ifndef OS_SETPRIORITY_METHODDEF
5402 #define OS_SETPRIORITY_METHODDEF
5403#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
5404
5405#ifndef OS_SYSTEM_METHODDEF
5406 #define OS_SYSTEM_METHODDEF
5407#endif /* !defined(OS_SYSTEM_METHODDEF) */
5408
5409#ifndef OS_UNAME_METHODDEF
5410 #define OS_UNAME_METHODDEF
5411#endif /* !defined(OS_UNAME_METHODDEF) */
5412
5413#ifndef OS_EXECV_METHODDEF
5414 #define OS_EXECV_METHODDEF
5415#endif /* !defined(OS_EXECV_METHODDEF) */
5416
5417#ifndef OS_EXECVE_METHODDEF
5418 #define OS_EXECVE_METHODDEF
5419#endif /* !defined(OS_EXECVE_METHODDEF) */
5420
5421#ifndef OS_SPAWNV_METHODDEF
5422 #define OS_SPAWNV_METHODDEF
5423#endif /* !defined(OS_SPAWNV_METHODDEF) */
5424
5425#ifndef OS_SPAWNVE_METHODDEF
5426 #define OS_SPAWNVE_METHODDEF
5427#endif /* !defined(OS_SPAWNVE_METHODDEF) */
5428
5429#ifndef OS_FORK1_METHODDEF
5430 #define OS_FORK1_METHODDEF
5431#endif /* !defined(OS_FORK1_METHODDEF) */
5432
5433#ifndef OS_FORK_METHODDEF
5434 #define OS_FORK_METHODDEF
5435#endif /* !defined(OS_FORK_METHODDEF) */
5436
5437#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5438 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5439#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
5440
5441#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5442 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5443#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
5444
5445#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
5446 #define OS_SCHED_GETSCHEDULER_METHODDEF
5447#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
5448
5449#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
5450 #define OS_SCHED_SETSCHEDULER_METHODDEF
5451#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
5452
5453#ifndef OS_SCHED_GETPARAM_METHODDEF
5454 #define OS_SCHED_GETPARAM_METHODDEF
5455#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
5456
5457#ifndef OS_SCHED_SETPARAM_METHODDEF
5458 #define OS_SCHED_SETPARAM_METHODDEF
5459#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
5460
5461#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
5462 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
5463#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
5464
5465#ifndef OS_SCHED_YIELD_METHODDEF
5466 #define OS_SCHED_YIELD_METHODDEF
5467#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
5468
5469#ifndef OS_SCHED_SETAFFINITY_METHODDEF
5470 #define OS_SCHED_SETAFFINITY_METHODDEF
5471#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
5472
5473#ifndef OS_SCHED_GETAFFINITY_METHODDEF
5474 #define OS_SCHED_GETAFFINITY_METHODDEF
5475#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
5476
5477#ifndef OS_OPENPTY_METHODDEF
5478 #define OS_OPENPTY_METHODDEF
5479#endif /* !defined(OS_OPENPTY_METHODDEF) */
5480
5481#ifndef OS_FORKPTY_METHODDEF
5482 #define OS_FORKPTY_METHODDEF
5483#endif /* !defined(OS_FORKPTY_METHODDEF) */
5484
5485#ifndef OS_GETEGID_METHODDEF
5486 #define OS_GETEGID_METHODDEF
5487#endif /* !defined(OS_GETEGID_METHODDEF) */
5488
5489#ifndef OS_GETEUID_METHODDEF
5490 #define OS_GETEUID_METHODDEF
5491#endif /* !defined(OS_GETEUID_METHODDEF) */
5492
5493#ifndef OS_GETGID_METHODDEF
5494 #define OS_GETGID_METHODDEF
5495#endif /* !defined(OS_GETGID_METHODDEF) */
5496
5497#ifndef OS_GETGROUPS_METHODDEF
5498 #define OS_GETGROUPS_METHODDEF
5499#endif /* !defined(OS_GETGROUPS_METHODDEF) */
5500
5501#ifndef OS_GETPGID_METHODDEF
5502 #define OS_GETPGID_METHODDEF
5503#endif /* !defined(OS_GETPGID_METHODDEF) */
5504
5505#ifndef OS_GETPGRP_METHODDEF
5506 #define OS_GETPGRP_METHODDEF
5507#endif /* !defined(OS_GETPGRP_METHODDEF) */
5508
5509#ifndef OS_SETPGRP_METHODDEF
5510 #define OS_SETPGRP_METHODDEF
5511#endif /* !defined(OS_SETPGRP_METHODDEF) */
5512
5513#ifndef OS_GETPPID_METHODDEF
5514 #define OS_GETPPID_METHODDEF
5515#endif /* !defined(OS_GETPPID_METHODDEF) */
5516
5517#ifndef OS_GETLOGIN_METHODDEF
5518 #define OS_GETLOGIN_METHODDEF
5519#endif /* !defined(OS_GETLOGIN_METHODDEF) */
5520
5521#ifndef OS_GETUID_METHODDEF
5522 #define OS_GETUID_METHODDEF
5523#endif /* !defined(OS_GETUID_METHODDEF) */
5524
5525#ifndef OS_KILL_METHODDEF
5526 #define OS_KILL_METHODDEF
5527#endif /* !defined(OS_KILL_METHODDEF) */
5528
5529#ifndef OS_KILLPG_METHODDEF
5530 #define OS_KILLPG_METHODDEF
5531#endif /* !defined(OS_KILLPG_METHODDEF) */
5532
5533#ifndef OS_PLOCK_METHODDEF
5534 #define OS_PLOCK_METHODDEF
5535#endif /* !defined(OS_PLOCK_METHODDEF) */
5536
5537#ifndef OS_SETUID_METHODDEF
5538 #define OS_SETUID_METHODDEF
5539#endif /* !defined(OS_SETUID_METHODDEF) */
5540
5541#ifndef OS_SETEUID_METHODDEF
5542 #define OS_SETEUID_METHODDEF
5543#endif /* !defined(OS_SETEUID_METHODDEF) */
5544
5545#ifndef OS_SETEGID_METHODDEF
5546 #define OS_SETEGID_METHODDEF
5547#endif /* !defined(OS_SETEGID_METHODDEF) */
5548
5549#ifndef OS_SETREUID_METHODDEF
5550 #define OS_SETREUID_METHODDEF
5551#endif /* !defined(OS_SETREUID_METHODDEF) */
5552
5553#ifndef OS_SETREGID_METHODDEF
5554 #define OS_SETREGID_METHODDEF
5555#endif /* !defined(OS_SETREGID_METHODDEF) */
5556
5557#ifndef OS_SETGID_METHODDEF
5558 #define OS_SETGID_METHODDEF
5559#endif /* !defined(OS_SETGID_METHODDEF) */
5560
5561#ifndef OS_SETGROUPS_METHODDEF
5562 #define OS_SETGROUPS_METHODDEF
5563#endif /* !defined(OS_SETGROUPS_METHODDEF) */
5564
5565#ifndef OS_WAIT3_METHODDEF
5566 #define OS_WAIT3_METHODDEF
5567#endif /* !defined(OS_WAIT3_METHODDEF) */
5568
5569#ifndef OS_WAIT4_METHODDEF
5570 #define OS_WAIT4_METHODDEF
5571#endif /* !defined(OS_WAIT4_METHODDEF) */
5572
5573#ifndef OS_WAITID_METHODDEF
5574 #define OS_WAITID_METHODDEF
5575#endif /* !defined(OS_WAITID_METHODDEF) */
5576
5577#ifndef OS_WAITPID_METHODDEF
5578 #define OS_WAITPID_METHODDEF
5579#endif /* !defined(OS_WAITPID_METHODDEF) */
5580
5581#ifndef OS_WAIT_METHODDEF
5582 #define OS_WAIT_METHODDEF
5583#endif /* !defined(OS_WAIT_METHODDEF) */
5584
5585#ifndef OS_SYMLINK_METHODDEF
5586 #define OS_SYMLINK_METHODDEF
5587#endif /* !defined(OS_SYMLINK_METHODDEF) */
5588
5589#ifndef OS_TIMES_METHODDEF
5590 #define OS_TIMES_METHODDEF
5591#endif /* !defined(OS_TIMES_METHODDEF) */
5592
5593#ifndef OS_GETSID_METHODDEF
5594 #define OS_GETSID_METHODDEF
5595#endif /* !defined(OS_GETSID_METHODDEF) */
5596
5597#ifndef OS_SETSID_METHODDEF
5598 #define OS_SETSID_METHODDEF
5599#endif /* !defined(OS_SETSID_METHODDEF) */
5600
5601#ifndef OS_SETPGID_METHODDEF
5602 #define OS_SETPGID_METHODDEF
5603#endif /* !defined(OS_SETPGID_METHODDEF) */
5604
5605#ifndef OS_TCGETPGRP_METHODDEF
5606 #define OS_TCGETPGRP_METHODDEF
5607#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
5608
5609#ifndef OS_TCSETPGRP_METHODDEF
5610 #define OS_TCSETPGRP_METHODDEF
5611#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
5612
5613#ifndef OS_LOCKF_METHODDEF
5614 #define OS_LOCKF_METHODDEF
5615#endif /* !defined(OS_LOCKF_METHODDEF) */
5616
5617#ifndef OS_READV_METHODDEF
5618 #define OS_READV_METHODDEF
5619#endif /* !defined(OS_READV_METHODDEF) */
5620
5621#ifndef OS_PREAD_METHODDEF
5622 #define OS_PREAD_METHODDEF
5623#endif /* !defined(OS_PREAD_METHODDEF) */
5624
5625#ifndef OS_PIPE_METHODDEF
5626 #define OS_PIPE_METHODDEF
5627#endif /* !defined(OS_PIPE_METHODDEF) */
5628
5629#ifndef OS_PIPE2_METHODDEF
5630 #define OS_PIPE2_METHODDEF
5631#endif /* !defined(OS_PIPE2_METHODDEF) */
5632
5633#ifndef OS_WRITEV_METHODDEF
5634 #define OS_WRITEV_METHODDEF
5635#endif /* !defined(OS_WRITEV_METHODDEF) */
5636
5637#ifndef OS_PWRITE_METHODDEF
5638 #define OS_PWRITE_METHODDEF
5639#endif /* !defined(OS_PWRITE_METHODDEF) */
5640
5641#ifndef OS_MKFIFO_METHODDEF
5642 #define OS_MKFIFO_METHODDEF
5643#endif /* !defined(OS_MKFIFO_METHODDEF) */
5644
5645#ifndef OS_MKNOD_METHODDEF
5646 #define OS_MKNOD_METHODDEF
5647#endif /* !defined(OS_MKNOD_METHODDEF) */
5648
5649#ifndef OS_MAJOR_METHODDEF
5650 #define OS_MAJOR_METHODDEF
5651#endif /* !defined(OS_MAJOR_METHODDEF) */
5652
5653#ifndef OS_MINOR_METHODDEF
5654 #define OS_MINOR_METHODDEF
5655#endif /* !defined(OS_MINOR_METHODDEF) */
5656
5657#ifndef OS_MAKEDEV_METHODDEF
5658 #define OS_MAKEDEV_METHODDEF
5659#endif /* !defined(OS_MAKEDEV_METHODDEF) */
5660
5661#ifndef OS_FTRUNCATE_METHODDEF
5662 #define OS_FTRUNCATE_METHODDEF
5663#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
5664
5665#ifndef OS_TRUNCATE_METHODDEF
5666 #define OS_TRUNCATE_METHODDEF
5667#endif /* !defined(OS_TRUNCATE_METHODDEF) */
5668
5669#ifndef OS_POSIX_FALLOCATE_METHODDEF
5670 #define OS_POSIX_FALLOCATE_METHODDEF
5671#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
5672
5673#ifndef OS_POSIX_FADVISE_METHODDEF
5674 #define OS_POSIX_FADVISE_METHODDEF
5675#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
5676
5677#ifndef OS_PUTENV_METHODDEF
5678 #define OS_PUTENV_METHODDEF
5679#endif /* !defined(OS_PUTENV_METHODDEF) */
5680
5681#ifndef OS_UNSETENV_METHODDEF
5682 #define OS_UNSETENV_METHODDEF
5683#endif /* !defined(OS_UNSETENV_METHODDEF) */
5684
5685#ifndef OS_WCOREDUMP_METHODDEF
5686 #define OS_WCOREDUMP_METHODDEF
5687#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
5688
5689#ifndef OS_WIFCONTINUED_METHODDEF
5690 #define OS_WIFCONTINUED_METHODDEF
5691#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
5692
5693#ifndef OS_WIFSTOPPED_METHODDEF
5694 #define OS_WIFSTOPPED_METHODDEF
5695#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
5696
5697#ifndef OS_WIFSIGNALED_METHODDEF
5698 #define OS_WIFSIGNALED_METHODDEF
5699#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
5700
5701#ifndef OS_WIFEXITED_METHODDEF
5702 #define OS_WIFEXITED_METHODDEF
5703#endif /* !defined(OS_WIFEXITED_METHODDEF) */
5704
5705#ifndef OS_WEXITSTATUS_METHODDEF
5706 #define OS_WEXITSTATUS_METHODDEF
5707#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
5708
5709#ifndef OS_WTERMSIG_METHODDEF
5710 #define OS_WTERMSIG_METHODDEF
5711#endif /* !defined(OS_WTERMSIG_METHODDEF) */
5712
5713#ifndef OS_WSTOPSIG_METHODDEF
5714 #define OS_WSTOPSIG_METHODDEF
5715#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
5716
5717#ifndef OS_FSTATVFS_METHODDEF
5718 #define OS_FSTATVFS_METHODDEF
5719#endif /* !defined(OS_FSTATVFS_METHODDEF) */
5720
5721#ifndef OS_STATVFS_METHODDEF
5722 #define OS_STATVFS_METHODDEF
5723#endif /* !defined(OS_STATVFS_METHODDEF) */
5724
5725#ifndef OS__GETDISKUSAGE_METHODDEF
5726 #define OS__GETDISKUSAGE_METHODDEF
5727#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
5728
5729#ifndef OS_FPATHCONF_METHODDEF
5730 #define OS_FPATHCONF_METHODDEF
5731#endif /* !defined(OS_FPATHCONF_METHODDEF) */
5732
5733#ifndef OS_PATHCONF_METHODDEF
5734 #define OS_PATHCONF_METHODDEF
5735#endif /* !defined(OS_PATHCONF_METHODDEF) */
5736
5737#ifndef OS_CONFSTR_METHODDEF
5738 #define OS_CONFSTR_METHODDEF
5739#endif /* !defined(OS_CONFSTR_METHODDEF) */
5740
5741#ifndef OS_SYSCONF_METHODDEF
5742 #define OS_SYSCONF_METHODDEF
5743#endif /* !defined(OS_SYSCONF_METHODDEF) */
5744
5745#ifndef OS_GETLOADAVG_METHODDEF
5746 #define OS_GETLOADAVG_METHODDEF
5747#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
5748
5749#ifndef OS_SETRESUID_METHODDEF
5750 #define OS_SETRESUID_METHODDEF
5751#endif /* !defined(OS_SETRESUID_METHODDEF) */
5752
5753#ifndef OS_SETRESGID_METHODDEF
5754 #define OS_SETRESGID_METHODDEF
5755#endif /* !defined(OS_SETRESGID_METHODDEF) */
5756
5757#ifndef OS_GETRESUID_METHODDEF
5758 #define OS_GETRESUID_METHODDEF
5759#endif /* !defined(OS_GETRESUID_METHODDEF) */
5760
5761#ifndef OS_GETRESGID_METHODDEF
5762 #define OS_GETRESGID_METHODDEF
5763#endif /* !defined(OS_GETRESGID_METHODDEF) */
5764
5765#ifndef OS_GETXATTR_METHODDEF
5766 #define OS_GETXATTR_METHODDEF
5767#endif /* !defined(OS_GETXATTR_METHODDEF) */
5768
5769#ifndef OS_SETXATTR_METHODDEF
5770 #define OS_SETXATTR_METHODDEF
5771#endif /* !defined(OS_SETXATTR_METHODDEF) */
5772
5773#ifndef OS_REMOVEXATTR_METHODDEF
5774 #define OS_REMOVEXATTR_METHODDEF
5775#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
5776
5777#ifndef OS_LISTXATTR_METHODDEF
5778 #define OS_LISTXATTR_METHODDEF
5779#endif /* !defined(OS_LISTXATTR_METHODDEF) */
5780
5781#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
5782 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
5783#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
5784
5785#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
5786 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
5787#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Serhiy Storchaka579f0382016-11-08 20:21:22 +02005788/*[clinic end generated code: output=7690b72549d2524e input=a9049054013a1b77]*/