blob: c88716f11116d8968d275a0f23226c458e5118e3 [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 Stinner3e1fad62017-01-17 01:29:01 +010045 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +010082 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100147 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100249 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100287 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100343 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100381 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100419 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100465 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100506 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100543 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100580 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100636 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100699 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100740 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100779 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100868 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100916 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300917 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300918 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300919 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300920 return_value = os_listdir_impl(module, &path);
921
922exit:
923 /* Cleanup for path */
924 path_cleanup(&path);
925
926 return return_value;
927}
928
929#if defined(MS_WINDOWS)
930
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300931PyDoc_STRVAR(os__getfullpathname__doc__,
932"_getfullpathname($module, path, /)\n"
933"--\n"
934"\n");
935
936#define OS__GETFULLPATHNAME_METHODDEF \
937 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
938
939static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300940os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300941
942static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300943os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300944{
945 PyObject *return_value = NULL;
946 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
947
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300948 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300949 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300950 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300951 return_value = os__getfullpathname_impl(module, &path);
952
953exit:
954 /* Cleanup for path */
955 path_cleanup(&path);
956
957 return return_value;
958}
959
960#endif /* defined(MS_WINDOWS) */
961
962#if defined(MS_WINDOWS)
963
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300964PyDoc_STRVAR(os__getfinalpathname__doc__,
965"_getfinalpathname($module, path, /)\n"
966"--\n"
967"\n"
968"A helper function for samepath on windows.");
969
970#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300971 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300972
973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300974os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300975
976static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300977os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300978{
979 PyObject *return_value = NULL;
980 PyObject *path;
981
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300982 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300983 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300984 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300985 return_value = os__getfinalpathname_impl(module, path);
986
987exit:
988 return return_value;
989}
990
991#endif /* defined(MS_WINDOWS) */
992
993#if defined(MS_WINDOWS)
994
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300995PyDoc_STRVAR(os__isdir__doc__,
996"_isdir($module, path, /)\n"
997"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200998"\n"
999"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001000
1001#define OS__ISDIR_METHODDEF \
1002 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1003
1004static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001005os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001006
1007static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001008os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001009{
1010 PyObject *return_value = NULL;
1011 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1012
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001013 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001014 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001015 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001016 return_value = os__isdir_impl(module, &path);
1017
1018exit:
1019 /* Cleanup for path */
1020 path_cleanup(&path);
1021
1022 return return_value;
1023}
1024
1025#endif /* defined(MS_WINDOWS) */
1026
1027#if defined(MS_WINDOWS)
1028
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001029PyDoc_STRVAR(os__getvolumepathname__doc__,
1030"_getvolumepathname($module, /, path)\n"
1031"--\n"
1032"\n"
1033"A helper function for ismount on Win32.");
1034
1035#define OS__GETVOLUMEPATHNAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001036 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001037
1038static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001039os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001040
1041static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001042os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001043{
1044 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001045 static const char * const _keywords[] = {"path", NULL};
1046 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001047 PyObject *path;
1048
Victor Stinner3e1fad62017-01-17 01:29:01 +01001049 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001050 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001051 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001052 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001053 return_value = os__getvolumepathname_impl(module, path);
1054
1055exit:
1056 return return_value;
1057}
1058
1059#endif /* defined(MS_WINDOWS) */
1060
1061PyDoc_STRVAR(os_mkdir__doc__,
1062"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1063"--\n"
1064"\n"
1065"Create a directory.\n"
1066"\n"
1067"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1068" and path should be relative; path will then be relative to that directory.\n"
1069"dir_fd may not be implemented on your platform.\n"
1070" If it is unavailable, using it will raise a NotImplementedError.\n"
1071"\n"
1072"The mode argument is ignored on Windows.");
1073
1074#define OS_MKDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001075 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001076
1077static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001078os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001079
1080static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001081os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001082{
1083 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001084 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1085 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001086 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1087 int mode = 511;
1088 int dir_fd = DEFAULT_DIR_FD;
1089
Victor Stinner3e1fad62017-01-17 01:29:01 +01001090 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001091 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001092 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001093 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001094 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1095
1096exit:
1097 /* Cleanup for path */
1098 path_cleanup(&path);
1099
1100 return return_value;
1101}
1102
1103#if defined(HAVE_NICE)
1104
1105PyDoc_STRVAR(os_nice__doc__,
1106"nice($module, increment, /)\n"
1107"--\n"
1108"\n"
1109"Add increment to the priority of process and return the new priority.");
1110
1111#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001112 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001113
1114static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001115os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001116
1117static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001118os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001119{
1120 PyObject *return_value = NULL;
1121 int increment;
1122
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001123 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001124 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001125 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001126 return_value = os_nice_impl(module, increment);
1127
1128exit:
1129 return return_value;
1130}
1131
1132#endif /* defined(HAVE_NICE) */
1133
1134#if defined(HAVE_GETPRIORITY)
1135
1136PyDoc_STRVAR(os_getpriority__doc__,
1137"getpriority($module, /, which, who)\n"
1138"--\n"
1139"\n"
1140"Return program scheduling priority.");
1141
1142#define OS_GETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001143 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001144
1145static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001146os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001147
1148static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001149os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001150{
1151 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001152 static const char * const _keywords[] = {"which", "who", NULL};
1153 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001154 int which;
1155 int who;
1156
Victor Stinner3e1fad62017-01-17 01:29:01 +01001157 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001158 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001159 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001160 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001161 return_value = os_getpriority_impl(module, which, who);
1162
1163exit:
1164 return return_value;
1165}
1166
1167#endif /* defined(HAVE_GETPRIORITY) */
1168
1169#if defined(HAVE_SETPRIORITY)
1170
1171PyDoc_STRVAR(os_setpriority__doc__,
1172"setpriority($module, /, which, who, priority)\n"
1173"--\n"
1174"\n"
1175"Set program scheduling priority.");
1176
1177#define OS_SETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001178 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001179
1180static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001181os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001182
1183static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001184os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001185{
1186 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001187 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1188 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001189 int which;
1190 int who;
1191 int priority;
1192
Victor Stinner3e1fad62017-01-17 01:29:01 +01001193 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001194 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001195 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001196 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001197 return_value = os_setpriority_impl(module, which, who, priority);
1198
1199exit:
1200 return return_value;
1201}
1202
1203#endif /* defined(HAVE_SETPRIORITY) */
1204
1205PyDoc_STRVAR(os_rename__doc__,
1206"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1207"--\n"
1208"\n"
1209"Rename a file or directory.\n"
1210"\n"
1211"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1212" descriptor open to a directory, and the respective path string (src or dst)\n"
1213" should be relative; the path will then be relative to that directory.\n"
1214"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1215" If they are unavailable, using them will raise a NotImplementedError.");
1216
1217#define OS_RENAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001218 {"rename", (PyCFunction)os_rename, METH_FASTCALL, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001219
1220static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001221os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001222 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001223
1224static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001225os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001226{
1227 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001228 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1229 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001230 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1231 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1232 int src_dir_fd = DEFAULT_DIR_FD;
1233 int dst_dir_fd = DEFAULT_DIR_FD;
1234
Victor Stinner3e1fad62017-01-17 01:29:01 +01001235 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001236 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001237 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001238 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001239 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1240
1241exit:
1242 /* Cleanup for src */
1243 path_cleanup(&src);
1244 /* Cleanup for dst */
1245 path_cleanup(&dst);
1246
1247 return return_value;
1248}
1249
1250PyDoc_STRVAR(os_replace__doc__,
1251"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1252"--\n"
1253"\n"
1254"Rename a file or directory, overwriting the destination.\n"
1255"\n"
1256"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1257" descriptor open to a directory, and the respective path string (src or dst)\n"
1258" should be relative; the path will then be relative to that directory.\n"
1259"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1260" If they are unavailable, using them will raise a NotImplementedError.\"");
1261
1262#define OS_REPLACE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001263 {"replace", (PyCFunction)os_replace, METH_FASTCALL, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001264
1265static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001266os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1267 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001268
1269static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001270os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001271{
1272 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001273 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1274 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001275 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1276 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1277 int src_dir_fd = DEFAULT_DIR_FD;
1278 int dst_dir_fd = DEFAULT_DIR_FD;
1279
Victor Stinner3e1fad62017-01-17 01:29:01 +01001280 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001281 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001282 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001283 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001284 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1285
1286exit:
1287 /* Cleanup for src */
1288 path_cleanup(&src);
1289 /* Cleanup for dst */
1290 path_cleanup(&dst);
1291
1292 return return_value;
1293}
1294
1295PyDoc_STRVAR(os_rmdir__doc__,
1296"rmdir($module, /, path, *, dir_fd=None)\n"
1297"--\n"
1298"\n"
1299"Remove a directory.\n"
1300"\n"
1301"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1302" and path should be relative; path will then be relative to that directory.\n"
1303"dir_fd may not be implemented on your platform.\n"
1304" If it is unavailable, using it will raise a NotImplementedError.");
1305
1306#define OS_RMDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001307 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001308
1309static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001310os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001311
1312static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001313os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001314{
1315 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001316 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1317 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001318 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1319 int dir_fd = DEFAULT_DIR_FD;
1320
Victor Stinner3e1fad62017-01-17 01:29:01 +01001321 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001322 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001323 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001324 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001325 return_value = os_rmdir_impl(module, &path, dir_fd);
1326
1327exit:
1328 /* Cleanup for path */
1329 path_cleanup(&path);
1330
1331 return return_value;
1332}
1333
1334#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1335
1336PyDoc_STRVAR(os_system__doc__,
1337"system($module, /, command)\n"
1338"--\n"
1339"\n"
1340"Execute the command in a subshell.");
1341
1342#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001343 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001344
1345static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001346os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001347
1348static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001349os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001350{
1351 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001352 static const char * const _keywords[] = {"command", NULL};
1353 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354 Py_UNICODE *command;
1355 long _return_value;
1356
Victor Stinner3e1fad62017-01-17 01:29:01 +01001357 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001358 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001359 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001360 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001361 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001362 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001363 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001364 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001365 return_value = PyLong_FromLong(_return_value);
1366
1367exit:
1368 return return_value;
1369}
1370
1371#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1372
1373#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1374
1375PyDoc_STRVAR(os_system__doc__,
1376"system($module, /, command)\n"
1377"--\n"
1378"\n"
1379"Execute the command in a subshell.");
1380
1381#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001382 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001383
1384static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001385os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001386
1387static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001388os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001389{
1390 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001391 static const char * const _keywords[] = {"command", NULL};
1392 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393 PyObject *command = NULL;
1394 long _return_value;
1395
Victor Stinner3e1fad62017-01-17 01:29:01 +01001396 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001397 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001400 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001401 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001402 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001403 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001404 return_value = PyLong_FromLong(_return_value);
1405
1406exit:
1407 /* Cleanup for command */
1408 Py_XDECREF(command);
1409
1410 return return_value;
1411}
1412
1413#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1414
1415PyDoc_STRVAR(os_umask__doc__,
1416"umask($module, mask, /)\n"
1417"--\n"
1418"\n"
1419"Set the current numeric umask and return the previous umask.");
1420
1421#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001422 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001423
1424static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001425os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001426
1427static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001428os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001429{
1430 PyObject *return_value = NULL;
1431 int mask;
1432
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001433 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001435 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001436 return_value = os_umask_impl(module, mask);
1437
1438exit:
1439 return return_value;
1440}
1441
1442PyDoc_STRVAR(os_unlink__doc__,
1443"unlink($module, /, path, *, dir_fd=None)\n"
1444"--\n"
1445"\n"
1446"Remove a file (same as remove()).\n"
1447"\n"
1448"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1449" and path should be relative; path will then be relative to that directory.\n"
1450"dir_fd may not be implemented on your platform.\n"
1451" If it is unavailable, using it will raise a NotImplementedError.");
1452
1453#define OS_UNLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001454 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001455
1456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001457os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001458
1459static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001460os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001461{
1462 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001463 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1464 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001465 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1466 int dir_fd = DEFAULT_DIR_FD;
1467
Victor Stinner3e1fad62017-01-17 01:29:01 +01001468 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001469 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001470 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001471 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001472 return_value = os_unlink_impl(module, &path, dir_fd);
1473
1474exit:
1475 /* Cleanup for path */
1476 path_cleanup(&path);
1477
1478 return return_value;
1479}
1480
1481PyDoc_STRVAR(os_remove__doc__,
1482"remove($module, /, path, *, dir_fd=None)\n"
1483"--\n"
1484"\n"
1485"Remove a file (same as unlink()).\n"
1486"\n"
1487"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1488" and path should be relative; path will then be relative to that directory.\n"
1489"dir_fd may not be implemented on your platform.\n"
1490" If it is unavailable, using it will raise a NotImplementedError.");
1491
1492#define OS_REMOVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001493 {"remove", (PyCFunction)os_remove, METH_FASTCALL, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001494
1495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001496os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001497
1498static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001499os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001500{
1501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001502 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1503 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001504 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1505 int dir_fd = DEFAULT_DIR_FD;
1506
Victor Stinner3e1fad62017-01-17 01:29:01 +01001507 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001508 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001511 return_value = os_remove_impl(module, &path, dir_fd);
1512
1513exit:
1514 /* Cleanup for path */
1515 path_cleanup(&path);
1516
1517 return return_value;
1518}
1519
1520#if defined(HAVE_UNAME)
1521
1522PyDoc_STRVAR(os_uname__doc__,
1523"uname($module, /)\n"
1524"--\n"
1525"\n"
1526"Return an object identifying the current operating system.\n"
1527"\n"
1528"The object behaves like a named tuple with the following fields:\n"
1529" (sysname, nodename, release, version, machine)");
1530
1531#define OS_UNAME_METHODDEF \
1532 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1533
1534static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001535os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001536
1537static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001538os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001539{
1540 return os_uname_impl(module);
1541}
1542
1543#endif /* defined(HAVE_UNAME) */
1544
1545PyDoc_STRVAR(os_utime__doc__,
1546"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1547" follow_symlinks=True)\n"
1548"--\n"
1549"\n"
1550"Set the access and modified time of path.\n"
1551"\n"
1552"path may always be specified as a string.\n"
1553"On some platforms, path may also be specified as an open file descriptor.\n"
1554" If this functionality is unavailable, using it raises an exception.\n"
1555"\n"
1556"If times is not None, it must be a tuple (atime, mtime);\n"
1557" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001558"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001559" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1560" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001561"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001562"Specifying tuples for both times and ns is an error.\n"
1563"\n"
1564"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1565" and path should be relative; path will then be relative to that directory.\n"
1566"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1567" link, utime will modify the symbolic link itself instead of the file the\n"
1568" link points to.\n"
1569"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1570" as an open file descriptor.\n"
1571"dir_fd and follow_symlinks may not be available on your platform.\n"
1572" If they are unavailable, using them will raise a NotImplementedError.");
1573
1574#define OS_UTIME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001575 {"utime", (PyCFunction)os_utime, METH_FASTCALL, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001576
1577static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001578os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1579 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001580
1581static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001582os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001583{
1584 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001585 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1586 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001587 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1588 PyObject *times = NULL;
1589 PyObject *ns = NULL;
1590 int dir_fd = DEFAULT_DIR_FD;
1591 int follow_symlinks = 1;
1592
Victor Stinner3e1fad62017-01-17 01:29:01 +01001593 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001594 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001595 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001596 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001597 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1598
1599exit:
1600 /* Cleanup for path */
1601 path_cleanup(&path);
1602
1603 return return_value;
1604}
1605
1606PyDoc_STRVAR(os__exit__doc__,
1607"_exit($module, /, status)\n"
1608"--\n"
1609"\n"
1610"Exit to the system with specified status, without normal exit processing.");
1611
1612#define OS__EXIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001613 {"_exit", (PyCFunction)os__exit, METH_FASTCALL, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001614
1615static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001616os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001617
1618static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001619os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001620{
1621 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001622 static const char * const _keywords[] = {"status", NULL};
1623 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001624 int status;
1625
Victor Stinner3e1fad62017-01-17 01:29:01 +01001626 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001627 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001628 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001629 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001630 return_value = os__exit_impl(module, status);
1631
1632exit:
1633 return return_value;
1634}
1635
1636#if defined(HAVE_EXECV)
1637
1638PyDoc_STRVAR(os_execv__doc__,
1639"execv($module, path, argv, /)\n"
1640"--\n"
1641"\n"
1642"Execute an executable path with arguments, replacing current process.\n"
1643"\n"
1644" path\n"
1645" Path of executable file.\n"
1646" argv\n"
1647" Tuple or list of strings.");
1648
1649#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001650 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001651
1652static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001653os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001654
1655static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001656os_execv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001657{
1658 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001659 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001660 PyObject *argv;
1661
Victor Stinner259f0e42017-01-17 01:35:17 +01001662 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
Steve Dowercc16be82016-09-08 10:35:16 -07001663 path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001664 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001665 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001666
1667 if (!_PyArg_NoStackKeywords("execv", kwnames)) {
1668 goto exit;
1669 }
Steve Dowercc16be82016-09-08 10:35:16 -07001670 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001671
1672exit:
1673 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001674 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001675
1676 return return_value;
1677}
1678
1679#endif /* defined(HAVE_EXECV) */
1680
1681#if defined(HAVE_EXECV)
1682
1683PyDoc_STRVAR(os_execve__doc__,
1684"execve($module, /, path, argv, env)\n"
1685"--\n"
1686"\n"
1687"Execute an executable path with arguments, replacing current process.\n"
1688"\n"
1689" path\n"
1690" Path of executable file.\n"
1691" argv\n"
1692" Tuple or list of strings.\n"
1693" env\n"
1694" Dictionary of strings mapping to strings.");
1695
1696#define OS_EXECVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001697 {"execve", (PyCFunction)os_execve, METH_FASTCALL, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001698
1699static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001700os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001701
1702static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001703os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001704{
1705 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001706 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1707 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001708 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1709 PyObject *argv;
1710 PyObject *env;
1711
Victor Stinner3e1fad62017-01-17 01:29:01 +01001712 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001713 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001714 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001715 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001716 return_value = os_execve_impl(module, &path, argv, env);
1717
1718exit:
1719 /* Cleanup for path */
1720 path_cleanup(&path);
1721
1722 return return_value;
1723}
1724
1725#endif /* defined(HAVE_EXECV) */
1726
Steve Dowercc16be82016-09-08 10:35:16 -07001727#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001728
1729PyDoc_STRVAR(os_spawnv__doc__,
1730"spawnv($module, mode, path, argv, /)\n"
1731"--\n"
1732"\n"
1733"Execute the program specified by path in a new process.\n"
1734"\n"
1735" mode\n"
1736" Mode of process creation.\n"
1737" path\n"
1738" Path of executable file.\n"
1739" argv\n"
1740" Tuple or list of strings.");
1741
1742#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001743 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001744
1745static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001746os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001747
1748static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001749os_spawnv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001750{
1751 PyObject *return_value = NULL;
1752 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001753 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001754 PyObject *argv;
1755
Victor Stinner259f0e42017-01-17 01:35:17 +01001756 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
Steve Dowercc16be82016-09-08 10:35:16 -07001757 &mode, path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001758 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001759 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001760
1761 if (!_PyArg_NoStackKeywords("spawnv", kwnames)) {
1762 goto exit;
1763 }
Steve Dowercc16be82016-09-08 10:35:16 -07001764 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001765
1766exit:
1767 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001768 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001769
1770 return return_value;
1771}
1772
Steve Dowercc16be82016-09-08 10:35:16 -07001773#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001774
Steve Dowercc16be82016-09-08 10:35:16 -07001775#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001776
1777PyDoc_STRVAR(os_spawnve__doc__,
1778"spawnve($module, mode, path, argv, env, /)\n"
1779"--\n"
1780"\n"
1781"Execute the program specified by path in a new process.\n"
1782"\n"
1783" mode\n"
1784" Mode of process creation.\n"
1785" path\n"
1786" Path of executable file.\n"
1787" argv\n"
1788" Tuple or list of strings.\n"
1789" env\n"
1790" Dictionary of strings mapping to strings.");
1791
1792#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001793 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001794
1795static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001796os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001797 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001798
1799static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001800os_spawnve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001801{
1802 PyObject *return_value = NULL;
1803 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001804 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001805 PyObject *argv;
1806 PyObject *env;
1807
Victor Stinner259f0e42017-01-17 01:35:17 +01001808 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
Steve Dowercc16be82016-09-08 10:35:16 -07001809 &mode, path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001810 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001811 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001812
1813 if (!_PyArg_NoStackKeywords("spawnve", kwnames)) {
1814 goto exit;
1815 }
Steve Dowercc16be82016-09-08 10:35:16 -07001816 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001817
1818exit:
1819 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001820 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001821
1822 return return_value;
1823}
1824
Steve Dowercc16be82016-09-08 10:35:16 -07001825#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001826
1827#if defined(HAVE_FORK1)
1828
1829PyDoc_STRVAR(os_fork1__doc__,
1830"fork1($module, /)\n"
1831"--\n"
1832"\n"
1833"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1834"\n"
1835"Return 0 to child process and PID of child to parent process.");
1836
1837#define OS_FORK1_METHODDEF \
1838 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1839
1840static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001841os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001842
1843static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001844os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001845{
1846 return os_fork1_impl(module);
1847}
1848
1849#endif /* defined(HAVE_FORK1) */
1850
1851#if defined(HAVE_FORK)
1852
1853PyDoc_STRVAR(os_fork__doc__,
1854"fork($module, /)\n"
1855"--\n"
1856"\n"
1857"Fork a child process.\n"
1858"\n"
1859"Return 0 to child process and PID of child to parent process.");
1860
1861#define OS_FORK_METHODDEF \
1862 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1863
1864static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001865os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001866
1867static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001868os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001869{
1870 return os_fork_impl(module);
1871}
1872
1873#endif /* defined(HAVE_FORK) */
1874
1875#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1876
1877PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1878"sched_get_priority_max($module, /, policy)\n"
1879"--\n"
1880"\n"
1881"Get the maximum scheduling priority for policy.");
1882
1883#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001884 {"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 +03001885
1886static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001887os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001888
1889static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001890os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001891{
1892 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001893 static const char * const _keywords[] = {"policy", NULL};
1894 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001895 int policy;
1896
Victor Stinner3e1fad62017-01-17 01:29:01 +01001897 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001898 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001899 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001900 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001901 return_value = os_sched_get_priority_max_impl(module, policy);
1902
1903exit:
1904 return return_value;
1905}
1906
1907#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1908
1909#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1910
1911PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1912"sched_get_priority_min($module, /, policy)\n"
1913"--\n"
1914"\n"
1915"Get the minimum scheduling priority for policy.");
1916
1917#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001918 {"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 +03001919
1920static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001921os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001922
1923static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001924os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001925{
1926 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001927 static const char * const _keywords[] = {"policy", NULL};
1928 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001929 int policy;
1930
Victor Stinner3e1fad62017-01-17 01:29:01 +01001931 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001932 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001933 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001934 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001935 return_value = os_sched_get_priority_min_impl(module, policy);
1936
1937exit:
1938 return return_value;
1939}
1940
1941#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1942
1943#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1944
1945PyDoc_STRVAR(os_sched_getscheduler__doc__,
1946"sched_getscheduler($module, pid, /)\n"
1947"--\n"
1948"\n"
1949"Get the scheduling policy for the process identifiedy by pid.\n"
1950"\n"
1951"Passing 0 for pid returns the scheduling policy for the calling process.");
1952
1953#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001954 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001955
1956static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001957os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001958
1959static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001960os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001961{
1962 PyObject *return_value = NULL;
1963 pid_t pid;
1964
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001965 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001966 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001967 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001968 return_value = os_sched_getscheduler_impl(module, pid);
1969
1970exit:
1971 return return_value;
1972}
1973
1974#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1975
1976#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1977
1978PyDoc_STRVAR(os_sched_param__doc__,
1979"sched_param(sched_priority)\n"
1980"--\n"
1981"\n"
1982"Current has only one field: sched_priority\");\n"
1983"\n"
1984" sched_priority\n"
1985" A scheduling parameter.");
1986
1987static PyObject *
1988os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1989
1990static PyObject *
1991os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1992{
1993 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001994 static const char * const _keywords[] = {"sched_priority", NULL};
1995 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001996 PyObject *sched_priority;
1997
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001998 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001999 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002000 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002001 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002002 return_value = os_sched_param_impl(type, sched_priority);
2003
2004exit:
2005 return return_value;
2006}
2007
2008#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2009
2010#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2011
2012PyDoc_STRVAR(os_sched_setscheduler__doc__,
2013"sched_setscheduler($module, pid, policy, param, /)\n"
2014"--\n"
2015"\n"
2016"Set the scheduling policy for the process identified by pid.\n"
2017"\n"
2018"If pid is 0, the calling process is changed.\n"
2019"param is an instance of sched_param.");
2020
2021#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002022 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002023
2024static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002025os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002026 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002027
2028static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002029os_sched_setscheduler(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002030{
2031 PyObject *return_value = NULL;
2032 pid_t pid;
2033 int policy;
2034 struct sched_param param;
2035
Victor Stinner259f0e42017-01-17 01:35:17 +01002036 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002037 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002038 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002039 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002040
2041 if (!_PyArg_NoStackKeywords("sched_setscheduler", kwnames)) {
2042 goto exit;
2043 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002044 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2045
2046exit:
2047 return return_value;
2048}
2049
2050#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2051
2052#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2053
2054PyDoc_STRVAR(os_sched_getparam__doc__,
2055"sched_getparam($module, pid, /)\n"
2056"--\n"
2057"\n"
2058"Returns scheduling parameters for the process identified by pid.\n"
2059"\n"
2060"If pid is 0, returns parameters for the calling process.\n"
2061"Return value is an instance of sched_param.");
2062
2063#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002064 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002065
2066static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002067os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002068
2069static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002070os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002071{
2072 PyObject *return_value = NULL;
2073 pid_t pid;
2074
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002075 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002076 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002077 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002078 return_value = os_sched_getparam_impl(module, pid);
2079
2080exit:
2081 return return_value;
2082}
2083
2084#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2085
2086#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2087
2088PyDoc_STRVAR(os_sched_setparam__doc__,
2089"sched_setparam($module, pid, param, /)\n"
2090"--\n"
2091"\n"
2092"Set scheduling parameters for the process identified by pid.\n"
2093"\n"
2094"If pid is 0, sets parameters for the calling process.\n"
2095"param should be an instance of sched_param.");
2096
2097#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002098 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002099
2100static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002101os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002102 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002103
2104static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002105os_sched_setparam(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002106{
2107 PyObject *return_value = NULL;
2108 pid_t pid;
2109 struct sched_param param;
2110
Victor Stinner259f0e42017-01-17 01:35:17 +01002111 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002112 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002113 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002114 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002115
2116 if (!_PyArg_NoStackKeywords("sched_setparam", kwnames)) {
2117 goto exit;
2118 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002119 return_value = os_sched_setparam_impl(module, pid, &param);
2120
2121exit:
2122 return return_value;
2123}
2124
2125#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2126
2127#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2128
2129PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2130"sched_rr_get_interval($module, pid, /)\n"
2131"--\n"
2132"\n"
2133"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2134"\n"
2135"Value returned is a float.");
2136
2137#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002138 {"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 +03002139
2140static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002141os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002142
2143static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002144os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002145{
2146 PyObject *return_value = NULL;
2147 pid_t pid;
2148 double _return_value;
2149
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002150 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002151 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002152 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002153 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002154 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002155 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002156 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002157 return_value = PyFloat_FromDouble(_return_value);
2158
2159exit:
2160 return return_value;
2161}
2162
2163#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2164
2165#if defined(HAVE_SCHED_H)
2166
2167PyDoc_STRVAR(os_sched_yield__doc__,
2168"sched_yield($module, /)\n"
2169"--\n"
2170"\n"
2171"Voluntarily relinquish the CPU.");
2172
2173#define OS_SCHED_YIELD_METHODDEF \
2174 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2175
2176static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002177os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002178
2179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002180os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002181{
2182 return os_sched_yield_impl(module);
2183}
2184
2185#endif /* defined(HAVE_SCHED_H) */
2186
2187#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2188
2189PyDoc_STRVAR(os_sched_setaffinity__doc__,
2190"sched_setaffinity($module, pid, mask, /)\n"
2191"--\n"
2192"\n"
2193"Set the CPU affinity of the process identified by pid to mask.\n"
2194"\n"
2195"mask should be an iterable of integers identifying CPUs.");
2196
2197#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002198 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002199
2200static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002201os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002202
2203static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002204os_sched_setaffinity(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002205{
2206 PyObject *return_value = NULL;
2207 pid_t pid;
2208 PyObject *mask;
2209
Victor Stinner259f0e42017-01-17 01:35:17 +01002210 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002211 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002212 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002213 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002214
2215 if (!_PyArg_NoStackKeywords("sched_setaffinity", kwnames)) {
2216 goto exit;
2217 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002218 return_value = os_sched_setaffinity_impl(module, pid, mask);
2219
2220exit:
2221 return return_value;
2222}
2223
2224#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2225
2226#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2227
2228PyDoc_STRVAR(os_sched_getaffinity__doc__,
2229"sched_getaffinity($module, pid, /)\n"
2230"--\n"
2231"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002232"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002233"\n"
2234"The affinity is returned as a set of CPU identifiers.");
2235
2236#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002237 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002238
2239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002240os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002241
2242static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002243os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002244{
2245 PyObject *return_value = NULL;
2246 pid_t pid;
2247
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002248 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002249 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002250 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002251 return_value = os_sched_getaffinity_impl(module, pid);
2252
2253exit:
2254 return return_value;
2255}
2256
2257#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2258
2259#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2260
2261PyDoc_STRVAR(os_openpty__doc__,
2262"openpty($module, /)\n"
2263"--\n"
2264"\n"
2265"Open a pseudo-terminal.\n"
2266"\n"
2267"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2268"for both the master and slave ends.");
2269
2270#define OS_OPENPTY_METHODDEF \
2271 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2272
2273static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002274os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002275
2276static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002277os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002278{
2279 return os_openpty_impl(module);
2280}
2281
2282#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2283
2284#if defined(HAVE_FORKPTY)
2285
2286PyDoc_STRVAR(os_forkpty__doc__,
2287"forkpty($module, /)\n"
2288"--\n"
2289"\n"
2290"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2291"\n"
2292"Returns a tuple of (pid, master_fd).\n"
2293"Like fork(), return pid of 0 to the child process,\n"
2294"and pid of child to the parent process.\n"
2295"To both, return fd of newly opened pseudo-terminal.");
2296
2297#define OS_FORKPTY_METHODDEF \
2298 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2299
2300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002301os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002302
2303static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002304os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002305{
2306 return os_forkpty_impl(module);
2307}
2308
2309#endif /* defined(HAVE_FORKPTY) */
2310
2311#if defined(HAVE_GETEGID)
2312
2313PyDoc_STRVAR(os_getegid__doc__,
2314"getegid($module, /)\n"
2315"--\n"
2316"\n"
2317"Return the current process\'s effective group id.");
2318
2319#define OS_GETEGID_METHODDEF \
2320 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2321
2322static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002323os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002324
2325static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002326os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002327{
2328 return os_getegid_impl(module);
2329}
2330
2331#endif /* defined(HAVE_GETEGID) */
2332
2333#if defined(HAVE_GETEUID)
2334
2335PyDoc_STRVAR(os_geteuid__doc__,
2336"geteuid($module, /)\n"
2337"--\n"
2338"\n"
2339"Return the current process\'s effective user id.");
2340
2341#define OS_GETEUID_METHODDEF \
2342 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2343
2344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002345os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002346
2347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002348os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002349{
2350 return os_geteuid_impl(module);
2351}
2352
2353#endif /* defined(HAVE_GETEUID) */
2354
2355#if defined(HAVE_GETGID)
2356
2357PyDoc_STRVAR(os_getgid__doc__,
2358"getgid($module, /)\n"
2359"--\n"
2360"\n"
2361"Return the current process\'s group id.");
2362
2363#define OS_GETGID_METHODDEF \
2364 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2365
2366static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002367os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002368
2369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002370os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002371{
2372 return os_getgid_impl(module);
2373}
2374
2375#endif /* defined(HAVE_GETGID) */
2376
Berker Peksag39404992016-09-15 20:45:16 +03002377#if defined(HAVE_GETPID)
2378
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002379PyDoc_STRVAR(os_getpid__doc__,
2380"getpid($module, /)\n"
2381"--\n"
2382"\n"
2383"Return the current process id.");
2384
2385#define OS_GETPID_METHODDEF \
2386 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2387
2388static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002389os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002390
2391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002392os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002393{
2394 return os_getpid_impl(module);
2395}
2396
Berker Peksag39404992016-09-15 20:45:16 +03002397#endif /* defined(HAVE_GETPID) */
2398
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002399#if defined(HAVE_GETGROUPS)
2400
2401PyDoc_STRVAR(os_getgroups__doc__,
2402"getgroups($module, /)\n"
2403"--\n"
2404"\n"
2405"Return list of supplemental group IDs for the process.");
2406
2407#define OS_GETGROUPS_METHODDEF \
2408 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2409
2410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002411os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002412
2413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002414os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002415{
2416 return os_getgroups_impl(module);
2417}
2418
2419#endif /* defined(HAVE_GETGROUPS) */
2420
2421#if defined(HAVE_GETPGID)
2422
2423PyDoc_STRVAR(os_getpgid__doc__,
2424"getpgid($module, /, pid)\n"
2425"--\n"
2426"\n"
2427"Call the system call getpgid(), and return the result.");
2428
2429#define OS_GETPGID_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002430 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002431
2432static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002433os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002434
2435static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002436os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002437{
2438 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002439 static const char * const _keywords[] = {"pid", NULL};
2440 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002441 pid_t pid;
2442
Victor Stinner3e1fad62017-01-17 01:29:01 +01002443 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002444 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002445 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002446 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002447 return_value = os_getpgid_impl(module, pid);
2448
2449exit:
2450 return return_value;
2451}
2452
2453#endif /* defined(HAVE_GETPGID) */
2454
2455#if defined(HAVE_GETPGRP)
2456
2457PyDoc_STRVAR(os_getpgrp__doc__,
2458"getpgrp($module, /)\n"
2459"--\n"
2460"\n"
2461"Return the current process group id.");
2462
2463#define OS_GETPGRP_METHODDEF \
2464 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2465
2466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002467os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002468
2469static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002470os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002471{
2472 return os_getpgrp_impl(module);
2473}
2474
2475#endif /* defined(HAVE_GETPGRP) */
2476
2477#if defined(HAVE_SETPGRP)
2478
2479PyDoc_STRVAR(os_setpgrp__doc__,
2480"setpgrp($module, /)\n"
2481"--\n"
2482"\n"
2483"Make the current process the leader of its process group.");
2484
2485#define OS_SETPGRP_METHODDEF \
2486 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2487
2488static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002489os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002490
2491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002492os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002493{
2494 return os_setpgrp_impl(module);
2495}
2496
2497#endif /* defined(HAVE_SETPGRP) */
2498
2499#if defined(HAVE_GETPPID)
2500
2501PyDoc_STRVAR(os_getppid__doc__,
2502"getppid($module, /)\n"
2503"--\n"
2504"\n"
2505"Return the parent\'s process id.\n"
2506"\n"
2507"If the parent process has already exited, Windows machines will still\n"
2508"return its id; others systems will return the id of the \'init\' process (1).");
2509
2510#define OS_GETPPID_METHODDEF \
2511 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2512
2513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002514os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002515
2516static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002517os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002518{
2519 return os_getppid_impl(module);
2520}
2521
2522#endif /* defined(HAVE_GETPPID) */
2523
2524#if defined(HAVE_GETLOGIN)
2525
2526PyDoc_STRVAR(os_getlogin__doc__,
2527"getlogin($module, /)\n"
2528"--\n"
2529"\n"
2530"Return the actual login name.");
2531
2532#define OS_GETLOGIN_METHODDEF \
2533 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2534
2535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002536os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002537
2538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002539os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002540{
2541 return os_getlogin_impl(module);
2542}
2543
2544#endif /* defined(HAVE_GETLOGIN) */
2545
2546#if defined(HAVE_GETUID)
2547
2548PyDoc_STRVAR(os_getuid__doc__,
2549"getuid($module, /)\n"
2550"--\n"
2551"\n"
2552"Return the current process\'s user id.");
2553
2554#define OS_GETUID_METHODDEF \
2555 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2556
2557static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002558os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002559
2560static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002561os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002562{
2563 return os_getuid_impl(module);
2564}
2565
2566#endif /* defined(HAVE_GETUID) */
2567
2568#if defined(HAVE_KILL)
2569
2570PyDoc_STRVAR(os_kill__doc__,
2571"kill($module, pid, signal, /)\n"
2572"--\n"
2573"\n"
2574"Kill a process with a signal.");
2575
2576#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002577 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002578
2579static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002580os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002581
2582static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002583os_kill(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002584{
2585 PyObject *return_value = NULL;
2586 pid_t pid;
2587 Py_ssize_t signal;
2588
Victor Stinner259f0e42017-01-17 01:35:17 +01002589 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002590 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002591 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002592 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002593
2594 if (!_PyArg_NoStackKeywords("kill", kwnames)) {
2595 goto exit;
2596 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002597 return_value = os_kill_impl(module, pid, signal);
2598
2599exit:
2600 return return_value;
2601}
2602
2603#endif /* defined(HAVE_KILL) */
2604
2605#if defined(HAVE_KILLPG)
2606
2607PyDoc_STRVAR(os_killpg__doc__,
2608"killpg($module, pgid, signal, /)\n"
2609"--\n"
2610"\n"
2611"Kill a process group with a signal.");
2612
2613#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002614 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002615
2616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002617os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002618
2619static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002620os_killpg(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002621{
2622 PyObject *return_value = NULL;
2623 pid_t pgid;
2624 int signal;
2625
Victor Stinner259f0e42017-01-17 01:35:17 +01002626 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002627 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002628 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002629 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002630
2631 if (!_PyArg_NoStackKeywords("killpg", kwnames)) {
2632 goto exit;
2633 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002634 return_value = os_killpg_impl(module, pgid, signal);
2635
2636exit:
2637 return return_value;
2638}
2639
2640#endif /* defined(HAVE_KILLPG) */
2641
2642#if defined(HAVE_PLOCK)
2643
2644PyDoc_STRVAR(os_plock__doc__,
2645"plock($module, op, /)\n"
2646"--\n"
2647"\n"
2648"Lock program segments into memory.\");");
2649
2650#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002651 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002652
2653static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002654os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002655
2656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002657os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002658{
2659 PyObject *return_value = NULL;
2660 int op;
2661
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002662 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002664 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002665 return_value = os_plock_impl(module, op);
2666
2667exit:
2668 return return_value;
2669}
2670
2671#endif /* defined(HAVE_PLOCK) */
2672
2673#if defined(HAVE_SETUID)
2674
2675PyDoc_STRVAR(os_setuid__doc__,
2676"setuid($module, uid, /)\n"
2677"--\n"
2678"\n"
2679"Set the current process\'s user id.");
2680
2681#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002682 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002683
2684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002685os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002686
2687static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002688os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002689{
2690 PyObject *return_value = NULL;
2691 uid_t uid;
2692
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002693 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002694 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002695 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002696 return_value = os_setuid_impl(module, uid);
2697
2698exit:
2699 return return_value;
2700}
2701
2702#endif /* defined(HAVE_SETUID) */
2703
2704#if defined(HAVE_SETEUID)
2705
2706PyDoc_STRVAR(os_seteuid__doc__,
2707"seteuid($module, euid, /)\n"
2708"--\n"
2709"\n"
2710"Set the current process\'s effective user id.");
2711
2712#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002713 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002714
2715static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002716os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002717
2718static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002719os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002720{
2721 PyObject *return_value = NULL;
2722 uid_t euid;
2723
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002724 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002725 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002726 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002727 return_value = os_seteuid_impl(module, euid);
2728
2729exit:
2730 return return_value;
2731}
2732
2733#endif /* defined(HAVE_SETEUID) */
2734
2735#if defined(HAVE_SETEGID)
2736
2737PyDoc_STRVAR(os_setegid__doc__,
2738"setegid($module, egid, /)\n"
2739"--\n"
2740"\n"
2741"Set the current process\'s effective group id.");
2742
2743#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002744 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002745
2746static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002747os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002748
2749static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002750os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002751{
2752 PyObject *return_value = NULL;
2753 gid_t egid;
2754
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002755 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
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_setegid_impl(module, egid);
2759
2760exit:
2761 return return_value;
2762}
2763
2764#endif /* defined(HAVE_SETEGID) */
2765
2766#if defined(HAVE_SETREUID)
2767
2768PyDoc_STRVAR(os_setreuid__doc__,
2769"setreuid($module, ruid, euid, /)\n"
2770"--\n"
2771"\n"
2772"Set the current process\'s real and effective user ids.");
2773
2774#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002775 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002776
2777static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002778os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002779
2780static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002781os_setreuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002782{
2783 PyObject *return_value = NULL;
2784 uid_t ruid;
2785 uid_t euid;
2786
Victor Stinner259f0e42017-01-17 01:35:17 +01002787 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002788 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002789 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002790 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002791
2792 if (!_PyArg_NoStackKeywords("setreuid", kwnames)) {
2793 goto exit;
2794 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002795 return_value = os_setreuid_impl(module, ruid, euid);
2796
2797exit:
2798 return return_value;
2799}
2800
2801#endif /* defined(HAVE_SETREUID) */
2802
2803#if defined(HAVE_SETREGID)
2804
2805PyDoc_STRVAR(os_setregid__doc__,
2806"setregid($module, rgid, egid, /)\n"
2807"--\n"
2808"\n"
2809"Set the current process\'s real and effective group ids.");
2810
2811#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002812 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002813
2814static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002815os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002816
2817static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002818os_setregid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002819{
2820 PyObject *return_value = NULL;
2821 gid_t rgid;
2822 gid_t egid;
2823
Victor Stinner259f0e42017-01-17 01:35:17 +01002824 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002825 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002826 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002827 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002828
2829 if (!_PyArg_NoStackKeywords("setregid", kwnames)) {
2830 goto exit;
2831 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002832 return_value = os_setregid_impl(module, rgid, egid);
2833
2834exit:
2835 return return_value;
2836}
2837
2838#endif /* defined(HAVE_SETREGID) */
2839
2840#if defined(HAVE_SETGID)
2841
2842PyDoc_STRVAR(os_setgid__doc__,
2843"setgid($module, gid, /)\n"
2844"--\n"
2845"\n"
2846"Set the current process\'s group id.");
2847
2848#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002849 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002850
2851static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002852os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002853
2854static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002855os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002856{
2857 PyObject *return_value = NULL;
2858 gid_t gid;
2859
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002860 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002861 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002862 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002863 return_value = os_setgid_impl(module, gid);
2864
2865exit:
2866 return return_value;
2867}
2868
2869#endif /* defined(HAVE_SETGID) */
2870
2871#if defined(HAVE_SETGROUPS)
2872
2873PyDoc_STRVAR(os_setgroups__doc__,
2874"setgroups($module, groups, /)\n"
2875"--\n"
2876"\n"
2877"Set the groups of the current process to list.");
2878
2879#define OS_SETGROUPS_METHODDEF \
2880 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2881
2882#endif /* defined(HAVE_SETGROUPS) */
2883
2884#if defined(HAVE_WAIT3)
2885
2886PyDoc_STRVAR(os_wait3__doc__,
2887"wait3($module, /, options)\n"
2888"--\n"
2889"\n"
2890"Wait for completion of a child process.\n"
2891"\n"
2892"Returns a tuple of information about the child process:\n"
2893" (pid, status, rusage)");
2894
2895#define OS_WAIT3_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002896 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002897
2898static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002899os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002900
2901static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002902os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002903{
2904 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002905 static const char * const _keywords[] = {"options", NULL};
2906 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002907 int options;
2908
Victor Stinner3e1fad62017-01-17 01:29:01 +01002909 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002910 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002911 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002912 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002913 return_value = os_wait3_impl(module, options);
2914
2915exit:
2916 return return_value;
2917}
2918
2919#endif /* defined(HAVE_WAIT3) */
2920
2921#if defined(HAVE_WAIT4)
2922
2923PyDoc_STRVAR(os_wait4__doc__,
2924"wait4($module, /, pid, options)\n"
2925"--\n"
2926"\n"
2927"Wait for completion of a specific child process.\n"
2928"\n"
2929"Returns a tuple of information about the child process:\n"
2930" (pid, status, rusage)");
2931
2932#define OS_WAIT4_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002933 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002934
2935static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002936os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002937
2938static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002939os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002940{
2941 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002942 static const char * const _keywords[] = {"pid", "options", NULL};
2943 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002944 pid_t pid;
2945 int options;
2946
Victor Stinner3e1fad62017-01-17 01:29:01 +01002947 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002948 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002949 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002950 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002951 return_value = os_wait4_impl(module, pid, options);
2952
2953exit:
2954 return return_value;
2955}
2956
2957#endif /* defined(HAVE_WAIT4) */
2958
2959#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2960
2961PyDoc_STRVAR(os_waitid__doc__,
2962"waitid($module, idtype, id, options, /)\n"
2963"--\n"
2964"\n"
2965"Returns the result of waiting for a process or processes.\n"
2966"\n"
2967" idtype\n"
2968" Must be one of be P_PID, P_PGID or P_ALL.\n"
2969" id\n"
2970" The id to wait on.\n"
2971" options\n"
2972" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2973" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2974"\n"
2975"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2976"no children in a waitable state.");
2977
2978#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002979 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002980
2981static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002982os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002983
2984static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002985os_waitid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002986{
2987 PyObject *return_value = NULL;
2988 idtype_t idtype;
2989 id_t id;
2990 int options;
2991
Victor Stinner259f0e42017-01-17 01:35:17 +01002992 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002993 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002994 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002995 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002996
2997 if (!_PyArg_NoStackKeywords("waitid", kwnames)) {
2998 goto exit;
2999 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003000 return_value = os_waitid_impl(module, idtype, id, options);
3001
3002exit:
3003 return return_value;
3004}
3005
3006#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3007
3008#if defined(HAVE_WAITPID)
3009
3010PyDoc_STRVAR(os_waitpid__doc__,
3011"waitpid($module, pid, options, /)\n"
3012"--\n"
3013"\n"
3014"Wait for completion of a given child process.\n"
3015"\n"
3016"Returns a tuple of information regarding the child process:\n"
3017" (pid, status)\n"
3018"\n"
3019"The options argument is ignored on Windows.");
3020
3021#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003022 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003023
3024static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003025os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003026
3027static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003028os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003029{
3030 PyObject *return_value = NULL;
3031 pid_t pid;
3032 int options;
3033
Victor Stinner259f0e42017-01-17 01:35:17 +01003034 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003035 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003036 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003037 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003038
3039 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3040 goto exit;
3041 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003042 return_value = os_waitpid_impl(module, pid, options);
3043
3044exit:
3045 return return_value;
3046}
3047
3048#endif /* defined(HAVE_WAITPID) */
3049
3050#if defined(HAVE_CWAIT)
3051
3052PyDoc_STRVAR(os_waitpid__doc__,
3053"waitpid($module, pid, options, /)\n"
3054"--\n"
3055"\n"
3056"Wait for completion of a given process.\n"
3057"\n"
3058"Returns a tuple of information regarding the process:\n"
3059" (pid, status << 8)\n"
3060"\n"
3061"The options argument is ignored on Windows.");
3062
3063#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003064 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003065
3066static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003067os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003068
3069static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003070os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003071{
3072 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003073 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003074 int options;
3075
Victor Stinner259f0e42017-01-17 01:35:17 +01003076 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003077 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003078 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003079 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003080
3081 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3082 goto exit;
3083 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003084 return_value = os_waitpid_impl(module, pid, options);
3085
3086exit:
3087 return return_value;
3088}
3089
3090#endif /* defined(HAVE_CWAIT) */
3091
3092#if defined(HAVE_WAIT)
3093
3094PyDoc_STRVAR(os_wait__doc__,
3095"wait($module, /)\n"
3096"--\n"
3097"\n"
3098"Wait for completion of a child process.\n"
3099"\n"
3100"Returns a tuple of information about the child process:\n"
3101" (pid, status)");
3102
3103#define OS_WAIT_METHODDEF \
3104 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3105
3106static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003107os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003108
3109static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003110os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003111{
3112 return os_wait_impl(module);
3113}
3114
3115#endif /* defined(HAVE_WAIT) */
3116
3117#if defined(HAVE_SYMLINK)
3118
3119PyDoc_STRVAR(os_symlink__doc__,
3120"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3121"--\n"
3122"\n"
3123"Create a symbolic link pointing to src named dst.\n"
3124"\n"
3125"target_is_directory is required on Windows if the target is to be\n"
3126" interpreted as a directory. (On Windows, symlink requires\n"
3127" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3128" target_is_directory is ignored on non-Windows platforms.\n"
3129"\n"
3130"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3131" and path should be relative; path will then be relative to that directory.\n"
3132"dir_fd may not be implemented on your platform.\n"
3133" If it is unavailable, using it will raise a NotImplementedError.");
3134
3135#define OS_SYMLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003136 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003137
3138static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003139os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003140 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003141
3142static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003143os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003144{
3145 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003146 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3147 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003148 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3149 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3150 int target_is_directory = 0;
3151 int dir_fd = DEFAULT_DIR_FD;
3152
Victor Stinner3e1fad62017-01-17 01:29:01 +01003153 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003154 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003155 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003156 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003157 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3158
3159exit:
3160 /* Cleanup for src */
3161 path_cleanup(&src);
3162 /* Cleanup for dst */
3163 path_cleanup(&dst);
3164
3165 return return_value;
3166}
3167
3168#endif /* defined(HAVE_SYMLINK) */
3169
3170#if defined(HAVE_TIMES)
3171
3172PyDoc_STRVAR(os_times__doc__,
3173"times($module, /)\n"
3174"--\n"
3175"\n"
3176"Return a collection containing process timing information.\n"
3177"\n"
3178"The object returned behaves like a named tuple with these fields:\n"
3179" (utime, stime, cutime, cstime, elapsed_time)\n"
3180"All fields are floating point numbers.");
3181
3182#define OS_TIMES_METHODDEF \
3183 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3184
3185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003186os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003187
3188static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003189os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003190{
3191 return os_times_impl(module);
3192}
3193
3194#endif /* defined(HAVE_TIMES) */
3195
3196#if defined(HAVE_GETSID)
3197
3198PyDoc_STRVAR(os_getsid__doc__,
3199"getsid($module, pid, /)\n"
3200"--\n"
3201"\n"
3202"Call the system call getsid(pid) and return the result.");
3203
3204#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003205 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003206
3207static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003208os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209
3210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003211os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003212{
3213 PyObject *return_value = NULL;
3214 pid_t pid;
3215
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003216 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003217 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003218 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003219 return_value = os_getsid_impl(module, pid);
3220
3221exit:
3222 return return_value;
3223}
3224
3225#endif /* defined(HAVE_GETSID) */
3226
3227#if defined(HAVE_SETSID)
3228
3229PyDoc_STRVAR(os_setsid__doc__,
3230"setsid($module, /)\n"
3231"--\n"
3232"\n"
3233"Call the system call setsid().");
3234
3235#define OS_SETSID_METHODDEF \
3236 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3237
3238static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003239os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003240
3241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003242os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003243{
3244 return os_setsid_impl(module);
3245}
3246
3247#endif /* defined(HAVE_SETSID) */
3248
3249#if defined(HAVE_SETPGID)
3250
3251PyDoc_STRVAR(os_setpgid__doc__,
3252"setpgid($module, pid, pgrp, /)\n"
3253"--\n"
3254"\n"
3255"Call the system call setpgid(pid, pgrp).");
3256
3257#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003258 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003259
3260static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003261os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262
3263static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003264os_setpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003265{
3266 PyObject *return_value = NULL;
3267 pid_t pid;
3268 pid_t pgrp;
3269
Victor Stinner259f0e42017-01-17 01:35:17 +01003270 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003271 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003272 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003273 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003274
3275 if (!_PyArg_NoStackKeywords("setpgid", kwnames)) {
3276 goto exit;
3277 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003278 return_value = os_setpgid_impl(module, pid, pgrp);
3279
3280exit:
3281 return return_value;
3282}
3283
3284#endif /* defined(HAVE_SETPGID) */
3285
3286#if defined(HAVE_TCGETPGRP)
3287
3288PyDoc_STRVAR(os_tcgetpgrp__doc__,
3289"tcgetpgrp($module, fd, /)\n"
3290"--\n"
3291"\n"
3292"Return the process group associated with the terminal specified by fd.");
3293
3294#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003295 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003296
3297static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003298os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003299
3300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003301os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003302{
3303 PyObject *return_value = NULL;
3304 int fd;
3305
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003306 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003307 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003308 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003309 return_value = os_tcgetpgrp_impl(module, fd);
3310
3311exit:
3312 return return_value;
3313}
3314
3315#endif /* defined(HAVE_TCGETPGRP) */
3316
3317#if defined(HAVE_TCSETPGRP)
3318
3319PyDoc_STRVAR(os_tcsetpgrp__doc__,
3320"tcsetpgrp($module, fd, pgid, /)\n"
3321"--\n"
3322"\n"
3323"Set the process group associated with the terminal specified by fd.");
3324
3325#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003326 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003327
3328static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003329os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003330
3331static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003332os_tcsetpgrp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003333{
3334 PyObject *return_value = NULL;
3335 int fd;
3336 pid_t pgid;
3337
Victor Stinner259f0e42017-01-17 01:35:17 +01003338 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003339 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003340 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003341 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003342
3343 if (!_PyArg_NoStackKeywords("tcsetpgrp", kwnames)) {
3344 goto exit;
3345 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003346 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3347
3348exit:
3349 return return_value;
3350}
3351
3352#endif /* defined(HAVE_TCSETPGRP) */
3353
3354PyDoc_STRVAR(os_open__doc__,
3355"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3356"--\n"
3357"\n"
3358"Open a file for low level IO. Returns a file descriptor (integer).\n"
3359"\n"
3360"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3361" and path should be relative; path will then be relative to that directory.\n"
3362"dir_fd may not be implemented on your platform.\n"
3363" If it is unavailable, using it will raise a NotImplementedError.");
3364
3365#define OS_OPEN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003366 {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003367
3368static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003369os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003370
3371static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003372os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003373{
3374 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003375 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3376 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003377 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3378 int flags;
3379 int mode = 511;
3380 int dir_fd = DEFAULT_DIR_FD;
3381 int _return_value;
3382
Victor Stinner3e1fad62017-01-17 01:29:01 +01003383 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003384 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003385 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003386 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003387 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003388 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003389 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003390 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003391 return_value = PyLong_FromLong((long)_return_value);
3392
3393exit:
3394 /* Cleanup for path */
3395 path_cleanup(&path);
3396
3397 return return_value;
3398}
3399
3400PyDoc_STRVAR(os_close__doc__,
3401"close($module, /, fd)\n"
3402"--\n"
3403"\n"
3404"Close a file descriptor.");
3405
3406#define OS_CLOSE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003407 {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003408
3409static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003410os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411
3412static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003413os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003414{
3415 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003416 static const char * const _keywords[] = {"fd", NULL};
3417 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003418 int fd;
3419
Victor Stinner3e1fad62017-01-17 01:29:01 +01003420 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003421 &fd)) {
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 = os_close_impl(module, fd);
3425
3426exit:
3427 return return_value;
3428}
3429
3430PyDoc_STRVAR(os_closerange__doc__,
3431"closerange($module, fd_low, fd_high, /)\n"
3432"--\n"
3433"\n"
3434"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3435
3436#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003437 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003438
3439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003440os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003441
3442static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003443os_closerange(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003444{
3445 PyObject *return_value = NULL;
3446 int fd_low;
3447 int fd_high;
3448
Victor Stinner259f0e42017-01-17 01:35:17 +01003449 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003450 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003451 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003452 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003453
3454 if (!_PyArg_NoStackKeywords("closerange", kwnames)) {
3455 goto exit;
3456 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003457 return_value = os_closerange_impl(module, fd_low, fd_high);
3458
3459exit:
3460 return return_value;
3461}
3462
3463PyDoc_STRVAR(os_dup__doc__,
3464"dup($module, fd, /)\n"
3465"--\n"
3466"\n"
3467"Return a duplicate of a file descriptor.");
3468
3469#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003470 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003471
3472static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003473os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003474
3475static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003476os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003477{
3478 PyObject *return_value = NULL;
3479 int fd;
3480 int _return_value;
3481
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003482 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003483 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003484 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003485 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003486 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003487 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003488 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003489 return_value = PyLong_FromLong((long)_return_value);
3490
3491exit:
3492 return return_value;
3493}
3494
3495PyDoc_STRVAR(os_dup2__doc__,
3496"dup2($module, /, fd, fd2, inheritable=True)\n"
3497"--\n"
3498"\n"
3499"Duplicate file descriptor.");
3500
3501#define OS_DUP2_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003502 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003503
3504static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003505os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003506
3507static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003508os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003509{
3510 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003511 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3512 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003513 int fd;
3514 int fd2;
3515 int inheritable = 1;
3516
Victor Stinner3e1fad62017-01-17 01:29:01 +01003517 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003518 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003519 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003520 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003521 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3522
3523exit:
3524 return return_value;
3525}
3526
3527#if defined(HAVE_LOCKF)
3528
3529PyDoc_STRVAR(os_lockf__doc__,
3530"lockf($module, fd, command, length, /)\n"
3531"--\n"
3532"\n"
3533"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3534"\n"
3535" fd\n"
3536" An open file descriptor.\n"
3537" command\n"
3538" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3539" length\n"
3540" The number of bytes to lock, starting at the current position.");
3541
3542#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003543 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003544
3545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003546os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003547
3548static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003549os_lockf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003550{
3551 PyObject *return_value = NULL;
3552 int fd;
3553 int command;
3554 Py_off_t length;
3555
Victor Stinner259f0e42017-01-17 01:35:17 +01003556 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003557 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003558 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003559 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003560
3561 if (!_PyArg_NoStackKeywords("lockf", kwnames)) {
3562 goto exit;
3563 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003564 return_value = os_lockf_impl(module, fd, command, length);
3565
3566exit:
3567 return return_value;
3568}
3569
3570#endif /* defined(HAVE_LOCKF) */
3571
3572PyDoc_STRVAR(os_lseek__doc__,
3573"lseek($module, fd, position, how, /)\n"
3574"--\n"
3575"\n"
3576"Set the position of a file descriptor. Return the new position.\n"
3577"\n"
3578"Return the new cursor position in number of bytes\n"
3579"relative to the beginning of the file.");
3580
3581#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003582 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003583
3584static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003585os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003586
3587static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003588os_lseek(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003589{
3590 PyObject *return_value = NULL;
3591 int fd;
3592 Py_off_t position;
3593 int how;
3594 Py_off_t _return_value;
3595
Victor Stinner259f0e42017-01-17 01:35:17 +01003596 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003597 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003598 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003599 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003600
3601 if (!_PyArg_NoStackKeywords("lseek", kwnames)) {
3602 goto exit;
3603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604 _return_value = os_lseek_impl(module, fd, position, how);
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_FromPy_off_t(_return_value);
3609
3610exit:
3611 return return_value;
3612}
3613
3614PyDoc_STRVAR(os_read__doc__,
3615"read($module, fd, length, /)\n"
3616"--\n"
3617"\n"
3618"Read from a file descriptor. Returns a bytes object.");
3619
3620#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003621 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003622
3623static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003624os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003625
3626static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003627os_read(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003628{
3629 PyObject *return_value = NULL;
3630 int fd;
3631 Py_ssize_t length;
3632
Victor Stinner259f0e42017-01-17 01:35:17 +01003633 if (!_PyArg_ParseStack(args, nargs, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003634 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003635 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003636 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003637
3638 if (!_PyArg_NoStackKeywords("read", kwnames)) {
3639 goto exit;
3640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003641 return_value = os_read_impl(module, fd, length);
3642
3643exit:
3644 return return_value;
3645}
3646
3647#if defined(HAVE_READV)
3648
3649PyDoc_STRVAR(os_readv__doc__,
3650"readv($module, fd, buffers, /)\n"
3651"--\n"
3652"\n"
3653"Read from a file descriptor fd into an iterable of buffers.\n"
3654"\n"
3655"The buffers should be mutable buffers accepting bytes.\n"
3656"readv will transfer data into each buffer until it is full\n"
3657"and then move on to the next buffer in the sequence to hold\n"
3658"the rest of the data.\n"
3659"\n"
3660"readv returns the total number of bytes read,\n"
3661"which may be less than the total capacity of all the buffers.");
3662
3663#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003664 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003665
3666static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003667os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003668
3669static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003670os_readv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003671{
3672 PyObject *return_value = NULL;
3673 int fd;
3674 PyObject *buffers;
3675 Py_ssize_t _return_value;
3676
Victor Stinner259f0e42017-01-17 01:35:17 +01003677 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003678 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003679 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003680 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003681
3682 if (!_PyArg_NoStackKeywords("readv", kwnames)) {
3683 goto exit;
3684 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003685 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003686 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003687 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003688 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003689 return_value = PyLong_FromSsize_t(_return_value);
3690
3691exit:
3692 return return_value;
3693}
3694
3695#endif /* defined(HAVE_READV) */
3696
3697#if defined(HAVE_PREAD)
3698
3699PyDoc_STRVAR(os_pread__doc__,
3700"pread($module, fd, length, offset, /)\n"
3701"--\n"
3702"\n"
3703"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3704"\n"
3705"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3706"the beginning of the file. The file offset remains unchanged.");
3707
3708#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003709 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003710
3711static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003712os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003713
3714static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003715os_pread(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003716{
3717 PyObject *return_value = NULL;
3718 int fd;
3719 int length;
3720 Py_off_t offset;
3721
Victor Stinner259f0e42017-01-17 01:35:17 +01003722 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003723 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003724 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003725 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003726
3727 if (!_PyArg_NoStackKeywords("pread", kwnames)) {
3728 goto exit;
3729 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003730 return_value = os_pread_impl(module, fd, length, offset);
3731
3732exit:
3733 return return_value;
3734}
3735
3736#endif /* defined(HAVE_PREAD) */
3737
3738PyDoc_STRVAR(os_write__doc__,
3739"write($module, fd, data, /)\n"
3740"--\n"
3741"\n"
3742"Write a bytes object to a file descriptor.");
3743
3744#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003745 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003746
3747static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003748os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003749
3750static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003751os_write(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003752{
3753 PyObject *return_value = NULL;
3754 int fd;
3755 Py_buffer data = {NULL, NULL};
3756 Py_ssize_t _return_value;
3757
Victor Stinner259f0e42017-01-17 01:35:17 +01003758 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003759 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003760 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003761 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003762
3763 if (!_PyArg_NoStackKeywords("write", kwnames)) {
3764 goto exit;
3765 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003766 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003767 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003768 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003769 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003770 return_value = PyLong_FromSsize_t(_return_value);
3771
3772exit:
3773 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003774 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003775 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003776 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003777
3778 return return_value;
3779}
3780
3781PyDoc_STRVAR(os_fstat__doc__,
3782"fstat($module, /, fd)\n"
3783"--\n"
3784"\n"
3785"Perform a stat system call on the given file descriptor.\n"
3786"\n"
3787"Like stat(), but for an open file descriptor.\n"
3788"Equivalent to os.stat(fd).");
3789
3790#define OS_FSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003791 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003792
3793static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003794os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003795
3796static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003797os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003798{
3799 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003800 static const char * const _keywords[] = {"fd", NULL};
3801 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003802 int fd;
3803
Victor Stinner3e1fad62017-01-17 01:29:01 +01003804 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003805 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003806 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003807 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003808 return_value = os_fstat_impl(module, fd);
3809
3810exit:
3811 return return_value;
3812}
3813
3814PyDoc_STRVAR(os_isatty__doc__,
3815"isatty($module, fd, /)\n"
3816"--\n"
3817"\n"
3818"Return True if the fd is connected to a terminal.\n"
3819"\n"
3820"Return True if the file descriptor is an open file descriptor\n"
3821"connected to the slave end of a terminal.");
3822
3823#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003824 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003825
3826static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003827os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003828
3829static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003830os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003831{
3832 PyObject *return_value = NULL;
3833 int fd;
3834 int _return_value;
3835
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003836 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003837 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003838 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003839 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003840 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003841 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003842 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003843 return_value = PyBool_FromLong((long)_return_value);
3844
3845exit:
3846 return return_value;
3847}
3848
3849#if defined(HAVE_PIPE)
3850
3851PyDoc_STRVAR(os_pipe__doc__,
3852"pipe($module, /)\n"
3853"--\n"
3854"\n"
3855"Create a pipe.\n"
3856"\n"
3857"Returns a tuple of two file descriptors:\n"
3858" (read_fd, write_fd)");
3859
3860#define OS_PIPE_METHODDEF \
3861 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3862
3863static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003864os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003865
3866static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003867os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003868{
3869 return os_pipe_impl(module);
3870}
3871
3872#endif /* defined(HAVE_PIPE) */
3873
3874#if defined(HAVE_PIPE2)
3875
3876PyDoc_STRVAR(os_pipe2__doc__,
3877"pipe2($module, flags, /)\n"
3878"--\n"
3879"\n"
3880"Create a pipe with flags set atomically.\n"
3881"\n"
3882"Returns a tuple of two file descriptors:\n"
3883" (read_fd, write_fd)\n"
3884"\n"
3885"flags can be constructed by ORing together one or more of these values:\n"
3886"O_NONBLOCK, O_CLOEXEC.");
3887
3888#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003889 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003890
3891static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003892os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003893
3894static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003895os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003896{
3897 PyObject *return_value = NULL;
3898 int flags;
3899
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003900 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003901 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003902 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003903 return_value = os_pipe2_impl(module, flags);
3904
3905exit:
3906 return return_value;
3907}
3908
3909#endif /* defined(HAVE_PIPE2) */
3910
3911#if defined(HAVE_WRITEV)
3912
3913PyDoc_STRVAR(os_writev__doc__,
3914"writev($module, fd, buffers, /)\n"
3915"--\n"
3916"\n"
3917"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3918"\n"
3919"Returns the total number of bytes written.\n"
3920"buffers must be a sequence of bytes-like objects.");
3921
3922#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003923 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003924
3925static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003926os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003927
3928static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003929os_writev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003930{
3931 PyObject *return_value = NULL;
3932 int fd;
3933 PyObject *buffers;
3934 Py_ssize_t _return_value;
3935
Victor Stinner259f0e42017-01-17 01:35:17 +01003936 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003937 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003938 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003939 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003940
3941 if (!_PyArg_NoStackKeywords("writev", kwnames)) {
3942 goto exit;
3943 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003944 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003945 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003946 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003947 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003948 return_value = PyLong_FromSsize_t(_return_value);
3949
3950exit:
3951 return return_value;
3952}
3953
3954#endif /* defined(HAVE_WRITEV) */
3955
3956#if defined(HAVE_PWRITE)
3957
3958PyDoc_STRVAR(os_pwrite__doc__,
3959"pwrite($module, fd, buffer, offset, /)\n"
3960"--\n"
3961"\n"
3962"Write bytes to a file descriptor starting at a particular offset.\n"
3963"\n"
3964"Write buffer to fd, starting at offset bytes from the beginning of\n"
3965"the file. Returns the number of bytes writte. Does not change the\n"
3966"current file offset.");
3967
3968#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003969 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003970
3971static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003972os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003973
3974static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003975os_pwrite(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976{
3977 PyObject *return_value = NULL;
3978 int fd;
3979 Py_buffer buffer = {NULL, NULL};
3980 Py_off_t offset;
3981 Py_ssize_t _return_value;
3982
Victor Stinner259f0e42017-01-17 01:35:17 +01003983 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003984 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003985 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003986 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003987
3988 if (!_PyArg_NoStackKeywords("pwrite", kwnames)) {
3989 goto exit;
3990 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003991 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003992 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003993 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003994 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003995 return_value = PyLong_FromSsize_t(_return_value);
3996
3997exit:
3998 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003999 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004000 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004001 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004002
4003 return return_value;
4004}
4005
4006#endif /* defined(HAVE_PWRITE) */
4007
4008#if defined(HAVE_MKFIFO)
4009
4010PyDoc_STRVAR(os_mkfifo__doc__,
4011"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4012"--\n"
4013"\n"
4014"Create a \"fifo\" (a POSIX named pipe).\n"
4015"\n"
4016"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4017" and path should be relative; path will then be relative to that directory.\n"
4018"dir_fd may not be implemented on your platform.\n"
4019" If it is unavailable, using it will raise a NotImplementedError.");
4020
4021#define OS_MKFIFO_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004022 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004023
4024static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004025os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004026
4027static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004028os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004029{
4030 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004031 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4032 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004033 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4034 int mode = 438;
4035 int dir_fd = DEFAULT_DIR_FD;
4036
Victor Stinner3e1fad62017-01-17 01:29:01 +01004037 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004038 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004039 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004040 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004041 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4042
4043exit:
4044 /* Cleanup for path */
4045 path_cleanup(&path);
4046
4047 return return_value;
4048}
4049
4050#endif /* defined(HAVE_MKFIFO) */
4051
4052#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4053
4054PyDoc_STRVAR(os_mknod__doc__,
4055"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4056"--\n"
4057"\n"
4058"Create a node in the file system.\n"
4059"\n"
4060"Create a node in the file system (file, device special file or named pipe)\n"
4061"at path. mode specifies both the permissions to use and the\n"
4062"type of node to be created, being combined (bitwise OR) with one of\n"
4063"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4064"device defines the newly created device special file (probably using\n"
4065"os.makedev()). Otherwise device is ignored.\n"
4066"\n"
4067"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4068" and path should be relative; path will then be relative to that directory.\n"
4069"dir_fd may not be implemented on your platform.\n"
4070" If it is unavailable, using it will raise a NotImplementedError.");
4071
4072#define OS_MKNOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004073 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074
4075static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004076os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004077 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004078
4079static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004080os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004081{
4082 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004083 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4084 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004085 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4086 int mode = 384;
4087 dev_t device = 0;
4088 int dir_fd = DEFAULT_DIR_FD;
4089
Victor Stinner3e1fad62017-01-17 01:29:01 +01004090 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004091 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004092 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004093 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004094 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4095
4096exit:
4097 /* Cleanup for path */
4098 path_cleanup(&path);
4099
4100 return return_value;
4101}
4102
4103#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4104
4105#if defined(HAVE_DEVICE_MACROS)
4106
4107PyDoc_STRVAR(os_major__doc__,
4108"major($module, device, /)\n"
4109"--\n"
4110"\n"
4111"Extracts a device major number from a raw device number.");
4112
4113#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004114 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004115
4116static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004117os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004118
4119static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004120os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004121{
4122 PyObject *return_value = NULL;
4123 dev_t device;
4124 unsigned int _return_value;
4125
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004126 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004127 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004128 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004129 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004130 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004131 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004132 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004133 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4134
4135exit:
4136 return return_value;
4137}
4138
4139#endif /* defined(HAVE_DEVICE_MACROS) */
4140
4141#if defined(HAVE_DEVICE_MACROS)
4142
4143PyDoc_STRVAR(os_minor__doc__,
4144"minor($module, device, /)\n"
4145"--\n"
4146"\n"
4147"Extracts a device minor number from a raw device number.");
4148
4149#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004150 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004151
4152static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004153os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004154
4155static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004156os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004157{
4158 PyObject *return_value = NULL;
4159 dev_t device;
4160 unsigned int _return_value;
4161
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004162 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004163 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004164 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004165 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004166 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004167 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004168 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004169 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4170
4171exit:
4172 return return_value;
4173}
4174
4175#endif /* defined(HAVE_DEVICE_MACROS) */
4176
4177#if defined(HAVE_DEVICE_MACROS)
4178
4179PyDoc_STRVAR(os_makedev__doc__,
4180"makedev($module, major, minor, /)\n"
4181"--\n"
4182"\n"
4183"Composes a raw device number from the major and minor device numbers.");
4184
4185#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004186 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004187
4188static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004189os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004190
4191static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004192os_makedev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004193{
4194 PyObject *return_value = NULL;
4195 int major;
4196 int minor;
4197 dev_t _return_value;
4198
Victor Stinner259f0e42017-01-17 01:35:17 +01004199 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004200 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004201 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004202 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004203
4204 if (!_PyArg_NoStackKeywords("makedev", kwnames)) {
4205 goto exit;
4206 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004207 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004208 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004209 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004210 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004211 return_value = _PyLong_FromDev(_return_value);
4212
4213exit:
4214 return return_value;
4215}
4216
4217#endif /* defined(HAVE_DEVICE_MACROS) */
4218
Steve Dowerf7377032015-04-12 15:44:54 -04004219#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004220
4221PyDoc_STRVAR(os_ftruncate__doc__,
4222"ftruncate($module, fd, length, /)\n"
4223"--\n"
4224"\n"
4225"Truncate a file, specified by file descriptor, to a specific length.");
4226
4227#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004228 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004229
4230static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004231os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004232
4233static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004234os_ftruncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004235{
4236 PyObject *return_value = NULL;
4237 int fd;
4238 Py_off_t length;
4239
Victor Stinner259f0e42017-01-17 01:35:17 +01004240 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004241 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004242 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004243 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004244
4245 if (!_PyArg_NoStackKeywords("ftruncate", kwnames)) {
4246 goto exit;
4247 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004248 return_value = os_ftruncate_impl(module, fd, length);
4249
4250exit:
4251 return return_value;
4252}
4253
Steve Dowerf7377032015-04-12 15:44:54 -04004254#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004255
Steve Dowerf7377032015-04-12 15:44:54 -04004256#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004257
4258PyDoc_STRVAR(os_truncate__doc__,
4259"truncate($module, /, path, length)\n"
4260"--\n"
4261"\n"
4262"Truncate a file, specified by path, to a specific length.\n"
4263"\n"
4264"On some platforms, path may also be specified as an open file descriptor.\n"
4265" If this functionality is unavailable, using it raises an exception.");
4266
4267#define OS_TRUNCATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004268 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004269
4270static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004271os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004272
4273static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004274os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004275{
4276 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004277 static const char * const _keywords[] = {"path", "length", NULL};
4278 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004279 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4280 Py_off_t length;
4281
Victor Stinner3e1fad62017-01-17 01:29:01 +01004282 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004283 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004284 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004285 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004286 return_value = os_truncate_impl(module, &path, length);
4287
4288exit:
4289 /* Cleanup for path */
4290 path_cleanup(&path);
4291
4292 return return_value;
4293}
4294
Steve Dowerf7377032015-04-12 15:44:54 -04004295#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004296
4297#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4298
4299PyDoc_STRVAR(os_posix_fallocate__doc__,
4300"posix_fallocate($module, fd, offset, length, /)\n"
4301"--\n"
4302"\n"
4303"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4304"\n"
4305"Ensure that the file specified by fd encompasses a range of bytes\n"
4306"starting at offset bytes from the beginning and continuing for length bytes.");
4307
4308#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004309 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004310
4311static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004312os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004313 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004314
4315static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004316os_posix_fallocate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004317{
4318 PyObject *return_value = NULL;
4319 int fd;
4320 Py_off_t offset;
4321 Py_off_t length;
4322
Victor Stinner259f0e42017-01-17 01:35:17 +01004323 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004324 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004325 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004326 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004327
4328 if (!_PyArg_NoStackKeywords("posix_fallocate", kwnames)) {
4329 goto exit;
4330 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004331 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4332
4333exit:
4334 return return_value;
4335}
4336
4337#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4338
4339#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4340
4341PyDoc_STRVAR(os_posix_fadvise__doc__,
4342"posix_fadvise($module, fd, offset, length, advice, /)\n"
4343"--\n"
4344"\n"
4345"Announce an intention to access data in a specific pattern.\n"
4346"\n"
4347"Announce an intention to access data in a specific pattern, thus allowing\n"
4348"the kernel to make optimizations.\n"
4349"The advice applies to the region of the file specified by fd starting at\n"
4350"offset and continuing for length bytes.\n"
4351"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4352"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4353"POSIX_FADV_DONTNEED.");
4354
4355#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004356 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004357
4358static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004359os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004360 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004361
4362static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004363os_posix_fadvise(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364{
4365 PyObject *return_value = NULL;
4366 int fd;
4367 Py_off_t offset;
4368 Py_off_t length;
4369 int advice;
4370
Victor Stinner259f0e42017-01-17 01:35:17 +01004371 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004372 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004373 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004374 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004375
4376 if (!_PyArg_NoStackKeywords("posix_fadvise", kwnames)) {
4377 goto exit;
4378 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004379 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4380
4381exit:
4382 return return_value;
4383}
4384
4385#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4386
4387#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4388
4389PyDoc_STRVAR(os_putenv__doc__,
4390"putenv($module, name, value, /)\n"
4391"--\n"
4392"\n"
4393"Change or add an environment variable.");
4394
4395#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004396 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004397
4398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004399os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004400
4401static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004402os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004403{
4404 PyObject *return_value = NULL;
4405 PyObject *name;
4406 PyObject *value;
4407
Victor Stinner259f0e42017-01-17 01:35:17 +01004408 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004409 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004410 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004411 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004412
4413 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4414 goto exit;
4415 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004416 return_value = os_putenv_impl(module, name, value);
4417
4418exit:
4419 return return_value;
4420}
4421
4422#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4423
4424#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4425
4426PyDoc_STRVAR(os_putenv__doc__,
4427"putenv($module, name, value, /)\n"
4428"--\n"
4429"\n"
4430"Change or add an environment variable.");
4431
4432#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004433 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004434
4435static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004436os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004437
4438static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004439os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004440{
4441 PyObject *return_value = NULL;
4442 PyObject *name = NULL;
4443 PyObject *value = NULL;
4444
Victor Stinner259f0e42017-01-17 01:35:17 +01004445 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004446 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004447 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004448 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004449
4450 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4451 goto exit;
4452 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004453 return_value = os_putenv_impl(module, name, value);
4454
4455exit:
4456 /* Cleanup for name */
4457 Py_XDECREF(name);
4458 /* Cleanup for value */
4459 Py_XDECREF(value);
4460
4461 return return_value;
4462}
4463
4464#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4465
4466#if defined(HAVE_UNSETENV)
4467
4468PyDoc_STRVAR(os_unsetenv__doc__,
4469"unsetenv($module, name, /)\n"
4470"--\n"
4471"\n"
4472"Delete an environment variable.");
4473
4474#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004475 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004476
4477static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004478os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004479
4480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004481os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004482{
4483 PyObject *return_value = NULL;
4484 PyObject *name = NULL;
4485
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004486 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004487 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004488 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004489 return_value = os_unsetenv_impl(module, name);
4490
4491exit:
4492 /* Cleanup for name */
4493 Py_XDECREF(name);
4494
4495 return return_value;
4496}
4497
4498#endif /* defined(HAVE_UNSETENV) */
4499
4500PyDoc_STRVAR(os_strerror__doc__,
4501"strerror($module, code, /)\n"
4502"--\n"
4503"\n"
4504"Translate an error code to a message string.");
4505
4506#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004507 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004508
4509static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004510os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004511
4512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004513os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004514{
4515 PyObject *return_value = NULL;
4516 int code;
4517
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004518 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004519 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004520 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004521 return_value = os_strerror_impl(module, code);
4522
4523exit:
4524 return return_value;
4525}
4526
4527#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4528
4529PyDoc_STRVAR(os_WCOREDUMP__doc__,
4530"WCOREDUMP($module, status, /)\n"
4531"--\n"
4532"\n"
4533"Return True if the process returning status was dumped to a core file.");
4534
4535#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004536 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004537
4538static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004539os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004540
4541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004542os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004543{
4544 PyObject *return_value = NULL;
4545 int status;
4546 int _return_value;
4547
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004548 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004549 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004550 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004551 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004552 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004553 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004554 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004555 return_value = PyBool_FromLong((long)_return_value);
4556
4557exit:
4558 return return_value;
4559}
4560
4561#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4562
4563#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4564
4565PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4566"WIFCONTINUED($module, /, status)\n"
4567"--\n"
4568"\n"
4569"Return True if a particular process was continued from a job control stop.\n"
4570"\n"
4571"Return True if the process returning status was continued from a\n"
4572"job control stop.");
4573
4574#define OS_WIFCONTINUED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004575 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004576
4577static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004578os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004579
4580static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004581os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004582{
4583 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004584 static const char * const _keywords[] = {"status", NULL};
4585 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004586 int status;
4587 int _return_value;
4588
Victor Stinner3e1fad62017-01-17 01:29:01 +01004589 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004590 &status)) {
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 = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004594 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004595 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004596 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004597 return_value = PyBool_FromLong((long)_return_value);
4598
4599exit:
4600 return return_value;
4601}
4602
4603#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4604
4605#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4606
4607PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4608"WIFSTOPPED($module, /, status)\n"
4609"--\n"
4610"\n"
4611"Return True if the process returning status was stopped.");
4612
4613#define OS_WIFSTOPPED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004614 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004615
4616static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004617os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004618
4619static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004620os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004621{
4622 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004623 static const char * const _keywords[] = {"status", NULL};
4624 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004625 int status;
4626 int _return_value;
4627
Victor Stinner3e1fad62017-01-17 01:29:01 +01004628 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004629 &status)) {
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 = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004633 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004634 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004635 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004636 return_value = PyBool_FromLong((long)_return_value);
4637
4638exit:
4639 return return_value;
4640}
4641
4642#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4643
4644#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4645
4646PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4647"WIFSIGNALED($module, /, status)\n"
4648"--\n"
4649"\n"
4650"Return True if the process returning status was terminated by a signal.");
4651
4652#define OS_WIFSIGNALED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004653 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004654
4655static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004656os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004657
4658static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004659os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004660{
4661 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004662 static const char * const _keywords[] = {"status", NULL};
4663 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004664 int status;
4665 int _return_value;
4666
Victor Stinner3e1fad62017-01-17 01:29:01 +01004667 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004668 &status)) {
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 = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004672 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004673 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004674 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004675 return_value = PyBool_FromLong((long)_return_value);
4676
4677exit:
4678 return return_value;
4679}
4680
4681#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4682
4683#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4684
4685PyDoc_STRVAR(os_WIFEXITED__doc__,
4686"WIFEXITED($module, /, status)\n"
4687"--\n"
4688"\n"
4689"Return True if the process returning status exited via the exit() system call.");
4690
4691#define OS_WIFEXITED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004692 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004693
4694static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004695os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004696
4697static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004698os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004699{
4700 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004701 static const char * const _keywords[] = {"status", NULL};
4702 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004703 int status;
4704 int _return_value;
4705
Victor Stinner3e1fad62017-01-17 01:29:01 +01004706 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004707 &status)) {
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 = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004711 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004712 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004713 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004714 return_value = PyBool_FromLong((long)_return_value);
4715
4716exit:
4717 return return_value;
4718}
4719
4720#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4721
4722#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4723
4724PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4725"WEXITSTATUS($module, /, status)\n"
4726"--\n"
4727"\n"
4728"Return the process return code from status.");
4729
4730#define OS_WEXITSTATUS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004731 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004732
4733static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004734os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004735
4736static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004737os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004738{
4739 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004740 static const char * const _keywords[] = {"status", NULL};
4741 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004742 int status;
4743 int _return_value;
4744
Victor Stinner3e1fad62017-01-17 01:29:01 +01004745 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004746 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004747 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004748 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004749 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004750 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004751 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004752 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004753 return_value = PyLong_FromLong((long)_return_value);
4754
4755exit:
4756 return return_value;
4757}
4758
4759#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4760
4761#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4762
4763PyDoc_STRVAR(os_WTERMSIG__doc__,
4764"WTERMSIG($module, /, status)\n"
4765"--\n"
4766"\n"
4767"Return the signal that terminated the process that provided the status value.");
4768
4769#define OS_WTERMSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004770 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004771
4772static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004773os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004774
4775static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004776os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004777{
4778 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004779 static const char * const _keywords[] = {"status", NULL};
4780 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004781 int status;
4782 int _return_value;
4783
Victor Stinner3e1fad62017-01-17 01:29:01 +01004784 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004785 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004786 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004787 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004788 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004789 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004790 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004791 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004792 return_value = PyLong_FromLong((long)_return_value);
4793
4794exit:
4795 return return_value;
4796}
4797
4798#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4799
4800#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4801
4802PyDoc_STRVAR(os_WSTOPSIG__doc__,
4803"WSTOPSIG($module, /, status)\n"
4804"--\n"
4805"\n"
4806"Return the signal that stopped the process that provided the status value.");
4807
4808#define OS_WSTOPSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004809 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004810
4811static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004812os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004813
4814static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004815os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004816{
4817 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004818 static const char * const _keywords[] = {"status", NULL};
4819 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004820 int status;
4821 int _return_value;
4822
Victor Stinner3e1fad62017-01-17 01:29:01 +01004823 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004824 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004825 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004826 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004827 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004828 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004829 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004830 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004831 return_value = PyLong_FromLong((long)_return_value);
4832
4833exit:
4834 return return_value;
4835}
4836
4837#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4838
4839#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4840
4841PyDoc_STRVAR(os_fstatvfs__doc__,
4842"fstatvfs($module, fd, /)\n"
4843"--\n"
4844"\n"
4845"Perform an fstatvfs system call on the given fd.\n"
4846"\n"
4847"Equivalent to statvfs(fd).");
4848
4849#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004850 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004851
4852static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004853os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004854
4855static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004856os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004857{
4858 PyObject *return_value = NULL;
4859 int fd;
4860
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004861 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004862 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004863 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004864 return_value = os_fstatvfs_impl(module, fd);
4865
4866exit:
4867 return return_value;
4868}
4869
4870#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4871
4872#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4873
4874PyDoc_STRVAR(os_statvfs__doc__,
4875"statvfs($module, /, path)\n"
4876"--\n"
4877"\n"
4878"Perform a statvfs system call on the given path.\n"
4879"\n"
4880"path may always be specified as a string.\n"
4881"On some platforms, path may also be specified as an open file descriptor.\n"
4882" If this functionality is unavailable, using it raises an exception.");
4883
4884#define OS_STATVFS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004885 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004886
4887static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004888os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004889
4890static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004891os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004892{
4893 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004894 static const char * const _keywords[] = {"path", NULL};
4895 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004896 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4897
Victor Stinner3e1fad62017-01-17 01:29:01 +01004898 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004899 path_converter, &path)) {
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 = os_statvfs_impl(module, &path);
4903
4904exit:
4905 /* Cleanup for path */
4906 path_cleanup(&path);
4907
4908 return return_value;
4909}
4910
4911#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4912
4913#if defined(MS_WINDOWS)
4914
4915PyDoc_STRVAR(os__getdiskusage__doc__,
4916"_getdiskusage($module, /, path)\n"
4917"--\n"
4918"\n"
4919"Return disk usage statistics about the given path as a (total, free) tuple.");
4920
4921#define OS__GETDISKUSAGE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004922 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004923
4924static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004925os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004926
4927static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004928os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004929{
4930 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004931 static const char * const _keywords[] = {"path", NULL};
4932 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004933 Py_UNICODE *path;
4934
Victor Stinner3e1fad62017-01-17 01:29:01 +01004935 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004936 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004937 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004938 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004939 return_value = os__getdiskusage_impl(module, path);
4940
4941exit:
4942 return return_value;
4943}
4944
4945#endif /* defined(MS_WINDOWS) */
4946
4947#if defined(HAVE_FPATHCONF)
4948
4949PyDoc_STRVAR(os_fpathconf__doc__,
4950"fpathconf($module, fd, name, /)\n"
4951"--\n"
4952"\n"
4953"Return the configuration limit name for the file descriptor fd.\n"
4954"\n"
4955"If there is no limit, return -1.");
4956
4957#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004958 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004959
4960static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004961os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004962
4963static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004964os_fpathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004965{
4966 PyObject *return_value = NULL;
4967 int fd;
4968 int name;
4969 long _return_value;
4970
Victor Stinner259f0e42017-01-17 01:35:17 +01004971 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004972 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004973 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004974 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004975
4976 if (!_PyArg_NoStackKeywords("fpathconf", kwnames)) {
4977 goto exit;
4978 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004979 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004980 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004981 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004982 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004983 return_value = PyLong_FromLong(_return_value);
4984
4985exit:
4986 return return_value;
4987}
4988
4989#endif /* defined(HAVE_FPATHCONF) */
4990
4991#if defined(HAVE_PATHCONF)
4992
4993PyDoc_STRVAR(os_pathconf__doc__,
4994"pathconf($module, /, path, name)\n"
4995"--\n"
4996"\n"
4997"Return the configuration limit name for the file or directory path.\n"
4998"\n"
4999"If there is no limit, return -1.\n"
5000"On some platforms, path may also be specified as an open file descriptor.\n"
5001" If this functionality is unavailable, using it raises an exception.");
5002
5003#define OS_PATHCONF_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005004 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005005
5006static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005007os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005008
5009static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005010os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005011{
5012 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005013 static const char * const _keywords[] = {"path", "name", NULL};
5014 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005015 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5016 int name;
5017 long _return_value;
5018
Victor Stinner3e1fad62017-01-17 01:29:01 +01005019 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005020 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005021 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005022 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005023 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005024 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005026 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005027 return_value = PyLong_FromLong(_return_value);
5028
5029exit:
5030 /* Cleanup for path */
5031 path_cleanup(&path);
5032
5033 return return_value;
5034}
5035
5036#endif /* defined(HAVE_PATHCONF) */
5037
5038#if defined(HAVE_CONFSTR)
5039
5040PyDoc_STRVAR(os_confstr__doc__,
5041"confstr($module, name, /)\n"
5042"--\n"
5043"\n"
5044"Return a string-valued system configuration variable.");
5045
5046#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005047 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005048
5049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005050os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005051
5052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005053os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005054{
5055 PyObject *return_value = NULL;
5056 int name;
5057
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005058 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005059 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005060 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005061 return_value = os_confstr_impl(module, name);
5062
5063exit:
5064 return return_value;
5065}
5066
5067#endif /* defined(HAVE_CONFSTR) */
5068
5069#if defined(HAVE_SYSCONF)
5070
5071PyDoc_STRVAR(os_sysconf__doc__,
5072"sysconf($module, name, /)\n"
5073"--\n"
5074"\n"
5075"Return an integer-valued system configuration variable.");
5076
5077#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005078 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005079
5080static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005081os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005082
5083static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005084os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005085{
5086 PyObject *return_value = NULL;
5087 int name;
5088 long _return_value;
5089
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005090 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005091 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005093 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005094 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005095 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005096 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005097 return_value = PyLong_FromLong(_return_value);
5098
5099exit:
5100 return return_value;
5101}
5102
5103#endif /* defined(HAVE_SYSCONF) */
5104
5105PyDoc_STRVAR(os_abort__doc__,
5106"abort($module, /)\n"
5107"--\n"
5108"\n"
5109"Abort the interpreter immediately.\n"
5110"\n"
5111"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5112"on the hosting operating system. This function never returns.");
5113
5114#define OS_ABORT_METHODDEF \
5115 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5116
5117static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005118os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005119
5120static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005121os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005122{
5123 return os_abort_impl(module);
5124}
5125
Steve Dowercc16be82016-09-08 10:35:16 -07005126#if defined(MS_WINDOWS)
5127
5128PyDoc_STRVAR(os_startfile__doc__,
5129"startfile($module, /, filepath, operation=None)\n"
5130"--\n"
5131"\n"
5132"startfile(filepath [, operation])\n"
5133"\n"
5134"Start a file with its associated application.\n"
5135"\n"
5136"When \"operation\" is not specified or \"open\", this acts like\n"
5137"double-clicking the file in Explorer, or giving the file name as an\n"
5138"argument to the DOS \"start\" command: the file is opened with whatever\n"
5139"application (if any) its extension is associated.\n"
5140"When another \"operation\" is given, it specifies what should be done with\n"
5141"the file. A typical operation is \"print\".\n"
5142"\n"
5143"startfile returns as soon as the associated application is launched.\n"
5144"There is no option to wait for the application to close, and no way\n"
5145"to retrieve the application\'s exit status.\n"
5146"\n"
5147"The filepath is relative to the current directory. If you want to use\n"
5148"an absolute path, make sure the first character is not a slash (\"/\");\n"
5149"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5150
5151#define OS_STARTFILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005152 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005153
5154static PyObject *
5155os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5156
5157static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005158os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005159{
5160 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005161 static const char * const _keywords[] = {"filepath", "operation", NULL};
5162 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005163 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5164 Py_UNICODE *operation = NULL;
5165
Victor Stinner3e1fad62017-01-17 01:29:01 +01005166 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005167 path_converter, &filepath, &operation)) {
5168 goto exit;
5169 }
5170 return_value = os_startfile_impl(module, &filepath, operation);
5171
5172exit:
5173 /* Cleanup for filepath */
5174 path_cleanup(&filepath);
5175
5176 return return_value;
5177}
5178
5179#endif /* defined(MS_WINDOWS) */
5180
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005181#if defined(HAVE_GETLOADAVG)
5182
5183PyDoc_STRVAR(os_getloadavg__doc__,
5184"getloadavg($module, /)\n"
5185"--\n"
5186"\n"
5187"Return average recent system load information.\n"
5188"\n"
5189"Return the number of processes in the system run queue averaged over\n"
5190"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5191"Raises OSError if the load average was unobtainable.");
5192
5193#define OS_GETLOADAVG_METHODDEF \
5194 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5195
5196static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005197os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005198
5199static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005200os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005201{
5202 return os_getloadavg_impl(module);
5203}
5204
5205#endif /* defined(HAVE_GETLOADAVG) */
5206
5207PyDoc_STRVAR(os_device_encoding__doc__,
5208"device_encoding($module, /, fd)\n"
5209"--\n"
5210"\n"
5211"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5212"\n"
5213"The file descriptor must be attached to a terminal.\n"
5214"If the device is not a terminal, return None.");
5215
5216#define OS_DEVICE_ENCODING_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005217 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005218
5219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005220os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005221
5222static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005223os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005224{
5225 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005226 static const char * const _keywords[] = {"fd", NULL};
5227 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005228 int fd;
5229
Victor Stinner3e1fad62017-01-17 01:29:01 +01005230 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005231 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005232 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005233 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005234 return_value = os_device_encoding_impl(module, fd);
5235
5236exit:
5237 return return_value;
5238}
5239
5240#if defined(HAVE_SETRESUID)
5241
5242PyDoc_STRVAR(os_setresuid__doc__,
5243"setresuid($module, ruid, euid, suid, /)\n"
5244"--\n"
5245"\n"
5246"Set the current process\'s real, effective, and saved user ids.");
5247
5248#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005249 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005250
5251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005252os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005253
5254static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005255os_setresuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005256{
5257 PyObject *return_value = NULL;
5258 uid_t ruid;
5259 uid_t euid;
5260 uid_t suid;
5261
Victor Stinner259f0e42017-01-17 01:35:17 +01005262 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005263 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005264 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005265 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005266
5267 if (!_PyArg_NoStackKeywords("setresuid", kwnames)) {
5268 goto exit;
5269 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005270 return_value = os_setresuid_impl(module, ruid, euid, suid);
5271
5272exit:
5273 return return_value;
5274}
5275
5276#endif /* defined(HAVE_SETRESUID) */
5277
5278#if defined(HAVE_SETRESGID)
5279
5280PyDoc_STRVAR(os_setresgid__doc__,
5281"setresgid($module, rgid, egid, sgid, /)\n"
5282"--\n"
5283"\n"
5284"Set the current process\'s real, effective, and saved group ids.");
5285
5286#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005287 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005288
5289static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005290os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005291
5292static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005293os_setresgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005294{
5295 PyObject *return_value = NULL;
5296 gid_t rgid;
5297 gid_t egid;
5298 gid_t sgid;
5299
Victor Stinner259f0e42017-01-17 01:35:17 +01005300 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005301 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005302 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005303 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005304
5305 if (!_PyArg_NoStackKeywords("setresgid", kwnames)) {
5306 goto exit;
5307 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005308 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5309
5310exit:
5311 return return_value;
5312}
5313
5314#endif /* defined(HAVE_SETRESGID) */
5315
5316#if defined(HAVE_GETRESUID)
5317
5318PyDoc_STRVAR(os_getresuid__doc__,
5319"getresuid($module, /)\n"
5320"--\n"
5321"\n"
5322"Return a tuple of the current process\'s real, effective, and saved user ids.");
5323
5324#define OS_GETRESUID_METHODDEF \
5325 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5326
5327static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005328os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005329
5330static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005331os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005332{
5333 return os_getresuid_impl(module);
5334}
5335
5336#endif /* defined(HAVE_GETRESUID) */
5337
5338#if defined(HAVE_GETRESGID)
5339
5340PyDoc_STRVAR(os_getresgid__doc__,
5341"getresgid($module, /)\n"
5342"--\n"
5343"\n"
5344"Return a tuple of the current process\'s real, effective, and saved group ids.");
5345
5346#define OS_GETRESGID_METHODDEF \
5347 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5348
5349static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005350os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005351
5352static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005353os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005354{
5355 return os_getresgid_impl(module);
5356}
5357
5358#endif /* defined(HAVE_GETRESGID) */
5359
5360#if defined(USE_XATTRS)
5361
5362PyDoc_STRVAR(os_getxattr__doc__,
5363"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5364"--\n"
5365"\n"
5366"Return the value of extended attribute attribute on path.\n"
5367"\n"
5368"path may be either a string or an open file descriptor.\n"
5369"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5370" link, getxattr will examine the symbolic link itself instead of the file\n"
5371" the link points to.");
5372
5373#define OS_GETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005374 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005375
5376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005377os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005378 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005379
5380static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005381os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005382{
5383 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005384 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5385 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005386 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5387 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5388 int follow_symlinks = 1;
5389
Victor Stinner3e1fad62017-01-17 01:29:01 +01005390 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005391 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005392 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005393 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005394 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5395
5396exit:
5397 /* Cleanup for path */
5398 path_cleanup(&path);
5399 /* Cleanup for attribute */
5400 path_cleanup(&attribute);
5401
5402 return return_value;
5403}
5404
5405#endif /* defined(USE_XATTRS) */
5406
5407#if defined(USE_XATTRS)
5408
5409PyDoc_STRVAR(os_setxattr__doc__,
5410"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5411" follow_symlinks=True)\n"
5412"--\n"
5413"\n"
5414"Set extended attribute attribute on path to value.\n"
5415"\n"
5416"path may be either a string or an open file descriptor.\n"
5417"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5418" link, setxattr will modify the symbolic link itself instead of the file\n"
5419" the link points to.");
5420
5421#define OS_SETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005422 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005423
5424static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005425os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005426 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005427
5428static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005429os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005430{
5431 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005432 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5433 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005434 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5435 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5436 Py_buffer value = {NULL, NULL};
5437 int flags = 0;
5438 int follow_symlinks = 1;
5439
Victor Stinner3e1fad62017-01-17 01:29:01 +01005440 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005441 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005442 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005443 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005444 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5445
5446exit:
5447 /* Cleanup for path */
5448 path_cleanup(&path);
5449 /* Cleanup for attribute */
5450 path_cleanup(&attribute);
5451 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005452 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005453 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005454 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005455
5456 return return_value;
5457}
5458
5459#endif /* defined(USE_XATTRS) */
5460
5461#if defined(USE_XATTRS)
5462
5463PyDoc_STRVAR(os_removexattr__doc__,
5464"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5465"--\n"
5466"\n"
5467"Remove extended attribute attribute on path.\n"
5468"\n"
5469"path may be either a string or an open file descriptor.\n"
5470"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5471" link, removexattr will modify the symbolic link itself instead of the file\n"
5472" the link points to.");
5473
5474#define OS_REMOVEXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005475 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005476
5477static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005478os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005479 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005480
5481static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005482os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483{
5484 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005485 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5486 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005487 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5488 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5489 int follow_symlinks = 1;
5490
Victor Stinner3e1fad62017-01-17 01:29:01 +01005491 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005492 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005493 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005494 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005495 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5496
5497exit:
5498 /* Cleanup for path */
5499 path_cleanup(&path);
5500 /* Cleanup for attribute */
5501 path_cleanup(&attribute);
5502
5503 return return_value;
5504}
5505
5506#endif /* defined(USE_XATTRS) */
5507
5508#if defined(USE_XATTRS)
5509
5510PyDoc_STRVAR(os_listxattr__doc__,
5511"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5512"--\n"
5513"\n"
5514"Return a list of extended attributes on path.\n"
5515"\n"
5516"path may be either None, a string, or an open file descriptor.\n"
5517"if path is None, listxattr will examine the current directory.\n"
5518"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5519" link, listxattr will examine the symbolic link itself instead of the file\n"
5520" the link points to.");
5521
5522#define OS_LISTXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005523 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005524
5525static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005526os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005527
5528static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005529os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005530{
5531 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005532 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5533 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005534 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5535 int follow_symlinks = 1;
5536
Victor Stinner3e1fad62017-01-17 01:29:01 +01005537 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005538 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005539 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005540 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005541 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5542
5543exit:
5544 /* Cleanup for path */
5545 path_cleanup(&path);
5546
5547 return return_value;
5548}
5549
5550#endif /* defined(USE_XATTRS) */
5551
5552PyDoc_STRVAR(os_urandom__doc__,
5553"urandom($module, size, /)\n"
5554"--\n"
5555"\n"
5556"Return a bytes object containing random bytes suitable for cryptographic use.");
5557
5558#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005559 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005560
5561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005562os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005563
5564static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005565os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005566{
5567 PyObject *return_value = NULL;
5568 Py_ssize_t size;
5569
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005570 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005571 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005572 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005573 return_value = os_urandom_impl(module, size);
5574
5575exit:
5576 return return_value;
5577}
5578
5579PyDoc_STRVAR(os_cpu_count__doc__,
5580"cpu_count($module, /)\n"
5581"--\n"
5582"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005583"Return the number of CPUs in the system; return None if indeterminable.\n"
5584"\n"
5585"This number is not equivalent to the number of CPUs the current process can\n"
5586"use. The number of usable CPUs can be obtained with\n"
5587"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005588
5589#define OS_CPU_COUNT_METHODDEF \
5590 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5591
5592static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005593os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005594
5595static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005596os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005597{
5598 return os_cpu_count_impl(module);
5599}
5600
5601PyDoc_STRVAR(os_get_inheritable__doc__,
5602"get_inheritable($module, fd, /)\n"
5603"--\n"
5604"\n"
5605"Get the close-on-exe flag of the specified file descriptor.");
5606
5607#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005608 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005609
5610static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005611os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005612
5613static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005614os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005615{
5616 PyObject *return_value = NULL;
5617 int fd;
5618 int _return_value;
5619
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005620 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005621 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005622 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005623 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005624 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005625 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005626 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005627 return_value = PyBool_FromLong((long)_return_value);
5628
5629exit:
5630 return return_value;
5631}
5632
5633PyDoc_STRVAR(os_set_inheritable__doc__,
5634"set_inheritable($module, fd, inheritable, /)\n"
5635"--\n"
5636"\n"
5637"Set the inheritable flag of the specified file descriptor.");
5638
5639#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005640 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005641
5642static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005643os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005644
5645static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005646os_set_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005647{
5648 PyObject *return_value = NULL;
5649 int fd;
5650 int inheritable;
5651
Victor Stinner259f0e42017-01-17 01:35:17 +01005652 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005653 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005654 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005655 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005656
5657 if (!_PyArg_NoStackKeywords("set_inheritable", kwnames)) {
5658 goto exit;
5659 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005660 return_value = os_set_inheritable_impl(module, fd, inheritable);
5661
5662exit:
5663 return return_value;
5664}
5665
5666#if defined(MS_WINDOWS)
5667
5668PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5669"get_handle_inheritable($module, handle, /)\n"
5670"--\n"
5671"\n"
5672"Get the close-on-exe flag of the specified file descriptor.");
5673
5674#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005675 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005676
5677static int
Victor Stinner581139c2016-09-06 15:54:20 -07005678os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005679
5680static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005681os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005682{
5683 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005684 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005685 int _return_value;
5686
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005687 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005688 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005689 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005690 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005691 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005692 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005693 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005694 return_value = PyBool_FromLong((long)_return_value);
5695
5696exit:
5697 return return_value;
5698}
5699
5700#endif /* defined(MS_WINDOWS) */
5701
5702#if defined(MS_WINDOWS)
5703
5704PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5705"set_handle_inheritable($module, handle, inheritable, /)\n"
5706"--\n"
5707"\n"
5708"Set the inheritable flag of the specified handle.");
5709
5710#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005711 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005712
5713static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005714os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005715 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005716
5717static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005718os_set_handle_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005719{
5720 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005721 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005722 int inheritable;
5723
Victor Stinner259f0e42017-01-17 01:35:17 +01005724 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005725 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005726 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005727 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005728
5729 if (!_PyArg_NoStackKeywords("set_handle_inheritable", kwnames)) {
5730 goto exit;
5731 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005732 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5733
5734exit:
5735 return return_value;
5736}
5737
5738#endif /* defined(MS_WINDOWS) */
5739
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005740PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5741"is_symlink($self, /)\n"
5742"--\n"
5743"\n"
5744"Return True if the entry is a symbolic link; cached per entry.");
5745
5746#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5747 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5748
5749static int
5750os_DirEntry_is_symlink_impl(DirEntry *self);
5751
5752static PyObject *
5753os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5754{
5755 PyObject *return_value = NULL;
5756 int _return_value;
5757
5758 _return_value = os_DirEntry_is_symlink_impl(self);
5759 if ((_return_value == -1) && PyErr_Occurred()) {
5760 goto exit;
5761 }
5762 return_value = PyBool_FromLong((long)_return_value);
5763
5764exit:
5765 return return_value;
5766}
5767
5768PyDoc_STRVAR(os_DirEntry_stat__doc__,
5769"stat($self, /, *, follow_symlinks=True)\n"
5770"--\n"
5771"\n"
5772"Return stat_result object for the entry; cached per entry.");
5773
5774#define OS_DIRENTRY_STAT_METHODDEF \
5775 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL, os_DirEntry_stat__doc__},
5776
5777static PyObject *
5778os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5779
5780static PyObject *
5781os_DirEntry_stat(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5782{
5783 PyObject *return_value = NULL;
5784 static const char * const _keywords[] = {"follow_symlinks", NULL};
5785 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5786 int follow_symlinks = 1;
5787
Victor Stinner3e1fad62017-01-17 01:29:01 +01005788 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005789 &follow_symlinks)) {
5790 goto exit;
5791 }
5792 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5793
5794exit:
5795 return return_value;
5796}
5797
5798PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5799"is_dir($self, /, *, follow_symlinks=True)\n"
5800"--\n"
5801"\n"
5802"Return True if the entry is a directory; cached per entry.");
5803
5804#define OS_DIRENTRY_IS_DIR_METHODDEF \
5805 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL, os_DirEntry_is_dir__doc__},
5806
5807static int
5808os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5809
5810static PyObject *
5811os_DirEntry_is_dir(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5812{
5813 PyObject *return_value = NULL;
5814 static const char * const _keywords[] = {"follow_symlinks", NULL};
5815 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5816 int follow_symlinks = 1;
5817 int _return_value;
5818
Victor Stinner3e1fad62017-01-17 01:29:01 +01005819 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005820 &follow_symlinks)) {
5821 goto exit;
5822 }
5823 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5824 if ((_return_value == -1) && PyErr_Occurred()) {
5825 goto exit;
5826 }
5827 return_value = PyBool_FromLong((long)_return_value);
5828
5829exit:
5830 return return_value;
5831}
5832
5833PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5834"is_file($self, /, *, follow_symlinks=True)\n"
5835"--\n"
5836"\n"
5837"Return True if the entry is a file; cached per entry.");
5838
5839#define OS_DIRENTRY_IS_FILE_METHODDEF \
5840 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL, os_DirEntry_is_file__doc__},
5841
5842static int
5843os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5844
5845static PyObject *
5846os_DirEntry_is_file(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5847{
5848 PyObject *return_value = NULL;
5849 static const char * const _keywords[] = {"follow_symlinks", NULL};
5850 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5851 int follow_symlinks = 1;
5852 int _return_value;
5853
Victor Stinner3e1fad62017-01-17 01:29:01 +01005854 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005855 &follow_symlinks)) {
5856 goto exit;
5857 }
5858 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5859 if ((_return_value == -1) && PyErr_Occurred()) {
5860 goto exit;
5861 }
5862 return_value = PyBool_FromLong((long)_return_value);
5863
5864exit:
5865 return return_value;
5866}
5867
5868PyDoc_STRVAR(os_DirEntry_inode__doc__,
5869"inode($self, /)\n"
5870"--\n"
5871"\n"
5872"Return inode of the entry; cached per entry.");
5873
5874#define OS_DIRENTRY_INODE_METHODDEF \
5875 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5876
5877static PyObject *
5878os_DirEntry_inode_impl(DirEntry *self);
5879
5880static PyObject *
5881os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5882{
5883 return os_DirEntry_inode_impl(self);
5884}
5885
5886PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5887"__fspath__($self, /)\n"
5888"--\n"
5889"\n"
5890"Returns the path for the entry.");
5891
5892#define OS_DIRENTRY___FSPATH___METHODDEF \
5893 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5894
5895static PyObject *
5896os_DirEntry___fspath___impl(DirEntry *self);
5897
5898static PyObject *
5899os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5900{
5901 return os_DirEntry___fspath___impl(self);
5902}
5903
5904PyDoc_STRVAR(os_scandir__doc__,
5905"scandir($module, /, path=None)\n"
5906"--\n"
5907"\n"
5908"Return an iterator of DirEntry objects for given path.\n"
5909"\n"
5910"path can be specified as either str, bytes or path-like object. If path\n"
5911"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5912"all other circumstances they will be str.\n"
5913"\n"
5914"If path is None, uses the path=\'.\'.");
5915
5916#define OS_SCANDIR_METHODDEF \
5917 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL, os_scandir__doc__},
5918
5919static PyObject *
5920os_scandir_impl(PyObject *module, path_t *path);
5921
5922static PyObject *
5923os_scandir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5924{
5925 PyObject *return_value = NULL;
5926 static const char * const _keywords[] = {"path", NULL};
5927 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
5928 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, 0);
5929
Victor Stinner3e1fad62017-01-17 01:29:01 +01005930 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005931 path_converter, &path)) {
5932 goto exit;
5933 }
5934 return_value = os_scandir_impl(module, &path);
5935
5936exit:
5937 /* Cleanup for path */
5938 path_cleanup(&path);
5939
5940 return return_value;
5941}
5942
Ethan Furman410ef8e2016-06-04 12:06:26 -07005943PyDoc_STRVAR(os_fspath__doc__,
5944"fspath($module, /, path)\n"
5945"--\n"
5946"\n"
5947"Return the file system path representation of the object.\n"
5948"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005949"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5950"object defines __fspath__(), then return the result of that method. All other\n"
5951"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005952
5953#define OS_FSPATH_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005954 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005955
5956static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005957os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005958
5959static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005960os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005961{
5962 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005963 static const char * const _keywords[] = {"path", NULL};
5964 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005965 PyObject *path;
5966
Victor Stinner3e1fad62017-01-17 01:29:01 +01005967 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005968 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005969 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005970 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005971 return_value = os_fspath_impl(module, path);
5972
5973exit:
5974 return return_value;
5975}
5976
Victor Stinner9b1f4742016-09-06 16:18:52 -07005977#if defined(HAVE_GETRANDOM_SYSCALL)
5978
5979PyDoc_STRVAR(os_getrandom__doc__,
5980"getrandom($module, /, size, flags=0)\n"
5981"--\n"
5982"\n"
5983"Obtain a series of random bytes.");
5984
5985#define OS_GETRANDOM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005986 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07005987
5988static PyObject *
5989os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
5990
5991static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005992os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07005993{
5994 PyObject *return_value = NULL;
5995 static const char * const _keywords[] = {"size", "flags", NULL};
5996 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
5997 Py_ssize_t size;
5998 int flags = 0;
5999
Victor Stinner3e1fad62017-01-17 01:29:01 +01006000 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006001 &size, &flags)) {
6002 goto exit;
6003 }
6004 return_value = os_getrandom_impl(module, size, flags);
6005
6006exit:
6007 return return_value;
6008}
6009
6010#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6011
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006012#ifndef OS_TTYNAME_METHODDEF
6013 #define OS_TTYNAME_METHODDEF
6014#endif /* !defined(OS_TTYNAME_METHODDEF) */
6015
6016#ifndef OS_CTERMID_METHODDEF
6017 #define OS_CTERMID_METHODDEF
6018#endif /* !defined(OS_CTERMID_METHODDEF) */
6019
6020#ifndef OS_FCHDIR_METHODDEF
6021 #define OS_FCHDIR_METHODDEF
6022#endif /* !defined(OS_FCHDIR_METHODDEF) */
6023
6024#ifndef OS_FCHMOD_METHODDEF
6025 #define OS_FCHMOD_METHODDEF
6026#endif /* !defined(OS_FCHMOD_METHODDEF) */
6027
6028#ifndef OS_LCHMOD_METHODDEF
6029 #define OS_LCHMOD_METHODDEF
6030#endif /* !defined(OS_LCHMOD_METHODDEF) */
6031
6032#ifndef OS_CHFLAGS_METHODDEF
6033 #define OS_CHFLAGS_METHODDEF
6034#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6035
6036#ifndef OS_LCHFLAGS_METHODDEF
6037 #define OS_LCHFLAGS_METHODDEF
6038#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6039
6040#ifndef OS_CHROOT_METHODDEF
6041 #define OS_CHROOT_METHODDEF
6042#endif /* !defined(OS_CHROOT_METHODDEF) */
6043
6044#ifndef OS_FSYNC_METHODDEF
6045 #define OS_FSYNC_METHODDEF
6046#endif /* !defined(OS_FSYNC_METHODDEF) */
6047
6048#ifndef OS_SYNC_METHODDEF
6049 #define OS_SYNC_METHODDEF
6050#endif /* !defined(OS_SYNC_METHODDEF) */
6051
6052#ifndef OS_FDATASYNC_METHODDEF
6053 #define OS_FDATASYNC_METHODDEF
6054#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6055
6056#ifndef OS_CHOWN_METHODDEF
6057 #define OS_CHOWN_METHODDEF
6058#endif /* !defined(OS_CHOWN_METHODDEF) */
6059
6060#ifndef OS_FCHOWN_METHODDEF
6061 #define OS_FCHOWN_METHODDEF
6062#endif /* !defined(OS_FCHOWN_METHODDEF) */
6063
6064#ifndef OS_LCHOWN_METHODDEF
6065 #define OS_LCHOWN_METHODDEF
6066#endif /* !defined(OS_LCHOWN_METHODDEF) */
6067
6068#ifndef OS_LINK_METHODDEF
6069 #define OS_LINK_METHODDEF
6070#endif /* !defined(OS_LINK_METHODDEF) */
6071
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006072#ifndef OS__GETFULLPATHNAME_METHODDEF
6073 #define OS__GETFULLPATHNAME_METHODDEF
6074#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6075
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006076#ifndef OS__GETFINALPATHNAME_METHODDEF
6077 #define OS__GETFINALPATHNAME_METHODDEF
6078#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6079
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006080#ifndef OS__ISDIR_METHODDEF
6081 #define OS__ISDIR_METHODDEF
6082#endif /* !defined(OS__ISDIR_METHODDEF) */
6083
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006084#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6085 #define OS__GETVOLUMEPATHNAME_METHODDEF
6086#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6087
6088#ifndef OS_NICE_METHODDEF
6089 #define OS_NICE_METHODDEF
6090#endif /* !defined(OS_NICE_METHODDEF) */
6091
6092#ifndef OS_GETPRIORITY_METHODDEF
6093 #define OS_GETPRIORITY_METHODDEF
6094#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6095
6096#ifndef OS_SETPRIORITY_METHODDEF
6097 #define OS_SETPRIORITY_METHODDEF
6098#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6099
6100#ifndef OS_SYSTEM_METHODDEF
6101 #define OS_SYSTEM_METHODDEF
6102#endif /* !defined(OS_SYSTEM_METHODDEF) */
6103
6104#ifndef OS_UNAME_METHODDEF
6105 #define OS_UNAME_METHODDEF
6106#endif /* !defined(OS_UNAME_METHODDEF) */
6107
6108#ifndef OS_EXECV_METHODDEF
6109 #define OS_EXECV_METHODDEF
6110#endif /* !defined(OS_EXECV_METHODDEF) */
6111
6112#ifndef OS_EXECVE_METHODDEF
6113 #define OS_EXECVE_METHODDEF
6114#endif /* !defined(OS_EXECVE_METHODDEF) */
6115
6116#ifndef OS_SPAWNV_METHODDEF
6117 #define OS_SPAWNV_METHODDEF
6118#endif /* !defined(OS_SPAWNV_METHODDEF) */
6119
6120#ifndef OS_SPAWNVE_METHODDEF
6121 #define OS_SPAWNVE_METHODDEF
6122#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6123
6124#ifndef OS_FORK1_METHODDEF
6125 #define OS_FORK1_METHODDEF
6126#endif /* !defined(OS_FORK1_METHODDEF) */
6127
6128#ifndef OS_FORK_METHODDEF
6129 #define OS_FORK_METHODDEF
6130#endif /* !defined(OS_FORK_METHODDEF) */
6131
6132#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6133 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6134#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6135
6136#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6137 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6138#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6139
6140#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6141 #define OS_SCHED_GETSCHEDULER_METHODDEF
6142#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6143
6144#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6145 #define OS_SCHED_SETSCHEDULER_METHODDEF
6146#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6147
6148#ifndef OS_SCHED_GETPARAM_METHODDEF
6149 #define OS_SCHED_GETPARAM_METHODDEF
6150#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6151
6152#ifndef OS_SCHED_SETPARAM_METHODDEF
6153 #define OS_SCHED_SETPARAM_METHODDEF
6154#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6155
6156#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6157 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6158#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6159
6160#ifndef OS_SCHED_YIELD_METHODDEF
6161 #define OS_SCHED_YIELD_METHODDEF
6162#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6163
6164#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6165 #define OS_SCHED_SETAFFINITY_METHODDEF
6166#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6167
6168#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6169 #define OS_SCHED_GETAFFINITY_METHODDEF
6170#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6171
6172#ifndef OS_OPENPTY_METHODDEF
6173 #define OS_OPENPTY_METHODDEF
6174#endif /* !defined(OS_OPENPTY_METHODDEF) */
6175
6176#ifndef OS_FORKPTY_METHODDEF
6177 #define OS_FORKPTY_METHODDEF
6178#endif /* !defined(OS_FORKPTY_METHODDEF) */
6179
6180#ifndef OS_GETEGID_METHODDEF
6181 #define OS_GETEGID_METHODDEF
6182#endif /* !defined(OS_GETEGID_METHODDEF) */
6183
6184#ifndef OS_GETEUID_METHODDEF
6185 #define OS_GETEUID_METHODDEF
6186#endif /* !defined(OS_GETEUID_METHODDEF) */
6187
6188#ifndef OS_GETGID_METHODDEF
6189 #define OS_GETGID_METHODDEF
6190#endif /* !defined(OS_GETGID_METHODDEF) */
6191
Berker Peksag39404992016-09-15 20:45:16 +03006192#ifndef OS_GETPID_METHODDEF
6193 #define OS_GETPID_METHODDEF
6194#endif /* !defined(OS_GETPID_METHODDEF) */
6195
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006196#ifndef OS_GETGROUPS_METHODDEF
6197 #define OS_GETGROUPS_METHODDEF
6198#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6199
6200#ifndef OS_GETPGID_METHODDEF
6201 #define OS_GETPGID_METHODDEF
6202#endif /* !defined(OS_GETPGID_METHODDEF) */
6203
6204#ifndef OS_GETPGRP_METHODDEF
6205 #define OS_GETPGRP_METHODDEF
6206#endif /* !defined(OS_GETPGRP_METHODDEF) */
6207
6208#ifndef OS_SETPGRP_METHODDEF
6209 #define OS_SETPGRP_METHODDEF
6210#endif /* !defined(OS_SETPGRP_METHODDEF) */
6211
6212#ifndef OS_GETPPID_METHODDEF
6213 #define OS_GETPPID_METHODDEF
6214#endif /* !defined(OS_GETPPID_METHODDEF) */
6215
6216#ifndef OS_GETLOGIN_METHODDEF
6217 #define OS_GETLOGIN_METHODDEF
6218#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6219
6220#ifndef OS_GETUID_METHODDEF
6221 #define OS_GETUID_METHODDEF
6222#endif /* !defined(OS_GETUID_METHODDEF) */
6223
6224#ifndef OS_KILL_METHODDEF
6225 #define OS_KILL_METHODDEF
6226#endif /* !defined(OS_KILL_METHODDEF) */
6227
6228#ifndef OS_KILLPG_METHODDEF
6229 #define OS_KILLPG_METHODDEF
6230#endif /* !defined(OS_KILLPG_METHODDEF) */
6231
6232#ifndef OS_PLOCK_METHODDEF
6233 #define OS_PLOCK_METHODDEF
6234#endif /* !defined(OS_PLOCK_METHODDEF) */
6235
6236#ifndef OS_SETUID_METHODDEF
6237 #define OS_SETUID_METHODDEF
6238#endif /* !defined(OS_SETUID_METHODDEF) */
6239
6240#ifndef OS_SETEUID_METHODDEF
6241 #define OS_SETEUID_METHODDEF
6242#endif /* !defined(OS_SETEUID_METHODDEF) */
6243
6244#ifndef OS_SETEGID_METHODDEF
6245 #define OS_SETEGID_METHODDEF
6246#endif /* !defined(OS_SETEGID_METHODDEF) */
6247
6248#ifndef OS_SETREUID_METHODDEF
6249 #define OS_SETREUID_METHODDEF
6250#endif /* !defined(OS_SETREUID_METHODDEF) */
6251
6252#ifndef OS_SETREGID_METHODDEF
6253 #define OS_SETREGID_METHODDEF
6254#endif /* !defined(OS_SETREGID_METHODDEF) */
6255
6256#ifndef OS_SETGID_METHODDEF
6257 #define OS_SETGID_METHODDEF
6258#endif /* !defined(OS_SETGID_METHODDEF) */
6259
6260#ifndef OS_SETGROUPS_METHODDEF
6261 #define OS_SETGROUPS_METHODDEF
6262#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6263
6264#ifndef OS_WAIT3_METHODDEF
6265 #define OS_WAIT3_METHODDEF
6266#endif /* !defined(OS_WAIT3_METHODDEF) */
6267
6268#ifndef OS_WAIT4_METHODDEF
6269 #define OS_WAIT4_METHODDEF
6270#endif /* !defined(OS_WAIT4_METHODDEF) */
6271
6272#ifndef OS_WAITID_METHODDEF
6273 #define OS_WAITID_METHODDEF
6274#endif /* !defined(OS_WAITID_METHODDEF) */
6275
6276#ifndef OS_WAITPID_METHODDEF
6277 #define OS_WAITPID_METHODDEF
6278#endif /* !defined(OS_WAITPID_METHODDEF) */
6279
6280#ifndef OS_WAIT_METHODDEF
6281 #define OS_WAIT_METHODDEF
6282#endif /* !defined(OS_WAIT_METHODDEF) */
6283
6284#ifndef OS_SYMLINK_METHODDEF
6285 #define OS_SYMLINK_METHODDEF
6286#endif /* !defined(OS_SYMLINK_METHODDEF) */
6287
6288#ifndef OS_TIMES_METHODDEF
6289 #define OS_TIMES_METHODDEF
6290#endif /* !defined(OS_TIMES_METHODDEF) */
6291
6292#ifndef OS_GETSID_METHODDEF
6293 #define OS_GETSID_METHODDEF
6294#endif /* !defined(OS_GETSID_METHODDEF) */
6295
6296#ifndef OS_SETSID_METHODDEF
6297 #define OS_SETSID_METHODDEF
6298#endif /* !defined(OS_SETSID_METHODDEF) */
6299
6300#ifndef OS_SETPGID_METHODDEF
6301 #define OS_SETPGID_METHODDEF
6302#endif /* !defined(OS_SETPGID_METHODDEF) */
6303
6304#ifndef OS_TCGETPGRP_METHODDEF
6305 #define OS_TCGETPGRP_METHODDEF
6306#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6307
6308#ifndef OS_TCSETPGRP_METHODDEF
6309 #define OS_TCSETPGRP_METHODDEF
6310#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6311
6312#ifndef OS_LOCKF_METHODDEF
6313 #define OS_LOCKF_METHODDEF
6314#endif /* !defined(OS_LOCKF_METHODDEF) */
6315
6316#ifndef OS_READV_METHODDEF
6317 #define OS_READV_METHODDEF
6318#endif /* !defined(OS_READV_METHODDEF) */
6319
6320#ifndef OS_PREAD_METHODDEF
6321 #define OS_PREAD_METHODDEF
6322#endif /* !defined(OS_PREAD_METHODDEF) */
6323
6324#ifndef OS_PIPE_METHODDEF
6325 #define OS_PIPE_METHODDEF
6326#endif /* !defined(OS_PIPE_METHODDEF) */
6327
6328#ifndef OS_PIPE2_METHODDEF
6329 #define OS_PIPE2_METHODDEF
6330#endif /* !defined(OS_PIPE2_METHODDEF) */
6331
6332#ifndef OS_WRITEV_METHODDEF
6333 #define OS_WRITEV_METHODDEF
6334#endif /* !defined(OS_WRITEV_METHODDEF) */
6335
6336#ifndef OS_PWRITE_METHODDEF
6337 #define OS_PWRITE_METHODDEF
6338#endif /* !defined(OS_PWRITE_METHODDEF) */
6339
6340#ifndef OS_MKFIFO_METHODDEF
6341 #define OS_MKFIFO_METHODDEF
6342#endif /* !defined(OS_MKFIFO_METHODDEF) */
6343
6344#ifndef OS_MKNOD_METHODDEF
6345 #define OS_MKNOD_METHODDEF
6346#endif /* !defined(OS_MKNOD_METHODDEF) */
6347
6348#ifndef OS_MAJOR_METHODDEF
6349 #define OS_MAJOR_METHODDEF
6350#endif /* !defined(OS_MAJOR_METHODDEF) */
6351
6352#ifndef OS_MINOR_METHODDEF
6353 #define OS_MINOR_METHODDEF
6354#endif /* !defined(OS_MINOR_METHODDEF) */
6355
6356#ifndef OS_MAKEDEV_METHODDEF
6357 #define OS_MAKEDEV_METHODDEF
6358#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6359
6360#ifndef OS_FTRUNCATE_METHODDEF
6361 #define OS_FTRUNCATE_METHODDEF
6362#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6363
6364#ifndef OS_TRUNCATE_METHODDEF
6365 #define OS_TRUNCATE_METHODDEF
6366#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6367
6368#ifndef OS_POSIX_FALLOCATE_METHODDEF
6369 #define OS_POSIX_FALLOCATE_METHODDEF
6370#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6371
6372#ifndef OS_POSIX_FADVISE_METHODDEF
6373 #define OS_POSIX_FADVISE_METHODDEF
6374#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6375
6376#ifndef OS_PUTENV_METHODDEF
6377 #define OS_PUTENV_METHODDEF
6378#endif /* !defined(OS_PUTENV_METHODDEF) */
6379
6380#ifndef OS_UNSETENV_METHODDEF
6381 #define OS_UNSETENV_METHODDEF
6382#endif /* !defined(OS_UNSETENV_METHODDEF) */
6383
6384#ifndef OS_WCOREDUMP_METHODDEF
6385 #define OS_WCOREDUMP_METHODDEF
6386#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6387
6388#ifndef OS_WIFCONTINUED_METHODDEF
6389 #define OS_WIFCONTINUED_METHODDEF
6390#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6391
6392#ifndef OS_WIFSTOPPED_METHODDEF
6393 #define OS_WIFSTOPPED_METHODDEF
6394#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6395
6396#ifndef OS_WIFSIGNALED_METHODDEF
6397 #define OS_WIFSIGNALED_METHODDEF
6398#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6399
6400#ifndef OS_WIFEXITED_METHODDEF
6401 #define OS_WIFEXITED_METHODDEF
6402#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6403
6404#ifndef OS_WEXITSTATUS_METHODDEF
6405 #define OS_WEXITSTATUS_METHODDEF
6406#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6407
6408#ifndef OS_WTERMSIG_METHODDEF
6409 #define OS_WTERMSIG_METHODDEF
6410#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6411
6412#ifndef OS_WSTOPSIG_METHODDEF
6413 #define OS_WSTOPSIG_METHODDEF
6414#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6415
6416#ifndef OS_FSTATVFS_METHODDEF
6417 #define OS_FSTATVFS_METHODDEF
6418#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6419
6420#ifndef OS_STATVFS_METHODDEF
6421 #define OS_STATVFS_METHODDEF
6422#endif /* !defined(OS_STATVFS_METHODDEF) */
6423
6424#ifndef OS__GETDISKUSAGE_METHODDEF
6425 #define OS__GETDISKUSAGE_METHODDEF
6426#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6427
6428#ifndef OS_FPATHCONF_METHODDEF
6429 #define OS_FPATHCONF_METHODDEF
6430#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6431
6432#ifndef OS_PATHCONF_METHODDEF
6433 #define OS_PATHCONF_METHODDEF
6434#endif /* !defined(OS_PATHCONF_METHODDEF) */
6435
6436#ifndef OS_CONFSTR_METHODDEF
6437 #define OS_CONFSTR_METHODDEF
6438#endif /* !defined(OS_CONFSTR_METHODDEF) */
6439
6440#ifndef OS_SYSCONF_METHODDEF
6441 #define OS_SYSCONF_METHODDEF
6442#endif /* !defined(OS_SYSCONF_METHODDEF) */
6443
Steve Dowercc16be82016-09-08 10:35:16 -07006444#ifndef OS_STARTFILE_METHODDEF
6445 #define OS_STARTFILE_METHODDEF
6446#endif /* !defined(OS_STARTFILE_METHODDEF) */
6447
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006448#ifndef OS_GETLOADAVG_METHODDEF
6449 #define OS_GETLOADAVG_METHODDEF
6450#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6451
6452#ifndef OS_SETRESUID_METHODDEF
6453 #define OS_SETRESUID_METHODDEF
6454#endif /* !defined(OS_SETRESUID_METHODDEF) */
6455
6456#ifndef OS_SETRESGID_METHODDEF
6457 #define OS_SETRESGID_METHODDEF
6458#endif /* !defined(OS_SETRESGID_METHODDEF) */
6459
6460#ifndef OS_GETRESUID_METHODDEF
6461 #define OS_GETRESUID_METHODDEF
6462#endif /* !defined(OS_GETRESUID_METHODDEF) */
6463
6464#ifndef OS_GETRESGID_METHODDEF
6465 #define OS_GETRESGID_METHODDEF
6466#endif /* !defined(OS_GETRESGID_METHODDEF) */
6467
6468#ifndef OS_GETXATTR_METHODDEF
6469 #define OS_GETXATTR_METHODDEF
6470#endif /* !defined(OS_GETXATTR_METHODDEF) */
6471
6472#ifndef OS_SETXATTR_METHODDEF
6473 #define OS_SETXATTR_METHODDEF
6474#endif /* !defined(OS_SETXATTR_METHODDEF) */
6475
6476#ifndef OS_REMOVEXATTR_METHODDEF
6477 #define OS_REMOVEXATTR_METHODDEF
6478#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6479
6480#ifndef OS_LISTXATTR_METHODDEF
6481 #define OS_LISTXATTR_METHODDEF
6482#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6483
6484#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6485 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6486#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6487
6488#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6489 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6490#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006491
6492#ifndef OS_GETRANDOM_METHODDEF
6493 #define OS_GETRANDOM_METHODDEF
6494#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Victor Stinner259f0e42017-01-17 01:35:17 +01006495/*[clinic end generated code: output=30cdd28fc524f2fb input=a9049054013a1b77]*/