blob: 2c919e18795c7f0f9b3bf3d767e5f56e7c252cd0 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(os_stat__doc__,
6"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
7"--\n"
8"\n"
9"Perform a stat system call on the given path.\n"
10"\n"
11" path\n"
Xiang Zhang4459e002017-01-22 13:04:17 +080012" Path to be examined; can be string, bytes, path-like object or\n"
13" open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030014" dir_fd\n"
15" If not None, it should be a file descriptor open to a directory,\n"
16" and path should be a relative string; path will then be relative to\n"
17" that directory.\n"
18" follow_symlinks\n"
19" If False, and the last element of the path is a symbolic link,\n"
20" stat will examine the symbolic link itself instead of the file\n"
21" the link points to.\n"
22"\n"
23"dir_fd and follow_symlinks may not be implemented\n"
24" on your platform. If they are unavailable, using them will raise a\n"
25" NotImplementedError.\n"
26"\n"
27"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
28" an open file descriptor.");
29
30#define OS_STAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070031 {"stat", (PyCFunction)os_stat, METH_FASTCALL, os_stat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030032
33static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030035
36static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070037os_stat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030038{
39 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030040 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
41 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030042 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
43 int dir_fd = DEFAULT_DIR_FD;
44 int follow_symlinks = 1;
45
Victor Stinner3e1fad62017-01-17 01:29:01 +010046 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030047 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030048 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030049 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
51
52exit:
53 /* Cleanup for path */
54 path_cleanup(&path);
55
56 return return_value;
57}
58
59PyDoc_STRVAR(os_lstat__doc__,
60"lstat($module, /, path, *, dir_fd=None)\n"
61"--\n"
62"\n"
63"Perform a stat system call on the given path, without following symbolic links.\n"
64"\n"
65"Like stat(), but do not follow symbolic links.\n"
66"Equivalent to stat(path, follow_symlinks=False).");
67
68#define OS_LSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070069 {"lstat", (PyCFunction)os_lstat, METH_FASTCALL, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070
71static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030072os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030073
74static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070075os_lstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"path", "dir_fd", NULL};
79 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030080 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
81 int dir_fd = DEFAULT_DIR_FD;
82
Victor Stinner3e1fad62017-01-17 01:29:01 +010083 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087 return_value = os_lstat_impl(module, &path, dir_fd);
88
89exit:
90 /* Cleanup for path */
91 path_cleanup(&path);
92
93 return return_value;
94}
95
96PyDoc_STRVAR(os_access__doc__,
97"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
98" follow_symlinks=True)\n"
99"--\n"
100"\n"
101"Use the real uid/gid to test for access to a path.\n"
102"\n"
103" path\n"
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700104" Path to be tested; can be string or bytes\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105" mode\n"
106" Operating-system mode bitfield. Can be F_OK to test existence,\n"
107" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
108" dir_fd\n"
109" If not None, it should be a file descriptor open to a directory,\n"
110" and path should be relative; path will then be relative to that\n"
111" directory.\n"
112" effective_ids\n"
113" If True, access will use the effective uid/gid instead of\n"
114" the real uid/gid.\n"
115" follow_symlinks\n"
116" If False, and the last element of the path is a symbolic link,\n"
117" access will examine the symbolic link itself instead of the file\n"
118" the link points to.\n"
119"\n"
120"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
121" on your platform. If they are unavailable, using them will raise a\n"
122" NotImplementedError.\n"
123"\n"
124"Note that most operations will use the effective uid/gid, therefore this\n"
125" routine can be used in a suid/sgid environment to test if the invoking user\n"
126" has the specified access to the path.");
127
128#define OS_ACCESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700129 {"access", (PyCFunction)os_access, METH_FASTCALL, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400133 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300134
135static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700136os_access(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300137{
138 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300139 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
140 static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700141 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300142 int mode;
143 int dir_fd = DEFAULT_DIR_FD;
144 int effective_ids = 0;
145 int follow_symlinks = 1;
146 int _return_value;
147
Victor Stinner3e1fad62017-01-17 01:29:01 +0100148 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300153 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156 return_value = PyBool_FromLong((long)_return_value);
157
158exit:
159 /* Cleanup for path */
160 path_cleanup(&path);
161
162 return return_value;
163}
164
165#if defined(HAVE_TTYNAME)
166
167PyDoc_STRVAR(os_ttyname__doc__,
168"ttyname($module, fd, /)\n"
169"--\n"
170"\n"
171"Return the name of the terminal device connected to \'fd\'.\n"
172"\n"
173" fd\n"
174" Integer file descriptor handle.");
175
176#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300177 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300178
179static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300180os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181
182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300183os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300184{
185 PyObject *return_value = NULL;
186 int fd;
187 char *_return_value;
188
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300189 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300190 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300193 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196 return_value = PyUnicode_DecodeFSDefault(_return_value);
197
198exit:
199 return return_value;
200}
201
202#endif /* defined(HAVE_TTYNAME) */
203
204#if defined(HAVE_CTERMID)
205
206PyDoc_STRVAR(os_ctermid__doc__,
207"ctermid($module, /)\n"
208"--\n"
209"\n"
210"Return the name of the controlling terminal for this process.");
211
212#define OS_CTERMID_METHODDEF \
213 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
214
215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300216os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300217
218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300219os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220{
221 return os_ctermid_impl(module);
222}
223
224#endif /* defined(HAVE_CTERMID) */
225
226PyDoc_STRVAR(os_chdir__doc__,
227"chdir($module, /, path)\n"
228"--\n"
229"\n"
230"Change the current working directory to the specified path.\n"
231"\n"
232"path may always be specified as a string.\n"
233"On some platforms, path may also be specified as an open file descriptor.\n"
234" If this functionality is unavailable, using it raises an exception.");
235
236#define OS_CHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700237 {"chdir", (PyCFunction)os_chdir, METH_FASTCALL, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238
239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300240os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300241
242static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700243os_chdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300244{
245 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300246 static const char * const _keywords[] = {"path", NULL};
247 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300248 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
249
Victor Stinner3e1fad62017-01-17 01:29:01 +0100250 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300251 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300252 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300253 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300254 return_value = os_chdir_impl(module, &path);
255
256exit:
257 /* Cleanup for path */
258 path_cleanup(&path);
259
260 return return_value;
261}
262
263#if defined(HAVE_FCHDIR)
264
265PyDoc_STRVAR(os_fchdir__doc__,
266"fchdir($module, /, fd)\n"
267"--\n"
268"\n"
269"Change to the directory of the given file descriptor.\n"
270"\n"
271"fd must be opened on a directory, not a file.\n"
272"Equivalent to os.chdir(fd).");
273
274#define OS_FCHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700275 {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300276
277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300278os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279
280static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700281os_fchdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300282{
283 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300284 static const char * const _keywords[] = {"fd", NULL};
285 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300286 int fd;
287
Victor Stinner3e1fad62017-01-17 01:29:01 +0100288 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300289 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300292 return_value = os_fchdir_impl(module, fd);
293
294exit:
295 return return_value;
296}
297
298#endif /* defined(HAVE_FCHDIR) */
299
300PyDoc_STRVAR(os_chmod__doc__,
301"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
302"--\n"
303"\n"
304"Change the access permissions of a file.\n"
305"\n"
306" path\n"
307" Path to be modified. May always be specified as a str or bytes.\n"
308" On some platforms, path may also be specified as an open file descriptor.\n"
309" If this functionality is unavailable, using it raises an exception.\n"
310" mode\n"
311" Operating-system mode bitfield.\n"
312" dir_fd\n"
313" If not None, it should be a file descriptor open to a directory,\n"
314" and path should be relative; path will then be relative to that\n"
315" directory.\n"
316" follow_symlinks\n"
317" If False, and the last element of the path is a symbolic link,\n"
318" chmod will modify the symbolic link itself instead of the file\n"
319" the link points to.\n"
320"\n"
321"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
322" an open file descriptor.\n"
323"dir_fd and follow_symlinks may not be implemented on your platform.\n"
324" If they are unavailable, using them will raise a NotImplementedError.");
325
326#define OS_CHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700327 {"chmod", (PyCFunction)os_chmod, METH_FASTCALL, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300328
329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300330os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400331 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300332
333static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700334os_chmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300335{
336 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300337 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
338 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300339 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
340 int mode;
341 int dir_fd = DEFAULT_DIR_FD;
342 int follow_symlinks = 1;
343
Victor Stinner3e1fad62017-01-17 01:29:01 +0100344 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300345 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300347 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300348 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
349
350exit:
351 /* Cleanup for path */
352 path_cleanup(&path);
353
354 return return_value;
355}
356
357#if defined(HAVE_FCHMOD)
358
359PyDoc_STRVAR(os_fchmod__doc__,
360"fchmod($module, /, fd, mode)\n"
361"--\n"
362"\n"
363"Change the access permissions of the file given by file descriptor fd.\n"
364"\n"
365"Equivalent to os.chmod(fd, mode).");
366
367#define OS_FCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700368 {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369
370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300371os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300372
373static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700374os_fchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300375{
376 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300377 static const char * const _keywords[] = {"fd", "mode", NULL};
378 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 int fd;
380 int mode;
381
Victor Stinner3e1fad62017-01-17 01:29:01 +0100382 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300383 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300386 return_value = os_fchmod_impl(module, fd, mode);
387
388exit:
389 return return_value;
390}
391
392#endif /* defined(HAVE_FCHMOD) */
393
394#if defined(HAVE_LCHMOD)
395
396PyDoc_STRVAR(os_lchmod__doc__,
397"lchmod($module, /, path, mode)\n"
398"--\n"
399"\n"
400"Change the access permissions of a file, without following symbolic links.\n"
401"\n"
402"If path is a symlink, this affects the link itself rather than the target.\n"
403"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
404
405#define OS_LCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700406 {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300407
408static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300409os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410
411static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700412os_lchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300413{
414 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300415 static const char * const _keywords[] = {"path", "mode", NULL};
416 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300417 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
418 int mode;
419
Victor Stinner3e1fad62017-01-17 01:29:01 +0100420 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300421 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300424 return_value = os_lchmod_impl(module, &path, mode);
425
426exit:
427 /* Cleanup for path */
428 path_cleanup(&path);
429
430 return return_value;
431}
432
433#endif /* defined(HAVE_LCHMOD) */
434
435#if defined(HAVE_CHFLAGS)
436
437PyDoc_STRVAR(os_chflags__doc__,
438"chflags($module, /, path, flags, follow_symlinks=True)\n"
439"--\n"
440"\n"
441"Set file flags.\n"
442"\n"
443"If follow_symlinks is False, and the last element of the path is a symbolic\n"
444" link, chflags will change flags on the symbolic link itself instead of the\n"
445" file the link points to.\n"
446"follow_symlinks may not be implemented on your platform. If it is\n"
447"unavailable, using it will raise a NotImplementedError.");
448
449#define OS_CHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700450 {"chflags", (PyCFunction)os_chflags, METH_FASTCALL, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300451
452static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300453os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400454 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300455
456static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700457os_chflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300458{
459 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300460 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
461 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300462 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
463 unsigned long flags;
464 int follow_symlinks = 1;
465
Victor Stinner3e1fad62017-01-17 01:29:01 +0100466 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300467 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300468 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300470 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
471
472exit:
473 /* Cleanup for path */
474 path_cleanup(&path);
475
476 return return_value;
477}
478
479#endif /* defined(HAVE_CHFLAGS) */
480
481#if defined(HAVE_LCHFLAGS)
482
483PyDoc_STRVAR(os_lchflags__doc__,
484"lchflags($module, /, path, flags)\n"
485"--\n"
486"\n"
487"Set file flags.\n"
488"\n"
489"This function will not follow symbolic links.\n"
490"Equivalent to chflags(path, flags, follow_symlinks=False).");
491
492#define OS_LCHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700493 {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300494
495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300496os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300497
498static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700499os_lchflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300500{
501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300502 static const char * const _keywords[] = {"path", "flags", NULL};
503 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
505 unsigned long flags;
506
Victor Stinner3e1fad62017-01-17 01:29:01 +0100507 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300508 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511 return_value = os_lchflags_impl(module, &path, flags);
512
513exit:
514 /* Cleanup for path */
515 path_cleanup(&path);
516
517 return return_value;
518}
519
520#endif /* defined(HAVE_LCHFLAGS) */
521
522#if defined(HAVE_CHROOT)
523
524PyDoc_STRVAR(os_chroot__doc__,
525"chroot($module, /, path)\n"
526"--\n"
527"\n"
528"Change root directory to path.");
529
530#define OS_CHROOT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700531 {"chroot", (PyCFunction)os_chroot, METH_FASTCALL, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300532
533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300534os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535
536static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700537os_chroot(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300538{
539 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300540 static const char * const _keywords[] = {"path", NULL};
541 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300542 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
543
Victor Stinner3e1fad62017-01-17 01:29:01 +0100544 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300545 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300547 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 return_value = os_chroot_impl(module, &path);
549
550exit:
551 /* Cleanup for path */
552 path_cleanup(&path);
553
554 return return_value;
555}
556
557#endif /* defined(HAVE_CHROOT) */
558
559#if defined(HAVE_FSYNC)
560
561PyDoc_STRVAR(os_fsync__doc__,
562"fsync($module, /, fd)\n"
563"--\n"
564"\n"
565"Force write of fd to disk.");
566
567#define OS_FSYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700568 {"fsync", (PyCFunction)os_fsync, METH_FASTCALL, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300569
570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300571os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300572
573static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700574os_fsync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300575{
576 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300577 static const char * const _keywords[] = {"fd", NULL};
578 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300579 int fd;
580
Victor Stinner3e1fad62017-01-17 01:29:01 +0100581 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300582 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585 return_value = os_fsync_impl(module, fd);
586
587exit:
588 return return_value;
589}
590
591#endif /* defined(HAVE_FSYNC) */
592
593#if defined(HAVE_SYNC)
594
595PyDoc_STRVAR(os_sync__doc__,
596"sync($module, /)\n"
597"--\n"
598"\n"
599"Force write of everything to disk.");
600
601#define OS_SYNC_METHODDEF \
602 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
603
604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300605os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300606
607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300608os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300609{
610 return os_sync_impl(module);
611}
612
613#endif /* defined(HAVE_SYNC) */
614
615#if defined(HAVE_FDATASYNC)
616
617PyDoc_STRVAR(os_fdatasync__doc__,
618"fdatasync($module, /, fd)\n"
619"--\n"
620"\n"
621"Force write of fd to disk without forcing update of metadata.");
622
623#define OS_FDATASYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700624 {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300625
626static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300627os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628
629static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700630os_fdatasync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631{
632 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300633 static const char * const _keywords[] = {"fd", NULL};
634 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300635 int fd;
636
Victor Stinner3e1fad62017-01-17 01:29:01 +0100637 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300638 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300639 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300641 return_value = os_fdatasync_impl(module, fd);
642
643exit:
644 return return_value;
645}
646
647#endif /* defined(HAVE_FDATASYNC) */
648
649#if defined(HAVE_CHOWN)
650
651PyDoc_STRVAR(os_chown__doc__,
652"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
653"--\n"
654"\n"
655"Change the owner and group id of path to the numeric uid and gid.\\\n"
656"\n"
657" path\n"
658" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
659" dir_fd\n"
660" If not None, it should be a file descriptor open to a directory,\n"
661" and path should be relative; path will then be relative to that\n"
662" directory.\n"
663" follow_symlinks\n"
664" If False, and the last element of the path is a symbolic link,\n"
665" stat will examine the symbolic link itself instead of the file\n"
666" the link points to.\n"
667"\n"
668"path may always be specified as a string.\n"
669"On some platforms, path may also be specified as an open file descriptor.\n"
670" If this functionality is unavailable, using it raises an exception.\n"
671"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
672" and path should be relative; path will then be relative to that directory.\n"
673"If follow_symlinks is False, and the last element of the path is a symbolic\n"
674" link, chown will modify the symbolic link itself instead of the file the\n"
675" link points to.\n"
676"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
677" an open file descriptor.\n"
678"dir_fd and follow_symlinks may not be implemented on your platform.\n"
679" If they are unavailable, using them will raise a NotImplementedError.");
680
681#define OS_CHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700682 {"chown", (PyCFunction)os_chown, METH_FASTCALL, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300683
684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300685os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400686 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300687
688static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700689os_chown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300690{
691 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300692 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
693 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300694 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
695 uid_t uid;
696 gid_t gid;
697 int dir_fd = DEFAULT_DIR_FD;
698 int follow_symlinks = 1;
699
Victor Stinner3e1fad62017-01-17 01:29:01 +0100700 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300701 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300703 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300704 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
705
706exit:
707 /* Cleanup for path */
708 path_cleanup(&path);
709
710 return return_value;
711}
712
713#endif /* defined(HAVE_CHOWN) */
714
715#if defined(HAVE_FCHOWN)
716
717PyDoc_STRVAR(os_fchown__doc__,
718"fchown($module, /, fd, uid, gid)\n"
719"--\n"
720"\n"
721"Change the owner and group id of the file specified by file descriptor.\n"
722"\n"
723"Equivalent to os.chown(fd, uid, gid).");
724
725#define OS_FCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700726 {"fchown", (PyCFunction)os_fchown, METH_FASTCALL, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300727
728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300729os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300730
731static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700732os_fchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300733{
734 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300735 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
736 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300737 int fd;
738 uid_t uid;
739 gid_t gid;
740
Victor Stinner3e1fad62017-01-17 01:29:01 +0100741 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300742 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300745 return_value = os_fchown_impl(module, fd, uid, gid);
746
747exit:
748 return return_value;
749}
750
751#endif /* defined(HAVE_FCHOWN) */
752
753#if defined(HAVE_LCHOWN)
754
755PyDoc_STRVAR(os_lchown__doc__,
756"lchown($module, /, path, uid, gid)\n"
757"--\n"
758"\n"
759"Change the owner and group id of path to the numeric uid and gid.\n"
760"\n"
761"This function will not follow symbolic links.\n"
762"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
763
764#define OS_LCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700765 {"lchown", (PyCFunction)os_lchown, METH_FASTCALL, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300769
770static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700771os_lchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300772{
773 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300774 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
775 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300776 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
777 uid_t uid;
778 gid_t gid;
779
Victor Stinner3e1fad62017-01-17 01:29:01 +0100780 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300781 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300782 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300783 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300784 return_value = os_lchown_impl(module, &path, uid, gid);
785
786exit:
787 /* Cleanup for path */
788 path_cleanup(&path);
789
790 return return_value;
791}
792
793#endif /* defined(HAVE_LCHOWN) */
794
795PyDoc_STRVAR(os_getcwd__doc__,
796"getcwd($module, /)\n"
797"--\n"
798"\n"
799"Return a unicode string representing the current working directory.");
800
801#define OS_GETCWD_METHODDEF \
802 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
803
804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300805os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300806
807static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300808os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300809{
810 return os_getcwd_impl(module);
811}
812
813PyDoc_STRVAR(os_getcwdb__doc__,
814"getcwdb($module, /)\n"
815"--\n"
816"\n"
817"Return a bytes string representing the current working directory.");
818
819#define OS_GETCWDB_METHODDEF \
820 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
821
822static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300823os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300824
825static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300826os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300827{
828 return os_getcwdb_impl(module);
829}
830
831#if defined(HAVE_LINK)
832
833PyDoc_STRVAR(os_link__doc__,
834"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
835" follow_symlinks=True)\n"
836"--\n"
837"\n"
838"Create a hard link to a file.\n"
839"\n"
840"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
841" descriptor open to a directory, and the respective path string (src or dst)\n"
842" should be relative; the path will then be relative to that directory.\n"
843"If follow_symlinks is False, and the last element of src is a symbolic\n"
844" link, link will create a link to the symbolic link itself instead of the\n"
845" file the link points to.\n"
846"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
847" platform. If they are unavailable, using them will raise a\n"
848" NotImplementedError.");
849
850#define OS_LINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700851 {"link", (PyCFunction)os_link, METH_FASTCALL, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300852
853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300854os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400855 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300856
857static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700858os_link(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300859{
860 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300861 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
862 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300863 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
864 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
865 int src_dir_fd = DEFAULT_DIR_FD;
866 int dst_dir_fd = DEFAULT_DIR_FD;
867 int follow_symlinks = 1;
868
Victor Stinner3e1fad62017-01-17 01:29:01 +0100869 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300870 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300873 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
874
875exit:
876 /* Cleanup for src */
877 path_cleanup(&src);
878 /* Cleanup for dst */
879 path_cleanup(&dst);
880
881 return return_value;
882}
883
884#endif /* defined(HAVE_LINK) */
885
886PyDoc_STRVAR(os_listdir__doc__,
887"listdir($module, /, path=None)\n"
888"--\n"
889"\n"
890"Return a list containing the names of the files in the directory.\n"
891"\n"
892"path can be specified as either str or bytes. If path is bytes,\n"
893" the filenames returned will also be bytes; in all other circumstances\n"
894" the filenames returned will be str.\n"
895"If path is None, uses the path=\'.\'.\n"
896"On some platforms, path may also be specified as an open file descriptor;\\\n"
897" the file descriptor must refer to a directory.\n"
898" If this functionality is unavailable, using it raises NotImplementedError.\n"
899"\n"
900"The list is in arbitrary order. It does not include the special\n"
901"entries \'.\' and \'..\' even if they are present in the directory.");
902
903#define OS_LISTDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700904 {"listdir", (PyCFunction)os_listdir, METH_FASTCALL, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300905
906static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300907os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300908
909static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700910os_listdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300911{
912 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300913 static const char * const _keywords[] = {"path", NULL};
914 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300915 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
916
Victor Stinner3e1fad62017-01-17 01:29:01 +0100917 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300918 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300921 return_value = os_listdir_impl(module, &path);
922
923exit:
924 /* Cleanup for path */
925 path_cleanup(&path);
926
927 return return_value;
928}
929
930#if defined(MS_WINDOWS)
931
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300932PyDoc_STRVAR(os__getfullpathname__doc__,
933"_getfullpathname($module, path, /)\n"
934"--\n"
935"\n");
936
937#define OS__GETFULLPATHNAME_METHODDEF \
938 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
939
940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300941os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300942
943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300944os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300945{
946 PyObject *return_value = NULL;
947 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
948
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300949 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300951 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300952 return_value = os__getfullpathname_impl(module, &path);
953
954exit:
955 /* Cleanup for path */
956 path_cleanup(&path);
957
958 return return_value;
959}
960
961#endif /* defined(MS_WINDOWS) */
962
963#if defined(MS_WINDOWS)
964
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300965PyDoc_STRVAR(os__getfinalpathname__doc__,
966"_getfinalpathname($module, path, /)\n"
967"--\n"
968"\n"
969"A helper function for samepath on windows.");
970
971#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300972 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300973
974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300975os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300976
977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300978os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979{
980 PyObject *return_value = NULL;
981 PyObject *path;
982
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300983 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300986 return_value = os__getfinalpathname_impl(module, path);
987
988exit:
989 return return_value;
990}
991
992#endif /* defined(MS_WINDOWS) */
993
994#if defined(MS_WINDOWS)
995
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300996PyDoc_STRVAR(os__isdir__doc__,
997"_isdir($module, path, /)\n"
998"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200999"\n"
1000"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001001
1002#define OS__ISDIR_METHODDEF \
1003 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1004
1005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001006os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010{
1011 PyObject *return_value = NULL;
1012 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1013
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001014 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001016 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001017 return_value = os__isdir_impl(module, &path);
1018
1019exit:
1020 /* Cleanup for path */
1021 path_cleanup(&path);
1022
1023 return return_value;
1024}
1025
1026#endif /* defined(MS_WINDOWS) */
1027
1028#if defined(MS_WINDOWS)
1029
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001030PyDoc_STRVAR(os__getvolumepathname__doc__,
1031"_getvolumepathname($module, /, path)\n"
1032"--\n"
1033"\n"
1034"A helper function for ismount on Win32.");
1035
1036#define OS__GETVOLUMEPATHNAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001037 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038
1039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001040os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001043os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044{
1045 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001046 static const char * const _keywords[] = {"path", NULL};
1047 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001048 PyObject *path;
1049
Victor Stinner3e1fad62017-01-17 01:29:01 +01001050 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001051 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001053 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001054 return_value = os__getvolumepathname_impl(module, path);
1055
1056exit:
1057 return return_value;
1058}
1059
1060#endif /* defined(MS_WINDOWS) */
1061
1062PyDoc_STRVAR(os_mkdir__doc__,
1063"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1064"--\n"
1065"\n"
1066"Create a directory.\n"
1067"\n"
1068"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1069" and path should be relative; path will then be relative to that directory.\n"
1070"dir_fd may not be implemented on your platform.\n"
1071" If it is unavailable, using it will raise a NotImplementedError.\n"
1072"\n"
1073"The mode argument is ignored on Windows.");
1074
1075#define OS_MKDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001076 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001077
1078static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001079os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001080
1081static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001082os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083{
1084 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001085 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1086 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001087 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1088 int mode = 511;
1089 int dir_fd = DEFAULT_DIR_FD;
1090
Victor Stinner3e1fad62017-01-17 01:29:01 +01001091 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001094 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001095 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1096
1097exit:
1098 /* Cleanup for path */
1099 path_cleanup(&path);
1100
1101 return return_value;
1102}
1103
1104#if defined(HAVE_NICE)
1105
1106PyDoc_STRVAR(os_nice__doc__,
1107"nice($module, increment, /)\n"
1108"--\n"
1109"\n"
1110"Add increment to the priority of process and return the new priority.");
1111
1112#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001113 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001114
1115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001116os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001117
1118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001119os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120{
1121 PyObject *return_value = NULL;
1122 int increment;
1123
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001124 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001127 return_value = os_nice_impl(module, increment);
1128
1129exit:
1130 return return_value;
1131}
1132
1133#endif /* defined(HAVE_NICE) */
1134
1135#if defined(HAVE_GETPRIORITY)
1136
1137PyDoc_STRVAR(os_getpriority__doc__,
1138"getpriority($module, /, which, who)\n"
1139"--\n"
1140"\n"
1141"Return program scheduling priority.");
1142
1143#define OS_GETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001144 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001145
1146static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001147os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001148
1149static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001150os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151{
1152 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001153 static const char * const _keywords[] = {"which", "who", NULL};
1154 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001155 int which;
1156 int who;
1157
Victor Stinner3e1fad62017-01-17 01:29:01 +01001158 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001159 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001162 return_value = os_getpriority_impl(module, which, who);
1163
1164exit:
1165 return return_value;
1166}
1167
1168#endif /* defined(HAVE_GETPRIORITY) */
1169
1170#if defined(HAVE_SETPRIORITY)
1171
1172PyDoc_STRVAR(os_setpriority__doc__,
1173"setpriority($module, /, which, who, priority)\n"
1174"--\n"
1175"\n"
1176"Set program scheduling priority.");
1177
1178#define OS_SETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001179 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001180
1181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001182os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001183
1184static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001185os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186{
1187 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001188 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1189 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001190 int which;
1191 int who;
1192 int priority;
1193
Victor Stinner3e1fad62017-01-17 01:29:01 +01001194 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001198 return_value = os_setpriority_impl(module, which, who, priority);
1199
1200exit:
1201 return return_value;
1202}
1203
1204#endif /* defined(HAVE_SETPRIORITY) */
1205
1206PyDoc_STRVAR(os_rename__doc__,
1207"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1208"--\n"
1209"\n"
1210"Rename a file or directory.\n"
1211"\n"
1212"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1213" descriptor open to a directory, and the respective path string (src or dst)\n"
1214" should be relative; the path will then be relative to that directory.\n"
1215"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1216" If they are unavailable, using them will raise a NotImplementedError.");
1217
1218#define OS_RENAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001219 {"rename", (PyCFunction)os_rename, METH_FASTCALL, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001220
1221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001222os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001223 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001224
1225static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001226os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001227{
1228 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001229 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1230 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001231 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1232 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1233 int src_dir_fd = DEFAULT_DIR_FD;
1234 int dst_dir_fd = DEFAULT_DIR_FD;
1235
Victor Stinner3e1fad62017-01-17 01:29:01 +01001236 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001237 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001240 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1241
1242exit:
1243 /* Cleanup for src */
1244 path_cleanup(&src);
1245 /* Cleanup for dst */
1246 path_cleanup(&dst);
1247
1248 return return_value;
1249}
1250
1251PyDoc_STRVAR(os_replace__doc__,
1252"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1253"--\n"
1254"\n"
1255"Rename a file or directory, overwriting the destination.\n"
1256"\n"
1257"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1258" descriptor open to a directory, and the respective path string (src or dst)\n"
1259" should be relative; the path will then be relative to that directory.\n"
1260"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1261" If they are unavailable, using them will raise a NotImplementedError.\"");
1262
1263#define OS_REPLACE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001264 {"replace", (PyCFunction)os_replace, METH_FASTCALL, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001265
1266static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001267os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1268 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001269
1270static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001271os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001272{
1273 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001274 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1275 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001276 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1277 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1278 int src_dir_fd = DEFAULT_DIR_FD;
1279 int dst_dir_fd = DEFAULT_DIR_FD;
1280
Victor Stinner3e1fad62017-01-17 01:29:01 +01001281 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001282 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001285 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1286
1287exit:
1288 /* Cleanup for src */
1289 path_cleanup(&src);
1290 /* Cleanup for dst */
1291 path_cleanup(&dst);
1292
1293 return return_value;
1294}
1295
1296PyDoc_STRVAR(os_rmdir__doc__,
1297"rmdir($module, /, path, *, dir_fd=None)\n"
1298"--\n"
1299"\n"
1300"Remove a directory.\n"
1301"\n"
1302"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1303" and path should be relative; path will then be relative to that directory.\n"
1304"dir_fd may not be implemented on your platform.\n"
1305" If it is unavailable, using it will raise a NotImplementedError.");
1306
1307#define OS_RMDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001308 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001309
1310static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001311os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001312
1313static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001314os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315{
1316 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001317 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1318 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001319 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1320 int dir_fd = DEFAULT_DIR_FD;
1321
Victor Stinner3e1fad62017-01-17 01:29:01 +01001322 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001323 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001324 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001325 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001326 return_value = os_rmdir_impl(module, &path, dir_fd);
1327
1328exit:
1329 /* Cleanup for path */
1330 path_cleanup(&path);
1331
1332 return return_value;
1333}
1334
1335#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1336
1337PyDoc_STRVAR(os_system__doc__,
1338"system($module, /, command)\n"
1339"--\n"
1340"\n"
1341"Execute the command in a subshell.");
1342
1343#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001344 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001345
1346static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001347os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348
1349static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001350os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351{
1352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001353 static const char * const _keywords[] = {"command", NULL};
1354 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001355 Py_UNICODE *command;
1356 long _return_value;
1357
Victor Stinner3e1fad62017-01-17 01:29:01 +01001358 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001359 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 return_value = PyLong_FromLong(_return_value);
1367
1368exit:
1369 return return_value;
1370}
1371
1372#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1373
1374#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1375
1376PyDoc_STRVAR(os_system__doc__,
1377"system($module, /, command)\n"
1378"--\n"
1379"\n"
1380"Execute the command in a subshell.");
1381
1382#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001383 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001384
1385static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001386os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001387
1388static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001389os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390{
1391 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001392 static const char * const _keywords[] = {"command", NULL};
1393 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001394 PyObject *command = NULL;
1395 long _return_value;
1396
Victor Stinner3e1fad62017-01-17 01:29:01 +01001397 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001398 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001399 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001400 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001401 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001402 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 return_value = PyLong_FromLong(_return_value);
1406
1407exit:
1408 /* Cleanup for command */
1409 Py_XDECREF(command);
1410
1411 return return_value;
1412}
1413
1414#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1415
1416PyDoc_STRVAR(os_umask__doc__,
1417"umask($module, mask, /)\n"
1418"--\n"
1419"\n"
1420"Set the current numeric umask and return the previous umask.");
1421
1422#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001423 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001424
1425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001426os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001427
1428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001429os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430{
1431 PyObject *return_value = NULL;
1432 int mask;
1433
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001437 return_value = os_umask_impl(module, mask);
1438
1439exit:
1440 return return_value;
1441}
1442
1443PyDoc_STRVAR(os_unlink__doc__,
1444"unlink($module, /, path, *, dir_fd=None)\n"
1445"--\n"
1446"\n"
1447"Remove a file (same as remove()).\n"
1448"\n"
1449"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1450" and path should be relative; path will then be relative to that directory.\n"
1451"dir_fd may not be implemented on your platform.\n"
1452" If it is unavailable, using it will raise a NotImplementedError.");
1453
1454#define OS_UNLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001455 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001456
1457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001458os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001459
1460static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001461os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462{
1463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001464 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1465 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001466 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1467 int dir_fd = DEFAULT_DIR_FD;
1468
Victor Stinner3e1fad62017-01-17 01:29:01 +01001469 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001473 return_value = os_unlink_impl(module, &path, dir_fd);
1474
1475exit:
1476 /* Cleanup for path */
1477 path_cleanup(&path);
1478
1479 return return_value;
1480}
1481
1482PyDoc_STRVAR(os_remove__doc__,
1483"remove($module, /, path, *, dir_fd=None)\n"
1484"--\n"
1485"\n"
1486"Remove a file (same as unlink()).\n"
1487"\n"
1488"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1489" and path should be relative; path will then be relative to that directory.\n"
1490"dir_fd may not be implemented on your platform.\n"
1491" If it is unavailable, using it will raise a NotImplementedError.");
1492
1493#define OS_REMOVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001494 {"remove", (PyCFunction)os_remove, METH_FASTCALL, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001495
1496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001497os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001498
1499static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001500os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501{
1502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001503 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1504 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001505 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1506 int dir_fd = DEFAULT_DIR_FD;
1507
Victor Stinner3e1fad62017-01-17 01:29:01 +01001508 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001512 return_value = os_remove_impl(module, &path, dir_fd);
1513
1514exit:
1515 /* Cleanup for path */
1516 path_cleanup(&path);
1517
1518 return return_value;
1519}
1520
1521#if defined(HAVE_UNAME)
1522
1523PyDoc_STRVAR(os_uname__doc__,
1524"uname($module, /)\n"
1525"--\n"
1526"\n"
1527"Return an object identifying the current operating system.\n"
1528"\n"
1529"The object behaves like a named tuple with the following fields:\n"
1530" (sysname, nodename, release, version, machine)");
1531
1532#define OS_UNAME_METHODDEF \
1533 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1534
1535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001536os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001537
1538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001539os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001540{
1541 return os_uname_impl(module);
1542}
1543
1544#endif /* defined(HAVE_UNAME) */
1545
1546PyDoc_STRVAR(os_utime__doc__,
1547"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1548" follow_symlinks=True)\n"
1549"--\n"
1550"\n"
1551"Set the access and modified time of path.\n"
1552"\n"
1553"path may always be specified as a string.\n"
1554"On some platforms, path may also be specified as an open file descriptor.\n"
1555" If this functionality is unavailable, using it raises an exception.\n"
1556"\n"
1557"If times is not None, it must be a tuple (atime, mtime);\n"
1558" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001559"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001560" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1561" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001562"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001563"Specifying tuples for both times and ns is an error.\n"
1564"\n"
1565"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1566" and path should be relative; path will then be relative to that directory.\n"
1567"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1568" link, utime will modify the symbolic link itself instead of the file the\n"
1569" link points to.\n"
1570"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1571" as an open file descriptor.\n"
1572"dir_fd and follow_symlinks may not be available on your platform.\n"
1573" If they are unavailable, using them will raise a NotImplementedError.");
1574
1575#define OS_UTIME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001576 {"utime", (PyCFunction)os_utime, METH_FASTCALL, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001577
1578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001579os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1580 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581
1582static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001583os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001584{
1585 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001586 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1587 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001588 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1589 PyObject *times = NULL;
1590 PyObject *ns = NULL;
1591 int dir_fd = DEFAULT_DIR_FD;
1592 int follow_symlinks = 1;
1593
Victor Stinner3e1fad62017-01-17 01:29:01 +01001594 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001598 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1599
1600exit:
1601 /* Cleanup for path */
1602 path_cleanup(&path);
1603
1604 return return_value;
1605}
1606
1607PyDoc_STRVAR(os__exit__doc__,
1608"_exit($module, /, status)\n"
1609"--\n"
1610"\n"
1611"Exit to the system with specified status, without normal exit processing.");
1612
1613#define OS__EXIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001614 {"_exit", (PyCFunction)os__exit, METH_FASTCALL, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001615
1616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001617os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001618
1619static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001620os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621{
1622 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001623 static const char * const _keywords[] = {"status", NULL};
1624 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001625 int status;
1626
Victor Stinner3e1fad62017-01-17 01:29:01 +01001627 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001630 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 return_value = os__exit_impl(module, status);
1632
1633exit:
1634 return return_value;
1635}
1636
1637#if defined(HAVE_EXECV)
1638
1639PyDoc_STRVAR(os_execv__doc__,
1640"execv($module, path, argv, /)\n"
1641"--\n"
1642"\n"
1643"Execute an executable path with arguments, replacing current process.\n"
1644"\n"
1645" path\n"
1646" Path of executable file.\n"
1647" argv\n"
1648" Tuple or list of strings.");
1649
1650#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001651 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001652
1653static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001654os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001655
1656static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001657os_execv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658{
1659 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001660 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661 PyObject *argv;
1662
Victor Stinner259f0e42017-01-17 01:35:17 +01001663 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
Steve Dowercc16be82016-09-08 10:35:16 -07001664 path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001665 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001666 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001667
1668 if (!_PyArg_NoStackKeywords("execv", kwnames)) {
1669 goto exit;
1670 }
Steve Dowercc16be82016-09-08 10:35:16 -07001671 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001672
1673exit:
1674 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001675 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001676
1677 return return_value;
1678}
1679
1680#endif /* defined(HAVE_EXECV) */
1681
1682#if defined(HAVE_EXECV)
1683
1684PyDoc_STRVAR(os_execve__doc__,
1685"execve($module, /, path, argv, env)\n"
1686"--\n"
1687"\n"
1688"Execute an executable path with arguments, replacing current process.\n"
1689"\n"
1690" path\n"
1691" Path of executable file.\n"
1692" argv\n"
1693" Tuple or list of strings.\n"
1694" env\n"
1695" Dictionary of strings mapping to strings.");
1696
1697#define OS_EXECVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001698 {"execve", (PyCFunction)os_execve, METH_FASTCALL, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001699
1700static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001701os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001702
1703static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001704os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001705{
1706 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001707 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1708 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001709 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1710 PyObject *argv;
1711 PyObject *env;
1712
Victor Stinner3e1fad62017-01-17 01:29:01 +01001713 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001714 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001715 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001716 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001717 return_value = os_execve_impl(module, &path, argv, env);
1718
1719exit:
1720 /* Cleanup for path */
1721 path_cleanup(&path);
1722
1723 return return_value;
1724}
1725
1726#endif /* defined(HAVE_EXECV) */
1727
Steve Dowercc16be82016-09-08 10:35:16 -07001728#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001729
1730PyDoc_STRVAR(os_spawnv__doc__,
1731"spawnv($module, mode, path, argv, /)\n"
1732"--\n"
1733"\n"
1734"Execute the program specified by path in a new process.\n"
1735"\n"
1736" mode\n"
1737" Mode of process creation.\n"
1738" path\n"
1739" Path of executable file.\n"
1740" argv\n"
1741" Tuple or list of strings.");
1742
1743#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001744 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001745
1746static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001747os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001748
1749static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001750os_spawnv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001751{
1752 PyObject *return_value = NULL;
1753 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001754 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001755 PyObject *argv;
1756
Victor Stinner259f0e42017-01-17 01:35:17 +01001757 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
Steve Dowercc16be82016-09-08 10:35:16 -07001758 &mode, path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001759 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001760 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001761
1762 if (!_PyArg_NoStackKeywords("spawnv", kwnames)) {
1763 goto exit;
1764 }
Steve Dowercc16be82016-09-08 10:35:16 -07001765 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001766
1767exit:
1768 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001769 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001770
1771 return return_value;
1772}
1773
Steve Dowercc16be82016-09-08 10:35:16 -07001774#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001775
Steve Dowercc16be82016-09-08 10:35:16 -07001776#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001777
1778PyDoc_STRVAR(os_spawnve__doc__,
1779"spawnve($module, mode, path, argv, env, /)\n"
1780"--\n"
1781"\n"
1782"Execute the program specified by path in a new process.\n"
1783"\n"
1784" mode\n"
1785" Mode of process creation.\n"
1786" path\n"
1787" Path of executable file.\n"
1788" argv\n"
1789" Tuple or list of strings.\n"
1790" env\n"
1791" Dictionary of strings mapping to strings.");
1792
1793#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001794 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001795
1796static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001797os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001798 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001799
1800static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001801os_spawnve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001802{
1803 PyObject *return_value = NULL;
1804 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001805 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001806 PyObject *argv;
1807 PyObject *env;
1808
Victor Stinner259f0e42017-01-17 01:35:17 +01001809 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
Steve Dowercc16be82016-09-08 10:35:16 -07001810 &mode, path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001811 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001812 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001813
1814 if (!_PyArg_NoStackKeywords("spawnve", kwnames)) {
1815 goto exit;
1816 }
Steve Dowercc16be82016-09-08 10:35:16 -07001817 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001818
1819exit:
1820 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001821 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001822
1823 return return_value;
1824}
1825
Steve Dowercc16be82016-09-08 10:35:16 -07001826#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001827
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001828#if defined(HAVE_FORK)
1829
1830PyDoc_STRVAR(os_register_at_fork__doc__,
1831"register_at_fork($module, func, /, when)\n"
1832"--\n"
1833"\n"
1834"Register a callable object to be called when forking.\n"
1835"\n"
1836" func\n"
1837" Function or callable\n"
1838" when\n"
1839" \'before\', \'child\' or \'parent\'\n"
1840"\n"
1841"\'before\' callbacks are called in reverse order before forking.\n"
1842"\'child\' callbacks are called in order after forking, in the child process.\n"
1843"\'parent\' callbacks are called in order after forking, in the parent process.");
1844
1845#define OS_REGISTER_AT_FORK_METHODDEF \
1846 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL, os_register_at_fork__doc__},
1847
1848static PyObject *
1849os_register_at_fork_impl(PyObject *module, PyObject *func, const char *when);
1850
1851static PyObject *
1852os_register_at_fork(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
1853{
1854 PyObject *return_value = NULL;
1855 static const char * const _keywords[] = {"", "when", NULL};
1856 static _PyArg_Parser _parser = {"Os:register_at_fork", _keywords, 0};
1857 PyObject *func;
1858 const char *when;
1859
1860 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1861 &func, &when)) {
1862 goto exit;
1863 }
1864 return_value = os_register_at_fork_impl(module, func, when);
1865
1866exit:
1867 return return_value;
1868}
1869
1870#endif /* defined(HAVE_FORK) */
1871
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001872#if defined(HAVE_FORK1)
1873
1874PyDoc_STRVAR(os_fork1__doc__,
1875"fork1($module, /)\n"
1876"--\n"
1877"\n"
1878"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1879"\n"
1880"Return 0 to child process and PID of child to parent process.");
1881
1882#define OS_FORK1_METHODDEF \
1883 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1884
1885static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001886os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001887
1888static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001889os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001890{
1891 return os_fork1_impl(module);
1892}
1893
1894#endif /* defined(HAVE_FORK1) */
1895
1896#if defined(HAVE_FORK)
1897
1898PyDoc_STRVAR(os_fork__doc__,
1899"fork($module, /)\n"
1900"--\n"
1901"\n"
1902"Fork a child process.\n"
1903"\n"
1904"Return 0 to child process and PID of child to parent process.");
1905
1906#define OS_FORK_METHODDEF \
1907 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1908
1909static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001910os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001911
1912static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001913os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001914{
1915 return os_fork_impl(module);
1916}
1917
1918#endif /* defined(HAVE_FORK) */
1919
1920#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1921
1922PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1923"sched_get_priority_max($module, /, policy)\n"
1924"--\n"
1925"\n"
1926"Get the maximum scheduling priority for policy.");
1927
1928#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001929 {"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 +03001930
1931static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001932os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001933
1934static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001935os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001936{
1937 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001938 static const char * const _keywords[] = {"policy", NULL};
1939 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001940 int policy;
1941
Victor Stinner3e1fad62017-01-17 01:29:01 +01001942 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001943 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001944 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001945 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001946 return_value = os_sched_get_priority_max_impl(module, policy);
1947
1948exit:
1949 return return_value;
1950}
1951
1952#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1953
1954#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1955
1956PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1957"sched_get_priority_min($module, /, policy)\n"
1958"--\n"
1959"\n"
1960"Get the minimum scheduling priority for policy.");
1961
1962#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001963 {"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 +03001964
1965static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001966os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001967
1968static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001969os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001970{
1971 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001972 static const char * const _keywords[] = {"policy", NULL};
1973 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001974 int policy;
1975
Victor Stinner3e1fad62017-01-17 01:29:01 +01001976 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001977 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001978 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001979 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001980 return_value = os_sched_get_priority_min_impl(module, policy);
1981
1982exit:
1983 return return_value;
1984}
1985
1986#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1987
1988#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1989
1990PyDoc_STRVAR(os_sched_getscheduler__doc__,
1991"sched_getscheduler($module, pid, /)\n"
1992"--\n"
1993"\n"
1994"Get the scheduling policy for the process identifiedy by pid.\n"
1995"\n"
1996"Passing 0 for pid returns the scheduling policy for the calling process.");
1997
1998#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001999 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002000
2001static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002002os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003
2004static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002005os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002006{
2007 PyObject *return_value = NULL;
2008 pid_t pid;
2009
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002010 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002011 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002012 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002013 return_value = os_sched_getscheduler_impl(module, pid);
2014
2015exit:
2016 return return_value;
2017}
2018
2019#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2020
2021#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2022
2023PyDoc_STRVAR(os_sched_param__doc__,
2024"sched_param(sched_priority)\n"
2025"--\n"
2026"\n"
2027"Current has only one field: sched_priority\");\n"
2028"\n"
2029" sched_priority\n"
2030" A scheduling parameter.");
2031
2032static PyObject *
2033os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2034
2035static PyObject *
2036os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2037{
2038 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002039 static const char * const _keywords[] = {"sched_priority", NULL};
2040 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002041 PyObject *sched_priority;
2042
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002043 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002044 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002045 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002046 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002047 return_value = os_sched_param_impl(type, sched_priority);
2048
2049exit:
2050 return return_value;
2051}
2052
2053#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2054
2055#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2056
2057PyDoc_STRVAR(os_sched_setscheduler__doc__,
2058"sched_setscheduler($module, pid, policy, param, /)\n"
2059"--\n"
2060"\n"
2061"Set the scheduling policy for the process identified by pid.\n"
2062"\n"
2063"If pid is 0, the calling process is changed.\n"
2064"param is an instance of sched_param.");
2065
2066#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002067 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002068
2069static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002070os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002071 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002072
2073static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002074os_sched_setscheduler(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002075{
2076 PyObject *return_value = NULL;
2077 pid_t pid;
2078 int policy;
2079 struct sched_param param;
2080
Victor Stinner259f0e42017-01-17 01:35:17 +01002081 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002082 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002083 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002084 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002085
2086 if (!_PyArg_NoStackKeywords("sched_setscheduler", kwnames)) {
2087 goto exit;
2088 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002089 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2090
2091exit:
2092 return return_value;
2093}
2094
2095#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2096
2097#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2098
2099PyDoc_STRVAR(os_sched_getparam__doc__,
2100"sched_getparam($module, pid, /)\n"
2101"--\n"
2102"\n"
2103"Returns scheduling parameters for the process identified by pid.\n"
2104"\n"
2105"If pid is 0, returns parameters for the calling process.\n"
2106"Return value is an instance of sched_param.");
2107
2108#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002109 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002110
2111static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002112os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002113
2114static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002115os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002116{
2117 PyObject *return_value = NULL;
2118 pid_t pid;
2119
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002120 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002121 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002122 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002123 return_value = os_sched_getparam_impl(module, pid);
2124
2125exit:
2126 return return_value;
2127}
2128
2129#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2130
2131#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2132
2133PyDoc_STRVAR(os_sched_setparam__doc__,
2134"sched_setparam($module, pid, param, /)\n"
2135"--\n"
2136"\n"
2137"Set scheduling parameters for the process identified by pid.\n"
2138"\n"
2139"If pid is 0, sets parameters for the calling process.\n"
2140"param should be an instance of sched_param.");
2141
2142#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002143 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002144
2145static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002146os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002147 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002148
2149static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002150os_sched_setparam(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002151{
2152 PyObject *return_value = NULL;
2153 pid_t pid;
2154 struct sched_param param;
2155
Victor Stinner259f0e42017-01-17 01:35:17 +01002156 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002157 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002159 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002160
2161 if (!_PyArg_NoStackKeywords("sched_setparam", kwnames)) {
2162 goto exit;
2163 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002164 return_value = os_sched_setparam_impl(module, pid, &param);
2165
2166exit:
2167 return return_value;
2168}
2169
2170#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2171
2172#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2173
2174PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2175"sched_rr_get_interval($module, pid, /)\n"
2176"--\n"
2177"\n"
2178"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2179"\n"
2180"Value returned is a float.");
2181
2182#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002183 {"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 +03002184
2185static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002186os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002187
2188static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002189os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002190{
2191 PyObject *return_value = NULL;
2192 pid_t pid;
2193 double _return_value;
2194
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002195 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002198 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002199 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002202 return_value = PyFloat_FromDouble(_return_value);
2203
2204exit:
2205 return return_value;
2206}
2207
2208#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2209
2210#if defined(HAVE_SCHED_H)
2211
2212PyDoc_STRVAR(os_sched_yield__doc__,
2213"sched_yield($module, /)\n"
2214"--\n"
2215"\n"
2216"Voluntarily relinquish the CPU.");
2217
2218#define OS_SCHED_YIELD_METHODDEF \
2219 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2220
2221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002222os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002223
2224static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002225os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002226{
2227 return os_sched_yield_impl(module);
2228}
2229
2230#endif /* defined(HAVE_SCHED_H) */
2231
2232#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2233
2234PyDoc_STRVAR(os_sched_setaffinity__doc__,
2235"sched_setaffinity($module, pid, mask, /)\n"
2236"--\n"
2237"\n"
2238"Set the CPU affinity of the process identified by pid to mask.\n"
2239"\n"
2240"mask should be an iterable of integers identifying CPUs.");
2241
2242#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002243 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002244
2245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002246os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002247
2248static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002249os_sched_setaffinity(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002250{
2251 PyObject *return_value = NULL;
2252 pid_t pid;
2253 PyObject *mask;
2254
Victor Stinner259f0e42017-01-17 01:35:17 +01002255 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002256 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002257 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002258 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002259
2260 if (!_PyArg_NoStackKeywords("sched_setaffinity", kwnames)) {
2261 goto exit;
2262 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002263 return_value = os_sched_setaffinity_impl(module, pid, mask);
2264
2265exit:
2266 return return_value;
2267}
2268
2269#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2270
2271#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2272
2273PyDoc_STRVAR(os_sched_getaffinity__doc__,
2274"sched_getaffinity($module, pid, /)\n"
2275"--\n"
2276"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002277"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002278"\n"
2279"The affinity is returned as a set of CPU identifiers.");
2280
2281#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002282 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002283
2284static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002285os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002286
2287static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002288os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002289{
2290 PyObject *return_value = NULL;
2291 pid_t pid;
2292
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002293 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002294 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002295 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002296 return_value = os_sched_getaffinity_impl(module, pid);
2297
2298exit:
2299 return return_value;
2300}
2301
2302#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2303
2304#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2305
2306PyDoc_STRVAR(os_openpty__doc__,
2307"openpty($module, /)\n"
2308"--\n"
2309"\n"
2310"Open a pseudo-terminal.\n"
2311"\n"
2312"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2313"for both the master and slave ends.");
2314
2315#define OS_OPENPTY_METHODDEF \
2316 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2317
2318static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002319os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002320
2321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002322os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002323{
2324 return os_openpty_impl(module);
2325}
2326
2327#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2328
2329#if defined(HAVE_FORKPTY)
2330
2331PyDoc_STRVAR(os_forkpty__doc__,
2332"forkpty($module, /)\n"
2333"--\n"
2334"\n"
2335"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2336"\n"
2337"Returns a tuple of (pid, master_fd).\n"
2338"Like fork(), return pid of 0 to the child process,\n"
2339"and pid of child to the parent process.\n"
2340"To both, return fd of newly opened pseudo-terminal.");
2341
2342#define OS_FORKPTY_METHODDEF \
2343 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2344
2345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002346os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002347
2348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002349os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002350{
2351 return os_forkpty_impl(module);
2352}
2353
2354#endif /* defined(HAVE_FORKPTY) */
2355
2356#if defined(HAVE_GETEGID)
2357
2358PyDoc_STRVAR(os_getegid__doc__,
2359"getegid($module, /)\n"
2360"--\n"
2361"\n"
2362"Return the current process\'s effective group id.");
2363
2364#define OS_GETEGID_METHODDEF \
2365 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2366
2367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002368os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002369
2370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002371os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002372{
2373 return os_getegid_impl(module);
2374}
2375
2376#endif /* defined(HAVE_GETEGID) */
2377
2378#if defined(HAVE_GETEUID)
2379
2380PyDoc_STRVAR(os_geteuid__doc__,
2381"geteuid($module, /)\n"
2382"--\n"
2383"\n"
2384"Return the current process\'s effective user id.");
2385
2386#define OS_GETEUID_METHODDEF \
2387 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2388
2389static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002390os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002391
2392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002393os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002394{
2395 return os_geteuid_impl(module);
2396}
2397
2398#endif /* defined(HAVE_GETEUID) */
2399
2400#if defined(HAVE_GETGID)
2401
2402PyDoc_STRVAR(os_getgid__doc__,
2403"getgid($module, /)\n"
2404"--\n"
2405"\n"
2406"Return the current process\'s group id.");
2407
2408#define OS_GETGID_METHODDEF \
2409 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2410
2411static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002412os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002413
2414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002415os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002416{
2417 return os_getgid_impl(module);
2418}
2419
2420#endif /* defined(HAVE_GETGID) */
2421
Berker Peksag39404992016-09-15 20:45:16 +03002422#if defined(HAVE_GETPID)
2423
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002424PyDoc_STRVAR(os_getpid__doc__,
2425"getpid($module, /)\n"
2426"--\n"
2427"\n"
2428"Return the current process id.");
2429
2430#define OS_GETPID_METHODDEF \
2431 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2432
2433static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002434os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002435
2436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002437os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002438{
2439 return os_getpid_impl(module);
2440}
2441
Berker Peksag39404992016-09-15 20:45:16 +03002442#endif /* defined(HAVE_GETPID) */
2443
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002444#if defined(HAVE_GETGROUPS)
2445
2446PyDoc_STRVAR(os_getgroups__doc__,
2447"getgroups($module, /)\n"
2448"--\n"
2449"\n"
2450"Return list of supplemental group IDs for the process.");
2451
2452#define OS_GETGROUPS_METHODDEF \
2453 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2454
2455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002456os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002457
2458static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002459os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002460{
2461 return os_getgroups_impl(module);
2462}
2463
2464#endif /* defined(HAVE_GETGROUPS) */
2465
2466#if defined(HAVE_GETPGID)
2467
2468PyDoc_STRVAR(os_getpgid__doc__,
2469"getpgid($module, /, pid)\n"
2470"--\n"
2471"\n"
2472"Call the system call getpgid(), and return the result.");
2473
2474#define OS_GETPGID_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002475 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002476
2477static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002478os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002479
2480static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002481os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002482{
2483 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002484 static const char * const _keywords[] = {"pid", NULL};
2485 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002486 pid_t pid;
2487
Victor Stinner3e1fad62017-01-17 01:29:01 +01002488 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002489 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002490 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002491 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002492 return_value = os_getpgid_impl(module, pid);
2493
2494exit:
2495 return return_value;
2496}
2497
2498#endif /* defined(HAVE_GETPGID) */
2499
2500#if defined(HAVE_GETPGRP)
2501
2502PyDoc_STRVAR(os_getpgrp__doc__,
2503"getpgrp($module, /)\n"
2504"--\n"
2505"\n"
2506"Return the current process group id.");
2507
2508#define OS_GETPGRP_METHODDEF \
2509 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2510
2511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002512os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002513
2514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002515os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002516{
2517 return os_getpgrp_impl(module);
2518}
2519
2520#endif /* defined(HAVE_GETPGRP) */
2521
2522#if defined(HAVE_SETPGRP)
2523
2524PyDoc_STRVAR(os_setpgrp__doc__,
2525"setpgrp($module, /)\n"
2526"--\n"
2527"\n"
2528"Make the current process the leader of its process group.");
2529
2530#define OS_SETPGRP_METHODDEF \
2531 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2532
2533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002534os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002535
2536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002537os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002538{
2539 return os_setpgrp_impl(module);
2540}
2541
2542#endif /* defined(HAVE_SETPGRP) */
2543
2544#if defined(HAVE_GETPPID)
2545
2546PyDoc_STRVAR(os_getppid__doc__,
2547"getppid($module, /)\n"
2548"--\n"
2549"\n"
2550"Return the parent\'s process id.\n"
2551"\n"
2552"If the parent process has already exited, Windows machines will still\n"
2553"return its id; others systems will return the id of the \'init\' process (1).");
2554
2555#define OS_GETPPID_METHODDEF \
2556 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2557
2558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002559os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002560
2561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002562os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002563{
2564 return os_getppid_impl(module);
2565}
2566
2567#endif /* defined(HAVE_GETPPID) */
2568
2569#if defined(HAVE_GETLOGIN)
2570
2571PyDoc_STRVAR(os_getlogin__doc__,
2572"getlogin($module, /)\n"
2573"--\n"
2574"\n"
2575"Return the actual login name.");
2576
2577#define OS_GETLOGIN_METHODDEF \
2578 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2579
2580static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002581os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002582
2583static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002584os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002585{
2586 return os_getlogin_impl(module);
2587}
2588
2589#endif /* defined(HAVE_GETLOGIN) */
2590
2591#if defined(HAVE_GETUID)
2592
2593PyDoc_STRVAR(os_getuid__doc__,
2594"getuid($module, /)\n"
2595"--\n"
2596"\n"
2597"Return the current process\'s user id.");
2598
2599#define OS_GETUID_METHODDEF \
2600 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2601
2602static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002603os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002604
2605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002606os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002607{
2608 return os_getuid_impl(module);
2609}
2610
2611#endif /* defined(HAVE_GETUID) */
2612
2613#if defined(HAVE_KILL)
2614
2615PyDoc_STRVAR(os_kill__doc__,
2616"kill($module, pid, signal, /)\n"
2617"--\n"
2618"\n"
2619"Kill a process with a signal.");
2620
2621#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002622 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002623
2624static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002625os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002626
2627static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002628os_kill(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002629{
2630 PyObject *return_value = NULL;
2631 pid_t pid;
2632 Py_ssize_t signal;
2633
Victor Stinner259f0e42017-01-17 01:35:17 +01002634 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002635 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002636 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002637 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002638
2639 if (!_PyArg_NoStackKeywords("kill", kwnames)) {
2640 goto exit;
2641 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002642 return_value = os_kill_impl(module, pid, signal);
2643
2644exit:
2645 return return_value;
2646}
2647
2648#endif /* defined(HAVE_KILL) */
2649
2650#if defined(HAVE_KILLPG)
2651
2652PyDoc_STRVAR(os_killpg__doc__,
2653"killpg($module, pgid, signal, /)\n"
2654"--\n"
2655"\n"
2656"Kill a process group with a signal.");
2657
2658#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002659 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002660
2661static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002662os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002663
2664static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002665os_killpg(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002666{
2667 PyObject *return_value = NULL;
2668 pid_t pgid;
2669 int signal;
2670
Victor Stinner259f0e42017-01-17 01:35:17 +01002671 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002672 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002673 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002674 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002675
2676 if (!_PyArg_NoStackKeywords("killpg", kwnames)) {
2677 goto exit;
2678 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002679 return_value = os_killpg_impl(module, pgid, signal);
2680
2681exit:
2682 return return_value;
2683}
2684
2685#endif /* defined(HAVE_KILLPG) */
2686
2687#if defined(HAVE_PLOCK)
2688
2689PyDoc_STRVAR(os_plock__doc__,
2690"plock($module, op, /)\n"
2691"--\n"
2692"\n"
2693"Lock program segments into memory.\");");
2694
2695#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002696 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002697
2698static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002699os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002700
2701static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002702os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002703{
2704 PyObject *return_value = NULL;
2705 int op;
2706
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002707 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002708 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002709 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002710 return_value = os_plock_impl(module, op);
2711
2712exit:
2713 return return_value;
2714}
2715
2716#endif /* defined(HAVE_PLOCK) */
2717
2718#if defined(HAVE_SETUID)
2719
2720PyDoc_STRVAR(os_setuid__doc__,
2721"setuid($module, uid, /)\n"
2722"--\n"
2723"\n"
2724"Set the current process\'s user id.");
2725
2726#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002727 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002728
2729static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002730os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002731
2732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002733os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002734{
2735 PyObject *return_value = NULL;
2736 uid_t uid;
2737
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002738 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002739 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002740 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002741 return_value = os_setuid_impl(module, uid);
2742
2743exit:
2744 return return_value;
2745}
2746
2747#endif /* defined(HAVE_SETUID) */
2748
2749#if defined(HAVE_SETEUID)
2750
2751PyDoc_STRVAR(os_seteuid__doc__,
2752"seteuid($module, euid, /)\n"
2753"--\n"
2754"\n"
2755"Set the current process\'s effective user id.");
2756
2757#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002758 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002759
2760static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002761os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002762
2763static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002764os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002765{
2766 PyObject *return_value = NULL;
2767 uid_t euid;
2768
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002769 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002770 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002771 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002772 return_value = os_seteuid_impl(module, euid);
2773
2774exit:
2775 return return_value;
2776}
2777
2778#endif /* defined(HAVE_SETEUID) */
2779
2780#if defined(HAVE_SETEGID)
2781
2782PyDoc_STRVAR(os_setegid__doc__,
2783"setegid($module, egid, /)\n"
2784"--\n"
2785"\n"
2786"Set the current process\'s effective group id.");
2787
2788#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002789 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002790
2791static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002792os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002793
2794static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002795os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002796{
2797 PyObject *return_value = NULL;
2798 gid_t egid;
2799
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002800 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002802 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002803 return_value = os_setegid_impl(module, egid);
2804
2805exit:
2806 return return_value;
2807}
2808
2809#endif /* defined(HAVE_SETEGID) */
2810
2811#if defined(HAVE_SETREUID)
2812
2813PyDoc_STRVAR(os_setreuid__doc__,
2814"setreuid($module, ruid, euid, /)\n"
2815"--\n"
2816"\n"
2817"Set the current process\'s real and effective user ids.");
2818
2819#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002820 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002821
2822static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002823os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002824
2825static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002826os_setreuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002827{
2828 PyObject *return_value = NULL;
2829 uid_t ruid;
2830 uid_t euid;
2831
Victor Stinner259f0e42017-01-17 01:35:17 +01002832 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002833 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002834 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002835 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002836
2837 if (!_PyArg_NoStackKeywords("setreuid", kwnames)) {
2838 goto exit;
2839 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002840 return_value = os_setreuid_impl(module, ruid, euid);
2841
2842exit:
2843 return return_value;
2844}
2845
2846#endif /* defined(HAVE_SETREUID) */
2847
2848#if defined(HAVE_SETREGID)
2849
2850PyDoc_STRVAR(os_setregid__doc__,
2851"setregid($module, rgid, egid, /)\n"
2852"--\n"
2853"\n"
2854"Set the current process\'s real and effective group ids.");
2855
2856#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002857 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002858
2859static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002860os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002861
2862static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002863os_setregid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002864{
2865 PyObject *return_value = NULL;
2866 gid_t rgid;
2867 gid_t egid;
2868
Victor Stinner259f0e42017-01-17 01:35:17 +01002869 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002870 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002872 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002873
2874 if (!_PyArg_NoStackKeywords("setregid", kwnames)) {
2875 goto exit;
2876 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002877 return_value = os_setregid_impl(module, rgid, egid);
2878
2879exit:
2880 return return_value;
2881}
2882
2883#endif /* defined(HAVE_SETREGID) */
2884
2885#if defined(HAVE_SETGID)
2886
2887PyDoc_STRVAR(os_setgid__doc__,
2888"setgid($module, gid, /)\n"
2889"--\n"
2890"\n"
2891"Set the current process\'s group id.");
2892
2893#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002894 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002895
2896static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002897os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002898
2899static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002900os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002901{
2902 PyObject *return_value = NULL;
2903 gid_t gid;
2904
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002905 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002906 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002907 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002908 return_value = os_setgid_impl(module, gid);
2909
2910exit:
2911 return return_value;
2912}
2913
2914#endif /* defined(HAVE_SETGID) */
2915
2916#if defined(HAVE_SETGROUPS)
2917
2918PyDoc_STRVAR(os_setgroups__doc__,
2919"setgroups($module, groups, /)\n"
2920"--\n"
2921"\n"
2922"Set the groups of the current process to list.");
2923
2924#define OS_SETGROUPS_METHODDEF \
2925 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2926
2927#endif /* defined(HAVE_SETGROUPS) */
2928
2929#if defined(HAVE_WAIT3)
2930
2931PyDoc_STRVAR(os_wait3__doc__,
2932"wait3($module, /, options)\n"
2933"--\n"
2934"\n"
2935"Wait for completion of a child process.\n"
2936"\n"
2937"Returns a tuple of information about the child process:\n"
2938" (pid, status, rusage)");
2939
2940#define OS_WAIT3_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002941 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002942
2943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002944os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002945
2946static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002947os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002948{
2949 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002950 static const char * const _keywords[] = {"options", NULL};
2951 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002952 int options;
2953
Victor Stinner3e1fad62017-01-17 01:29:01 +01002954 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002955 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002956 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002957 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002958 return_value = os_wait3_impl(module, options);
2959
2960exit:
2961 return return_value;
2962}
2963
2964#endif /* defined(HAVE_WAIT3) */
2965
2966#if defined(HAVE_WAIT4)
2967
2968PyDoc_STRVAR(os_wait4__doc__,
2969"wait4($module, /, pid, options)\n"
2970"--\n"
2971"\n"
2972"Wait for completion of a specific child process.\n"
2973"\n"
2974"Returns a tuple of information about the child process:\n"
2975" (pid, status, rusage)");
2976
2977#define OS_WAIT4_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002978 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002979
2980static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002981os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002982
2983static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002984os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002985{
2986 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002987 static const char * const _keywords[] = {"pid", "options", NULL};
2988 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002989 pid_t pid;
2990 int options;
2991
Victor Stinner3e1fad62017-01-17 01:29:01 +01002992 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002993 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002994 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002995 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002996 return_value = os_wait4_impl(module, pid, options);
2997
2998exit:
2999 return return_value;
3000}
3001
3002#endif /* defined(HAVE_WAIT4) */
3003
3004#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3005
3006PyDoc_STRVAR(os_waitid__doc__,
3007"waitid($module, idtype, id, options, /)\n"
3008"--\n"
3009"\n"
3010"Returns the result of waiting for a process or processes.\n"
3011"\n"
3012" idtype\n"
3013" Must be one of be P_PID, P_PGID or P_ALL.\n"
3014" id\n"
3015" The id to wait on.\n"
3016" options\n"
3017" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3018" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3019"\n"
3020"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3021"no children in a waitable state.");
3022
3023#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003024 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003025
3026static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003027os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003028
3029static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003030os_waitid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003031{
3032 PyObject *return_value = NULL;
3033 idtype_t idtype;
3034 id_t id;
3035 int options;
3036
Victor Stinner259f0e42017-01-17 01:35:17 +01003037 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003038 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003039 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003040 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003041
3042 if (!_PyArg_NoStackKeywords("waitid", kwnames)) {
3043 goto exit;
3044 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003045 return_value = os_waitid_impl(module, idtype, id, options);
3046
3047exit:
3048 return return_value;
3049}
3050
3051#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3052
3053#if defined(HAVE_WAITPID)
3054
3055PyDoc_STRVAR(os_waitpid__doc__,
3056"waitpid($module, pid, options, /)\n"
3057"--\n"
3058"\n"
3059"Wait for completion of a given child process.\n"
3060"\n"
3061"Returns a tuple of information regarding the child process:\n"
3062" (pid, status)\n"
3063"\n"
3064"The options argument is ignored on Windows.");
3065
3066#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003067 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003068
3069static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003070os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003071
3072static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003073os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003074{
3075 PyObject *return_value = NULL;
3076 pid_t pid;
3077 int options;
3078
Victor Stinner259f0e42017-01-17 01:35:17 +01003079 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003080 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003081 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003082 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003083
3084 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3085 goto exit;
3086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003087 return_value = os_waitpid_impl(module, pid, options);
3088
3089exit:
3090 return return_value;
3091}
3092
3093#endif /* defined(HAVE_WAITPID) */
3094
3095#if defined(HAVE_CWAIT)
3096
3097PyDoc_STRVAR(os_waitpid__doc__,
3098"waitpid($module, pid, options, /)\n"
3099"--\n"
3100"\n"
3101"Wait for completion of a given process.\n"
3102"\n"
3103"Returns a tuple of information regarding the process:\n"
3104" (pid, status << 8)\n"
3105"\n"
3106"The options argument is ignored on Windows.");
3107
3108#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003109 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003110
3111static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003112os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003113
3114static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003115os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003116{
3117 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003118 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003119 int options;
3120
Victor Stinner259f0e42017-01-17 01:35:17 +01003121 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003122 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003124 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003125
3126 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3127 goto exit;
3128 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003129 return_value = os_waitpid_impl(module, pid, options);
3130
3131exit:
3132 return return_value;
3133}
3134
3135#endif /* defined(HAVE_CWAIT) */
3136
3137#if defined(HAVE_WAIT)
3138
3139PyDoc_STRVAR(os_wait__doc__,
3140"wait($module, /)\n"
3141"--\n"
3142"\n"
3143"Wait for completion of a child process.\n"
3144"\n"
3145"Returns a tuple of information about the child process:\n"
3146" (pid, status)");
3147
3148#define OS_WAIT_METHODDEF \
3149 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3150
3151static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003152os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003153
3154static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003155os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003156{
3157 return os_wait_impl(module);
3158}
3159
3160#endif /* defined(HAVE_WAIT) */
3161
3162#if defined(HAVE_SYMLINK)
3163
3164PyDoc_STRVAR(os_symlink__doc__,
3165"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3166"--\n"
3167"\n"
3168"Create a symbolic link pointing to src named dst.\n"
3169"\n"
3170"target_is_directory is required on Windows if the target is to be\n"
3171" interpreted as a directory. (On Windows, symlink requires\n"
3172" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3173" target_is_directory is ignored on non-Windows platforms.\n"
3174"\n"
3175"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3176" and path should be relative; path will then be relative to that directory.\n"
3177"dir_fd may not be implemented on your platform.\n"
3178" If it is unavailable, using it will raise a NotImplementedError.");
3179
3180#define OS_SYMLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003181 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003182
3183static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003184os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003185 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003186
3187static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003188os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003189{
3190 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003191 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3192 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003193 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3194 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3195 int target_is_directory = 0;
3196 int dir_fd = DEFAULT_DIR_FD;
3197
Victor Stinner3e1fad62017-01-17 01:29:01 +01003198 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003199 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003202 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3203
3204exit:
3205 /* Cleanup for src */
3206 path_cleanup(&src);
3207 /* Cleanup for dst */
3208 path_cleanup(&dst);
3209
3210 return return_value;
3211}
3212
3213#endif /* defined(HAVE_SYMLINK) */
3214
3215#if defined(HAVE_TIMES)
3216
3217PyDoc_STRVAR(os_times__doc__,
3218"times($module, /)\n"
3219"--\n"
3220"\n"
3221"Return a collection containing process timing information.\n"
3222"\n"
3223"The object returned behaves like a named tuple with these fields:\n"
3224" (utime, stime, cutime, cstime, elapsed_time)\n"
3225"All fields are floating point numbers.");
3226
3227#define OS_TIMES_METHODDEF \
3228 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3229
3230static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003231os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003232
3233static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003234os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003235{
3236 return os_times_impl(module);
3237}
3238
3239#endif /* defined(HAVE_TIMES) */
3240
3241#if defined(HAVE_GETSID)
3242
3243PyDoc_STRVAR(os_getsid__doc__,
3244"getsid($module, pid, /)\n"
3245"--\n"
3246"\n"
3247"Call the system call getsid(pid) and return the result.");
3248
3249#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003250 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003251
3252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003253os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003254
3255static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003256os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003257{
3258 PyObject *return_value = NULL;
3259 pid_t pid;
3260
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003261 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003263 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003264 return_value = os_getsid_impl(module, pid);
3265
3266exit:
3267 return return_value;
3268}
3269
3270#endif /* defined(HAVE_GETSID) */
3271
3272#if defined(HAVE_SETSID)
3273
3274PyDoc_STRVAR(os_setsid__doc__,
3275"setsid($module, /)\n"
3276"--\n"
3277"\n"
3278"Call the system call setsid().");
3279
3280#define OS_SETSID_METHODDEF \
3281 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3282
3283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003284os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285
3286static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003287os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003288{
3289 return os_setsid_impl(module);
3290}
3291
3292#endif /* defined(HAVE_SETSID) */
3293
3294#if defined(HAVE_SETPGID)
3295
3296PyDoc_STRVAR(os_setpgid__doc__,
3297"setpgid($module, pid, pgrp, /)\n"
3298"--\n"
3299"\n"
3300"Call the system call setpgid(pid, pgrp).");
3301
3302#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003303 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003304
3305static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003306os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003307
3308static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003309os_setpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003310{
3311 PyObject *return_value = NULL;
3312 pid_t pid;
3313 pid_t pgrp;
3314
Victor Stinner259f0e42017-01-17 01:35:17 +01003315 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003316 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003317 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003318 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003319
3320 if (!_PyArg_NoStackKeywords("setpgid", kwnames)) {
3321 goto exit;
3322 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003323 return_value = os_setpgid_impl(module, pid, pgrp);
3324
3325exit:
3326 return return_value;
3327}
3328
3329#endif /* defined(HAVE_SETPGID) */
3330
3331#if defined(HAVE_TCGETPGRP)
3332
3333PyDoc_STRVAR(os_tcgetpgrp__doc__,
3334"tcgetpgrp($module, fd, /)\n"
3335"--\n"
3336"\n"
3337"Return the process group associated with the terminal specified by fd.");
3338
3339#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003340 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003341
3342static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003343os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003344
3345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003346os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003347{
3348 PyObject *return_value = NULL;
3349 int fd;
3350
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003351 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003352 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003354 return_value = os_tcgetpgrp_impl(module, fd);
3355
3356exit:
3357 return return_value;
3358}
3359
3360#endif /* defined(HAVE_TCGETPGRP) */
3361
3362#if defined(HAVE_TCSETPGRP)
3363
3364PyDoc_STRVAR(os_tcsetpgrp__doc__,
3365"tcsetpgrp($module, fd, pgid, /)\n"
3366"--\n"
3367"\n"
3368"Set the process group associated with the terminal specified by fd.");
3369
3370#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003371 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003372
3373static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003374os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003375
3376static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003377os_tcsetpgrp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378{
3379 PyObject *return_value = NULL;
3380 int fd;
3381 pid_t pgid;
3382
Victor Stinner259f0e42017-01-17 01:35:17 +01003383 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003384 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003385 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003386 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003387
3388 if (!_PyArg_NoStackKeywords("tcsetpgrp", kwnames)) {
3389 goto exit;
3390 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003391 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3392
3393exit:
3394 return return_value;
3395}
3396
3397#endif /* defined(HAVE_TCSETPGRP) */
3398
3399PyDoc_STRVAR(os_open__doc__,
3400"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3401"--\n"
3402"\n"
3403"Open a file for low level IO. Returns a file descriptor (integer).\n"
3404"\n"
3405"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3406" and path should be relative; path will then be relative to that directory.\n"
3407"dir_fd may not be implemented on your platform.\n"
3408" If it is unavailable, using it will raise a NotImplementedError.");
3409
3410#define OS_OPEN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003411 {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003412
3413static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003414os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003415
3416static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003417os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003418{
3419 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003420 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3421 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003422 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3423 int flags;
3424 int mode = 511;
3425 int dir_fd = DEFAULT_DIR_FD;
3426 int _return_value;
3427
Victor Stinner3e1fad62017-01-17 01:29:01 +01003428 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003429 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003430 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003431 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003432 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003433 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003435 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003436 return_value = PyLong_FromLong((long)_return_value);
3437
3438exit:
3439 /* Cleanup for path */
3440 path_cleanup(&path);
3441
3442 return return_value;
3443}
3444
3445PyDoc_STRVAR(os_close__doc__,
3446"close($module, /, fd)\n"
3447"--\n"
3448"\n"
3449"Close a file descriptor.");
3450
3451#define OS_CLOSE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003452 {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003453
3454static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003455os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003456
3457static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003458os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003459{
3460 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003461 static const char * const _keywords[] = {"fd", NULL};
3462 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003463 int fd;
3464
Victor Stinner3e1fad62017-01-17 01:29:01 +01003465 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003466 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003467 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003468 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003469 return_value = os_close_impl(module, fd);
3470
3471exit:
3472 return return_value;
3473}
3474
3475PyDoc_STRVAR(os_closerange__doc__,
3476"closerange($module, fd_low, fd_high, /)\n"
3477"--\n"
3478"\n"
3479"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3480
3481#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003482 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003483
3484static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003485os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003486
3487static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003488os_closerange(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003489{
3490 PyObject *return_value = NULL;
3491 int fd_low;
3492 int fd_high;
3493
Victor Stinner259f0e42017-01-17 01:35:17 +01003494 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003495 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003496 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003497 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003498
3499 if (!_PyArg_NoStackKeywords("closerange", kwnames)) {
3500 goto exit;
3501 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003502 return_value = os_closerange_impl(module, fd_low, fd_high);
3503
3504exit:
3505 return return_value;
3506}
3507
3508PyDoc_STRVAR(os_dup__doc__,
3509"dup($module, fd, /)\n"
3510"--\n"
3511"\n"
3512"Return a duplicate of a file descriptor.");
3513
3514#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003515 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003516
3517static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003518os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003519
3520static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003521os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003522{
3523 PyObject *return_value = NULL;
3524 int fd;
3525 int _return_value;
3526
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003527 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003528 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003529 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003530 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003531 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003532 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003533 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003534 return_value = PyLong_FromLong((long)_return_value);
3535
3536exit:
3537 return return_value;
3538}
3539
3540PyDoc_STRVAR(os_dup2__doc__,
3541"dup2($module, /, fd, fd2, inheritable=True)\n"
3542"--\n"
3543"\n"
3544"Duplicate file descriptor.");
3545
3546#define OS_DUP2_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003547 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003548
3549static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003550os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003551
3552static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003553os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003554{
3555 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003556 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3557 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003558 int fd;
3559 int fd2;
3560 int inheritable = 1;
3561
Victor Stinner3e1fad62017-01-17 01:29:01 +01003562 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003563 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003564 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003565 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003566 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3567
3568exit:
3569 return return_value;
3570}
3571
3572#if defined(HAVE_LOCKF)
3573
3574PyDoc_STRVAR(os_lockf__doc__,
3575"lockf($module, fd, command, length, /)\n"
3576"--\n"
3577"\n"
3578"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3579"\n"
3580" fd\n"
3581" An open file descriptor.\n"
3582" command\n"
3583" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3584" length\n"
3585" The number of bytes to lock, starting at the current position.");
3586
3587#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003588 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003589
3590static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003591os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003592
3593static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003594os_lockf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003595{
3596 PyObject *return_value = NULL;
3597 int fd;
3598 int command;
3599 Py_off_t length;
3600
Victor Stinner259f0e42017-01-17 01:35:17 +01003601 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003602 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003603 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003604 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003605
3606 if (!_PyArg_NoStackKeywords("lockf", kwnames)) {
3607 goto exit;
3608 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003609 return_value = os_lockf_impl(module, fd, command, length);
3610
3611exit:
3612 return return_value;
3613}
3614
3615#endif /* defined(HAVE_LOCKF) */
3616
3617PyDoc_STRVAR(os_lseek__doc__,
3618"lseek($module, fd, position, how, /)\n"
3619"--\n"
3620"\n"
3621"Set the position of a file descriptor. Return the new position.\n"
3622"\n"
3623"Return the new cursor position in number of bytes\n"
3624"relative to the beginning of the file.");
3625
3626#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003627 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003628
3629static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003630os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003631
3632static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003633os_lseek(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003634{
3635 PyObject *return_value = NULL;
3636 int fd;
3637 Py_off_t position;
3638 int how;
3639 Py_off_t _return_value;
3640
Victor Stinner259f0e42017-01-17 01:35:17 +01003641 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003642 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003643 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003644 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003645
3646 if (!_PyArg_NoStackKeywords("lseek", kwnames)) {
3647 goto exit;
3648 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003649 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003650 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003651 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003652 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003653 return_value = PyLong_FromPy_off_t(_return_value);
3654
3655exit:
3656 return return_value;
3657}
3658
3659PyDoc_STRVAR(os_read__doc__,
3660"read($module, fd, length, /)\n"
3661"--\n"
3662"\n"
3663"Read from a file descriptor. Returns a bytes object.");
3664
3665#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003666 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003667
3668static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003669os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003670
3671static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003672os_read(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003673{
3674 PyObject *return_value = NULL;
3675 int fd;
3676 Py_ssize_t length;
3677
Victor Stinner259f0e42017-01-17 01:35:17 +01003678 if (!_PyArg_ParseStack(args, nargs, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003679 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003680 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003681 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003682
3683 if (!_PyArg_NoStackKeywords("read", kwnames)) {
3684 goto exit;
3685 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003686 return_value = os_read_impl(module, fd, length);
3687
3688exit:
3689 return return_value;
3690}
3691
3692#if defined(HAVE_READV)
3693
3694PyDoc_STRVAR(os_readv__doc__,
3695"readv($module, fd, buffers, /)\n"
3696"--\n"
3697"\n"
3698"Read from a file descriptor fd into an iterable of buffers.\n"
3699"\n"
3700"The buffers should be mutable buffers accepting bytes.\n"
3701"readv will transfer data into each buffer until it is full\n"
3702"and then move on to the next buffer in the sequence to hold\n"
3703"the rest of the data.\n"
3704"\n"
3705"readv returns the total number of bytes read,\n"
3706"which may be less than the total capacity of all the buffers.");
3707
3708#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003709 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003710
3711static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003712os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003713
3714static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003715os_readv(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 PyObject *buffers;
3720 Py_ssize_t _return_value;
3721
Victor Stinner259f0e42017-01-17 01:35:17 +01003722 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003723 &fd, &buffers)) {
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("readv", kwnames)) {
3728 goto exit;
3729 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003730 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003731 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003732 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003733 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003734 return_value = PyLong_FromSsize_t(_return_value);
3735
3736exit:
3737 return return_value;
3738}
3739
3740#endif /* defined(HAVE_READV) */
3741
3742#if defined(HAVE_PREAD)
3743
3744PyDoc_STRVAR(os_pread__doc__,
3745"pread($module, fd, length, offset, /)\n"
3746"--\n"
3747"\n"
3748"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3749"\n"
3750"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3751"the beginning of the file. The file offset remains unchanged.");
3752
3753#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003754 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003755
3756static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003757os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003758
3759static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003760os_pread(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003761{
3762 PyObject *return_value = NULL;
3763 int fd;
3764 int length;
3765 Py_off_t offset;
3766
Victor Stinner259f0e42017-01-17 01:35:17 +01003767 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003768 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003769 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003770 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003771
3772 if (!_PyArg_NoStackKeywords("pread", kwnames)) {
3773 goto exit;
3774 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003775 return_value = os_pread_impl(module, fd, length, offset);
3776
3777exit:
3778 return return_value;
3779}
3780
3781#endif /* defined(HAVE_PREAD) */
3782
3783PyDoc_STRVAR(os_write__doc__,
3784"write($module, fd, data, /)\n"
3785"--\n"
3786"\n"
3787"Write a bytes object to a file descriptor.");
3788
3789#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003790 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003791
3792static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003793os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003794
3795static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003796os_write(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003797{
3798 PyObject *return_value = NULL;
3799 int fd;
3800 Py_buffer data = {NULL, NULL};
3801 Py_ssize_t _return_value;
3802
Victor Stinner259f0e42017-01-17 01:35:17 +01003803 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003804 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003805 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003806 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003807
3808 if (!_PyArg_NoStackKeywords("write", kwnames)) {
3809 goto exit;
3810 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003811 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003812 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003813 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003814 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003815 return_value = PyLong_FromSsize_t(_return_value);
3816
3817exit:
3818 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003819 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003820 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003821 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003822
3823 return return_value;
3824}
3825
3826PyDoc_STRVAR(os_fstat__doc__,
3827"fstat($module, /, fd)\n"
3828"--\n"
3829"\n"
3830"Perform a stat system call on the given file descriptor.\n"
3831"\n"
3832"Like stat(), but for an open file descriptor.\n"
3833"Equivalent to os.stat(fd).");
3834
3835#define OS_FSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003836 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003837
3838static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003839os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003840
3841static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003842os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003843{
3844 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003845 static const char * const _keywords[] = {"fd", NULL};
3846 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003847 int fd;
3848
Victor Stinner3e1fad62017-01-17 01:29:01 +01003849 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003850 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003851 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003852 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003853 return_value = os_fstat_impl(module, fd);
3854
3855exit:
3856 return return_value;
3857}
3858
3859PyDoc_STRVAR(os_isatty__doc__,
3860"isatty($module, fd, /)\n"
3861"--\n"
3862"\n"
3863"Return True if the fd is connected to a terminal.\n"
3864"\n"
3865"Return True if the file descriptor is an open file descriptor\n"
3866"connected to the slave end of a terminal.");
3867
3868#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003869 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003870
3871static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003872os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003873
3874static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003875os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003876{
3877 PyObject *return_value = NULL;
3878 int fd;
3879 int _return_value;
3880
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003881 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003882 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003883 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003884 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003885 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003886 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003887 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003888 return_value = PyBool_FromLong((long)_return_value);
3889
3890exit:
3891 return return_value;
3892}
3893
3894#if defined(HAVE_PIPE)
3895
3896PyDoc_STRVAR(os_pipe__doc__,
3897"pipe($module, /)\n"
3898"--\n"
3899"\n"
3900"Create a pipe.\n"
3901"\n"
3902"Returns a tuple of two file descriptors:\n"
3903" (read_fd, write_fd)");
3904
3905#define OS_PIPE_METHODDEF \
3906 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3907
3908static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003909os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003910
3911static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003912os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003913{
3914 return os_pipe_impl(module);
3915}
3916
3917#endif /* defined(HAVE_PIPE) */
3918
3919#if defined(HAVE_PIPE2)
3920
3921PyDoc_STRVAR(os_pipe2__doc__,
3922"pipe2($module, flags, /)\n"
3923"--\n"
3924"\n"
3925"Create a pipe with flags set atomically.\n"
3926"\n"
3927"Returns a tuple of two file descriptors:\n"
3928" (read_fd, write_fd)\n"
3929"\n"
3930"flags can be constructed by ORing together one or more of these values:\n"
3931"O_NONBLOCK, O_CLOEXEC.");
3932
3933#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003934 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003935
3936static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003937os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003938
3939static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003940os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003941{
3942 PyObject *return_value = NULL;
3943 int flags;
3944
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003945 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
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 = os_pipe2_impl(module, flags);
3949
3950exit:
3951 return return_value;
3952}
3953
3954#endif /* defined(HAVE_PIPE2) */
3955
3956#if defined(HAVE_WRITEV)
3957
3958PyDoc_STRVAR(os_writev__doc__,
3959"writev($module, fd, buffers, /)\n"
3960"--\n"
3961"\n"
3962"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3963"\n"
3964"Returns the total number of bytes written.\n"
3965"buffers must be a sequence of bytes-like objects.");
3966
3967#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003968 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003969
3970static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003971os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003972
3973static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003974os_writev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003975{
3976 PyObject *return_value = NULL;
3977 int fd;
3978 PyObject *buffers;
3979 Py_ssize_t _return_value;
3980
Victor Stinner259f0e42017-01-17 01:35:17 +01003981 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003982 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003983 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003984 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003985
3986 if (!_PyArg_NoStackKeywords("writev", kwnames)) {
3987 goto exit;
3988 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003989 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003990 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003991 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003992 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003993 return_value = PyLong_FromSsize_t(_return_value);
3994
3995exit:
3996 return return_value;
3997}
3998
3999#endif /* defined(HAVE_WRITEV) */
4000
4001#if defined(HAVE_PWRITE)
4002
4003PyDoc_STRVAR(os_pwrite__doc__,
4004"pwrite($module, fd, buffer, offset, /)\n"
4005"--\n"
4006"\n"
4007"Write bytes to a file descriptor starting at a particular offset.\n"
4008"\n"
4009"Write buffer to fd, starting at offset bytes from the beginning of\n"
4010"the file. Returns the number of bytes writte. Does not change the\n"
4011"current file offset.");
4012
4013#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004014 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004015
4016static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004017os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004018
4019static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004020os_pwrite(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004021{
4022 PyObject *return_value = NULL;
4023 int fd;
4024 Py_buffer buffer = {NULL, NULL};
4025 Py_off_t offset;
4026 Py_ssize_t _return_value;
4027
Victor Stinner259f0e42017-01-17 01:35:17 +01004028 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004029 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004030 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004031 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004032
4033 if (!_PyArg_NoStackKeywords("pwrite", kwnames)) {
4034 goto exit;
4035 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004036 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004037 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004038 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004039 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004040 return_value = PyLong_FromSsize_t(_return_value);
4041
4042exit:
4043 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004044 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004045 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004046 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004047
4048 return return_value;
4049}
4050
4051#endif /* defined(HAVE_PWRITE) */
4052
4053#if defined(HAVE_MKFIFO)
4054
4055PyDoc_STRVAR(os_mkfifo__doc__,
4056"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4057"--\n"
4058"\n"
4059"Create a \"fifo\" (a POSIX named pipe).\n"
4060"\n"
4061"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4062" and path should be relative; path will then be relative to that directory.\n"
4063"dir_fd may not be implemented on your platform.\n"
4064" If it is unavailable, using it will raise a NotImplementedError.");
4065
4066#define OS_MKFIFO_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004067 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004068
4069static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004070os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004071
4072static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004073os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074{
4075 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004076 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4077 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004078 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4079 int mode = 438;
4080 int dir_fd = DEFAULT_DIR_FD;
4081
Victor Stinner3e1fad62017-01-17 01:29:01 +01004082 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004083 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004084 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004085 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004086 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4087
4088exit:
4089 /* Cleanup for path */
4090 path_cleanup(&path);
4091
4092 return return_value;
4093}
4094
4095#endif /* defined(HAVE_MKFIFO) */
4096
4097#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4098
4099PyDoc_STRVAR(os_mknod__doc__,
4100"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4101"--\n"
4102"\n"
4103"Create a node in the file system.\n"
4104"\n"
4105"Create a node in the file system (file, device special file or named pipe)\n"
4106"at path. mode specifies both the permissions to use and the\n"
4107"type of node to be created, being combined (bitwise OR) with one of\n"
4108"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4109"device defines the newly created device special file (probably using\n"
4110"os.makedev()). Otherwise device is ignored.\n"
4111"\n"
4112"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4113" and path should be relative; path will then be relative to that directory.\n"
4114"dir_fd may not be implemented on your platform.\n"
4115" If it is unavailable, using it will raise a NotImplementedError.");
4116
4117#define OS_MKNOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004118 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004119
4120static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004121os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004122 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004123
4124static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004125os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004126{
4127 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004128 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4129 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004130 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4131 int mode = 384;
4132 dev_t device = 0;
4133 int dir_fd = DEFAULT_DIR_FD;
4134
Victor Stinner3e1fad62017-01-17 01:29:01 +01004135 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004136 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004137 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004138 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004139 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4140
4141exit:
4142 /* Cleanup for path */
4143 path_cleanup(&path);
4144
4145 return return_value;
4146}
4147
4148#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4149
4150#if defined(HAVE_DEVICE_MACROS)
4151
4152PyDoc_STRVAR(os_major__doc__,
4153"major($module, device, /)\n"
4154"--\n"
4155"\n"
4156"Extracts a device major number from a raw device number.");
4157
4158#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004159 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004160
4161static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004162os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004163
4164static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004165os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004166{
4167 PyObject *return_value = NULL;
4168 dev_t device;
4169 unsigned int _return_value;
4170
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004171 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004172 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004173 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004174 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004175 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004176 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004177 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004178 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4179
4180exit:
4181 return return_value;
4182}
4183
4184#endif /* defined(HAVE_DEVICE_MACROS) */
4185
4186#if defined(HAVE_DEVICE_MACROS)
4187
4188PyDoc_STRVAR(os_minor__doc__,
4189"minor($module, device, /)\n"
4190"--\n"
4191"\n"
4192"Extracts a device minor number from a raw device number.");
4193
4194#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004195 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004196
4197static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004198os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004199
4200static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004201os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004202{
4203 PyObject *return_value = NULL;
4204 dev_t device;
4205 unsigned int _return_value;
4206
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004207 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004208 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004209 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004210 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004211 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004212 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004213 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004214 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4215
4216exit:
4217 return return_value;
4218}
4219
4220#endif /* defined(HAVE_DEVICE_MACROS) */
4221
4222#if defined(HAVE_DEVICE_MACROS)
4223
4224PyDoc_STRVAR(os_makedev__doc__,
4225"makedev($module, major, minor, /)\n"
4226"--\n"
4227"\n"
4228"Composes a raw device number from the major and minor device numbers.");
4229
4230#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004231 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004232
4233static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004234os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004235
4236static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004237os_makedev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004238{
4239 PyObject *return_value = NULL;
4240 int major;
4241 int minor;
4242 dev_t _return_value;
4243
Victor Stinner259f0e42017-01-17 01:35:17 +01004244 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004245 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004246 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004247 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004248
4249 if (!_PyArg_NoStackKeywords("makedev", kwnames)) {
4250 goto exit;
4251 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004252 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004253 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004254 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004255 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004256 return_value = _PyLong_FromDev(_return_value);
4257
4258exit:
4259 return return_value;
4260}
4261
4262#endif /* defined(HAVE_DEVICE_MACROS) */
4263
Steve Dowerf7377032015-04-12 15:44:54 -04004264#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004265
4266PyDoc_STRVAR(os_ftruncate__doc__,
4267"ftruncate($module, fd, length, /)\n"
4268"--\n"
4269"\n"
4270"Truncate a file, specified by file descriptor, to a specific length.");
4271
4272#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004273 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004274
4275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004276os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004277
4278static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004279os_ftruncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004280{
4281 PyObject *return_value = NULL;
4282 int fd;
4283 Py_off_t length;
4284
Victor Stinner259f0e42017-01-17 01:35:17 +01004285 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004286 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004287 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004288 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004289
4290 if (!_PyArg_NoStackKeywords("ftruncate", kwnames)) {
4291 goto exit;
4292 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004293 return_value = os_ftruncate_impl(module, fd, length);
4294
4295exit:
4296 return return_value;
4297}
4298
Steve Dowerf7377032015-04-12 15:44:54 -04004299#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004300
Steve Dowerf7377032015-04-12 15:44:54 -04004301#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004302
4303PyDoc_STRVAR(os_truncate__doc__,
4304"truncate($module, /, path, length)\n"
4305"--\n"
4306"\n"
4307"Truncate a file, specified by path, to a specific length.\n"
4308"\n"
4309"On some platforms, path may also be specified as an open file descriptor.\n"
4310" If this functionality is unavailable, using it raises an exception.");
4311
4312#define OS_TRUNCATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004313 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004314
4315static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004316os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004317
4318static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004319os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004320{
4321 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004322 static const char * const _keywords[] = {"path", "length", NULL};
4323 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004324 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4325 Py_off_t length;
4326
Victor Stinner3e1fad62017-01-17 01:29:01 +01004327 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004328 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004329 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004330 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004331 return_value = os_truncate_impl(module, &path, length);
4332
4333exit:
4334 /* Cleanup for path */
4335 path_cleanup(&path);
4336
4337 return return_value;
4338}
4339
Steve Dowerf7377032015-04-12 15:44:54 -04004340#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004341
4342#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4343
4344PyDoc_STRVAR(os_posix_fallocate__doc__,
4345"posix_fallocate($module, fd, offset, length, /)\n"
4346"--\n"
4347"\n"
4348"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4349"\n"
4350"Ensure that the file specified by fd encompasses a range of bytes\n"
4351"starting at offset bytes from the beginning and continuing for length bytes.");
4352
4353#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004354 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004355
4356static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004357os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004358 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004359
4360static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004361os_posix_fallocate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362{
4363 PyObject *return_value = NULL;
4364 int fd;
4365 Py_off_t offset;
4366 Py_off_t length;
4367
Victor Stinner259f0e42017-01-17 01:35:17 +01004368 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004369 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004371 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004372
4373 if (!_PyArg_NoStackKeywords("posix_fallocate", kwnames)) {
4374 goto exit;
4375 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004376 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4377
4378exit:
4379 return return_value;
4380}
4381
4382#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4383
4384#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4385
4386PyDoc_STRVAR(os_posix_fadvise__doc__,
4387"posix_fadvise($module, fd, offset, length, advice, /)\n"
4388"--\n"
4389"\n"
4390"Announce an intention to access data in a specific pattern.\n"
4391"\n"
4392"Announce an intention to access data in a specific pattern, thus allowing\n"
4393"the kernel to make optimizations.\n"
4394"The advice applies to the region of the file specified by fd starting at\n"
4395"offset and continuing for length bytes.\n"
4396"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4397"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4398"POSIX_FADV_DONTNEED.");
4399
4400#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004401 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004402
4403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004404os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004405 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004406
4407static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004408os_posix_fadvise(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004409{
4410 PyObject *return_value = NULL;
4411 int fd;
4412 Py_off_t offset;
4413 Py_off_t length;
4414 int advice;
4415
Victor Stinner259f0e42017-01-17 01:35:17 +01004416 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004417 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004418 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004419 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004420
4421 if (!_PyArg_NoStackKeywords("posix_fadvise", kwnames)) {
4422 goto exit;
4423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004424 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4425
4426exit:
4427 return return_value;
4428}
4429
4430#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4431
4432#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4433
4434PyDoc_STRVAR(os_putenv__doc__,
4435"putenv($module, name, value, /)\n"
4436"--\n"
4437"\n"
4438"Change or add an environment variable.");
4439
4440#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004441 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004442
4443static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004444os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004445
4446static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004447os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004448{
4449 PyObject *return_value = NULL;
4450 PyObject *name;
4451 PyObject *value;
4452
Victor Stinner259f0e42017-01-17 01:35:17 +01004453 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004454 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004455 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004456 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004457
4458 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4459 goto exit;
4460 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461 return_value = os_putenv_impl(module, name, value);
4462
4463exit:
4464 return return_value;
4465}
4466
4467#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4468
4469#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4470
4471PyDoc_STRVAR(os_putenv__doc__,
4472"putenv($module, name, value, /)\n"
4473"--\n"
4474"\n"
4475"Change or add an environment variable.");
4476
4477#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004478 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004479
4480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004481os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004482
4483static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004484os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004485{
4486 PyObject *return_value = NULL;
4487 PyObject *name = NULL;
4488 PyObject *value = NULL;
4489
Victor Stinner259f0e42017-01-17 01:35:17 +01004490 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004491 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004492 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004493 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004494
4495 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4496 goto exit;
4497 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004498 return_value = os_putenv_impl(module, name, value);
4499
4500exit:
4501 /* Cleanup for name */
4502 Py_XDECREF(name);
4503 /* Cleanup for value */
4504 Py_XDECREF(value);
4505
4506 return return_value;
4507}
4508
4509#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4510
4511#if defined(HAVE_UNSETENV)
4512
4513PyDoc_STRVAR(os_unsetenv__doc__,
4514"unsetenv($module, name, /)\n"
4515"--\n"
4516"\n"
4517"Delete an environment variable.");
4518
4519#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004520 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004521
4522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004523os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004524
4525static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004526os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004527{
4528 PyObject *return_value = NULL;
4529 PyObject *name = NULL;
4530
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004531 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004532 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004533 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004534 return_value = os_unsetenv_impl(module, name);
4535
4536exit:
4537 /* Cleanup for name */
4538 Py_XDECREF(name);
4539
4540 return return_value;
4541}
4542
4543#endif /* defined(HAVE_UNSETENV) */
4544
4545PyDoc_STRVAR(os_strerror__doc__,
4546"strerror($module, code, /)\n"
4547"--\n"
4548"\n"
4549"Translate an error code to a message string.");
4550
4551#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004552 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004553
4554static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004555os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004556
4557static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004558os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004559{
4560 PyObject *return_value = NULL;
4561 int code;
4562
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004563 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004564 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004565 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004566 return_value = os_strerror_impl(module, code);
4567
4568exit:
4569 return return_value;
4570}
4571
4572#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4573
4574PyDoc_STRVAR(os_WCOREDUMP__doc__,
4575"WCOREDUMP($module, status, /)\n"
4576"--\n"
4577"\n"
4578"Return True if the process returning status was dumped to a core file.");
4579
4580#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004581 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004582
4583static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004584os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004585
4586static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004587os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004588{
4589 PyObject *return_value = NULL;
4590 int status;
4591 int _return_value;
4592
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004593 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004594 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004595 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004596 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004597 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004598 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004599 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004600 return_value = PyBool_FromLong((long)_return_value);
4601
4602exit:
4603 return return_value;
4604}
4605
4606#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4607
4608#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4609
4610PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4611"WIFCONTINUED($module, /, status)\n"
4612"--\n"
4613"\n"
4614"Return True if a particular process was continued from a job control stop.\n"
4615"\n"
4616"Return True if the process returning status was continued from a\n"
4617"job control stop.");
4618
4619#define OS_WIFCONTINUED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004620 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004621
4622static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004623os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004624
4625static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004626os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004627{
4628 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004629 static const char * const _keywords[] = {"status", NULL};
4630 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004631 int status;
4632 int _return_value;
4633
Victor Stinner3e1fad62017-01-17 01:29:01 +01004634 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004635 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004636 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004637 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004638 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004639 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004640 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004641 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004642 return_value = PyBool_FromLong((long)_return_value);
4643
4644exit:
4645 return return_value;
4646}
4647
4648#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4649
4650#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4651
4652PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4653"WIFSTOPPED($module, /, status)\n"
4654"--\n"
4655"\n"
4656"Return True if the process returning status was stopped.");
4657
4658#define OS_WIFSTOPPED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004659 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004660
4661static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004662os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004663
4664static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004665os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004666{
4667 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004668 static const char * const _keywords[] = {"status", NULL};
4669 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004670 int status;
4671 int _return_value;
4672
Victor Stinner3e1fad62017-01-17 01:29:01 +01004673 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004674 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004675 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004676 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004677 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004678 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004679 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004680 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004681 return_value = PyBool_FromLong((long)_return_value);
4682
4683exit:
4684 return return_value;
4685}
4686
4687#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4688
4689#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4690
4691PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4692"WIFSIGNALED($module, /, status)\n"
4693"--\n"
4694"\n"
4695"Return True if the process returning status was terminated by a signal.");
4696
4697#define OS_WIFSIGNALED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004698 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004699
4700static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004701os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004702
4703static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004704os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004705{
4706 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004707 static const char * const _keywords[] = {"status", NULL};
4708 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004709 int status;
4710 int _return_value;
4711
Victor Stinner3e1fad62017-01-17 01:29:01 +01004712 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004713 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004714 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004715 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004716 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004717 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004718 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004719 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004720 return_value = PyBool_FromLong((long)_return_value);
4721
4722exit:
4723 return return_value;
4724}
4725
4726#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4727
4728#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4729
4730PyDoc_STRVAR(os_WIFEXITED__doc__,
4731"WIFEXITED($module, /, status)\n"
4732"--\n"
4733"\n"
4734"Return True if the process returning status exited via the exit() system call.");
4735
4736#define OS_WIFEXITED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004737 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004738
4739static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004740os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004741
4742static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004743os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004744{
4745 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004746 static const char * const _keywords[] = {"status", NULL};
4747 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004748 int status;
4749 int _return_value;
4750
Victor Stinner3e1fad62017-01-17 01:29:01 +01004751 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004752 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004753 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004754 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004755 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004756 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004757 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004758 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004759 return_value = PyBool_FromLong((long)_return_value);
4760
4761exit:
4762 return return_value;
4763}
4764
4765#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4766
4767#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4768
4769PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4770"WEXITSTATUS($module, /, status)\n"
4771"--\n"
4772"\n"
4773"Return the process return code from status.");
4774
4775#define OS_WEXITSTATUS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004776 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004777
4778static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004779os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004780
4781static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004782os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004783{
4784 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004785 static const char * const _keywords[] = {"status", NULL};
4786 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004787 int status;
4788 int _return_value;
4789
Victor Stinner3e1fad62017-01-17 01:29:01 +01004790 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004791 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004792 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004793 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004794 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004795 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004796 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004797 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004798 return_value = PyLong_FromLong((long)_return_value);
4799
4800exit:
4801 return return_value;
4802}
4803
4804#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4805
4806#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4807
4808PyDoc_STRVAR(os_WTERMSIG__doc__,
4809"WTERMSIG($module, /, status)\n"
4810"--\n"
4811"\n"
4812"Return the signal that terminated the process that provided the status value.");
4813
4814#define OS_WTERMSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004815 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004816
4817static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004818os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004819
4820static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004821os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004822{
4823 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004824 static const char * const _keywords[] = {"status", NULL};
4825 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004826 int status;
4827 int _return_value;
4828
Victor Stinner3e1fad62017-01-17 01:29:01 +01004829 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004830 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004831 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004832 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004833 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004834 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004835 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004836 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004837 return_value = PyLong_FromLong((long)_return_value);
4838
4839exit:
4840 return return_value;
4841}
4842
4843#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4844
4845#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4846
4847PyDoc_STRVAR(os_WSTOPSIG__doc__,
4848"WSTOPSIG($module, /, status)\n"
4849"--\n"
4850"\n"
4851"Return the signal that stopped the process that provided the status value.");
4852
4853#define OS_WSTOPSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004854 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004855
4856static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004857os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004858
4859static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004860os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004861{
4862 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004863 static const char * const _keywords[] = {"status", NULL};
4864 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004865 int status;
4866 int _return_value;
4867
Victor Stinner3e1fad62017-01-17 01:29:01 +01004868 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004869 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004872 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004873 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004874 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004875 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004876 return_value = PyLong_FromLong((long)_return_value);
4877
4878exit:
4879 return return_value;
4880}
4881
4882#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4883
4884#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4885
4886PyDoc_STRVAR(os_fstatvfs__doc__,
4887"fstatvfs($module, fd, /)\n"
4888"--\n"
4889"\n"
4890"Perform an fstatvfs system call on the given fd.\n"
4891"\n"
4892"Equivalent to statvfs(fd).");
4893
4894#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004895 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004896
4897static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004898os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004899
4900static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004901os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004902{
4903 PyObject *return_value = NULL;
4904 int fd;
4905
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004906 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004907 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004908 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004909 return_value = os_fstatvfs_impl(module, fd);
4910
4911exit:
4912 return return_value;
4913}
4914
4915#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4916
4917#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4918
4919PyDoc_STRVAR(os_statvfs__doc__,
4920"statvfs($module, /, path)\n"
4921"--\n"
4922"\n"
4923"Perform a statvfs system call on the given path.\n"
4924"\n"
4925"path may always be specified as a string.\n"
4926"On some platforms, path may also be specified as an open file descriptor.\n"
4927" If this functionality is unavailable, using it raises an exception.");
4928
4929#define OS_STATVFS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004930 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004931
4932static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004933os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004934
4935static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004936os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004937{
4938 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004939 static const char * const _keywords[] = {"path", NULL};
4940 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004941 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4942
Victor Stinner3e1fad62017-01-17 01:29:01 +01004943 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004944 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004945 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004946 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004947 return_value = os_statvfs_impl(module, &path);
4948
4949exit:
4950 /* Cleanup for path */
4951 path_cleanup(&path);
4952
4953 return return_value;
4954}
4955
4956#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4957
4958#if defined(MS_WINDOWS)
4959
4960PyDoc_STRVAR(os__getdiskusage__doc__,
4961"_getdiskusage($module, /, path)\n"
4962"--\n"
4963"\n"
4964"Return disk usage statistics about the given path as a (total, free) tuple.");
4965
4966#define OS__GETDISKUSAGE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004967 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004968
4969static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004970os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004971
4972static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004973os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004974{
4975 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004976 static const char * const _keywords[] = {"path", NULL};
4977 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978 Py_UNICODE *path;
4979
Victor Stinner3e1fad62017-01-17 01:29:01 +01004980 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004981 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004982 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004983 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984 return_value = os__getdiskusage_impl(module, path);
4985
4986exit:
4987 return return_value;
4988}
4989
4990#endif /* defined(MS_WINDOWS) */
4991
4992#if defined(HAVE_FPATHCONF)
4993
4994PyDoc_STRVAR(os_fpathconf__doc__,
4995"fpathconf($module, fd, name, /)\n"
4996"--\n"
4997"\n"
4998"Return the configuration limit name for the file descriptor fd.\n"
4999"\n"
5000"If there is no limit, return -1.");
5001
5002#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005003 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005004
5005static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005006os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005007
5008static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005009os_fpathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005010{
5011 PyObject *return_value = NULL;
5012 int fd;
5013 int name;
5014 long _return_value;
5015
Victor Stinner259f0e42017-01-17 01:35:17 +01005016 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005017 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005018 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005019 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005020
5021 if (!_PyArg_NoStackKeywords("fpathconf", kwnames)) {
5022 goto exit;
5023 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005024 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005025 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005026 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005027 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005028 return_value = PyLong_FromLong(_return_value);
5029
5030exit:
5031 return return_value;
5032}
5033
5034#endif /* defined(HAVE_FPATHCONF) */
5035
5036#if defined(HAVE_PATHCONF)
5037
5038PyDoc_STRVAR(os_pathconf__doc__,
5039"pathconf($module, /, path, name)\n"
5040"--\n"
5041"\n"
5042"Return the configuration limit name for the file or directory path.\n"
5043"\n"
5044"If there is no limit, return -1.\n"
5045"On some platforms, path may also be specified as an open file descriptor.\n"
5046" If this functionality is unavailable, using it raises an exception.");
5047
5048#define OS_PATHCONF_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005049 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005050
5051static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005052os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005053
5054static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005055os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005056{
5057 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005058 static const char * const _keywords[] = {"path", "name", NULL};
5059 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5061 int name;
5062 long _return_value;
5063
Victor Stinner3e1fad62017-01-17 01:29:01 +01005064 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005065 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005066 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005067 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005068 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005069 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005070 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005071 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005072 return_value = PyLong_FromLong(_return_value);
5073
5074exit:
5075 /* Cleanup for path */
5076 path_cleanup(&path);
5077
5078 return return_value;
5079}
5080
5081#endif /* defined(HAVE_PATHCONF) */
5082
5083#if defined(HAVE_CONFSTR)
5084
5085PyDoc_STRVAR(os_confstr__doc__,
5086"confstr($module, name, /)\n"
5087"--\n"
5088"\n"
5089"Return a string-valued system configuration variable.");
5090
5091#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005092 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005093
5094static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005095os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005096
5097static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005098os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005099{
5100 PyObject *return_value = NULL;
5101 int name;
5102
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005103 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005105 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005106 return_value = os_confstr_impl(module, name);
5107
5108exit:
5109 return return_value;
5110}
5111
5112#endif /* defined(HAVE_CONFSTR) */
5113
5114#if defined(HAVE_SYSCONF)
5115
5116PyDoc_STRVAR(os_sysconf__doc__,
5117"sysconf($module, name, /)\n"
5118"--\n"
5119"\n"
5120"Return an integer-valued system configuration variable.");
5121
5122#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005123 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005124
5125static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005126os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005127
5128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005129os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005130{
5131 PyObject *return_value = NULL;
5132 int name;
5133 long _return_value;
5134
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005135 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005136 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005137 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005138 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005139 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005140 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005141 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005142 return_value = PyLong_FromLong(_return_value);
5143
5144exit:
5145 return return_value;
5146}
5147
5148#endif /* defined(HAVE_SYSCONF) */
5149
5150PyDoc_STRVAR(os_abort__doc__,
5151"abort($module, /)\n"
5152"--\n"
5153"\n"
5154"Abort the interpreter immediately.\n"
5155"\n"
5156"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5157"on the hosting operating system. This function never returns.");
5158
5159#define OS_ABORT_METHODDEF \
5160 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5161
5162static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005163os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005164
5165static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005166os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005167{
5168 return os_abort_impl(module);
5169}
5170
Steve Dowercc16be82016-09-08 10:35:16 -07005171#if defined(MS_WINDOWS)
5172
5173PyDoc_STRVAR(os_startfile__doc__,
5174"startfile($module, /, filepath, operation=None)\n"
5175"--\n"
5176"\n"
5177"startfile(filepath [, operation])\n"
5178"\n"
5179"Start a file with its associated application.\n"
5180"\n"
5181"When \"operation\" is not specified or \"open\", this acts like\n"
5182"double-clicking the file in Explorer, or giving the file name as an\n"
5183"argument to the DOS \"start\" command: the file is opened with whatever\n"
5184"application (if any) its extension is associated.\n"
5185"When another \"operation\" is given, it specifies what should be done with\n"
5186"the file. A typical operation is \"print\".\n"
5187"\n"
5188"startfile returns as soon as the associated application is launched.\n"
5189"There is no option to wait for the application to close, and no way\n"
5190"to retrieve the application\'s exit status.\n"
5191"\n"
5192"The filepath is relative to the current directory. If you want to use\n"
5193"an absolute path, make sure the first character is not a slash (\"/\");\n"
5194"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5195
5196#define OS_STARTFILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005197 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005198
5199static PyObject *
5200os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5201
5202static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005203os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005204{
5205 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005206 static const char * const _keywords[] = {"filepath", "operation", NULL};
5207 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005208 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5209 Py_UNICODE *operation = NULL;
5210
Victor Stinner3e1fad62017-01-17 01:29:01 +01005211 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005212 path_converter, &filepath, &operation)) {
5213 goto exit;
5214 }
5215 return_value = os_startfile_impl(module, &filepath, operation);
5216
5217exit:
5218 /* Cleanup for filepath */
5219 path_cleanup(&filepath);
5220
5221 return return_value;
5222}
5223
5224#endif /* defined(MS_WINDOWS) */
5225
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005226#if defined(HAVE_GETLOADAVG)
5227
5228PyDoc_STRVAR(os_getloadavg__doc__,
5229"getloadavg($module, /)\n"
5230"--\n"
5231"\n"
5232"Return average recent system load information.\n"
5233"\n"
5234"Return the number of processes in the system run queue averaged over\n"
5235"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5236"Raises OSError if the load average was unobtainable.");
5237
5238#define OS_GETLOADAVG_METHODDEF \
5239 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5240
5241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005242os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005243
5244static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005245os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005246{
5247 return os_getloadavg_impl(module);
5248}
5249
5250#endif /* defined(HAVE_GETLOADAVG) */
5251
5252PyDoc_STRVAR(os_device_encoding__doc__,
5253"device_encoding($module, /, fd)\n"
5254"--\n"
5255"\n"
5256"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5257"\n"
5258"The file descriptor must be attached to a terminal.\n"
5259"If the device is not a terminal, return None.");
5260
5261#define OS_DEVICE_ENCODING_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005262 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005263
5264static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005265os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005266
5267static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005268os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005269{
5270 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005271 static const char * const _keywords[] = {"fd", NULL};
5272 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005273 int fd;
5274
Victor Stinner3e1fad62017-01-17 01:29:01 +01005275 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005276 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005277 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005278 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005279 return_value = os_device_encoding_impl(module, fd);
5280
5281exit:
5282 return return_value;
5283}
5284
5285#if defined(HAVE_SETRESUID)
5286
5287PyDoc_STRVAR(os_setresuid__doc__,
5288"setresuid($module, ruid, euid, suid, /)\n"
5289"--\n"
5290"\n"
5291"Set the current process\'s real, effective, and saved user ids.");
5292
5293#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005294 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005295
5296static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005297os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005298
5299static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005300os_setresuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005301{
5302 PyObject *return_value = NULL;
5303 uid_t ruid;
5304 uid_t euid;
5305 uid_t suid;
5306
Victor Stinner259f0e42017-01-17 01:35:17 +01005307 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005308 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005309 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005310 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005311
5312 if (!_PyArg_NoStackKeywords("setresuid", kwnames)) {
5313 goto exit;
5314 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005315 return_value = os_setresuid_impl(module, ruid, euid, suid);
5316
5317exit:
5318 return return_value;
5319}
5320
5321#endif /* defined(HAVE_SETRESUID) */
5322
5323#if defined(HAVE_SETRESGID)
5324
5325PyDoc_STRVAR(os_setresgid__doc__,
5326"setresgid($module, rgid, egid, sgid, /)\n"
5327"--\n"
5328"\n"
5329"Set the current process\'s real, effective, and saved group ids.");
5330
5331#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005332 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005333
5334static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005335os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005336
5337static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005338os_setresgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005339{
5340 PyObject *return_value = NULL;
5341 gid_t rgid;
5342 gid_t egid;
5343 gid_t sgid;
5344
Victor Stinner259f0e42017-01-17 01:35:17 +01005345 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005346 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005347 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005348 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005349
5350 if (!_PyArg_NoStackKeywords("setresgid", kwnames)) {
5351 goto exit;
5352 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005353 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5354
5355exit:
5356 return return_value;
5357}
5358
5359#endif /* defined(HAVE_SETRESGID) */
5360
5361#if defined(HAVE_GETRESUID)
5362
5363PyDoc_STRVAR(os_getresuid__doc__,
5364"getresuid($module, /)\n"
5365"--\n"
5366"\n"
5367"Return a tuple of the current process\'s real, effective, and saved user ids.");
5368
5369#define OS_GETRESUID_METHODDEF \
5370 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5371
5372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005373os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005374
5375static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005376os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005377{
5378 return os_getresuid_impl(module);
5379}
5380
5381#endif /* defined(HAVE_GETRESUID) */
5382
5383#if defined(HAVE_GETRESGID)
5384
5385PyDoc_STRVAR(os_getresgid__doc__,
5386"getresgid($module, /)\n"
5387"--\n"
5388"\n"
5389"Return a tuple of the current process\'s real, effective, and saved group ids.");
5390
5391#define OS_GETRESGID_METHODDEF \
5392 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5393
5394static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005395os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005396
5397static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005398os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005399{
5400 return os_getresgid_impl(module);
5401}
5402
5403#endif /* defined(HAVE_GETRESGID) */
5404
5405#if defined(USE_XATTRS)
5406
5407PyDoc_STRVAR(os_getxattr__doc__,
5408"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5409"--\n"
5410"\n"
5411"Return the value of extended attribute attribute on path.\n"
5412"\n"
5413"path may be either a string or an open file descriptor.\n"
5414"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5415" link, getxattr will examine the symbolic link itself instead of the file\n"
5416" the link points to.");
5417
5418#define OS_GETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005419 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005420
5421static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005422os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005423 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005424
5425static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005426os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005427{
5428 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005429 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5430 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5432 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5433 int follow_symlinks = 1;
5434
Victor Stinner3e1fad62017-01-17 01:29:01 +01005435 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005436 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005437 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005438 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005439 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5440
5441exit:
5442 /* Cleanup for path */
5443 path_cleanup(&path);
5444 /* Cleanup for attribute */
5445 path_cleanup(&attribute);
5446
5447 return return_value;
5448}
5449
5450#endif /* defined(USE_XATTRS) */
5451
5452#if defined(USE_XATTRS)
5453
5454PyDoc_STRVAR(os_setxattr__doc__,
5455"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5456" follow_symlinks=True)\n"
5457"--\n"
5458"\n"
5459"Set extended attribute attribute on path to value.\n"
5460"\n"
5461"path may be either a string or an open file descriptor.\n"
5462"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5463" link, setxattr will modify the symbolic link itself instead of the file\n"
5464" the link points to.");
5465
5466#define OS_SETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005467 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005468
5469static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005470os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005471 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005472
5473static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005474os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005475{
5476 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005477 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5478 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005479 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5480 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5481 Py_buffer value = {NULL, NULL};
5482 int flags = 0;
5483 int follow_symlinks = 1;
5484
Victor Stinner3e1fad62017-01-17 01:29:01 +01005485 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005486 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005487 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005488 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005489 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5490
5491exit:
5492 /* Cleanup for path */
5493 path_cleanup(&path);
5494 /* Cleanup for attribute */
5495 path_cleanup(&attribute);
5496 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005497 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005498 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005499 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005500
5501 return return_value;
5502}
5503
5504#endif /* defined(USE_XATTRS) */
5505
5506#if defined(USE_XATTRS)
5507
5508PyDoc_STRVAR(os_removexattr__doc__,
5509"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5510"--\n"
5511"\n"
5512"Remove extended attribute attribute on path.\n"
5513"\n"
5514"path may be either a string or an open file descriptor.\n"
5515"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5516" link, removexattr will modify the symbolic link itself instead of the file\n"
5517" the link points to.");
5518
5519#define OS_REMOVEXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005520 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005521
5522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005523os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005524 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005525
5526static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005527os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005528{
5529 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005530 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5531 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005532 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5533 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5534 int follow_symlinks = 1;
5535
Victor Stinner3e1fad62017-01-17 01:29:01 +01005536 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005537 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005538 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005539 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005540 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5541
5542exit:
5543 /* Cleanup for path */
5544 path_cleanup(&path);
5545 /* Cleanup for attribute */
5546 path_cleanup(&attribute);
5547
5548 return return_value;
5549}
5550
5551#endif /* defined(USE_XATTRS) */
5552
5553#if defined(USE_XATTRS)
5554
5555PyDoc_STRVAR(os_listxattr__doc__,
5556"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5557"--\n"
5558"\n"
5559"Return a list of extended attributes on path.\n"
5560"\n"
5561"path may be either None, a string, or an open file descriptor.\n"
5562"if path is None, listxattr will examine the current directory.\n"
5563"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5564" link, listxattr will examine the symbolic link itself instead of the file\n"
5565" the link points to.");
5566
5567#define OS_LISTXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005568 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005569
5570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005571os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005572
5573static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005574os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005575{
5576 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005577 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5578 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005579 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5580 int follow_symlinks = 1;
5581
Victor Stinner3e1fad62017-01-17 01:29:01 +01005582 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005583 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005584 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005585 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005586 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5587
5588exit:
5589 /* Cleanup for path */
5590 path_cleanup(&path);
5591
5592 return return_value;
5593}
5594
5595#endif /* defined(USE_XATTRS) */
5596
5597PyDoc_STRVAR(os_urandom__doc__,
5598"urandom($module, size, /)\n"
5599"--\n"
5600"\n"
5601"Return a bytes object containing random bytes suitable for cryptographic use.");
5602
5603#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005604 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005605
5606static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005607os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005608
5609static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005610os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005611{
5612 PyObject *return_value = NULL;
5613 Py_ssize_t size;
5614
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005615 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005616 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005617 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005618 return_value = os_urandom_impl(module, size);
5619
5620exit:
5621 return return_value;
5622}
5623
5624PyDoc_STRVAR(os_cpu_count__doc__,
5625"cpu_count($module, /)\n"
5626"--\n"
5627"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005628"Return the number of CPUs in the system; return None if indeterminable.\n"
5629"\n"
5630"This number is not equivalent to the number of CPUs the current process can\n"
5631"use. The number of usable CPUs can be obtained with\n"
5632"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005633
5634#define OS_CPU_COUNT_METHODDEF \
5635 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5636
5637static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005638os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005639
5640static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005641os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005642{
5643 return os_cpu_count_impl(module);
5644}
5645
5646PyDoc_STRVAR(os_get_inheritable__doc__,
5647"get_inheritable($module, fd, /)\n"
5648"--\n"
5649"\n"
5650"Get the close-on-exe flag of the specified file descriptor.");
5651
5652#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005653 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005654
5655static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005656os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005657
5658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005659os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005660{
5661 PyObject *return_value = NULL;
5662 int fd;
5663 int _return_value;
5664
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005665 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005666 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005667 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005668 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005669 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005670 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005672 return_value = PyBool_FromLong((long)_return_value);
5673
5674exit:
5675 return return_value;
5676}
5677
5678PyDoc_STRVAR(os_set_inheritable__doc__,
5679"set_inheritable($module, fd, inheritable, /)\n"
5680"--\n"
5681"\n"
5682"Set the inheritable flag of the specified file descriptor.");
5683
5684#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005685 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005686
5687static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005688os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005689
5690static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005691os_set_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005692{
5693 PyObject *return_value = NULL;
5694 int fd;
5695 int inheritable;
5696
Victor Stinner259f0e42017-01-17 01:35:17 +01005697 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005698 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005699 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005700 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005701
5702 if (!_PyArg_NoStackKeywords("set_inheritable", kwnames)) {
5703 goto exit;
5704 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005705 return_value = os_set_inheritable_impl(module, fd, inheritable);
5706
5707exit:
5708 return return_value;
5709}
5710
5711#if defined(MS_WINDOWS)
5712
5713PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5714"get_handle_inheritable($module, handle, /)\n"
5715"--\n"
5716"\n"
5717"Get the close-on-exe flag of the specified file descriptor.");
5718
5719#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005720 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005721
5722static int
Victor Stinner581139c2016-09-06 15:54:20 -07005723os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005724
5725static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005726os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005727{
5728 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005729 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005730 int _return_value;
5731
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005732 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005733 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005734 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005735 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005736 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005737 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005738 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005739 return_value = PyBool_FromLong((long)_return_value);
5740
5741exit:
5742 return return_value;
5743}
5744
5745#endif /* defined(MS_WINDOWS) */
5746
5747#if defined(MS_WINDOWS)
5748
5749PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5750"set_handle_inheritable($module, handle, inheritable, /)\n"
5751"--\n"
5752"\n"
5753"Set the inheritable flag of the specified handle.");
5754
5755#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005756 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005757
5758static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005759os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005760 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761
5762static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005763os_set_handle_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005764{
5765 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005766 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005767 int inheritable;
5768
Victor Stinner259f0e42017-01-17 01:35:17 +01005769 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005770 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005771 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005772 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005773
5774 if (!_PyArg_NoStackKeywords("set_handle_inheritable", kwnames)) {
5775 goto exit;
5776 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005777 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5778
5779exit:
5780 return return_value;
5781}
5782
5783#endif /* defined(MS_WINDOWS) */
5784
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005785PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5786"is_symlink($self, /)\n"
5787"--\n"
5788"\n"
5789"Return True if the entry is a symbolic link; cached per entry.");
5790
5791#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5792 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5793
5794static int
5795os_DirEntry_is_symlink_impl(DirEntry *self);
5796
5797static PyObject *
5798os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5799{
5800 PyObject *return_value = NULL;
5801 int _return_value;
5802
5803 _return_value = os_DirEntry_is_symlink_impl(self);
5804 if ((_return_value == -1) && PyErr_Occurred()) {
5805 goto exit;
5806 }
5807 return_value = PyBool_FromLong((long)_return_value);
5808
5809exit:
5810 return return_value;
5811}
5812
5813PyDoc_STRVAR(os_DirEntry_stat__doc__,
5814"stat($self, /, *, follow_symlinks=True)\n"
5815"--\n"
5816"\n"
5817"Return stat_result object for the entry; cached per entry.");
5818
5819#define OS_DIRENTRY_STAT_METHODDEF \
5820 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL, os_DirEntry_stat__doc__},
5821
5822static PyObject *
5823os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5824
5825static PyObject *
5826os_DirEntry_stat(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5827{
5828 PyObject *return_value = NULL;
5829 static const char * const _keywords[] = {"follow_symlinks", NULL};
5830 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5831 int follow_symlinks = 1;
5832
Victor Stinner3e1fad62017-01-17 01:29:01 +01005833 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005834 &follow_symlinks)) {
5835 goto exit;
5836 }
5837 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5838
5839exit:
5840 return return_value;
5841}
5842
5843PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5844"is_dir($self, /, *, follow_symlinks=True)\n"
5845"--\n"
5846"\n"
5847"Return True if the entry is a directory; cached per entry.");
5848
5849#define OS_DIRENTRY_IS_DIR_METHODDEF \
5850 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL, os_DirEntry_is_dir__doc__},
5851
5852static int
5853os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5854
5855static PyObject *
5856os_DirEntry_is_dir(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5857{
5858 PyObject *return_value = NULL;
5859 static const char * const _keywords[] = {"follow_symlinks", NULL};
5860 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5861 int follow_symlinks = 1;
5862 int _return_value;
5863
Victor Stinner3e1fad62017-01-17 01:29:01 +01005864 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005865 &follow_symlinks)) {
5866 goto exit;
5867 }
5868 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5869 if ((_return_value == -1) && PyErr_Occurred()) {
5870 goto exit;
5871 }
5872 return_value = PyBool_FromLong((long)_return_value);
5873
5874exit:
5875 return return_value;
5876}
5877
5878PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5879"is_file($self, /, *, follow_symlinks=True)\n"
5880"--\n"
5881"\n"
5882"Return True if the entry is a file; cached per entry.");
5883
5884#define OS_DIRENTRY_IS_FILE_METHODDEF \
5885 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL, os_DirEntry_is_file__doc__},
5886
5887static int
5888os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5889
5890static PyObject *
5891os_DirEntry_is_file(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5892{
5893 PyObject *return_value = NULL;
5894 static const char * const _keywords[] = {"follow_symlinks", NULL};
5895 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5896 int follow_symlinks = 1;
5897 int _return_value;
5898
Victor Stinner3e1fad62017-01-17 01:29:01 +01005899 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005900 &follow_symlinks)) {
5901 goto exit;
5902 }
5903 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5904 if ((_return_value == -1) && PyErr_Occurred()) {
5905 goto exit;
5906 }
5907 return_value = PyBool_FromLong((long)_return_value);
5908
5909exit:
5910 return return_value;
5911}
5912
5913PyDoc_STRVAR(os_DirEntry_inode__doc__,
5914"inode($self, /)\n"
5915"--\n"
5916"\n"
5917"Return inode of the entry; cached per entry.");
5918
5919#define OS_DIRENTRY_INODE_METHODDEF \
5920 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5921
5922static PyObject *
5923os_DirEntry_inode_impl(DirEntry *self);
5924
5925static PyObject *
5926os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5927{
5928 return os_DirEntry_inode_impl(self);
5929}
5930
5931PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5932"__fspath__($self, /)\n"
5933"--\n"
5934"\n"
5935"Returns the path for the entry.");
5936
5937#define OS_DIRENTRY___FSPATH___METHODDEF \
5938 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5939
5940static PyObject *
5941os_DirEntry___fspath___impl(DirEntry *self);
5942
5943static PyObject *
5944os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5945{
5946 return os_DirEntry___fspath___impl(self);
5947}
5948
5949PyDoc_STRVAR(os_scandir__doc__,
5950"scandir($module, /, path=None)\n"
5951"--\n"
5952"\n"
5953"Return an iterator of DirEntry objects for given path.\n"
5954"\n"
5955"path can be specified as either str, bytes or path-like object. If path\n"
5956"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5957"all other circumstances they will be str.\n"
5958"\n"
5959"If path is None, uses the path=\'.\'.");
5960
5961#define OS_SCANDIR_METHODDEF \
5962 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL, os_scandir__doc__},
5963
5964static PyObject *
5965os_scandir_impl(PyObject *module, path_t *path);
5966
5967static PyObject *
5968os_scandir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5969{
5970 PyObject *return_value = NULL;
5971 static const char * const _keywords[] = {"path", NULL};
5972 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03005973 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005974
Victor Stinner3e1fad62017-01-17 01:29:01 +01005975 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005976 path_converter, &path)) {
5977 goto exit;
5978 }
5979 return_value = os_scandir_impl(module, &path);
5980
5981exit:
5982 /* Cleanup for path */
5983 path_cleanup(&path);
5984
5985 return return_value;
5986}
5987
Ethan Furman410ef8e2016-06-04 12:06:26 -07005988PyDoc_STRVAR(os_fspath__doc__,
5989"fspath($module, /, path)\n"
5990"--\n"
5991"\n"
5992"Return the file system path representation of the object.\n"
5993"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005994"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5995"object defines __fspath__(), then return the result of that method. All other\n"
5996"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005997
5998#define OS_FSPATH_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005999 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006000
6001static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006002os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006003
6004static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07006005os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006006{
6007 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006008 static const char * const _keywords[] = {"path", NULL};
6009 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006010 PyObject *path;
6011
Victor Stinner3e1fad62017-01-17 01:29:01 +01006012 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006013 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006014 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006015 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006016 return_value = os_fspath_impl(module, path);
6017
6018exit:
6019 return return_value;
6020}
6021
Victor Stinner9b1f4742016-09-06 16:18:52 -07006022#if defined(HAVE_GETRANDOM_SYSCALL)
6023
6024PyDoc_STRVAR(os_getrandom__doc__,
6025"getrandom($module, /, size, flags=0)\n"
6026"--\n"
6027"\n"
6028"Obtain a series of random bytes.");
6029
6030#define OS_GETRANDOM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07006031 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006032
6033static PyObject *
6034os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6035
6036static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07006037os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006038{
6039 PyObject *return_value = NULL;
6040 static const char * const _keywords[] = {"size", "flags", NULL};
6041 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6042 Py_ssize_t size;
6043 int flags = 0;
6044
Victor Stinner3e1fad62017-01-17 01:29:01 +01006045 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006046 &size, &flags)) {
6047 goto exit;
6048 }
6049 return_value = os_getrandom_impl(module, size, flags);
6050
6051exit:
6052 return return_value;
6053}
6054
6055#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6056
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006057#ifndef OS_TTYNAME_METHODDEF
6058 #define OS_TTYNAME_METHODDEF
6059#endif /* !defined(OS_TTYNAME_METHODDEF) */
6060
6061#ifndef OS_CTERMID_METHODDEF
6062 #define OS_CTERMID_METHODDEF
6063#endif /* !defined(OS_CTERMID_METHODDEF) */
6064
6065#ifndef OS_FCHDIR_METHODDEF
6066 #define OS_FCHDIR_METHODDEF
6067#endif /* !defined(OS_FCHDIR_METHODDEF) */
6068
6069#ifndef OS_FCHMOD_METHODDEF
6070 #define OS_FCHMOD_METHODDEF
6071#endif /* !defined(OS_FCHMOD_METHODDEF) */
6072
6073#ifndef OS_LCHMOD_METHODDEF
6074 #define OS_LCHMOD_METHODDEF
6075#endif /* !defined(OS_LCHMOD_METHODDEF) */
6076
6077#ifndef OS_CHFLAGS_METHODDEF
6078 #define OS_CHFLAGS_METHODDEF
6079#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6080
6081#ifndef OS_LCHFLAGS_METHODDEF
6082 #define OS_LCHFLAGS_METHODDEF
6083#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6084
6085#ifndef OS_CHROOT_METHODDEF
6086 #define OS_CHROOT_METHODDEF
6087#endif /* !defined(OS_CHROOT_METHODDEF) */
6088
6089#ifndef OS_FSYNC_METHODDEF
6090 #define OS_FSYNC_METHODDEF
6091#endif /* !defined(OS_FSYNC_METHODDEF) */
6092
6093#ifndef OS_SYNC_METHODDEF
6094 #define OS_SYNC_METHODDEF
6095#endif /* !defined(OS_SYNC_METHODDEF) */
6096
6097#ifndef OS_FDATASYNC_METHODDEF
6098 #define OS_FDATASYNC_METHODDEF
6099#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6100
6101#ifndef OS_CHOWN_METHODDEF
6102 #define OS_CHOWN_METHODDEF
6103#endif /* !defined(OS_CHOWN_METHODDEF) */
6104
6105#ifndef OS_FCHOWN_METHODDEF
6106 #define OS_FCHOWN_METHODDEF
6107#endif /* !defined(OS_FCHOWN_METHODDEF) */
6108
6109#ifndef OS_LCHOWN_METHODDEF
6110 #define OS_LCHOWN_METHODDEF
6111#endif /* !defined(OS_LCHOWN_METHODDEF) */
6112
6113#ifndef OS_LINK_METHODDEF
6114 #define OS_LINK_METHODDEF
6115#endif /* !defined(OS_LINK_METHODDEF) */
6116
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006117#ifndef OS__GETFULLPATHNAME_METHODDEF
6118 #define OS__GETFULLPATHNAME_METHODDEF
6119#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6120
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006121#ifndef OS__GETFINALPATHNAME_METHODDEF
6122 #define OS__GETFINALPATHNAME_METHODDEF
6123#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6124
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006125#ifndef OS__ISDIR_METHODDEF
6126 #define OS__ISDIR_METHODDEF
6127#endif /* !defined(OS__ISDIR_METHODDEF) */
6128
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006129#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6130 #define OS__GETVOLUMEPATHNAME_METHODDEF
6131#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6132
6133#ifndef OS_NICE_METHODDEF
6134 #define OS_NICE_METHODDEF
6135#endif /* !defined(OS_NICE_METHODDEF) */
6136
6137#ifndef OS_GETPRIORITY_METHODDEF
6138 #define OS_GETPRIORITY_METHODDEF
6139#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6140
6141#ifndef OS_SETPRIORITY_METHODDEF
6142 #define OS_SETPRIORITY_METHODDEF
6143#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6144
6145#ifndef OS_SYSTEM_METHODDEF
6146 #define OS_SYSTEM_METHODDEF
6147#endif /* !defined(OS_SYSTEM_METHODDEF) */
6148
6149#ifndef OS_UNAME_METHODDEF
6150 #define OS_UNAME_METHODDEF
6151#endif /* !defined(OS_UNAME_METHODDEF) */
6152
6153#ifndef OS_EXECV_METHODDEF
6154 #define OS_EXECV_METHODDEF
6155#endif /* !defined(OS_EXECV_METHODDEF) */
6156
6157#ifndef OS_EXECVE_METHODDEF
6158 #define OS_EXECVE_METHODDEF
6159#endif /* !defined(OS_EXECVE_METHODDEF) */
6160
6161#ifndef OS_SPAWNV_METHODDEF
6162 #define OS_SPAWNV_METHODDEF
6163#endif /* !defined(OS_SPAWNV_METHODDEF) */
6164
6165#ifndef OS_SPAWNVE_METHODDEF
6166 #define OS_SPAWNVE_METHODDEF
6167#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6168
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006169#ifndef OS_REGISTER_AT_FORK_METHODDEF
6170 #define OS_REGISTER_AT_FORK_METHODDEF
6171#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6172
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006173#ifndef OS_FORK1_METHODDEF
6174 #define OS_FORK1_METHODDEF
6175#endif /* !defined(OS_FORK1_METHODDEF) */
6176
6177#ifndef OS_FORK_METHODDEF
6178 #define OS_FORK_METHODDEF
6179#endif /* !defined(OS_FORK_METHODDEF) */
6180
6181#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6182 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6183#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6184
6185#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6186 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6187#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6188
6189#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6190 #define OS_SCHED_GETSCHEDULER_METHODDEF
6191#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6192
6193#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6194 #define OS_SCHED_SETSCHEDULER_METHODDEF
6195#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6196
6197#ifndef OS_SCHED_GETPARAM_METHODDEF
6198 #define OS_SCHED_GETPARAM_METHODDEF
6199#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6200
6201#ifndef OS_SCHED_SETPARAM_METHODDEF
6202 #define OS_SCHED_SETPARAM_METHODDEF
6203#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6204
6205#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6206 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6207#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6208
6209#ifndef OS_SCHED_YIELD_METHODDEF
6210 #define OS_SCHED_YIELD_METHODDEF
6211#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6212
6213#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6214 #define OS_SCHED_SETAFFINITY_METHODDEF
6215#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6216
6217#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6218 #define OS_SCHED_GETAFFINITY_METHODDEF
6219#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6220
6221#ifndef OS_OPENPTY_METHODDEF
6222 #define OS_OPENPTY_METHODDEF
6223#endif /* !defined(OS_OPENPTY_METHODDEF) */
6224
6225#ifndef OS_FORKPTY_METHODDEF
6226 #define OS_FORKPTY_METHODDEF
6227#endif /* !defined(OS_FORKPTY_METHODDEF) */
6228
6229#ifndef OS_GETEGID_METHODDEF
6230 #define OS_GETEGID_METHODDEF
6231#endif /* !defined(OS_GETEGID_METHODDEF) */
6232
6233#ifndef OS_GETEUID_METHODDEF
6234 #define OS_GETEUID_METHODDEF
6235#endif /* !defined(OS_GETEUID_METHODDEF) */
6236
6237#ifndef OS_GETGID_METHODDEF
6238 #define OS_GETGID_METHODDEF
6239#endif /* !defined(OS_GETGID_METHODDEF) */
6240
Berker Peksag39404992016-09-15 20:45:16 +03006241#ifndef OS_GETPID_METHODDEF
6242 #define OS_GETPID_METHODDEF
6243#endif /* !defined(OS_GETPID_METHODDEF) */
6244
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006245#ifndef OS_GETGROUPS_METHODDEF
6246 #define OS_GETGROUPS_METHODDEF
6247#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6248
6249#ifndef OS_GETPGID_METHODDEF
6250 #define OS_GETPGID_METHODDEF
6251#endif /* !defined(OS_GETPGID_METHODDEF) */
6252
6253#ifndef OS_GETPGRP_METHODDEF
6254 #define OS_GETPGRP_METHODDEF
6255#endif /* !defined(OS_GETPGRP_METHODDEF) */
6256
6257#ifndef OS_SETPGRP_METHODDEF
6258 #define OS_SETPGRP_METHODDEF
6259#endif /* !defined(OS_SETPGRP_METHODDEF) */
6260
6261#ifndef OS_GETPPID_METHODDEF
6262 #define OS_GETPPID_METHODDEF
6263#endif /* !defined(OS_GETPPID_METHODDEF) */
6264
6265#ifndef OS_GETLOGIN_METHODDEF
6266 #define OS_GETLOGIN_METHODDEF
6267#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6268
6269#ifndef OS_GETUID_METHODDEF
6270 #define OS_GETUID_METHODDEF
6271#endif /* !defined(OS_GETUID_METHODDEF) */
6272
6273#ifndef OS_KILL_METHODDEF
6274 #define OS_KILL_METHODDEF
6275#endif /* !defined(OS_KILL_METHODDEF) */
6276
6277#ifndef OS_KILLPG_METHODDEF
6278 #define OS_KILLPG_METHODDEF
6279#endif /* !defined(OS_KILLPG_METHODDEF) */
6280
6281#ifndef OS_PLOCK_METHODDEF
6282 #define OS_PLOCK_METHODDEF
6283#endif /* !defined(OS_PLOCK_METHODDEF) */
6284
6285#ifndef OS_SETUID_METHODDEF
6286 #define OS_SETUID_METHODDEF
6287#endif /* !defined(OS_SETUID_METHODDEF) */
6288
6289#ifndef OS_SETEUID_METHODDEF
6290 #define OS_SETEUID_METHODDEF
6291#endif /* !defined(OS_SETEUID_METHODDEF) */
6292
6293#ifndef OS_SETEGID_METHODDEF
6294 #define OS_SETEGID_METHODDEF
6295#endif /* !defined(OS_SETEGID_METHODDEF) */
6296
6297#ifndef OS_SETREUID_METHODDEF
6298 #define OS_SETREUID_METHODDEF
6299#endif /* !defined(OS_SETREUID_METHODDEF) */
6300
6301#ifndef OS_SETREGID_METHODDEF
6302 #define OS_SETREGID_METHODDEF
6303#endif /* !defined(OS_SETREGID_METHODDEF) */
6304
6305#ifndef OS_SETGID_METHODDEF
6306 #define OS_SETGID_METHODDEF
6307#endif /* !defined(OS_SETGID_METHODDEF) */
6308
6309#ifndef OS_SETGROUPS_METHODDEF
6310 #define OS_SETGROUPS_METHODDEF
6311#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6312
6313#ifndef OS_WAIT3_METHODDEF
6314 #define OS_WAIT3_METHODDEF
6315#endif /* !defined(OS_WAIT3_METHODDEF) */
6316
6317#ifndef OS_WAIT4_METHODDEF
6318 #define OS_WAIT4_METHODDEF
6319#endif /* !defined(OS_WAIT4_METHODDEF) */
6320
6321#ifndef OS_WAITID_METHODDEF
6322 #define OS_WAITID_METHODDEF
6323#endif /* !defined(OS_WAITID_METHODDEF) */
6324
6325#ifndef OS_WAITPID_METHODDEF
6326 #define OS_WAITPID_METHODDEF
6327#endif /* !defined(OS_WAITPID_METHODDEF) */
6328
6329#ifndef OS_WAIT_METHODDEF
6330 #define OS_WAIT_METHODDEF
6331#endif /* !defined(OS_WAIT_METHODDEF) */
6332
6333#ifndef OS_SYMLINK_METHODDEF
6334 #define OS_SYMLINK_METHODDEF
6335#endif /* !defined(OS_SYMLINK_METHODDEF) */
6336
6337#ifndef OS_TIMES_METHODDEF
6338 #define OS_TIMES_METHODDEF
6339#endif /* !defined(OS_TIMES_METHODDEF) */
6340
6341#ifndef OS_GETSID_METHODDEF
6342 #define OS_GETSID_METHODDEF
6343#endif /* !defined(OS_GETSID_METHODDEF) */
6344
6345#ifndef OS_SETSID_METHODDEF
6346 #define OS_SETSID_METHODDEF
6347#endif /* !defined(OS_SETSID_METHODDEF) */
6348
6349#ifndef OS_SETPGID_METHODDEF
6350 #define OS_SETPGID_METHODDEF
6351#endif /* !defined(OS_SETPGID_METHODDEF) */
6352
6353#ifndef OS_TCGETPGRP_METHODDEF
6354 #define OS_TCGETPGRP_METHODDEF
6355#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6356
6357#ifndef OS_TCSETPGRP_METHODDEF
6358 #define OS_TCSETPGRP_METHODDEF
6359#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6360
6361#ifndef OS_LOCKF_METHODDEF
6362 #define OS_LOCKF_METHODDEF
6363#endif /* !defined(OS_LOCKF_METHODDEF) */
6364
6365#ifndef OS_READV_METHODDEF
6366 #define OS_READV_METHODDEF
6367#endif /* !defined(OS_READV_METHODDEF) */
6368
6369#ifndef OS_PREAD_METHODDEF
6370 #define OS_PREAD_METHODDEF
6371#endif /* !defined(OS_PREAD_METHODDEF) */
6372
6373#ifndef OS_PIPE_METHODDEF
6374 #define OS_PIPE_METHODDEF
6375#endif /* !defined(OS_PIPE_METHODDEF) */
6376
6377#ifndef OS_PIPE2_METHODDEF
6378 #define OS_PIPE2_METHODDEF
6379#endif /* !defined(OS_PIPE2_METHODDEF) */
6380
6381#ifndef OS_WRITEV_METHODDEF
6382 #define OS_WRITEV_METHODDEF
6383#endif /* !defined(OS_WRITEV_METHODDEF) */
6384
6385#ifndef OS_PWRITE_METHODDEF
6386 #define OS_PWRITE_METHODDEF
6387#endif /* !defined(OS_PWRITE_METHODDEF) */
6388
6389#ifndef OS_MKFIFO_METHODDEF
6390 #define OS_MKFIFO_METHODDEF
6391#endif /* !defined(OS_MKFIFO_METHODDEF) */
6392
6393#ifndef OS_MKNOD_METHODDEF
6394 #define OS_MKNOD_METHODDEF
6395#endif /* !defined(OS_MKNOD_METHODDEF) */
6396
6397#ifndef OS_MAJOR_METHODDEF
6398 #define OS_MAJOR_METHODDEF
6399#endif /* !defined(OS_MAJOR_METHODDEF) */
6400
6401#ifndef OS_MINOR_METHODDEF
6402 #define OS_MINOR_METHODDEF
6403#endif /* !defined(OS_MINOR_METHODDEF) */
6404
6405#ifndef OS_MAKEDEV_METHODDEF
6406 #define OS_MAKEDEV_METHODDEF
6407#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6408
6409#ifndef OS_FTRUNCATE_METHODDEF
6410 #define OS_FTRUNCATE_METHODDEF
6411#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6412
6413#ifndef OS_TRUNCATE_METHODDEF
6414 #define OS_TRUNCATE_METHODDEF
6415#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6416
6417#ifndef OS_POSIX_FALLOCATE_METHODDEF
6418 #define OS_POSIX_FALLOCATE_METHODDEF
6419#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6420
6421#ifndef OS_POSIX_FADVISE_METHODDEF
6422 #define OS_POSIX_FADVISE_METHODDEF
6423#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6424
6425#ifndef OS_PUTENV_METHODDEF
6426 #define OS_PUTENV_METHODDEF
6427#endif /* !defined(OS_PUTENV_METHODDEF) */
6428
6429#ifndef OS_UNSETENV_METHODDEF
6430 #define OS_UNSETENV_METHODDEF
6431#endif /* !defined(OS_UNSETENV_METHODDEF) */
6432
6433#ifndef OS_WCOREDUMP_METHODDEF
6434 #define OS_WCOREDUMP_METHODDEF
6435#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6436
6437#ifndef OS_WIFCONTINUED_METHODDEF
6438 #define OS_WIFCONTINUED_METHODDEF
6439#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6440
6441#ifndef OS_WIFSTOPPED_METHODDEF
6442 #define OS_WIFSTOPPED_METHODDEF
6443#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6444
6445#ifndef OS_WIFSIGNALED_METHODDEF
6446 #define OS_WIFSIGNALED_METHODDEF
6447#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6448
6449#ifndef OS_WIFEXITED_METHODDEF
6450 #define OS_WIFEXITED_METHODDEF
6451#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6452
6453#ifndef OS_WEXITSTATUS_METHODDEF
6454 #define OS_WEXITSTATUS_METHODDEF
6455#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6456
6457#ifndef OS_WTERMSIG_METHODDEF
6458 #define OS_WTERMSIG_METHODDEF
6459#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6460
6461#ifndef OS_WSTOPSIG_METHODDEF
6462 #define OS_WSTOPSIG_METHODDEF
6463#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6464
6465#ifndef OS_FSTATVFS_METHODDEF
6466 #define OS_FSTATVFS_METHODDEF
6467#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6468
6469#ifndef OS_STATVFS_METHODDEF
6470 #define OS_STATVFS_METHODDEF
6471#endif /* !defined(OS_STATVFS_METHODDEF) */
6472
6473#ifndef OS__GETDISKUSAGE_METHODDEF
6474 #define OS__GETDISKUSAGE_METHODDEF
6475#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6476
6477#ifndef OS_FPATHCONF_METHODDEF
6478 #define OS_FPATHCONF_METHODDEF
6479#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6480
6481#ifndef OS_PATHCONF_METHODDEF
6482 #define OS_PATHCONF_METHODDEF
6483#endif /* !defined(OS_PATHCONF_METHODDEF) */
6484
6485#ifndef OS_CONFSTR_METHODDEF
6486 #define OS_CONFSTR_METHODDEF
6487#endif /* !defined(OS_CONFSTR_METHODDEF) */
6488
6489#ifndef OS_SYSCONF_METHODDEF
6490 #define OS_SYSCONF_METHODDEF
6491#endif /* !defined(OS_SYSCONF_METHODDEF) */
6492
Steve Dowercc16be82016-09-08 10:35:16 -07006493#ifndef OS_STARTFILE_METHODDEF
6494 #define OS_STARTFILE_METHODDEF
6495#endif /* !defined(OS_STARTFILE_METHODDEF) */
6496
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006497#ifndef OS_GETLOADAVG_METHODDEF
6498 #define OS_GETLOADAVG_METHODDEF
6499#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6500
6501#ifndef OS_SETRESUID_METHODDEF
6502 #define OS_SETRESUID_METHODDEF
6503#endif /* !defined(OS_SETRESUID_METHODDEF) */
6504
6505#ifndef OS_SETRESGID_METHODDEF
6506 #define OS_SETRESGID_METHODDEF
6507#endif /* !defined(OS_SETRESGID_METHODDEF) */
6508
6509#ifndef OS_GETRESUID_METHODDEF
6510 #define OS_GETRESUID_METHODDEF
6511#endif /* !defined(OS_GETRESUID_METHODDEF) */
6512
6513#ifndef OS_GETRESGID_METHODDEF
6514 #define OS_GETRESGID_METHODDEF
6515#endif /* !defined(OS_GETRESGID_METHODDEF) */
6516
6517#ifndef OS_GETXATTR_METHODDEF
6518 #define OS_GETXATTR_METHODDEF
6519#endif /* !defined(OS_GETXATTR_METHODDEF) */
6520
6521#ifndef OS_SETXATTR_METHODDEF
6522 #define OS_SETXATTR_METHODDEF
6523#endif /* !defined(OS_SETXATTR_METHODDEF) */
6524
6525#ifndef OS_REMOVEXATTR_METHODDEF
6526 #define OS_REMOVEXATTR_METHODDEF
6527#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6528
6529#ifndef OS_LISTXATTR_METHODDEF
6530 #define OS_LISTXATTR_METHODDEF
6531#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6532
6533#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6534 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6535#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6536
6537#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6538 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6539#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006540
6541#ifndef OS_GETRANDOM_METHODDEF
6542 #define OS_GETRANDOM_METHODDEF
6543#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006544/*[clinic end generated code: output=699e11c5579a104e input=a9049054013a1b77]*/