blob: 0d3ce6eed65d260980a5af7f7c1ca4270c2cf045 [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"
Xiang Zhang4459e002017-01-22 13:04:17 +080012" Path to be examined; can be string, bytes, path-like object or\n"
13" open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030014" dir_fd\n"
15" If not None, it should be a file descriptor open to a directory,\n"
16" and path should be a relative string; path will then be relative to\n"
17" that directory.\n"
18" follow_symlinks\n"
19" If False, and the last element of the path is a symbolic link,\n"
20" stat will examine the symbolic link itself instead of the file\n"
21" the link points to.\n"
22"\n"
23"dir_fd and follow_symlinks may not be implemented\n"
24" on your platform. If they are unavailable, using them will raise a\n"
25" NotImplementedError.\n"
26"\n"
27"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
28" an open file descriptor.");
29
30#define OS_STAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070031 {"stat", (PyCFunction)os_stat, METH_FASTCALL, os_stat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030032
33static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030035
36static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070037os_stat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030038{
39 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030040 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
41 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030042 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
43 int dir_fd = DEFAULT_DIR_FD;
44 int follow_symlinks = 1;
45
Victor Stinner37e4ef72016-09-09 20:00:13 -070046 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030047 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030048 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030049 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
51
52exit:
53 /* Cleanup for path */
54 path_cleanup(&path);
55
56 return return_value;
57}
58
59PyDoc_STRVAR(os_lstat__doc__,
60"lstat($module, /, path, *, dir_fd=None)\n"
61"--\n"
62"\n"
63"Perform a stat system call on the given path, without following symbolic links.\n"
64"\n"
65"Like stat(), but do not follow symbolic links.\n"
66"Equivalent to stat(path, follow_symlinks=False).");
67
68#define OS_LSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070069 {"lstat", (PyCFunction)os_lstat, METH_FASTCALL, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070
71static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030072os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030073
74static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070075os_lstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"path", "dir_fd", NULL};
79 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030080 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
81 int dir_fd = DEFAULT_DIR_FD;
82
Victor Stinner37e4ef72016-09-09 20:00:13 -070083 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087 return_value = os_lstat_impl(module, &path, dir_fd);
88
89exit:
90 /* Cleanup for path */
91 path_cleanup(&path);
92
93 return return_value;
94}
95
96PyDoc_STRVAR(os_access__doc__,
97"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
98" follow_symlinks=True)\n"
99"--\n"
100"\n"
101"Use the real uid/gid to test for access to a path.\n"
102"\n"
103" path\n"
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700104" Path to be tested; can be string or bytes\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105" mode\n"
106" Operating-system mode bitfield. Can be F_OK to test existence,\n"
107" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
108" dir_fd\n"
109" If not None, it should be a file descriptor open to a directory,\n"
110" and path should be relative; path will then be relative to that\n"
111" directory.\n"
112" effective_ids\n"
113" If True, access will use the effective uid/gid instead of\n"
114" the real uid/gid.\n"
115" follow_symlinks\n"
116" If False, and the last element of the path is a symbolic link,\n"
117" access will examine the symbolic link itself instead of the file\n"
118" the link points to.\n"
119"\n"
120"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
121" on your platform. If they are unavailable, using them will raise a\n"
122" NotImplementedError.\n"
123"\n"
124"Note that most operations will use the effective uid/gid, therefore this\n"
125" routine can be used in a suid/sgid environment to test if the invoking user\n"
126" has the specified access to the path.");
127
128#define OS_ACCESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700129 {"access", (PyCFunction)os_access, METH_FASTCALL, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400133 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300134
135static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700136os_access(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300137{
138 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300139 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
140 static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700141 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300142 int mode;
143 int dir_fd = DEFAULT_DIR_FD;
144 int effective_ids = 0;
145 int follow_symlinks = 1;
146 int _return_value;
147
Victor Stinner37e4ef72016-09-09 20:00:13 -0700148 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300153 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156 return_value = PyBool_FromLong((long)_return_value);
157
158exit:
159 /* Cleanup for path */
160 path_cleanup(&path);
161
162 return return_value;
163}
164
165#if defined(HAVE_TTYNAME)
166
167PyDoc_STRVAR(os_ttyname__doc__,
168"ttyname($module, fd, /)\n"
169"--\n"
170"\n"
171"Return the name of the terminal device connected to \'fd\'.\n"
172"\n"
173" fd\n"
174" Integer file descriptor handle.");
175
176#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300177 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300178
179static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300180os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181
182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300183os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300184{
185 PyObject *return_value = NULL;
186 int fd;
187 char *_return_value;
188
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300189 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300190 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300193 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196 return_value = PyUnicode_DecodeFSDefault(_return_value);
197
198exit:
199 return return_value;
200}
201
202#endif /* defined(HAVE_TTYNAME) */
203
204#if defined(HAVE_CTERMID)
205
206PyDoc_STRVAR(os_ctermid__doc__,
207"ctermid($module, /)\n"
208"--\n"
209"\n"
210"Return the name of the controlling terminal for this process.");
211
212#define OS_CTERMID_METHODDEF \
213 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
214
215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300216os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300217
218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300219os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220{
221 return os_ctermid_impl(module);
222}
223
224#endif /* defined(HAVE_CTERMID) */
225
226PyDoc_STRVAR(os_chdir__doc__,
227"chdir($module, /, path)\n"
228"--\n"
229"\n"
230"Change the current working directory to the specified path.\n"
231"\n"
232"path may always be specified as a string.\n"
233"On some platforms, path may also be specified as an open file descriptor.\n"
234" If this functionality is unavailable, using it raises an exception.");
235
236#define OS_CHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700237 {"chdir", (PyCFunction)os_chdir, METH_FASTCALL, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238
239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300240os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300241
242static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700243os_chdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300244{
245 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300246 static const char * const _keywords[] = {"path", NULL};
247 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300248 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
249
Victor Stinner37e4ef72016-09-09 20:00:13 -0700250 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300251 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300252 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300253 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300254 return_value = os_chdir_impl(module, &path);
255
256exit:
257 /* Cleanup for path */
258 path_cleanup(&path);
259
260 return return_value;
261}
262
263#if defined(HAVE_FCHDIR)
264
265PyDoc_STRVAR(os_fchdir__doc__,
266"fchdir($module, /, fd)\n"
267"--\n"
268"\n"
269"Change to the directory of the given file descriptor.\n"
270"\n"
271"fd must be opened on a directory, not a file.\n"
272"Equivalent to os.chdir(fd).");
273
274#define OS_FCHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700275 {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300276
277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300278os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279
280static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700281os_fchdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300282{
283 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300284 static const char * const _keywords[] = {"fd", NULL};
285 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300286 int fd;
287
Victor Stinner37e4ef72016-09-09 20:00:13 -0700288 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300289 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300292 return_value = os_fchdir_impl(module, fd);
293
294exit:
295 return return_value;
296}
297
298#endif /* defined(HAVE_FCHDIR) */
299
300PyDoc_STRVAR(os_chmod__doc__,
301"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
302"--\n"
303"\n"
304"Change the access permissions of a file.\n"
305"\n"
306" path\n"
307" Path to be modified. May always be specified as a str or bytes.\n"
308" On some platforms, path may also be specified as an open file descriptor.\n"
309" If this functionality is unavailable, using it raises an exception.\n"
310" mode\n"
311" Operating-system mode bitfield.\n"
312" dir_fd\n"
313" If not None, it should be a file descriptor open to a directory,\n"
314" and path should be relative; path will then be relative to that\n"
315" directory.\n"
316" follow_symlinks\n"
317" If False, and the last element of the path is a symbolic link,\n"
318" chmod will modify the symbolic link itself instead of the file\n"
319" the link points to.\n"
320"\n"
321"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
322" an open file descriptor.\n"
323"dir_fd and follow_symlinks may not be implemented on your platform.\n"
324" If they are unavailable, using them will raise a NotImplementedError.");
325
326#define OS_CHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700327 {"chmod", (PyCFunction)os_chmod, METH_FASTCALL, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300328
329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300330os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400331 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300332
333static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700334os_chmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300335{
336 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300337 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
338 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300339 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
340 int mode;
341 int dir_fd = DEFAULT_DIR_FD;
342 int follow_symlinks = 1;
343
Victor Stinner37e4ef72016-09-09 20:00:13 -0700344 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300345 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300347 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300348 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
349
350exit:
351 /* Cleanup for path */
352 path_cleanup(&path);
353
354 return return_value;
355}
356
357#if defined(HAVE_FCHMOD)
358
359PyDoc_STRVAR(os_fchmod__doc__,
360"fchmod($module, /, fd, mode)\n"
361"--\n"
362"\n"
363"Change the access permissions of the file given by file descriptor fd.\n"
364"\n"
365"Equivalent to os.chmod(fd, mode).");
366
367#define OS_FCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700368 {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369
370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300371os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300372
373static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700374os_fchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300375{
376 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300377 static const char * const _keywords[] = {"fd", "mode", NULL};
378 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 int fd;
380 int mode;
381
Victor Stinner37e4ef72016-09-09 20:00:13 -0700382 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300383 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300386 return_value = os_fchmod_impl(module, fd, mode);
387
388exit:
389 return return_value;
390}
391
392#endif /* defined(HAVE_FCHMOD) */
393
394#if defined(HAVE_LCHMOD)
395
396PyDoc_STRVAR(os_lchmod__doc__,
397"lchmod($module, /, path, mode)\n"
398"--\n"
399"\n"
400"Change the access permissions of a file, without following symbolic links.\n"
401"\n"
402"If path is a symlink, this affects the link itself rather than the target.\n"
403"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
404
405#define OS_LCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700406 {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300407
408static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300409os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410
411static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700412os_lchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300413{
414 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300415 static const char * const _keywords[] = {"path", "mode", NULL};
416 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300417 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
418 int mode;
419
Victor Stinner37e4ef72016-09-09 20:00:13 -0700420 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300421 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300424 return_value = os_lchmod_impl(module, &path, mode);
425
426exit:
427 /* Cleanup for path */
428 path_cleanup(&path);
429
430 return return_value;
431}
432
433#endif /* defined(HAVE_LCHMOD) */
434
435#if defined(HAVE_CHFLAGS)
436
437PyDoc_STRVAR(os_chflags__doc__,
438"chflags($module, /, path, flags, follow_symlinks=True)\n"
439"--\n"
440"\n"
441"Set file flags.\n"
442"\n"
443"If follow_symlinks is False, and the last element of the path is a symbolic\n"
444" link, chflags will change flags on the symbolic link itself instead of the\n"
445" file the link points to.\n"
446"follow_symlinks may not be implemented on your platform. If it is\n"
447"unavailable, using it will raise a NotImplementedError.");
448
449#define OS_CHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700450 {"chflags", (PyCFunction)os_chflags, METH_FASTCALL, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300451
452static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300453os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400454 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300455
456static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700457os_chflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300458{
459 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300460 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
461 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300462 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
463 unsigned long flags;
464 int follow_symlinks = 1;
465
Victor Stinner37e4ef72016-09-09 20:00:13 -0700466 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300467 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300468 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300470 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
471
472exit:
473 /* Cleanup for path */
474 path_cleanup(&path);
475
476 return return_value;
477}
478
479#endif /* defined(HAVE_CHFLAGS) */
480
481#if defined(HAVE_LCHFLAGS)
482
483PyDoc_STRVAR(os_lchflags__doc__,
484"lchflags($module, /, path, flags)\n"
485"--\n"
486"\n"
487"Set file flags.\n"
488"\n"
489"This function will not follow symbolic links.\n"
490"Equivalent to chflags(path, flags, follow_symlinks=False).");
491
492#define OS_LCHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700493 {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300494
495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300496os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300497
498static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700499os_lchflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300500{
501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300502 static const char * const _keywords[] = {"path", "flags", NULL};
503 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
505 unsigned long flags;
506
Victor Stinner37e4ef72016-09-09 20:00:13 -0700507 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300508 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511 return_value = os_lchflags_impl(module, &path, flags);
512
513exit:
514 /* Cleanup for path */
515 path_cleanup(&path);
516
517 return return_value;
518}
519
520#endif /* defined(HAVE_LCHFLAGS) */
521
522#if defined(HAVE_CHROOT)
523
524PyDoc_STRVAR(os_chroot__doc__,
525"chroot($module, /, path)\n"
526"--\n"
527"\n"
528"Change root directory to path.");
529
530#define OS_CHROOT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700531 {"chroot", (PyCFunction)os_chroot, METH_FASTCALL, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300532
533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300534os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535
536static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700537os_chroot(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300538{
539 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300540 static const char * const _keywords[] = {"path", NULL};
541 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300542 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
543
Victor Stinner37e4ef72016-09-09 20:00:13 -0700544 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300545 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300547 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 return_value = os_chroot_impl(module, &path);
549
550exit:
551 /* Cleanup for path */
552 path_cleanup(&path);
553
554 return return_value;
555}
556
557#endif /* defined(HAVE_CHROOT) */
558
559#if defined(HAVE_FSYNC)
560
561PyDoc_STRVAR(os_fsync__doc__,
562"fsync($module, /, fd)\n"
563"--\n"
564"\n"
565"Force write of fd to disk.");
566
567#define OS_FSYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700568 {"fsync", (PyCFunction)os_fsync, METH_FASTCALL, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300569
570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300571os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300572
573static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700574os_fsync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300575{
576 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300577 static const char * const _keywords[] = {"fd", NULL};
578 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300579 int fd;
580
Victor Stinner37e4ef72016-09-09 20:00:13 -0700581 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300582 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585 return_value = os_fsync_impl(module, fd);
586
587exit:
588 return return_value;
589}
590
591#endif /* defined(HAVE_FSYNC) */
592
593#if defined(HAVE_SYNC)
594
595PyDoc_STRVAR(os_sync__doc__,
596"sync($module, /)\n"
597"--\n"
598"\n"
599"Force write of everything to disk.");
600
601#define OS_SYNC_METHODDEF \
602 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
603
604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300605os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300606
607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300608os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300609{
610 return os_sync_impl(module);
611}
612
613#endif /* defined(HAVE_SYNC) */
614
615#if defined(HAVE_FDATASYNC)
616
617PyDoc_STRVAR(os_fdatasync__doc__,
618"fdatasync($module, /, fd)\n"
619"--\n"
620"\n"
621"Force write of fd to disk without forcing update of metadata.");
622
623#define OS_FDATASYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700624 {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300625
626static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300627os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628
629static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700630os_fdatasync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631{
632 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300633 static const char * const _keywords[] = {"fd", NULL};
634 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300635 int fd;
636
Victor Stinner37e4ef72016-09-09 20:00:13 -0700637 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300638 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300639 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300641 return_value = os_fdatasync_impl(module, fd);
642
643exit:
644 return return_value;
645}
646
647#endif /* defined(HAVE_FDATASYNC) */
648
649#if defined(HAVE_CHOWN)
650
651PyDoc_STRVAR(os_chown__doc__,
652"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
653"--\n"
654"\n"
655"Change the owner and group id of path to the numeric uid and gid.\\\n"
656"\n"
657" path\n"
658" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
659" dir_fd\n"
660" If not None, it should be a file descriptor open to a directory,\n"
661" and path should be relative; path will then be relative to that\n"
662" directory.\n"
663" follow_symlinks\n"
664" If False, and the last element of the path is a symbolic link,\n"
665" stat will examine the symbolic link itself instead of the file\n"
666" the link points to.\n"
667"\n"
668"path may always be specified as a string.\n"
669"On some platforms, path may also be specified as an open file descriptor.\n"
670" If this functionality is unavailable, using it raises an exception.\n"
671"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
672" and path should be relative; path will then be relative to that directory.\n"
673"If follow_symlinks is False, and the last element of the path is a symbolic\n"
674" link, chown will modify the symbolic link itself instead of the file the\n"
675" link points to.\n"
676"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
677" an open file descriptor.\n"
678"dir_fd and follow_symlinks may not be implemented on your platform.\n"
679" If they are unavailable, using them will raise a NotImplementedError.");
680
681#define OS_CHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700682 {"chown", (PyCFunction)os_chown, METH_FASTCALL, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300683
684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300685os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400686 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300687
688static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700689os_chown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300690{
691 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300692 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
693 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300694 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
695 uid_t uid;
696 gid_t gid;
697 int dir_fd = DEFAULT_DIR_FD;
698 int follow_symlinks = 1;
699
Victor Stinner37e4ef72016-09-09 20:00:13 -0700700 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300701 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300703 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300704 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
705
706exit:
707 /* Cleanup for path */
708 path_cleanup(&path);
709
710 return return_value;
711}
712
713#endif /* defined(HAVE_CHOWN) */
714
715#if defined(HAVE_FCHOWN)
716
717PyDoc_STRVAR(os_fchown__doc__,
718"fchown($module, /, fd, uid, gid)\n"
719"--\n"
720"\n"
721"Change the owner and group id of the file specified by file descriptor.\n"
722"\n"
723"Equivalent to os.chown(fd, uid, gid).");
724
725#define OS_FCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700726 {"fchown", (PyCFunction)os_fchown, METH_FASTCALL, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300727
728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300729os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300730
731static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700732os_fchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300733{
734 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300735 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
736 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300737 int fd;
738 uid_t uid;
739 gid_t gid;
740
Victor Stinner37e4ef72016-09-09 20:00:13 -0700741 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300742 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300745 return_value = os_fchown_impl(module, fd, uid, gid);
746
747exit:
748 return return_value;
749}
750
751#endif /* defined(HAVE_FCHOWN) */
752
753#if defined(HAVE_LCHOWN)
754
755PyDoc_STRVAR(os_lchown__doc__,
756"lchown($module, /, path, uid, gid)\n"
757"--\n"
758"\n"
759"Change the owner and group id of path to the numeric uid and gid.\n"
760"\n"
761"This function will not follow symbolic links.\n"
762"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
763
764#define OS_LCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700765 {"lchown", (PyCFunction)os_lchown, METH_FASTCALL, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300769
770static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700771os_lchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300772{
773 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300774 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
775 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300776 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
777 uid_t uid;
778 gid_t gid;
779
Victor Stinner37e4ef72016-09-09 20:00:13 -0700780 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300781 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300782 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300783 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300784 return_value = os_lchown_impl(module, &path, uid, gid);
785
786exit:
787 /* Cleanup for path */
788 path_cleanup(&path);
789
790 return return_value;
791}
792
793#endif /* defined(HAVE_LCHOWN) */
794
795PyDoc_STRVAR(os_getcwd__doc__,
796"getcwd($module, /)\n"
797"--\n"
798"\n"
799"Return a unicode string representing the current working directory.");
800
801#define OS_GETCWD_METHODDEF \
802 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
803
804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300805os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300806
807static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300808os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300809{
810 return os_getcwd_impl(module);
811}
812
813PyDoc_STRVAR(os_getcwdb__doc__,
814"getcwdb($module, /)\n"
815"--\n"
816"\n"
817"Return a bytes string representing the current working directory.");
818
819#define OS_GETCWDB_METHODDEF \
820 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
821
822static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300823os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300824
825static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300826os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300827{
828 return os_getcwdb_impl(module);
829}
830
831#if defined(HAVE_LINK)
832
833PyDoc_STRVAR(os_link__doc__,
834"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
835" follow_symlinks=True)\n"
836"--\n"
837"\n"
838"Create a hard link to a file.\n"
839"\n"
840"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
841" descriptor open to a directory, and the respective path string (src or dst)\n"
842" should be relative; the path will then be relative to that directory.\n"
843"If follow_symlinks is False, and the last element of src is a symbolic\n"
844" link, link will create a link to the symbolic link itself instead of the\n"
845" file the link points to.\n"
846"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
847" platform. If they are unavailable, using them will raise a\n"
848" NotImplementedError.");
849
850#define OS_LINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700851 {"link", (PyCFunction)os_link, METH_FASTCALL, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300852
853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300854os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400855 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300856
857static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700858os_link(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300859{
860 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300861 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
862 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300863 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
864 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
865 int src_dir_fd = DEFAULT_DIR_FD;
866 int dst_dir_fd = DEFAULT_DIR_FD;
867 int follow_symlinks = 1;
868
Victor Stinner37e4ef72016-09-09 20:00:13 -0700869 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300870 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300873 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
874
875exit:
876 /* Cleanup for src */
877 path_cleanup(&src);
878 /* Cleanup for dst */
879 path_cleanup(&dst);
880
881 return return_value;
882}
883
884#endif /* defined(HAVE_LINK) */
885
886PyDoc_STRVAR(os_listdir__doc__,
887"listdir($module, /, path=None)\n"
888"--\n"
889"\n"
890"Return a list containing the names of the files in the directory.\n"
891"\n"
892"path can be specified as either str or bytes. If path is bytes,\n"
893" the filenames returned will also be bytes; in all other circumstances\n"
894" the filenames returned will be str.\n"
895"If path is None, uses the path=\'.\'.\n"
896"On some platforms, path may also be specified as an open file descriptor;\\\n"
897" the file descriptor must refer to a directory.\n"
898" If this functionality is unavailable, using it raises NotImplementedError.\n"
899"\n"
900"The list is in arbitrary order. It does not include the special\n"
901"entries \'.\' and \'..\' even if they are present in the directory.");
902
903#define OS_LISTDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700904 {"listdir", (PyCFunction)os_listdir, METH_FASTCALL, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300905
906static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300907os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300908
909static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700910os_listdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300911{
912 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300913 static const char * const _keywords[] = {"path", NULL};
914 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300915 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
916
Victor Stinner37e4ef72016-09-09 20:00:13 -0700917 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300918 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300921 return_value = os_listdir_impl(module, &path);
922
923exit:
924 /* Cleanup for path */
925 path_cleanup(&path);
926
927 return return_value;
928}
929
930#if defined(MS_WINDOWS)
931
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300932PyDoc_STRVAR(os__getfullpathname__doc__,
933"_getfullpathname($module, path, /)\n"
934"--\n"
935"\n");
936
937#define OS__GETFULLPATHNAME_METHODDEF \
938 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
939
940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300941os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300942
943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300944os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300945{
946 PyObject *return_value = NULL;
947 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
948
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300949 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300951 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300952 return_value = os__getfullpathname_impl(module, &path);
953
954exit:
955 /* Cleanup for path */
956 path_cleanup(&path);
957
958 return return_value;
959}
960
961#endif /* defined(MS_WINDOWS) */
962
963#if defined(MS_WINDOWS)
964
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300965PyDoc_STRVAR(os__getfinalpathname__doc__,
966"_getfinalpathname($module, path, /)\n"
967"--\n"
968"\n"
969"A helper function for samepath on windows.");
970
971#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300972 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300973
974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300975os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300976
977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300978os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979{
980 PyObject *return_value = NULL;
981 PyObject *path;
982
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300983 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300986 return_value = os__getfinalpathname_impl(module, path);
987
988exit:
989 return return_value;
990}
991
992#endif /* defined(MS_WINDOWS) */
993
994#if defined(MS_WINDOWS)
995
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300996PyDoc_STRVAR(os__isdir__doc__,
997"_isdir($module, path, /)\n"
998"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200999"\n"
1000"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001001
1002#define OS__ISDIR_METHODDEF \
1003 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1004
1005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001006os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010{
1011 PyObject *return_value = NULL;
1012 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1013
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001014 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001016 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001017 return_value = os__isdir_impl(module, &path);
1018
1019exit:
1020 /* Cleanup for path */
1021 path_cleanup(&path);
1022
1023 return return_value;
1024}
1025
1026#endif /* defined(MS_WINDOWS) */
1027
1028#if defined(MS_WINDOWS)
1029
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001030PyDoc_STRVAR(os__getvolumepathname__doc__,
1031"_getvolumepathname($module, /, path)\n"
1032"--\n"
1033"\n"
1034"A helper function for ismount on Win32.");
1035
1036#define OS__GETVOLUMEPATHNAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001037 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038
1039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001040os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001043os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044{
1045 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001046 static const char * const _keywords[] = {"path", NULL};
1047 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001048 PyObject *path;
1049
Victor Stinner37e4ef72016-09-09 20:00:13 -07001050 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001051 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001053 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001054 return_value = os__getvolumepathname_impl(module, path);
1055
1056exit:
1057 return return_value;
1058}
1059
1060#endif /* defined(MS_WINDOWS) */
1061
1062PyDoc_STRVAR(os_mkdir__doc__,
1063"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1064"--\n"
1065"\n"
1066"Create a directory.\n"
1067"\n"
1068"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1069" and path should be relative; path will then be relative to that directory.\n"
1070"dir_fd may not be implemented on your platform.\n"
1071" If it is unavailable, using it will raise a NotImplementedError.\n"
1072"\n"
1073"The mode argument is ignored on Windows.");
1074
1075#define OS_MKDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001076 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001077
1078static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001079os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001080
1081static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001082os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083{
1084 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001085 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1086 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001087 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1088 int mode = 511;
1089 int dir_fd = DEFAULT_DIR_FD;
1090
Victor Stinner37e4ef72016-09-09 20:00:13 -07001091 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001094 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001095 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1096
1097exit:
1098 /* Cleanup for path */
1099 path_cleanup(&path);
1100
1101 return return_value;
1102}
1103
1104#if defined(HAVE_NICE)
1105
1106PyDoc_STRVAR(os_nice__doc__,
1107"nice($module, increment, /)\n"
1108"--\n"
1109"\n"
1110"Add increment to the priority of process and return the new priority.");
1111
1112#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001113 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001114
1115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001116os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001117
1118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001119os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120{
1121 PyObject *return_value = NULL;
1122 int increment;
1123
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001124 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001127 return_value = os_nice_impl(module, increment);
1128
1129exit:
1130 return return_value;
1131}
1132
1133#endif /* defined(HAVE_NICE) */
1134
1135#if defined(HAVE_GETPRIORITY)
1136
1137PyDoc_STRVAR(os_getpriority__doc__,
1138"getpriority($module, /, which, who)\n"
1139"--\n"
1140"\n"
1141"Return program scheduling priority.");
1142
1143#define OS_GETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001144 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001145
1146static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001147os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001148
1149static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001150os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151{
1152 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001153 static const char * const _keywords[] = {"which", "who", NULL};
1154 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001155 int which;
1156 int who;
1157
Victor Stinner37e4ef72016-09-09 20:00:13 -07001158 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001159 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001162 return_value = os_getpriority_impl(module, which, who);
1163
1164exit:
1165 return return_value;
1166}
1167
1168#endif /* defined(HAVE_GETPRIORITY) */
1169
1170#if defined(HAVE_SETPRIORITY)
1171
1172PyDoc_STRVAR(os_setpriority__doc__,
1173"setpriority($module, /, which, who, priority)\n"
1174"--\n"
1175"\n"
1176"Set program scheduling priority.");
1177
1178#define OS_SETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001179 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001180
1181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001182os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001183
1184static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001185os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186{
1187 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001188 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1189 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001190 int which;
1191 int who;
1192 int priority;
1193
Victor Stinner37e4ef72016-09-09 20:00:13 -07001194 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001198 return_value = os_setpriority_impl(module, which, who, priority);
1199
1200exit:
1201 return return_value;
1202}
1203
1204#endif /* defined(HAVE_SETPRIORITY) */
1205
1206PyDoc_STRVAR(os_rename__doc__,
1207"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1208"--\n"
1209"\n"
1210"Rename a file or directory.\n"
1211"\n"
1212"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1213" descriptor open to a directory, and the respective path string (src or dst)\n"
1214" should be relative; the path will then be relative to that directory.\n"
1215"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1216" If they are unavailable, using them will raise a NotImplementedError.");
1217
1218#define OS_RENAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001219 {"rename", (PyCFunction)os_rename, METH_FASTCALL, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001220
1221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001222os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001223 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001224
1225static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001226os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001227{
1228 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001229 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1230 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001231 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1232 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1233 int src_dir_fd = DEFAULT_DIR_FD;
1234 int dst_dir_fd = DEFAULT_DIR_FD;
1235
Victor Stinner37e4ef72016-09-09 20:00:13 -07001236 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001237 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001240 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1241
1242exit:
1243 /* Cleanup for src */
1244 path_cleanup(&src);
1245 /* Cleanup for dst */
1246 path_cleanup(&dst);
1247
1248 return return_value;
1249}
1250
1251PyDoc_STRVAR(os_replace__doc__,
1252"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1253"--\n"
1254"\n"
1255"Rename a file or directory, overwriting the destination.\n"
1256"\n"
1257"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1258" descriptor open to a directory, and the respective path string (src or dst)\n"
1259" should be relative; the path will then be relative to that directory.\n"
1260"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1261" If they are unavailable, using them will raise a NotImplementedError.\"");
1262
1263#define OS_REPLACE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001264 {"replace", (PyCFunction)os_replace, METH_FASTCALL, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001265
1266static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001267os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1268 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001269
1270static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001271os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001272{
1273 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001274 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1275 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001276 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1277 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1278 int src_dir_fd = DEFAULT_DIR_FD;
1279 int dst_dir_fd = DEFAULT_DIR_FD;
1280
Victor Stinner37e4ef72016-09-09 20:00:13 -07001281 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001282 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001285 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1286
1287exit:
1288 /* Cleanup for src */
1289 path_cleanup(&src);
1290 /* Cleanup for dst */
1291 path_cleanup(&dst);
1292
1293 return return_value;
1294}
1295
1296PyDoc_STRVAR(os_rmdir__doc__,
1297"rmdir($module, /, path, *, dir_fd=None)\n"
1298"--\n"
1299"\n"
1300"Remove a directory.\n"
1301"\n"
1302"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1303" and path should be relative; path will then be relative to that directory.\n"
1304"dir_fd may not be implemented on your platform.\n"
1305" If it is unavailable, using it will raise a NotImplementedError.");
1306
1307#define OS_RMDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001308 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001309
1310static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001311os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001312
1313static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001314os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315{
1316 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001317 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1318 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001319 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1320 int dir_fd = DEFAULT_DIR_FD;
1321
Victor Stinner37e4ef72016-09-09 20:00:13 -07001322 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001323 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001324 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001325 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001326 return_value = os_rmdir_impl(module, &path, dir_fd);
1327
1328exit:
1329 /* Cleanup for path */
1330 path_cleanup(&path);
1331
1332 return return_value;
1333}
1334
1335#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1336
1337PyDoc_STRVAR(os_system__doc__,
1338"system($module, /, command)\n"
1339"--\n"
1340"\n"
1341"Execute the command in a subshell.");
1342
1343#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001344 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001345
1346static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001347os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348
1349static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001350os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351{
1352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001353 static const char * const _keywords[] = {"command", NULL};
1354 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001355 Py_UNICODE *command;
1356 long _return_value;
1357
Victor Stinner37e4ef72016-09-09 20:00:13 -07001358 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001359 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 return_value = PyLong_FromLong(_return_value);
1367
1368exit:
1369 return return_value;
1370}
1371
1372#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1373
1374#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1375
1376PyDoc_STRVAR(os_system__doc__,
1377"system($module, /, command)\n"
1378"--\n"
1379"\n"
1380"Execute the command in a subshell.");
1381
1382#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001383 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001384
1385static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001386os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001387
1388static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001389os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390{
1391 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001392 static const char * const _keywords[] = {"command", NULL};
1393 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001394 PyObject *command = NULL;
1395 long _return_value;
1396
Victor Stinner37e4ef72016-09-09 20:00:13 -07001397 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001398 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001399 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001400 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001401 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001402 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 return_value = PyLong_FromLong(_return_value);
1406
1407exit:
1408 /* Cleanup for command */
1409 Py_XDECREF(command);
1410
1411 return return_value;
1412}
1413
1414#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1415
1416PyDoc_STRVAR(os_umask__doc__,
1417"umask($module, mask, /)\n"
1418"--\n"
1419"\n"
1420"Set the current numeric umask and return the previous umask.");
1421
1422#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001423 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001424
1425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001426os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001427
1428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001429os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430{
1431 PyObject *return_value = NULL;
1432 int mask;
1433
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001437 return_value = os_umask_impl(module, mask);
1438
1439exit:
1440 return return_value;
1441}
1442
1443PyDoc_STRVAR(os_unlink__doc__,
1444"unlink($module, /, path, *, dir_fd=None)\n"
1445"--\n"
1446"\n"
1447"Remove a file (same as remove()).\n"
1448"\n"
1449"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1450" and path should be relative; path will then be relative to that directory.\n"
1451"dir_fd may not be implemented on your platform.\n"
1452" If it is unavailable, using it will raise a NotImplementedError.");
1453
1454#define OS_UNLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001455 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001456
1457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001458os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001459
1460static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001461os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462{
1463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001464 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1465 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001466 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1467 int dir_fd = DEFAULT_DIR_FD;
1468
Victor Stinner37e4ef72016-09-09 20:00:13 -07001469 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001473 return_value = os_unlink_impl(module, &path, dir_fd);
1474
1475exit:
1476 /* Cleanup for path */
1477 path_cleanup(&path);
1478
1479 return return_value;
1480}
1481
1482PyDoc_STRVAR(os_remove__doc__,
1483"remove($module, /, path, *, dir_fd=None)\n"
1484"--\n"
1485"\n"
1486"Remove a file (same as unlink()).\n"
1487"\n"
1488"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1489" and path should be relative; path will then be relative to that directory.\n"
1490"dir_fd may not be implemented on your platform.\n"
1491" If it is unavailable, using it will raise a NotImplementedError.");
1492
1493#define OS_REMOVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001494 {"remove", (PyCFunction)os_remove, METH_FASTCALL, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001495
1496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001497os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001498
1499static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001500os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501{
1502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001503 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1504 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001505 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1506 int dir_fd = DEFAULT_DIR_FD;
1507
Victor Stinner37e4ef72016-09-09 20:00:13 -07001508 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001512 return_value = os_remove_impl(module, &path, dir_fd);
1513
1514exit:
1515 /* Cleanup for path */
1516 path_cleanup(&path);
1517
1518 return return_value;
1519}
1520
1521#if defined(HAVE_UNAME)
1522
1523PyDoc_STRVAR(os_uname__doc__,
1524"uname($module, /)\n"
1525"--\n"
1526"\n"
1527"Return an object identifying the current operating system.\n"
1528"\n"
1529"The object behaves like a named tuple with the following fields:\n"
1530" (sysname, nodename, release, version, machine)");
1531
1532#define OS_UNAME_METHODDEF \
1533 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1534
1535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001536os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001537
1538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001539os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001540{
1541 return os_uname_impl(module);
1542}
1543
1544#endif /* defined(HAVE_UNAME) */
1545
1546PyDoc_STRVAR(os_utime__doc__,
1547"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1548" follow_symlinks=True)\n"
1549"--\n"
1550"\n"
1551"Set the access and modified time of path.\n"
1552"\n"
1553"path may always be specified as a string.\n"
1554"On some platforms, path may also be specified as an open file descriptor.\n"
1555" If this functionality is unavailable, using it raises an exception.\n"
1556"\n"
1557"If times is not None, it must be a tuple (atime, mtime);\n"
1558" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001559"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001560" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1561" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001562"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001563"Specifying tuples for both times and ns is an error.\n"
1564"\n"
1565"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1566" and path should be relative; path will then be relative to that directory.\n"
1567"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1568" link, utime will modify the symbolic link itself instead of the file the\n"
1569" link points to.\n"
1570"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1571" as an open file descriptor.\n"
1572"dir_fd and follow_symlinks may not be available on your platform.\n"
1573" If they are unavailable, using them will raise a NotImplementedError.");
1574
1575#define OS_UTIME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001576 {"utime", (PyCFunction)os_utime, METH_FASTCALL, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001577
1578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001579os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1580 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581
1582static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001583os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001584{
1585 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001586 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1587 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001588 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1589 PyObject *times = NULL;
1590 PyObject *ns = NULL;
1591 int dir_fd = DEFAULT_DIR_FD;
1592 int follow_symlinks = 1;
1593
Victor Stinner37e4ef72016-09-09 20:00:13 -07001594 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001598 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1599
1600exit:
1601 /* Cleanup for path */
1602 path_cleanup(&path);
1603
1604 return return_value;
1605}
1606
1607PyDoc_STRVAR(os__exit__doc__,
1608"_exit($module, /, status)\n"
1609"--\n"
1610"\n"
1611"Exit to the system with specified status, without normal exit processing.");
1612
1613#define OS__EXIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001614 {"_exit", (PyCFunction)os__exit, METH_FASTCALL, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001615
1616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001617os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001618
1619static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001620os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621{
1622 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001623 static const char * const _keywords[] = {"status", NULL};
1624 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001625 int status;
1626
Victor Stinner37e4ef72016-09-09 20:00:13 -07001627 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001630 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 return_value = os__exit_impl(module, status);
1632
1633exit:
1634 return return_value;
1635}
1636
1637#if defined(HAVE_EXECV)
1638
1639PyDoc_STRVAR(os_execv__doc__,
1640"execv($module, path, argv, /)\n"
1641"--\n"
1642"\n"
1643"Execute an executable path with arguments, replacing current process.\n"
1644"\n"
1645" path\n"
1646" Path of executable file.\n"
1647" argv\n"
1648" Tuple or list of strings.");
1649
1650#define OS_EXECV_METHODDEF \
1651 {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
1652
1653static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001654os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001655
1656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001657os_execv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658{
1659 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001660 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661 PyObject *argv;
1662
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001663 if (!PyArg_ParseTuple(args, "O&O:execv",
Steve Dowercc16be82016-09-08 10:35:16 -07001664 path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001665 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001666 }
Steve Dowercc16be82016-09-08 10:35:16 -07001667 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001668
1669exit:
1670 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001671 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001672
1673 return return_value;
1674}
1675
1676#endif /* defined(HAVE_EXECV) */
1677
1678#if defined(HAVE_EXECV)
1679
1680PyDoc_STRVAR(os_execve__doc__,
1681"execve($module, /, path, argv, env)\n"
1682"--\n"
1683"\n"
1684"Execute an executable path with arguments, replacing current process.\n"
1685"\n"
1686" path\n"
1687" Path of executable file.\n"
1688" argv\n"
1689" Tuple or list of strings.\n"
1690" env\n"
1691" Dictionary of strings mapping to strings.");
1692
1693#define OS_EXECVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001694 {"execve", (PyCFunction)os_execve, METH_FASTCALL, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001695
1696static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001697os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001698
1699static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001700os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001701{
1702 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001703 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1704 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001705 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1706 PyObject *argv;
1707 PyObject *env;
1708
Victor Stinner37e4ef72016-09-09 20:00:13 -07001709 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001710 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001712 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001713 return_value = os_execve_impl(module, &path, argv, env);
1714
1715exit:
1716 /* Cleanup for path */
1717 path_cleanup(&path);
1718
1719 return return_value;
1720}
1721
1722#endif /* defined(HAVE_EXECV) */
1723
Steve Dowercc16be82016-09-08 10:35:16 -07001724#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001725
1726PyDoc_STRVAR(os_spawnv__doc__,
1727"spawnv($module, mode, path, argv, /)\n"
1728"--\n"
1729"\n"
1730"Execute the program specified by path in a new process.\n"
1731"\n"
1732" mode\n"
1733" Mode of process creation.\n"
1734" path\n"
1735" Path of executable file.\n"
1736" argv\n"
1737" Tuple or list of strings.");
1738
1739#define OS_SPAWNV_METHODDEF \
1740 {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
1741
1742static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001743os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001744
1745static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001746os_spawnv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001747{
1748 PyObject *return_value = NULL;
1749 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001750 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001751 PyObject *argv;
1752
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001753 if (!PyArg_ParseTuple(args, "iO&O:spawnv",
Steve Dowercc16be82016-09-08 10:35:16 -07001754 &mode, path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001755 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001756 }
Steve Dowercc16be82016-09-08 10:35:16 -07001757 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001758
1759exit:
1760 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001761 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001762
1763 return return_value;
1764}
1765
Steve Dowercc16be82016-09-08 10:35:16 -07001766#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001767
Steve Dowercc16be82016-09-08 10:35:16 -07001768#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001769
1770PyDoc_STRVAR(os_spawnve__doc__,
1771"spawnve($module, mode, path, argv, env, /)\n"
1772"--\n"
1773"\n"
1774"Execute the program specified by path in a new process.\n"
1775"\n"
1776" mode\n"
1777" Mode of process creation.\n"
1778" path\n"
1779" Path of executable file.\n"
1780" argv\n"
1781" Tuple or list of strings.\n"
1782" env\n"
1783" Dictionary of strings mapping to strings.");
1784
1785#define OS_SPAWNVE_METHODDEF \
1786 {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
1787
1788static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001789os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001790 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001791
1792static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001793os_spawnve(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001794{
1795 PyObject *return_value = NULL;
1796 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001797 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001798 PyObject *argv;
1799 PyObject *env;
1800
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001801 if (!PyArg_ParseTuple(args, "iO&OO:spawnve",
Steve Dowercc16be82016-09-08 10:35:16 -07001802 &mode, path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001803 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001804 }
Steve Dowercc16be82016-09-08 10:35:16 -07001805 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001806
1807exit:
1808 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001809 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001810
1811 return return_value;
1812}
1813
Steve Dowercc16be82016-09-08 10:35:16 -07001814#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001815
1816#if defined(HAVE_FORK1)
1817
1818PyDoc_STRVAR(os_fork1__doc__,
1819"fork1($module, /)\n"
1820"--\n"
1821"\n"
1822"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1823"\n"
1824"Return 0 to child process and PID of child to parent process.");
1825
1826#define OS_FORK1_METHODDEF \
1827 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1828
1829static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001830os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001831
1832static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001833os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001834{
1835 return os_fork1_impl(module);
1836}
1837
1838#endif /* defined(HAVE_FORK1) */
1839
1840#if defined(HAVE_FORK)
1841
1842PyDoc_STRVAR(os_fork__doc__,
1843"fork($module, /)\n"
1844"--\n"
1845"\n"
1846"Fork a child process.\n"
1847"\n"
1848"Return 0 to child process and PID of child to parent process.");
1849
1850#define OS_FORK_METHODDEF \
1851 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1852
1853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001854os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001855
1856static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001857os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001858{
1859 return os_fork_impl(module);
1860}
1861
1862#endif /* defined(HAVE_FORK) */
1863
1864#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1865
1866PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1867"sched_get_priority_max($module, /, policy)\n"
1868"--\n"
1869"\n"
1870"Get the maximum scheduling priority for policy.");
1871
1872#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001873 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_FASTCALL, os_sched_get_priority_max__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001874
1875static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001876os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001877
1878static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001879os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001880{
1881 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001882 static const char * const _keywords[] = {"policy", NULL};
1883 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001884 int policy;
1885
Victor Stinner37e4ef72016-09-09 20:00:13 -07001886 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001887 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001888 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001889 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001890 return_value = os_sched_get_priority_max_impl(module, policy);
1891
1892exit:
1893 return return_value;
1894}
1895
1896#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1897
1898#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1899
1900PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1901"sched_get_priority_min($module, /, policy)\n"
1902"--\n"
1903"\n"
1904"Get the minimum scheduling priority for policy.");
1905
1906#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001907 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_FASTCALL, os_sched_get_priority_min__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001908
1909static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001910os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001911
1912static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001913os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001914{
1915 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001916 static const char * const _keywords[] = {"policy", NULL};
1917 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001918 int policy;
1919
Victor Stinner37e4ef72016-09-09 20:00:13 -07001920 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001921 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001922 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001923 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001924 return_value = os_sched_get_priority_min_impl(module, policy);
1925
1926exit:
1927 return return_value;
1928}
1929
1930#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1931
1932#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1933
1934PyDoc_STRVAR(os_sched_getscheduler__doc__,
1935"sched_getscheduler($module, pid, /)\n"
1936"--\n"
1937"\n"
1938"Get the scheduling policy for the process identifiedy by pid.\n"
1939"\n"
1940"Passing 0 for pid returns the scheduling policy for the calling process.");
1941
1942#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001943 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001944
1945static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001946os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001947
1948static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001949os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001950{
1951 PyObject *return_value = NULL;
1952 pid_t pid;
1953
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001954 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001955 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001956 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001957 return_value = os_sched_getscheduler_impl(module, pid);
1958
1959exit:
1960 return return_value;
1961}
1962
1963#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1964
1965#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1966
1967PyDoc_STRVAR(os_sched_param__doc__,
1968"sched_param(sched_priority)\n"
1969"--\n"
1970"\n"
1971"Current has only one field: sched_priority\");\n"
1972"\n"
1973" sched_priority\n"
1974" A scheduling parameter.");
1975
1976static PyObject *
1977os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1978
1979static PyObject *
1980os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1981{
1982 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001983 static const char * const _keywords[] = {"sched_priority", NULL};
1984 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001985 PyObject *sched_priority;
1986
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001987 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001988 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001989 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001990 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001991 return_value = os_sched_param_impl(type, sched_priority);
1992
1993exit:
1994 return return_value;
1995}
1996
1997#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
1998
1999#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2000
2001PyDoc_STRVAR(os_sched_setscheduler__doc__,
2002"sched_setscheduler($module, pid, policy, param, /)\n"
2003"--\n"
2004"\n"
2005"Set the scheduling policy for the process identified by pid.\n"
2006"\n"
2007"If pid is 0, the calling process is changed.\n"
2008"param is an instance of sched_param.");
2009
2010#define OS_SCHED_SETSCHEDULER_METHODDEF \
2011 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
2012
2013static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002014os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002015 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002016
2017static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002018os_sched_setscheduler(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002019{
2020 PyObject *return_value = NULL;
2021 pid_t pid;
2022 int policy;
2023 struct sched_param param;
2024
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002025 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002026 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002027 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002028 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002029 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2030
2031exit:
2032 return return_value;
2033}
2034
2035#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2036
2037#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2038
2039PyDoc_STRVAR(os_sched_getparam__doc__,
2040"sched_getparam($module, pid, /)\n"
2041"--\n"
2042"\n"
2043"Returns scheduling parameters for the process identified by pid.\n"
2044"\n"
2045"If pid is 0, returns parameters for the calling process.\n"
2046"Return value is an instance of sched_param.");
2047
2048#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002049 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002050
2051static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002052os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002053
2054static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002055os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002056{
2057 PyObject *return_value = NULL;
2058 pid_t pid;
2059
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002060 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002061 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002062 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002063 return_value = os_sched_getparam_impl(module, pid);
2064
2065exit:
2066 return return_value;
2067}
2068
2069#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2070
2071#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2072
2073PyDoc_STRVAR(os_sched_setparam__doc__,
2074"sched_setparam($module, pid, param, /)\n"
2075"--\n"
2076"\n"
2077"Set scheduling parameters for the process identified by pid.\n"
2078"\n"
2079"If pid is 0, sets parameters for the calling process.\n"
2080"param should be an instance of sched_param.");
2081
2082#define OS_SCHED_SETPARAM_METHODDEF \
2083 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
2084
2085static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002086os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002087 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002088
2089static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002090os_sched_setparam(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002091{
2092 PyObject *return_value = NULL;
2093 pid_t pid;
2094 struct sched_param param;
2095
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002096 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002097 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002098 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002099 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002100 return_value = os_sched_setparam_impl(module, pid, &param);
2101
2102exit:
2103 return return_value;
2104}
2105
2106#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2107
2108#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2109
2110PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2111"sched_rr_get_interval($module, pid, /)\n"
2112"--\n"
2113"\n"
2114"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2115"\n"
2116"Value returned is a float.");
2117
2118#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002119 {"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 +03002120
2121static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002122os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002123
2124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002125os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002126{
2127 PyObject *return_value = NULL;
2128 pid_t pid;
2129 double _return_value;
2130
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002131 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002132 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002133 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002135 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002136 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002137 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002138 return_value = PyFloat_FromDouble(_return_value);
2139
2140exit:
2141 return return_value;
2142}
2143
2144#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2145
2146#if defined(HAVE_SCHED_H)
2147
2148PyDoc_STRVAR(os_sched_yield__doc__,
2149"sched_yield($module, /)\n"
2150"--\n"
2151"\n"
2152"Voluntarily relinquish the CPU.");
2153
2154#define OS_SCHED_YIELD_METHODDEF \
2155 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2156
2157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002158os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002159
2160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002161os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002162{
2163 return os_sched_yield_impl(module);
2164}
2165
2166#endif /* defined(HAVE_SCHED_H) */
2167
2168#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2169
2170PyDoc_STRVAR(os_sched_setaffinity__doc__,
2171"sched_setaffinity($module, pid, mask, /)\n"
2172"--\n"
2173"\n"
2174"Set the CPU affinity of the process identified by pid to mask.\n"
2175"\n"
2176"mask should be an iterable of integers identifying CPUs.");
2177
2178#define OS_SCHED_SETAFFINITY_METHODDEF \
2179 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
2180
2181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002182os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002183
2184static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002185os_sched_setaffinity(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186{
2187 PyObject *return_value = NULL;
2188 pid_t pid;
2189 PyObject *mask;
2190
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002191 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002192 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002193 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002194 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002195 return_value = os_sched_setaffinity_impl(module, pid, mask);
2196
2197exit:
2198 return return_value;
2199}
2200
2201#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2202
2203#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2204
2205PyDoc_STRVAR(os_sched_getaffinity__doc__,
2206"sched_getaffinity($module, pid, /)\n"
2207"--\n"
2208"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002209"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002210"\n"
2211"The affinity is returned as a set of CPU identifiers.");
2212
2213#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002214 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002215
2216static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002217os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002218
2219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002220os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002221{
2222 PyObject *return_value = NULL;
2223 pid_t pid;
2224
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002225 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002226 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002227 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002228 return_value = os_sched_getaffinity_impl(module, pid);
2229
2230exit:
2231 return return_value;
2232}
2233
2234#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2235
2236#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2237
2238PyDoc_STRVAR(os_openpty__doc__,
2239"openpty($module, /)\n"
2240"--\n"
2241"\n"
2242"Open a pseudo-terminal.\n"
2243"\n"
2244"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2245"for both the master and slave ends.");
2246
2247#define OS_OPENPTY_METHODDEF \
2248 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2249
2250static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002251os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002252
2253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002254os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002255{
2256 return os_openpty_impl(module);
2257}
2258
2259#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2260
2261#if defined(HAVE_FORKPTY)
2262
2263PyDoc_STRVAR(os_forkpty__doc__,
2264"forkpty($module, /)\n"
2265"--\n"
2266"\n"
2267"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2268"\n"
2269"Returns a tuple of (pid, master_fd).\n"
2270"Like fork(), return pid of 0 to the child process,\n"
2271"and pid of child to the parent process.\n"
2272"To both, return fd of newly opened pseudo-terminal.");
2273
2274#define OS_FORKPTY_METHODDEF \
2275 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2276
2277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002278os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002279
2280static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002281os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002282{
2283 return os_forkpty_impl(module);
2284}
2285
2286#endif /* defined(HAVE_FORKPTY) */
2287
2288#if defined(HAVE_GETEGID)
2289
2290PyDoc_STRVAR(os_getegid__doc__,
2291"getegid($module, /)\n"
2292"--\n"
2293"\n"
2294"Return the current process\'s effective group id.");
2295
2296#define OS_GETEGID_METHODDEF \
2297 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2298
2299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002300os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002301
2302static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002303os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002304{
2305 return os_getegid_impl(module);
2306}
2307
2308#endif /* defined(HAVE_GETEGID) */
2309
2310#if defined(HAVE_GETEUID)
2311
2312PyDoc_STRVAR(os_geteuid__doc__,
2313"geteuid($module, /)\n"
2314"--\n"
2315"\n"
2316"Return the current process\'s effective user id.");
2317
2318#define OS_GETEUID_METHODDEF \
2319 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2320
2321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002322os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002323
2324static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002325os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002326{
2327 return os_geteuid_impl(module);
2328}
2329
2330#endif /* defined(HAVE_GETEUID) */
2331
2332#if defined(HAVE_GETGID)
2333
2334PyDoc_STRVAR(os_getgid__doc__,
2335"getgid($module, /)\n"
2336"--\n"
2337"\n"
2338"Return the current process\'s group id.");
2339
2340#define OS_GETGID_METHODDEF \
2341 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2342
2343static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002344os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002345
2346static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002347os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002348{
2349 return os_getgid_impl(module);
2350}
2351
2352#endif /* defined(HAVE_GETGID) */
2353
Berker Peksag39404992016-09-15 20:45:16 +03002354#if defined(HAVE_GETPID)
2355
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002356PyDoc_STRVAR(os_getpid__doc__,
2357"getpid($module, /)\n"
2358"--\n"
2359"\n"
2360"Return the current process id.");
2361
2362#define OS_GETPID_METHODDEF \
2363 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2364
2365static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002366os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002367
2368static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002369os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002370{
2371 return os_getpid_impl(module);
2372}
2373
Berker Peksag39404992016-09-15 20:45:16 +03002374#endif /* defined(HAVE_GETPID) */
2375
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002376#if defined(HAVE_GETGROUPS)
2377
2378PyDoc_STRVAR(os_getgroups__doc__,
2379"getgroups($module, /)\n"
2380"--\n"
2381"\n"
2382"Return list of supplemental group IDs for the process.");
2383
2384#define OS_GETGROUPS_METHODDEF \
2385 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2386
2387static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002388os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002389
2390static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002391os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002392{
2393 return os_getgroups_impl(module);
2394}
2395
2396#endif /* defined(HAVE_GETGROUPS) */
2397
2398#if defined(HAVE_GETPGID)
2399
2400PyDoc_STRVAR(os_getpgid__doc__,
2401"getpgid($module, /, pid)\n"
2402"--\n"
2403"\n"
2404"Call the system call getpgid(), and return the result.");
2405
2406#define OS_GETPGID_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002407 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002408
2409static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002410os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002411
2412static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002413os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002414{
2415 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002416 static const char * const _keywords[] = {"pid", NULL};
2417 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002418 pid_t pid;
2419
Victor Stinner37e4ef72016-09-09 20:00:13 -07002420 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002421 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002424 return_value = os_getpgid_impl(module, pid);
2425
2426exit:
2427 return return_value;
2428}
2429
2430#endif /* defined(HAVE_GETPGID) */
2431
2432#if defined(HAVE_GETPGRP)
2433
2434PyDoc_STRVAR(os_getpgrp__doc__,
2435"getpgrp($module, /)\n"
2436"--\n"
2437"\n"
2438"Return the current process group id.");
2439
2440#define OS_GETPGRP_METHODDEF \
2441 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2442
2443static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002444os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002445
2446static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002447os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002448{
2449 return os_getpgrp_impl(module);
2450}
2451
2452#endif /* defined(HAVE_GETPGRP) */
2453
2454#if defined(HAVE_SETPGRP)
2455
2456PyDoc_STRVAR(os_setpgrp__doc__,
2457"setpgrp($module, /)\n"
2458"--\n"
2459"\n"
2460"Make the current process the leader of its process group.");
2461
2462#define OS_SETPGRP_METHODDEF \
2463 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2464
2465static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002466os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002467
2468static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002469os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002470{
2471 return os_setpgrp_impl(module);
2472}
2473
2474#endif /* defined(HAVE_SETPGRP) */
2475
2476#if defined(HAVE_GETPPID)
2477
2478PyDoc_STRVAR(os_getppid__doc__,
2479"getppid($module, /)\n"
2480"--\n"
2481"\n"
2482"Return the parent\'s process id.\n"
2483"\n"
2484"If the parent process has already exited, Windows machines will still\n"
2485"return its id; others systems will return the id of the \'init\' process (1).");
2486
2487#define OS_GETPPID_METHODDEF \
2488 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2489
2490static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002491os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002492
2493static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002494os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002495{
2496 return os_getppid_impl(module);
2497}
2498
2499#endif /* defined(HAVE_GETPPID) */
2500
2501#if defined(HAVE_GETLOGIN)
2502
2503PyDoc_STRVAR(os_getlogin__doc__,
2504"getlogin($module, /)\n"
2505"--\n"
2506"\n"
2507"Return the actual login name.");
2508
2509#define OS_GETLOGIN_METHODDEF \
2510 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2511
2512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002513os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002514
2515static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002516os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002517{
2518 return os_getlogin_impl(module);
2519}
2520
2521#endif /* defined(HAVE_GETLOGIN) */
2522
2523#if defined(HAVE_GETUID)
2524
2525PyDoc_STRVAR(os_getuid__doc__,
2526"getuid($module, /)\n"
2527"--\n"
2528"\n"
2529"Return the current process\'s user id.");
2530
2531#define OS_GETUID_METHODDEF \
2532 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2533
2534static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002535os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002536
2537static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002538os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002539{
2540 return os_getuid_impl(module);
2541}
2542
2543#endif /* defined(HAVE_GETUID) */
2544
2545#if defined(HAVE_KILL)
2546
2547PyDoc_STRVAR(os_kill__doc__,
2548"kill($module, pid, signal, /)\n"
2549"--\n"
2550"\n"
2551"Kill a process with a signal.");
2552
2553#define OS_KILL_METHODDEF \
2554 {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
2555
2556static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002557os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002558
2559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002560os_kill(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002561{
2562 PyObject *return_value = NULL;
2563 pid_t pid;
2564 Py_ssize_t signal;
2565
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002566 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002567 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002568 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002569 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002570 return_value = os_kill_impl(module, pid, signal);
2571
2572exit:
2573 return return_value;
2574}
2575
2576#endif /* defined(HAVE_KILL) */
2577
2578#if defined(HAVE_KILLPG)
2579
2580PyDoc_STRVAR(os_killpg__doc__,
2581"killpg($module, pgid, signal, /)\n"
2582"--\n"
2583"\n"
2584"Kill a process group with a signal.");
2585
2586#define OS_KILLPG_METHODDEF \
2587 {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
2588
2589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002590os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002591
2592static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002593os_killpg(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002594{
2595 PyObject *return_value = NULL;
2596 pid_t pgid;
2597 int signal;
2598
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002599 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002600 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002601 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002602 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002603 return_value = os_killpg_impl(module, pgid, signal);
2604
2605exit:
2606 return return_value;
2607}
2608
2609#endif /* defined(HAVE_KILLPG) */
2610
2611#if defined(HAVE_PLOCK)
2612
2613PyDoc_STRVAR(os_plock__doc__,
2614"plock($module, op, /)\n"
2615"--\n"
2616"\n"
2617"Lock program segments into memory.\");");
2618
2619#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002620 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002621
2622static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002623os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002624
2625static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002626os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002627{
2628 PyObject *return_value = NULL;
2629 int op;
2630
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002631 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002632 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002633 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002634 return_value = os_plock_impl(module, op);
2635
2636exit:
2637 return return_value;
2638}
2639
2640#endif /* defined(HAVE_PLOCK) */
2641
2642#if defined(HAVE_SETUID)
2643
2644PyDoc_STRVAR(os_setuid__doc__,
2645"setuid($module, uid, /)\n"
2646"--\n"
2647"\n"
2648"Set the current process\'s user id.");
2649
2650#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002651 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002652
2653static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002654os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002655
2656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002657os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002658{
2659 PyObject *return_value = NULL;
2660 uid_t uid;
2661
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002662 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002664 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002665 return_value = os_setuid_impl(module, uid);
2666
2667exit:
2668 return return_value;
2669}
2670
2671#endif /* defined(HAVE_SETUID) */
2672
2673#if defined(HAVE_SETEUID)
2674
2675PyDoc_STRVAR(os_seteuid__doc__,
2676"seteuid($module, euid, /)\n"
2677"--\n"
2678"\n"
2679"Set the current process\'s effective user id.");
2680
2681#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002682 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002683
2684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002685os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002686
2687static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002688os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002689{
2690 PyObject *return_value = NULL;
2691 uid_t euid;
2692
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002693 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002694 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002695 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002696 return_value = os_seteuid_impl(module, euid);
2697
2698exit:
2699 return return_value;
2700}
2701
2702#endif /* defined(HAVE_SETEUID) */
2703
2704#if defined(HAVE_SETEGID)
2705
2706PyDoc_STRVAR(os_setegid__doc__,
2707"setegid($module, egid, /)\n"
2708"--\n"
2709"\n"
2710"Set the current process\'s effective group id.");
2711
2712#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002713 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002714
2715static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002716os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002717
2718static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002719os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002720{
2721 PyObject *return_value = NULL;
2722 gid_t egid;
2723
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002724 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002725 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002726 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002727 return_value = os_setegid_impl(module, egid);
2728
2729exit:
2730 return return_value;
2731}
2732
2733#endif /* defined(HAVE_SETEGID) */
2734
2735#if defined(HAVE_SETREUID)
2736
2737PyDoc_STRVAR(os_setreuid__doc__,
2738"setreuid($module, ruid, euid, /)\n"
2739"--\n"
2740"\n"
2741"Set the current process\'s real and effective user ids.");
2742
2743#define OS_SETREUID_METHODDEF \
2744 {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
2745
2746static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002747os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002748
2749static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002750os_setreuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002751{
2752 PyObject *return_value = NULL;
2753 uid_t ruid;
2754 uid_t euid;
2755
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002756 if (!PyArg_ParseTuple(args, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002757 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002758 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002759 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002760 return_value = os_setreuid_impl(module, ruid, euid);
2761
2762exit:
2763 return return_value;
2764}
2765
2766#endif /* defined(HAVE_SETREUID) */
2767
2768#if defined(HAVE_SETREGID)
2769
2770PyDoc_STRVAR(os_setregid__doc__,
2771"setregid($module, rgid, egid, /)\n"
2772"--\n"
2773"\n"
2774"Set the current process\'s real and effective group ids.");
2775
2776#define OS_SETREGID_METHODDEF \
2777 {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
2778
2779static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002780os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002781
2782static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002783os_setregid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002784{
2785 PyObject *return_value = NULL;
2786 gid_t rgid;
2787 gid_t egid;
2788
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002789 if (!PyArg_ParseTuple(args, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002790 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002791 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002792 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002793 return_value = os_setregid_impl(module, rgid, egid);
2794
2795exit:
2796 return return_value;
2797}
2798
2799#endif /* defined(HAVE_SETREGID) */
2800
2801#if defined(HAVE_SETGID)
2802
2803PyDoc_STRVAR(os_setgid__doc__,
2804"setgid($module, gid, /)\n"
2805"--\n"
2806"\n"
2807"Set the current process\'s group id.");
2808
2809#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002810 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002811
2812static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002813os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002814
2815static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002816os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002817{
2818 PyObject *return_value = NULL;
2819 gid_t gid;
2820
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002821 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002822 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002823 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002824 return_value = os_setgid_impl(module, gid);
2825
2826exit:
2827 return return_value;
2828}
2829
2830#endif /* defined(HAVE_SETGID) */
2831
2832#if defined(HAVE_SETGROUPS)
2833
2834PyDoc_STRVAR(os_setgroups__doc__,
2835"setgroups($module, groups, /)\n"
2836"--\n"
2837"\n"
2838"Set the groups of the current process to list.");
2839
2840#define OS_SETGROUPS_METHODDEF \
2841 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2842
2843#endif /* defined(HAVE_SETGROUPS) */
2844
2845#if defined(HAVE_WAIT3)
2846
2847PyDoc_STRVAR(os_wait3__doc__,
2848"wait3($module, /, options)\n"
2849"--\n"
2850"\n"
2851"Wait for completion of a child process.\n"
2852"\n"
2853"Returns a tuple of information about the child process:\n"
2854" (pid, status, rusage)");
2855
2856#define OS_WAIT3_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002857 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002858
2859static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002860os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002861
2862static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002863os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002864{
2865 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002866 static const char * const _keywords[] = {"options", NULL};
2867 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002868 int options;
2869
Victor Stinner37e4ef72016-09-09 20:00:13 -07002870 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002871 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002872 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002873 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002874 return_value = os_wait3_impl(module, options);
2875
2876exit:
2877 return return_value;
2878}
2879
2880#endif /* defined(HAVE_WAIT3) */
2881
2882#if defined(HAVE_WAIT4)
2883
2884PyDoc_STRVAR(os_wait4__doc__,
2885"wait4($module, /, pid, options)\n"
2886"--\n"
2887"\n"
2888"Wait for completion of a specific child process.\n"
2889"\n"
2890"Returns a tuple of information about the child process:\n"
2891" (pid, status, rusage)");
2892
2893#define OS_WAIT4_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002894 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002895
2896static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002897os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002898
2899static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002900os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002901{
2902 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002903 static const char * const _keywords[] = {"pid", "options", NULL};
2904 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002905 pid_t pid;
2906 int options;
2907
Victor Stinner37e4ef72016-09-09 20:00:13 -07002908 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002909 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002910 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002911 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912 return_value = os_wait4_impl(module, pid, options);
2913
2914exit:
2915 return return_value;
2916}
2917
2918#endif /* defined(HAVE_WAIT4) */
2919
2920#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2921
2922PyDoc_STRVAR(os_waitid__doc__,
2923"waitid($module, idtype, id, options, /)\n"
2924"--\n"
2925"\n"
2926"Returns the result of waiting for a process or processes.\n"
2927"\n"
2928" idtype\n"
2929" Must be one of be P_PID, P_PGID or P_ALL.\n"
2930" id\n"
2931" The id to wait on.\n"
2932" options\n"
2933" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2934" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2935"\n"
2936"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2937"no children in a waitable state.");
2938
2939#define OS_WAITID_METHODDEF \
2940 {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
2941
2942static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002943os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002944
2945static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002946os_waitid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002947{
2948 PyObject *return_value = NULL;
2949 idtype_t idtype;
2950 id_t id;
2951 int options;
2952
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002953 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002954 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002955 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002956 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002957 return_value = os_waitid_impl(module, idtype, id, options);
2958
2959exit:
2960 return return_value;
2961}
2962
2963#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
2964
2965#if defined(HAVE_WAITPID)
2966
2967PyDoc_STRVAR(os_waitpid__doc__,
2968"waitpid($module, pid, options, /)\n"
2969"--\n"
2970"\n"
2971"Wait for completion of a given child process.\n"
2972"\n"
2973"Returns a tuple of information regarding the child process:\n"
2974" (pid, status)\n"
2975"\n"
2976"The options argument is ignored on Windows.");
2977
2978#define OS_WAITPID_METHODDEF \
2979 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2980
2981static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002982os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002983
2984static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002985os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002986{
2987 PyObject *return_value = NULL;
2988 pid_t pid;
2989 int options;
2990
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002991 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002992 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002993 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002994 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995 return_value = os_waitpid_impl(module, pid, options);
2996
2997exit:
2998 return return_value;
2999}
3000
3001#endif /* defined(HAVE_WAITPID) */
3002
3003#if defined(HAVE_CWAIT)
3004
3005PyDoc_STRVAR(os_waitpid__doc__,
3006"waitpid($module, pid, options, /)\n"
3007"--\n"
3008"\n"
3009"Wait for completion of a given process.\n"
3010"\n"
3011"Returns a tuple of information regarding the process:\n"
3012" (pid, status << 8)\n"
3013"\n"
3014"The options argument is ignored on Windows.");
3015
3016#define OS_WAITPID_METHODDEF \
3017 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
3018
3019static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003020os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003021
3022static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003023os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003024{
3025 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003026 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003027 int options;
3028
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003029 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003030 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003031 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003032 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003033 return_value = os_waitpid_impl(module, pid, options);
3034
3035exit:
3036 return return_value;
3037}
3038
3039#endif /* defined(HAVE_CWAIT) */
3040
3041#if defined(HAVE_WAIT)
3042
3043PyDoc_STRVAR(os_wait__doc__,
3044"wait($module, /)\n"
3045"--\n"
3046"\n"
3047"Wait for completion of a child process.\n"
3048"\n"
3049"Returns a tuple of information about the child process:\n"
3050" (pid, status)");
3051
3052#define OS_WAIT_METHODDEF \
3053 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3054
3055static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003056os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003057
3058static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003059os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003060{
3061 return os_wait_impl(module);
3062}
3063
3064#endif /* defined(HAVE_WAIT) */
3065
3066#if defined(HAVE_SYMLINK)
3067
3068PyDoc_STRVAR(os_symlink__doc__,
3069"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3070"--\n"
3071"\n"
3072"Create a symbolic link pointing to src named dst.\n"
3073"\n"
3074"target_is_directory is required on Windows if the target is to be\n"
3075" interpreted as a directory. (On Windows, symlink requires\n"
3076" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3077" target_is_directory is ignored on non-Windows platforms.\n"
3078"\n"
3079"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3080" and path should be relative; path will then be relative to that directory.\n"
3081"dir_fd may not be implemented on your platform.\n"
3082" If it is unavailable, using it will raise a NotImplementedError.");
3083
3084#define OS_SYMLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003085 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003086
3087static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003088os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003089 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003090
3091static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003092os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003093{
3094 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003095 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3096 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003097 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3098 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3099 int target_is_directory = 0;
3100 int dir_fd = DEFAULT_DIR_FD;
3101
Victor Stinner37e4ef72016-09-09 20:00:13 -07003102 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003103 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003105 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003106 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3107
3108exit:
3109 /* Cleanup for src */
3110 path_cleanup(&src);
3111 /* Cleanup for dst */
3112 path_cleanup(&dst);
3113
3114 return return_value;
3115}
3116
3117#endif /* defined(HAVE_SYMLINK) */
3118
3119#if defined(HAVE_TIMES)
3120
3121PyDoc_STRVAR(os_times__doc__,
3122"times($module, /)\n"
3123"--\n"
3124"\n"
3125"Return a collection containing process timing information.\n"
3126"\n"
3127"The object returned behaves like a named tuple with these fields:\n"
3128" (utime, stime, cutime, cstime, elapsed_time)\n"
3129"All fields are floating point numbers.");
3130
3131#define OS_TIMES_METHODDEF \
3132 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3133
3134static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003135os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003136
3137static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003138os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003139{
3140 return os_times_impl(module);
3141}
3142
3143#endif /* defined(HAVE_TIMES) */
3144
3145#if defined(HAVE_GETSID)
3146
3147PyDoc_STRVAR(os_getsid__doc__,
3148"getsid($module, pid, /)\n"
3149"--\n"
3150"\n"
3151"Call the system call getsid(pid) and return the result.");
3152
3153#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003154 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003155
3156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003157os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003158
3159static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003160os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003161{
3162 PyObject *return_value = NULL;
3163 pid_t pid;
3164
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003165 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003166 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003167 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003168 return_value = os_getsid_impl(module, pid);
3169
3170exit:
3171 return return_value;
3172}
3173
3174#endif /* defined(HAVE_GETSID) */
3175
3176#if defined(HAVE_SETSID)
3177
3178PyDoc_STRVAR(os_setsid__doc__,
3179"setsid($module, /)\n"
3180"--\n"
3181"\n"
3182"Call the system call setsid().");
3183
3184#define OS_SETSID_METHODDEF \
3185 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3186
3187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003188os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003189
3190static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003191os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003192{
3193 return os_setsid_impl(module);
3194}
3195
3196#endif /* defined(HAVE_SETSID) */
3197
3198#if defined(HAVE_SETPGID)
3199
3200PyDoc_STRVAR(os_setpgid__doc__,
3201"setpgid($module, pid, pgrp, /)\n"
3202"--\n"
3203"\n"
3204"Call the system call setpgid(pid, pgrp).");
3205
3206#define OS_SETPGID_METHODDEF \
3207 {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
3208
3209static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003210os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003211
3212static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003213os_setpgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003214{
3215 PyObject *return_value = NULL;
3216 pid_t pid;
3217 pid_t pgrp;
3218
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003219 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003220 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003221 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003222 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003223 return_value = os_setpgid_impl(module, pid, pgrp);
3224
3225exit:
3226 return return_value;
3227}
3228
3229#endif /* defined(HAVE_SETPGID) */
3230
3231#if defined(HAVE_TCGETPGRP)
3232
3233PyDoc_STRVAR(os_tcgetpgrp__doc__,
3234"tcgetpgrp($module, fd, /)\n"
3235"--\n"
3236"\n"
3237"Return the process group associated with the terminal specified by fd.");
3238
3239#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003240 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003241
3242static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003243os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003244
3245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003246os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003247{
3248 PyObject *return_value = NULL;
3249 int fd;
3250
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003251 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003252 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003253 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003254 return_value = os_tcgetpgrp_impl(module, fd);
3255
3256exit:
3257 return return_value;
3258}
3259
3260#endif /* defined(HAVE_TCGETPGRP) */
3261
3262#if defined(HAVE_TCSETPGRP)
3263
3264PyDoc_STRVAR(os_tcsetpgrp__doc__,
3265"tcsetpgrp($module, fd, pgid, /)\n"
3266"--\n"
3267"\n"
3268"Set the process group associated with the terminal specified by fd.");
3269
3270#define OS_TCSETPGRP_METHODDEF \
3271 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
3272
3273static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003274os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003275
3276static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003277os_tcsetpgrp(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003278{
3279 PyObject *return_value = NULL;
3280 int fd;
3281 pid_t pgid;
3282
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003283 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003284 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003286 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003287 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3288
3289exit:
3290 return return_value;
3291}
3292
3293#endif /* defined(HAVE_TCSETPGRP) */
3294
3295PyDoc_STRVAR(os_open__doc__,
3296"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3297"--\n"
3298"\n"
3299"Open a file for low level IO. Returns a file descriptor (integer).\n"
3300"\n"
3301"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3302" and path should be relative; path will then be relative to that directory.\n"
3303"dir_fd may not be implemented on your platform.\n"
3304" If it is unavailable, using it will raise a NotImplementedError.");
3305
3306#define OS_OPEN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003307 {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003308
3309static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003310os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003311
3312static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003313os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003314{
3315 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003316 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3317 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003318 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3319 int flags;
3320 int mode = 511;
3321 int dir_fd = DEFAULT_DIR_FD;
3322 int _return_value;
3323
Victor Stinner37e4ef72016-09-09 20:00:13 -07003324 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003325 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003327 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003328 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003329 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003332 return_value = PyLong_FromLong((long)_return_value);
3333
3334exit:
3335 /* Cleanup for path */
3336 path_cleanup(&path);
3337
3338 return return_value;
3339}
3340
3341PyDoc_STRVAR(os_close__doc__,
3342"close($module, /, fd)\n"
3343"--\n"
3344"\n"
3345"Close a file descriptor.");
3346
3347#define OS_CLOSE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003348 {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003349
3350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003351os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003352
3353static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003354os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003355{
3356 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003357 static const char * const _keywords[] = {"fd", NULL};
3358 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003359 int fd;
3360
Victor Stinner37e4ef72016-09-09 20:00:13 -07003361 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003362 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003363 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003364 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003365 return_value = os_close_impl(module, fd);
3366
3367exit:
3368 return return_value;
3369}
3370
3371PyDoc_STRVAR(os_closerange__doc__,
3372"closerange($module, fd_low, fd_high, /)\n"
3373"--\n"
3374"\n"
3375"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3376
3377#define OS_CLOSERANGE_METHODDEF \
3378 {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
3379
3380static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003381os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003382
3383static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003384os_closerange(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003385{
3386 PyObject *return_value = NULL;
3387 int fd_low;
3388 int fd_high;
3389
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003390 if (!PyArg_ParseTuple(args, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003391 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003392 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003393 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003394 return_value = os_closerange_impl(module, fd_low, fd_high);
3395
3396exit:
3397 return return_value;
3398}
3399
3400PyDoc_STRVAR(os_dup__doc__,
3401"dup($module, fd, /)\n"
3402"--\n"
3403"\n"
3404"Return a duplicate of a file descriptor.");
3405
3406#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003407 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003408
3409static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003410os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411
3412static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003413os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003414{
3415 PyObject *return_value = NULL;
3416 int fd;
3417 int _return_value;
3418
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003419 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003420 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003421 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003422 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003423 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003424 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003425 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003426 return_value = PyLong_FromLong((long)_return_value);
3427
3428exit:
3429 return return_value;
3430}
3431
3432PyDoc_STRVAR(os_dup2__doc__,
3433"dup2($module, /, fd, fd2, inheritable=True)\n"
3434"--\n"
3435"\n"
3436"Duplicate file descriptor.");
3437
3438#define OS_DUP2_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003439 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003440
3441static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003442os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003443
3444static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003445os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003446{
3447 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003448 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3449 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003450 int fd;
3451 int fd2;
3452 int inheritable = 1;
3453
Victor Stinner37e4ef72016-09-09 20:00:13 -07003454 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003455 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003456 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003457 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003458 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3459
3460exit:
3461 return return_value;
3462}
3463
3464#if defined(HAVE_LOCKF)
3465
3466PyDoc_STRVAR(os_lockf__doc__,
3467"lockf($module, fd, command, length, /)\n"
3468"--\n"
3469"\n"
3470"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3471"\n"
3472" fd\n"
3473" An open file descriptor.\n"
3474" command\n"
3475" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3476" length\n"
3477" The number of bytes to lock, starting at the current position.");
3478
3479#define OS_LOCKF_METHODDEF \
3480 {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
3481
3482static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003483os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003484
3485static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003486os_lockf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003487{
3488 PyObject *return_value = NULL;
3489 int fd;
3490 int command;
3491 Py_off_t length;
3492
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003493 if (!PyArg_ParseTuple(args, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003494 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003495 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003496 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003497 return_value = os_lockf_impl(module, fd, command, length);
3498
3499exit:
3500 return return_value;
3501}
3502
3503#endif /* defined(HAVE_LOCKF) */
3504
3505PyDoc_STRVAR(os_lseek__doc__,
3506"lseek($module, fd, position, how, /)\n"
3507"--\n"
3508"\n"
3509"Set the position of a file descriptor. Return the new position.\n"
3510"\n"
3511"Return the new cursor position in number of bytes\n"
3512"relative to the beginning of the file.");
3513
3514#define OS_LSEEK_METHODDEF \
3515 {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
3516
3517static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003518os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003519
3520static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003521os_lseek(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003522{
3523 PyObject *return_value = NULL;
3524 int fd;
3525 Py_off_t position;
3526 int how;
3527 Py_off_t _return_value;
3528
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003529 if (!PyArg_ParseTuple(args, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003530 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003531 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003532 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003533 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003534 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003535 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003536 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003537 return_value = PyLong_FromPy_off_t(_return_value);
3538
3539exit:
3540 return return_value;
3541}
3542
3543PyDoc_STRVAR(os_read__doc__,
3544"read($module, fd, length, /)\n"
3545"--\n"
3546"\n"
3547"Read from a file descriptor. Returns a bytes object.");
3548
3549#define OS_READ_METHODDEF \
3550 {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
3551
3552static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003553os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003554
3555static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003556os_read(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003557{
3558 PyObject *return_value = NULL;
3559 int fd;
3560 Py_ssize_t length;
3561
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003562 if (!PyArg_ParseTuple(args, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003563 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003564 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003565 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003566 return_value = os_read_impl(module, fd, length);
3567
3568exit:
3569 return return_value;
3570}
3571
3572#if defined(HAVE_READV)
3573
3574PyDoc_STRVAR(os_readv__doc__,
3575"readv($module, fd, buffers, /)\n"
3576"--\n"
3577"\n"
3578"Read from a file descriptor fd into an iterable of buffers.\n"
3579"\n"
3580"The buffers should be mutable buffers accepting bytes.\n"
3581"readv will transfer data into each buffer until it is full\n"
3582"and then move on to the next buffer in the sequence to hold\n"
3583"the rest of the data.\n"
3584"\n"
3585"readv returns the total number of bytes read,\n"
3586"which may be less than the total capacity of all the buffers.");
3587
3588#define OS_READV_METHODDEF \
3589 {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
3590
3591static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003592os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003593
3594static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003595os_readv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003596{
3597 PyObject *return_value = NULL;
3598 int fd;
3599 PyObject *buffers;
3600 Py_ssize_t _return_value;
3601
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003602 if (!PyArg_ParseTuple(args, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003603 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003605 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003606 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003607 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003608 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003609 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003610 return_value = PyLong_FromSsize_t(_return_value);
3611
3612exit:
3613 return return_value;
3614}
3615
3616#endif /* defined(HAVE_READV) */
3617
3618#if defined(HAVE_PREAD)
3619
3620PyDoc_STRVAR(os_pread__doc__,
3621"pread($module, fd, length, offset, /)\n"
3622"--\n"
3623"\n"
3624"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3625"\n"
3626"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3627"the beginning of the file. The file offset remains unchanged.");
3628
3629#define OS_PREAD_METHODDEF \
3630 {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
3631
3632static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003633os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003634
3635static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003636os_pread(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003637{
3638 PyObject *return_value = NULL;
3639 int fd;
3640 int length;
3641 Py_off_t offset;
3642
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003643 if (!PyArg_ParseTuple(args, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003644 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003645 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003646 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003647 return_value = os_pread_impl(module, fd, length, offset);
3648
3649exit:
3650 return return_value;
3651}
3652
3653#endif /* defined(HAVE_PREAD) */
3654
3655PyDoc_STRVAR(os_write__doc__,
3656"write($module, fd, data, /)\n"
3657"--\n"
3658"\n"
3659"Write a bytes object to a file descriptor.");
3660
3661#define OS_WRITE_METHODDEF \
3662 {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
3663
3664static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003665os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003666
3667static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003668os_write(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003669{
3670 PyObject *return_value = NULL;
3671 int fd;
3672 Py_buffer data = {NULL, NULL};
3673 Py_ssize_t _return_value;
3674
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003675 if (!PyArg_ParseTuple(args, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003676 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003677 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003678 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003679 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003680 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003681 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003683 return_value = PyLong_FromSsize_t(_return_value);
3684
3685exit:
3686 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003687 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003688 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003689 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003690
3691 return return_value;
3692}
3693
3694PyDoc_STRVAR(os_fstat__doc__,
3695"fstat($module, /, fd)\n"
3696"--\n"
3697"\n"
3698"Perform a stat system call on the given file descriptor.\n"
3699"\n"
3700"Like stat(), but for an open file descriptor.\n"
3701"Equivalent to os.stat(fd).");
3702
3703#define OS_FSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003704 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003705
3706static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003707os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003708
3709static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003710os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003711{
3712 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003713 static const char * const _keywords[] = {"fd", NULL};
3714 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003715 int fd;
3716
Victor Stinner37e4ef72016-09-09 20:00:13 -07003717 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003718 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003719 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003720 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003721 return_value = os_fstat_impl(module, fd);
3722
3723exit:
3724 return return_value;
3725}
3726
3727PyDoc_STRVAR(os_isatty__doc__,
3728"isatty($module, fd, /)\n"
3729"--\n"
3730"\n"
3731"Return True if the fd is connected to a terminal.\n"
3732"\n"
3733"Return True if the file descriptor is an open file descriptor\n"
3734"connected to the slave end of a terminal.");
3735
3736#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003737 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738
3739static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003740os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003741
3742static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003743os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003744{
3745 PyObject *return_value = NULL;
3746 int fd;
3747 int _return_value;
3748
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003749 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003750 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003751 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003752 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003753 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003754 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003755 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003756 return_value = PyBool_FromLong((long)_return_value);
3757
3758exit:
3759 return return_value;
3760}
3761
3762#if defined(HAVE_PIPE)
3763
3764PyDoc_STRVAR(os_pipe__doc__,
3765"pipe($module, /)\n"
3766"--\n"
3767"\n"
3768"Create a pipe.\n"
3769"\n"
3770"Returns a tuple of two file descriptors:\n"
3771" (read_fd, write_fd)");
3772
3773#define OS_PIPE_METHODDEF \
3774 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3775
3776static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003777os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003778
3779static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003780os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003781{
3782 return os_pipe_impl(module);
3783}
3784
3785#endif /* defined(HAVE_PIPE) */
3786
3787#if defined(HAVE_PIPE2)
3788
3789PyDoc_STRVAR(os_pipe2__doc__,
3790"pipe2($module, flags, /)\n"
3791"--\n"
3792"\n"
3793"Create a pipe with flags set atomically.\n"
3794"\n"
3795"Returns a tuple of two file descriptors:\n"
3796" (read_fd, write_fd)\n"
3797"\n"
3798"flags can be constructed by ORing together one or more of these values:\n"
3799"O_NONBLOCK, O_CLOEXEC.");
3800
3801#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003802 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003803
3804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003805os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003806
3807static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003808os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003809{
3810 PyObject *return_value = NULL;
3811 int flags;
3812
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003813 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003814 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003815 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003816 return_value = os_pipe2_impl(module, flags);
3817
3818exit:
3819 return return_value;
3820}
3821
3822#endif /* defined(HAVE_PIPE2) */
3823
3824#if defined(HAVE_WRITEV)
3825
3826PyDoc_STRVAR(os_writev__doc__,
3827"writev($module, fd, buffers, /)\n"
3828"--\n"
3829"\n"
3830"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3831"\n"
3832"Returns the total number of bytes written.\n"
3833"buffers must be a sequence of bytes-like objects.");
3834
3835#define OS_WRITEV_METHODDEF \
3836 {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
3837
3838static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003839os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003840
3841static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003842os_writev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003843{
3844 PyObject *return_value = NULL;
3845 int fd;
3846 PyObject *buffers;
3847 Py_ssize_t _return_value;
3848
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003849 if (!PyArg_ParseTuple(args, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003850 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003851 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003852 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003853 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003854 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003855 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003856 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003857 return_value = PyLong_FromSsize_t(_return_value);
3858
3859exit:
3860 return return_value;
3861}
3862
3863#endif /* defined(HAVE_WRITEV) */
3864
3865#if defined(HAVE_PWRITE)
3866
3867PyDoc_STRVAR(os_pwrite__doc__,
3868"pwrite($module, fd, buffer, offset, /)\n"
3869"--\n"
3870"\n"
3871"Write bytes to a file descriptor starting at a particular offset.\n"
3872"\n"
3873"Write buffer to fd, starting at offset bytes from the beginning of\n"
3874"the file. Returns the number of bytes writte. Does not change the\n"
3875"current file offset.");
3876
3877#define OS_PWRITE_METHODDEF \
3878 {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
3879
3880static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003881os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003882
3883static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003884os_pwrite(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003885{
3886 PyObject *return_value = NULL;
3887 int fd;
3888 Py_buffer buffer = {NULL, NULL};
3889 Py_off_t offset;
3890 Py_ssize_t _return_value;
3891
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003892 if (!PyArg_ParseTuple(args, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003893 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003894 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003895 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003896 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003897 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003898 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003899 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003900 return_value = PyLong_FromSsize_t(_return_value);
3901
3902exit:
3903 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003904 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003905 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003906 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003907
3908 return return_value;
3909}
3910
3911#endif /* defined(HAVE_PWRITE) */
3912
3913#if defined(HAVE_MKFIFO)
3914
3915PyDoc_STRVAR(os_mkfifo__doc__,
3916"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3917"--\n"
3918"\n"
3919"Create a \"fifo\" (a POSIX named pipe).\n"
3920"\n"
3921"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3922" and path should be relative; path will then be relative to that directory.\n"
3923"dir_fd may not be implemented on your platform.\n"
3924" If it is unavailable, using it will raise a NotImplementedError.");
3925
3926#define OS_MKFIFO_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003927 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003928
3929static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003930os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003931
3932static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003933os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003934{
3935 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003936 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
3937 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003938 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3939 int mode = 438;
3940 int dir_fd = DEFAULT_DIR_FD;
3941
Victor Stinner37e4ef72016-09-09 20:00:13 -07003942 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003943 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003944 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003945 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003946 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3947
3948exit:
3949 /* Cleanup for path */
3950 path_cleanup(&path);
3951
3952 return return_value;
3953}
3954
3955#endif /* defined(HAVE_MKFIFO) */
3956
3957#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
3958
3959PyDoc_STRVAR(os_mknod__doc__,
3960"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
3961"--\n"
3962"\n"
3963"Create a node in the file system.\n"
3964"\n"
3965"Create a node in the file system (file, device special file or named pipe)\n"
3966"at path. mode specifies both the permissions to use and the\n"
3967"type of node to be created, being combined (bitwise OR) with one of\n"
3968"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
3969"device defines the newly created device special file (probably using\n"
3970"os.makedev()). Otherwise device is ignored.\n"
3971"\n"
3972"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3973" and path should be relative; path will then be relative to that directory.\n"
3974"dir_fd may not be implemented on your platform.\n"
3975" If it is unavailable, using it will raise a NotImplementedError.");
3976
3977#define OS_MKNOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003978 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003979
3980static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003981os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04003982 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003983
3984static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003985os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003986{
3987 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003988 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
3989 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003990 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
3991 int mode = 384;
3992 dev_t device = 0;
3993 int dir_fd = DEFAULT_DIR_FD;
3994
Victor Stinner37e4ef72016-09-09 20:00:13 -07003995 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003996 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003997 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003998 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003999 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4000
4001exit:
4002 /* Cleanup for path */
4003 path_cleanup(&path);
4004
4005 return return_value;
4006}
4007
4008#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4009
4010#if defined(HAVE_DEVICE_MACROS)
4011
4012PyDoc_STRVAR(os_major__doc__,
4013"major($module, device, /)\n"
4014"--\n"
4015"\n"
4016"Extracts a device major number from a raw device number.");
4017
4018#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004019 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004020
4021static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004022os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004023
4024static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004025os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004026{
4027 PyObject *return_value = NULL;
4028 dev_t device;
4029 unsigned int _return_value;
4030
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004031 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004032 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004033 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004034 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004035 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004036 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004037 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004038 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4039
4040exit:
4041 return return_value;
4042}
4043
4044#endif /* defined(HAVE_DEVICE_MACROS) */
4045
4046#if defined(HAVE_DEVICE_MACROS)
4047
4048PyDoc_STRVAR(os_minor__doc__,
4049"minor($module, device, /)\n"
4050"--\n"
4051"\n"
4052"Extracts a device minor number from a raw device number.");
4053
4054#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004055 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004056
4057static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004058os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004059
4060static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004061os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004062{
4063 PyObject *return_value = NULL;
4064 dev_t device;
4065 unsigned int _return_value;
4066
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004067 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004068 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004069 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004070 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004071 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004072 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004073 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4075
4076exit:
4077 return return_value;
4078}
4079
4080#endif /* defined(HAVE_DEVICE_MACROS) */
4081
4082#if defined(HAVE_DEVICE_MACROS)
4083
4084PyDoc_STRVAR(os_makedev__doc__,
4085"makedev($module, major, minor, /)\n"
4086"--\n"
4087"\n"
4088"Composes a raw device number from the major and minor device numbers.");
4089
4090#define OS_MAKEDEV_METHODDEF \
4091 {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
4092
4093static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004094os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004095
4096static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004097os_makedev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004098{
4099 PyObject *return_value = NULL;
4100 int major;
4101 int minor;
4102 dev_t _return_value;
4103
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004104 if (!PyArg_ParseTuple(args, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004105 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004106 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004107 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004108 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004109 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004110 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004111 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004112 return_value = _PyLong_FromDev(_return_value);
4113
4114exit:
4115 return return_value;
4116}
4117
4118#endif /* defined(HAVE_DEVICE_MACROS) */
4119
Steve Dowerf7377032015-04-12 15:44:54 -04004120#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004121
4122PyDoc_STRVAR(os_ftruncate__doc__,
4123"ftruncate($module, fd, length, /)\n"
4124"--\n"
4125"\n"
4126"Truncate a file, specified by file descriptor, to a specific length.");
4127
4128#define OS_FTRUNCATE_METHODDEF \
4129 {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
4130
4131static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004132os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004133
4134static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004135os_ftruncate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004136{
4137 PyObject *return_value = NULL;
4138 int fd;
4139 Py_off_t length;
4140
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004141 if (!PyArg_ParseTuple(args, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004142 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004143 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004144 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004145 return_value = os_ftruncate_impl(module, fd, length);
4146
4147exit:
4148 return return_value;
4149}
4150
Steve Dowerf7377032015-04-12 15:44:54 -04004151#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004152
Steve Dowerf7377032015-04-12 15:44:54 -04004153#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004154
4155PyDoc_STRVAR(os_truncate__doc__,
4156"truncate($module, /, path, length)\n"
4157"--\n"
4158"\n"
4159"Truncate a file, specified by path, to a specific length.\n"
4160"\n"
4161"On some platforms, path may also be specified as an open file descriptor.\n"
4162" If this functionality is unavailable, using it raises an exception.");
4163
4164#define OS_TRUNCATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004165 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004166
4167static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004168os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004169
4170static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004171os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004172{
4173 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004174 static const char * const _keywords[] = {"path", "length", NULL};
4175 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004176 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4177 Py_off_t length;
4178
Victor Stinner37e4ef72016-09-09 20:00:13 -07004179 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004180 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004181 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004182 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004183 return_value = os_truncate_impl(module, &path, length);
4184
4185exit:
4186 /* Cleanup for path */
4187 path_cleanup(&path);
4188
4189 return return_value;
4190}
4191
Steve Dowerf7377032015-04-12 15:44:54 -04004192#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004193
4194#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4195
4196PyDoc_STRVAR(os_posix_fallocate__doc__,
4197"posix_fallocate($module, fd, offset, length, /)\n"
4198"--\n"
4199"\n"
4200"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4201"\n"
4202"Ensure that the file specified by fd encompasses a range of bytes\n"
4203"starting at offset bytes from the beginning and continuing for length bytes.");
4204
4205#define OS_POSIX_FALLOCATE_METHODDEF \
4206 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
4207
4208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004209os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004210 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004211
4212static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004213os_posix_fallocate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004214{
4215 PyObject *return_value = NULL;
4216 int fd;
4217 Py_off_t offset;
4218 Py_off_t length;
4219
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004220 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004221 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004222 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004223 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004224 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4225
4226exit:
4227 return return_value;
4228}
4229
4230#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4231
4232#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4233
4234PyDoc_STRVAR(os_posix_fadvise__doc__,
4235"posix_fadvise($module, fd, offset, length, advice, /)\n"
4236"--\n"
4237"\n"
4238"Announce an intention to access data in a specific pattern.\n"
4239"\n"
4240"Announce an intention to access data in a specific pattern, thus allowing\n"
4241"the kernel to make optimizations.\n"
4242"The advice applies to the region of the file specified by fd starting at\n"
4243"offset and continuing for length bytes.\n"
4244"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4245"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4246"POSIX_FADV_DONTNEED.");
4247
4248#define OS_POSIX_FADVISE_METHODDEF \
4249 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
4250
4251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004252os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004253 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004254
4255static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004256os_posix_fadvise(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004257{
4258 PyObject *return_value = NULL;
4259 int fd;
4260 Py_off_t offset;
4261 Py_off_t length;
4262 int advice;
4263
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004264 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004265 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004266 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004267 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004268 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4269
4270exit:
4271 return return_value;
4272}
4273
4274#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4275
4276#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4277
4278PyDoc_STRVAR(os_putenv__doc__,
4279"putenv($module, name, value, /)\n"
4280"--\n"
4281"\n"
4282"Change or add an environment variable.");
4283
4284#define OS_PUTENV_METHODDEF \
4285 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4286
4287static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004288os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004289
4290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004291os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004292{
4293 PyObject *return_value = NULL;
4294 PyObject *name;
4295 PyObject *value;
4296
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004297 if (!PyArg_ParseTuple(args, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004298 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004299 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004300 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004301 return_value = os_putenv_impl(module, name, value);
4302
4303exit:
4304 return return_value;
4305}
4306
4307#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4308
4309#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4310
4311PyDoc_STRVAR(os_putenv__doc__,
4312"putenv($module, name, value, /)\n"
4313"--\n"
4314"\n"
4315"Change or add an environment variable.");
4316
4317#define OS_PUTENV_METHODDEF \
4318 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4319
4320static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004321os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004322
4323static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004324os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004325{
4326 PyObject *return_value = NULL;
4327 PyObject *name = NULL;
4328 PyObject *value = NULL;
4329
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004330 if (!PyArg_ParseTuple(args, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004331 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004332 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004333 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004334 return_value = os_putenv_impl(module, name, value);
4335
4336exit:
4337 /* Cleanup for name */
4338 Py_XDECREF(name);
4339 /* Cleanup for value */
4340 Py_XDECREF(value);
4341
4342 return return_value;
4343}
4344
4345#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4346
4347#if defined(HAVE_UNSETENV)
4348
4349PyDoc_STRVAR(os_unsetenv__doc__,
4350"unsetenv($module, name, /)\n"
4351"--\n"
4352"\n"
4353"Delete an environment variable.");
4354
4355#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004356 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004357
4358static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004359os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004360
4361static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004362os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004363{
4364 PyObject *return_value = NULL;
4365 PyObject *name = NULL;
4366
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004367 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004368 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004369 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370 return_value = os_unsetenv_impl(module, name);
4371
4372exit:
4373 /* Cleanup for name */
4374 Py_XDECREF(name);
4375
4376 return return_value;
4377}
4378
4379#endif /* defined(HAVE_UNSETENV) */
4380
4381PyDoc_STRVAR(os_strerror__doc__,
4382"strerror($module, code, /)\n"
4383"--\n"
4384"\n"
4385"Translate an error code to a message string.");
4386
4387#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004388 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004389
4390static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004391os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004392
4393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004394os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004395{
4396 PyObject *return_value = NULL;
4397 int code;
4398
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004399 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004400 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004401 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004402 return_value = os_strerror_impl(module, code);
4403
4404exit:
4405 return return_value;
4406}
4407
4408#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4409
4410PyDoc_STRVAR(os_WCOREDUMP__doc__,
4411"WCOREDUMP($module, status, /)\n"
4412"--\n"
4413"\n"
4414"Return True if the process returning status was dumped to a core file.");
4415
4416#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004417 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004418
4419static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004420os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004421
4422static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004423os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004424{
4425 PyObject *return_value = NULL;
4426 int status;
4427 int _return_value;
4428
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004429 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004430 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004431 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004432 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004433 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004435 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004436 return_value = PyBool_FromLong((long)_return_value);
4437
4438exit:
4439 return return_value;
4440}
4441
4442#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4443
4444#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4445
4446PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4447"WIFCONTINUED($module, /, status)\n"
4448"--\n"
4449"\n"
4450"Return True if a particular process was continued from a job control stop.\n"
4451"\n"
4452"Return True if the process returning status was continued from a\n"
4453"job control stop.");
4454
4455#define OS_WIFCONTINUED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004456 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004457
4458static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004459os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004460
4461static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004462os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004463{
4464 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004465 static const char * const _keywords[] = {"status", NULL};
4466 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004467 int status;
4468 int _return_value;
4469
Victor Stinner37e4ef72016-09-09 20:00:13 -07004470 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004471 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004472 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004473 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004474 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004475 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004476 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004477 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004478 return_value = PyBool_FromLong((long)_return_value);
4479
4480exit:
4481 return return_value;
4482}
4483
4484#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4485
4486#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4487
4488PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4489"WIFSTOPPED($module, /, status)\n"
4490"--\n"
4491"\n"
4492"Return True if the process returning status was stopped.");
4493
4494#define OS_WIFSTOPPED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004495 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004496
4497static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004498os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004499
4500static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004501os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004502{
4503 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004504 static const char * const _keywords[] = {"status", NULL};
4505 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004506 int status;
4507 int _return_value;
4508
Victor Stinner37e4ef72016-09-09 20:00:13 -07004509 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004510 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004511 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004512 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004513 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004514 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004515 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004516 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004517 return_value = PyBool_FromLong((long)_return_value);
4518
4519exit:
4520 return return_value;
4521}
4522
4523#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4524
4525#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4526
4527PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4528"WIFSIGNALED($module, /, status)\n"
4529"--\n"
4530"\n"
4531"Return True if the process returning status was terminated by a signal.");
4532
4533#define OS_WIFSIGNALED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004534 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004535
4536static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004537os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004538
4539static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004540os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004541{
4542 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004543 static const char * const _keywords[] = {"status", NULL};
4544 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004545 int status;
4546 int _return_value;
4547
Victor Stinner37e4ef72016-09-09 20:00:13 -07004548 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004549 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004550 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004551 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004552 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004553 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004554 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004555 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004556 return_value = PyBool_FromLong((long)_return_value);
4557
4558exit:
4559 return return_value;
4560}
4561
4562#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4563
4564#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4565
4566PyDoc_STRVAR(os_WIFEXITED__doc__,
4567"WIFEXITED($module, /, status)\n"
4568"--\n"
4569"\n"
4570"Return True if the process returning status exited via the exit() system call.");
4571
4572#define OS_WIFEXITED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004573 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004574
4575static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004576os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004577
4578static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004579os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004580{
4581 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004582 static const char * const _keywords[] = {"status", NULL};
4583 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004584 int status;
4585 int _return_value;
4586
Victor Stinner37e4ef72016-09-09 20:00:13 -07004587 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004588 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004589 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004590 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004591 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004592 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004593 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004594 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004595 return_value = PyBool_FromLong((long)_return_value);
4596
4597exit:
4598 return return_value;
4599}
4600
4601#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4602
4603#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4604
4605PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4606"WEXITSTATUS($module, /, status)\n"
4607"--\n"
4608"\n"
4609"Return the process return code from status.");
4610
4611#define OS_WEXITSTATUS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004612 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004613
4614static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004615os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004616
4617static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004618os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004619{
4620 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004621 static const char * const _keywords[] = {"status", NULL};
4622 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004623 int status;
4624 int _return_value;
4625
Victor Stinner37e4ef72016-09-09 20:00:13 -07004626 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004627 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004628 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004629 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004630 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004631 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004632 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004633 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004634 return_value = PyLong_FromLong((long)_return_value);
4635
4636exit:
4637 return return_value;
4638}
4639
4640#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4641
4642#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4643
4644PyDoc_STRVAR(os_WTERMSIG__doc__,
4645"WTERMSIG($module, /, status)\n"
4646"--\n"
4647"\n"
4648"Return the signal that terminated the process that provided the status value.");
4649
4650#define OS_WTERMSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004651 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004652
4653static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004654os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004655
4656static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004657os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004658{
4659 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004660 static const char * const _keywords[] = {"status", NULL};
4661 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004662 int status;
4663 int _return_value;
4664
Victor Stinner37e4ef72016-09-09 20:00:13 -07004665 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004666 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004667 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004668 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004669 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004670 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004671 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004672 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004673 return_value = PyLong_FromLong((long)_return_value);
4674
4675exit:
4676 return return_value;
4677}
4678
4679#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4680
4681#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4682
4683PyDoc_STRVAR(os_WSTOPSIG__doc__,
4684"WSTOPSIG($module, /, status)\n"
4685"--\n"
4686"\n"
4687"Return the signal that stopped the process that provided the status value.");
4688
4689#define OS_WSTOPSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004690 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004691
4692static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004693os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004694
4695static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004696os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004697{
4698 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004699 static const char * const _keywords[] = {"status", NULL};
4700 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004701 int status;
4702 int _return_value;
4703
Victor Stinner37e4ef72016-09-09 20:00:13 -07004704 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004705 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004707 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004709 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004710 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004711 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004712 return_value = PyLong_FromLong((long)_return_value);
4713
4714exit:
4715 return return_value;
4716}
4717
4718#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4719
4720#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4721
4722PyDoc_STRVAR(os_fstatvfs__doc__,
4723"fstatvfs($module, fd, /)\n"
4724"--\n"
4725"\n"
4726"Perform an fstatvfs system call on the given fd.\n"
4727"\n"
4728"Equivalent to statvfs(fd).");
4729
4730#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004731 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004732
4733static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004734os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004735
4736static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004737os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004738{
4739 PyObject *return_value = NULL;
4740 int fd;
4741
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004742 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004745 return_value = os_fstatvfs_impl(module, fd);
4746
4747exit:
4748 return return_value;
4749}
4750
4751#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4752
4753#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4754
4755PyDoc_STRVAR(os_statvfs__doc__,
4756"statvfs($module, /, path)\n"
4757"--\n"
4758"\n"
4759"Perform a statvfs system call on the given path.\n"
4760"\n"
4761"path may always be specified as a string.\n"
4762"On some platforms, path may also be specified as an open file descriptor.\n"
4763" If this functionality is unavailable, using it raises an exception.");
4764
4765#define OS_STATVFS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004766 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004767
4768static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004769os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004770
4771static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004772os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004773{
4774 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004775 static const char * const _keywords[] = {"path", NULL};
4776 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004777 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4778
Victor Stinner37e4ef72016-09-09 20:00:13 -07004779 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004780 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004781 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004782 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004783 return_value = os_statvfs_impl(module, &path);
4784
4785exit:
4786 /* Cleanup for path */
4787 path_cleanup(&path);
4788
4789 return return_value;
4790}
4791
4792#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4793
4794#if defined(MS_WINDOWS)
4795
4796PyDoc_STRVAR(os__getdiskusage__doc__,
4797"_getdiskusage($module, /, path)\n"
4798"--\n"
4799"\n"
4800"Return disk usage statistics about the given path as a (total, free) tuple.");
4801
4802#define OS__GETDISKUSAGE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004803 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004804
4805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004806os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004807
4808static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004809os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004810{
4811 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004812 static const char * const _keywords[] = {"path", NULL};
4813 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004814 Py_UNICODE *path;
4815
Victor Stinner37e4ef72016-09-09 20:00:13 -07004816 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004817 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004818 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004819 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004820 return_value = os__getdiskusage_impl(module, path);
4821
4822exit:
4823 return return_value;
4824}
4825
4826#endif /* defined(MS_WINDOWS) */
4827
4828#if defined(HAVE_FPATHCONF)
4829
4830PyDoc_STRVAR(os_fpathconf__doc__,
4831"fpathconf($module, fd, name, /)\n"
4832"--\n"
4833"\n"
4834"Return the configuration limit name for the file descriptor fd.\n"
4835"\n"
4836"If there is no limit, return -1.");
4837
4838#define OS_FPATHCONF_METHODDEF \
4839 {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
4840
4841static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004842os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004843
4844static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004845os_fpathconf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004846{
4847 PyObject *return_value = NULL;
4848 int fd;
4849 int name;
4850 long _return_value;
4851
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004852 if (!PyArg_ParseTuple(args, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004853 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004854 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004855 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004856 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004857 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004858 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004859 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004860 return_value = PyLong_FromLong(_return_value);
4861
4862exit:
4863 return return_value;
4864}
4865
4866#endif /* defined(HAVE_FPATHCONF) */
4867
4868#if defined(HAVE_PATHCONF)
4869
4870PyDoc_STRVAR(os_pathconf__doc__,
4871"pathconf($module, /, path, name)\n"
4872"--\n"
4873"\n"
4874"Return the configuration limit name for the file or directory path.\n"
4875"\n"
4876"If there is no limit, return -1.\n"
4877"On some platforms, path may also be specified as an open file descriptor.\n"
4878" If this functionality is unavailable, using it raises an exception.");
4879
4880#define OS_PATHCONF_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004881 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004882
4883static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004884os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004885
4886static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004887os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004888{
4889 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004890 static const char * const _keywords[] = {"path", "name", NULL};
4891 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004892 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4893 int name;
4894 long _return_value;
4895
Victor Stinner37e4ef72016-09-09 20:00:13 -07004896 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004897 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004898 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004899 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004900 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004901 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004902 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004903 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904 return_value = PyLong_FromLong(_return_value);
4905
4906exit:
4907 /* Cleanup for path */
4908 path_cleanup(&path);
4909
4910 return return_value;
4911}
4912
4913#endif /* defined(HAVE_PATHCONF) */
4914
4915#if defined(HAVE_CONFSTR)
4916
4917PyDoc_STRVAR(os_confstr__doc__,
4918"confstr($module, name, /)\n"
4919"--\n"
4920"\n"
4921"Return a string-valued system configuration variable.");
4922
4923#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004924 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004925
4926static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004927os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004928
4929static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004930os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004931{
4932 PyObject *return_value = NULL;
4933 int name;
4934
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004935 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004936 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004937 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004938 return_value = os_confstr_impl(module, name);
4939
4940exit:
4941 return return_value;
4942}
4943
4944#endif /* defined(HAVE_CONFSTR) */
4945
4946#if defined(HAVE_SYSCONF)
4947
4948PyDoc_STRVAR(os_sysconf__doc__,
4949"sysconf($module, name, /)\n"
4950"--\n"
4951"\n"
4952"Return an integer-valued system configuration variable.");
4953
4954#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004955 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004956
4957static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004958os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004959
4960static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004961os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004962{
4963 PyObject *return_value = NULL;
4964 int name;
4965 long _return_value;
4966
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004967 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004968 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004969 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004970 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004971 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004972 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004973 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004974 return_value = PyLong_FromLong(_return_value);
4975
4976exit:
4977 return return_value;
4978}
4979
4980#endif /* defined(HAVE_SYSCONF) */
4981
4982PyDoc_STRVAR(os_abort__doc__,
4983"abort($module, /)\n"
4984"--\n"
4985"\n"
4986"Abort the interpreter immediately.\n"
4987"\n"
4988"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
4989"on the hosting operating system. This function never returns.");
4990
4991#define OS_ABORT_METHODDEF \
4992 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
4993
4994static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004995os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004996
4997static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004998os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004999{
5000 return os_abort_impl(module);
5001}
5002
Steve Dowercc16be82016-09-08 10:35:16 -07005003#if defined(MS_WINDOWS)
5004
5005PyDoc_STRVAR(os_startfile__doc__,
5006"startfile($module, /, filepath, operation=None)\n"
5007"--\n"
5008"\n"
5009"startfile(filepath [, operation])\n"
5010"\n"
5011"Start a file with its associated application.\n"
5012"\n"
5013"When \"operation\" is not specified or \"open\", this acts like\n"
5014"double-clicking the file in Explorer, or giving the file name as an\n"
5015"argument to the DOS \"start\" command: the file is opened with whatever\n"
5016"application (if any) its extension is associated.\n"
5017"When another \"operation\" is given, it specifies what should be done with\n"
5018"the file. A typical operation is \"print\".\n"
5019"\n"
5020"startfile returns as soon as the associated application is launched.\n"
5021"There is no option to wait for the application to close, and no way\n"
5022"to retrieve the application\'s exit status.\n"
5023"\n"
5024"The filepath is relative to the current directory. If you want to use\n"
5025"an absolute path, make sure the first character is not a slash (\"/\");\n"
5026"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5027
5028#define OS_STARTFILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005029 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005030
5031static PyObject *
5032os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5033
5034static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005035os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005036{
5037 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005038 static const char * const _keywords[] = {"filepath", "operation", NULL};
5039 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005040 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5041 Py_UNICODE *operation = NULL;
5042
Victor Stinner37e4ef72016-09-09 20:00:13 -07005043 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005044 path_converter, &filepath, &operation)) {
5045 goto exit;
5046 }
5047 return_value = os_startfile_impl(module, &filepath, operation);
5048
5049exit:
5050 /* Cleanup for filepath */
5051 path_cleanup(&filepath);
5052
5053 return return_value;
5054}
5055
5056#endif /* defined(MS_WINDOWS) */
5057
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005058#if defined(HAVE_GETLOADAVG)
5059
5060PyDoc_STRVAR(os_getloadavg__doc__,
5061"getloadavg($module, /)\n"
5062"--\n"
5063"\n"
5064"Return average recent system load information.\n"
5065"\n"
5066"Return the number of processes in the system run queue averaged over\n"
5067"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5068"Raises OSError if the load average was unobtainable.");
5069
5070#define OS_GETLOADAVG_METHODDEF \
5071 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5072
5073static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005074os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005075
5076static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005077os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005078{
5079 return os_getloadavg_impl(module);
5080}
5081
5082#endif /* defined(HAVE_GETLOADAVG) */
5083
5084PyDoc_STRVAR(os_device_encoding__doc__,
5085"device_encoding($module, /, fd)\n"
5086"--\n"
5087"\n"
5088"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5089"\n"
5090"The file descriptor must be attached to a terminal.\n"
5091"If the device is not a terminal, return None.");
5092
5093#define OS_DEVICE_ENCODING_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005094 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005095
5096static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005097os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005098
5099static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005100os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005101{
5102 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005103 static const char * const _keywords[] = {"fd", NULL};
5104 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005105 int fd;
5106
Victor Stinner37e4ef72016-09-09 20:00:13 -07005107 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005108 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005109 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005111 return_value = os_device_encoding_impl(module, fd);
5112
5113exit:
5114 return return_value;
5115}
5116
5117#if defined(HAVE_SETRESUID)
5118
5119PyDoc_STRVAR(os_setresuid__doc__,
5120"setresuid($module, ruid, euid, suid, /)\n"
5121"--\n"
5122"\n"
5123"Set the current process\'s real, effective, and saved user ids.");
5124
5125#define OS_SETRESUID_METHODDEF \
5126 {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
5127
5128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005129os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005130
5131static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005132os_setresuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005133{
5134 PyObject *return_value = NULL;
5135 uid_t ruid;
5136 uid_t euid;
5137 uid_t suid;
5138
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005139 if (!PyArg_ParseTuple(args, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005140 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005141 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005142 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005143 return_value = os_setresuid_impl(module, ruid, euid, suid);
5144
5145exit:
5146 return return_value;
5147}
5148
5149#endif /* defined(HAVE_SETRESUID) */
5150
5151#if defined(HAVE_SETRESGID)
5152
5153PyDoc_STRVAR(os_setresgid__doc__,
5154"setresgid($module, rgid, egid, sgid, /)\n"
5155"--\n"
5156"\n"
5157"Set the current process\'s real, effective, and saved group ids.");
5158
5159#define OS_SETRESGID_METHODDEF \
5160 {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
5161
5162static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005163os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005164
5165static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005166os_setresgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005167{
5168 PyObject *return_value = NULL;
5169 gid_t rgid;
5170 gid_t egid;
5171 gid_t sgid;
5172
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005173 if (!PyArg_ParseTuple(args, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005174 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005176 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005177 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5178
5179exit:
5180 return return_value;
5181}
5182
5183#endif /* defined(HAVE_SETRESGID) */
5184
5185#if defined(HAVE_GETRESUID)
5186
5187PyDoc_STRVAR(os_getresuid__doc__,
5188"getresuid($module, /)\n"
5189"--\n"
5190"\n"
5191"Return a tuple of the current process\'s real, effective, and saved user ids.");
5192
5193#define OS_GETRESUID_METHODDEF \
5194 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5195
5196static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005197os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005198
5199static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005200os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005201{
5202 return os_getresuid_impl(module);
5203}
5204
5205#endif /* defined(HAVE_GETRESUID) */
5206
5207#if defined(HAVE_GETRESGID)
5208
5209PyDoc_STRVAR(os_getresgid__doc__,
5210"getresgid($module, /)\n"
5211"--\n"
5212"\n"
5213"Return a tuple of the current process\'s real, effective, and saved group ids.");
5214
5215#define OS_GETRESGID_METHODDEF \
5216 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5217
5218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005219os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005220
5221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005222os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005223{
5224 return os_getresgid_impl(module);
5225}
5226
5227#endif /* defined(HAVE_GETRESGID) */
5228
5229#if defined(USE_XATTRS)
5230
5231PyDoc_STRVAR(os_getxattr__doc__,
5232"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5233"--\n"
5234"\n"
5235"Return the value of extended attribute attribute on path.\n"
5236"\n"
5237"path may be either a string or an open file descriptor.\n"
5238"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5239" link, getxattr will examine the symbolic link itself instead of the file\n"
5240" the link points to.");
5241
5242#define OS_GETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005243 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005244
5245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005246os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005247 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005248
5249static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005250os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005251{
5252 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005253 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5254 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005255 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5256 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5257 int follow_symlinks = 1;
5258
Victor Stinner37e4ef72016-09-09 20:00:13 -07005259 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005260 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005261 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005262 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005263 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5264
5265exit:
5266 /* Cleanup for path */
5267 path_cleanup(&path);
5268 /* Cleanup for attribute */
5269 path_cleanup(&attribute);
5270
5271 return return_value;
5272}
5273
5274#endif /* defined(USE_XATTRS) */
5275
5276#if defined(USE_XATTRS)
5277
5278PyDoc_STRVAR(os_setxattr__doc__,
5279"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5280" follow_symlinks=True)\n"
5281"--\n"
5282"\n"
5283"Set extended attribute attribute on path to value.\n"
5284"\n"
5285"path may be either a string or an open file descriptor.\n"
5286"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5287" link, setxattr will modify the symbolic link itself instead of the file\n"
5288" the link points to.");
5289
5290#define OS_SETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005291 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005292
5293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005294os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005295 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005296
5297static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005298os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005299{
5300 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005301 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5302 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005303 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5304 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5305 Py_buffer value = {NULL, NULL};
5306 int flags = 0;
5307 int follow_symlinks = 1;
5308
Victor Stinner37e4ef72016-09-09 20:00:13 -07005309 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005310 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005311 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005312 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005313 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5314
5315exit:
5316 /* Cleanup for path */
5317 path_cleanup(&path);
5318 /* Cleanup for attribute */
5319 path_cleanup(&attribute);
5320 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005321 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005322 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005323 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005324
5325 return return_value;
5326}
5327
5328#endif /* defined(USE_XATTRS) */
5329
5330#if defined(USE_XATTRS)
5331
5332PyDoc_STRVAR(os_removexattr__doc__,
5333"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5334"--\n"
5335"\n"
5336"Remove extended attribute attribute on path.\n"
5337"\n"
5338"path may be either a string or an open file descriptor.\n"
5339"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5340" link, removexattr will modify the symbolic link itself instead of the file\n"
5341" the link points to.");
5342
5343#define OS_REMOVEXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005344 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005345
5346static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005347os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005348 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005349
5350static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005351os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005352{
5353 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005354 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5355 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005356 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5357 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5358 int follow_symlinks = 1;
5359
Victor Stinner37e4ef72016-09-09 20:00:13 -07005360 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005361 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005364 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5365
5366exit:
5367 /* Cleanup for path */
5368 path_cleanup(&path);
5369 /* Cleanup for attribute */
5370 path_cleanup(&attribute);
5371
5372 return return_value;
5373}
5374
5375#endif /* defined(USE_XATTRS) */
5376
5377#if defined(USE_XATTRS)
5378
5379PyDoc_STRVAR(os_listxattr__doc__,
5380"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5381"--\n"
5382"\n"
5383"Return a list of extended attributes on path.\n"
5384"\n"
5385"path may be either None, a string, or an open file descriptor.\n"
5386"if path is None, listxattr will examine the current directory.\n"
5387"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5388" link, listxattr will examine the symbolic link itself instead of the file\n"
5389" the link points to.");
5390
5391#define OS_LISTXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005392 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005393
5394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005395os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005396
5397static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005398os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005399{
5400 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005401 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5402 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005403 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5404 int follow_symlinks = 1;
5405
Victor Stinner37e4ef72016-09-09 20:00:13 -07005406 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005407 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005408 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005409 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005410 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5411
5412exit:
5413 /* Cleanup for path */
5414 path_cleanup(&path);
5415
5416 return return_value;
5417}
5418
5419#endif /* defined(USE_XATTRS) */
5420
5421PyDoc_STRVAR(os_urandom__doc__,
5422"urandom($module, size, /)\n"
5423"--\n"
5424"\n"
5425"Return a bytes object containing random bytes suitable for cryptographic use.");
5426
5427#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005428 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005429
5430static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005431os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005432
5433static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005434os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005435{
5436 PyObject *return_value = NULL;
5437 Py_ssize_t size;
5438
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005439 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005440 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005441 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005442 return_value = os_urandom_impl(module, size);
5443
5444exit:
5445 return return_value;
5446}
5447
5448PyDoc_STRVAR(os_cpu_count__doc__,
5449"cpu_count($module, /)\n"
5450"--\n"
5451"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005452"Return the number of CPUs in the system; return None if indeterminable.\n"
5453"\n"
5454"This number is not equivalent to the number of CPUs the current process can\n"
5455"use. The number of usable CPUs can be obtained with\n"
5456"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005457
5458#define OS_CPU_COUNT_METHODDEF \
5459 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5460
5461static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005462os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005463
5464static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005465os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005466{
5467 return os_cpu_count_impl(module);
5468}
5469
5470PyDoc_STRVAR(os_get_inheritable__doc__,
5471"get_inheritable($module, fd, /)\n"
5472"--\n"
5473"\n"
5474"Get the close-on-exe flag of the specified file descriptor.");
5475
5476#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005477 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005478
5479static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005480os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005481
5482static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005483os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005484{
5485 PyObject *return_value = NULL;
5486 int fd;
5487 int _return_value;
5488
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005489 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005490 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005491 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005492 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005493 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005494 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005496 return_value = PyBool_FromLong((long)_return_value);
5497
5498exit:
5499 return return_value;
5500}
5501
5502PyDoc_STRVAR(os_set_inheritable__doc__,
5503"set_inheritable($module, fd, inheritable, /)\n"
5504"--\n"
5505"\n"
5506"Set the inheritable flag of the specified file descriptor.");
5507
5508#define OS_SET_INHERITABLE_METHODDEF \
5509 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
5510
5511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005512os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005513
5514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005515os_set_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005516{
5517 PyObject *return_value = NULL;
5518 int fd;
5519 int inheritable;
5520
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005521 if (!PyArg_ParseTuple(args, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005522 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005523 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005524 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005525 return_value = os_set_inheritable_impl(module, fd, inheritable);
5526
5527exit:
5528 return return_value;
5529}
5530
5531#if defined(MS_WINDOWS)
5532
5533PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5534"get_handle_inheritable($module, handle, /)\n"
5535"--\n"
5536"\n"
5537"Get the close-on-exe flag of the specified file descriptor.");
5538
5539#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005540 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005541
5542static int
Victor Stinner581139c2016-09-06 15:54:20 -07005543os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005544
5545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005546os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005547{
5548 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005549 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005550 int _return_value;
5551
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005552 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005553 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005554 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005555 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005556 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005557 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005558 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005559 return_value = PyBool_FromLong((long)_return_value);
5560
5561exit:
5562 return return_value;
5563}
5564
5565#endif /* defined(MS_WINDOWS) */
5566
5567#if defined(MS_WINDOWS)
5568
5569PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5570"set_handle_inheritable($module, handle, inheritable, /)\n"
5571"--\n"
5572"\n"
5573"Set the inheritable flag of the specified handle.");
5574
5575#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
5576 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
5577
5578static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005579os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005580 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005581
5582static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005583os_set_handle_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005584{
5585 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005586 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005587 int inheritable;
5588
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005589 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005590 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005591 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005592 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005593 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5594
5595exit:
5596 return return_value;
5597}
5598
5599#endif /* defined(MS_WINDOWS) */
5600
Ethan Furman410ef8e2016-06-04 12:06:26 -07005601PyDoc_STRVAR(os_fspath__doc__,
5602"fspath($module, /, path)\n"
5603"--\n"
5604"\n"
5605"Return the file system path representation of the object.\n"
5606"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005607"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5608"object defines __fspath__(), then return the result of that method. All other\n"
5609"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005610
5611#define OS_FSPATH_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005612 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005613
5614static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005615os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005616
5617static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005618os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005619{
5620 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005621 static const char * const _keywords[] = {"path", NULL};
5622 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005623 PyObject *path;
5624
Victor Stinner37e4ef72016-09-09 20:00:13 -07005625 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005626 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005627 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005628 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005629 return_value = os_fspath_impl(module, path);
5630
5631exit:
5632 return return_value;
5633}
5634
Victor Stinner9b1f4742016-09-06 16:18:52 -07005635#if defined(HAVE_GETRANDOM_SYSCALL)
5636
5637PyDoc_STRVAR(os_getrandom__doc__,
5638"getrandom($module, /, size, flags=0)\n"
5639"--\n"
5640"\n"
5641"Obtain a series of random bytes.");
5642
5643#define OS_GETRANDOM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005644 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07005645
5646static PyObject *
5647os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
5648
5649static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005650os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07005651{
5652 PyObject *return_value = NULL;
5653 static const char * const _keywords[] = {"size", "flags", NULL};
5654 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
5655 Py_ssize_t size;
5656 int flags = 0;
5657
Victor Stinner37e4ef72016-09-09 20:00:13 -07005658 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07005659 &size, &flags)) {
5660 goto exit;
5661 }
5662 return_value = os_getrandom_impl(module, size, flags);
5663
5664exit:
5665 return return_value;
5666}
5667
5668#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
5669
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005670#ifndef OS_TTYNAME_METHODDEF
5671 #define OS_TTYNAME_METHODDEF
5672#endif /* !defined(OS_TTYNAME_METHODDEF) */
5673
5674#ifndef OS_CTERMID_METHODDEF
5675 #define OS_CTERMID_METHODDEF
5676#endif /* !defined(OS_CTERMID_METHODDEF) */
5677
5678#ifndef OS_FCHDIR_METHODDEF
5679 #define OS_FCHDIR_METHODDEF
5680#endif /* !defined(OS_FCHDIR_METHODDEF) */
5681
5682#ifndef OS_FCHMOD_METHODDEF
5683 #define OS_FCHMOD_METHODDEF
5684#endif /* !defined(OS_FCHMOD_METHODDEF) */
5685
5686#ifndef OS_LCHMOD_METHODDEF
5687 #define OS_LCHMOD_METHODDEF
5688#endif /* !defined(OS_LCHMOD_METHODDEF) */
5689
5690#ifndef OS_CHFLAGS_METHODDEF
5691 #define OS_CHFLAGS_METHODDEF
5692#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5693
5694#ifndef OS_LCHFLAGS_METHODDEF
5695 #define OS_LCHFLAGS_METHODDEF
5696#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5697
5698#ifndef OS_CHROOT_METHODDEF
5699 #define OS_CHROOT_METHODDEF
5700#endif /* !defined(OS_CHROOT_METHODDEF) */
5701
5702#ifndef OS_FSYNC_METHODDEF
5703 #define OS_FSYNC_METHODDEF
5704#endif /* !defined(OS_FSYNC_METHODDEF) */
5705
5706#ifndef OS_SYNC_METHODDEF
5707 #define OS_SYNC_METHODDEF
5708#endif /* !defined(OS_SYNC_METHODDEF) */
5709
5710#ifndef OS_FDATASYNC_METHODDEF
5711 #define OS_FDATASYNC_METHODDEF
5712#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5713
5714#ifndef OS_CHOWN_METHODDEF
5715 #define OS_CHOWN_METHODDEF
5716#endif /* !defined(OS_CHOWN_METHODDEF) */
5717
5718#ifndef OS_FCHOWN_METHODDEF
5719 #define OS_FCHOWN_METHODDEF
5720#endif /* !defined(OS_FCHOWN_METHODDEF) */
5721
5722#ifndef OS_LCHOWN_METHODDEF
5723 #define OS_LCHOWN_METHODDEF
5724#endif /* !defined(OS_LCHOWN_METHODDEF) */
5725
5726#ifndef OS_LINK_METHODDEF
5727 #define OS_LINK_METHODDEF
5728#endif /* !defined(OS_LINK_METHODDEF) */
5729
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005730#ifndef OS__GETFULLPATHNAME_METHODDEF
5731 #define OS__GETFULLPATHNAME_METHODDEF
5732#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5733
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005734#ifndef OS__GETFINALPATHNAME_METHODDEF
5735 #define OS__GETFINALPATHNAME_METHODDEF
5736#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5737
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005738#ifndef OS__ISDIR_METHODDEF
5739 #define OS__ISDIR_METHODDEF
5740#endif /* !defined(OS__ISDIR_METHODDEF) */
5741
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005742#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5743 #define OS__GETVOLUMEPATHNAME_METHODDEF
5744#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5745
5746#ifndef OS_NICE_METHODDEF
5747 #define OS_NICE_METHODDEF
5748#endif /* !defined(OS_NICE_METHODDEF) */
5749
5750#ifndef OS_GETPRIORITY_METHODDEF
5751 #define OS_GETPRIORITY_METHODDEF
5752#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
5753
5754#ifndef OS_SETPRIORITY_METHODDEF
5755 #define OS_SETPRIORITY_METHODDEF
5756#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
5757
5758#ifndef OS_SYSTEM_METHODDEF
5759 #define OS_SYSTEM_METHODDEF
5760#endif /* !defined(OS_SYSTEM_METHODDEF) */
5761
5762#ifndef OS_UNAME_METHODDEF
5763 #define OS_UNAME_METHODDEF
5764#endif /* !defined(OS_UNAME_METHODDEF) */
5765
5766#ifndef OS_EXECV_METHODDEF
5767 #define OS_EXECV_METHODDEF
5768#endif /* !defined(OS_EXECV_METHODDEF) */
5769
5770#ifndef OS_EXECVE_METHODDEF
5771 #define OS_EXECVE_METHODDEF
5772#endif /* !defined(OS_EXECVE_METHODDEF) */
5773
5774#ifndef OS_SPAWNV_METHODDEF
5775 #define OS_SPAWNV_METHODDEF
5776#endif /* !defined(OS_SPAWNV_METHODDEF) */
5777
5778#ifndef OS_SPAWNVE_METHODDEF
5779 #define OS_SPAWNVE_METHODDEF
5780#endif /* !defined(OS_SPAWNVE_METHODDEF) */
5781
5782#ifndef OS_FORK1_METHODDEF
5783 #define OS_FORK1_METHODDEF
5784#endif /* !defined(OS_FORK1_METHODDEF) */
5785
5786#ifndef OS_FORK_METHODDEF
5787 #define OS_FORK_METHODDEF
5788#endif /* !defined(OS_FORK_METHODDEF) */
5789
5790#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5791 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5792#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
5793
5794#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5795 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5796#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
5797
5798#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
5799 #define OS_SCHED_GETSCHEDULER_METHODDEF
5800#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
5801
5802#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
5803 #define OS_SCHED_SETSCHEDULER_METHODDEF
5804#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
5805
5806#ifndef OS_SCHED_GETPARAM_METHODDEF
5807 #define OS_SCHED_GETPARAM_METHODDEF
5808#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
5809
5810#ifndef OS_SCHED_SETPARAM_METHODDEF
5811 #define OS_SCHED_SETPARAM_METHODDEF
5812#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
5813
5814#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
5815 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
5816#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
5817
5818#ifndef OS_SCHED_YIELD_METHODDEF
5819 #define OS_SCHED_YIELD_METHODDEF
5820#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
5821
5822#ifndef OS_SCHED_SETAFFINITY_METHODDEF
5823 #define OS_SCHED_SETAFFINITY_METHODDEF
5824#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
5825
5826#ifndef OS_SCHED_GETAFFINITY_METHODDEF
5827 #define OS_SCHED_GETAFFINITY_METHODDEF
5828#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
5829
5830#ifndef OS_OPENPTY_METHODDEF
5831 #define OS_OPENPTY_METHODDEF
5832#endif /* !defined(OS_OPENPTY_METHODDEF) */
5833
5834#ifndef OS_FORKPTY_METHODDEF
5835 #define OS_FORKPTY_METHODDEF
5836#endif /* !defined(OS_FORKPTY_METHODDEF) */
5837
5838#ifndef OS_GETEGID_METHODDEF
5839 #define OS_GETEGID_METHODDEF
5840#endif /* !defined(OS_GETEGID_METHODDEF) */
5841
5842#ifndef OS_GETEUID_METHODDEF
5843 #define OS_GETEUID_METHODDEF
5844#endif /* !defined(OS_GETEUID_METHODDEF) */
5845
5846#ifndef OS_GETGID_METHODDEF
5847 #define OS_GETGID_METHODDEF
5848#endif /* !defined(OS_GETGID_METHODDEF) */
5849
Berker Peksag39404992016-09-15 20:45:16 +03005850#ifndef OS_GETPID_METHODDEF
5851 #define OS_GETPID_METHODDEF
5852#endif /* !defined(OS_GETPID_METHODDEF) */
5853
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005854#ifndef OS_GETGROUPS_METHODDEF
5855 #define OS_GETGROUPS_METHODDEF
5856#endif /* !defined(OS_GETGROUPS_METHODDEF) */
5857
5858#ifndef OS_GETPGID_METHODDEF
5859 #define OS_GETPGID_METHODDEF
5860#endif /* !defined(OS_GETPGID_METHODDEF) */
5861
5862#ifndef OS_GETPGRP_METHODDEF
5863 #define OS_GETPGRP_METHODDEF
5864#endif /* !defined(OS_GETPGRP_METHODDEF) */
5865
5866#ifndef OS_SETPGRP_METHODDEF
5867 #define OS_SETPGRP_METHODDEF
5868#endif /* !defined(OS_SETPGRP_METHODDEF) */
5869
5870#ifndef OS_GETPPID_METHODDEF
5871 #define OS_GETPPID_METHODDEF
5872#endif /* !defined(OS_GETPPID_METHODDEF) */
5873
5874#ifndef OS_GETLOGIN_METHODDEF
5875 #define OS_GETLOGIN_METHODDEF
5876#endif /* !defined(OS_GETLOGIN_METHODDEF) */
5877
5878#ifndef OS_GETUID_METHODDEF
5879 #define OS_GETUID_METHODDEF
5880#endif /* !defined(OS_GETUID_METHODDEF) */
5881
5882#ifndef OS_KILL_METHODDEF
5883 #define OS_KILL_METHODDEF
5884#endif /* !defined(OS_KILL_METHODDEF) */
5885
5886#ifndef OS_KILLPG_METHODDEF
5887 #define OS_KILLPG_METHODDEF
5888#endif /* !defined(OS_KILLPG_METHODDEF) */
5889
5890#ifndef OS_PLOCK_METHODDEF
5891 #define OS_PLOCK_METHODDEF
5892#endif /* !defined(OS_PLOCK_METHODDEF) */
5893
5894#ifndef OS_SETUID_METHODDEF
5895 #define OS_SETUID_METHODDEF
5896#endif /* !defined(OS_SETUID_METHODDEF) */
5897
5898#ifndef OS_SETEUID_METHODDEF
5899 #define OS_SETEUID_METHODDEF
5900#endif /* !defined(OS_SETEUID_METHODDEF) */
5901
5902#ifndef OS_SETEGID_METHODDEF
5903 #define OS_SETEGID_METHODDEF
5904#endif /* !defined(OS_SETEGID_METHODDEF) */
5905
5906#ifndef OS_SETREUID_METHODDEF
5907 #define OS_SETREUID_METHODDEF
5908#endif /* !defined(OS_SETREUID_METHODDEF) */
5909
5910#ifndef OS_SETREGID_METHODDEF
5911 #define OS_SETREGID_METHODDEF
5912#endif /* !defined(OS_SETREGID_METHODDEF) */
5913
5914#ifndef OS_SETGID_METHODDEF
5915 #define OS_SETGID_METHODDEF
5916#endif /* !defined(OS_SETGID_METHODDEF) */
5917
5918#ifndef OS_SETGROUPS_METHODDEF
5919 #define OS_SETGROUPS_METHODDEF
5920#endif /* !defined(OS_SETGROUPS_METHODDEF) */
5921
5922#ifndef OS_WAIT3_METHODDEF
5923 #define OS_WAIT3_METHODDEF
5924#endif /* !defined(OS_WAIT3_METHODDEF) */
5925
5926#ifndef OS_WAIT4_METHODDEF
5927 #define OS_WAIT4_METHODDEF
5928#endif /* !defined(OS_WAIT4_METHODDEF) */
5929
5930#ifndef OS_WAITID_METHODDEF
5931 #define OS_WAITID_METHODDEF
5932#endif /* !defined(OS_WAITID_METHODDEF) */
5933
5934#ifndef OS_WAITPID_METHODDEF
5935 #define OS_WAITPID_METHODDEF
5936#endif /* !defined(OS_WAITPID_METHODDEF) */
5937
5938#ifndef OS_WAIT_METHODDEF
5939 #define OS_WAIT_METHODDEF
5940#endif /* !defined(OS_WAIT_METHODDEF) */
5941
5942#ifndef OS_SYMLINK_METHODDEF
5943 #define OS_SYMLINK_METHODDEF
5944#endif /* !defined(OS_SYMLINK_METHODDEF) */
5945
5946#ifndef OS_TIMES_METHODDEF
5947 #define OS_TIMES_METHODDEF
5948#endif /* !defined(OS_TIMES_METHODDEF) */
5949
5950#ifndef OS_GETSID_METHODDEF
5951 #define OS_GETSID_METHODDEF
5952#endif /* !defined(OS_GETSID_METHODDEF) */
5953
5954#ifndef OS_SETSID_METHODDEF
5955 #define OS_SETSID_METHODDEF
5956#endif /* !defined(OS_SETSID_METHODDEF) */
5957
5958#ifndef OS_SETPGID_METHODDEF
5959 #define OS_SETPGID_METHODDEF
5960#endif /* !defined(OS_SETPGID_METHODDEF) */
5961
5962#ifndef OS_TCGETPGRP_METHODDEF
5963 #define OS_TCGETPGRP_METHODDEF
5964#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
5965
5966#ifndef OS_TCSETPGRP_METHODDEF
5967 #define OS_TCSETPGRP_METHODDEF
5968#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
5969
5970#ifndef OS_LOCKF_METHODDEF
5971 #define OS_LOCKF_METHODDEF
5972#endif /* !defined(OS_LOCKF_METHODDEF) */
5973
5974#ifndef OS_READV_METHODDEF
5975 #define OS_READV_METHODDEF
5976#endif /* !defined(OS_READV_METHODDEF) */
5977
5978#ifndef OS_PREAD_METHODDEF
5979 #define OS_PREAD_METHODDEF
5980#endif /* !defined(OS_PREAD_METHODDEF) */
5981
5982#ifndef OS_PIPE_METHODDEF
5983 #define OS_PIPE_METHODDEF
5984#endif /* !defined(OS_PIPE_METHODDEF) */
5985
5986#ifndef OS_PIPE2_METHODDEF
5987 #define OS_PIPE2_METHODDEF
5988#endif /* !defined(OS_PIPE2_METHODDEF) */
5989
5990#ifndef OS_WRITEV_METHODDEF
5991 #define OS_WRITEV_METHODDEF
5992#endif /* !defined(OS_WRITEV_METHODDEF) */
5993
5994#ifndef OS_PWRITE_METHODDEF
5995 #define OS_PWRITE_METHODDEF
5996#endif /* !defined(OS_PWRITE_METHODDEF) */
5997
5998#ifndef OS_MKFIFO_METHODDEF
5999 #define OS_MKFIFO_METHODDEF
6000#endif /* !defined(OS_MKFIFO_METHODDEF) */
6001
6002#ifndef OS_MKNOD_METHODDEF
6003 #define OS_MKNOD_METHODDEF
6004#endif /* !defined(OS_MKNOD_METHODDEF) */
6005
6006#ifndef OS_MAJOR_METHODDEF
6007 #define OS_MAJOR_METHODDEF
6008#endif /* !defined(OS_MAJOR_METHODDEF) */
6009
6010#ifndef OS_MINOR_METHODDEF
6011 #define OS_MINOR_METHODDEF
6012#endif /* !defined(OS_MINOR_METHODDEF) */
6013
6014#ifndef OS_MAKEDEV_METHODDEF
6015 #define OS_MAKEDEV_METHODDEF
6016#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6017
6018#ifndef OS_FTRUNCATE_METHODDEF
6019 #define OS_FTRUNCATE_METHODDEF
6020#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6021
6022#ifndef OS_TRUNCATE_METHODDEF
6023 #define OS_TRUNCATE_METHODDEF
6024#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6025
6026#ifndef OS_POSIX_FALLOCATE_METHODDEF
6027 #define OS_POSIX_FALLOCATE_METHODDEF
6028#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6029
6030#ifndef OS_POSIX_FADVISE_METHODDEF
6031 #define OS_POSIX_FADVISE_METHODDEF
6032#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6033
6034#ifndef OS_PUTENV_METHODDEF
6035 #define OS_PUTENV_METHODDEF
6036#endif /* !defined(OS_PUTENV_METHODDEF) */
6037
6038#ifndef OS_UNSETENV_METHODDEF
6039 #define OS_UNSETENV_METHODDEF
6040#endif /* !defined(OS_UNSETENV_METHODDEF) */
6041
6042#ifndef OS_WCOREDUMP_METHODDEF
6043 #define OS_WCOREDUMP_METHODDEF
6044#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6045
6046#ifndef OS_WIFCONTINUED_METHODDEF
6047 #define OS_WIFCONTINUED_METHODDEF
6048#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6049
6050#ifndef OS_WIFSTOPPED_METHODDEF
6051 #define OS_WIFSTOPPED_METHODDEF
6052#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6053
6054#ifndef OS_WIFSIGNALED_METHODDEF
6055 #define OS_WIFSIGNALED_METHODDEF
6056#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6057
6058#ifndef OS_WIFEXITED_METHODDEF
6059 #define OS_WIFEXITED_METHODDEF
6060#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6061
6062#ifndef OS_WEXITSTATUS_METHODDEF
6063 #define OS_WEXITSTATUS_METHODDEF
6064#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6065
6066#ifndef OS_WTERMSIG_METHODDEF
6067 #define OS_WTERMSIG_METHODDEF
6068#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6069
6070#ifndef OS_WSTOPSIG_METHODDEF
6071 #define OS_WSTOPSIG_METHODDEF
6072#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6073
6074#ifndef OS_FSTATVFS_METHODDEF
6075 #define OS_FSTATVFS_METHODDEF
6076#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6077
6078#ifndef OS_STATVFS_METHODDEF
6079 #define OS_STATVFS_METHODDEF
6080#endif /* !defined(OS_STATVFS_METHODDEF) */
6081
6082#ifndef OS__GETDISKUSAGE_METHODDEF
6083 #define OS__GETDISKUSAGE_METHODDEF
6084#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6085
6086#ifndef OS_FPATHCONF_METHODDEF
6087 #define OS_FPATHCONF_METHODDEF
6088#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6089
6090#ifndef OS_PATHCONF_METHODDEF
6091 #define OS_PATHCONF_METHODDEF
6092#endif /* !defined(OS_PATHCONF_METHODDEF) */
6093
6094#ifndef OS_CONFSTR_METHODDEF
6095 #define OS_CONFSTR_METHODDEF
6096#endif /* !defined(OS_CONFSTR_METHODDEF) */
6097
6098#ifndef OS_SYSCONF_METHODDEF
6099 #define OS_SYSCONF_METHODDEF
6100#endif /* !defined(OS_SYSCONF_METHODDEF) */
6101
Steve Dowercc16be82016-09-08 10:35:16 -07006102#ifndef OS_STARTFILE_METHODDEF
6103 #define OS_STARTFILE_METHODDEF
6104#endif /* !defined(OS_STARTFILE_METHODDEF) */
6105
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006106#ifndef OS_GETLOADAVG_METHODDEF
6107 #define OS_GETLOADAVG_METHODDEF
6108#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6109
6110#ifndef OS_SETRESUID_METHODDEF
6111 #define OS_SETRESUID_METHODDEF
6112#endif /* !defined(OS_SETRESUID_METHODDEF) */
6113
6114#ifndef OS_SETRESGID_METHODDEF
6115 #define OS_SETRESGID_METHODDEF
6116#endif /* !defined(OS_SETRESGID_METHODDEF) */
6117
6118#ifndef OS_GETRESUID_METHODDEF
6119 #define OS_GETRESUID_METHODDEF
6120#endif /* !defined(OS_GETRESUID_METHODDEF) */
6121
6122#ifndef OS_GETRESGID_METHODDEF
6123 #define OS_GETRESGID_METHODDEF
6124#endif /* !defined(OS_GETRESGID_METHODDEF) */
6125
6126#ifndef OS_GETXATTR_METHODDEF
6127 #define OS_GETXATTR_METHODDEF
6128#endif /* !defined(OS_GETXATTR_METHODDEF) */
6129
6130#ifndef OS_SETXATTR_METHODDEF
6131 #define OS_SETXATTR_METHODDEF
6132#endif /* !defined(OS_SETXATTR_METHODDEF) */
6133
6134#ifndef OS_REMOVEXATTR_METHODDEF
6135 #define OS_REMOVEXATTR_METHODDEF
6136#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6137
6138#ifndef OS_LISTXATTR_METHODDEF
6139 #define OS_LISTXATTR_METHODDEF
6140#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6141
6142#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6143 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6144#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6145
6146#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6147 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6148#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006149
6150#ifndef OS_GETRANDOM_METHODDEF
6151 #define OS_GETRANDOM_METHODDEF
6152#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Xiang Zhang4459e002017-01-22 13:04:17 +08006153/*[clinic end generated code: output=455def991740915a input=a9049054013a1b77]*/