blob: 2c0074a1a569fbb5d8a3b810aaeee0c4c6c32b4d [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(os_stat__doc__,
6"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
7"--\n"
8"\n"
9"Perform a stat system call on the given path.\n"
10"\n"
11" path\n"
12" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
13" dir_fd\n"
14" If not None, it should be a file descriptor open to a directory,\n"
15" and path should be a relative string; path will then be relative to\n"
16" that directory.\n"
17" follow_symlinks\n"
18" If False, and the last element of the path is a symbolic link,\n"
19" stat will examine the symbolic link itself instead of the file\n"
20" the link points to.\n"
21"\n"
22"dir_fd and follow_symlinks may not be implemented\n"
23" on your platform. If they are unavailable, using them will raise a\n"
24" NotImplementedError.\n"
25"\n"
26"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
27" an open file descriptor.");
28
29#define OS_STAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070030 {"stat", (PyCFunction)os_stat, METH_FASTCALL, os_stat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030031
32static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030033os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030034
35static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070036os_stat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030037{
38 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030039 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
40 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030041 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
42 int dir_fd = DEFAULT_DIR_FD;
43 int follow_symlinks = 1;
44
Victor Stinner37e4ef72016-09-09 20:00:13 -070045 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030046 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030047 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030048 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030049 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
50
51exit:
52 /* Cleanup for path */
53 path_cleanup(&path);
54
55 return return_value;
56}
57
58PyDoc_STRVAR(os_lstat__doc__,
59"lstat($module, /, path, *, dir_fd=None)\n"
60"--\n"
61"\n"
62"Perform a stat system call on the given path, without following symbolic links.\n"
63"\n"
64"Like stat(), but do not follow symbolic links.\n"
65"Equivalent to stat(path, follow_symlinks=False).");
66
67#define OS_LSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070068 {"lstat", (PyCFunction)os_lstat, METH_FASTCALL, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030069
70static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030071os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030072
73static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070074os_lstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030075{
76 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030077 static const char * const _keywords[] = {"path", "dir_fd", NULL};
78 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030079 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
80 int dir_fd = DEFAULT_DIR_FD;
81
Victor Stinner37e4ef72016-09-09 20:00:13 -070082 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030083 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030084 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030085 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030086 return_value = os_lstat_impl(module, &path, dir_fd);
87
88exit:
89 /* Cleanup for path */
90 path_cleanup(&path);
91
92 return return_value;
93}
94
95PyDoc_STRVAR(os_access__doc__,
96"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
97" follow_symlinks=True)\n"
98"--\n"
99"\n"
100"Use the real uid/gid to test for access to a path.\n"
101"\n"
102" path\n"
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700103" Path to be tested; can be string or bytes\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300104" mode\n"
105" Operating-system mode bitfield. Can be F_OK to test existence,\n"
106" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
107" dir_fd\n"
108" If not None, it should be a file descriptor open to a directory,\n"
109" and path should be relative; path will then be relative to that\n"
110" directory.\n"
111" effective_ids\n"
112" If True, access will use the effective uid/gid instead of\n"
113" the real uid/gid.\n"
114" follow_symlinks\n"
115" If False, and the last element of the path is a symbolic link,\n"
116" access will examine the symbolic link itself instead of the file\n"
117" the link points to.\n"
118"\n"
119"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
120" on your platform. If they are unavailable, using them will raise a\n"
121" NotImplementedError.\n"
122"\n"
123"Note that most operations will use the effective uid/gid, therefore this\n"
124" routine can be used in a suid/sgid environment to test if the invoking user\n"
125" has the specified access to the path.");
126
127#define OS_ACCESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700128 {"access", (PyCFunction)os_access, METH_FASTCALL, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300129
130static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300131os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400132 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300133
134static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700135os_access(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300136{
137 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300138 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
139 static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700140 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300141 int mode;
142 int dir_fd = DEFAULT_DIR_FD;
143 int effective_ids = 0;
144 int follow_symlinks = 1;
145 int _return_value;
146
Victor Stinner37e4ef72016-09-09 20:00:13 -0700147 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300148 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300149 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300150 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300151 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300152 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300153 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300154 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155 return_value = PyBool_FromLong((long)_return_value);
156
157exit:
158 /* Cleanup for path */
159 path_cleanup(&path);
160
161 return return_value;
162}
163
164#if defined(HAVE_TTYNAME)
165
166PyDoc_STRVAR(os_ttyname__doc__,
167"ttyname($module, fd, /)\n"
168"--\n"
169"\n"
170"Return the name of the terminal device connected to \'fd\'.\n"
171"\n"
172" fd\n"
173" Integer file descriptor handle.");
174
175#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300176 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300177
178static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300179os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300180
181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300182os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300183{
184 PyObject *return_value = NULL;
185 int fd;
186 char *_return_value;
187
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300188 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300189 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300190 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300191 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300192 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300193 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300194 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300195 return_value = PyUnicode_DecodeFSDefault(_return_value);
196
197exit:
198 return return_value;
199}
200
201#endif /* defined(HAVE_TTYNAME) */
202
203#if defined(HAVE_CTERMID)
204
205PyDoc_STRVAR(os_ctermid__doc__,
206"ctermid($module, /)\n"
207"--\n"
208"\n"
209"Return the name of the controlling terminal for this process.");
210
211#define OS_CTERMID_METHODDEF \
212 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
213
214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300215os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300216
217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300218os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300219{
220 return os_ctermid_impl(module);
221}
222
223#endif /* defined(HAVE_CTERMID) */
224
225PyDoc_STRVAR(os_chdir__doc__,
226"chdir($module, /, path)\n"
227"--\n"
228"\n"
229"Change the current working directory to the specified path.\n"
230"\n"
231"path may always be specified as a string.\n"
232"On some platforms, path may also be specified as an open file descriptor.\n"
233" If this functionality is unavailable, using it raises an exception.");
234
235#define OS_CHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700236 {"chdir", (PyCFunction)os_chdir, METH_FASTCALL, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300237
238static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300239os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240
241static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700242os_chdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300243{
244 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300245 static const char * const _keywords[] = {"path", NULL};
246 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300247 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
248
Victor Stinner37e4ef72016-09-09 20:00:13 -0700249 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300250 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300251 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300252 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300253 return_value = os_chdir_impl(module, &path);
254
255exit:
256 /* Cleanup for path */
257 path_cleanup(&path);
258
259 return return_value;
260}
261
262#if defined(HAVE_FCHDIR)
263
264PyDoc_STRVAR(os_fchdir__doc__,
265"fchdir($module, /, fd)\n"
266"--\n"
267"\n"
268"Change to the directory of the given file descriptor.\n"
269"\n"
270"fd must be opened on a directory, not a file.\n"
271"Equivalent to os.chdir(fd).");
272
273#define OS_FCHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700274 {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300275
276static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300277os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300278
279static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700280os_fchdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300281{
282 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300283 static const char * const _keywords[] = {"fd", NULL};
284 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300285 int fd;
286
Victor Stinner37e4ef72016-09-09 20:00:13 -0700287 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300288 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300289 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300291 return_value = os_fchdir_impl(module, fd);
292
293exit:
294 return return_value;
295}
296
297#endif /* defined(HAVE_FCHDIR) */
298
299PyDoc_STRVAR(os_chmod__doc__,
300"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
301"--\n"
302"\n"
303"Change the access permissions of a file.\n"
304"\n"
305" path\n"
306" Path to be modified. May always be specified as a str or bytes.\n"
307" On some platforms, path may also be specified as an open file descriptor.\n"
308" If this functionality is unavailable, using it raises an exception.\n"
309" mode\n"
310" Operating-system mode bitfield.\n"
311" dir_fd\n"
312" If not None, it should be a file descriptor open to a directory,\n"
313" and path should be relative; path will then be relative to that\n"
314" directory.\n"
315" follow_symlinks\n"
316" If False, and the last element of the path is a symbolic link,\n"
317" chmod will modify the symbolic link itself instead of the file\n"
318" the link points to.\n"
319"\n"
320"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
321" an open file descriptor.\n"
322"dir_fd and follow_symlinks may not be implemented on your platform.\n"
323" If they are unavailable, using them will raise a NotImplementedError.");
324
325#define OS_CHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700326 {"chmod", (PyCFunction)os_chmod, METH_FASTCALL, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300327
328static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300329os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400330 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300331
332static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700333os_chmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300334{
335 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300336 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
337 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300338 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
339 int mode;
340 int dir_fd = DEFAULT_DIR_FD;
341 int follow_symlinks = 1;
342
Victor Stinner37e4ef72016-09-09 20:00:13 -0700343 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300344 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300345 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300346 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300347 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
348
349exit:
350 /* Cleanup for path */
351 path_cleanup(&path);
352
353 return return_value;
354}
355
356#if defined(HAVE_FCHMOD)
357
358PyDoc_STRVAR(os_fchmod__doc__,
359"fchmod($module, /, fd, mode)\n"
360"--\n"
361"\n"
362"Change the access permissions of the file given by file descriptor fd.\n"
363"\n"
364"Equivalent to os.chmod(fd, mode).");
365
366#define OS_FCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700367 {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300368
369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300370os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300371
372static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700373os_fchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300374{
375 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300376 static const char * const _keywords[] = {"fd", "mode", NULL};
377 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300378 int fd;
379 int mode;
380
Victor Stinner37e4ef72016-09-09 20:00:13 -0700381 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300382 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300383 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300384 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300385 return_value = os_fchmod_impl(module, fd, mode);
386
387exit:
388 return return_value;
389}
390
391#endif /* defined(HAVE_FCHMOD) */
392
393#if defined(HAVE_LCHMOD)
394
395PyDoc_STRVAR(os_lchmod__doc__,
396"lchmod($module, /, path, mode)\n"
397"--\n"
398"\n"
399"Change the access permissions of a file, without following symbolic links.\n"
400"\n"
401"If path is a symlink, this affects the link itself rather than the target.\n"
402"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
403
404#define OS_LCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700405 {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300406
407static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300408os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300409
410static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700411os_lchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300412{
413 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300414 static const char * const _keywords[] = {"path", "mode", NULL};
415 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300416 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
417 int mode;
418
Victor Stinner37e4ef72016-09-09 20:00:13 -0700419 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300420 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300421 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300422 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300423 return_value = os_lchmod_impl(module, &path, mode);
424
425exit:
426 /* Cleanup for path */
427 path_cleanup(&path);
428
429 return return_value;
430}
431
432#endif /* defined(HAVE_LCHMOD) */
433
434#if defined(HAVE_CHFLAGS)
435
436PyDoc_STRVAR(os_chflags__doc__,
437"chflags($module, /, path, flags, follow_symlinks=True)\n"
438"--\n"
439"\n"
440"Set file flags.\n"
441"\n"
442"If follow_symlinks is False, and the last element of the path is a symbolic\n"
443" link, chflags will change flags on the symbolic link itself instead of the\n"
444" file the link points to.\n"
445"follow_symlinks may not be implemented on your platform. If it is\n"
446"unavailable, using it will raise a NotImplementedError.");
447
448#define OS_CHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700449 {"chflags", (PyCFunction)os_chflags, METH_FASTCALL, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300450
451static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300452os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400453 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300454
455static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700456os_chflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300457{
458 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300459 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
460 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300461 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
462 unsigned long flags;
463 int follow_symlinks = 1;
464
Victor Stinner37e4ef72016-09-09 20:00:13 -0700465 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300466 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300467 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300468 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300469 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
470
471exit:
472 /* Cleanup for path */
473 path_cleanup(&path);
474
475 return return_value;
476}
477
478#endif /* defined(HAVE_CHFLAGS) */
479
480#if defined(HAVE_LCHFLAGS)
481
482PyDoc_STRVAR(os_lchflags__doc__,
483"lchflags($module, /, path, flags)\n"
484"--\n"
485"\n"
486"Set file flags.\n"
487"\n"
488"This function will not follow symbolic links.\n"
489"Equivalent to chflags(path, flags, follow_symlinks=False).");
490
491#define OS_LCHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700492 {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300493
494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300495os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300496
497static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700498os_lchflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300499{
500 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300501 static const char * const _keywords[] = {"path", "flags", NULL};
502 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300503 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
504 unsigned long flags;
505
Victor Stinner37e4ef72016-09-09 20:00:13 -0700506 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300507 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300508 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300509 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300510 return_value = os_lchflags_impl(module, &path, flags);
511
512exit:
513 /* Cleanup for path */
514 path_cleanup(&path);
515
516 return return_value;
517}
518
519#endif /* defined(HAVE_LCHFLAGS) */
520
521#if defined(HAVE_CHROOT)
522
523PyDoc_STRVAR(os_chroot__doc__,
524"chroot($module, /, path)\n"
525"--\n"
526"\n"
527"Change root directory to path.");
528
529#define OS_CHROOT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700530 {"chroot", (PyCFunction)os_chroot, METH_FASTCALL, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300531
532static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300533os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300534
535static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700536os_chroot(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537{
538 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300539 static const char * const _keywords[] = {"path", NULL};
540 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300541 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
542
Victor Stinner37e4ef72016-09-09 20:00:13 -0700543 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300544 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300545 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300546 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300547 return_value = os_chroot_impl(module, &path);
548
549exit:
550 /* Cleanup for path */
551 path_cleanup(&path);
552
553 return return_value;
554}
555
556#endif /* defined(HAVE_CHROOT) */
557
558#if defined(HAVE_FSYNC)
559
560PyDoc_STRVAR(os_fsync__doc__,
561"fsync($module, /, fd)\n"
562"--\n"
563"\n"
564"Force write of fd to disk.");
565
566#define OS_FSYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700567 {"fsync", (PyCFunction)os_fsync, METH_FASTCALL, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300568
569static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300570os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300571
572static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700573os_fsync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300574{
575 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300576 static const char * const _keywords[] = {"fd", NULL};
577 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300578 int fd;
579
Victor Stinner37e4ef72016-09-09 20:00:13 -0700580 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300581 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300582 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300583 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300584 return_value = os_fsync_impl(module, fd);
585
586exit:
587 return return_value;
588}
589
590#endif /* defined(HAVE_FSYNC) */
591
592#if defined(HAVE_SYNC)
593
594PyDoc_STRVAR(os_sync__doc__,
595"sync($module, /)\n"
596"--\n"
597"\n"
598"Force write of everything to disk.");
599
600#define OS_SYNC_METHODDEF \
601 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
602
603static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300604os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300605
606static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300607os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300608{
609 return os_sync_impl(module);
610}
611
612#endif /* defined(HAVE_SYNC) */
613
614#if defined(HAVE_FDATASYNC)
615
616PyDoc_STRVAR(os_fdatasync__doc__,
617"fdatasync($module, /, fd)\n"
618"--\n"
619"\n"
620"Force write of fd to disk without forcing update of metadata.");
621
622#define OS_FDATASYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700623 {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300624
625static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300626os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300627
628static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700629os_fdatasync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300630{
631 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300632 static const char * const _keywords[] = {"fd", NULL};
633 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300634 int fd;
635
Victor Stinner37e4ef72016-09-09 20:00:13 -0700636 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300637 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300638 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300639 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300640 return_value = os_fdatasync_impl(module, fd);
641
642exit:
643 return return_value;
644}
645
646#endif /* defined(HAVE_FDATASYNC) */
647
648#if defined(HAVE_CHOWN)
649
650PyDoc_STRVAR(os_chown__doc__,
651"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
652"--\n"
653"\n"
654"Change the owner and group id of path to the numeric uid and gid.\\\n"
655"\n"
656" path\n"
657" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
658" dir_fd\n"
659" If not None, it should be a file descriptor open to a directory,\n"
660" and path should be relative; path will then be relative to that\n"
661" directory.\n"
662" follow_symlinks\n"
663" If False, and the last element of the path is a symbolic link,\n"
664" stat will examine the symbolic link itself instead of the file\n"
665" the link points to.\n"
666"\n"
667"path may always be specified as a string.\n"
668"On some platforms, path may also be specified as an open file descriptor.\n"
669" If this functionality is unavailable, using it raises an exception.\n"
670"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
671" and path should be relative; path will then be relative to that directory.\n"
672"If follow_symlinks is False, and the last element of the path is a symbolic\n"
673" link, chown will modify the symbolic link itself instead of the file the\n"
674" link points to.\n"
675"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
676" an open file descriptor.\n"
677"dir_fd and follow_symlinks may not be implemented on your platform.\n"
678" If they are unavailable, using them will raise a NotImplementedError.");
679
680#define OS_CHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700681 {"chown", (PyCFunction)os_chown, METH_FASTCALL, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300682
683static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300684os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400685 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300686
687static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700688os_chown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300689{
690 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300691 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
692 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300693 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
694 uid_t uid;
695 gid_t gid;
696 int dir_fd = DEFAULT_DIR_FD;
697 int follow_symlinks = 1;
698
Victor Stinner37e4ef72016-09-09 20:00:13 -0700699 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300700 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 +0300701 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300702 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300703 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
704
705exit:
706 /* Cleanup for path */
707 path_cleanup(&path);
708
709 return return_value;
710}
711
712#endif /* defined(HAVE_CHOWN) */
713
714#if defined(HAVE_FCHOWN)
715
716PyDoc_STRVAR(os_fchown__doc__,
717"fchown($module, /, fd, uid, gid)\n"
718"--\n"
719"\n"
720"Change the owner and group id of the file specified by file descriptor.\n"
721"\n"
722"Equivalent to os.chown(fd, uid, gid).");
723
724#define OS_FCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700725 {"fchown", (PyCFunction)os_fchown, METH_FASTCALL, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300726
727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300728os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300729
730static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700731os_fchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300732{
733 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300734 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
735 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300736 int fd;
737 uid_t uid;
738 gid_t gid;
739
Victor Stinner37e4ef72016-09-09 20:00:13 -0700740 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300741 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300742 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300743 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300744 return_value = os_fchown_impl(module, fd, uid, gid);
745
746exit:
747 return return_value;
748}
749
750#endif /* defined(HAVE_FCHOWN) */
751
752#if defined(HAVE_LCHOWN)
753
754PyDoc_STRVAR(os_lchown__doc__,
755"lchown($module, /, path, uid, gid)\n"
756"--\n"
757"\n"
758"Change the owner and group id of path to the numeric uid and gid.\n"
759"\n"
760"This function will not follow symbolic links.\n"
761"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
762
763#define OS_LCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700764 {"lchown", (PyCFunction)os_lchown, METH_FASTCALL, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300765
766static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300767os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300768
769static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700770os_lchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300771{
772 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300773 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
774 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300775 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
776 uid_t uid;
777 gid_t gid;
778
Victor Stinner37e4ef72016-09-09 20:00:13 -0700779 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300780 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300781 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300782 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300783 return_value = os_lchown_impl(module, &path, uid, gid);
784
785exit:
786 /* Cleanup for path */
787 path_cleanup(&path);
788
789 return return_value;
790}
791
792#endif /* defined(HAVE_LCHOWN) */
793
794PyDoc_STRVAR(os_getcwd__doc__,
795"getcwd($module, /)\n"
796"--\n"
797"\n"
798"Return a unicode string representing the current working directory.");
799
800#define OS_GETCWD_METHODDEF \
801 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
802
803static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300804os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300805
806static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300807os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300808{
809 return os_getcwd_impl(module);
810}
811
812PyDoc_STRVAR(os_getcwdb__doc__,
813"getcwdb($module, /)\n"
814"--\n"
815"\n"
816"Return a bytes string representing the current working directory.");
817
818#define OS_GETCWDB_METHODDEF \
819 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
820
821static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300822os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300823
824static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300825os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300826{
827 return os_getcwdb_impl(module);
828}
829
830#if defined(HAVE_LINK)
831
832PyDoc_STRVAR(os_link__doc__,
833"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
834" follow_symlinks=True)\n"
835"--\n"
836"\n"
837"Create a hard link to a file.\n"
838"\n"
839"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
840" descriptor open to a directory, and the respective path string (src or dst)\n"
841" should be relative; the path will then be relative to that directory.\n"
842"If follow_symlinks is False, and the last element of src is a symbolic\n"
843" link, link will create a link to the symbolic link itself instead of the\n"
844" file the link points to.\n"
845"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
846" platform. If they are unavailable, using them will raise a\n"
847" NotImplementedError.");
848
849#define OS_LINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700850 {"link", (PyCFunction)os_link, METH_FASTCALL, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300851
852static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300853os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400854 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300855
856static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700857os_link(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300858{
859 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300860 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
861 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300862 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
863 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
864 int src_dir_fd = DEFAULT_DIR_FD;
865 int dst_dir_fd = DEFAULT_DIR_FD;
866 int follow_symlinks = 1;
867
Victor Stinner37e4ef72016-09-09 20:00:13 -0700868 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300869 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 +0300870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300872 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
873
874exit:
875 /* Cleanup for src */
876 path_cleanup(&src);
877 /* Cleanup for dst */
878 path_cleanup(&dst);
879
880 return return_value;
881}
882
883#endif /* defined(HAVE_LINK) */
884
885PyDoc_STRVAR(os_listdir__doc__,
886"listdir($module, /, path=None)\n"
887"--\n"
888"\n"
889"Return a list containing the names of the files in the directory.\n"
890"\n"
891"path can be specified as either str or bytes. If path is bytes,\n"
892" the filenames returned will also be bytes; in all other circumstances\n"
893" the filenames returned will be str.\n"
894"If path is None, uses the path=\'.\'.\n"
895"On some platforms, path may also be specified as an open file descriptor;\\\n"
896" the file descriptor must refer to a directory.\n"
897" If this functionality is unavailable, using it raises NotImplementedError.\n"
898"\n"
899"The list is in arbitrary order. It does not include the special\n"
900"entries \'.\' and \'..\' even if they are present in the directory.");
901
902#define OS_LISTDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700903 {"listdir", (PyCFunction)os_listdir, METH_FASTCALL, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300904
905static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300906os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300907
908static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700909os_listdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300910{
911 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300912 static const char * const _keywords[] = {"path", NULL};
913 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300914 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
915
Victor Stinner37e4ef72016-09-09 20:00:13 -0700916 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300917 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300918 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300919 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300920 return_value = os_listdir_impl(module, &path);
921
922exit:
923 /* Cleanup for path */
924 path_cleanup(&path);
925
926 return return_value;
927}
928
929#if defined(MS_WINDOWS)
930
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300931PyDoc_STRVAR(os__getfullpathname__doc__,
932"_getfullpathname($module, path, /)\n"
933"--\n"
934"\n");
935
936#define OS__GETFULLPATHNAME_METHODDEF \
937 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
938
939static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300940os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300941
942static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300943os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300944{
945 PyObject *return_value = NULL;
946 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
947
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300948 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300949 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300950 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300951 return_value = os__getfullpathname_impl(module, &path);
952
953exit:
954 /* Cleanup for path */
955 path_cleanup(&path);
956
957 return return_value;
958}
959
960#endif /* defined(MS_WINDOWS) */
961
962#if defined(MS_WINDOWS)
963
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300964PyDoc_STRVAR(os__getfinalpathname__doc__,
965"_getfinalpathname($module, path, /)\n"
966"--\n"
967"\n"
968"A helper function for samepath on windows.");
969
970#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300971 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300972
973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300974os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300975
976static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300977os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300978{
979 PyObject *return_value = NULL;
980 PyObject *path;
981
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300982 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300983 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300984 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300985 return_value = os__getfinalpathname_impl(module, path);
986
987exit:
988 return return_value;
989}
990
991#endif /* defined(MS_WINDOWS) */
992
993#if defined(MS_WINDOWS)
994
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300995PyDoc_STRVAR(os__isdir__doc__,
996"_isdir($module, path, /)\n"
997"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200998"\n"
999"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001000
1001#define OS__ISDIR_METHODDEF \
1002 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1003
1004static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001005os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001006
1007static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001008os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001009{
1010 PyObject *return_value = NULL;
1011 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1012
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001013 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001014 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001015 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001016 return_value = os__isdir_impl(module, &path);
1017
1018exit:
1019 /* Cleanup for path */
1020 path_cleanup(&path);
1021
1022 return return_value;
1023}
1024
1025#endif /* defined(MS_WINDOWS) */
1026
1027#if defined(MS_WINDOWS)
1028
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001029PyDoc_STRVAR(os__getvolumepathname__doc__,
1030"_getvolumepathname($module, /, path)\n"
1031"--\n"
1032"\n"
1033"A helper function for ismount on Win32.");
1034
1035#define OS__GETVOLUMEPATHNAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001036 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001037
1038static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001039os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001040
1041static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001042os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001043{
1044 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001045 static const char * const _keywords[] = {"path", NULL};
1046 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001047 PyObject *path;
1048
Victor Stinner37e4ef72016-09-09 20:00:13 -07001049 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001050 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001051 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001052 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001053 return_value = os__getvolumepathname_impl(module, path);
1054
1055exit:
1056 return return_value;
1057}
1058
1059#endif /* defined(MS_WINDOWS) */
1060
1061PyDoc_STRVAR(os_mkdir__doc__,
1062"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1063"--\n"
1064"\n"
1065"Create a directory.\n"
1066"\n"
1067"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1068" and path should be relative; path will then be relative to that directory.\n"
1069"dir_fd may not be implemented on your platform.\n"
1070" If it is unavailable, using it will raise a NotImplementedError.\n"
1071"\n"
1072"The mode argument is ignored on Windows.");
1073
1074#define OS_MKDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001075 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001076
1077static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001078os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001079
1080static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001081os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001082{
1083 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001084 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1085 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001086 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1087 int mode = 511;
1088 int dir_fd = DEFAULT_DIR_FD;
1089
Victor Stinner37e4ef72016-09-09 20:00:13 -07001090 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001091 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001092 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001093 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001094 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1095
1096exit:
1097 /* Cleanup for path */
1098 path_cleanup(&path);
1099
1100 return return_value;
1101}
1102
1103#if defined(HAVE_NICE)
1104
1105PyDoc_STRVAR(os_nice__doc__,
1106"nice($module, increment, /)\n"
1107"--\n"
1108"\n"
1109"Add increment to the priority of process and return the new priority.");
1110
1111#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001112 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001113
1114static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001115os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001116
1117static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001118os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001119{
1120 PyObject *return_value = NULL;
1121 int increment;
1122
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001123 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001124 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001125 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001126 return_value = os_nice_impl(module, increment);
1127
1128exit:
1129 return return_value;
1130}
1131
1132#endif /* defined(HAVE_NICE) */
1133
1134#if defined(HAVE_GETPRIORITY)
1135
1136PyDoc_STRVAR(os_getpriority__doc__,
1137"getpriority($module, /, which, who)\n"
1138"--\n"
1139"\n"
1140"Return program scheduling priority.");
1141
1142#define OS_GETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001143 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001144
1145static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001146os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001147
1148static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001149os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001150{
1151 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001152 static const char * const _keywords[] = {"which", "who", NULL};
1153 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001154 int which;
1155 int who;
1156
Victor Stinner37e4ef72016-09-09 20:00:13 -07001157 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001158 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001159 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001160 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001161 return_value = os_getpriority_impl(module, which, who);
1162
1163exit:
1164 return return_value;
1165}
1166
1167#endif /* defined(HAVE_GETPRIORITY) */
1168
1169#if defined(HAVE_SETPRIORITY)
1170
1171PyDoc_STRVAR(os_setpriority__doc__,
1172"setpriority($module, /, which, who, priority)\n"
1173"--\n"
1174"\n"
1175"Set program scheduling priority.");
1176
1177#define OS_SETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001178 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001179
1180static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001181os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001182
1183static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001184os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001185{
1186 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001187 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1188 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001189 int which;
1190 int who;
1191 int priority;
1192
Victor Stinner37e4ef72016-09-09 20:00:13 -07001193 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001194 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001195 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001196 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001197 return_value = os_setpriority_impl(module, which, who, priority);
1198
1199exit:
1200 return return_value;
1201}
1202
1203#endif /* defined(HAVE_SETPRIORITY) */
1204
1205PyDoc_STRVAR(os_rename__doc__,
1206"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1207"--\n"
1208"\n"
1209"Rename a file or directory.\n"
1210"\n"
1211"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1212" descriptor open to a directory, and the respective path string (src or dst)\n"
1213" should be relative; the path will then be relative to that directory.\n"
1214"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1215" If they are unavailable, using them will raise a NotImplementedError.");
1216
1217#define OS_RENAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001218 {"rename", (PyCFunction)os_rename, METH_FASTCALL, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001219
1220static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001221os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001222 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001223
1224static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001225os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001226{
1227 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001228 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1229 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001230 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1231 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1232 int src_dir_fd = DEFAULT_DIR_FD;
1233 int dst_dir_fd = DEFAULT_DIR_FD;
1234
Victor Stinner37e4ef72016-09-09 20:00:13 -07001235 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001236 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 +03001237 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001238 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001239 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1240
1241exit:
1242 /* Cleanup for src */
1243 path_cleanup(&src);
1244 /* Cleanup for dst */
1245 path_cleanup(&dst);
1246
1247 return return_value;
1248}
1249
1250PyDoc_STRVAR(os_replace__doc__,
1251"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1252"--\n"
1253"\n"
1254"Rename a file or directory, overwriting the destination.\n"
1255"\n"
1256"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1257" descriptor open to a directory, and the respective path string (src or dst)\n"
1258" should be relative; the path will then be relative to that directory.\n"
1259"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1260" If they are unavailable, using them will raise a NotImplementedError.\"");
1261
1262#define OS_REPLACE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001263 {"replace", (PyCFunction)os_replace, METH_FASTCALL, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001264
1265static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001266os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1267 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001268
1269static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001270os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001271{
1272 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001273 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1274 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001275 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1276 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1277 int src_dir_fd = DEFAULT_DIR_FD;
1278 int dst_dir_fd = DEFAULT_DIR_FD;
1279
Victor Stinner37e4ef72016-09-09 20:00:13 -07001280 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001281 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 +03001282 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001283 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001284 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1285
1286exit:
1287 /* Cleanup for src */
1288 path_cleanup(&src);
1289 /* Cleanup for dst */
1290 path_cleanup(&dst);
1291
1292 return return_value;
1293}
1294
1295PyDoc_STRVAR(os_rmdir__doc__,
1296"rmdir($module, /, path, *, dir_fd=None)\n"
1297"--\n"
1298"\n"
1299"Remove a directory.\n"
1300"\n"
1301"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1302" and path should be relative; path will then be relative to that directory.\n"
1303"dir_fd may not be implemented on your platform.\n"
1304" If it is unavailable, using it will raise a NotImplementedError.");
1305
1306#define OS_RMDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001307 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001308
1309static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001310os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001311
1312static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001313os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001314{
1315 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001316 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1317 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001318 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1319 int dir_fd = DEFAULT_DIR_FD;
1320
Victor Stinner37e4ef72016-09-09 20:00:13 -07001321 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001322 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001323 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001324 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001325 return_value = os_rmdir_impl(module, &path, dir_fd);
1326
1327exit:
1328 /* Cleanup for path */
1329 path_cleanup(&path);
1330
1331 return return_value;
1332}
1333
1334#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1335
1336PyDoc_STRVAR(os_system__doc__,
1337"system($module, /, command)\n"
1338"--\n"
1339"\n"
1340"Execute the command in a subshell.");
1341
1342#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001343 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001344
1345static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001346os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001347
1348static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001349os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001350{
1351 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001352 static const char * const _keywords[] = {"command", NULL};
1353 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354 Py_UNICODE *command;
1355 long _return_value;
1356
Victor Stinner37e4ef72016-09-09 20:00:13 -07001357 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001358 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001359 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001360 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001361 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001362 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001363 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001364 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001365 return_value = PyLong_FromLong(_return_value);
1366
1367exit:
1368 return return_value;
1369}
1370
1371#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1372
1373#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1374
1375PyDoc_STRVAR(os_system__doc__,
1376"system($module, /, command)\n"
1377"--\n"
1378"\n"
1379"Execute the command in a subshell.");
1380
1381#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001382 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001383
1384static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001385os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001386
1387static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001388os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001389{
1390 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001391 static const char * const _keywords[] = {"command", NULL};
1392 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393 PyObject *command = NULL;
1394 long _return_value;
1395
Victor Stinner37e4ef72016-09-09 20:00:13 -07001396 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001397 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001400 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001401 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001402 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001403 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001404 return_value = PyLong_FromLong(_return_value);
1405
1406exit:
1407 /* Cleanup for command */
1408 Py_XDECREF(command);
1409
1410 return return_value;
1411}
1412
1413#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1414
1415PyDoc_STRVAR(os_umask__doc__,
1416"umask($module, mask, /)\n"
1417"--\n"
1418"\n"
1419"Set the current numeric umask and return the previous umask.");
1420
1421#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001422 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001423
1424static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001425os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001426
1427static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001428os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001429{
1430 PyObject *return_value = NULL;
1431 int mask;
1432
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001433 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001435 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001436 return_value = os_umask_impl(module, mask);
1437
1438exit:
1439 return return_value;
1440}
1441
1442PyDoc_STRVAR(os_unlink__doc__,
1443"unlink($module, /, path, *, dir_fd=None)\n"
1444"--\n"
1445"\n"
1446"Remove a file (same as remove()).\n"
1447"\n"
1448"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1449" and path should be relative; path will then be relative to that directory.\n"
1450"dir_fd may not be implemented on your platform.\n"
1451" If it is unavailable, using it will raise a NotImplementedError.");
1452
1453#define OS_UNLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001454 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001455
1456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001457os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001458
1459static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001460os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001461{
1462 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001463 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1464 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001465 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1466 int dir_fd = DEFAULT_DIR_FD;
1467
Victor Stinner37e4ef72016-09-09 20:00:13 -07001468 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001469 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001470 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001471 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001472 return_value = os_unlink_impl(module, &path, dir_fd);
1473
1474exit:
1475 /* Cleanup for path */
1476 path_cleanup(&path);
1477
1478 return return_value;
1479}
1480
1481PyDoc_STRVAR(os_remove__doc__,
1482"remove($module, /, path, *, dir_fd=None)\n"
1483"--\n"
1484"\n"
1485"Remove a file (same as unlink()).\n"
1486"\n"
1487"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1488" and path should be relative; path will then be relative to that directory.\n"
1489"dir_fd may not be implemented on your platform.\n"
1490" If it is unavailable, using it will raise a NotImplementedError.");
1491
1492#define OS_REMOVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001493 {"remove", (PyCFunction)os_remove, METH_FASTCALL, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001494
1495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001496os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001497
1498static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001499os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001500{
1501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001502 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1503 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001504 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1505 int dir_fd = DEFAULT_DIR_FD;
1506
Victor Stinner37e4ef72016-09-09 20:00:13 -07001507 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001508 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001511 return_value = os_remove_impl(module, &path, dir_fd);
1512
1513exit:
1514 /* Cleanup for path */
1515 path_cleanup(&path);
1516
1517 return return_value;
1518}
1519
1520#if defined(HAVE_UNAME)
1521
1522PyDoc_STRVAR(os_uname__doc__,
1523"uname($module, /)\n"
1524"--\n"
1525"\n"
1526"Return an object identifying the current operating system.\n"
1527"\n"
1528"The object behaves like a named tuple with the following fields:\n"
1529" (sysname, nodename, release, version, machine)");
1530
1531#define OS_UNAME_METHODDEF \
1532 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1533
1534static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001535os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001536
1537static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001538os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001539{
1540 return os_uname_impl(module);
1541}
1542
1543#endif /* defined(HAVE_UNAME) */
1544
1545PyDoc_STRVAR(os_utime__doc__,
1546"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1547" follow_symlinks=True)\n"
1548"--\n"
1549"\n"
1550"Set the access and modified time of path.\n"
1551"\n"
1552"path may always be specified as a string.\n"
1553"On some platforms, path may also be specified as an open file descriptor.\n"
1554" If this functionality is unavailable, using it raises an exception.\n"
1555"\n"
1556"If times is not None, it must be a tuple (atime, mtime);\n"
1557" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001558"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001559" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1560" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001561"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001562"Specifying tuples for both times and ns is an error.\n"
1563"\n"
1564"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1565" and path should be relative; path will then be relative to that directory.\n"
1566"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1567" link, utime will modify the symbolic link itself instead of the file the\n"
1568" link points to.\n"
1569"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1570" as an open file descriptor.\n"
1571"dir_fd and follow_symlinks may not be available on your platform.\n"
1572" If they are unavailable, using them will raise a NotImplementedError.");
1573
1574#define OS_UTIME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001575 {"utime", (PyCFunction)os_utime, METH_FASTCALL, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001576
1577static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001578os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1579 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001580
1581static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001582os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001583{
1584 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001585 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1586 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001587 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1588 PyObject *times = NULL;
1589 PyObject *ns = NULL;
1590 int dir_fd = DEFAULT_DIR_FD;
1591 int follow_symlinks = 1;
1592
Victor Stinner37e4ef72016-09-09 20:00:13 -07001593 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001594 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001595 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001596 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001597 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1598
1599exit:
1600 /* Cleanup for path */
1601 path_cleanup(&path);
1602
1603 return return_value;
1604}
1605
1606PyDoc_STRVAR(os__exit__doc__,
1607"_exit($module, /, status)\n"
1608"--\n"
1609"\n"
1610"Exit to the system with specified status, without normal exit processing.");
1611
1612#define OS__EXIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001613 {"_exit", (PyCFunction)os__exit, METH_FASTCALL, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001614
1615static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001616os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001617
1618static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001619os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001620{
1621 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001622 static const char * const _keywords[] = {"status", NULL};
1623 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001624 int status;
1625
Victor Stinner37e4ef72016-09-09 20:00:13 -07001626 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001627 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001628 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001629 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001630 return_value = os__exit_impl(module, status);
1631
1632exit:
1633 return return_value;
1634}
1635
1636#if defined(HAVE_EXECV)
1637
1638PyDoc_STRVAR(os_execv__doc__,
1639"execv($module, path, argv, /)\n"
1640"--\n"
1641"\n"
1642"Execute an executable path with arguments, replacing current process.\n"
1643"\n"
1644" path\n"
1645" Path of executable file.\n"
1646" argv\n"
1647" Tuple or list of strings.");
1648
1649#define OS_EXECV_METHODDEF \
1650 {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
1651
1652static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001653os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001654
1655static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001656os_execv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001657{
1658 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001659 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001660 PyObject *argv;
1661
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001662 if (!PyArg_ParseTuple(args, "O&O:execv",
Steve Dowercc16be82016-09-08 10:35:16 -07001663 path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001664 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001665 }
Steve Dowercc16be82016-09-08 10:35:16 -07001666 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001667
1668exit:
1669 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001670 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001671
1672 return return_value;
1673}
1674
1675#endif /* defined(HAVE_EXECV) */
1676
1677#if defined(HAVE_EXECV)
1678
1679PyDoc_STRVAR(os_execve__doc__,
1680"execve($module, /, path, argv, env)\n"
1681"--\n"
1682"\n"
1683"Execute an executable path with arguments, replacing current process.\n"
1684"\n"
1685" path\n"
1686" Path of executable file.\n"
1687" argv\n"
1688" Tuple or list of strings.\n"
1689" env\n"
1690" Dictionary of strings mapping to strings.");
1691
1692#define OS_EXECVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001693 {"execve", (PyCFunction)os_execve, METH_FASTCALL, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001694
1695static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001696os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001697
1698static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001699os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001700{
1701 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001702 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1703 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001704 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1705 PyObject *argv;
1706 PyObject *env;
1707
Victor Stinner37e4ef72016-09-09 20:00:13 -07001708 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001709 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001710 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001711 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001712 return_value = os_execve_impl(module, &path, argv, env);
1713
1714exit:
1715 /* Cleanup for path */
1716 path_cleanup(&path);
1717
1718 return return_value;
1719}
1720
1721#endif /* defined(HAVE_EXECV) */
1722
Steve Dowercc16be82016-09-08 10:35:16 -07001723#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001724
1725PyDoc_STRVAR(os_spawnv__doc__,
1726"spawnv($module, mode, path, argv, /)\n"
1727"--\n"
1728"\n"
1729"Execute the program specified by path in a new process.\n"
1730"\n"
1731" mode\n"
1732" Mode of process creation.\n"
1733" path\n"
1734" Path of executable file.\n"
1735" argv\n"
1736" Tuple or list of strings.");
1737
1738#define OS_SPAWNV_METHODDEF \
1739 {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
1740
1741static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001742os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001743
1744static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001745os_spawnv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001746{
1747 PyObject *return_value = NULL;
1748 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001749 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001750 PyObject *argv;
1751
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001752 if (!PyArg_ParseTuple(args, "iO&O:spawnv",
Steve Dowercc16be82016-09-08 10:35:16 -07001753 &mode, path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001754 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001755 }
Steve Dowercc16be82016-09-08 10:35:16 -07001756 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001757
1758exit:
1759 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001760 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001761
1762 return return_value;
1763}
1764
Steve Dowercc16be82016-09-08 10:35:16 -07001765#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001766
Steve Dowercc16be82016-09-08 10:35:16 -07001767#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001768
1769PyDoc_STRVAR(os_spawnve__doc__,
1770"spawnve($module, mode, path, argv, env, /)\n"
1771"--\n"
1772"\n"
1773"Execute the program specified by path in a new process.\n"
1774"\n"
1775" mode\n"
1776" Mode of process creation.\n"
1777" path\n"
1778" Path of executable file.\n"
1779" argv\n"
1780" Tuple or list of strings.\n"
1781" env\n"
1782" Dictionary of strings mapping to strings.");
1783
1784#define OS_SPAWNVE_METHODDEF \
1785 {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
1786
1787static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001788os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001789 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001790
1791static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001792os_spawnve(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001793{
1794 PyObject *return_value = NULL;
1795 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001796 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001797 PyObject *argv;
1798 PyObject *env;
1799
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001800 if (!PyArg_ParseTuple(args, "iO&OO:spawnve",
Steve Dowercc16be82016-09-08 10:35:16 -07001801 &mode, path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001802 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001803 }
Steve Dowercc16be82016-09-08 10:35:16 -07001804 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001805
1806exit:
1807 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001808 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001809
1810 return return_value;
1811}
1812
Steve Dowercc16be82016-09-08 10:35:16 -07001813#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001814
1815#if defined(HAVE_FORK1)
1816
1817PyDoc_STRVAR(os_fork1__doc__,
1818"fork1($module, /)\n"
1819"--\n"
1820"\n"
1821"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1822"\n"
1823"Return 0 to child process and PID of child to parent process.");
1824
1825#define OS_FORK1_METHODDEF \
1826 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1827
1828static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001829os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001830
1831static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001832os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001833{
1834 return os_fork1_impl(module);
1835}
1836
1837#endif /* defined(HAVE_FORK1) */
1838
1839#if defined(HAVE_FORK)
1840
1841PyDoc_STRVAR(os_fork__doc__,
1842"fork($module, /)\n"
1843"--\n"
1844"\n"
1845"Fork a child process.\n"
1846"\n"
1847"Return 0 to child process and PID of child to parent process.");
1848
1849#define OS_FORK_METHODDEF \
1850 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1851
1852static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001853os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001854
1855static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001856os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001857{
1858 return os_fork_impl(module);
1859}
1860
1861#endif /* defined(HAVE_FORK) */
1862
1863#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1864
1865PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1866"sched_get_priority_max($module, /, policy)\n"
1867"--\n"
1868"\n"
1869"Get the maximum scheduling priority for policy.");
1870
1871#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001872 {"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 +03001873
1874static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001875os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001876
1877static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001878os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001879{
1880 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001881 static const char * const _keywords[] = {"policy", NULL};
1882 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001883 int policy;
1884
Victor Stinner37e4ef72016-09-09 20:00:13 -07001885 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001886 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001887 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001888 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001889 return_value = os_sched_get_priority_max_impl(module, policy);
1890
1891exit:
1892 return return_value;
1893}
1894
1895#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1896
1897#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1898
1899PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1900"sched_get_priority_min($module, /, policy)\n"
1901"--\n"
1902"\n"
1903"Get the minimum scheduling priority for policy.");
1904
1905#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001906 {"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 +03001907
1908static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001909os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001910
1911static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001912os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001913{
1914 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001915 static const char * const _keywords[] = {"policy", NULL};
1916 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001917 int policy;
1918
Victor Stinner37e4ef72016-09-09 20:00:13 -07001919 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001920 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001921 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001922 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001923 return_value = os_sched_get_priority_min_impl(module, policy);
1924
1925exit:
1926 return return_value;
1927}
1928
1929#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1930
1931#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1932
1933PyDoc_STRVAR(os_sched_getscheduler__doc__,
1934"sched_getscheduler($module, pid, /)\n"
1935"--\n"
1936"\n"
1937"Get the scheduling policy for the process identifiedy by pid.\n"
1938"\n"
1939"Passing 0 for pid returns the scheduling policy for the calling process.");
1940
1941#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001942 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001943
1944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001945os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001946
1947static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001948os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001949{
1950 PyObject *return_value = NULL;
1951 pid_t pid;
1952
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001953 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001954 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001955 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001956 return_value = os_sched_getscheduler_impl(module, pid);
1957
1958exit:
1959 return return_value;
1960}
1961
1962#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1963
1964#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1965
1966PyDoc_STRVAR(os_sched_param__doc__,
1967"sched_param(sched_priority)\n"
1968"--\n"
1969"\n"
1970"Current has only one field: sched_priority\");\n"
1971"\n"
1972" sched_priority\n"
1973" A scheduling parameter.");
1974
1975static PyObject *
1976os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1977
1978static PyObject *
1979os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1980{
1981 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001982 static const char * const _keywords[] = {"sched_priority", NULL};
1983 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001984 PyObject *sched_priority;
1985
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001986 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001987 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001988 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001989 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001990 return_value = os_sched_param_impl(type, sched_priority);
1991
1992exit:
1993 return return_value;
1994}
1995
1996#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
1997
1998#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1999
2000PyDoc_STRVAR(os_sched_setscheduler__doc__,
2001"sched_setscheduler($module, pid, policy, param, /)\n"
2002"--\n"
2003"\n"
2004"Set the scheduling policy for the process identified by pid.\n"
2005"\n"
2006"If pid is 0, the calling process is changed.\n"
2007"param is an instance of sched_param.");
2008
2009#define OS_SCHED_SETSCHEDULER_METHODDEF \
2010 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
2011
2012static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002013os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002014 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002015
2016static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002017os_sched_setscheduler(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002018{
2019 PyObject *return_value = NULL;
2020 pid_t pid;
2021 int policy;
2022 struct sched_param param;
2023
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002024 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002025 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002026 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002027 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002028 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2029
2030exit:
2031 return return_value;
2032}
2033
2034#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2035
2036#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2037
2038PyDoc_STRVAR(os_sched_getparam__doc__,
2039"sched_getparam($module, pid, /)\n"
2040"--\n"
2041"\n"
2042"Returns scheduling parameters for the process identified by pid.\n"
2043"\n"
2044"If pid is 0, returns parameters for the calling process.\n"
2045"Return value is an instance of sched_param.");
2046
2047#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002048 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002049
2050static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002051os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002052
2053static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002054os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002055{
2056 PyObject *return_value = NULL;
2057 pid_t pid;
2058
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002059 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002060 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002061 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002062 return_value = os_sched_getparam_impl(module, pid);
2063
2064exit:
2065 return return_value;
2066}
2067
2068#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2069
2070#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2071
2072PyDoc_STRVAR(os_sched_setparam__doc__,
2073"sched_setparam($module, pid, param, /)\n"
2074"--\n"
2075"\n"
2076"Set scheduling parameters for the process identified by pid.\n"
2077"\n"
2078"If pid is 0, sets parameters for the calling process.\n"
2079"param should be an instance of sched_param.");
2080
2081#define OS_SCHED_SETPARAM_METHODDEF \
2082 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
2083
2084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002085os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002086 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002087
2088static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002089os_sched_setparam(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002090{
2091 PyObject *return_value = NULL;
2092 pid_t pid;
2093 struct sched_param param;
2094
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002095 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002096 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002097 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002098 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002099 return_value = os_sched_setparam_impl(module, pid, &param);
2100
2101exit:
2102 return return_value;
2103}
2104
2105#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2106
2107#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2108
2109PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2110"sched_rr_get_interval($module, pid, /)\n"
2111"--\n"
2112"\n"
2113"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2114"\n"
2115"Value returned is a float.");
2116
2117#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002118 {"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 +03002119
2120static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002121os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002122
2123static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002124os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002125{
2126 PyObject *return_value = NULL;
2127 pid_t pid;
2128 double _return_value;
2129
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002130 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002131 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002132 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002133 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002134 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002135 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002136 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002137 return_value = PyFloat_FromDouble(_return_value);
2138
2139exit:
2140 return return_value;
2141}
2142
2143#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2144
2145#if defined(HAVE_SCHED_H)
2146
2147PyDoc_STRVAR(os_sched_yield__doc__,
2148"sched_yield($module, /)\n"
2149"--\n"
2150"\n"
2151"Voluntarily relinquish the CPU.");
2152
2153#define OS_SCHED_YIELD_METHODDEF \
2154 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2155
2156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002157os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158
2159static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002160os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002161{
2162 return os_sched_yield_impl(module);
2163}
2164
2165#endif /* defined(HAVE_SCHED_H) */
2166
2167#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2168
2169PyDoc_STRVAR(os_sched_setaffinity__doc__,
2170"sched_setaffinity($module, pid, mask, /)\n"
2171"--\n"
2172"\n"
2173"Set the CPU affinity of the process identified by pid to mask.\n"
2174"\n"
2175"mask should be an iterable of integers identifying CPUs.");
2176
2177#define OS_SCHED_SETAFFINITY_METHODDEF \
2178 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
2179
2180static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002181os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002182
2183static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002184os_sched_setaffinity(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002185{
2186 PyObject *return_value = NULL;
2187 pid_t pid;
2188 PyObject *mask;
2189
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002190 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002191 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002192 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002193 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002194 return_value = os_sched_setaffinity_impl(module, pid, mask);
2195
2196exit:
2197 return return_value;
2198}
2199
2200#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2201
2202#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2203
2204PyDoc_STRVAR(os_sched_getaffinity__doc__,
2205"sched_getaffinity($module, pid, /)\n"
2206"--\n"
2207"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002208"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002209"\n"
2210"The affinity is returned as a set of CPU identifiers.");
2211
2212#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002213 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002214
2215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002216os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002217
2218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002219os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002220{
2221 PyObject *return_value = NULL;
2222 pid_t pid;
2223
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002224 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002225 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002226 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002227 return_value = os_sched_getaffinity_impl(module, pid);
2228
2229exit:
2230 return return_value;
2231}
2232
2233#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2234
2235#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2236
2237PyDoc_STRVAR(os_openpty__doc__,
2238"openpty($module, /)\n"
2239"--\n"
2240"\n"
2241"Open a pseudo-terminal.\n"
2242"\n"
2243"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2244"for both the master and slave ends.");
2245
2246#define OS_OPENPTY_METHODDEF \
2247 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2248
2249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002250os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002251
2252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002253os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002254{
2255 return os_openpty_impl(module);
2256}
2257
2258#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2259
2260#if defined(HAVE_FORKPTY)
2261
2262PyDoc_STRVAR(os_forkpty__doc__,
2263"forkpty($module, /)\n"
2264"--\n"
2265"\n"
2266"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2267"\n"
2268"Returns a tuple of (pid, master_fd).\n"
2269"Like fork(), return pid of 0 to the child process,\n"
2270"and pid of child to the parent process.\n"
2271"To both, return fd of newly opened pseudo-terminal.");
2272
2273#define OS_FORKPTY_METHODDEF \
2274 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2275
2276static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002277os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002278
2279static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002280os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002281{
2282 return os_forkpty_impl(module);
2283}
2284
2285#endif /* defined(HAVE_FORKPTY) */
2286
2287#if defined(HAVE_GETEGID)
2288
2289PyDoc_STRVAR(os_getegid__doc__,
2290"getegid($module, /)\n"
2291"--\n"
2292"\n"
2293"Return the current process\'s effective group id.");
2294
2295#define OS_GETEGID_METHODDEF \
2296 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2297
2298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002299os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002300
2301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002302os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002303{
2304 return os_getegid_impl(module);
2305}
2306
2307#endif /* defined(HAVE_GETEGID) */
2308
2309#if defined(HAVE_GETEUID)
2310
2311PyDoc_STRVAR(os_geteuid__doc__,
2312"geteuid($module, /)\n"
2313"--\n"
2314"\n"
2315"Return the current process\'s effective user id.");
2316
2317#define OS_GETEUID_METHODDEF \
2318 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2319
2320static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002321os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002322
2323static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002324os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002325{
2326 return os_geteuid_impl(module);
2327}
2328
2329#endif /* defined(HAVE_GETEUID) */
2330
2331#if defined(HAVE_GETGID)
2332
2333PyDoc_STRVAR(os_getgid__doc__,
2334"getgid($module, /)\n"
2335"--\n"
2336"\n"
2337"Return the current process\'s group id.");
2338
2339#define OS_GETGID_METHODDEF \
2340 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2341
2342static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002343os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002344
2345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002346os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002347{
2348 return os_getgid_impl(module);
2349}
2350
2351#endif /* defined(HAVE_GETGID) */
2352
Berker Peksag39404992016-09-15 20:45:16 +03002353#if defined(HAVE_GETPID)
2354
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002355PyDoc_STRVAR(os_getpid__doc__,
2356"getpid($module, /)\n"
2357"--\n"
2358"\n"
2359"Return the current process id.");
2360
2361#define OS_GETPID_METHODDEF \
2362 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2363
2364static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002365os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002366
2367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002368os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002369{
2370 return os_getpid_impl(module);
2371}
2372
Berker Peksag39404992016-09-15 20:45:16 +03002373#endif /* defined(HAVE_GETPID) */
2374
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002375#if defined(HAVE_GETGROUPS)
2376
2377PyDoc_STRVAR(os_getgroups__doc__,
2378"getgroups($module, /)\n"
2379"--\n"
2380"\n"
2381"Return list of supplemental group IDs for the process.");
2382
2383#define OS_GETGROUPS_METHODDEF \
2384 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2385
2386static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002387os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002388
2389static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002390os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002391{
2392 return os_getgroups_impl(module);
2393}
2394
2395#endif /* defined(HAVE_GETGROUPS) */
2396
2397#if defined(HAVE_GETPGID)
2398
2399PyDoc_STRVAR(os_getpgid__doc__,
2400"getpgid($module, /, pid)\n"
2401"--\n"
2402"\n"
2403"Call the system call getpgid(), and return the result.");
2404
2405#define OS_GETPGID_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002406 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002407
2408static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002409os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002410
2411static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002412os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002413{
2414 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002415 static const char * const _keywords[] = {"pid", NULL};
2416 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002417 pid_t pid;
2418
Victor Stinner37e4ef72016-09-09 20:00:13 -07002419 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002420 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002421 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002422 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002423 return_value = os_getpgid_impl(module, pid);
2424
2425exit:
2426 return return_value;
2427}
2428
2429#endif /* defined(HAVE_GETPGID) */
2430
2431#if defined(HAVE_GETPGRP)
2432
2433PyDoc_STRVAR(os_getpgrp__doc__,
2434"getpgrp($module, /)\n"
2435"--\n"
2436"\n"
2437"Return the current process group id.");
2438
2439#define OS_GETPGRP_METHODDEF \
2440 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2441
2442static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002443os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002444
2445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002446os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002447{
2448 return os_getpgrp_impl(module);
2449}
2450
2451#endif /* defined(HAVE_GETPGRP) */
2452
2453#if defined(HAVE_SETPGRP)
2454
2455PyDoc_STRVAR(os_setpgrp__doc__,
2456"setpgrp($module, /)\n"
2457"--\n"
2458"\n"
2459"Make the current process the leader of its process group.");
2460
2461#define OS_SETPGRP_METHODDEF \
2462 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2463
2464static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002465os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002466
2467static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002468os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002469{
2470 return os_setpgrp_impl(module);
2471}
2472
2473#endif /* defined(HAVE_SETPGRP) */
2474
2475#if defined(HAVE_GETPPID)
2476
2477PyDoc_STRVAR(os_getppid__doc__,
2478"getppid($module, /)\n"
2479"--\n"
2480"\n"
2481"Return the parent\'s process id.\n"
2482"\n"
2483"If the parent process has already exited, Windows machines will still\n"
2484"return its id; others systems will return the id of the \'init\' process (1).");
2485
2486#define OS_GETPPID_METHODDEF \
2487 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2488
2489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002490os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491
2492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002493os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002494{
2495 return os_getppid_impl(module);
2496}
2497
2498#endif /* defined(HAVE_GETPPID) */
2499
2500#if defined(HAVE_GETLOGIN)
2501
2502PyDoc_STRVAR(os_getlogin__doc__,
2503"getlogin($module, /)\n"
2504"--\n"
2505"\n"
2506"Return the actual login name.");
2507
2508#define OS_GETLOGIN_METHODDEF \
2509 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2510
2511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002512os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002513
2514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002515os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002516{
2517 return os_getlogin_impl(module);
2518}
2519
2520#endif /* defined(HAVE_GETLOGIN) */
2521
2522#if defined(HAVE_GETUID)
2523
2524PyDoc_STRVAR(os_getuid__doc__,
2525"getuid($module, /)\n"
2526"--\n"
2527"\n"
2528"Return the current process\'s user id.");
2529
2530#define OS_GETUID_METHODDEF \
2531 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2532
2533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002534os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002535
2536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002537os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002538{
2539 return os_getuid_impl(module);
2540}
2541
2542#endif /* defined(HAVE_GETUID) */
2543
2544#if defined(HAVE_KILL)
2545
2546PyDoc_STRVAR(os_kill__doc__,
2547"kill($module, pid, signal, /)\n"
2548"--\n"
2549"\n"
2550"Kill a process with a signal.");
2551
2552#define OS_KILL_METHODDEF \
2553 {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
2554
2555static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002556os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002557
2558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002559os_kill(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002560{
2561 PyObject *return_value = NULL;
2562 pid_t pid;
2563 Py_ssize_t signal;
2564
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002565 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002566 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002567 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002568 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002569 return_value = os_kill_impl(module, pid, signal);
2570
2571exit:
2572 return return_value;
2573}
2574
2575#endif /* defined(HAVE_KILL) */
2576
2577#if defined(HAVE_KILLPG)
2578
2579PyDoc_STRVAR(os_killpg__doc__,
2580"killpg($module, pgid, signal, /)\n"
2581"--\n"
2582"\n"
2583"Kill a process group with a signal.");
2584
2585#define OS_KILLPG_METHODDEF \
2586 {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
2587
2588static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002589os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002590
2591static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002592os_killpg(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002593{
2594 PyObject *return_value = NULL;
2595 pid_t pgid;
2596 int signal;
2597
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002598 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002599 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002600 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002601 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002602 return_value = os_killpg_impl(module, pgid, signal);
2603
2604exit:
2605 return return_value;
2606}
2607
2608#endif /* defined(HAVE_KILLPG) */
2609
2610#if defined(HAVE_PLOCK)
2611
2612PyDoc_STRVAR(os_plock__doc__,
2613"plock($module, op, /)\n"
2614"--\n"
2615"\n"
2616"Lock program segments into memory.\");");
2617
2618#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002619 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002620
2621static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002622os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002623
2624static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002625os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002626{
2627 PyObject *return_value = NULL;
2628 int op;
2629
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002630 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002631 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002632 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002633 return_value = os_plock_impl(module, op);
2634
2635exit:
2636 return return_value;
2637}
2638
2639#endif /* defined(HAVE_PLOCK) */
2640
2641#if defined(HAVE_SETUID)
2642
2643PyDoc_STRVAR(os_setuid__doc__,
2644"setuid($module, uid, /)\n"
2645"--\n"
2646"\n"
2647"Set the current process\'s user id.");
2648
2649#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002650 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002651
2652static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002653os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002654
2655static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002656os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657{
2658 PyObject *return_value = NULL;
2659 uid_t uid;
2660
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002661 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002662 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002663 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002664 return_value = os_setuid_impl(module, uid);
2665
2666exit:
2667 return return_value;
2668}
2669
2670#endif /* defined(HAVE_SETUID) */
2671
2672#if defined(HAVE_SETEUID)
2673
2674PyDoc_STRVAR(os_seteuid__doc__,
2675"seteuid($module, euid, /)\n"
2676"--\n"
2677"\n"
2678"Set the current process\'s effective user id.");
2679
2680#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002681 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002682
2683static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002684os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002685
2686static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002687os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002688{
2689 PyObject *return_value = NULL;
2690 uid_t euid;
2691
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002692 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002693 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002694 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002695 return_value = os_seteuid_impl(module, euid);
2696
2697exit:
2698 return return_value;
2699}
2700
2701#endif /* defined(HAVE_SETEUID) */
2702
2703#if defined(HAVE_SETEGID)
2704
2705PyDoc_STRVAR(os_setegid__doc__,
2706"setegid($module, egid, /)\n"
2707"--\n"
2708"\n"
2709"Set the current process\'s effective group id.");
2710
2711#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002712 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002713
2714static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002715os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002716
2717static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002718os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002719{
2720 PyObject *return_value = NULL;
2721 gid_t egid;
2722
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002723 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002724 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002725 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002726 return_value = os_setegid_impl(module, egid);
2727
2728exit:
2729 return return_value;
2730}
2731
2732#endif /* defined(HAVE_SETEGID) */
2733
2734#if defined(HAVE_SETREUID)
2735
2736PyDoc_STRVAR(os_setreuid__doc__,
2737"setreuid($module, ruid, euid, /)\n"
2738"--\n"
2739"\n"
2740"Set the current process\'s real and effective user ids.");
2741
2742#define OS_SETREUID_METHODDEF \
2743 {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
2744
2745static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002746os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002747
2748static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002749os_setreuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002750{
2751 PyObject *return_value = NULL;
2752 uid_t ruid;
2753 uid_t euid;
2754
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002755 if (!PyArg_ParseTuple(args, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002756 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002757 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002758 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002759 return_value = os_setreuid_impl(module, ruid, euid);
2760
2761exit:
2762 return return_value;
2763}
2764
2765#endif /* defined(HAVE_SETREUID) */
2766
2767#if defined(HAVE_SETREGID)
2768
2769PyDoc_STRVAR(os_setregid__doc__,
2770"setregid($module, rgid, egid, /)\n"
2771"--\n"
2772"\n"
2773"Set the current process\'s real and effective group ids.");
2774
2775#define OS_SETREGID_METHODDEF \
2776 {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
2777
2778static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002779os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002780
2781static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002782os_setregid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002783{
2784 PyObject *return_value = NULL;
2785 gid_t rgid;
2786 gid_t egid;
2787
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002788 if (!PyArg_ParseTuple(args, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002789 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002790 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002791 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002792 return_value = os_setregid_impl(module, rgid, egid);
2793
2794exit:
2795 return return_value;
2796}
2797
2798#endif /* defined(HAVE_SETREGID) */
2799
2800#if defined(HAVE_SETGID)
2801
2802PyDoc_STRVAR(os_setgid__doc__,
2803"setgid($module, gid, /)\n"
2804"--\n"
2805"\n"
2806"Set the current process\'s group id.");
2807
2808#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002809 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002810
2811static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002812os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002813
2814static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002815os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002816{
2817 PyObject *return_value = NULL;
2818 gid_t gid;
2819
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002820 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002821 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002822 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002823 return_value = os_setgid_impl(module, gid);
2824
2825exit:
2826 return return_value;
2827}
2828
2829#endif /* defined(HAVE_SETGID) */
2830
2831#if defined(HAVE_SETGROUPS)
2832
2833PyDoc_STRVAR(os_setgroups__doc__,
2834"setgroups($module, groups, /)\n"
2835"--\n"
2836"\n"
2837"Set the groups of the current process to list.");
2838
2839#define OS_SETGROUPS_METHODDEF \
2840 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2841
2842#endif /* defined(HAVE_SETGROUPS) */
2843
2844#if defined(HAVE_WAIT3)
2845
2846PyDoc_STRVAR(os_wait3__doc__,
2847"wait3($module, /, options)\n"
2848"--\n"
2849"\n"
2850"Wait for completion of a child process.\n"
2851"\n"
2852"Returns a tuple of information about the child process:\n"
2853" (pid, status, rusage)");
2854
2855#define OS_WAIT3_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002856 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002857
2858static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002859os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002860
2861static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002862os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002863{
2864 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002865 static const char * const _keywords[] = {"options", NULL};
2866 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002867 int options;
2868
Victor Stinner37e4ef72016-09-09 20:00:13 -07002869 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002870 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002873 return_value = os_wait3_impl(module, options);
2874
2875exit:
2876 return return_value;
2877}
2878
2879#endif /* defined(HAVE_WAIT3) */
2880
2881#if defined(HAVE_WAIT4)
2882
2883PyDoc_STRVAR(os_wait4__doc__,
2884"wait4($module, /, pid, options)\n"
2885"--\n"
2886"\n"
2887"Wait for completion of a specific child process.\n"
2888"\n"
2889"Returns a tuple of information about the child process:\n"
2890" (pid, status, rusage)");
2891
2892#define OS_WAIT4_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002893 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002894
2895static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002896os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002897
2898static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002899os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002900{
2901 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002902 static const char * const _keywords[] = {"pid", "options", NULL};
2903 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002904 pid_t pid;
2905 int options;
2906
Victor Stinner37e4ef72016-09-09 20:00:13 -07002907 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002908 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002909 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002910 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002911 return_value = os_wait4_impl(module, pid, options);
2912
2913exit:
2914 return return_value;
2915}
2916
2917#endif /* defined(HAVE_WAIT4) */
2918
2919#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2920
2921PyDoc_STRVAR(os_waitid__doc__,
2922"waitid($module, idtype, id, options, /)\n"
2923"--\n"
2924"\n"
2925"Returns the result of waiting for a process or processes.\n"
2926"\n"
2927" idtype\n"
2928" Must be one of be P_PID, P_PGID or P_ALL.\n"
2929" id\n"
2930" The id to wait on.\n"
2931" options\n"
2932" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2933" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2934"\n"
2935"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2936"no children in a waitable state.");
2937
2938#define OS_WAITID_METHODDEF \
2939 {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
2940
2941static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002942os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002943
2944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002945os_waitid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002946{
2947 PyObject *return_value = NULL;
2948 idtype_t idtype;
2949 id_t id;
2950 int options;
2951
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002952 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002953 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002954 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002955 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002956 return_value = os_waitid_impl(module, idtype, id, options);
2957
2958exit:
2959 return return_value;
2960}
2961
2962#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
2963
2964#if defined(HAVE_WAITPID)
2965
2966PyDoc_STRVAR(os_waitpid__doc__,
2967"waitpid($module, pid, options, /)\n"
2968"--\n"
2969"\n"
2970"Wait for completion of a given child process.\n"
2971"\n"
2972"Returns a tuple of information regarding the child process:\n"
2973" (pid, status)\n"
2974"\n"
2975"The options argument is ignored on Windows.");
2976
2977#define OS_WAITPID_METHODDEF \
2978 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2979
2980static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002981os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002982
2983static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002984os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002985{
2986 PyObject *return_value = NULL;
2987 pid_t pid;
2988 int options;
2989
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002990 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002991 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002992 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002993 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002994 return_value = os_waitpid_impl(module, pid, options);
2995
2996exit:
2997 return return_value;
2998}
2999
3000#endif /* defined(HAVE_WAITPID) */
3001
3002#if defined(HAVE_CWAIT)
3003
3004PyDoc_STRVAR(os_waitpid__doc__,
3005"waitpid($module, pid, options, /)\n"
3006"--\n"
3007"\n"
3008"Wait for completion of a given process.\n"
3009"\n"
3010"Returns a tuple of information regarding the process:\n"
3011" (pid, status << 8)\n"
3012"\n"
3013"The options argument is ignored on Windows.");
3014
3015#define OS_WAITPID_METHODDEF \
3016 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
3017
3018static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003019os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003020
3021static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003022os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003023{
3024 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003025 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003026 int options;
3027
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003028 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003029 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003030 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003031 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003032 return_value = os_waitpid_impl(module, pid, options);
3033
3034exit:
3035 return return_value;
3036}
3037
3038#endif /* defined(HAVE_CWAIT) */
3039
3040#if defined(HAVE_WAIT)
3041
3042PyDoc_STRVAR(os_wait__doc__,
3043"wait($module, /)\n"
3044"--\n"
3045"\n"
3046"Wait for completion of a child process.\n"
3047"\n"
3048"Returns a tuple of information about the child process:\n"
3049" (pid, status)");
3050
3051#define OS_WAIT_METHODDEF \
3052 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3053
3054static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003055os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003056
3057static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003058os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003059{
3060 return os_wait_impl(module);
3061}
3062
3063#endif /* defined(HAVE_WAIT) */
3064
3065#if defined(HAVE_SYMLINK)
3066
3067PyDoc_STRVAR(os_symlink__doc__,
3068"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3069"--\n"
3070"\n"
3071"Create a symbolic link pointing to src named dst.\n"
3072"\n"
3073"target_is_directory is required on Windows if the target is to be\n"
3074" interpreted as a directory. (On Windows, symlink requires\n"
3075" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3076" target_is_directory is ignored on non-Windows platforms.\n"
3077"\n"
3078"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3079" and path should be relative; path will then be relative to that directory.\n"
3080"dir_fd may not be implemented on your platform.\n"
3081" If it is unavailable, using it will raise a NotImplementedError.");
3082
3083#define OS_SYMLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003084 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003085
3086static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003087os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003088 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003089
3090static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003091os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003092{
3093 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003094 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3095 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003096 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3097 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3098 int target_is_directory = 0;
3099 int dir_fd = DEFAULT_DIR_FD;
3100
Victor Stinner37e4ef72016-09-09 20:00:13 -07003101 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003102 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003103 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003104 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003105 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3106
3107exit:
3108 /* Cleanup for src */
3109 path_cleanup(&src);
3110 /* Cleanup for dst */
3111 path_cleanup(&dst);
3112
3113 return return_value;
3114}
3115
3116#endif /* defined(HAVE_SYMLINK) */
3117
3118#if defined(HAVE_TIMES)
3119
3120PyDoc_STRVAR(os_times__doc__,
3121"times($module, /)\n"
3122"--\n"
3123"\n"
3124"Return a collection containing process timing information.\n"
3125"\n"
3126"The object returned behaves like a named tuple with these fields:\n"
3127" (utime, stime, cutime, cstime, elapsed_time)\n"
3128"All fields are floating point numbers.");
3129
3130#define OS_TIMES_METHODDEF \
3131 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3132
3133static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003134os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003135
3136static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003137os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003138{
3139 return os_times_impl(module);
3140}
3141
3142#endif /* defined(HAVE_TIMES) */
3143
3144#if defined(HAVE_GETSID)
3145
3146PyDoc_STRVAR(os_getsid__doc__,
3147"getsid($module, pid, /)\n"
3148"--\n"
3149"\n"
3150"Call the system call getsid(pid) and return the result.");
3151
3152#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003153 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003154
3155static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003156os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003157
3158static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003159os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003160{
3161 PyObject *return_value = NULL;
3162 pid_t pid;
3163
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003164 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003165 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003166 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003167 return_value = os_getsid_impl(module, pid);
3168
3169exit:
3170 return return_value;
3171}
3172
3173#endif /* defined(HAVE_GETSID) */
3174
3175#if defined(HAVE_SETSID)
3176
3177PyDoc_STRVAR(os_setsid__doc__,
3178"setsid($module, /)\n"
3179"--\n"
3180"\n"
3181"Call the system call setsid().");
3182
3183#define OS_SETSID_METHODDEF \
3184 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3185
3186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003187os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003188
3189static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003190os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003191{
3192 return os_setsid_impl(module);
3193}
3194
3195#endif /* defined(HAVE_SETSID) */
3196
3197#if defined(HAVE_SETPGID)
3198
3199PyDoc_STRVAR(os_setpgid__doc__,
3200"setpgid($module, pid, pgrp, /)\n"
3201"--\n"
3202"\n"
3203"Call the system call setpgid(pid, pgrp).");
3204
3205#define OS_SETPGID_METHODDEF \
3206 {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
3207
3208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003209os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003210
3211static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003212os_setpgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003213{
3214 PyObject *return_value = NULL;
3215 pid_t pid;
3216 pid_t pgrp;
3217
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003218 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003219 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003220 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003221 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003222 return_value = os_setpgid_impl(module, pid, pgrp);
3223
3224exit:
3225 return return_value;
3226}
3227
3228#endif /* defined(HAVE_SETPGID) */
3229
3230#if defined(HAVE_TCGETPGRP)
3231
3232PyDoc_STRVAR(os_tcgetpgrp__doc__,
3233"tcgetpgrp($module, fd, /)\n"
3234"--\n"
3235"\n"
3236"Return the process group associated with the terminal specified by fd.");
3237
3238#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003239 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003240
3241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003242os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003243
3244static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003245os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003246{
3247 PyObject *return_value = NULL;
3248 int fd;
3249
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003250 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003251 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003252 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003253 return_value = os_tcgetpgrp_impl(module, fd);
3254
3255exit:
3256 return return_value;
3257}
3258
3259#endif /* defined(HAVE_TCGETPGRP) */
3260
3261#if defined(HAVE_TCSETPGRP)
3262
3263PyDoc_STRVAR(os_tcsetpgrp__doc__,
3264"tcsetpgrp($module, fd, pgid, /)\n"
3265"--\n"
3266"\n"
3267"Set the process group associated with the terminal specified by fd.");
3268
3269#define OS_TCSETPGRP_METHODDEF \
3270 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
3271
3272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003273os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003274
3275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003276os_tcsetpgrp(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003277{
3278 PyObject *return_value = NULL;
3279 int fd;
3280 pid_t pgid;
3281
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003282 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003283 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003284 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003285 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003286 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3287
3288exit:
3289 return return_value;
3290}
3291
3292#endif /* defined(HAVE_TCSETPGRP) */
3293
3294PyDoc_STRVAR(os_open__doc__,
3295"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3296"--\n"
3297"\n"
3298"Open a file for low level IO. Returns a file descriptor (integer).\n"
3299"\n"
3300"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3301" and path should be relative; path will then be relative to that directory.\n"
3302"dir_fd may not be implemented on your platform.\n"
3303" If it is unavailable, using it will raise a NotImplementedError.");
3304
3305#define OS_OPEN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003306 {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003307
3308static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003309os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003310
3311static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003312os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003313{
3314 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003315 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3316 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003317 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3318 int flags;
3319 int mode = 511;
3320 int dir_fd = DEFAULT_DIR_FD;
3321 int _return_value;
3322
Victor Stinner37e4ef72016-09-09 20:00:13 -07003323 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003324 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003325 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003326 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003327 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003328 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003329 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003330 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003331 return_value = PyLong_FromLong((long)_return_value);
3332
3333exit:
3334 /* Cleanup for path */
3335 path_cleanup(&path);
3336
3337 return return_value;
3338}
3339
3340PyDoc_STRVAR(os_close__doc__,
3341"close($module, /, fd)\n"
3342"--\n"
3343"\n"
3344"Close a file descriptor.");
3345
3346#define OS_CLOSE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003347 {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003348
3349static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003350os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003351
3352static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003353os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003354{
3355 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003356 static const char * const _keywords[] = {"fd", NULL};
3357 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003358 int fd;
3359
Victor Stinner37e4ef72016-09-09 20:00:13 -07003360 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003361 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003364 return_value = os_close_impl(module, fd);
3365
3366exit:
3367 return return_value;
3368}
3369
3370PyDoc_STRVAR(os_closerange__doc__,
3371"closerange($module, fd_low, fd_high, /)\n"
3372"--\n"
3373"\n"
3374"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3375
3376#define OS_CLOSERANGE_METHODDEF \
3377 {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
3378
3379static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003380os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003381
3382static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003383os_closerange(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003384{
3385 PyObject *return_value = NULL;
3386 int fd_low;
3387 int fd_high;
3388
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003389 if (!PyArg_ParseTuple(args, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003390 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003391 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003392 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003393 return_value = os_closerange_impl(module, fd_low, fd_high);
3394
3395exit:
3396 return return_value;
3397}
3398
3399PyDoc_STRVAR(os_dup__doc__,
3400"dup($module, fd, /)\n"
3401"--\n"
3402"\n"
3403"Return a duplicate of a file descriptor.");
3404
3405#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003406 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003407
3408static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003409os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003410
3411static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003412os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003413{
3414 PyObject *return_value = NULL;
3415 int fd;
3416 int _return_value;
3417
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003418 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003419 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003420 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003421 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003422 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003423 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003424 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003425 return_value = PyLong_FromLong((long)_return_value);
3426
3427exit:
3428 return return_value;
3429}
3430
3431PyDoc_STRVAR(os_dup2__doc__,
3432"dup2($module, /, fd, fd2, inheritable=True)\n"
3433"--\n"
3434"\n"
3435"Duplicate file descriptor.");
3436
3437#define OS_DUP2_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003438 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003439
3440static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003441os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003442
3443static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003444os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003445{
3446 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003447 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3448 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003449 int fd;
3450 int fd2;
3451 int inheritable = 1;
3452
Victor Stinner37e4ef72016-09-09 20:00:13 -07003453 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003454 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003455 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003456 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003457 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3458
3459exit:
3460 return return_value;
3461}
3462
3463#if defined(HAVE_LOCKF)
3464
3465PyDoc_STRVAR(os_lockf__doc__,
3466"lockf($module, fd, command, length, /)\n"
3467"--\n"
3468"\n"
3469"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3470"\n"
3471" fd\n"
3472" An open file descriptor.\n"
3473" command\n"
3474" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3475" length\n"
3476" The number of bytes to lock, starting at the current position.");
3477
3478#define OS_LOCKF_METHODDEF \
3479 {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
3480
3481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003482os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003483
3484static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003485os_lockf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003486{
3487 PyObject *return_value = NULL;
3488 int fd;
3489 int command;
3490 Py_off_t length;
3491
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003492 if (!PyArg_ParseTuple(args, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003493 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003494 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003496 return_value = os_lockf_impl(module, fd, command, length);
3497
3498exit:
3499 return return_value;
3500}
3501
3502#endif /* defined(HAVE_LOCKF) */
3503
3504PyDoc_STRVAR(os_lseek__doc__,
3505"lseek($module, fd, position, how, /)\n"
3506"--\n"
3507"\n"
3508"Set the position of a file descriptor. Return the new position.\n"
3509"\n"
3510"Return the new cursor position in number of bytes\n"
3511"relative to the beginning of the file.");
3512
3513#define OS_LSEEK_METHODDEF \
3514 {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
3515
3516static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003517os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003518
3519static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003520os_lseek(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003521{
3522 PyObject *return_value = NULL;
3523 int fd;
3524 Py_off_t position;
3525 int how;
3526 Py_off_t _return_value;
3527
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003528 if (!PyArg_ParseTuple(args, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003529 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003530 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003531 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003532 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003533 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003534 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003535 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003536 return_value = PyLong_FromPy_off_t(_return_value);
3537
3538exit:
3539 return return_value;
3540}
3541
3542PyDoc_STRVAR(os_read__doc__,
3543"read($module, fd, length, /)\n"
3544"--\n"
3545"\n"
3546"Read from a file descriptor. Returns a bytes object.");
3547
3548#define OS_READ_METHODDEF \
3549 {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
3550
3551static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003552os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003553
3554static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003555os_read(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003556{
3557 PyObject *return_value = NULL;
3558 int fd;
3559 Py_ssize_t length;
3560
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003561 if (!PyArg_ParseTuple(args, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003562 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003563 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003564 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003565 return_value = os_read_impl(module, fd, length);
3566
3567exit:
3568 return return_value;
3569}
3570
3571#if defined(HAVE_READV)
3572
3573PyDoc_STRVAR(os_readv__doc__,
3574"readv($module, fd, buffers, /)\n"
3575"--\n"
3576"\n"
3577"Read from a file descriptor fd into an iterable of buffers.\n"
3578"\n"
3579"The buffers should be mutable buffers accepting bytes.\n"
3580"readv will transfer data into each buffer until it is full\n"
3581"and then move on to the next buffer in the sequence to hold\n"
3582"the rest of the data.\n"
3583"\n"
3584"readv returns the total number of bytes read,\n"
3585"which may be less than the total capacity of all the buffers.");
3586
3587#define OS_READV_METHODDEF \
3588 {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
3589
3590static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003591os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003592
3593static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003594os_readv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003595{
3596 PyObject *return_value = NULL;
3597 int fd;
3598 PyObject *buffers;
3599 Py_ssize_t _return_value;
3600
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003601 if (!PyArg_ParseTuple(args, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003602 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003603 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003604 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003605 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003606 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003607 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003608 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003609 return_value = PyLong_FromSsize_t(_return_value);
3610
3611exit:
3612 return return_value;
3613}
3614
3615#endif /* defined(HAVE_READV) */
3616
3617#if defined(HAVE_PREAD)
3618
3619PyDoc_STRVAR(os_pread__doc__,
3620"pread($module, fd, length, offset, /)\n"
3621"--\n"
3622"\n"
3623"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3624"\n"
3625"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3626"the beginning of the file. The file offset remains unchanged.");
3627
3628#define OS_PREAD_METHODDEF \
3629 {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
3630
3631static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003632os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003633
3634static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003635os_pread(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003636{
3637 PyObject *return_value = NULL;
3638 int fd;
3639 int length;
3640 Py_off_t offset;
3641
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003642 if (!PyArg_ParseTuple(args, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003643 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003644 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003645 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003646 return_value = os_pread_impl(module, fd, length, offset);
3647
3648exit:
3649 return return_value;
3650}
3651
3652#endif /* defined(HAVE_PREAD) */
3653
3654PyDoc_STRVAR(os_write__doc__,
3655"write($module, fd, data, /)\n"
3656"--\n"
3657"\n"
3658"Write a bytes object to a file descriptor.");
3659
3660#define OS_WRITE_METHODDEF \
3661 {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
3662
3663static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003664os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003665
3666static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003667os_write(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003668{
3669 PyObject *return_value = NULL;
3670 int fd;
3671 Py_buffer data = {NULL, NULL};
3672 Py_ssize_t _return_value;
3673
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003674 if (!PyArg_ParseTuple(args, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003675 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003676 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003677 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003678 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003679 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003680 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003681 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003682 return_value = PyLong_FromSsize_t(_return_value);
3683
3684exit:
3685 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003686 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003687 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003688 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003689
3690 return return_value;
3691}
3692
3693PyDoc_STRVAR(os_fstat__doc__,
3694"fstat($module, /, fd)\n"
3695"--\n"
3696"\n"
3697"Perform a stat system call on the given file descriptor.\n"
3698"\n"
3699"Like stat(), but for an open file descriptor.\n"
3700"Equivalent to os.stat(fd).");
3701
3702#define OS_FSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003703 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003704
3705static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003706os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003707
3708static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003709os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003710{
3711 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003712 static const char * const _keywords[] = {"fd", NULL};
3713 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003714 int fd;
3715
Victor Stinner37e4ef72016-09-09 20:00:13 -07003716 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003717 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003718 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003719 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003720 return_value = os_fstat_impl(module, fd);
3721
3722exit:
3723 return return_value;
3724}
3725
3726PyDoc_STRVAR(os_isatty__doc__,
3727"isatty($module, fd, /)\n"
3728"--\n"
3729"\n"
3730"Return True if the fd is connected to a terminal.\n"
3731"\n"
3732"Return True if the file descriptor is an open file descriptor\n"
3733"connected to the slave end of a terminal.");
3734
3735#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003736 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003737
3738static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003739os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003740
3741static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003742os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003743{
3744 PyObject *return_value = NULL;
3745 int fd;
3746 int _return_value;
3747
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003748 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003749 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003750 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003751 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003752 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003753 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003754 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003755 return_value = PyBool_FromLong((long)_return_value);
3756
3757exit:
3758 return return_value;
3759}
3760
3761#if defined(HAVE_PIPE)
3762
3763PyDoc_STRVAR(os_pipe__doc__,
3764"pipe($module, /)\n"
3765"--\n"
3766"\n"
3767"Create a pipe.\n"
3768"\n"
3769"Returns a tuple of two file descriptors:\n"
3770" (read_fd, write_fd)");
3771
3772#define OS_PIPE_METHODDEF \
3773 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3774
3775static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003776os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003777
3778static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003779os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003780{
3781 return os_pipe_impl(module);
3782}
3783
3784#endif /* defined(HAVE_PIPE) */
3785
3786#if defined(HAVE_PIPE2)
3787
3788PyDoc_STRVAR(os_pipe2__doc__,
3789"pipe2($module, flags, /)\n"
3790"--\n"
3791"\n"
3792"Create a pipe with flags set atomically.\n"
3793"\n"
3794"Returns a tuple of two file descriptors:\n"
3795" (read_fd, write_fd)\n"
3796"\n"
3797"flags can be constructed by ORing together one or more of these values:\n"
3798"O_NONBLOCK, O_CLOEXEC.");
3799
3800#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003801 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003802
3803static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003804os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003805
3806static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003807os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003808{
3809 PyObject *return_value = NULL;
3810 int flags;
3811
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003812 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003813 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003814 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003815 return_value = os_pipe2_impl(module, flags);
3816
3817exit:
3818 return return_value;
3819}
3820
3821#endif /* defined(HAVE_PIPE2) */
3822
3823#if defined(HAVE_WRITEV)
3824
3825PyDoc_STRVAR(os_writev__doc__,
3826"writev($module, fd, buffers, /)\n"
3827"--\n"
3828"\n"
3829"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3830"\n"
3831"Returns the total number of bytes written.\n"
3832"buffers must be a sequence of bytes-like objects.");
3833
3834#define OS_WRITEV_METHODDEF \
3835 {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
3836
3837static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003838os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003839
3840static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003841os_writev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003842{
3843 PyObject *return_value = NULL;
3844 int fd;
3845 PyObject *buffers;
3846 Py_ssize_t _return_value;
3847
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003848 if (!PyArg_ParseTuple(args, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003849 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003850 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003851 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003852 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003853 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003854 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003855 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003856 return_value = PyLong_FromSsize_t(_return_value);
3857
3858exit:
3859 return return_value;
3860}
3861
3862#endif /* defined(HAVE_WRITEV) */
3863
3864#if defined(HAVE_PWRITE)
3865
3866PyDoc_STRVAR(os_pwrite__doc__,
3867"pwrite($module, fd, buffer, offset, /)\n"
3868"--\n"
3869"\n"
3870"Write bytes to a file descriptor starting at a particular offset.\n"
3871"\n"
3872"Write buffer to fd, starting at offset bytes from the beginning of\n"
3873"the file. Returns the number of bytes writte. Does not change the\n"
3874"current file offset.");
3875
3876#define OS_PWRITE_METHODDEF \
3877 {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
3878
3879static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003880os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003881
3882static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003883os_pwrite(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003884{
3885 PyObject *return_value = NULL;
3886 int fd;
3887 Py_buffer buffer = {NULL, NULL};
3888 Py_off_t offset;
3889 Py_ssize_t _return_value;
3890
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003891 if (!PyArg_ParseTuple(args, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003892 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003893 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003894 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003895 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003896 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003897 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003898 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003899 return_value = PyLong_FromSsize_t(_return_value);
3900
3901exit:
3902 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003903 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003904 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003905 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003906
3907 return return_value;
3908}
3909
3910#endif /* defined(HAVE_PWRITE) */
3911
3912#if defined(HAVE_MKFIFO)
3913
3914PyDoc_STRVAR(os_mkfifo__doc__,
3915"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3916"--\n"
3917"\n"
3918"Create a \"fifo\" (a POSIX named pipe).\n"
3919"\n"
3920"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3921" and path should be relative; path will then be relative to that directory.\n"
3922"dir_fd may not be implemented on your platform.\n"
3923" If it is unavailable, using it will raise a NotImplementedError.");
3924
3925#define OS_MKFIFO_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003926 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003927
3928static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003929os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003930
3931static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003932os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003933{
3934 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003935 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
3936 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003937 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3938 int mode = 438;
3939 int dir_fd = DEFAULT_DIR_FD;
3940
Victor Stinner37e4ef72016-09-09 20:00:13 -07003941 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003942 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003943 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003945 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3946
3947exit:
3948 /* Cleanup for path */
3949 path_cleanup(&path);
3950
3951 return return_value;
3952}
3953
3954#endif /* defined(HAVE_MKFIFO) */
3955
3956#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
3957
3958PyDoc_STRVAR(os_mknod__doc__,
3959"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
3960"--\n"
3961"\n"
3962"Create a node in the file system.\n"
3963"\n"
3964"Create a node in the file system (file, device special file or named pipe)\n"
3965"at path. mode specifies both the permissions to use and the\n"
3966"type of node to be created, being combined (bitwise OR) with one of\n"
3967"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
3968"device defines the newly created device special file (probably using\n"
3969"os.makedev()). Otherwise device is ignored.\n"
3970"\n"
3971"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3972" and path should be relative; path will then be relative to that directory.\n"
3973"dir_fd may not be implemented on your platform.\n"
3974" If it is unavailable, using it will raise a NotImplementedError.");
3975
3976#define OS_MKNOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003977 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003978
3979static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003980os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04003981 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003982
3983static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003984os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003985{
3986 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003987 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
3988 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003989 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
3990 int mode = 384;
3991 dev_t device = 0;
3992 int dir_fd = DEFAULT_DIR_FD;
3993
Victor Stinner37e4ef72016-09-09 20:00:13 -07003994 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003995 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003996 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003997 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003998 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
3999
4000exit:
4001 /* Cleanup for path */
4002 path_cleanup(&path);
4003
4004 return return_value;
4005}
4006
4007#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4008
4009#if defined(HAVE_DEVICE_MACROS)
4010
4011PyDoc_STRVAR(os_major__doc__,
4012"major($module, device, /)\n"
4013"--\n"
4014"\n"
4015"Extracts a device major number from a raw device number.");
4016
4017#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004018 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004019
4020static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004021os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004022
4023static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004024os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004025{
4026 PyObject *return_value = NULL;
4027 dev_t device;
4028 unsigned int _return_value;
4029
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004030 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004031 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004032 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004033 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004034 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004035 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004036 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004037 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4038
4039exit:
4040 return return_value;
4041}
4042
4043#endif /* defined(HAVE_DEVICE_MACROS) */
4044
4045#if defined(HAVE_DEVICE_MACROS)
4046
4047PyDoc_STRVAR(os_minor__doc__,
4048"minor($module, device, /)\n"
4049"--\n"
4050"\n"
4051"Extracts a device minor number from a raw device number.");
4052
4053#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004054 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004055
4056static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004057os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004058
4059static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004060os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004061{
4062 PyObject *return_value = NULL;
4063 dev_t device;
4064 unsigned int _return_value;
4065
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004066 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004067 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004068 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004069 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004070 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004071 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004072 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004073 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4074
4075exit:
4076 return return_value;
4077}
4078
4079#endif /* defined(HAVE_DEVICE_MACROS) */
4080
4081#if defined(HAVE_DEVICE_MACROS)
4082
4083PyDoc_STRVAR(os_makedev__doc__,
4084"makedev($module, major, minor, /)\n"
4085"--\n"
4086"\n"
4087"Composes a raw device number from the major and minor device numbers.");
4088
4089#define OS_MAKEDEV_METHODDEF \
4090 {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
4091
4092static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004093os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004094
4095static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004096os_makedev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004097{
4098 PyObject *return_value = NULL;
4099 int major;
4100 int minor;
4101 dev_t _return_value;
4102
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004103 if (!PyArg_ParseTuple(args, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004104 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004105 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004106 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004107 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004108 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004109 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004111 return_value = _PyLong_FromDev(_return_value);
4112
4113exit:
4114 return return_value;
4115}
4116
4117#endif /* defined(HAVE_DEVICE_MACROS) */
4118
Steve Dowerf7377032015-04-12 15:44:54 -04004119#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004120
4121PyDoc_STRVAR(os_ftruncate__doc__,
4122"ftruncate($module, fd, length, /)\n"
4123"--\n"
4124"\n"
4125"Truncate a file, specified by file descriptor, to a specific length.");
4126
4127#define OS_FTRUNCATE_METHODDEF \
4128 {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
4129
4130static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004131os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004132
4133static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004134os_ftruncate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004135{
4136 PyObject *return_value = NULL;
4137 int fd;
4138 Py_off_t length;
4139
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004140 if (!PyArg_ParseTuple(args, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004141 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004142 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004143 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004144 return_value = os_ftruncate_impl(module, fd, length);
4145
4146exit:
4147 return return_value;
4148}
4149
Steve Dowerf7377032015-04-12 15:44:54 -04004150#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004151
Steve Dowerf7377032015-04-12 15:44:54 -04004152#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004153
4154PyDoc_STRVAR(os_truncate__doc__,
4155"truncate($module, /, path, length)\n"
4156"--\n"
4157"\n"
4158"Truncate a file, specified by path, to a specific length.\n"
4159"\n"
4160"On some platforms, path may also be specified as an open file descriptor.\n"
4161" If this functionality is unavailable, using it raises an exception.");
4162
4163#define OS_TRUNCATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004164 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004165
4166static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004167os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004168
4169static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004170os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004171{
4172 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004173 static const char * const _keywords[] = {"path", "length", NULL};
4174 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004175 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4176 Py_off_t length;
4177
Victor Stinner37e4ef72016-09-09 20:00:13 -07004178 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004179 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004180 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004181 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004182 return_value = os_truncate_impl(module, &path, length);
4183
4184exit:
4185 /* Cleanup for path */
4186 path_cleanup(&path);
4187
4188 return return_value;
4189}
4190
Steve Dowerf7377032015-04-12 15:44:54 -04004191#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004192
4193#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4194
4195PyDoc_STRVAR(os_posix_fallocate__doc__,
4196"posix_fallocate($module, fd, offset, length, /)\n"
4197"--\n"
4198"\n"
4199"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4200"\n"
4201"Ensure that the file specified by fd encompasses a range of bytes\n"
4202"starting at offset bytes from the beginning and continuing for length bytes.");
4203
4204#define OS_POSIX_FALLOCATE_METHODDEF \
4205 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
4206
4207static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004208os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004209 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004210
4211static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004212os_posix_fallocate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004213{
4214 PyObject *return_value = NULL;
4215 int fd;
4216 Py_off_t offset;
4217 Py_off_t length;
4218
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004219 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004220 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004221 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004222 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004223 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4224
4225exit:
4226 return return_value;
4227}
4228
4229#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4230
4231#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4232
4233PyDoc_STRVAR(os_posix_fadvise__doc__,
4234"posix_fadvise($module, fd, offset, length, advice, /)\n"
4235"--\n"
4236"\n"
4237"Announce an intention to access data in a specific pattern.\n"
4238"\n"
4239"Announce an intention to access data in a specific pattern, thus allowing\n"
4240"the kernel to make optimizations.\n"
4241"The advice applies to the region of the file specified by fd starting at\n"
4242"offset and continuing for length bytes.\n"
4243"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4244"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4245"POSIX_FADV_DONTNEED.");
4246
4247#define OS_POSIX_FADVISE_METHODDEF \
4248 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
4249
4250static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004251os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004252 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004253
4254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004255os_posix_fadvise(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004256{
4257 PyObject *return_value = NULL;
4258 int fd;
4259 Py_off_t offset;
4260 Py_off_t length;
4261 int advice;
4262
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004263 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004264 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004265 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004266 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004267 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4268
4269exit:
4270 return return_value;
4271}
4272
4273#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4274
4275#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4276
4277PyDoc_STRVAR(os_putenv__doc__,
4278"putenv($module, name, value, /)\n"
4279"--\n"
4280"\n"
4281"Change or add an environment variable.");
4282
4283#define OS_PUTENV_METHODDEF \
4284 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4285
4286static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004287os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004288
4289static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004290os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004291{
4292 PyObject *return_value = NULL;
4293 PyObject *name;
4294 PyObject *value;
4295
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004296 if (!PyArg_ParseTuple(args, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004297 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004298 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004299 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004300 return_value = os_putenv_impl(module, name, value);
4301
4302exit:
4303 return return_value;
4304}
4305
4306#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4307
4308#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4309
4310PyDoc_STRVAR(os_putenv__doc__,
4311"putenv($module, name, value, /)\n"
4312"--\n"
4313"\n"
4314"Change or add an environment variable.");
4315
4316#define OS_PUTENV_METHODDEF \
4317 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4318
4319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004320os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321
4322static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004323os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004324{
4325 PyObject *return_value = NULL;
4326 PyObject *name = NULL;
4327 PyObject *value = NULL;
4328
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004329 if (!PyArg_ParseTuple(args, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004330 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004331 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004332 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004333 return_value = os_putenv_impl(module, name, value);
4334
4335exit:
4336 /* Cleanup for name */
4337 Py_XDECREF(name);
4338 /* Cleanup for value */
4339 Py_XDECREF(value);
4340
4341 return return_value;
4342}
4343
4344#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4345
4346#if defined(HAVE_UNSETENV)
4347
4348PyDoc_STRVAR(os_unsetenv__doc__,
4349"unsetenv($module, name, /)\n"
4350"--\n"
4351"\n"
4352"Delete an environment variable.");
4353
4354#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004355 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004356
4357static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004358os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004359
4360static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004361os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362{
4363 PyObject *return_value = NULL;
4364 PyObject *name = NULL;
4365
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004366 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004367 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004368 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004369 return_value = os_unsetenv_impl(module, name);
4370
4371exit:
4372 /* Cleanup for name */
4373 Py_XDECREF(name);
4374
4375 return return_value;
4376}
4377
4378#endif /* defined(HAVE_UNSETENV) */
4379
4380PyDoc_STRVAR(os_strerror__doc__,
4381"strerror($module, code, /)\n"
4382"--\n"
4383"\n"
4384"Translate an error code to a message string.");
4385
4386#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004387 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004388
4389static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004390os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004391
4392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004393os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004394{
4395 PyObject *return_value = NULL;
4396 int code;
4397
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004398 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004399 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004400 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004401 return_value = os_strerror_impl(module, code);
4402
4403exit:
4404 return return_value;
4405}
4406
4407#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4408
4409PyDoc_STRVAR(os_WCOREDUMP__doc__,
4410"WCOREDUMP($module, status, /)\n"
4411"--\n"
4412"\n"
4413"Return True if the process returning status was dumped to a core file.");
4414
4415#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004416 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004417
4418static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004419os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004420
4421static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004422os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004423{
4424 PyObject *return_value = NULL;
4425 int status;
4426 int _return_value;
4427
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004428 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004429 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004430 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004431 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004432 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004435 return_value = PyBool_FromLong((long)_return_value);
4436
4437exit:
4438 return return_value;
4439}
4440
4441#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4442
4443#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4444
4445PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4446"WIFCONTINUED($module, /, status)\n"
4447"--\n"
4448"\n"
4449"Return True if a particular process was continued from a job control stop.\n"
4450"\n"
4451"Return True if the process returning status was continued from a\n"
4452"job control stop.");
4453
4454#define OS_WIFCONTINUED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004455 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004456
4457static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004458os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004459
4460static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004461os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004462{
4463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004464 static const char * const _keywords[] = {"status", NULL};
4465 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004466 int status;
4467 int _return_value;
4468
Victor Stinner37e4ef72016-09-09 20:00:13 -07004469 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004470 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004473 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004474 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004475 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004476 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004477 return_value = PyBool_FromLong((long)_return_value);
4478
4479exit:
4480 return return_value;
4481}
4482
4483#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4484
4485#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4486
4487PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4488"WIFSTOPPED($module, /, status)\n"
4489"--\n"
4490"\n"
4491"Return True if the process returning status was stopped.");
4492
4493#define OS_WIFSTOPPED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004494 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004495
4496static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004497os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004498
4499static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004500os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004501{
4502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004503 static const char * const _keywords[] = {"status", NULL};
4504 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004505 int status;
4506 int _return_value;
4507
Victor Stinner37e4ef72016-09-09 20:00:13 -07004508 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004509 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004512 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004513 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004514 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004515 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004516 return_value = PyBool_FromLong((long)_return_value);
4517
4518exit:
4519 return return_value;
4520}
4521
4522#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4523
4524#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4525
4526PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4527"WIFSIGNALED($module, /, status)\n"
4528"--\n"
4529"\n"
4530"Return True if the process returning status was terminated by a signal.");
4531
4532#define OS_WIFSIGNALED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004533 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004534
4535static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004536os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004537
4538static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004539os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004540{
4541 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004542 static const char * const _keywords[] = {"status", NULL};
4543 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004544 int status;
4545 int _return_value;
4546
Victor Stinner37e4ef72016-09-09 20:00:13 -07004547 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004548 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004549 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004550 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004551 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004552 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004553 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004554 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004555 return_value = PyBool_FromLong((long)_return_value);
4556
4557exit:
4558 return return_value;
4559}
4560
4561#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4562
4563#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4564
4565PyDoc_STRVAR(os_WIFEXITED__doc__,
4566"WIFEXITED($module, /, status)\n"
4567"--\n"
4568"\n"
4569"Return True if the process returning status exited via the exit() system call.");
4570
4571#define OS_WIFEXITED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004572 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004573
4574static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004575os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004576
4577static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004578os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004579{
4580 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004581 static const char * const _keywords[] = {"status", NULL};
4582 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004583 int status;
4584 int _return_value;
4585
Victor Stinner37e4ef72016-09-09 20:00:13 -07004586 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004587 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004588 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004589 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004590 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004591 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004592 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004593 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004594 return_value = PyBool_FromLong((long)_return_value);
4595
4596exit:
4597 return return_value;
4598}
4599
4600#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4601
4602#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4603
4604PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4605"WEXITSTATUS($module, /, status)\n"
4606"--\n"
4607"\n"
4608"Return the process return code from status.");
4609
4610#define OS_WEXITSTATUS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004611 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004612
4613static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004614os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004615
4616static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004617os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004618{
4619 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004620 static const char * const _keywords[] = {"status", NULL};
4621 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004622 int status;
4623 int _return_value;
4624
Victor Stinner37e4ef72016-09-09 20:00:13 -07004625 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004626 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004627 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004628 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004629 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004630 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004631 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004632 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004633 return_value = PyLong_FromLong((long)_return_value);
4634
4635exit:
4636 return return_value;
4637}
4638
4639#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4640
4641#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4642
4643PyDoc_STRVAR(os_WTERMSIG__doc__,
4644"WTERMSIG($module, /, status)\n"
4645"--\n"
4646"\n"
4647"Return the signal that terminated the process that provided the status value.");
4648
4649#define OS_WTERMSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004650 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004651
4652static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004653os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004654
4655static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004656os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004657{
4658 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004659 static const char * const _keywords[] = {"status", NULL};
4660 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004661 int status;
4662 int _return_value;
4663
Victor Stinner37e4ef72016-09-09 20:00:13 -07004664 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004665 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004666 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004667 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004668 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004669 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004670 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004672 return_value = PyLong_FromLong((long)_return_value);
4673
4674exit:
4675 return return_value;
4676}
4677
4678#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4679
4680#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4681
4682PyDoc_STRVAR(os_WSTOPSIG__doc__,
4683"WSTOPSIG($module, /, status)\n"
4684"--\n"
4685"\n"
4686"Return the signal that stopped the process that provided the status value.");
4687
4688#define OS_WSTOPSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004689 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004690
4691static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004692os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004693
4694static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004695os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004696{
4697 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004698 static const char * const _keywords[] = {"status", NULL};
4699 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004700 int status;
4701 int _return_value;
4702
Victor Stinner37e4ef72016-09-09 20:00:13 -07004703 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004704 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004705 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004706 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004707 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004708 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004709 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004710 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004711 return_value = PyLong_FromLong((long)_return_value);
4712
4713exit:
4714 return return_value;
4715}
4716
4717#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4718
4719#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4720
4721PyDoc_STRVAR(os_fstatvfs__doc__,
4722"fstatvfs($module, fd, /)\n"
4723"--\n"
4724"\n"
4725"Perform an fstatvfs system call on the given fd.\n"
4726"\n"
4727"Equivalent to statvfs(fd).");
4728
4729#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004730 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004731
4732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004733os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004734
4735static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004736os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004737{
4738 PyObject *return_value = NULL;
4739 int fd;
4740
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004741 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004742 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004743 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004744 return_value = os_fstatvfs_impl(module, fd);
4745
4746exit:
4747 return return_value;
4748}
4749
4750#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4751
4752#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4753
4754PyDoc_STRVAR(os_statvfs__doc__,
4755"statvfs($module, /, path)\n"
4756"--\n"
4757"\n"
4758"Perform a statvfs system call on the given path.\n"
4759"\n"
4760"path may always be specified as a string.\n"
4761"On some platforms, path may also be specified as an open file descriptor.\n"
4762" If this functionality is unavailable, using it raises an exception.");
4763
4764#define OS_STATVFS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004765 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004766
4767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004768os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004769
4770static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004771os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004772{
4773 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004774 static const char * const _keywords[] = {"path", NULL};
4775 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004776 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4777
Victor Stinner37e4ef72016-09-09 20:00:13 -07004778 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004779 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004780 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004781 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004782 return_value = os_statvfs_impl(module, &path);
4783
4784exit:
4785 /* Cleanup for path */
4786 path_cleanup(&path);
4787
4788 return return_value;
4789}
4790
4791#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4792
4793#if defined(MS_WINDOWS)
4794
4795PyDoc_STRVAR(os__getdiskusage__doc__,
4796"_getdiskusage($module, /, path)\n"
4797"--\n"
4798"\n"
4799"Return disk usage statistics about the given path as a (total, free) tuple.");
4800
4801#define OS__GETDISKUSAGE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004802 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004803
4804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004805os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004806
4807static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004808os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004809{
4810 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004811 static const char * const _keywords[] = {"path", NULL};
4812 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004813 Py_UNICODE *path;
4814
Victor Stinner37e4ef72016-09-09 20:00:13 -07004815 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004816 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004817 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004818 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004819 return_value = os__getdiskusage_impl(module, path);
4820
4821exit:
4822 return return_value;
4823}
4824
4825#endif /* defined(MS_WINDOWS) */
4826
4827#if defined(HAVE_FPATHCONF)
4828
4829PyDoc_STRVAR(os_fpathconf__doc__,
4830"fpathconf($module, fd, name, /)\n"
4831"--\n"
4832"\n"
4833"Return the configuration limit name for the file descriptor fd.\n"
4834"\n"
4835"If there is no limit, return -1.");
4836
4837#define OS_FPATHCONF_METHODDEF \
4838 {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
4839
4840static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004841os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004842
4843static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004844os_fpathconf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004845{
4846 PyObject *return_value = NULL;
4847 int fd;
4848 int name;
4849 long _return_value;
4850
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004851 if (!PyArg_ParseTuple(args, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004852 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004853 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004854 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004855 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004856 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004857 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004858 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004859 return_value = PyLong_FromLong(_return_value);
4860
4861exit:
4862 return return_value;
4863}
4864
4865#endif /* defined(HAVE_FPATHCONF) */
4866
4867#if defined(HAVE_PATHCONF)
4868
4869PyDoc_STRVAR(os_pathconf__doc__,
4870"pathconf($module, /, path, name)\n"
4871"--\n"
4872"\n"
4873"Return the configuration limit name for the file or directory path.\n"
4874"\n"
4875"If there is no limit, return -1.\n"
4876"On some platforms, path may also be specified as an open file descriptor.\n"
4877" If this functionality is unavailable, using it raises an exception.");
4878
4879#define OS_PATHCONF_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004880 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004881
4882static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004883os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004884
4885static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004886os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004887{
4888 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004889 static const char * const _keywords[] = {"path", "name", NULL};
4890 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004891 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4892 int name;
4893 long _return_value;
4894
Victor Stinner37e4ef72016-09-09 20:00:13 -07004895 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004896 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004897 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004898 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004899 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004900 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004901 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004902 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004903 return_value = PyLong_FromLong(_return_value);
4904
4905exit:
4906 /* Cleanup for path */
4907 path_cleanup(&path);
4908
4909 return return_value;
4910}
4911
4912#endif /* defined(HAVE_PATHCONF) */
4913
4914#if defined(HAVE_CONFSTR)
4915
4916PyDoc_STRVAR(os_confstr__doc__,
4917"confstr($module, name, /)\n"
4918"--\n"
4919"\n"
4920"Return a string-valued system configuration variable.");
4921
4922#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004923 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004924
4925static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004926os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004927
4928static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004929os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004930{
4931 PyObject *return_value = NULL;
4932 int name;
4933
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004934 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004935 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004936 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004937 return_value = os_confstr_impl(module, name);
4938
4939exit:
4940 return return_value;
4941}
4942
4943#endif /* defined(HAVE_CONFSTR) */
4944
4945#if defined(HAVE_SYSCONF)
4946
4947PyDoc_STRVAR(os_sysconf__doc__,
4948"sysconf($module, name, /)\n"
4949"--\n"
4950"\n"
4951"Return an integer-valued system configuration variable.");
4952
4953#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004954 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004955
4956static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004957os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004958
4959static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004960os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004961{
4962 PyObject *return_value = NULL;
4963 int name;
4964 long _return_value;
4965
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004966 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004967 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004968 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004969 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004970 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004971 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004972 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004973 return_value = PyLong_FromLong(_return_value);
4974
4975exit:
4976 return return_value;
4977}
4978
4979#endif /* defined(HAVE_SYSCONF) */
4980
4981PyDoc_STRVAR(os_abort__doc__,
4982"abort($module, /)\n"
4983"--\n"
4984"\n"
4985"Abort the interpreter immediately.\n"
4986"\n"
4987"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
4988"on the hosting operating system. This function never returns.");
4989
4990#define OS_ABORT_METHODDEF \
4991 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
4992
4993static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004994os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004995
4996static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004997os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004998{
4999 return os_abort_impl(module);
5000}
5001
Steve Dowercc16be82016-09-08 10:35:16 -07005002#if defined(MS_WINDOWS)
5003
5004PyDoc_STRVAR(os_startfile__doc__,
5005"startfile($module, /, filepath, operation=None)\n"
5006"--\n"
5007"\n"
5008"startfile(filepath [, operation])\n"
5009"\n"
5010"Start a file with its associated application.\n"
5011"\n"
5012"When \"operation\" is not specified or \"open\", this acts like\n"
5013"double-clicking the file in Explorer, or giving the file name as an\n"
5014"argument to the DOS \"start\" command: the file is opened with whatever\n"
5015"application (if any) its extension is associated.\n"
5016"When another \"operation\" is given, it specifies what should be done with\n"
5017"the file. A typical operation is \"print\".\n"
5018"\n"
5019"startfile returns as soon as the associated application is launched.\n"
5020"There is no option to wait for the application to close, and no way\n"
5021"to retrieve the application\'s exit status.\n"
5022"\n"
5023"The filepath is relative to the current directory. If you want to use\n"
5024"an absolute path, make sure the first character is not a slash (\"/\");\n"
5025"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5026
5027#define OS_STARTFILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005028 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005029
5030static PyObject *
5031os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5032
5033static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005034os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005035{
5036 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005037 static const char * const _keywords[] = {"filepath", "operation", NULL};
5038 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005039 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5040 Py_UNICODE *operation = NULL;
5041
Victor Stinner37e4ef72016-09-09 20:00:13 -07005042 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005043 path_converter, &filepath, &operation)) {
5044 goto exit;
5045 }
5046 return_value = os_startfile_impl(module, &filepath, operation);
5047
5048exit:
5049 /* Cleanup for filepath */
5050 path_cleanup(&filepath);
5051
5052 return return_value;
5053}
5054
5055#endif /* defined(MS_WINDOWS) */
5056
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005057#if defined(HAVE_GETLOADAVG)
5058
5059PyDoc_STRVAR(os_getloadavg__doc__,
5060"getloadavg($module, /)\n"
5061"--\n"
5062"\n"
5063"Return average recent system load information.\n"
5064"\n"
5065"Return the number of processes in the system run queue averaged over\n"
5066"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5067"Raises OSError if the load average was unobtainable.");
5068
5069#define OS_GETLOADAVG_METHODDEF \
5070 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5071
5072static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005073os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005074
5075static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005076os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005077{
5078 return os_getloadavg_impl(module);
5079}
5080
5081#endif /* defined(HAVE_GETLOADAVG) */
5082
5083PyDoc_STRVAR(os_device_encoding__doc__,
5084"device_encoding($module, /, fd)\n"
5085"--\n"
5086"\n"
5087"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5088"\n"
5089"The file descriptor must be attached to a terminal.\n"
5090"If the device is not a terminal, return None.");
5091
5092#define OS_DEVICE_ENCODING_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005093 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005094
5095static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005096os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005097
5098static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005099os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005100{
5101 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005102 static const char * const _keywords[] = {"fd", NULL};
5103 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005104 int fd;
5105
Victor Stinner37e4ef72016-09-09 20:00:13 -07005106 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005107 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005110 return_value = os_device_encoding_impl(module, fd);
5111
5112exit:
5113 return return_value;
5114}
5115
5116#if defined(HAVE_SETRESUID)
5117
5118PyDoc_STRVAR(os_setresuid__doc__,
5119"setresuid($module, ruid, euid, suid, /)\n"
5120"--\n"
5121"\n"
5122"Set the current process\'s real, effective, and saved user ids.");
5123
5124#define OS_SETRESUID_METHODDEF \
5125 {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
5126
5127static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005128os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005129
5130static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005131os_setresuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005132{
5133 PyObject *return_value = NULL;
5134 uid_t ruid;
5135 uid_t euid;
5136 uid_t suid;
5137
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005138 if (!PyArg_ParseTuple(args, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005139 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005140 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005141 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005142 return_value = os_setresuid_impl(module, ruid, euid, suid);
5143
5144exit:
5145 return return_value;
5146}
5147
5148#endif /* defined(HAVE_SETRESUID) */
5149
5150#if defined(HAVE_SETRESGID)
5151
5152PyDoc_STRVAR(os_setresgid__doc__,
5153"setresgid($module, rgid, egid, sgid, /)\n"
5154"--\n"
5155"\n"
5156"Set the current process\'s real, effective, and saved group ids.");
5157
5158#define OS_SETRESGID_METHODDEF \
5159 {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
5160
5161static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005162os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005163
5164static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005165os_setresgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005166{
5167 PyObject *return_value = NULL;
5168 gid_t rgid;
5169 gid_t egid;
5170 gid_t sgid;
5171
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005172 if (!PyArg_ParseTuple(args, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005173 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005174 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005175 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005176 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5177
5178exit:
5179 return return_value;
5180}
5181
5182#endif /* defined(HAVE_SETRESGID) */
5183
5184#if defined(HAVE_GETRESUID)
5185
5186PyDoc_STRVAR(os_getresuid__doc__,
5187"getresuid($module, /)\n"
5188"--\n"
5189"\n"
5190"Return a tuple of the current process\'s real, effective, and saved user ids.");
5191
5192#define OS_GETRESUID_METHODDEF \
5193 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5194
5195static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005196os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005197
5198static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005199os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005200{
5201 return os_getresuid_impl(module);
5202}
5203
5204#endif /* defined(HAVE_GETRESUID) */
5205
5206#if defined(HAVE_GETRESGID)
5207
5208PyDoc_STRVAR(os_getresgid__doc__,
5209"getresgid($module, /)\n"
5210"--\n"
5211"\n"
5212"Return a tuple of the current process\'s real, effective, and saved group ids.");
5213
5214#define OS_GETRESGID_METHODDEF \
5215 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5216
5217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005218os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005219
5220static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005221os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005222{
5223 return os_getresgid_impl(module);
5224}
5225
5226#endif /* defined(HAVE_GETRESGID) */
5227
5228#if defined(USE_XATTRS)
5229
5230PyDoc_STRVAR(os_getxattr__doc__,
5231"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5232"--\n"
5233"\n"
5234"Return the value of extended attribute attribute on path.\n"
5235"\n"
5236"path may be either a string or an open file descriptor.\n"
5237"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5238" link, getxattr will examine the symbolic link itself instead of the file\n"
5239" the link points to.");
5240
5241#define OS_GETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005242 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005243
5244static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005245os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005246 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247
5248static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005249os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005250{
5251 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005252 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5253 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005254 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5255 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5256 int follow_symlinks = 1;
5257
Victor Stinner37e4ef72016-09-09 20:00:13 -07005258 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005259 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005260 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005261 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005262 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5263
5264exit:
5265 /* Cleanup for path */
5266 path_cleanup(&path);
5267 /* Cleanup for attribute */
5268 path_cleanup(&attribute);
5269
5270 return return_value;
5271}
5272
5273#endif /* defined(USE_XATTRS) */
5274
5275#if defined(USE_XATTRS)
5276
5277PyDoc_STRVAR(os_setxattr__doc__,
5278"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5279" follow_symlinks=True)\n"
5280"--\n"
5281"\n"
5282"Set extended attribute attribute on path to value.\n"
5283"\n"
5284"path may be either a string or an open file descriptor.\n"
5285"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5286" link, setxattr will modify the symbolic link itself instead of the file\n"
5287" the link points to.");
5288
5289#define OS_SETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005290 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005291
5292static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005293os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005294 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005295
5296static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005297os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005298{
5299 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005300 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5301 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005302 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5303 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5304 Py_buffer value = {NULL, NULL};
5305 int flags = 0;
5306 int follow_symlinks = 1;
5307
Victor Stinner37e4ef72016-09-09 20:00:13 -07005308 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005309 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005310 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005311 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005312 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5313
5314exit:
5315 /* Cleanup for path */
5316 path_cleanup(&path);
5317 /* Cleanup for attribute */
5318 path_cleanup(&attribute);
5319 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005320 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005321 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005322 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005323
5324 return return_value;
5325}
5326
5327#endif /* defined(USE_XATTRS) */
5328
5329#if defined(USE_XATTRS)
5330
5331PyDoc_STRVAR(os_removexattr__doc__,
5332"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5333"--\n"
5334"\n"
5335"Remove extended attribute attribute on path.\n"
5336"\n"
5337"path may be either a string or an open file descriptor.\n"
5338"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5339" link, removexattr will modify the symbolic link itself instead of the file\n"
5340" the link points to.");
5341
5342#define OS_REMOVEXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005343 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005344
5345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005346os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005347 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005348
5349static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005350os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005351{
5352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005353 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5354 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005355 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5356 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5357 int follow_symlinks = 1;
5358
Victor Stinner37e4ef72016-09-09 20:00:13 -07005359 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005360 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005361 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005362 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005363 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5364
5365exit:
5366 /* Cleanup for path */
5367 path_cleanup(&path);
5368 /* Cleanup for attribute */
5369 path_cleanup(&attribute);
5370
5371 return return_value;
5372}
5373
5374#endif /* defined(USE_XATTRS) */
5375
5376#if defined(USE_XATTRS)
5377
5378PyDoc_STRVAR(os_listxattr__doc__,
5379"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5380"--\n"
5381"\n"
5382"Return a list of extended attributes on path.\n"
5383"\n"
5384"path may be either None, a string, or an open file descriptor.\n"
5385"if path is None, listxattr will examine the current directory.\n"
5386"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5387" link, listxattr will examine the symbolic link itself instead of the file\n"
5388" the link points to.");
5389
5390#define OS_LISTXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005391 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005392
5393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005394os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005395
5396static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005397os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005398{
5399 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005400 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5401 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005402 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5403 int follow_symlinks = 1;
5404
Victor Stinner37e4ef72016-09-09 20:00:13 -07005405 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005406 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005407 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005408 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005409 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5410
5411exit:
5412 /* Cleanup for path */
5413 path_cleanup(&path);
5414
5415 return return_value;
5416}
5417
5418#endif /* defined(USE_XATTRS) */
5419
5420PyDoc_STRVAR(os_urandom__doc__,
5421"urandom($module, size, /)\n"
5422"--\n"
5423"\n"
5424"Return a bytes object containing random bytes suitable for cryptographic use.");
5425
5426#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005427 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005428
5429static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005430os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431
5432static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005433os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005434{
5435 PyObject *return_value = NULL;
5436 Py_ssize_t size;
5437
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005438 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005439 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005440 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005441 return_value = os_urandom_impl(module, size);
5442
5443exit:
5444 return return_value;
5445}
5446
5447PyDoc_STRVAR(os_cpu_count__doc__,
5448"cpu_count($module, /)\n"
5449"--\n"
5450"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005451"Return the number of CPUs in the system; return None if indeterminable.\n"
5452"\n"
5453"This number is not equivalent to the number of CPUs the current process can\n"
5454"use. The number of usable CPUs can be obtained with\n"
5455"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005456
5457#define OS_CPU_COUNT_METHODDEF \
5458 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5459
5460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005461os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005462
5463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005464os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005465{
5466 return os_cpu_count_impl(module);
5467}
5468
5469PyDoc_STRVAR(os_get_inheritable__doc__,
5470"get_inheritable($module, fd, /)\n"
5471"--\n"
5472"\n"
5473"Get the close-on-exe flag of the specified file descriptor.");
5474
5475#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005476 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005477
5478static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005479os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005480
5481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005482os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483{
5484 PyObject *return_value = NULL;
5485 int fd;
5486 int _return_value;
5487
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005488 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005489 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005490 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005491 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005492 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005493 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005494 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005495 return_value = PyBool_FromLong((long)_return_value);
5496
5497exit:
5498 return return_value;
5499}
5500
5501PyDoc_STRVAR(os_set_inheritable__doc__,
5502"set_inheritable($module, fd, inheritable, /)\n"
5503"--\n"
5504"\n"
5505"Set the inheritable flag of the specified file descriptor.");
5506
5507#define OS_SET_INHERITABLE_METHODDEF \
5508 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
5509
5510static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005511os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005512
5513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005514os_set_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005515{
5516 PyObject *return_value = NULL;
5517 int fd;
5518 int inheritable;
5519
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005520 if (!PyArg_ParseTuple(args, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005521 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005522 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005523 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005524 return_value = os_set_inheritable_impl(module, fd, inheritable);
5525
5526exit:
5527 return return_value;
5528}
5529
5530#if defined(MS_WINDOWS)
5531
5532PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5533"get_handle_inheritable($module, handle, /)\n"
5534"--\n"
5535"\n"
5536"Get the close-on-exe flag of the specified file descriptor.");
5537
5538#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005539 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005540
5541static int
Victor Stinner581139c2016-09-06 15:54:20 -07005542os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005543
5544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005545os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005546{
5547 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005548 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005549 int _return_value;
5550
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005551 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005552 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005553 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005554 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005555 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005556 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005557 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005558 return_value = PyBool_FromLong((long)_return_value);
5559
5560exit:
5561 return return_value;
5562}
5563
5564#endif /* defined(MS_WINDOWS) */
5565
5566#if defined(MS_WINDOWS)
5567
5568PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5569"set_handle_inheritable($module, handle, inheritable, /)\n"
5570"--\n"
5571"\n"
5572"Set the inheritable flag of the specified handle.");
5573
5574#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
5575 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
5576
5577static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005578os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005579 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005580
5581static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005582os_set_handle_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005583{
5584 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005585 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005586 int inheritable;
5587
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005588 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005589 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005590 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005591 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005592 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5593
5594exit:
5595 return return_value;
5596}
5597
5598#endif /* defined(MS_WINDOWS) */
5599
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005600PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5601"is_symlink($self, /)\n"
5602"--\n"
5603"\n"
5604"Return True if the entry is a symbolic link; cached per entry.");
5605
5606#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5607 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5608
5609static int
5610os_DirEntry_is_symlink_impl(DirEntry *self);
5611
5612static PyObject *
5613os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5614{
5615 PyObject *return_value = NULL;
5616 int _return_value;
5617
5618 _return_value = os_DirEntry_is_symlink_impl(self);
5619 if ((_return_value == -1) && PyErr_Occurred()) {
5620 goto exit;
5621 }
5622 return_value = PyBool_FromLong((long)_return_value);
5623
5624exit:
5625 return return_value;
5626}
5627
5628PyDoc_STRVAR(os_DirEntry_stat__doc__,
5629"stat($self, /, *, follow_symlinks=True)\n"
5630"--\n"
5631"\n"
5632"Return stat_result object for the entry; cached per entry.");
5633
5634#define OS_DIRENTRY_STAT_METHODDEF \
5635 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL, os_DirEntry_stat__doc__},
5636
5637static PyObject *
5638os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5639
5640static PyObject *
5641os_DirEntry_stat(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5642{
5643 PyObject *return_value = NULL;
5644 static const char * const _keywords[] = {"follow_symlinks", NULL};
5645 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5646 int follow_symlinks = 1;
5647
5648 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
5649 &follow_symlinks)) {
5650 goto exit;
5651 }
5652 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5653
5654exit:
5655 return return_value;
5656}
5657
5658PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5659"is_dir($self, /, *, follow_symlinks=True)\n"
5660"--\n"
5661"\n"
5662"Return True if the entry is a directory; cached per entry.");
5663
5664#define OS_DIRENTRY_IS_DIR_METHODDEF \
5665 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL, os_DirEntry_is_dir__doc__},
5666
5667static int
5668os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5669
5670static PyObject *
5671os_DirEntry_is_dir(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5672{
5673 PyObject *return_value = NULL;
5674 static const char * const _keywords[] = {"follow_symlinks", NULL};
5675 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5676 int follow_symlinks = 1;
5677 int _return_value;
5678
5679 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
5680 &follow_symlinks)) {
5681 goto exit;
5682 }
5683 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5684 if ((_return_value == -1) && PyErr_Occurred()) {
5685 goto exit;
5686 }
5687 return_value = PyBool_FromLong((long)_return_value);
5688
5689exit:
5690 return return_value;
5691}
5692
5693PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5694"is_file($self, /, *, follow_symlinks=True)\n"
5695"--\n"
5696"\n"
5697"Return True if the entry is a file; cached per entry.");
5698
5699#define OS_DIRENTRY_IS_FILE_METHODDEF \
5700 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL, os_DirEntry_is_file__doc__},
5701
5702static int
5703os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5704
5705static PyObject *
5706os_DirEntry_is_file(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5707{
5708 PyObject *return_value = NULL;
5709 static const char * const _keywords[] = {"follow_symlinks", NULL};
5710 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5711 int follow_symlinks = 1;
5712 int _return_value;
5713
5714 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
5715 &follow_symlinks)) {
5716 goto exit;
5717 }
5718 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5719 if ((_return_value == -1) && PyErr_Occurred()) {
5720 goto exit;
5721 }
5722 return_value = PyBool_FromLong((long)_return_value);
5723
5724exit:
5725 return return_value;
5726}
5727
5728PyDoc_STRVAR(os_DirEntry_inode__doc__,
5729"inode($self, /)\n"
5730"--\n"
5731"\n"
5732"Return inode of the entry; cached per entry.");
5733
5734#define OS_DIRENTRY_INODE_METHODDEF \
5735 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5736
5737static PyObject *
5738os_DirEntry_inode_impl(DirEntry *self);
5739
5740static PyObject *
5741os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5742{
5743 return os_DirEntry_inode_impl(self);
5744}
5745
5746PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5747"__fspath__($self, /)\n"
5748"--\n"
5749"\n"
5750"Returns the path for the entry.");
5751
5752#define OS_DIRENTRY___FSPATH___METHODDEF \
5753 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5754
5755static PyObject *
5756os_DirEntry___fspath___impl(DirEntry *self);
5757
5758static PyObject *
5759os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5760{
5761 return os_DirEntry___fspath___impl(self);
5762}
5763
5764PyDoc_STRVAR(os_scandir__doc__,
5765"scandir($module, /, path=None)\n"
5766"--\n"
5767"\n"
5768"Return an iterator of DirEntry objects for given path.\n"
5769"\n"
5770"path can be specified as either str, bytes or path-like object. If path\n"
5771"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5772"all other circumstances they will be str.\n"
5773"\n"
5774"If path is None, uses the path=\'.\'.");
5775
5776#define OS_SCANDIR_METHODDEF \
5777 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL, os_scandir__doc__},
5778
5779static PyObject *
5780os_scandir_impl(PyObject *module, path_t *path);
5781
5782static PyObject *
5783os_scandir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5784{
5785 PyObject *return_value = NULL;
5786 static const char * const _keywords[] = {"path", NULL};
5787 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
5788 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, 0);
5789
5790 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
5791 path_converter, &path)) {
5792 goto exit;
5793 }
5794 return_value = os_scandir_impl(module, &path);
5795
5796exit:
5797 /* Cleanup for path */
5798 path_cleanup(&path);
5799
5800 return return_value;
5801}
5802
Ethan Furman410ef8e2016-06-04 12:06:26 -07005803PyDoc_STRVAR(os_fspath__doc__,
5804"fspath($module, /, path)\n"
5805"--\n"
5806"\n"
5807"Return the file system path representation of the object.\n"
5808"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005809"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5810"object defines __fspath__(), then return the result of that method. All other\n"
5811"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005812
5813#define OS_FSPATH_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005814 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005815
5816static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005817os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005818
5819static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005820os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005821{
5822 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005823 static const char * const _keywords[] = {"path", NULL};
5824 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005825 PyObject *path;
5826
Victor Stinner37e4ef72016-09-09 20:00:13 -07005827 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005828 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005829 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005830 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005831 return_value = os_fspath_impl(module, path);
5832
5833exit:
5834 return return_value;
5835}
5836
Victor Stinner9b1f4742016-09-06 16:18:52 -07005837#if defined(HAVE_GETRANDOM_SYSCALL)
5838
5839PyDoc_STRVAR(os_getrandom__doc__,
5840"getrandom($module, /, size, flags=0)\n"
5841"--\n"
5842"\n"
5843"Obtain a series of random bytes.");
5844
5845#define OS_GETRANDOM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005846 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07005847
5848static PyObject *
5849os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
5850
5851static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005852os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07005853{
5854 PyObject *return_value = NULL;
5855 static const char * const _keywords[] = {"size", "flags", NULL};
5856 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
5857 Py_ssize_t size;
5858 int flags = 0;
5859
Victor Stinner37e4ef72016-09-09 20:00:13 -07005860 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07005861 &size, &flags)) {
5862 goto exit;
5863 }
5864 return_value = os_getrandom_impl(module, size, flags);
5865
5866exit:
5867 return return_value;
5868}
5869
5870#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
5871
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005872#ifndef OS_TTYNAME_METHODDEF
5873 #define OS_TTYNAME_METHODDEF
5874#endif /* !defined(OS_TTYNAME_METHODDEF) */
5875
5876#ifndef OS_CTERMID_METHODDEF
5877 #define OS_CTERMID_METHODDEF
5878#endif /* !defined(OS_CTERMID_METHODDEF) */
5879
5880#ifndef OS_FCHDIR_METHODDEF
5881 #define OS_FCHDIR_METHODDEF
5882#endif /* !defined(OS_FCHDIR_METHODDEF) */
5883
5884#ifndef OS_FCHMOD_METHODDEF
5885 #define OS_FCHMOD_METHODDEF
5886#endif /* !defined(OS_FCHMOD_METHODDEF) */
5887
5888#ifndef OS_LCHMOD_METHODDEF
5889 #define OS_LCHMOD_METHODDEF
5890#endif /* !defined(OS_LCHMOD_METHODDEF) */
5891
5892#ifndef OS_CHFLAGS_METHODDEF
5893 #define OS_CHFLAGS_METHODDEF
5894#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5895
5896#ifndef OS_LCHFLAGS_METHODDEF
5897 #define OS_LCHFLAGS_METHODDEF
5898#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5899
5900#ifndef OS_CHROOT_METHODDEF
5901 #define OS_CHROOT_METHODDEF
5902#endif /* !defined(OS_CHROOT_METHODDEF) */
5903
5904#ifndef OS_FSYNC_METHODDEF
5905 #define OS_FSYNC_METHODDEF
5906#endif /* !defined(OS_FSYNC_METHODDEF) */
5907
5908#ifndef OS_SYNC_METHODDEF
5909 #define OS_SYNC_METHODDEF
5910#endif /* !defined(OS_SYNC_METHODDEF) */
5911
5912#ifndef OS_FDATASYNC_METHODDEF
5913 #define OS_FDATASYNC_METHODDEF
5914#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5915
5916#ifndef OS_CHOWN_METHODDEF
5917 #define OS_CHOWN_METHODDEF
5918#endif /* !defined(OS_CHOWN_METHODDEF) */
5919
5920#ifndef OS_FCHOWN_METHODDEF
5921 #define OS_FCHOWN_METHODDEF
5922#endif /* !defined(OS_FCHOWN_METHODDEF) */
5923
5924#ifndef OS_LCHOWN_METHODDEF
5925 #define OS_LCHOWN_METHODDEF
5926#endif /* !defined(OS_LCHOWN_METHODDEF) */
5927
5928#ifndef OS_LINK_METHODDEF
5929 #define OS_LINK_METHODDEF
5930#endif /* !defined(OS_LINK_METHODDEF) */
5931
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005932#ifndef OS__GETFULLPATHNAME_METHODDEF
5933 #define OS__GETFULLPATHNAME_METHODDEF
5934#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5935
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005936#ifndef OS__GETFINALPATHNAME_METHODDEF
5937 #define OS__GETFINALPATHNAME_METHODDEF
5938#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5939
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005940#ifndef OS__ISDIR_METHODDEF
5941 #define OS__ISDIR_METHODDEF
5942#endif /* !defined(OS__ISDIR_METHODDEF) */
5943
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005944#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5945 #define OS__GETVOLUMEPATHNAME_METHODDEF
5946#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5947
5948#ifndef OS_NICE_METHODDEF
5949 #define OS_NICE_METHODDEF
5950#endif /* !defined(OS_NICE_METHODDEF) */
5951
5952#ifndef OS_GETPRIORITY_METHODDEF
5953 #define OS_GETPRIORITY_METHODDEF
5954#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
5955
5956#ifndef OS_SETPRIORITY_METHODDEF
5957 #define OS_SETPRIORITY_METHODDEF
5958#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
5959
5960#ifndef OS_SYSTEM_METHODDEF
5961 #define OS_SYSTEM_METHODDEF
5962#endif /* !defined(OS_SYSTEM_METHODDEF) */
5963
5964#ifndef OS_UNAME_METHODDEF
5965 #define OS_UNAME_METHODDEF
5966#endif /* !defined(OS_UNAME_METHODDEF) */
5967
5968#ifndef OS_EXECV_METHODDEF
5969 #define OS_EXECV_METHODDEF
5970#endif /* !defined(OS_EXECV_METHODDEF) */
5971
5972#ifndef OS_EXECVE_METHODDEF
5973 #define OS_EXECVE_METHODDEF
5974#endif /* !defined(OS_EXECVE_METHODDEF) */
5975
5976#ifndef OS_SPAWNV_METHODDEF
5977 #define OS_SPAWNV_METHODDEF
5978#endif /* !defined(OS_SPAWNV_METHODDEF) */
5979
5980#ifndef OS_SPAWNVE_METHODDEF
5981 #define OS_SPAWNVE_METHODDEF
5982#endif /* !defined(OS_SPAWNVE_METHODDEF) */
5983
5984#ifndef OS_FORK1_METHODDEF
5985 #define OS_FORK1_METHODDEF
5986#endif /* !defined(OS_FORK1_METHODDEF) */
5987
5988#ifndef OS_FORK_METHODDEF
5989 #define OS_FORK_METHODDEF
5990#endif /* !defined(OS_FORK_METHODDEF) */
5991
5992#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5993 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5994#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
5995
5996#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5997 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5998#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
5999
6000#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6001 #define OS_SCHED_GETSCHEDULER_METHODDEF
6002#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6003
6004#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6005 #define OS_SCHED_SETSCHEDULER_METHODDEF
6006#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6007
6008#ifndef OS_SCHED_GETPARAM_METHODDEF
6009 #define OS_SCHED_GETPARAM_METHODDEF
6010#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6011
6012#ifndef OS_SCHED_SETPARAM_METHODDEF
6013 #define OS_SCHED_SETPARAM_METHODDEF
6014#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6015
6016#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6017 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6018#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6019
6020#ifndef OS_SCHED_YIELD_METHODDEF
6021 #define OS_SCHED_YIELD_METHODDEF
6022#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6023
6024#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6025 #define OS_SCHED_SETAFFINITY_METHODDEF
6026#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6027
6028#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6029 #define OS_SCHED_GETAFFINITY_METHODDEF
6030#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6031
6032#ifndef OS_OPENPTY_METHODDEF
6033 #define OS_OPENPTY_METHODDEF
6034#endif /* !defined(OS_OPENPTY_METHODDEF) */
6035
6036#ifndef OS_FORKPTY_METHODDEF
6037 #define OS_FORKPTY_METHODDEF
6038#endif /* !defined(OS_FORKPTY_METHODDEF) */
6039
6040#ifndef OS_GETEGID_METHODDEF
6041 #define OS_GETEGID_METHODDEF
6042#endif /* !defined(OS_GETEGID_METHODDEF) */
6043
6044#ifndef OS_GETEUID_METHODDEF
6045 #define OS_GETEUID_METHODDEF
6046#endif /* !defined(OS_GETEUID_METHODDEF) */
6047
6048#ifndef OS_GETGID_METHODDEF
6049 #define OS_GETGID_METHODDEF
6050#endif /* !defined(OS_GETGID_METHODDEF) */
6051
Berker Peksag39404992016-09-15 20:45:16 +03006052#ifndef OS_GETPID_METHODDEF
6053 #define OS_GETPID_METHODDEF
6054#endif /* !defined(OS_GETPID_METHODDEF) */
6055
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006056#ifndef OS_GETGROUPS_METHODDEF
6057 #define OS_GETGROUPS_METHODDEF
6058#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6059
6060#ifndef OS_GETPGID_METHODDEF
6061 #define OS_GETPGID_METHODDEF
6062#endif /* !defined(OS_GETPGID_METHODDEF) */
6063
6064#ifndef OS_GETPGRP_METHODDEF
6065 #define OS_GETPGRP_METHODDEF
6066#endif /* !defined(OS_GETPGRP_METHODDEF) */
6067
6068#ifndef OS_SETPGRP_METHODDEF
6069 #define OS_SETPGRP_METHODDEF
6070#endif /* !defined(OS_SETPGRP_METHODDEF) */
6071
6072#ifndef OS_GETPPID_METHODDEF
6073 #define OS_GETPPID_METHODDEF
6074#endif /* !defined(OS_GETPPID_METHODDEF) */
6075
6076#ifndef OS_GETLOGIN_METHODDEF
6077 #define OS_GETLOGIN_METHODDEF
6078#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6079
6080#ifndef OS_GETUID_METHODDEF
6081 #define OS_GETUID_METHODDEF
6082#endif /* !defined(OS_GETUID_METHODDEF) */
6083
6084#ifndef OS_KILL_METHODDEF
6085 #define OS_KILL_METHODDEF
6086#endif /* !defined(OS_KILL_METHODDEF) */
6087
6088#ifndef OS_KILLPG_METHODDEF
6089 #define OS_KILLPG_METHODDEF
6090#endif /* !defined(OS_KILLPG_METHODDEF) */
6091
6092#ifndef OS_PLOCK_METHODDEF
6093 #define OS_PLOCK_METHODDEF
6094#endif /* !defined(OS_PLOCK_METHODDEF) */
6095
6096#ifndef OS_SETUID_METHODDEF
6097 #define OS_SETUID_METHODDEF
6098#endif /* !defined(OS_SETUID_METHODDEF) */
6099
6100#ifndef OS_SETEUID_METHODDEF
6101 #define OS_SETEUID_METHODDEF
6102#endif /* !defined(OS_SETEUID_METHODDEF) */
6103
6104#ifndef OS_SETEGID_METHODDEF
6105 #define OS_SETEGID_METHODDEF
6106#endif /* !defined(OS_SETEGID_METHODDEF) */
6107
6108#ifndef OS_SETREUID_METHODDEF
6109 #define OS_SETREUID_METHODDEF
6110#endif /* !defined(OS_SETREUID_METHODDEF) */
6111
6112#ifndef OS_SETREGID_METHODDEF
6113 #define OS_SETREGID_METHODDEF
6114#endif /* !defined(OS_SETREGID_METHODDEF) */
6115
6116#ifndef OS_SETGID_METHODDEF
6117 #define OS_SETGID_METHODDEF
6118#endif /* !defined(OS_SETGID_METHODDEF) */
6119
6120#ifndef OS_SETGROUPS_METHODDEF
6121 #define OS_SETGROUPS_METHODDEF
6122#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6123
6124#ifndef OS_WAIT3_METHODDEF
6125 #define OS_WAIT3_METHODDEF
6126#endif /* !defined(OS_WAIT3_METHODDEF) */
6127
6128#ifndef OS_WAIT4_METHODDEF
6129 #define OS_WAIT4_METHODDEF
6130#endif /* !defined(OS_WAIT4_METHODDEF) */
6131
6132#ifndef OS_WAITID_METHODDEF
6133 #define OS_WAITID_METHODDEF
6134#endif /* !defined(OS_WAITID_METHODDEF) */
6135
6136#ifndef OS_WAITPID_METHODDEF
6137 #define OS_WAITPID_METHODDEF
6138#endif /* !defined(OS_WAITPID_METHODDEF) */
6139
6140#ifndef OS_WAIT_METHODDEF
6141 #define OS_WAIT_METHODDEF
6142#endif /* !defined(OS_WAIT_METHODDEF) */
6143
6144#ifndef OS_SYMLINK_METHODDEF
6145 #define OS_SYMLINK_METHODDEF
6146#endif /* !defined(OS_SYMLINK_METHODDEF) */
6147
6148#ifndef OS_TIMES_METHODDEF
6149 #define OS_TIMES_METHODDEF
6150#endif /* !defined(OS_TIMES_METHODDEF) */
6151
6152#ifndef OS_GETSID_METHODDEF
6153 #define OS_GETSID_METHODDEF
6154#endif /* !defined(OS_GETSID_METHODDEF) */
6155
6156#ifndef OS_SETSID_METHODDEF
6157 #define OS_SETSID_METHODDEF
6158#endif /* !defined(OS_SETSID_METHODDEF) */
6159
6160#ifndef OS_SETPGID_METHODDEF
6161 #define OS_SETPGID_METHODDEF
6162#endif /* !defined(OS_SETPGID_METHODDEF) */
6163
6164#ifndef OS_TCGETPGRP_METHODDEF
6165 #define OS_TCGETPGRP_METHODDEF
6166#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6167
6168#ifndef OS_TCSETPGRP_METHODDEF
6169 #define OS_TCSETPGRP_METHODDEF
6170#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6171
6172#ifndef OS_LOCKF_METHODDEF
6173 #define OS_LOCKF_METHODDEF
6174#endif /* !defined(OS_LOCKF_METHODDEF) */
6175
6176#ifndef OS_READV_METHODDEF
6177 #define OS_READV_METHODDEF
6178#endif /* !defined(OS_READV_METHODDEF) */
6179
6180#ifndef OS_PREAD_METHODDEF
6181 #define OS_PREAD_METHODDEF
6182#endif /* !defined(OS_PREAD_METHODDEF) */
6183
6184#ifndef OS_PIPE_METHODDEF
6185 #define OS_PIPE_METHODDEF
6186#endif /* !defined(OS_PIPE_METHODDEF) */
6187
6188#ifndef OS_PIPE2_METHODDEF
6189 #define OS_PIPE2_METHODDEF
6190#endif /* !defined(OS_PIPE2_METHODDEF) */
6191
6192#ifndef OS_WRITEV_METHODDEF
6193 #define OS_WRITEV_METHODDEF
6194#endif /* !defined(OS_WRITEV_METHODDEF) */
6195
6196#ifndef OS_PWRITE_METHODDEF
6197 #define OS_PWRITE_METHODDEF
6198#endif /* !defined(OS_PWRITE_METHODDEF) */
6199
6200#ifndef OS_MKFIFO_METHODDEF
6201 #define OS_MKFIFO_METHODDEF
6202#endif /* !defined(OS_MKFIFO_METHODDEF) */
6203
6204#ifndef OS_MKNOD_METHODDEF
6205 #define OS_MKNOD_METHODDEF
6206#endif /* !defined(OS_MKNOD_METHODDEF) */
6207
6208#ifndef OS_MAJOR_METHODDEF
6209 #define OS_MAJOR_METHODDEF
6210#endif /* !defined(OS_MAJOR_METHODDEF) */
6211
6212#ifndef OS_MINOR_METHODDEF
6213 #define OS_MINOR_METHODDEF
6214#endif /* !defined(OS_MINOR_METHODDEF) */
6215
6216#ifndef OS_MAKEDEV_METHODDEF
6217 #define OS_MAKEDEV_METHODDEF
6218#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6219
6220#ifndef OS_FTRUNCATE_METHODDEF
6221 #define OS_FTRUNCATE_METHODDEF
6222#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6223
6224#ifndef OS_TRUNCATE_METHODDEF
6225 #define OS_TRUNCATE_METHODDEF
6226#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6227
6228#ifndef OS_POSIX_FALLOCATE_METHODDEF
6229 #define OS_POSIX_FALLOCATE_METHODDEF
6230#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6231
6232#ifndef OS_POSIX_FADVISE_METHODDEF
6233 #define OS_POSIX_FADVISE_METHODDEF
6234#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6235
6236#ifndef OS_PUTENV_METHODDEF
6237 #define OS_PUTENV_METHODDEF
6238#endif /* !defined(OS_PUTENV_METHODDEF) */
6239
6240#ifndef OS_UNSETENV_METHODDEF
6241 #define OS_UNSETENV_METHODDEF
6242#endif /* !defined(OS_UNSETENV_METHODDEF) */
6243
6244#ifndef OS_WCOREDUMP_METHODDEF
6245 #define OS_WCOREDUMP_METHODDEF
6246#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6247
6248#ifndef OS_WIFCONTINUED_METHODDEF
6249 #define OS_WIFCONTINUED_METHODDEF
6250#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6251
6252#ifndef OS_WIFSTOPPED_METHODDEF
6253 #define OS_WIFSTOPPED_METHODDEF
6254#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6255
6256#ifndef OS_WIFSIGNALED_METHODDEF
6257 #define OS_WIFSIGNALED_METHODDEF
6258#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6259
6260#ifndef OS_WIFEXITED_METHODDEF
6261 #define OS_WIFEXITED_METHODDEF
6262#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6263
6264#ifndef OS_WEXITSTATUS_METHODDEF
6265 #define OS_WEXITSTATUS_METHODDEF
6266#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6267
6268#ifndef OS_WTERMSIG_METHODDEF
6269 #define OS_WTERMSIG_METHODDEF
6270#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6271
6272#ifndef OS_WSTOPSIG_METHODDEF
6273 #define OS_WSTOPSIG_METHODDEF
6274#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6275
6276#ifndef OS_FSTATVFS_METHODDEF
6277 #define OS_FSTATVFS_METHODDEF
6278#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6279
6280#ifndef OS_STATVFS_METHODDEF
6281 #define OS_STATVFS_METHODDEF
6282#endif /* !defined(OS_STATVFS_METHODDEF) */
6283
6284#ifndef OS__GETDISKUSAGE_METHODDEF
6285 #define OS__GETDISKUSAGE_METHODDEF
6286#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6287
6288#ifndef OS_FPATHCONF_METHODDEF
6289 #define OS_FPATHCONF_METHODDEF
6290#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6291
6292#ifndef OS_PATHCONF_METHODDEF
6293 #define OS_PATHCONF_METHODDEF
6294#endif /* !defined(OS_PATHCONF_METHODDEF) */
6295
6296#ifndef OS_CONFSTR_METHODDEF
6297 #define OS_CONFSTR_METHODDEF
6298#endif /* !defined(OS_CONFSTR_METHODDEF) */
6299
6300#ifndef OS_SYSCONF_METHODDEF
6301 #define OS_SYSCONF_METHODDEF
6302#endif /* !defined(OS_SYSCONF_METHODDEF) */
6303
Steve Dowercc16be82016-09-08 10:35:16 -07006304#ifndef OS_STARTFILE_METHODDEF
6305 #define OS_STARTFILE_METHODDEF
6306#endif /* !defined(OS_STARTFILE_METHODDEF) */
6307
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006308#ifndef OS_GETLOADAVG_METHODDEF
6309 #define OS_GETLOADAVG_METHODDEF
6310#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6311
6312#ifndef OS_SETRESUID_METHODDEF
6313 #define OS_SETRESUID_METHODDEF
6314#endif /* !defined(OS_SETRESUID_METHODDEF) */
6315
6316#ifndef OS_SETRESGID_METHODDEF
6317 #define OS_SETRESGID_METHODDEF
6318#endif /* !defined(OS_SETRESGID_METHODDEF) */
6319
6320#ifndef OS_GETRESUID_METHODDEF
6321 #define OS_GETRESUID_METHODDEF
6322#endif /* !defined(OS_GETRESUID_METHODDEF) */
6323
6324#ifndef OS_GETRESGID_METHODDEF
6325 #define OS_GETRESGID_METHODDEF
6326#endif /* !defined(OS_GETRESGID_METHODDEF) */
6327
6328#ifndef OS_GETXATTR_METHODDEF
6329 #define OS_GETXATTR_METHODDEF
6330#endif /* !defined(OS_GETXATTR_METHODDEF) */
6331
6332#ifndef OS_SETXATTR_METHODDEF
6333 #define OS_SETXATTR_METHODDEF
6334#endif /* !defined(OS_SETXATTR_METHODDEF) */
6335
6336#ifndef OS_REMOVEXATTR_METHODDEF
6337 #define OS_REMOVEXATTR_METHODDEF
6338#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6339
6340#ifndef OS_LISTXATTR_METHODDEF
6341 #define OS_LISTXATTR_METHODDEF
6342#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6343
6344#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6345 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6346#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6347
6348#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6349 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6350#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006351
6352#ifndef OS_GETRANDOM_METHODDEF
6353 #define OS_GETRANDOM_METHODDEF
6354#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Serhiy Storchakab74fecc2016-11-08 20:28:43 +02006355/*[clinic end generated code: output=61abf6df195aa5f1 input=a9049054013a1b77]*/