blob: 72d78342110496e267ba332d9b2ebc8d17a194a9 [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"
998"\n");
999
1000#define OS__ISDIR_METHODDEF \
1001 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1002
1003static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001004os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001005
1006static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001007os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001008{
1009 PyObject *return_value = NULL;
1010 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1011
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001012 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001013 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001014 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001015 return_value = os__isdir_impl(module, &path);
1016
1017exit:
1018 /* Cleanup for path */
1019 path_cleanup(&path);
1020
1021 return return_value;
1022}
1023
1024#endif /* defined(MS_WINDOWS) */
1025
1026#if defined(MS_WINDOWS)
1027
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001028PyDoc_STRVAR(os__getvolumepathname__doc__,
1029"_getvolumepathname($module, /, path)\n"
1030"--\n"
1031"\n"
1032"A helper function for ismount on Win32.");
1033
1034#define OS__GETVOLUMEPATHNAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001035 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001036
1037static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001038os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001039
1040static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001041os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001042{
1043 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001044 static const char * const _keywords[] = {"path", NULL};
1045 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001046 PyObject *path;
1047
Victor Stinner37e4ef72016-09-09 20:00:13 -07001048 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001049 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001050 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001051 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052 return_value = os__getvolumepathname_impl(module, path);
1053
1054exit:
1055 return return_value;
1056}
1057
1058#endif /* defined(MS_WINDOWS) */
1059
1060PyDoc_STRVAR(os_mkdir__doc__,
1061"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1062"--\n"
1063"\n"
1064"Create a directory.\n"
1065"\n"
1066"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1067" and path should be relative; path will then be relative to that directory.\n"
1068"dir_fd may not be implemented on your platform.\n"
1069" If it is unavailable, using it will raise a NotImplementedError.\n"
1070"\n"
1071"The mode argument is ignored on Windows.");
1072
1073#define OS_MKDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001074 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001075
1076static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001077os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001078
1079static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001080os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001081{
1082 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001083 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1084 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001085 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1086 int mode = 511;
1087 int dir_fd = DEFAULT_DIR_FD;
1088
Victor Stinner37e4ef72016-09-09 20:00:13 -07001089 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001090 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001091 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1094
1095exit:
1096 /* Cleanup for path */
1097 path_cleanup(&path);
1098
1099 return return_value;
1100}
1101
1102#if defined(HAVE_NICE)
1103
1104PyDoc_STRVAR(os_nice__doc__,
1105"nice($module, increment, /)\n"
1106"--\n"
1107"\n"
1108"Add increment to the priority of process and return the new priority.");
1109
1110#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001111 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001112
1113static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001114os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001115
1116static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001117os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001118{
1119 PyObject *return_value = NULL;
1120 int increment;
1121
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001122 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001123 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001124 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125 return_value = os_nice_impl(module, increment);
1126
1127exit:
1128 return return_value;
1129}
1130
1131#endif /* defined(HAVE_NICE) */
1132
1133#if defined(HAVE_GETPRIORITY)
1134
1135PyDoc_STRVAR(os_getpriority__doc__,
1136"getpriority($module, /, which, who)\n"
1137"--\n"
1138"\n"
1139"Return program scheduling priority.");
1140
1141#define OS_GETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001142 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001143
1144static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001145os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001146
1147static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001148os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001149{
1150 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001151 static const char * const _keywords[] = {"which", "who", NULL};
1152 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001153 int which;
1154 int who;
1155
Victor Stinner37e4ef72016-09-09 20:00:13 -07001156 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001157 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001159 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160 return_value = os_getpriority_impl(module, which, who);
1161
1162exit:
1163 return return_value;
1164}
1165
1166#endif /* defined(HAVE_GETPRIORITY) */
1167
1168#if defined(HAVE_SETPRIORITY)
1169
1170PyDoc_STRVAR(os_setpriority__doc__,
1171"setpriority($module, /, which, who, priority)\n"
1172"--\n"
1173"\n"
1174"Set program scheduling priority.");
1175
1176#define OS_SETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001177 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001178
1179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001180os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001181
1182static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001183os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001184{
1185 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001186 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1187 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001188 int which;
1189 int who;
1190 int priority;
1191
Victor Stinner37e4ef72016-09-09 20:00:13 -07001192 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001193 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 return_value = os_setpriority_impl(module, which, who, priority);
1197
1198exit:
1199 return return_value;
1200}
1201
1202#endif /* defined(HAVE_SETPRIORITY) */
1203
1204PyDoc_STRVAR(os_rename__doc__,
1205"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1206"--\n"
1207"\n"
1208"Rename a file or directory.\n"
1209"\n"
1210"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1211" descriptor open to a directory, and the respective path string (src or dst)\n"
1212" should be relative; the path will then be relative to that directory.\n"
1213"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1214" If they are unavailable, using them will raise a NotImplementedError.");
1215
1216#define OS_RENAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001217 {"rename", (PyCFunction)os_rename, METH_FASTCALL, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001218
1219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001220os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001221 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001222
1223static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001224os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001225{
1226 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001227 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1228 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001229 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1230 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1231 int src_dir_fd = DEFAULT_DIR_FD;
1232 int dst_dir_fd = DEFAULT_DIR_FD;
1233
Victor Stinner37e4ef72016-09-09 20:00:13 -07001234 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001235 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 +03001236 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001237 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001238 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1239
1240exit:
1241 /* Cleanup for src */
1242 path_cleanup(&src);
1243 /* Cleanup for dst */
1244 path_cleanup(&dst);
1245
1246 return return_value;
1247}
1248
1249PyDoc_STRVAR(os_replace__doc__,
1250"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1251"--\n"
1252"\n"
1253"Rename a file or directory, overwriting the destination.\n"
1254"\n"
1255"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1256" descriptor open to a directory, and the respective path string (src or dst)\n"
1257" should be relative; the path will then be relative to that directory.\n"
1258"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1259" If they are unavailable, using them will raise a NotImplementedError.\"");
1260
1261#define OS_REPLACE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001262 {"replace", (PyCFunction)os_replace, METH_FASTCALL, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001263
1264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001265os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1266 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001267
1268static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001269os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001270{
1271 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001272 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1273 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001274 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1275 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1276 int src_dir_fd = DEFAULT_DIR_FD;
1277 int dst_dir_fd = DEFAULT_DIR_FD;
1278
Victor Stinner37e4ef72016-09-09 20:00:13 -07001279 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001280 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 +03001281 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001282 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001283 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1284
1285exit:
1286 /* Cleanup for src */
1287 path_cleanup(&src);
1288 /* Cleanup for dst */
1289 path_cleanup(&dst);
1290
1291 return return_value;
1292}
1293
1294PyDoc_STRVAR(os_rmdir__doc__,
1295"rmdir($module, /, path, *, dir_fd=None)\n"
1296"--\n"
1297"\n"
1298"Remove a directory.\n"
1299"\n"
1300"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1301" and path should be relative; path will then be relative to that directory.\n"
1302"dir_fd may not be implemented on your platform.\n"
1303" If it is unavailable, using it will raise a NotImplementedError.");
1304
1305#define OS_RMDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001306 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001307
1308static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001309os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001310
1311static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001312os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001313{
1314 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001315 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1316 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001317 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1318 int dir_fd = DEFAULT_DIR_FD;
1319
Victor Stinner37e4ef72016-09-09 20:00:13 -07001320 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001321 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001322 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001323 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001324 return_value = os_rmdir_impl(module, &path, dir_fd);
1325
1326exit:
1327 /* Cleanup for path */
1328 path_cleanup(&path);
1329
1330 return return_value;
1331}
1332
1333#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1334
1335PyDoc_STRVAR(os_system__doc__,
1336"system($module, /, command)\n"
1337"--\n"
1338"\n"
1339"Execute the command in a subshell.");
1340
1341#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001342 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001343
1344static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001345os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001346
1347static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001348os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001349{
1350 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001351 static const char * const _keywords[] = {"command", NULL};
1352 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001353 Py_UNICODE *command;
1354 long _return_value;
1355
Victor Stinner37e4ef72016-09-09 20:00:13 -07001356 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001357 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001358 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001359 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364 return_value = PyLong_FromLong(_return_value);
1365
1366exit:
1367 return return_value;
1368}
1369
1370#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1371
1372#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1373
1374PyDoc_STRVAR(os_system__doc__,
1375"system($module, /, command)\n"
1376"--\n"
1377"\n"
1378"Execute the command in a subshell.");
1379
1380#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001381 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001382
1383static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001384os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001385
1386static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001387os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001388{
1389 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001390 static const char * const _keywords[] = {"command", NULL};
1391 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001392 PyObject *command = NULL;
1393 long _return_value;
1394
Victor Stinner37e4ef72016-09-09 20:00:13 -07001395 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001396 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001397 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001398 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001399 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001400 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001401 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001402 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 return_value = PyLong_FromLong(_return_value);
1404
1405exit:
1406 /* Cleanup for command */
1407 Py_XDECREF(command);
1408
1409 return return_value;
1410}
1411
1412#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1413
1414PyDoc_STRVAR(os_umask__doc__,
1415"umask($module, mask, /)\n"
1416"--\n"
1417"\n"
1418"Set the current numeric umask and return the previous umask.");
1419
1420#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001421 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001422
1423static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001424os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001425
1426static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001427os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001428{
1429 PyObject *return_value = NULL;
1430 int mask;
1431
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001432 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 return_value = os_umask_impl(module, mask);
1436
1437exit:
1438 return return_value;
1439}
1440
1441PyDoc_STRVAR(os_unlink__doc__,
1442"unlink($module, /, path, *, dir_fd=None)\n"
1443"--\n"
1444"\n"
1445"Remove a file (same as remove()).\n"
1446"\n"
1447"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1448" and path should be relative; path will then be relative to that directory.\n"
1449"dir_fd may not be implemented on your platform.\n"
1450" If it is unavailable, using it will raise a NotImplementedError.");
1451
1452#define OS_UNLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001453 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001454
1455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001456os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001457
1458static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001459os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001460{
1461 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001462 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1463 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001464 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1465 int dir_fd = DEFAULT_DIR_FD;
1466
Victor Stinner37e4ef72016-09-09 20:00:13 -07001467 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001468 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001469 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 return_value = os_unlink_impl(module, &path, dir_fd);
1472
1473exit:
1474 /* Cleanup for path */
1475 path_cleanup(&path);
1476
1477 return return_value;
1478}
1479
1480PyDoc_STRVAR(os_remove__doc__,
1481"remove($module, /, path, *, dir_fd=None)\n"
1482"--\n"
1483"\n"
1484"Remove a file (same as unlink()).\n"
1485"\n"
1486"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1487" and path should be relative; path will then be relative to that directory.\n"
1488"dir_fd may not be implemented on your platform.\n"
1489" If it is unavailable, using it will raise a NotImplementedError.");
1490
1491#define OS_REMOVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001492 {"remove", (PyCFunction)os_remove, METH_FASTCALL, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001493
1494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001495os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001496
1497static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001498os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001499{
1500 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001501 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1502 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001503 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1504 int dir_fd = DEFAULT_DIR_FD;
1505
Victor Stinner37e4ef72016-09-09 20:00:13 -07001506 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001507 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001508 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 return_value = os_remove_impl(module, &path, dir_fd);
1511
1512exit:
1513 /* Cleanup for path */
1514 path_cleanup(&path);
1515
1516 return return_value;
1517}
1518
1519#if defined(HAVE_UNAME)
1520
1521PyDoc_STRVAR(os_uname__doc__,
1522"uname($module, /)\n"
1523"--\n"
1524"\n"
1525"Return an object identifying the current operating system.\n"
1526"\n"
1527"The object behaves like a named tuple with the following fields:\n"
1528" (sysname, nodename, release, version, machine)");
1529
1530#define OS_UNAME_METHODDEF \
1531 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1532
1533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001534os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001535
1536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001537os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001538{
1539 return os_uname_impl(module);
1540}
1541
1542#endif /* defined(HAVE_UNAME) */
1543
1544PyDoc_STRVAR(os_utime__doc__,
1545"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1546" follow_symlinks=True)\n"
1547"--\n"
1548"\n"
1549"Set the access and modified time of path.\n"
1550"\n"
1551"path may always be specified as a string.\n"
1552"On some platforms, path may also be specified as an open file descriptor.\n"
1553" If this functionality is unavailable, using it raises an exception.\n"
1554"\n"
1555"If times is not None, it must be a tuple (atime, mtime);\n"
1556" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001557"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001558" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1559" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001560"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001561"Specifying tuples for both times and ns is an error.\n"
1562"\n"
1563"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1564" and path should be relative; path will then be relative to that directory.\n"
1565"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1566" link, utime will modify the symbolic link itself instead of the file the\n"
1567" link points to.\n"
1568"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1569" as an open file descriptor.\n"
1570"dir_fd and follow_symlinks may not be available on your platform.\n"
1571" If they are unavailable, using them will raise a NotImplementedError.");
1572
1573#define OS_UTIME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001574 {"utime", (PyCFunction)os_utime, METH_FASTCALL, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001575
1576static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001577os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1578 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001579
1580static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001581os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001582{
1583 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001584 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1585 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001586 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1587 PyObject *times = NULL;
1588 PyObject *ns = NULL;
1589 int dir_fd = DEFAULT_DIR_FD;
1590 int follow_symlinks = 1;
1591
Victor Stinner37e4ef72016-09-09 20:00:13 -07001592 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001593 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001594 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1597
1598exit:
1599 /* Cleanup for path */
1600 path_cleanup(&path);
1601
1602 return return_value;
1603}
1604
1605PyDoc_STRVAR(os__exit__doc__,
1606"_exit($module, /, status)\n"
1607"--\n"
1608"\n"
1609"Exit to the system with specified status, without normal exit processing.");
1610
1611#define OS__EXIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001612 {"_exit", (PyCFunction)os__exit, METH_FASTCALL, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001613
1614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001615os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001616
1617static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001618os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001619{
1620 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001621 static const char * const _keywords[] = {"status", NULL};
1622 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001623 int status;
1624
Victor Stinner37e4ef72016-09-09 20:00:13 -07001625 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001626 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 return_value = os__exit_impl(module, status);
1630
1631exit:
1632 return return_value;
1633}
1634
1635#if defined(HAVE_EXECV)
1636
1637PyDoc_STRVAR(os_execv__doc__,
1638"execv($module, path, argv, /)\n"
1639"--\n"
1640"\n"
1641"Execute an executable path with arguments, replacing current process.\n"
1642"\n"
1643" path\n"
1644" Path of executable file.\n"
1645" argv\n"
1646" Tuple or list of strings.");
1647
1648#define OS_EXECV_METHODDEF \
1649 {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__},
1650
1651static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001652os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001653
1654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001655os_execv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001656{
1657 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001658 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001659 PyObject *argv;
1660
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001661 if (!PyArg_ParseTuple(args, "O&O:execv",
Steve Dowercc16be82016-09-08 10:35:16 -07001662 path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001664 }
Steve Dowercc16be82016-09-08 10:35:16 -07001665 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001666
1667exit:
1668 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001669 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001670
1671 return return_value;
1672}
1673
1674#endif /* defined(HAVE_EXECV) */
1675
1676#if defined(HAVE_EXECV)
1677
1678PyDoc_STRVAR(os_execve__doc__,
1679"execve($module, /, path, argv, env)\n"
1680"--\n"
1681"\n"
1682"Execute an executable path with arguments, replacing current process.\n"
1683"\n"
1684" path\n"
1685" Path of executable file.\n"
1686" argv\n"
1687" Tuple or list of strings.\n"
1688" env\n"
1689" Dictionary of strings mapping to strings.");
1690
1691#define OS_EXECVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001692 {"execve", (PyCFunction)os_execve, METH_FASTCALL, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001693
1694static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001695os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001696
1697static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001698os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001699{
1700 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001701 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1702 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001703 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1704 PyObject *argv;
1705 PyObject *env;
1706
Victor Stinner37e4ef72016-09-09 20:00:13 -07001707 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001708 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001709 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001710 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 return_value = os_execve_impl(module, &path, argv, env);
1712
1713exit:
1714 /* Cleanup for path */
1715 path_cleanup(&path);
1716
1717 return return_value;
1718}
1719
1720#endif /* defined(HAVE_EXECV) */
1721
Steve Dowercc16be82016-09-08 10:35:16 -07001722#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001723
1724PyDoc_STRVAR(os_spawnv__doc__,
1725"spawnv($module, mode, path, argv, /)\n"
1726"--\n"
1727"\n"
1728"Execute the program specified by path in a new process.\n"
1729"\n"
1730" mode\n"
1731" Mode of process creation.\n"
1732" path\n"
1733" Path of executable file.\n"
1734" argv\n"
1735" Tuple or list of strings.");
1736
1737#define OS_SPAWNV_METHODDEF \
1738 {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__},
1739
1740static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001741os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001742
1743static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001744os_spawnv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001745{
1746 PyObject *return_value = NULL;
1747 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001748 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001749 PyObject *argv;
1750
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001751 if (!PyArg_ParseTuple(args, "iO&O:spawnv",
Steve Dowercc16be82016-09-08 10:35:16 -07001752 &mode, path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001753 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001754 }
Steve Dowercc16be82016-09-08 10:35:16 -07001755 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001756
1757exit:
1758 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001759 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001760
1761 return return_value;
1762}
1763
Steve Dowercc16be82016-09-08 10:35:16 -07001764#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001765
Steve Dowercc16be82016-09-08 10:35:16 -07001766#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001767
1768PyDoc_STRVAR(os_spawnve__doc__,
1769"spawnve($module, mode, path, argv, env, /)\n"
1770"--\n"
1771"\n"
1772"Execute the program specified by path in a new process.\n"
1773"\n"
1774" mode\n"
1775" Mode of process creation.\n"
1776" path\n"
1777" Path of executable file.\n"
1778" argv\n"
1779" Tuple or list of strings.\n"
1780" env\n"
1781" Dictionary of strings mapping to strings.");
1782
1783#define OS_SPAWNVE_METHODDEF \
1784 {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__},
1785
1786static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001787os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001788 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001789
1790static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001791os_spawnve(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001792{
1793 PyObject *return_value = NULL;
1794 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001795 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001796 PyObject *argv;
1797 PyObject *env;
1798
Serhiy Storchaka247789c2015-04-24 00:40:51 +03001799 if (!PyArg_ParseTuple(args, "iO&OO:spawnve",
Steve Dowercc16be82016-09-08 10:35:16 -07001800 &mode, path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001802 }
Steve Dowercc16be82016-09-08 10:35:16 -07001803 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001804
1805exit:
1806 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001807 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001808
1809 return return_value;
1810}
1811
Steve Dowercc16be82016-09-08 10:35:16 -07001812#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001813
1814#if defined(HAVE_FORK1)
1815
1816PyDoc_STRVAR(os_fork1__doc__,
1817"fork1($module, /)\n"
1818"--\n"
1819"\n"
1820"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1821"\n"
1822"Return 0 to child process and PID of child to parent process.");
1823
1824#define OS_FORK1_METHODDEF \
1825 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1826
1827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001828os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001829
1830static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001831os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001832{
1833 return os_fork1_impl(module);
1834}
1835
1836#endif /* defined(HAVE_FORK1) */
1837
1838#if defined(HAVE_FORK)
1839
1840PyDoc_STRVAR(os_fork__doc__,
1841"fork($module, /)\n"
1842"--\n"
1843"\n"
1844"Fork a child process.\n"
1845"\n"
1846"Return 0 to child process and PID of child to parent process.");
1847
1848#define OS_FORK_METHODDEF \
1849 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1850
1851static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001852os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001853
1854static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001855os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001856{
1857 return os_fork_impl(module);
1858}
1859
1860#endif /* defined(HAVE_FORK) */
1861
1862#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1863
1864PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1865"sched_get_priority_max($module, /, policy)\n"
1866"--\n"
1867"\n"
1868"Get the maximum scheduling priority for policy.");
1869
1870#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001871 {"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 +03001872
1873static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001874os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001875
1876static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001877os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001878{
1879 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001880 static const char * const _keywords[] = {"policy", NULL};
1881 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001882 int policy;
1883
Victor Stinner37e4ef72016-09-09 20:00:13 -07001884 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001885 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001886 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001887 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001888 return_value = os_sched_get_priority_max_impl(module, policy);
1889
1890exit:
1891 return return_value;
1892}
1893
1894#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1895
1896#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1897
1898PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1899"sched_get_priority_min($module, /, policy)\n"
1900"--\n"
1901"\n"
1902"Get the minimum scheduling priority for policy.");
1903
1904#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001905 {"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 +03001906
1907static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001908os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001909
1910static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001911os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001912{
1913 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001914 static const char * const _keywords[] = {"policy", NULL};
1915 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001916 int policy;
1917
Victor Stinner37e4ef72016-09-09 20:00:13 -07001918 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001919 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001921 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001922 return_value = os_sched_get_priority_min_impl(module, policy);
1923
1924exit:
1925 return return_value;
1926}
1927
1928#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1929
1930#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1931
1932PyDoc_STRVAR(os_sched_getscheduler__doc__,
1933"sched_getscheduler($module, pid, /)\n"
1934"--\n"
1935"\n"
1936"Get the scheduling policy for the process identifiedy by pid.\n"
1937"\n"
1938"Passing 0 for pid returns the scheduling policy for the calling process.");
1939
1940#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001941 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001942
1943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001944os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001945
1946static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001947os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001948{
1949 PyObject *return_value = NULL;
1950 pid_t pid;
1951
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001952 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001953 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001954 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001955 return_value = os_sched_getscheduler_impl(module, pid);
1956
1957exit:
1958 return return_value;
1959}
1960
1961#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1962
1963#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1964
1965PyDoc_STRVAR(os_sched_param__doc__,
1966"sched_param(sched_priority)\n"
1967"--\n"
1968"\n"
1969"Current has only one field: sched_priority\");\n"
1970"\n"
1971" sched_priority\n"
1972" A scheduling parameter.");
1973
1974static PyObject *
1975os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1976
1977static PyObject *
1978os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1979{
1980 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001981 static const char * const _keywords[] = {"sched_priority", NULL};
1982 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001983 PyObject *sched_priority;
1984
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001985 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001986 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001987 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001988 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001989 return_value = os_sched_param_impl(type, sched_priority);
1990
1991exit:
1992 return return_value;
1993}
1994
1995#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
1996
1997#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1998
1999PyDoc_STRVAR(os_sched_setscheduler__doc__,
2000"sched_setscheduler($module, pid, policy, param, /)\n"
2001"--\n"
2002"\n"
2003"Set the scheduling policy for the process identified by pid.\n"
2004"\n"
2005"If pid is 0, the calling process is changed.\n"
2006"param is an instance of sched_param.");
2007
2008#define OS_SCHED_SETSCHEDULER_METHODDEF \
2009 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__},
2010
2011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002012os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002013 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002014
2015static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002016os_sched_setscheduler(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002017{
2018 PyObject *return_value = NULL;
2019 pid_t pid;
2020 int policy;
2021 struct sched_param param;
2022
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002023 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002024 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002026 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002027 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2028
2029exit:
2030 return return_value;
2031}
2032
2033#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2034
2035#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2036
2037PyDoc_STRVAR(os_sched_getparam__doc__,
2038"sched_getparam($module, pid, /)\n"
2039"--\n"
2040"\n"
2041"Returns scheduling parameters for the process identified by pid.\n"
2042"\n"
2043"If pid is 0, returns parameters for the calling process.\n"
2044"Return value is an instance of sched_param.");
2045
2046#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002047 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002048
2049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002050os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002051
2052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002053os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002054{
2055 PyObject *return_value = NULL;
2056 pid_t pid;
2057
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002058 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002059 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002060 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002061 return_value = os_sched_getparam_impl(module, pid);
2062
2063exit:
2064 return return_value;
2065}
2066
2067#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2068
2069#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2070
2071PyDoc_STRVAR(os_sched_setparam__doc__,
2072"sched_setparam($module, pid, param, /)\n"
2073"--\n"
2074"\n"
2075"Set scheduling parameters for the process identified by pid.\n"
2076"\n"
2077"If pid is 0, sets parameters for the calling process.\n"
2078"param should be an instance of sched_param.");
2079
2080#define OS_SCHED_SETPARAM_METHODDEF \
2081 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__},
2082
2083static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002084os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002085 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002086
2087static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002088os_sched_setparam(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002089{
2090 PyObject *return_value = NULL;
2091 pid_t pid;
2092 struct sched_param param;
2093
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002094 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002095 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002096 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002097 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002098 return_value = os_sched_setparam_impl(module, pid, &param);
2099
2100exit:
2101 return return_value;
2102}
2103
2104#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2105
2106#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2107
2108PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2109"sched_rr_get_interval($module, pid, /)\n"
2110"--\n"
2111"\n"
2112"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2113"\n"
2114"Value returned is a float.");
2115
2116#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002117 {"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 +03002118
2119static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002120os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002121
2122static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002123os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002124{
2125 PyObject *return_value = NULL;
2126 pid_t pid;
2127 double _return_value;
2128
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002129 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002130 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002131 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002132 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002133 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002135 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002136 return_value = PyFloat_FromDouble(_return_value);
2137
2138exit:
2139 return return_value;
2140}
2141
2142#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2143
2144#if defined(HAVE_SCHED_H)
2145
2146PyDoc_STRVAR(os_sched_yield__doc__,
2147"sched_yield($module, /)\n"
2148"--\n"
2149"\n"
2150"Voluntarily relinquish the CPU.");
2151
2152#define OS_SCHED_YIELD_METHODDEF \
2153 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2154
2155static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002156os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002157
2158static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002159os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002160{
2161 return os_sched_yield_impl(module);
2162}
2163
2164#endif /* defined(HAVE_SCHED_H) */
2165
2166#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2167
2168PyDoc_STRVAR(os_sched_setaffinity__doc__,
2169"sched_setaffinity($module, pid, mask, /)\n"
2170"--\n"
2171"\n"
2172"Set the CPU affinity of the process identified by pid to mask.\n"
2173"\n"
2174"mask should be an iterable of integers identifying CPUs.");
2175
2176#define OS_SCHED_SETAFFINITY_METHODDEF \
2177 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__},
2178
2179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002180os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002181
2182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002183os_sched_setaffinity(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002184{
2185 PyObject *return_value = NULL;
2186 pid_t pid;
2187 PyObject *mask;
2188
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002189 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002190 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002191 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002193 return_value = os_sched_setaffinity_impl(module, pid, mask);
2194
2195exit:
2196 return return_value;
2197}
2198
2199#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2200
2201#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2202
2203PyDoc_STRVAR(os_sched_getaffinity__doc__,
2204"sched_getaffinity($module, pid, /)\n"
2205"--\n"
2206"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002207"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002208"\n"
2209"The affinity is returned as a set of CPU identifiers.");
2210
2211#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002212 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002213
2214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002215os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002216
2217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002218os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002219{
2220 PyObject *return_value = NULL;
2221 pid_t pid;
2222
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002223 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002224 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002225 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002226 return_value = os_sched_getaffinity_impl(module, pid);
2227
2228exit:
2229 return return_value;
2230}
2231
2232#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2233
2234#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2235
2236PyDoc_STRVAR(os_openpty__doc__,
2237"openpty($module, /)\n"
2238"--\n"
2239"\n"
2240"Open a pseudo-terminal.\n"
2241"\n"
2242"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2243"for both the master and slave ends.");
2244
2245#define OS_OPENPTY_METHODDEF \
2246 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2247
2248static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002249os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002250
2251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002252os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002253{
2254 return os_openpty_impl(module);
2255}
2256
2257#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2258
2259#if defined(HAVE_FORKPTY)
2260
2261PyDoc_STRVAR(os_forkpty__doc__,
2262"forkpty($module, /)\n"
2263"--\n"
2264"\n"
2265"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2266"\n"
2267"Returns a tuple of (pid, master_fd).\n"
2268"Like fork(), return pid of 0 to the child process,\n"
2269"and pid of child to the parent process.\n"
2270"To both, return fd of newly opened pseudo-terminal.");
2271
2272#define OS_FORKPTY_METHODDEF \
2273 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2274
2275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002276os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002277
2278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002279os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002280{
2281 return os_forkpty_impl(module);
2282}
2283
2284#endif /* defined(HAVE_FORKPTY) */
2285
2286#if defined(HAVE_GETEGID)
2287
2288PyDoc_STRVAR(os_getegid__doc__,
2289"getegid($module, /)\n"
2290"--\n"
2291"\n"
2292"Return the current process\'s effective group id.");
2293
2294#define OS_GETEGID_METHODDEF \
2295 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2296
2297static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002298os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002299
2300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002301os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002302{
2303 return os_getegid_impl(module);
2304}
2305
2306#endif /* defined(HAVE_GETEGID) */
2307
2308#if defined(HAVE_GETEUID)
2309
2310PyDoc_STRVAR(os_geteuid__doc__,
2311"geteuid($module, /)\n"
2312"--\n"
2313"\n"
2314"Return the current process\'s effective user id.");
2315
2316#define OS_GETEUID_METHODDEF \
2317 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2318
2319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002320os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002321
2322static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002323os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002324{
2325 return os_geteuid_impl(module);
2326}
2327
2328#endif /* defined(HAVE_GETEUID) */
2329
2330#if defined(HAVE_GETGID)
2331
2332PyDoc_STRVAR(os_getgid__doc__,
2333"getgid($module, /)\n"
2334"--\n"
2335"\n"
2336"Return the current process\'s group id.");
2337
2338#define OS_GETGID_METHODDEF \
2339 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2340
2341static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002342os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002343
2344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002345os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002346{
2347 return os_getgid_impl(module);
2348}
2349
2350#endif /* defined(HAVE_GETGID) */
2351
Berker Peksag39404992016-09-15 20:45:16 +03002352#if defined(HAVE_GETPID)
2353
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002354PyDoc_STRVAR(os_getpid__doc__,
2355"getpid($module, /)\n"
2356"--\n"
2357"\n"
2358"Return the current process id.");
2359
2360#define OS_GETPID_METHODDEF \
2361 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2362
2363static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002364os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002365
2366static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002367os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002368{
2369 return os_getpid_impl(module);
2370}
2371
Berker Peksag39404992016-09-15 20:45:16 +03002372#endif /* defined(HAVE_GETPID) */
2373
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002374#if defined(HAVE_GETGROUPS)
2375
2376PyDoc_STRVAR(os_getgroups__doc__,
2377"getgroups($module, /)\n"
2378"--\n"
2379"\n"
2380"Return list of supplemental group IDs for the process.");
2381
2382#define OS_GETGROUPS_METHODDEF \
2383 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2384
2385static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002386os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002387
2388static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002389os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002390{
2391 return os_getgroups_impl(module);
2392}
2393
2394#endif /* defined(HAVE_GETGROUPS) */
2395
2396#if defined(HAVE_GETPGID)
2397
2398PyDoc_STRVAR(os_getpgid__doc__,
2399"getpgid($module, /, pid)\n"
2400"--\n"
2401"\n"
2402"Call the system call getpgid(), and return the result.");
2403
2404#define OS_GETPGID_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002405 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002406
2407static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002408os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002409
2410static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002411os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002412{
2413 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002414 static const char * const _keywords[] = {"pid", NULL};
2415 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002416 pid_t pid;
2417
Victor Stinner37e4ef72016-09-09 20:00:13 -07002418 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002419 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002420 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002421 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002422 return_value = os_getpgid_impl(module, pid);
2423
2424exit:
2425 return return_value;
2426}
2427
2428#endif /* defined(HAVE_GETPGID) */
2429
2430#if defined(HAVE_GETPGRP)
2431
2432PyDoc_STRVAR(os_getpgrp__doc__,
2433"getpgrp($module, /)\n"
2434"--\n"
2435"\n"
2436"Return the current process group id.");
2437
2438#define OS_GETPGRP_METHODDEF \
2439 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2440
2441static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002442os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002443
2444static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002445os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002446{
2447 return os_getpgrp_impl(module);
2448}
2449
2450#endif /* defined(HAVE_GETPGRP) */
2451
2452#if defined(HAVE_SETPGRP)
2453
2454PyDoc_STRVAR(os_setpgrp__doc__,
2455"setpgrp($module, /)\n"
2456"--\n"
2457"\n"
2458"Make the current process the leader of its process group.");
2459
2460#define OS_SETPGRP_METHODDEF \
2461 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2462
2463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002464os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002465
2466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002467os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002468{
2469 return os_setpgrp_impl(module);
2470}
2471
2472#endif /* defined(HAVE_SETPGRP) */
2473
2474#if defined(HAVE_GETPPID)
2475
2476PyDoc_STRVAR(os_getppid__doc__,
2477"getppid($module, /)\n"
2478"--\n"
2479"\n"
2480"Return the parent\'s process id.\n"
2481"\n"
2482"If the parent process has already exited, Windows machines will still\n"
2483"return its id; others systems will return the id of the \'init\' process (1).");
2484
2485#define OS_GETPPID_METHODDEF \
2486 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2487
2488static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002489os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002490
2491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002492os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002493{
2494 return os_getppid_impl(module);
2495}
2496
2497#endif /* defined(HAVE_GETPPID) */
2498
2499#if defined(HAVE_GETLOGIN)
2500
2501PyDoc_STRVAR(os_getlogin__doc__,
2502"getlogin($module, /)\n"
2503"--\n"
2504"\n"
2505"Return the actual login name.");
2506
2507#define OS_GETLOGIN_METHODDEF \
2508 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2509
2510static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002511os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002512
2513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002514os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002515{
2516 return os_getlogin_impl(module);
2517}
2518
2519#endif /* defined(HAVE_GETLOGIN) */
2520
2521#if defined(HAVE_GETUID)
2522
2523PyDoc_STRVAR(os_getuid__doc__,
2524"getuid($module, /)\n"
2525"--\n"
2526"\n"
2527"Return the current process\'s user id.");
2528
2529#define OS_GETUID_METHODDEF \
2530 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2531
2532static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002533os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002534
2535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002536os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002537{
2538 return os_getuid_impl(module);
2539}
2540
2541#endif /* defined(HAVE_GETUID) */
2542
2543#if defined(HAVE_KILL)
2544
2545PyDoc_STRVAR(os_kill__doc__,
2546"kill($module, pid, signal, /)\n"
2547"--\n"
2548"\n"
2549"Kill a process with a signal.");
2550
2551#define OS_KILL_METHODDEF \
2552 {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__},
2553
2554static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002555os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002556
2557static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002558os_kill(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002559{
2560 PyObject *return_value = NULL;
2561 pid_t pid;
2562 Py_ssize_t signal;
2563
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002564 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002565 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002566 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002567 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002568 return_value = os_kill_impl(module, pid, signal);
2569
2570exit:
2571 return return_value;
2572}
2573
2574#endif /* defined(HAVE_KILL) */
2575
2576#if defined(HAVE_KILLPG)
2577
2578PyDoc_STRVAR(os_killpg__doc__,
2579"killpg($module, pgid, signal, /)\n"
2580"--\n"
2581"\n"
2582"Kill a process group with a signal.");
2583
2584#define OS_KILLPG_METHODDEF \
2585 {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__},
2586
2587static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002588os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002589
2590static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002591os_killpg(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002592{
2593 PyObject *return_value = NULL;
2594 pid_t pgid;
2595 int signal;
2596
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002597 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002598 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002599 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002600 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002601 return_value = os_killpg_impl(module, pgid, signal);
2602
2603exit:
2604 return return_value;
2605}
2606
2607#endif /* defined(HAVE_KILLPG) */
2608
2609#if defined(HAVE_PLOCK)
2610
2611PyDoc_STRVAR(os_plock__doc__,
2612"plock($module, op, /)\n"
2613"--\n"
2614"\n"
2615"Lock program segments into memory.\");");
2616
2617#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002618 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002619
2620static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002621os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002622
2623static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002624os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002625{
2626 PyObject *return_value = NULL;
2627 int op;
2628
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002629 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002630 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002631 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002632 return_value = os_plock_impl(module, op);
2633
2634exit:
2635 return return_value;
2636}
2637
2638#endif /* defined(HAVE_PLOCK) */
2639
2640#if defined(HAVE_SETUID)
2641
2642PyDoc_STRVAR(os_setuid__doc__,
2643"setuid($module, uid, /)\n"
2644"--\n"
2645"\n"
2646"Set the current process\'s user id.");
2647
2648#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002649 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002650
2651static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002652os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002653
2654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002655os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002656{
2657 PyObject *return_value = NULL;
2658 uid_t uid;
2659
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002660 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002661 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002662 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002663 return_value = os_setuid_impl(module, uid);
2664
2665exit:
2666 return return_value;
2667}
2668
2669#endif /* defined(HAVE_SETUID) */
2670
2671#if defined(HAVE_SETEUID)
2672
2673PyDoc_STRVAR(os_seteuid__doc__,
2674"seteuid($module, euid, /)\n"
2675"--\n"
2676"\n"
2677"Set the current process\'s effective user id.");
2678
2679#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002680 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002681
2682static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002683os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002684
2685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002686os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002687{
2688 PyObject *return_value = NULL;
2689 uid_t euid;
2690
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002691 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002692 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002693 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002694 return_value = os_seteuid_impl(module, euid);
2695
2696exit:
2697 return return_value;
2698}
2699
2700#endif /* defined(HAVE_SETEUID) */
2701
2702#if defined(HAVE_SETEGID)
2703
2704PyDoc_STRVAR(os_setegid__doc__,
2705"setegid($module, egid, /)\n"
2706"--\n"
2707"\n"
2708"Set the current process\'s effective group id.");
2709
2710#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002711 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002712
2713static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002714os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002715
2716static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002717os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002718{
2719 PyObject *return_value = NULL;
2720 gid_t egid;
2721
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002722 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002723 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002724 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002725 return_value = os_setegid_impl(module, egid);
2726
2727exit:
2728 return return_value;
2729}
2730
2731#endif /* defined(HAVE_SETEGID) */
2732
2733#if defined(HAVE_SETREUID)
2734
2735PyDoc_STRVAR(os_setreuid__doc__,
2736"setreuid($module, ruid, euid, /)\n"
2737"--\n"
2738"\n"
2739"Set the current process\'s real and effective user ids.");
2740
2741#define OS_SETREUID_METHODDEF \
2742 {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__},
2743
2744static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002745os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002746
2747static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002748os_setreuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002749{
2750 PyObject *return_value = NULL;
2751 uid_t ruid;
2752 uid_t euid;
2753
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002754 if (!PyArg_ParseTuple(args, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002755 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002756 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002757 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002758 return_value = os_setreuid_impl(module, ruid, euid);
2759
2760exit:
2761 return return_value;
2762}
2763
2764#endif /* defined(HAVE_SETREUID) */
2765
2766#if defined(HAVE_SETREGID)
2767
2768PyDoc_STRVAR(os_setregid__doc__,
2769"setregid($module, rgid, egid, /)\n"
2770"--\n"
2771"\n"
2772"Set the current process\'s real and effective group ids.");
2773
2774#define OS_SETREGID_METHODDEF \
2775 {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__},
2776
2777static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002778os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002779
2780static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002781os_setregid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002782{
2783 PyObject *return_value = NULL;
2784 gid_t rgid;
2785 gid_t egid;
2786
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002787 if (!PyArg_ParseTuple(args, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002788 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002789 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002790 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002791 return_value = os_setregid_impl(module, rgid, egid);
2792
2793exit:
2794 return return_value;
2795}
2796
2797#endif /* defined(HAVE_SETREGID) */
2798
2799#if defined(HAVE_SETGID)
2800
2801PyDoc_STRVAR(os_setgid__doc__,
2802"setgid($module, gid, /)\n"
2803"--\n"
2804"\n"
2805"Set the current process\'s group id.");
2806
2807#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002808 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002809
2810static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002811os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002812
2813static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002814os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002815{
2816 PyObject *return_value = NULL;
2817 gid_t gid;
2818
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002819 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002820 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002821 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002822 return_value = os_setgid_impl(module, gid);
2823
2824exit:
2825 return return_value;
2826}
2827
2828#endif /* defined(HAVE_SETGID) */
2829
2830#if defined(HAVE_SETGROUPS)
2831
2832PyDoc_STRVAR(os_setgroups__doc__,
2833"setgroups($module, groups, /)\n"
2834"--\n"
2835"\n"
2836"Set the groups of the current process to list.");
2837
2838#define OS_SETGROUPS_METHODDEF \
2839 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2840
2841#endif /* defined(HAVE_SETGROUPS) */
2842
2843#if defined(HAVE_WAIT3)
2844
2845PyDoc_STRVAR(os_wait3__doc__,
2846"wait3($module, /, options)\n"
2847"--\n"
2848"\n"
2849"Wait for completion of a child process.\n"
2850"\n"
2851"Returns a tuple of information about the child process:\n"
2852" (pid, status, rusage)");
2853
2854#define OS_WAIT3_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002855 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002856
2857static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002858os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002859
2860static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002861os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862{
2863 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002864 static const char * const _keywords[] = {"options", NULL};
2865 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002866 int options;
2867
Victor Stinner37e4ef72016-09-09 20:00:13 -07002868 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002869 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002872 return_value = os_wait3_impl(module, options);
2873
2874exit:
2875 return return_value;
2876}
2877
2878#endif /* defined(HAVE_WAIT3) */
2879
2880#if defined(HAVE_WAIT4)
2881
2882PyDoc_STRVAR(os_wait4__doc__,
2883"wait4($module, /, pid, options)\n"
2884"--\n"
2885"\n"
2886"Wait for completion of a specific child process.\n"
2887"\n"
2888"Returns a tuple of information about the child process:\n"
2889" (pid, status, rusage)");
2890
2891#define OS_WAIT4_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002892 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002893
2894static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002895os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002896
2897static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002898os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002899{
2900 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002901 static const char * const _keywords[] = {"pid", "options", NULL};
2902 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002903 pid_t pid;
2904 int options;
2905
Victor Stinner37e4ef72016-09-09 20:00:13 -07002906 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002907 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002908 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002909 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002910 return_value = os_wait4_impl(module, pid, options);
2911
2912exit:
2913 return return_value;
2914}
2915
2916#endif /* defined(HAVE_WAIT4) */
2917
2918#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2919
2920PyDoc_STRVAR(os_waitid__doc__,
2921"waitid($module, idtype, id, options, /)\n"
2922"--\n"
2923"\n"
2924"Returns the result of waiting for a process or processes.\n"
2925"\n"
2926" idtype\n"
2927" Must be one of be P_PID, P_PGID or P_ALL.\n"
2928" id\n"
2929" The id to wait on.\n"
2930" options\n"
2931" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2932" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2933"\n"
2934"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2935"no children in a waitable state.");
2936
2937#define OS_WAITID_METHODDEF \
2938 {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__},
2939
2940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002941os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002942
2943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002944os_waitid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002945{
2946 PyObject *return_value = NULL;
2947 idtype_t idtype;
2948 id_t id;
2949 int options;
2950
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002951 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002952 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002953 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002954 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002955 return_value = os_waitid_impl(module, idtype, id, options);
2956
2957exit:
2958 return return_value;
2959}
2960
2961#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
2962
2963#if defined(HAVE_WAITPID)
2964
2965PyDoc_STRVAR(os_waitpid__doc__,
2966"waitpid($module, pid, options, /)\n"
2967"--\n"
2968"\n"
2969"Wait for completion of a given child process.\n"
2970"\n"
2971"Returns a tuple of information regarding the child process:\n"
2972" (pid, status)\n"
2973"\n"
2974"The options argument is ignored on Windows.");
2975
2976#define OS_WAITPID_METHODDEF \
2977 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
2978
2979static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002980os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002981
2982static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002983os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002984{
2985 PyObject *return_value = NULL;
2986 pid_t pid;
2987 int options;
2988
Serhiy Storchaka247789c2015-04-24 00:40:51 +03002989 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002990 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002991 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002992 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002993 return_value = os_waitpid_impl(module, pid, options);
2994
2995exit:
2996 return return_value;
2997}
2998
2999#endif /* defined(HAVE_WAITPID) */
3000
3001#if defined(HAVE_CWAIT)
3002
3003PyDoc_STRVAR(os_waitpid__doc__,
3004"waitpid($module, pid, options, /)\n"
3005"--\n"
3006"\n"
3007"Wait for completion of a given process.\n"
3008"\n"
3009"Returns a tuple of information regarding the process:\n"
3010" (pid, status << 8)\n"
3011"\n"
3012"The options argument is ignored on Windows.");
3013
3014#define OS_WAITPID_METHODDEF \
3015 {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__},
3016
3017static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003018os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003019
3020static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003021os_waitpid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003022{
3023 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003024 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003025 int options;
3026
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003027 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003028 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003029 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003030 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003031 return_value = os_waitpid_impl(module, pid, options);
3032
3033exit:
3034 return return_value;
3035}
3036
3037#endif /* defined(HAVE_CWAIT) */
3038
3039#if defined(HAVE_WAIT)
3040
3041PyDoc_STRVAR(os_wait__doc__,
3042"wait($module, /)\n"
3043"--\n"
3044"\n"
3045"Wait for completion of a child process.\n"
3046"\n"
3047"Returns a tuple of information about the child process:\n"
3048" (pid, status)");
3049
3050#define OS_WAIT_METHODDEF \
3051 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3052
3053static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003054os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003055
3056static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003057os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003058{
3059 return os_wait_impl(module);
3060}
3061
3062#endif /* defined(HAVE_WAIT) */
3063
3064#if defined(HAVE_SYMLINK)
3065
3066PyDoc_STRVAR(os_symlink__doc__,
3067"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3068"--\n"
3069"\n"
3070"Create a symbolic link pointing to src named dst.\n"
3071"\n"
3072"target_is_directory is required on Windows if the target is to be\n"
3073" interpreted as a directory. (On Windows, symlink requires\n"
3074" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3075" target_is_directory is ignored on non-Windows platforms.\n"
3076"\n"
3077"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3078" and path should be relative; path will then be relative to that directory.\n"
3079"dir_fd may not be implemented on your platform.\n"
3080" If it is unavailable, using it will raise a NotImplementedError.");
3081
3082#define OS_SYMLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003083 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003084
3085static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003086os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003087 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003088
3089static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003090os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003091{
3092 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003093 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3094 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003095 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3096 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3097 int target_is_directory = 0;
3098 int dir_fd = DEFAULT_DIR_FD;
3099
Victor Stinner37e4ef72016-09-09 20:00:13 -07003100 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003101 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003102 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003103 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003104 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3105
3106exit:
3107 /* Cleanup for src */
3108 path_cleanup(&src);
3109 /* Cleanup for dst */
3110 path_cleanup(&dst);
3111
3112 return return_value;
3113}
3114
3115#endif /* defined(HAVE_SYMLINK) */
3116
3117#if defined(HAVE_TIMES)
3118
3119PyDoc_STRVAR(os_times__doc__,
3120"times($module, /)\n"
3121"--\n"
3122"\n"
3123"Return a collection containing process timing information.\n"
3124"\n"
3125"The object returned behaves like a named tuple with these fields:\n"
3126" (utime, stime, cutime, cstime, elapsed_time)\n"
3127"All fields are floating point numbers.");
3128
3129#define OS_TIMES_METHODDEF \
3130 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3131
3132static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003133os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003134
3135static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003136os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003137{
3138 return os_times_impl(module);
3139}
3140
3141#endif /* defined(HAVE_TIMES) */
3142
3143#if defined(HAVE_GETSID)
3144
3145PyDoc_STRVAR(os_getsid__doc__,
3146"getsid($module, pid, /)\n"
3147"--\n"
3148"\n"
3149"Call the system call getsid(pid) and return the result.");
3150
3151#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003152 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003153
3154static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003155os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003156
3157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003158os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003159{
3160 PyObject *return_value = NULL;
3161 pid_t pid;
3162
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003163 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003164 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003165 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003166 return_value = os_getsid_impl(module, pid);
3167
3168exit:
3169 return return_value;
3170}
3171
3172#endif /* defined(HAVE_GETSID) */
3173
3174#if defined(HAVE_SETSID)
3175
3176PyDoc_STRVAR(os_setsid__doc__,
3177"setsid($module, /)\n"
3178"--\n"
3179"\n"
3180"Call the system call setsid().");
3181
3182#define OS_SETSID_METHODDEF \
3183 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3184
3185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003186os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003187
3188static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003189os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003190{
3191 return os_setsid_impl(module);
3192}
3193
3194#endif /* defined(HAVE_SETSID) */
3195
3196#if defined(HAVE_SETPGID)
3197
3198PyDoc_STRVAR(os_setpgid__doc__,
3199"setpgid($module, pid, pgrp, /)\n"
3200"--\n"
3201"\n"
3202"Call the system call setpgid(pid, pgrp).");
3203
3204#define OS_SETPGID_METHODDEF \
3205 {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__},
3206
3207static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003208os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209
3210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003211os_setpgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003212{
3213 PyObject *return_value = NULL;
3214 pid_t pid;
3215 pid_t pgrp;
3216
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003217 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003218 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003219 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003220 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003221 return_value = os_setpgid_impl(module, pid, pgrp);
3222
3223exit:
3224 return return_value;
3225}
3226
3227#endif /* defined(HAVE_SETPGID) */
3228
3229#if defined(HAVE_TCGETPGRP)
3230
3231PyDoc_STRVAR(os_tcgetpgrp__doc__,
3232"tcgetpgrp($module, fd, /)\n"
3233"--\n"
3234"\n"
3235"Return the process group associated with the terminal specified by fd.");
3236
3237#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003238 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003239
3240static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003241os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003242
3243static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003244os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003245{
3246 PyObject *return_value = NULL;
3247 int fd;
3248
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003249 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003250 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003251 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003252 return_value = os_tcgetpgrp_impl(module, fd);
3253
3254exit:
3255 return return_value;
3256}
3257
3258#endif /* defined(HAVE_TCGETPGRP) */
3259
3260#if defined(HAVE_TCSETPGRP)
3261
3262PyDoc_STRVAR(os_tcsetpgrp__doc__,
3263"tcsetpgrp($module, fd, pgid, /)\n"
3264"--\n"
3265"\n"
3266"Set the process group associated with the terminal specified by fd.");
3267
3268#define OS_TCSETPGRP_METHODDEF \
3269 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__},
3270
3271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003272os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003273
3274static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003275os_tcsetpgrp(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003276{
3277 PyObject *return_value = NULL;
3278 int fd;
3279 pid_t pgid;
3280
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003281 if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003282 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3286
3287exit:
3288 return return_value;
3289}
3290
3291#endif /* defined(HAVE_TCSETPGRP) */
3292
3293PyDoc_STRVAR(os_open__doc__,
3294"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3295"--\n"
3296"\n"
3297"Open a file for low level IO. Returns a file descriptor (integer).\n"
3298"\n"
3299"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3300" and path should be relative; path will then be relative to that directory.\n"
3301"dir_fd may not be implemented on your platform.\n"
3302" If it is unavailable, using it will raise a NotImplementedError.");
3303
3304#define OS_OPEN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003305 {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003306
3307static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003308os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003309
3310static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003311os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003312{
3313 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003314 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3315 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003316 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3317 int flags;
3318 int mode = 511;
3319 int dir_fd = DEFAULT_DIR_FD;
3320 int _return_value;
3321
Victor Stinner37e4ef72016-09-09 20:00:13 -07003322 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003323 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003324 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003325 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003327 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003328 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003329 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003330 return_value = PyLong_FromLong((long)_return_value);
3331
3332exit:
3333 /* Cleanup for path */
3334 path_cleanup(&path);
3335
3336 return return_value;
3337}
3338
3339PyDoc_STRVAR(os_close__doc__,
3340"close($module, /, fd)\n"
3341"--\n"
3342"\n"
3343"Close a file descriptor.");
3344
3345#define OS_CLOSE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003346 {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003347
3348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003349os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003350
3351static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003352os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003353{
3354 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003355 static const char * const _keywords[] = {"fd", NULL};
3356 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003357 int fd;
3358
Victor Stinner37e4ef72016-09-09 20:00:13 -07003359 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003360 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003361 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003362 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003363 return_value = os_close_impl(module, fd);
3364
3365exit:
3366 return return_value;
3367}
3368
3369PyDoc_STRVAR(os_closerange__doc__,
3370"closerange($module, fd_low, fd_high, /)\n"
3371"--\n"
3372"\n"
3373"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3374
3375#define OS_CLOSERANGE_METHODDEF \
3376 {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__},
3377
3378static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003379os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003380
3381static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003382os_closerange(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003383{
3384 PyObject *return_value = NULL;
3385 int fd_low;
3386 int fd_high;
3387
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003388 if (!PyArg_ParseTuple(args, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003389 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003390 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003391 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003392 return_value = os_closerange_impl(module, fd_low, fd_high);
3393
3394exit:
3395 return return_value;
3396}
3397
3398PyDoc_STRVAR(os_dup__doc__,
3399"dup($module, fd, /)\n"
3400"--\n"
3401"\n"
3402"Return a duplicate of a file descriptor.");
3403
3404#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003405 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003406
3407static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003408os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003409
3410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003411os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003412{
3413 PyObject *return_value = NULL;
3414 int fd;
3415 int _return_value;
3416
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003417 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003418 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003419 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003420 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003421 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003424 return_value = PyLong_FromLong((long)_return_value);
3425
3426exit:
3427 return return_value;
3428}
3429
3430PyDoc_STRVAR(os_dup2__doc__,
3431"dup2($module, /, fd, fd2, inheritable=True)\n"
3432"--\n"
3433"\n"
3434"Duplicate file descriptor.");
3435
3436#define OS_DUP2_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003437 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003438
3439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003440os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003441
3442static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003443os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003444{
3445 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003446 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3447 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003448 int fd;
3449 int fd2;
3450 int inheritable = 1;
3451
Victor Stinner37e4ef72016-09-09 20:00:13 -07003452 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003453 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003454 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003455 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003456 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3457
3458exit:
3459 return return_value;
3460}
3461
3462#if defined(HAVE_LOCKF)
3463
3464PyDoc_STRVAR(os_lockf__doc__,
3465"lockf($module, fd, command, length, /)\n"
3466"--\n"
3467"\n"
3468"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3469"\n"
3470" fd\n"
3471" An open file descriptor.\n"
3472" command\n"
3473" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3474" length\n"
3475" The number of bytes to lock, starting at the current position.");
3476
3477#define OS_LOCKF_METHODDEF \
3478 {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__},
3479
3480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003481os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003482
3483static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003484os_lockf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003485{
3486 PyObject *return_value = NULL;
3487 int fd;
3488 int command;
3489 Py_off_t length;
3490
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003491 if (!PyArg_ParseTuple(args, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003492 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003493 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003494 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003495 return_value = os_lockf_impl(module, fd, command, length);
3496
3497exit:
3498 return return_value;
3499}
3500
3501#endif /* defined(HAVE_LOCKF) */
3502
3503PyDoc_STRVAR(os_lseek__doc__,
3504"lseek($module, fd, position, how, /)\n"
3505"--\n"
3506"\n"
3507"Set the position of a file descriptor. Return the new position.\n"
3508"\n"
3509"Return the new cursor position in number of bytes\n"
3510"relative to the beginning of the file.");
3511
3512#define OS_LSEEK_METHODDEF \
3513 {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__},
3514
3515static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003516os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003517
3518static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003519os_lseek(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003520{
3521 PyObject *return_value = NULL;
3522 int fd;
3523 Py_off_t position;
3524 int how;
3525 Py_off_t _return_value;
3526
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003527 if (!PyArg_ParseTuple(args, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003528 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003529 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003530 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003531 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003532 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003533 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003534 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003535 return_value = PyLong_FromPy_off_t(_return_value);
3536
3537exit:
3538 return return_value;
3539}
3540
3541PyDoc_STRVAR(os_read__doc__,
3542"read($module, fd, length, /)\n"
3543"--\n"
3544"\n"
3545"Read from a file descriptor. Returns a bytes object.");
3546
3547#define OS_READ_METHODDEF \
3548 {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__},
3549
3550static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003551os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003552
3553static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003554os_read(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003555{
3556 PyObject *return_value = NULL;
3557 int fd;
3558 Py_ssize_t length;
3559
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003560 if (!PyArg_ParseTuple(args, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003561 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003562 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003563 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003564 return_value = os_read_impl(module, fd, length);
3565
3566exit:
3567 return return_value;
3568}
3569
3570#if defined(HAVE_READV)
3571
3572PyDoc_STRVAR(os_readv__doc__,
3573"readv($module, fd, buffers, /)\n"
3574"--\n"
3575"\n"
3576"Read from a file descriptor fd into an iterable of buffers.\n"
3577"\n"
3578"The buffers should be mutable buffers accepting bytes.\n"
3579"readv will transfer data into each buffer until it is full\n"
3580"and then move on to the next buffer in the sequence to hold\n"
3581"the rest of the data.\n"
3582"\n"
3583"readv returns the total number of bytes read,\n"
3584"which may be less than the total capacity of all the buffers.");
3585
3586#define OS_READV_METHODDEF \
3587 {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__},
3588
3589static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003590os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003591
3592static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003593os_readv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003594{
3595 PyObject *return_value = NULL;
3596 int fd;
3597 PyObject *buffers;
3598 Py_ssize_t _return_value;
3599
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003600 if (!PyArg_ParseTuple(args, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003601 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003605 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003606 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003607 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003608 return_value = PyLong_FromSsize_t(_return_value);
3609
3610exit:
3611 return return_value;
3612}
3613
3614#endif /* defined(HAVE_READV) */
3615
3616#if defined(HAVE_PREAD)
3617
3618PyDoc_STRVAR(os_pread__doc__,
3619"pread($module, fd, length, offset, /)\n"
3620"--\n"
3621"\n"
3622"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3623"\n"
3624"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3625"the beginning of the file. The file offset remains unchanged.");
3626
3627#define OS_PREAD_METHODDEF \
3628 {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__},
3629
3630static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003631os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003632
3633static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003634os_pread(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003635{
3636 PyObject *return_value = NULL;
3637 int fd;
3638 int length;
3639 Py_off_t offset;
3640
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003641 if (!PyArg_ParseTuple(args, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003642 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003643 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003644 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003645 return_value = os_pread_impl(module, fd, length, offset);
3646
3647exit:
3648 return return_value;
3649}
3650
3651#endif /* defined(HAVE_PREAD) */
3652
3653PyDoc_STRVAR(os_write__doc__,
3654"write($module, fd, data, /)\n"
3655"--\n"
3656"\n"
3657"Write a bytes object to a file descriptor.");
3658
3659#define OS_WRITE_METHODDEF \
3660 {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__},
3661
3662static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003663os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003664
3665static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003666os_write(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003667{
3668 PyObject *return_value = NULL;
3669 int fd;
3670 Py_buffer data = {NULL, NULL};
3671 Py_ssize_t _return_value;
3672
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003673 if (!PyArg_ParseTuple(args, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003674 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003675 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003676 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003677 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003678 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003679 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003680 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003681 return_value = PyLong_FromSsize_t(_return_value);
3682
3683exit:
3684 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003685 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003686 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003687 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003688
3689 return return_value;
3690}
3691
3692PyDoc_STRVAR(os_fstat__doc__,
3693"fstat($module, /, fd)\n"
3694"--\n"
3695"\n"
3696"Perform a stat system call on the given file descriptor.\n"
3697"\n"
3698"Like stat(), but for an open file descriptor.\n"
3699"Equivalent to os.stat(fd).");
3700
3701#define OS_FSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003702 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003703
3704static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003705os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003706
3707static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003708os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003709{
3710 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003711 static const char * const _keywords[] = {"fd", NULL};
3712 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003713 int fd;
3714
Victor Stinner37e4ef72016-09-09 20:00:13 -07003715 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003716 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003718 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003719 return_value = os_fstat_impl(module, fd);
3720
3721exit:
3722 return return_value;
3723}
3724
3725PyDoc_STRVAR(os_isatty__doc__,
3726"isatty($module, fd, /)\n"
3727"--\n"
3728"\n"
3729"Return True if the fd is connected to a terminal.\n"
3730"\n"
3731"Return True if the file descriptor is an open file descriptor\n"
3732"connected to the slave end of a terminal.");
3733
3734#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003735 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003736
3737static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003738os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003739
3740static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003741os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003742{
3743 PyObject *return_value = NULL;
3744 int fd;
3745 int _return_value;
3746
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003747 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003748 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003749 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003750 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003751 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003752 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003753 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003754 return_value = PyBool_FromLong((long)_return_value);
3755
3756exit:
3757 return return_value;
3758}
3759
3760#if defined(HAVE_PIPE)
3761
3762PyDoc_STRVAR(os_pipe__doc__,
3763"pipe($module, /)\n"
3764"--\n"
3765"\n"
3766"Create a pipe.\n"
3767"\n"
3768"Returns a tuple of two file descriptors:\n"
3769" (read_fd, write_fd)");
3770
3771#define OS_PIPE_METHODDEF \
3772 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3773
3774static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003775os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003776
3777static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003778os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003779{
3780 return os_pipe_impl(module);
3781}
3782
3783#endif /* defined(HAVE_PIPE) */
3784
3785#if defined(HAVE_PIPE2)
3786
3787PyDoc_STRVAR(os_pipe2__doc__,
3788"pipe2($module, flags, /)\n"
3789"--\n"
3790"\n"
3791"Create a pipe with flags set atomically.\n"
3792"\n"
3793"Returns a tuple of two file descriptors:\n"
3794" (read_fd, write_fd)\n"
3795"\n"
3796"flags can be constructed by ORing together one or more of these values:\n"
3797"O_NONBLOCK, O_CLOEXEC.");
3798
3799#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003800 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003801
3802static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003803os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003804
3805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003806os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003807{
3808 PyObject *return_value = NULL;
3809 int flags;
3810
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003811 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003812 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003813 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003814 return_value = os_pipe2_impl(module, flags);
3815
3816exit:
3817 return return_value;
3818}
3819
3820#endif /* defined(HAVE_PIPE2) */
3821
3822#if defined(HAVE_WRITEV)
3823
3824PyDoc_STRVAR(os_writev__doc__,
3825"writev($module, fd, buffers, /)\n"
3826"--\n"
3827"\n"
3828"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3829"\n"
3830"Returns the total number of bytes written.\n"
3831"buffers must be a sequence of bytes-like objects.");
3832
3833#define OS_WRITEV_METHODDEF \
3834 {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__},
3835
3836static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003837os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003838
3839static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003840os_writev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003841{
3842 PyObject *return_value = NULL;
3843 int fd;
3844 PyObject *buffers;
3845 Py_ssize_t _return_value;
3846
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003847 if (!PyArg_ParseTuple(args, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003848 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003849 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003850 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003851 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003852 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003853 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003854 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003855 return_value = PyLong_FromSsize_t(_return_value);
3856
3857exit:
3858 return return_value;
3859}
3860
3861#endif /* defined(HAVE_WRITEV) */
3862
3863#if defined(HAVE_PWRITE)
3864
3865PyDoc_STRVAR(os_pwrite__doc__,
3866"pwrite($module, fd, buffer, offset, /)\n"
3867"--\n"
3868"\n"
3869"Write bytes to a file descriptor starting at a particular offset.\n"
3870"\n"
3871"Write buffer to fd, starting at offset bytes from the beginning of\n"
3872"the file. Returns the number of bytes writte. Does not change the\n"
3873"current file offset.");
3874
3875#define OS_PWRITE_METHODDEF \
3876 {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__},
3877
3878static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003879os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003880
3881static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003882os_pwrite(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003883{
3884 PyObject *return_value = NULL;
3885 int fd;
3886 Py_buffer buffer = {NULL, NULL};
3887 Py_off_t offset;
3888 Py_ssize_t _return_value;
3889
Serhiy Storchaka247789c2015-04-24 00:40:51 +03003890 if (!PyArg_ParseTuple(args, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003891 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003892 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003893 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003894 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003895 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003896 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003897 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003898 return_value = PyLong_FromSsize_t(_return_value);
3899
3900exit:
3901 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003902 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003903 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003904 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003905
3906 return return_value;
3907}
3908
3909#endif /* defined(HAVE_PWRITE) */
3910
3911#if defined(HAVE_MKFIFO)
3912
3913PyDoc_STRVAR(os_mkfifo__doc__,
3914"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
3915"--\n"
3916"\n"
3917"Create a \"fifo\" (a POSIX named pipe).\n"
3918"\n"
3919"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3920" and path should be relative; path will then be relative to that directory.\n"
3921"dir_fd may not be implemented on your platform.\n"
3922" If it is unavailable, using it will raise a NotImplementedError.");
3923
3924#define OS_MKFIFO_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003925 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003926
3927static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003928os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003929
3930static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003931os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003932{
3933 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003934 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
3935 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003936 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
3937 int mode = 438;
3938 int dir_fd = DEFAULT_DIR_FD;
3939
Victor Stinner37e4ef72016-09-09 20:00:13 -07003940 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003941 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003942 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003943 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003944 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
3945
3946exit:
3947 /* Cleanup for path */
3948 path_cleanup(&path);
3949
3950 return return_value;
3951}
3952
3953#endif /* defined(HAVE_MKFIFO) */
3954
3955#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
3956
3957PyDoc_STRVAR(os_mknod__doc__,
3958"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
3959"--\n"
3960"\n"
3961"Create a node in the file system.\n"
3962"\n"
3963"Create a node in the file system (file, device special file or named pipe)\n"
3964"at path. mode specifies both the permissions to use and the\n"
3965"type of node to be created, being combined (bitwise OR) with one of\n"
3966"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
3967"device defines the newly created device special file (probably using\n"
3968"os.makedev()). Otherwise device is ignored.\n"
3969"\n"
3970"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3971" and path should be relative; path will then be relative to that directory.\n"
3972"dir_fd may not be implemented on your platform.\n"
3973" If it is unavailable, using it will raise a NotImplementedError.");
3974
3975#define OS_MKNOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003976 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003977
3978static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003979os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04003980 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003981
3982static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003983os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003984{
3985 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003986 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
3987 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003988 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
3989 int mode = 384;
3990 dev_t device = 0;
3991 int dir_fd = DEFAULT_DIR_FD;
3992
Victor Stinner37e4ef72016-09-09 20:00:13 -07003993 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003994 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003995 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003996 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003997 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
3998
3999exit:
4000 /* Cleanup for path */
4001 path_cleanup(&path);
4002
4003 return return_value;
4004}
4005
4006#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4007
4008#if defined(HAVE_DEVICE_MACROS)
4009
4010PyDoc_STRVAR(os_major__doc__,
4011"major($module, device, /)\n"
4012"--\n"
4013"\n"
4014"Extracts a device major number from a raw device number.");
4015
4016#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004017 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004018
4019static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004020os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004021
4022static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004023os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004024{
4025 PyObject *return_value = NULL;
4026 dev_t device;
4027 unsigned int _return_value;
4028
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004029 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004030 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004031 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004032 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004033 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004034 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004035 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004036 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4037
4038exit:
4039 return return_value;
4040}
4041
4042#endif /* defined(HAVE_DEVICE_MACROS) */
4043
4044#if defined(HAVE_DEVICE_MACROS)
4045
4046PyDoc_STRVAR(os_minor__doc__,
4047"minor($module, device, /)\n"
4048"--\n"
4049"\n"
4050"Extracts a device minor number from a raw device number.");
4051
4052#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004053 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004054
4055static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004056os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004057
4058static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004059os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004060{
4061 PyObject *return_value = NULL;
4062 dev_t device;
4063 unsigned int _return_value;
4064
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004065 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004066 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004067 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004068 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004069 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004070 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004071 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004072 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4073
4074exit:
4075 return return_value;
4076}
4077
4078#endif /* defined(HAVE_DEVICE_MACROS) */
4079
4080#if defined(HAVE_DEVICE_MACROS)
4081
4082PyDoc_STRVAR(os_makedev__doc__,
4083"makedev($module, major, minor, /)\n"
4084"--\n"
4085"\n"
4086"Composes a raw device number from the major and minor device numbers.");
4087
4088#define OS_MAKEDEV_METHODDEF \
4089 {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__},
4090
4091static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004092os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004093
4094static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004095os_makedev(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004096{
4097 PyObject *return_value = NULL;
4098 int major;
4099 int minor;
4100 dev_t _return_value;
4101
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004102 if (!PyArg_ParseTuple(args, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004103 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004105 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004106 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004107 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004110 return_value = _PyLong_FromDev(_return_value);
4111
4112exit:
4113 return return_value;
4114}
4115
4116#endif /* defined(HAVE_DEVICE_MACROS) */
4117
Steve Dowerf7377032015-04-12 15:44:54 -04004118#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004119
4120PyDoc_STRVAR(os_ftruncate__doc__,
4121"ftruncate($module, fd, length, /)\n"
4122"--\n"
4123"\n"
4124"Truncate a file, specified by file descriptor, to a specific length.");
4125
4126#define OS_FTRUNCATE_METHODDEF \
4127 {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__},
4128
4129static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004130os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004131
4132static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004133os_ftruncate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004134{
4135 PyObject *return_value = NULL;
4136 int fd;
4137 Py_off_t length;
4138
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004139 if (!PyArg_ParseTuple(args, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004140 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004141 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004142 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004143 return_value = os_ftruncate_impl(module, fd, length);
4144
4145exit:
4146 return return_value;
4147}
4148
Steve Dowerf7377032015-04-12 15:44:54 -04004149#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004150
Steve Dowerf7377032015-04-12 15:44:54 -04004151#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004152
4153PyDoc_STRVAR(os_truncate__doc__,
4154"truncate($module, /, path, length)\n"
4155"--\n"
4156"\n"
4157"Truncate a file, specified by path, to a specific length.\n"
4158"\n"
4159"On some platforms, path may also be specified as an open file descriptor.\n"
4160" If this functionality is unavailable, using it raises an exception.");
4161
4162#define OS_TRUNCATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004163 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004164
4165static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004166os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004167
4168static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004169os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004170{
4171 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004172 static const char * const _keywords[] = {"path", "length", NULL};
4173 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004174 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4175 Py_off_t length;
4176
Victor Stinner37e4ef72016-09-09 20:00:13 -07004177 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004178 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004179 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004180 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004181 return_value = os_truncate_impl(module, &path, length);
4182
4183exit:
4184 /* Cleanup for path */
4185 path_cleanup(&path);
4186
4187 return return_value;
4188}
4189
Steve Dowerf7377032015-04-12 15:44:54 -04004190#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004191
4192#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4193
4194PyDoc_STRVAR(os_posix_fallocate__doc__,
4195"posix_fallocate($module, fd, offset, length, /)\n"
4196"--\n"
4197"\n"
4198"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4199"\n"
4200"Ensure that the file specified by fd encompasses a range of bytes\n"
4201"starting at offset bytes from the beginning and continuing for length bytes.");
4202
4203#define OS_POSIX_FALLOCATE_METHODDEF \
4204 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__},
4205
4206static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004207os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004208 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004209
4210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004211os_posix_fallocate(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004212{
4213 PyObject *return_value = NULL;
4214 int fd;
4215 Py_off_t offset;
4216 Py_off_t length;
4217
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004218 if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004219 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004220 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004221 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004222 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4223
4224exit:
4225 return return_value;
4226}
4227
4228#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4229
4230#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4231
4232PyDoc_STRVAR(os_posix_fadvise__doc__,
4233"posix_fadvise($module, fd, offset, length, advice, /)\n"
4234"--\n"
4235"\n"
4236"Announce an intention to access data in a specific pattern.\n"
4237"\n"
4238"Announce an intention to access data in a specific pattern, thus allowing\n"
4239"the kernel to make optimizations.\n"
4240"The advice applies to the region of the file specified by fd starting at\n"
4241"offset and continuing for length bytes.\n"
4242"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4243"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4244"POSIX_FADV_DONTNEED.");
4245
4246#define OS_POSIX_FADVISE_METHODDEF \
4247 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__},
4248
4249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004250os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004251 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004252
4253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004254os_posix_fadvise(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004255{
4256 PyObject *return_value = NULL;
4257 int fd;
4258 Py_off_t offset;
4259 Py_off_t length;
4260 int advice;
4261
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004262 if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004263 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004264 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004265 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004266 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4267
4268exit:
4269 return return_value;
4270}
4271
4272#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4273
4274#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4275
4276PyDoc_STRVAR(os_putenv__doc__,
4277"putenv($module, name, value, /)\n"
4278"--\n"
4279"\n"
4280"Change or add an environment variable.");
4281
4282#define OS_PUTENV_METHODDEF \
4283 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4284
4285static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004286os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004287
4288static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004289os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004290{
4291 PyObject *return_value = NULL;
4292 PyObject *name;
4293 PyObject *value;
4294
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004295 if (!PyArg_ParseTuple(args, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004296 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004297 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004298 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004299 return_value = os_putenv_impl(module, name, value);
4300
4301exit:
4302 return return_value;
4303}
4304
4305#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4306
4307#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4308
4309PyDoc_STRVAR(os_putenv__doc__,
4310"putenv($module, name, value, /)\n"
4311"--\n"
4312"\n"
4313"Change or add an environment variable.");
4314
4315#define OS_PUTENV_METHODDEF \
4316 {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__},
4317
4318static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004319os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004320
4321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004322os_putenv(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004323{
4324 PyObject *return_value = NULL;
4325 PyObject *name = NULL;
4326 PyObject *value = NULL;
4327
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004328 if (!PyArg_ParseTuple(args, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004329 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004332 return_value = os_putenv_impl(module, name, value);
4333
4334exit:
4335 /* Cleanup for name */
4336 Py_XDECREF(name);
4337 /* Cleanup for value */
4338 Py_XDECREF(value);
4339
4340 return return_value;
4341}
4342
4343#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4344
4345#if defined(HAVE_UNSETENV)
4346
4347PyDoc_STRVAR(os_unsetenv__doc__,
4348"unsetenv($module, name, /)\n"
4349"--\n"
4350"\n"
4351"Delete an environment variable.");
4352
4353#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004354 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004355
4356static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004357os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004358
4359static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004360os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004361{
4362 PyObject *return_value = NULL;
4363 PyObject *name = NULL;
4364
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004365 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004366 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004367 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004368 return_value = os_unsetenv_impl(module, name);
4369
4370exit:
4371 /* Cleanup for name */
4372 Py_XDECREF(name);
4373
4374 return return_value;
4375}
4376
4377#endif /* defined(HAVE_UNSETENV) */
4378
4379PyDoc_STRVAR(os_strerror__doc__,
4380"strerror($module, code, /)\n"
4381"--\n"
4382"\n"
4383"Translate an error code to a message string.");
4384
4385#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004386 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004387
4388static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004389os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004390
4391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004392os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004393{
4394 PyObject *return_value = NULL;
4395 int code;
4396
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004397 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004400 return_value = os_strerror_impl(module, code);
4401
4402exit:
4403 return return_value;
4404}
4405
4406#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4407
4408PyDoc_STRVAR(os_WCOREDUMP__doc__,
4409"WCOREDUMP($module, status, /)\n"
4410"--\n"
4411"\n"
4412"Return True if the process returning status was dumped to a core file.");
4413
4414#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004415 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004416
4417static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004418os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004419
4420static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004421os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004422{
4423 PyObject *return_value = NULL;
4424 int status;
4425 int _return_value;
4426
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004427 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004428 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004429 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004430 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004431 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004432 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004433 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004434 return_value = PyBool_FromLong((long)_return_value);
4435
4436exit:
4437 return return_value;
4438}
4439
4440#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4441
4442#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4443
4444PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4445"WIFCONTINUED($module, /, status)\n"
4446"--\n"
4447"\n"
4448"Return True if a particular process was continued from a job control stop.\n"
4449"\n"
4450"Return True if the process returning status was continued from a\n"
4451"job control stop.");
4452
4453#define OS_WIFCONTINUED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004454 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004455
4456static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004457os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004458
4459static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004460os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461{
4462 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004463 static const char * const _keywords[] = {"status", NULL};
4464 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004465 int status;
4466 int _return_value;
4467
Victor Stinner37e4ef72016-09-09 20:00:13 -07004468 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004469 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004470 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004471 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004472 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004473 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004474 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004475 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004476 return_value = PyBool_FromLong((long)_return_value);
4477
4478exit:
4479 return return_value;
4480}
4481
4482#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4483
4484#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4485
4486PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4487"WIFSTOPPED($module, /, status)\n"
4488"--\n"
4489"\n"
4490"Return True if the process returning status was stopped.");
4491
4492#define OS_WIFSTOPPED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004493 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004494
4495static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004496os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004497
4498static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004499os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004500{
4501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004502 static const char * const _keywords[] = {"status", NULL};
4503 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004504 int status;
4505 int _return_value;
4506
Victor Stinner37e4ef72016-09-09 20:00:13 -07004507 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004508 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004511 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004512 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004513 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004514 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004515 return_value = PyBool_FromLong((long)_return_value);
4516
4517exit:
4518 return return_value;
4519}
4520
4521#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4522
4523#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4524
4525PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4526"WIFSIGNALED($module, /, status)\n"
4527"--\n"
4528"\n"
4529"Return True if the process returning status was terminated by a signal.");
4530
4531#define OS_WIFSIGNALED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004532 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004533
4534static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004535os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004536
4537static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004538os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004539{
4540 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004541 static const char * const _keywords[] = {"status", NULL};
4542 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004543 int status;
4544 int _return_value;
4545
Victor Stinner37e4ef72016-09-09 20:00:13 -07004546 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004547 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004548 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004549 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004550 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004551 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004552 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004553 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004554 return_value = PyBool_FromLong((long)_return_value);
4555
4556exit:
4557 return return_value;
4558}
4559
4560#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4561
4562#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4563
4564PyDoc_STRVAR(os_WIFEXITED__doc__,
4565"WIFEXITED($module, /, status)\n"
4566"--\n"
4567"\n"
4568"Return True if the process returning status exited via the exit() system call.");
4569
4570#define OS_WIFEXITED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004571 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004572
4573static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004574os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004575
4576static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004577os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004578{
4579 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004580 static const char * const _keywords[] = {"status", NULL};
4581 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004582 int status;
4583 int _return_value;
4584
Victor Stinner37e4ef72016-09-09 20:00:13 -07004585 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004586 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004587 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004588 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004589 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004590 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004591 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004592 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004593 return_value = PyBool_FromLong((long)_return_value);
4594
4595exit:
4596 return return_value;
4597}
4598
4599#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4600
4601#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4602
4603PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4604"WEXITSTATUS($module, /, status)\n"
4605"--\n"
4606"\n"
4607"Return the process return code from status.");
4608
4609#define OS_WEXITSTATUS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004610 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004611
4612static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004613os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004614
4615static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004616os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004617{
4618 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004619 static const char * const _keywords[] = {"status", NULL};
4620 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004621 int status;
4622 int _return_value;
4623
Victor Stinner37e4ef72016-09-09 20:00:13 -07004624 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004625 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004626 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004627 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004628 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004629 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004630 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004631 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004632 return_value = PyLong_FromLong((long)_return_value);
4633
4634exit:
4635 return return_value;
4636}
4637
4638#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4639
4640#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4641
4642PyDoc_STRVAR(os_WTERMSIG__doc__,
4643"WTERMSIG($module, /, status)\n"
4644"--\n"
4645"\n"
4646"Return the signal that terminated the process that provided the status value.");
4647
4648#define OS_WTERMSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004649 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004650
4651static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004652os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004653
4654static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004655os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004656{
4657 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004658 static const char * const _keywords[] = {"status", NULL};
4659 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004660 int status;
4661 int _return_value;
4662
Victor Stinner37e4ef72016-09-09 20:00:13 -07004663 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004664 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004665 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004666 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004667 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004668 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004669 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004670 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004671 return_value = PyLong_FromLong((long)_return_value);
4672
4673exit:
4674 return return_value;
4675}
4676
4677#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4678
4679#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4680
4681PyDoc_STRVAR(os_WSTOPSIG__doc__,
4682"WSTOPSIG($module, /, status)\n"
4683"--\n"
4684"\n"
4685"Return the signal that stopped the process that provided the status value.");
4686
4687#define OS_WSTOPSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004688 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004689
4690static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004691os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004692
4693static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004694os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004695{
4696 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004697 static const char * const _keywords[] = {"status", NULL};
4698 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004699 int status;
4700 int _return_value;
4701
Victor Stinner37e4ef72016-09-09 20:00:13 -07004702 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004703 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004704 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004705 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004707 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004709 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004710 return_value = PyLong_FromLong((long)_return_value);
4711
4712exit:
4713 return return_value;
4714}
4715
4716#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4717
4718#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4719
4720PyDoc_STRVAR(os_fstatvfs__doc__,
4721"fstatvfs($module, fd, /)\n"
4722"--\n"
4723"\n"
4724"Perform an fstatvfs system call on the given fd.\n"
4725"\n"
4726"Equivalent to statvfs(fd).");
4727
4728#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004729 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004730
4731static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004732os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004733
4734static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004735os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004736{
4737 PyObject *return_value = NULL;
4738 int fd;
4739
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004740 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004741 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004742 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004743 return_value = os_fstatvfs_impl(module, fd);
4744
4745exit:
4746 return return_value;
4747}
4748
4749#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4750
4751#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4752
4753PyDoc_STRVAR(os_statvfs__doc__,
4754"statvfs($module, /, path)\n"
4755"--\n"
4756"\n"
4757"Perform a statvfs system call on the given path.\n"
4758"\n"
4759"path may always be specified as a string.\n"
4760"On some platforms, path may also be specified as an open file descriptor.\n"
4761" If this functionality is unavailable, using it raises an exception.");
4762
4763#define OS_STATVFS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004764 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004765
4766static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004767os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004768
4769static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004770os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004771{
4772 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004773 static const char * const _keywords[] = {"path", NULL};
4774 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004775 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4776
Victor Stinner37e4ef72016-09-09 20:00:13 -07004777 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004778 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004779 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004780 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004781 return_value = os_statvfs_impl(module, &path);
4782
4783exit:
4784 /* Cleanup for path */
4785 path_cleanup(&path);
4786
4787 return return_value;
4788}
4789
4790#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4791
4792#if defined(MS_WINDOWS)
4793
4794PyDoc_STRVAR(os__getdiskusage__doc__,
4795"_getdiskusage($module, /, path)\n"
4796"--\n"
4797"\n"
4798"Return disk usage statistics about the given path as a (total, free) tuple.");
4799
4800#define OS__GETDISKUSAGE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004801 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004802
4803static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004804os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004805
4806static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004807os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004808{
4809 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004810 static const char * const _keywords[] = {"path", NULL};
4811 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004812 Py_UNICODE *path;
4813
Victor Stinner37e4ef72016-09-09 20:00:13 -07004814 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004815 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004816 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004817 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004818 return_value = os__getdiskusage_impl(module, path);
4819
4820exit:
4821 return return_value;
4822}
4823
4824#endif /* defined(MS_WINDOWS) */
4825
4826#if defined(HAVE_FPATHCONF)
4827
4828PyDoc_STRVAR(os_fpathconf__doc__,
4829"fpathconf($module, fd, name, /)\n"
4830"--\n"
4831"\n"
4832"Return the configuration limit name for the file descriptor fd.\n"
4833"\n"
4834"If there is no limit, return -1.");
4835
4836#define OS_FPATHCONF_METHODDEF \
4837 {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__},
4838
4839static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004840os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004841
4842static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004843os_fpathconf(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004844{
4845 PyObject *return_value = NULL;
4846 int fd;
4847 int name;
4848 long _return_value;
4849
Serhiy Storchaka247789c2015-04-24 00:40:51 +03004850 if (!PyArg_ParseTuple(args, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004851 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004852 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004853 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004854 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004855 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004856 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004857 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004858 return_value = PyLong_FromLong(_return_value);
4859
4860exit:
4861 return return_value;
4862}
4863
4864#endif /* defined(HAVE_FPATHCONF) */
4865
4866#if defined(HAVE_PATHCONF)
4867
4868PyDoc_STRVAR(os_pathconf__doc__,
4869"pathconf($module, /, path, name)\n"
4870"--\n"
4871"\n"
4872"Return the configuration limit name for the file or directory path.\n"
4873"\n"
4874"If there is no limit, return -1.\n"
4875"On some platforms, path may also be specified as an open file descriptor.\n"
4876" If this functionality is unavailable, using it raises an exception.");
4877
4878#define OS_PATHCONF_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004879 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004880
4881static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004882os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004883
4884static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004885os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004886{
4887 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004888 static const char * const _keywords[] = {"path", "name", NULL};
4889 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004890 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
4891 int name;
4892 long _return_value;
4893
Victor Stinner37e4ef72016-09-09 20:00:13 -07004894 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004895 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004896 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004897 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004898 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004899 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004900 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004901 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004902 return_value = PyLong_FromLong(_return_value);
4903
4904exit:
4905 /* Cleanup for path */
4906 path_cleanup(&path);
4907
4908 return return_value;
4909}
4910
4911#endif /* defined(HAVE_PATHCONF) */
4912
4913#if defined(HAVE_CONFSTR)
4914
4915PyDoc_STRVAR(os_confstr__doc__,
4916"confstr($module, name, /)\n"
4917"--\n"
4918"\n"
4919"Return a string-valued system configuration variable.");
4920
4921#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004922 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004923
4924static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004925os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004926
4927static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004928os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004929{
4930 PyObject *return_value = NULL;
4931 int name;
4932
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004933 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004934 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004935 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004936 return_value = os_confstr_impl(module, name);
4937
4938exit:
4939 return return_value;
4940}
4941
4942#endif /* defined(HAVE_CONFSTR) */
4943
4944#if defined(HAVE_SYSCONF)
4945
4946PyDoc_STRVAR(os_sysconf__doc__,
4947"sysconf($module, name, /)\n"
4948"--\n"
4949"\n"
4950"Return an integer-valued system configuration variable.");
4951
4952#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004953 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004954
4955static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004956os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004957
4958static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004959os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004960{
4961 PyObject *return_value = NULL;
4962 int name;
4963 long _return_value;
4964
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004965 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004966 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004967 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004968 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004969 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004970 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004971 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004972 return_value = PyLong_FromLong(_return_value);
4973
4974exit:
4975 return return_value;
4976}
4977
4978#endif /* defined(HAVE_SYSCONF) */
4979
4980PyDoc_STRVAR(os_abort__doc__,
4981"abort($module, /)\n"
4982"--\n"
4983"\n"
4984"Abort the interpreter immediately.\n"
4985"\n"
4986"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
4987"on the hosting operating system. This function never returns.");
4988
4989#define OS_ABORT_METHODDEF \
4990 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
4991
4992static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004993os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004994
4995static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004996os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004997{
4998 return os_abort_impl(module);
4999}
5000
Steve Dowercc16be82016-09-08 10:35:16 -07005001#if defined(MS_WINDOWS)
5002
5003PyDoc_STRVAR(os_startfile__doc__,
5004"startfile($module, /, filepath, operation=None)\n"
5005"--\n"
5006"\n"
5007"startfile(filepath [, operation])\n"
5008"\n"
5009"Start a file with its associated application.\n"
5010"\n"
5011"When \"operation\" is not specified or \"open\", this acts like\n"
5012"double-clicking the file in Explorer, or giving the file name as an\n"
5013"argument to the DOS \"start\" command: the file is opened with whatever\n"
5014"application (if any) its extension is associated.\n"
5015"When another \"operation\" is given, it specifies what should be done with\n"
5016"the file. A typical operation is \"print\".\n"
5017"\n"
5018"startfile returns as soon as the associated application is launched.\n"
5019"There is no option to wait for the application to close, and no way\n"
5020"to retrieve the application\'s exit status.\n"
5021"\n"
5022"The filepath is relative to the current directory. If you want to use\n"
5023"an absolute path, make sure the first character is not a slash (\"/\");\n"
5024"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5025
5026#define OS_STARTFILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005027 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005028
5029static PyObject *
5030os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5031
5032static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005033os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005034{
5035 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005036 static const char * const _keywords[] = {"filepath", "operation", NULL};
5037 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005038 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5039 Py_UNICODE *operation = NULL;
5040
Victor Stinner37e4ef72016-09-09 20:00:13 -07005041 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005042 path_converter, &filepath, &operation)) {
5043 goto exit;
5044 }
5045 return_value = os_startfile_impl(module, &filepath, operation);
5046
5047exit:
5048 /* Cleanup for filepath */
5049 path_cleanup(&filepath);
5050
5051 return return_value;
5052}
5053
5054#endif /* defined(MS_WINDOWS) */
5055
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005056#if defined(HAVE_GETLOADAVG)
5057
5058PyDoc_STRVAR(os_getloadavg__doc__,
5059"getloadavg($module, /)\n"
5060"--\n"
5061"\n"
5062"Return average recent system load information.\n"
5063"\n"
5064"Return the number of processes in the system run queue averaged over\n"
5065"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5066"Raises OSError if the load average was unobtainable.");
5067
5068#define OS_GETLOADAVG_METHODDEF \
5069 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5070
5071static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005072os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005073
5074static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005075os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005076{
5077 return os_getloadavg_impl(module);
5078}
5079
5080#endif /* defined(HAVE_GETLOADAVG) */
5081
5082PyDoc_STRVAR(os_device_encoding__doc__,
5083"device_encoding($module, /, fd)\n"
5084"--\n"
5085"\n"
5086"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5087"\n"
5088"The file descriptor must be attached to a terminal.\n"
5089"If the device is not a terminal, return None.");
5090
5091#define OS_DEVICE_ENCODING_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005092 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005093
5094static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005095os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005096
5097static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005098os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005099{
5100 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005101 static const char * const _keywords[] = {"fd", NULL};
5102 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005103 int fd;
5104
Victor Stinner37e4ef72016-09-09 20:00:13 -07005105 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005106 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005107 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005108 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005109 return_value = os_device_encoding_impl(module, fd);
5110
5111exit:
5112 return return_value;
5113}
5114
5115#if defined(HAVE_SETRESUID)
5116
5117PyDoc_STRVAR(os_setresuid__doc__,
5118"setresuid($module, ruid, euid, suid, /)\n"
5119"--\n"
5120"\n"
5121"Set the current process\'s real, effective, and saved user ids.");
5122
5123#define OS_SETRESUID_METHODDEF \
5124 {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__},
5125
5126static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005127os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005128
5129static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005130os_setresuid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005131{
5132 PyObject *return_value = NULL;
5133 uid_t ruid;
5134 uid_t euid;
5135 uid_t suid;
5136
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005137 if (!PyArg_ParseTuple(args, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005138 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005139 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005140 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005141 return_value = os_setresuid_impl(module, ruid, euid, suid);
5142
5143exit:
5144 return return_value;
5145}
5146
5147#endif /* defined(HAVE_SETRESUID) */
5148
5149#if defined(HAVE_SETRESGID)
5150
5151PyDoc_STRVAR(os_setresgid__doc__,
5152"setresgid($module, rgid, egid, sgid, /)\n"
5153"--\n"
5154"\n"
5155"Set the current process\'s real, effective, and saved group ids.");
5156
5157#define OS_SETRESGID_METHODDEF \
5158 {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__},
5159
5160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005161os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005162
5163static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005164os_setresgid(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005165{
5166 PyObject *return_value = NULL;
5167 gid_t rgid;
5168 gid_t egid;
5169 gid_t sgid;
5170
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005171 if (!PyArg_ParseTuple(args, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005172 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005173 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005174 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5176
5177exit:
5178 return return_value;
5179}
5180
5181#endif /* defined(HAVE_SETRESGID) */
5182
5183#if defined(HAVE_GETRESUID)
5184
5185PyDoc_STRVAR(os_getresuid__doc__,
5186"getresuid($module, /)\n"
5187"--\n"
5188"\n"
5189"Return a tuple of the current process\'s real, effective, and saved user ids.");
5190
5191#define OS_GETRESUID_METHODDEF \
5192 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5193
5194static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005195os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005196
5197static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005198os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005199{
5200 return os_getresuid_impl(module);
5201}
5202
5203#endif /* defined(HAVE_GETRESUID) */
5204
5205#if defined(HAVE_GETRESGID)
5206
5207PyDoc_STRVAR(os_getresgid__doc__,
5208"getresgid($module, /)\n"
5209"--\n"
5210"\n"
5211"Return a tuple of the current process\'s real, effective, and saved group ids.");
5212
5213#define OS_GETRESGID_METHODDEF \
5214 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5215
5216static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005217os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005218
5219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005220os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005221{
5222 return os_getresgid_impl(module);
5223}
5224
5225#endif /* defined(HAVE_GETRESGID) */
5226
5227#if defined(USE_XATTRS)
5228
5229PyDoc_STRVAR(os_getxattr__doc__,
5230"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5231"--\n"
5232"\n"
5233"Return the value of extended attribute attribute on path.\n"
5234"\n"
5235"path may be either a string or an open file descriptor.\n"
5236"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5237" link, getxattr will examine the symbolic link itself instead of the file\n"
5238" the link points to.");
5239
5240#define OS_GETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005241 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005242
5243static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005244os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005245 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005246
5247static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005248os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005249{
5250 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005251 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5252 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005253 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5254 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5255 int follow_symlinks = 1;
5256
Victor Stinner37e4ef72016-09-09 20:00:13 -07005257 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005258 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005259 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005260 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005261 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5262
5263exit:
5264 /* Cleanup for path */
5265 path_cleanup(&path);
5266 /* Cleanup for attribute */
5267 path_cleanup(&attribute);
5268
5269 return return_value;
5270}
5271
5272#endif /* defined(USE_XATTRS) */
5273
5274#if defined(USE_XATTRS)
5275
5276PyDoc_STRVAR(os_setxattr__doc__,
5277"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5278" follow_symlinks=True)\n"
5279"--\n"
5280"\n"
5281"Set extended attribute attribute on path to value.\n"
5282"\n"
5283"path may be either a string or an open file descriptor.\n"
5284"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5285" link, setxattr will modify the symbolic link itself instead of the file\n"
5286" the link points to.");
5287
5288#define OS_SETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005289 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005290
5291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005292os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005293 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005294
5295static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005296os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005297{
5298 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005299 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5300 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005301 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5302 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5303 Py_buffer value = {NULL, NULL};
5304 int flags = 0;
5305 int follow_symlinks = 1;
5306
Victor Stinner37e4ef72016-09-09 20:00:13 -07005307 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005308 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005309 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005310 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005311 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5312
5313exit:
5314 /* Cleanup for path */
5315 path_cleanup(&path);
5316 /* Cleanup for attribute */
5317 path_cleanup(&attribute);
5318 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005319 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005320 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005321 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005322
5323 return return_value;
5324}
5325
5326#endif /* defined(USE_XATTRS) */
5327
5328#if defined(USE_XATTRS)
5329
5330PyDoc_STRVAR(os_removexattr__doc__,
5331"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5332"--\n"
5333"\n"
5334"Remove extended attribute attribute on path.\n"
5335"\n"
5336"path may be either a string or an open file descriptor.\n"
5337"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5338" link, removexattr will modify the symbolic link itself instead of the file\n"
5339" the link points to.");
5340
5341#define OS_REMOVEXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005342 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005343
5344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005345os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005346 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005347
5348static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005349os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005350{
5351 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005352 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5353 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005354 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5355 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5356 int follow_symlinks = 1;
5357
Victor Stinner37e4ef72016-09-09 20:00:13 -07005358 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005359 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005362 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5363
5364exit:
5365 /* Cleanup for path */
5366 path_cleanup(&path);
5367 /* Cleanup for attribute */
5368 path_cleanup(&attribute);
5369
5370 return return_value;
5371}
5372
5373#endif /* defined(USE_XATTRS) */
5374
5375#if defined(USE_XATTRS)
5376
5377PyDoc_STRVAR(os_listxattr__doc__,
5378"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5379"--\n"
5380"\n"
5381"Return a list of extended attributes on path.\n"
5382"\n"
5383"path may be either None, a string, or an open file descriptor.\n"
5384"if path is None, listxattr will examine the current directory.\n"
5385"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5386" link, listxattr will examine the symbolic link itself instead of the file\n"
5387" the link points to.");
5388
5389#define OS_LISTXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005390 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005391
5392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005393os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005394
5395static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005396os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005397{
5398 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005399 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5400 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005401 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5402 int follow_symlinks = 1;
5403
Victor Stinner37e4ef72016-09-09 20:00:13 -07005404 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005405 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005406 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005407 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005408 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5409
5410exit:
5411 /* Cleanup for path */
5412 path_cleanup(&path);
5413
5414 return return_value;
5415}
5416
5417#endif /* defined(USE_XATTRS) */
5418
5419PyDoc_STRVAR(os_urandom__doc__,
5420"urandom($module, size, /)\n"
5421"--\n"
5422"\n"
5423"Return a bytes object containing random bytes suitable for cryptographic use.");
5424
5425#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005426 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005427
5428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005429os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005430
5431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005432os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005433{
5434 PyObject *return_value = NULL;
5435 Py_ssize_t size;
5436
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005437 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005438 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005440 return_value = os_urandom_impl(module, size);
5441
5442exit:
5443 return return_value;
5444}
5445
5446PyDoc_STRVAR(os_cpu_count__doc__,
5447"cpu_count($module, /)\n"
5448"--\n"
5449"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005450"Return the number of CPUs in the system; return None if indeterminable.\n"
5451"\n"
5452"This number is not equivalent to the number of CPUs the current process can\n"
5453"use. The number of usable CPUs can be obtained with\n"
5454"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005455
5456#define OS_CPU_COUNT_METHODDEF \
5457 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5458
5459static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005460os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005461
5462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005463os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005464{
5465 return os_cpu_count_impl(module);
5466}
5467
5468PyDoc_STRVAR(os_get_inheritable__doc__,
5469"get_inheritable($module, fd, /)\n"
5470"--\n"
5471"\n"
5472"Get the close-on-exe flag of the specified file descriptor.");
5473
5474#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005475 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005476
5477static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005478os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005479
5480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005481os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005482{
5483 PyObject *return_value = NULL;
5484 int fd;
5485 int _return_value;
5486
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005487 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005488 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005489 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005490 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005491 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005492 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005493 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005494 return_value = PyBool_FromLong((long)_return_value);
5495
5496exit:
5497 return return_value;
5498}
5499
5500PyDoc_STRVAR(os_set_inheritable__doc__,
5501"set_inheritable($module, fd, inheritable, /)\n"
5502"--\n"
5503"\n"
5504"Set the inheritable flag of the specified file descriptor.");
5505
5506#define OS_SET_INHERITABLE_METHODDEF \
5507 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__},
5508
5509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005510os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005511
5512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005513os_set_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005514{
5515 PyObject *return_value = NULL;
5516 int fd;
5517 int inheritable;
5518
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005519 if (!PyArg_ParseTuple(args, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005520 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005521 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005522 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005523 return_value = os_set_inheritable_impl(module, fd, inheritable);
5524
5525exit:
5526 return return_value;
5527}
5528
5529#if defined(MS_WINDOWS)
5530
5531PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5532"get_handle_inheritable($module, handle, /)\n"
5533"--\n"
5534"\n"
5535"Get the close-on-exe flag of the specified file descriptor.");
5536
5537#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005538 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005539
5540static int
Victor Stinner581139c2016-09-06 15:54:20 -07005541os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542
5543static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005544os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005545{
5546 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005547 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005548 int _return_value;
5549
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005550 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005551 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005552 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005553 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005554 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005555 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005556 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005557 return_value = PyBool_FromLong((long)_return_value);
5558
5559exit:
5560 return return_value;
5561}
5562
5563#endif /* defined(MS_WINDOWS) */
5564
5565#if defined(MS_WINDOWS)
5566
5567PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5568"set_handle_inheritable($module, handle, inheritable, /)\n"
5569"--\n"
5570"\n"
5571"Set the inheritable flag of the specified handle.");
5572
5573#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
5574 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__},
5575
5576static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005577os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005578 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005579
5580static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005581os_set_handle_inheritable(PyObject *module, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005582{
5583 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005584 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005585 int inheritable;
5586
Serhiy Storchaka247789c2015-04-24 00:40:51 +03005587 if (!PyArg_ParseTuple(args, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005588 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005589 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005590 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005591 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5592
5593exit:
5594 return return_value;
5595}
5596
5597#endif /* defined(MS_WINDOWS) */
5598
Ethan Furman410ef8e2016-06-04 12:06:26 -07005599PyDoc_STRVAR(os_fspath__doc__,
5600"fspath($module, /, path)\n"
5601"--\n"
5602"\n"
5603"Return the file system path representation of the object.\n"
5604"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005605"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5606"object defines __fspath__(), then return the result of that method. All other\n"
5607"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005608
5609#define OS_FSPATH_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005610 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005611
5612static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005613os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005614
5615static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005616os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005617{
5618 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005619 static const char * const _keywords[] = {"path", NULL};
5620 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005621 PyObject *path;
5622
Victor Stinner37e4ef72016-09-09 20:00:13 -07005623 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005624 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005625 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005626 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005627 return_value = os_fspath_impl(module, path);
5628
5629exit:
5630 return return_value;
5631}
5632
Victor Stinner9b1f4742016-09-06 16:18:52 -07005633#if defined(HAVE_GETRANDOM_SYSCALL)
5634
5635PyDoc_STRVAR(os_getrandom__doc__,
5636"getrandom($module, /, size, flags=0)\n"
5637"--\n"
5638"\n"
5639"Obtain a series of random bytes.");
5640
5641#define OS_GETRANDOM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005642 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07005643
5644static PyObject *
5645os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
5646
5647static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005648os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07005649{
5650 PyObject *return_value = NULL;
5651 static const char * const _keywords[] = {"size", "flags", NULL};
5652 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
5653 Py_ssize_t size;
5654 int flags = 0;
5655
Victor Stinner37e4ef72016-09-09 20:00:13 -07005656 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07005657 &size, &flags)) {
5658 goto exit;
5659 }
5660 return_value = os_getrandom_impl(module, size, flags);
5661
5662exit:
5663 return return_value;
5664}
5665
5666#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
5667
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005668#ifndef OS_TTYNAME_METHODDEF
5669 #define OS_TTYNAME_METHODDEF
5670#endif /* !defined(OS_TTYNAME_METHODDEF) */
5671
5672#ifndef OS_CTERMID_METHODDEF
5673 #define OS_CTERMID_METHODDEF
5674#endif /* !defined(OS_CTERMID_METHODDEF) */
5675
5676#ifndef OS_FCHDIR_METHODDEF
5677 #define OS_FCHDIR_METHODDEF
5678#endif /* !defined(OS_FCHDIR_METHODDEF) */
5679
5680#ifndef OS_FCHMOD_METHODDEF
5681 #define OS_FCHMOD_METHODDEF
5682#endif /* !defined(OS_FCHMOD_METHODDEF) */
5683
5684#ifndef OS_LCHMOD_METHODDEF
5685 #define OS_LCHMOD_METHODDEF
5686#endif /* !defined(OS_LCHMOD_METHODDEF) */
5687
5688#ifndef OS_CHFLAGS_METHODDEF
5689 #define OS_CHFLAGS_METHODDEF
5690#endif /* !defined(OS_CHFLAGS_METHODDEF) */
5691
5692#ifndef OS_LCHFLAGS_METHODDEF
5693 #define OS_LCHFLAGS_METHODDEF
5694#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
5695
5696#ifndef OS_CHROOT_METHODDEF
5697 #define OS_CHROOT_METHODDEF
5698#endif /* !defined(OS_CHROOT_METHODDEF) */
5699
5700#ifndef OS_FSYNC_METHODDEF
5701 #define OS_FSYNC_METHODDEF
5702#endif /* !defined(OS_FSYNC_METHODDEF) */
5703
5704#ifndef OS_SYNC_METHODDEF
5705 #define OS_SYNC_METHODDEF
5706#endif /* !defined(OS_SYNC_METHODDEF) */
5707
5708#ifndef OS_FDATASYNC_METHODDEF
5709 #define OS_FDATASYNC_METHODDEF
5710#endif /* !defined(OS_FDATASYNC_METHODDEF) */
5711
5712#ifndef OS_CHOWN_METHODDEF
5713 #define OS_CHOWN_METHODDEF
5714#endif /* !defined(OS_CHOWN_METHODDEF) */
5715
5716#ifndef OS_FCHOWN_METHODDEF
5717 #define OS_FCHOWN_METHODDEF
5718#endif /* !defined(OS_FCHOWN_METHODDEF) */
5719
5720#ifndef OS_LCHOWN_METHODDEF
5721 #define OS_LCHOWN_METHODDEF
5722#endif /* !defined(OS_LCHOWN_METHODDEF) */
5723
5724#ifndef OS_LINK_METHODDEF
5725 #define OS_LINK_METHODDEF
5726#endif /* !defined(OS_LINK_METHODDEF) */
5727
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005728#ifndef OS__GETFULLPATHNAME_METHODDEF
5729 #define OS__GETFULLPATHNAME_METHODDEF
5730#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
5731
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005732#ifndef OS__GETFINALPATHNAME_METHODDEF
5733 #define OS__GETFINALPATHNAME_METHODDEF
5734#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
5735
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03005736#ifndef OS__ISDIR_METHODDEF
5737 #define OS__ISDIR_METHODDEF
5738#endif /* !defined(OS__ISDIR_METHODDEF) */
5739
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005740#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
5741 #define OS__GETVOLUMEPATHNAME_METHODDEF
5742#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
5743
5744#ifndef OS_NICE_METHODDEF
5745 #define OS_NICE_METHODDEF
5746#endif /* !defined(OS_NICE_METHODDEF) */
5747
5748#ifndef OS_GETPRIORITY_METHODDEF
5749 #define OS_GETPRIORITY_METHODDEF
5750#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
5751
5752#ifndef OS_SETPRIORITY_METHODDEF
5753 #define OS_SETPRIORITY_METHODDEF
5754#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
5755
5756#ifndef OS_SYSTEM_METHODDEF
5757 #define OS_SYSTEM_METHODDEF
5758#endif /* !defined(OS_SYSTEM_METHODDEF) */
5759
5760#ifndef OS_UNAME_METHODDEF
5761 #define OS_UNAME_METHODDEF
5762#endif /* !defined(OS_UNAME_METHODDEF) */
5763
5764#ifndef OS_EXECV_METHODDEF
5765 #define OS_EXECV_METHODDEF
5766#endif /* !defined(OS_EXECV_METHODDEF) */
5767
5768#ifndef OS_EXECVE_METHODDEF
5769 #define OS_EXECVE_METHODDEF
5770#endif /* !defined(OS_EXECVE_METHODDEF) */
5771
5772#ifndef OS_SPAWNV_METHODDEF
5773 #define OS_SPAWNV_METHODDEF
5774#endif /* !defined(OS_SPAWNV_METHODDEF) */
5775
5776#ifndef OS_SPAWNVE_METHODDEF
5777 #define OS_SPAWNVE_METHODDEF
5778#endif /* !defined(OS_SPAWNVE_METHODDEF) */
5779
5780#ifndef OS_FORK1_METHODDEF
5781 #define OS_FORK1_METHODDEF
5782#endif /* !defined(OS_FORK1_METHODDEF) */
5783
5784#ifndef OS_FORK_METHODDEF
5785 #define OS_FORK_METHODDEF
5786#endif /* !defined(OS_FORK_METHODDEF) */
5787
5788#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5789 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
5790#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
5791
5792#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5793 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
5794#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
5795
5796#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
5797 #define OS_SCHED_GETSCHEDULER_METHODDEF
5798#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
5799
5800#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
5801 #define OS_SCHED_SETSCHEDULER_METHODDEF
5802#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
5803
5804#ifndef OS_SCHED_GETPARAM_METHODDEF
5805 #define OS_SCHED_GETPARAM_METHODDEF
5806#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
5807
5808#ifndef OS_SCHED_SETPARAM_METHODDEF
5809 #define OS_SCHED_SETPARAM_METHODDEF
5810#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
5811
5812#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
5813 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
5814#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
5815
5816#ifndef OS_SCHED_YIELD_METHODDEF
5817 #define OS_SCHED_YIELD_METHODDEF
5818#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
5819
5820#ifndef OS_SCHED_SETAFFINITY_METHODDEF
5821 #define OS_SCHED_SETAFFINITY_METHODDEF
5822#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
5823
5824#ifndef OS_SCHED_GETAFFINITY_METHODDEF
5825 #define OS_SCHED_GETAFFINITY_METHODDEF
5826#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
5827
5828#ifndef OS_OPENPTY_METHODDEF
5829 #define OS_OPENPTY_METHODDEF
5830#endif /* !defined(OS_OPENPTY_METHODDEF) */
5831
5832#ifndef OS_FORKPTY_METHODDEF
5833 #define OS_FORKPTY_METHODDEF
5834#endif /* !defined(OS_FORKPTY_METHODDEF) */
5835
5836#ifndef OS_GETEGID_METHODDEF
5837 #define OS_GETEGID_METHODDEF
5838#endif /* !defined(OS_GETEGID_METHODDEF) */
5839
5840#ifndef OS_GETEUID_METHODDEF
5841 #define OS_GETEUID_METHODDEF
5842#endif /* !defined(OS_GETEUID_METHODDEF) */
5843
5844#ifndef OS_GETGID_METHODDEF
5845 #define OS_GETGID_METHODDEF
5846#endif /* !defined(OS_GETGID_METHODDEF) */
5847
Berker Peksag39404992016-09-15 20:45:16 +03005848#ifndef OS_GETPID_METHODDEF
5849 #define OS_GETPID_METHODDEF
5850#endif /* !defined(OS_GETPID_METHODDEF) */
5851
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005852#ifndef OS_GETGROUPS_METHODDEF
5853 #define OS_GETGROUPS_METHODDEF
5854#endif /* !defined(OS_GETGROUPS_METHODDEF) */
5855
5856#ifndef OS_GETPGID_METHODDEF
5857 #define OS_GETPGID_METHODDEF
5858#endif /* !defined(OS_GETPGID_METHODDEF) */
5859
5860#ifndef OS_GETPGRP_METHODDEF
5861 #define OS_GETPGRP_METHODDEF
5862#endif /* !defined(OS_GETPGRP_METHODDEF) */
5863
5864#ifndef OS_SETPGRP_METHODDEF
5865 #define OS_SETPGRP_METHODDEF
5866#endif /* !defined(OS_SETPGRP_METHODDEF) */
5867
5868#ifndef OS_GETPPID_METHODDEF
5869 #define OS_GETPPID_METHODDEF
5870#endif /* !defined(OS_GETPPID_METHODDEF) */
5871
5872#ifndef OS_GETLOGIN_METHODDEF
5873 #define OS_GETLOGIN_METHODDEF
5874#endif /* !defined(OS_GETLOGIN_METHODDEF) */
5875
5876#ifndef OS_GETUID_METHODDEF
5877 #define OS_GETUID_METHODDEF
5878#endif /* !defined(OS_GETUID_METHODDEF) */
5879
5880#ifndef OS_KILL_METHODDEF
5881 #define OS_KILL_METHODDEF
5882#endif /* !defined(OS_KILL_METHODDEF) */
5883
5884#ifndef OS_KILLPG_METHODDEF
5885 #define OS_KILLPG_METHODDEF
5886#endif /* !defined(OS_KILLPG_METHODDEF) */
5887
5888#ifndef OS_PLOCK_METHODDEF
5889 #define OS_PLOCK_METHODDEF
5890#endif /* !defined(OS_PLOCK_METHODDEF) */
5891
5892#ifndef OS_SETUID_METHODDEF
5893 #define OS_SETUID_METHODDEF
5894#endif /* !defined(OS_SETUID_METHODDEF) */
5895
5896#ifndef OS_SETEUID_METHODDEF
5897 #define OS_SETEUID_METHODDEF
5898#endif /* !defined(OS_SETEUID_METHODDEF) */
5899
5900#ifndef OS_SETEGID_METHODDEF
5901 #define OS_SETEGID_METHODDEF
5902#endif /* !defined(OS_SETEGID_METHODDEF) */
5903
5904#ifndef OS_SETREUID_METHODDEF
5905 #define OS_SETREUID_METHODDEF
5906#endif /* !defined(OS_SETREUID_METHODDEF) */
5907
5908#ifndef OS_SETREGID_METHODDEF
5909 #define OS_SETREGID_METHODDEF
5910#endif /* !defined(OS_SETREGID_METHODDEF) */
5911
5912#ifndef OS_SETGID_METHODDEF
5913 #define OS_SETGID_METHODDEF
5914#endif /* !defined(OS_SETGID_METHODDEF) */
5915
5916#ifndef OS_SETGROUPS_METHODDEF
5917 #define OS_SETGROUPS_METHODDEF
5918#endif /* !defined(OS_SETGROUPS_METHODDEF) */
5919
5920#ifndef OS_WAIT3_METHODDEF
5921 #define OS_WAIT3_METHODDEF
5922#endif /* !defined(OS_WAIT3_METHODDEF) */
5923
5924#ifndef OS_WAIT4_METHODDEF
5925 #define OS_WAIT4_METHODDEF
5926#endif /* !defined(OS_WAIT4_METHODDEF) */
5927
5928#ifndef OS_WAITID_METHODDEF
5929 #define OS_WAITID_METHODDEF
5930#endif /* !defined(OS_WAITID_METHODDEF) */
5931
5932#ifndef OS_WAITPID_METHODDEF
5933 #define OS_WAITPID_METHODDEF
5934#endif /* !defined(OS_WAITPID_METHODDEF) */
5935
5936#ifndef OS_WAIT_METHODDEF
5937 #define OS_WAIT_METHODDEF
5938#endif /* !defined(OS_WAIT_METHODDEF) */
5939
5940#ifndef OS_SYMLINK_METHODDEF
5941 #define OS_SYMLINK_METHODDEF
5942#endif /* !defined(OS_SYMLINK_METHODDEF) */
5943
5944#ifndef OS_TIMES_METHODDEF
5945 #define OS_TIMES_METHODDEF
5946#endif /* !defined(OS_TIMES_METHODDEF) */
5947
5948#ifndef OS_GETSID_METHODDEF
5949 #define OS_GETSID_METHODDEF
5950#endif /* !defined(OS_GETSID_METHODDEF) */
5951
5952#ifndef OS_SETSID_METHODDEF
5953 #define OS_SETSID_METHODDEF
5954#endif /* !defined(OS_SETSID_METHODDEF) */
5955
5956#ifndef OS_SETPGID_METHODDEF
5957 #define OS_SETPGID_METHODDEF
5958#endif /* !defined(OS_SETPGID_METHODDEF) */
5959
5960#ifndef OS_TCGETPGRP_METHODDEF
5961 #define OS_TCGETPGRP_METHODDEF
5962#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
5963
5964#ifndef OS_TCSETPGRP_METHODDEF
5965 #define OS_TCSETPGRP_METHODDEF
5966#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
5967
5968#ifndef OS_LOCKF_METHODDEF
5969 #define OS_LOCKF_METHODDEF
5970#endif /* !defined(OS_LOCKF_METHODDEF) */
5971
5972#ifndef OS_READV_METHODDEF
5973 #define OS_READV_METHODDEF
5974#endif /* !defined(OS_READV_METHODDEF) */
5975
5976#ifndef OS_PREAD_METHODDEF
5977 #define OS_PREAD_METHODDEF
5978#endif /* !defined(OS_PREAD_METHODDEF) */
5979
5980#ifndef OS_PIPE_METHODDEF
5981 #define OS_PIPE_METHODDEF
5982#endif /* !defined(OS_PIPE_METHODDEF) */
5983
5984#ifndef OS_PIPE2_METHODDEF
5985 #define OS_PIPE2_METHODDEF
5986#endif /* !defined(OS_PIPE2_METHODDEF) */
5987
5988#ifndef OS_WRITEV_METHODDEF
5989 #define OS_WRITEV_METHODDEF
5990#endif /* !defined(OS_WRITEV_METHODDEF) */
5991
5992#ifndef OS_PWRITE_METHODDEF
5993 #define OS_PWRITE_METHODDEF
5994#endif /* !defined(OS_PWRITE_METHODDEF) */
5995
5996#ifndef OS_MKFIFO_METHODDEF
5997 #define OS_MKFIFO_METHODDEF
5998#endif /* !defined(OS_MKFIFO_METHODDEF) */
5999
6000#ifndef OS_MKNOD_METHODDEF
6001 #define OS_MKNOD_METHODDEF
6002#endif /* !defined(OS_MKNOD_METHODDEF) */
6003
6004#ifndef OS_MAJOR_METHODDEF
6005 #define OS_MAJOR_METHODDEF
6006#endif /* !defined(OS_MAJOR_METHODDEF) */
6007
6008#ifndef OS_MINOR_METHODDEF
6009 #define OS_MINOR_METHODDEF
6010#endif /* !defined(OS_MINOR_METHODDEF) */
6011
6012#ifndef OS_MAKEDEV_METHODDEF
6013 #define OS_MAKEDEV_METHODDEF
6014#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6015
6016#ifndef OS_FTRUNCATE_METHODDEF
6017 #define OS_FTRUNCATE_METHODDEF
6018#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6019
6020#ifndef OS_TRUNCATE_METHODDEF
6021 #define OS_TRUNCATE_METHODDEF
6022#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6023
6024#ifndef OS_POSIX_FALLOCATE_METHODDEF
6025 #define OS_POSIX_FALLOCATE_METHODDEF
6026#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6027
6028#ifndef OS_POSIX_FADVISE_METHODDEF
6029 #define OS_POSIX_FADVISE_METHODDEF
6030#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6031
6032#ifndef OS_PUTENV_METHODDEF
6033 #define OS_PUTENV_METHODDEF
6034#endif /* !defined(OS_PUTENV_METHODDEF) */
6035
6036#ifndef OS_UNSETENV_METHODDEF
6037 #define OS_UNSETENV_METHODDEF
6038#endif /* !defined(OS_UNSETENV_METHODDEF) */
6039
6040#ifndef OS_WCOREDUMP_METHODDEF
6041 #define OS_WCOREDUMP_METHODDEF
6042#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6043
6044#ifndef OS_WIFCONTINUED_METHODDEF
6045 #define OS_WIFCONTINUED_METHODDEF
6046#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6047
6048#ifndef OS_WIFSTOPPED_METHODDEF
6049 #define OS_WIFSTOPPED_METHODDEF
6050#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6051
6052#ifndef OS_WIFSIGNALED_METHODDEF
6053 #define OS_WIFSIGNALED_METHODDEF
6054#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6055
6056#ifndef OS_WIFEXITED_METHODDEF
6057 #define OS_WIFEXITED_METHODDEF
6058#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6059
6060#ifndef OS_WEXITSTATUS_METHODDEF
6061 #define OS_WEXITSTATUS_METHODDEF
6062#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6063
6064#ifndef OS_WTERMSIG_METHODDEF
6065 #define OS_WTERMSIG_METHODDEF
6066#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6067
6068#ifndef OS_WSTOPSIG_METHODDEF
6069 #define OS_WSTOPSIG_METHODDEF
6070#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6071
6072#ifndef OS_FSTATVFS_METHODDEF
6073 #define OS_FSTATVFS_METHODDEF
6074#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6075
6076#ifndef OS_STATVFS_METHODDEF
6077 #define OS_STATVFS_METHODDEF
6078#endif /* !defined(OS_STATVFS_METHODDEF) */
6079
6080#ifndef OS__GETDISKUSAGE_METHODDEF
6081 #define OS__GETDISKUSAGE_METHODDEF
6082#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6083
6084#ifndef OS_FPATHCONF_METHODDEF
6085 #define OS_FPATHCONF_METHODDEF
6086#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6087
6088#ifndef OS_PATHCONF_METHODDEF
6089 #define OS_PATHCONF_METHODDEF
6090#endif /* !defined(OS_PATHCONF_METHODDEF) */
6091
6092#ifndef OS_CONFSTR_METHODDEF
6093 #define OS_CONFSTR_METHODDEF
6094#endif /* !defined(OS_CONFSTR_METHODDEF) */
6095
6096#ifndef OS_SYSCONF_METHODDEF
6097 #define OS_SYSCONF_METHODDEF
6098#endif /* !defined(OS_SYSCONF_METHODDEF) */
6099
Steve Dowercc16be82016-09-08 10:35:16 -07006100#ifndef OS_STARTFILE_METHODDEF
6101 #define OS_STARTFILE_METHODDEF
6102#endif /* !defined(OS_STARTFILE_METHODDEF) */
6103
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006104#ifndef OS_GETLOADAVG_METHODDEF
6105 #define OS_GETLOADAVG_METHODDEF
6106#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6107
6108#ifndef OS_SETRESUID_METHODDEF
6109 #define OS_SETRESUID_METHODDEF
6110#endif /* !defined(OS_SETRESUID_METHODDEF) */
6111
6112#ifndef OS_SETRESGID_METHODDEF
6113 #define OS_SETRESGID_METHODDEF
6114#endif /* !defined(OS_SETRESGID_METHODDEF) */
6115
6116#ifndef OS_GETRESUID_METHODDEF
6117 #define OS_GETRESUID_METHODDEF
6118#endif /* !defined(OS_GETRESUID_METHODDEF) */
6119
6120#ifndef OS_GETRESGID_METHODDEF
6121 #define OS_GETRESGID_METHODDEF
6122#endif /* !defined(OS_GETRESGID_METHODDEF) */
6123
6124#ifndef OS_GETXATTR_METHODDEF
6125 #define OS_GETXATTR_METHODDEF
6126#endif /* !defined(OS_GETXATTR_METHODDEF) */
6127
6128#ifndef OS_SETXATTR_METHODDEF
6129 #define OS_SETXATTR_METHODDEF
6130#endif /* !defined(OS_SETXATTR_METHODDEF) */
6131
6132#ifndef OS_REMOVEXATTR_METHODDEF
6133 #define OS_REMOVEXATTR_METHODDEF
6134#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6135
6136#ifndef OS_LISTXATTR_METHODDEF
6137 #define OS_LISTXATTR_METHODDEF
6138#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6139
6140#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6141 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6142#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6143
6144#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6145 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6146#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006147
6148#ifndef OS_GETRANDOM_METHODDEF
6149 #define OS_GETRANDOM_METHODDEF
6150#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Berker Peksag39404992016-09-15 20:45:16 +03006151/*[clinic end generated code: output=b9ed5703d2feb0d9 input=a9049054013a1b77]*/