blob: 6ef0293efd78ea57b8e9a459e424ebd067c972cc [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
1828#if defined(HAVE_FORK1)
1829
1830PyDoc_STRVAR(os_fork1__doc__,
1831"fork1($module, /)\n"
1832"--\n"
1833"\n"
1834"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1835"\n"
1836"Return 0 to child process and PID of child to parent process.");
1837
1838#define OS_FORK1_METHODDEF \
1839 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1840
1841static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001842os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001843
1844static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001845os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001846{
1847 return os_fork1_impl(module);
1848}
1849
1850#endif /* defined(HAVE_FORK1) */
1851
1852#if defined(HAVE_FORK)
1853
1854PyDoc_STRVAR(os_fork__doc__,
1855"fork($module, /)\n"
1856"--\n"
1857"\n"
1858"Fork a child process.\n"
1859"\n"
1860"Return 0 to child process and PID of child to parent process.");
1861
1862#define OS_FORK_METHODDEF \
1863 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1864
1865static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001866os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001867
1868static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001869os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001870{
1871 return os_fork_impl(module);
1872}
1873
1874#endif /* defined(HAVE_FORK) */
1875
1876#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1877
1878PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1879"sched_get_priority_max($module, /, policy)\n"
1880"--\n"
1881"\n"
1882"Get the maximum scheduling priority for policy.");
1883
1884#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001885 {"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 +03001886
1887static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001888os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001889
1890static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001891os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001892{
1893 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001894 static const char * const _keywords[] = {"policy", NULL};
1895 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001896 int policy;
1897
Victor Stinner3e1fad62017-01-17 01:29:01 +01001898 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001899 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001900 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001901 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001902 return_value = os_sched_get_priority_max_impl(module, policy);
1903
1904exit:
1905 return return_value;
1906}
1907
1908#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1909
1910#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1911
1912PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1913"sched_get_priority_min($module, /, policy)\n"
1914"--\n"
1915"\n"
1916"Get the minimum scheduling priority for policy.");
1917
1918#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001919 {"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 +03001920
1921static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001922os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001923
1924static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001925os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001926{
1927 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001928 static const char * const _keywords[] = {"policy", NULL};
1929 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001930 int policy;
1931
Victor Stinner3e1fad62017-01-17 01:29:01 +01001932 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001933 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001934 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001935 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001936 return_value = os_sched_get_priority_min_impl(module, policy);
1937
1938exit:
1939 return return_value;
1940}
1941
1942#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1943
1944#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1945
1946PyDoc_STRVAR(os_sched_getscheduler__doc__,
1947"sched_getscheduler($module, pid, /)\n"
1948"--\n"
1949"\n"
1950"Get the scheduling policy for the process identifiedy by pid.\n"
1951"\n"
1952"Passing 0 for pid returns the scheduling policy for the calling process.");
1953
1954#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001955 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001956
1957static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001958os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001959
1960static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001961os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001962{
1963 PyObject *return_value = NULL;
1964 pid_t pid;
1965
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001966 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001967 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001968 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001969 return_value = os_sched_getscheduler_impl(module, pid);
1970
1971exit:
1972 return return_value;
1973}
1974
1975#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
1976
1977#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
1978
1979PyDoc_STRVAR(os_sched_param__doc__,
1980"sched_param(sched_priority)\n"
1981"--\n"
1982"\n"
1983"Current has only one field: sched_priority\");\n"
1984"\n"
1985" sched_priority\n"
1986" A scheduling parameter.");
1987
1988static PyObject *
1989os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
1990
1991static PyObject *
1992os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1993{
1994 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001995 static const char * const _keywords[] = {"sched_priority", NULL};
1996 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001997 PyObject *sched_priority;
1998
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001999 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002000 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002001 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002002 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003 return_value = os_sched_param_impl(type, sched_priority);
2004
2005exit:
2006 return return_value;
2007}
2008
2009#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2010
2011#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2012
2013PyDoc_STRVAR(os_sched_setscheduler__doc__,
2014"sched_setscheduler($module, pid, policy, param, /)\n"
2015"--\n"
2016"\n"
2017"Set the scheduling policy for the process identified by pid.\n"
2018"\n"
2019"If pid is 0, the calling process is changed.\n"
2020"param is an instance of sched_param.");
2021
2022#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002023 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002024
2025static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002026os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002027 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002028
2029static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002030os_sched_setscheduler(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002031{
2032 PyObject *return_value = NULL;
2033 pid_t pid;
2034 int policy;
2035 struct sched_param param;
2036
Victor Stinner259f0e42017-01-17 01:35:17 +01002037 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002038 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002039 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002040 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002041
2042 if (!_PyArg_NoStackKeywords("sched_setscheduler", kwnames)) {
2043 goto exit;
2044 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002045 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2046
2047exit:
2048 return return_value;
2049}
2050
2051#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2052
2053#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2054
2055PyDoc_STRVAR(os_sched_getparam__doc__,
2056"sched_getparam($module, pid, /)\n"
2057"--\n"
2058"\n"
2059"Returns scheduling parameters for the process identified by pid.\n"
2060"\n"
2061"If pid is 0, returns parameters for the calling process.\n"
2062"Return value is an instance of sched_param.");
2063
2064#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002065 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002066
2067static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002068os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002069
2070static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002071os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002072{
2073 PyObject *return_value = NULL;
2074 pid_t pid;
2075
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002076 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002077 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002078 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002079 return_value = os_sched_getparam_impl(module, pid);
2080
2081exit:
2082 return return_value;
2083}
2084
2085#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2086
2087#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2088
2089PyDoc_STRVAR(os_sched_setparam__doc__,
2090"sched_setparam($module, pid, param, /)\n"
2091"--\n"
2092"\n"
2093"Set scheduling parameters for the process identified by pid.\n"
2094"\n"
2095"If pid is 0, sets parameters for the calling process.\n"
2096"param should be an instance of sched_param.");
2097
2098#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002099 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002100
2101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002102os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002103 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002104
2105static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002106os_sched_setparam(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002107{
2108 PyObject *return_value = NULL;
2109 pid_t pid;
2110 struct sched_param param;
2111
Victor Stinner259f0e42017-01-17 01:35:17 +01002112 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002113 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002114 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002115 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002116
2117 if (!_PyArg_NoStackKeywords("sched_setparam", kwnames)) {
2118 goto exit;
2119 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002120 return_value = os_sched_setparam_impl(module, pid, &param);
2121
2122exit:
2123 return return_value;
2124}
2125
2126#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2127
2128#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2129
2130PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2131"sched_rr_get_interval($module, pid, /)\n"
2132"--\n"
2133"\n"
2134"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2135"\n"
2136"Value returned is a float.");
2137
2138#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002139 {"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 +03002140
2141static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002142os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002143
2144static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002145os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002146{
2147 PyObject *return_value = NULL;
2148 pid_t pid;
2149 double _return_value;
2150
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002151 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002152 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002154 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002155 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002156 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002157 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158 return_value = PyFloat_FromDouble(_return_value);
2159
2160exit:
2161 return return_value;
2162}
2163
2164#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2165
2166#if defined(HAVE_SCHED_H)
2167
2168PyDoc_STRVAR(os_sched_yield__doc__,
2169"sched_yield($module, /)\n"
2170"--\n"
2171"\n"
2172"Voluntarily relinquish the CPU.");
2173
2174#define OS_SCHED_YIELD_METHODDEF \
2175 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2176
2177static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002178os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002179
2180static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002181os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002182{
2183 return os_sched_yield_impl(module);
2184}
2185
2186#endif /* defined(HAVE_SCHED_H) */
2187
2188#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2189
2190PyDoc_STRVAR(os_sched_setaffinity__doc__,
2191"sched_setaffinity($module, pid, mask, /)\n"
2192"--\n"
2193"\n"
2194"Set the CPU affinity of the process identified by pid to mask.\n"
2195"\n"
2196"mask should be an iterable of integers identifying CPUs.");
2197
2198#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002199 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002200
2201static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002202os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002203
2204static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002205os_sched_setaffinity(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002206{
2207 PyObject *return_value = NULL;
2208 pid_t pid;
2209 PyObject *mask;
2210
Victor Stinner259f0e42017-01-17 01:35:17 +01002211 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002212 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002213 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002214 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002215
2216 if (!_PyArg_NoStackKeywords("sched_setaffinity", kwnames)) {
2217 goto exit;
2218 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002219 return_value = os_sched_setaffinity_impl(module, pid, mask);
2220
2221exit:
2222 return return_value;
2223}
2224
2225#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2226
2227#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2228
2229PyDoc_STRVAR(os_sched_getaffinity__doc__,
2230"sched_getaffinity($module, pid, /)\n"
2231"--\n"
2232"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002233"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234"\n"
2235"The affinity is returned as a set of CPU identifiers.");
2236
2237#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002238 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002239
2240static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002241os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002242
2243static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002244os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002245{
2246 PyObject *return_value = NULL;
2247 pid_t pid;
2248
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002249 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002250 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002251 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002252 return_value = os_sched_getaffinity_impl(module, pid);
2253
2254exit:
2255 return return_value;
2256}
2257
2258#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2259
2260#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2261
2262PyDoc_STRVAR(os_openpty__doc__,
2263"openpty($module, /)\n"
2264"--\n"
2265"\n"
2266"Open a pseudo-terminal.\n"
2267"\n"
2268"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2269"for both the master and slave ends.");
2270
2271#define OS_OPENPTY_METHODDEF \
2272 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2273
2274static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002275os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002276
2277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002278os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002279{
2280 return os_openpty_impl(module);
2281}
2282
2283#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2284
2285#if defined(HAVE_FORKPTY)
2286
2287PyDoc_STRVAR(os_forkpty__doc__,
2288"forkpty($module, /)\n"
2289"--\n"
2290"\n"
2291"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2292"\n"
2293"Returns a tuple of (pid, master_fd).\n"
2294"Like fork(), return pid of 0 to the child process,\n"
2295"and pid of child to the parent process.\n"
2296"To both, return fd of newly opened pseudo-terminal.");
2297
2298#define OS_FORKPTY_METHODDEF \
2299 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2300
2301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002302os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002303
2304static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002305os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002306{
2307 return os_forkpty_impl(module);
2308}
2309
2310#endif /* defined(HAVE_FORKPTY) */
2311
2312#if defined(HAVE_GETEGID)
2313
2314PyDoc_STRVAR(os_getegid__doc__,
2315"getegid($module, /)\n"
2316"--\n"
2317"\n"
2318"Return the current process\'s effective group id.");
2319
2320#define OS_GETEGID_METHODDEF \
2321 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2322
2323static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002324os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002325
2326static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002327os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002328{
2329 return os_getegid_impl(module);
2330}
2331
2332#endif /* defined(HAVE_GETEGID) */
2333
2334#if defined(HAVE_GETEUID)
2335
2336PyDoc_STRVAR(os_geteuid__doc__,
2337"geteuid($module, /)\n"
2338"--\n"
2339"\n"
2340"Return the current process\'s effective user id.");
2341
2342#define OS_GETEUID_METHODDEF \
2343 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2344
2345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002346os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002347
2348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002349os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002350{
2351 return os_geteuid_impl(module);
2352}
2353
2354#endif /* defined(HAVE_GETEUID) */
2355
2356#if defined(HAVE_GETGID)
2357
2358PyDoc_STRVAR(os_getgid__doc__,
2359"getgid($module, /)\n"
2360"--\n"
2361"\n"
2362"Return the current process\'s group id.");
2363
2364#define OS_GETGID_METHODDEF \
2365 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2366
2367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002368os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002369
2370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002371os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002372{
2373 return os_getgid_impl(module);
2374}
2375
2376#endif /* defined(HAVE_GETGID) */
2377
Berker Peksag39404992016-09-15 20:45:16 +03002378#if defined(HAVE_GETPID)
2379
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002380PyDoc_STRVAR(os_getpid__doc__,
2381"getpid($module, /)\n"
2382"--\n"
2383"\n"
2384"Return the current process id.");
2385
2386#define OS_GETPID_METHODDEF \
2387 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2388
2389static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002390os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002391
2392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002393os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002394{
2395 return os_getpid_impl(module);
2396}
2397
Berker Peksag39404992016-09-15 20:45:16 +03002398#endif /* defined(HAVE_GETPID) */
2399
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002400#if defined(HAVE_GETGROUPS)
2401
2402PyDoc_STRVAR(os_getgroups__doc__,
2403"getgroups($module, /)\n"
2404"--\n"
2405"\n"
2406"Return list of supplemental group IDs for the process.");
2407
2408#define OS_GETGROUPS_METHODDEF \
2409 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2410
2411static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002412os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002413
2414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002415os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002416{
2417 return os_getgroups_impl(module);
2418}
2419
2420#endif /* defined(HAVE_GETGROUPS) */
2421
2422#if defined(HAVE_GETPGID)
2423
2424PyDoc_STRVAR(os_getpgid__doc__,
2425"getpgid($module, /, pid)\n"
2426"--\n"
2427"\n"
2428"Call the system call getpgid(), and return the result.");
2429
2430#define OS_GETPGID_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002431 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002432
2433static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002434os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002435
2436static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002437os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002438{
2439 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002440 static const char * const _keywords[] = {"pid", NULL};
2441 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002442 pid_t pid;
2443
Victor Stinner3e1fad62017-01-17 01:29:01 +01002444 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002445 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002446 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002447 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002448 return_value = os_getpgid_impl(module, pid);
2449
2450exit:
2451 return return_value;
2452}
2453
2454#endif /* defined(HAVE_GETPGID) */
2455
2456#if defined(HAVE_GETPGRP)
2457
2458PyDoc_STRVAR(os_getpgrp__doc__,
2459"getpgrp($module, /)\n"
2460"--\n"
2461"\n"
2462"Return the current process group id.");
2463
2464#define OS_GETPGRP_METHODDEF \
2465 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2466
2467static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002468os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002469
2470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002471os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472{
2473 return os_getpgrp_impl(module);
2474}
2475
2476#endif /* defined(HAVE_GETPGRP) */
2477
2478#if defined(HAVE_SETPGRP)
2479
2480PyDoc_STRVAR(os_setpgrp__doc__,
2481"setpgrp($module, /)\n"
2482"--\n"
2483"\n"
2484"Make the current process the leader of its process group.");
2485
2486#define OS_SETPGRP_METHODDEF \
2487 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2488
2489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002490os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491
2492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002493os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002494{
2495 return os_setpgrp_impl(module);
2496}
2497
2498#endif /* defined(HAVE_SETPGRP) */
2499
2500#if defined(HAVE_GETPPID)
2501
2502PyDoc_STRVAR(os_getppid__doc__,
2503"getppid($module, /)\n"
2504"--\n"
2505"\n"
2506"Return the parent\'s process id.\n"
2507"\n"
2508"If the parent process has already exited, Windows machines will still\n"
2509"return its id; others systems will return the id of the \'init\' process (1).");
2510
2511#define OS_GETPPID_METHODDEF \
2512 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2513
2514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002515os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002516
2517static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002518os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002519{
2520 return os_getppid_impl(module);
2521}
2522
2523#endif /* defined(HAVE_GETPPID) */
2524
2525#if defined(HAVE_GETLOGIN)
2526
2527PyDoc_STRVAR(os_getlogin__doc__,
2528"getlogin($module, /)\n"
2529"--\n"
2530"\n"
2531"Return the actual login name.");
2532
2533#define OS_GETLOGIN_METHODDEF \
2534 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2535
2536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002537os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002538
2539static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002540os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002541{
2542 return os_getlogin_impl(module);
2543}
2544
2545#endif /* defined(HAVE_GETLOGIN) */
2546
2547#if defined(HAVE_GETUID)
2548
2549PyDoc_STRVAR(os_getuid__doc__,
2550"getuid($module, /)\n"
2551"--\n"
2552"\n"
2553"Return the current process\'s user id.");
2554
2555#define OS_GETUID_METHODDEF \
2556 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2557
2558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002559os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002560
2561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002562os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002563{
2564 return os_getuid_impl(module);
2565}
2566
2567#endif /* defined(HAVE_GETUID) */
2568
2569#if defined(HAVE_KILL)
2570
2571PyDoc_STRVAR(os_kill__doc__,
2572"kill($module, pid, signal, /)\n"
2573"--\n"
2574"\n"
2575"Kill a process with a signal.");
2576
2577#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002578 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002579
2580static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002581os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002582
2583static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002584os_kill(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002585{
2586 PyObject *return_value = NULL;
2587 pid_t pid;
2588 Py_ssize_t signal;
2589
Victor Stinner259f0e42017-01-17 01:35:17 +01002590 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002591 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002592 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002593 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002594
2595 if (!_PyArg_NoStackKeywords("kill", kwnames)) {
2596 goto exit;
2597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002598 return_value = os_kill_impl(module, pid, signal);
2599
2600exit:
2601 return return_value;
2602}
2603
2604#endif /* defined(HAVE_KILL) */
2605
2606#if defined(HAVE_KILLPG)
2607
2608PyDoc_STRVAR(os_killpg__doc__,
2609"killpg($module, pgid, signal, /)\n"
2610"--\n"
2611"\n"
2612"Kill a process group with a signal.");
2613
2614#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002615 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002616
2617static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002618os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002619
2620static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002621os_killpg(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002622{
2623 PyObject *return_value = NULL;
2624 pid_t pgid;
2625 int signal;
2626
Victor Stinner259f0e42017-01-17 01:35:17 +01002627 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002628 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002629 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002630 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002631
2632 if (!_PyArg_NoStackKeywords("killpg", kwnames)) {
2633 goto exit;
2634 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002635 return_value = os_killpg_impl(module, pgid, signal);
2636
2637exit:
2638 return return_value;
2639}
2640
2641#endif /* defined(HAVE_KILLPG) */
2642
2643#if defined(HAVE_PLOCK)
2644
2645PyDoc_STRVAR(os_plock__doc__,
2646"plock($module, op, /)\n"
2647"--\n"
2648"\n"
2649"Lock program segments into memory.\");");
2650
2651#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002652 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002653
2654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002655os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002656
2657static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002658os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002659{
2660 PyObject *return_value = NULL;
2661 int op;
2662
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002663 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002664 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002665 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002666 return_value = os_plock_impl(module, op);
2667
2668exit:
2669 return return_value;
2670}
2671
2672#endif /* defined(HAVE_PLOCK) */
2673
2674#if defined(HAVE_SETUID)
2675
2676PyDoc_STRVAR(os_setuid__doc__,
2677"setuid($module, uid, /)\n"
2678"--\n"
2679"\n"
2680"Set the current process\'s user id.");
2681
2682#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002683 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002684
2685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002686os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002687
2688static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002689os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002690{
2691 PyObject *return_value = NULL;
2692 uid_t uid;
2693
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002694 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002695 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002696 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002697 return_value = os_setuid_impl(module, uid);
2698
2699exit:
2700 return return_value;
2701}
2702
2703#endif /* defined(HAVE_SETUID) */
2704
2705#if defined(HAVE_SETEUID)
2706
2707PyDoc_STRVAR(os_seteuid__doc__,
2708"seteuid($module, euid, /)\n"
2709"--\n"
2710"\n"
2711"Set the current process\'s effective user id.");
2712
2713#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002714 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002715
2716static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002717os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002718
2719static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002720os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002721{
2722 PyObject *return_value = NULL;
2723 uid_t euid;
2724
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002725 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002726 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002727 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002728 return_value = os_seteuid_impl(module, euid);
2729
2730exit:
2731 return return_value;
2732}
2733
2734#endif /* defined(HAVE_SETEUID) */
2735
2736#if defined(HAVE_SETEGID)
2737
2738PyDoc_STRVAR(os_setegid__doc__,
2739"setegid($module, egid, /)\n"
2740"--\n"
2741"\n"
2742"Set the current process\'s effective group id.");
2743
2744#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002745 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002746
2747static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002748os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002749
2750static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002751os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002752{
2753 PyObject *return_value = NULL;
2754 gid_t egid;
2755
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002756 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002757 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002758 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002759 return_value = os_setegid_impl(module, egid);
2760
2761exit:
2762 return return_value;
2763}
2764
2765#endif /* defined(HAVE_SETEGID) */
2766
2767#if defined(HAVE_SETREUID)
2768
2769PyDoc_STRVAR(os_setreuid__doc__,
2770"setreuid($module, ruid, euid, /)\n"
2771"--\n"
2772"\n"
2773"Set the current process\'s real and effective user ids.");
2774
2775#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002776 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002777
2778static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002779os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002780
2781static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002782os_setreuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002783{
2784 PyObject *return_value = NULL;
2785 uid_t ruid;
2786 uid_t euid;
2787
Victor Stinner259f0e42017-01-17 01:35:17 +01002788 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002789 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002790 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002791 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002792
2793 if (!_PyArg_NoStackKeywords("setreuid", kwnames)) {
2794 goto exit;
2795 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002796 return_value = os_setreuid_impl(module, ruid, euid);
2797
2798exit:
2799 return return_value;
2800}
2801
2802#endif /* defined(HAVE_SETREUID) */
2803
2804#if defined(HAVE_SETREGID)
2805
2806PyDoc_STRVAR(os_setregid__doc__,
2807"setregid($module, rgid, egid, /)\n"
2808"--\n"
2809"\n"
2810"Set the current process\'s real and effective group ids.");
2811
2812#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002813 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002814
2815static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002816os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002817
2818static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002819os_setregid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002820{
2821 PyObject *return_value = NULL;
2822 gid_t rgid;
2823 gid_t egid;
2824
Victor Stinner259f0e42017-01-17 01:35:17 +01002825 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002826 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002827 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002828 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002829
2830 if (!_PyArg_NoStackKeywords("setregid", kwnames)) {
2831 goto exit;
2832 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002833 return_value = os_setregid_impl(module, rgid, egid);
2834
2835exit:
2836 return return_value;
2837}
2838
2839#endif /* defined(HAVE_SETREGID) */
2840
2841#if defined(HAVE_SETGID)
2842
2843PyDoc_STRVAR(os_setgid__doc__,
2844"setgid($module, gid, /)\n"
2845"--\n"
2846"\n"
2847"Set the current process\'s group id.");
2848
2849#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002850 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002851
2852static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002853os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002854
2855static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002856os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002857{
2858 PyObject *return_value = NULL;
2859 gid_t gid;
2860
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002861 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002863 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002864 return_value = os_setgid_impl(module, gid);
2865
2866exit:
2867 return return_value;
2868}
2869
2870#endif /* defined(HAVE_SETGID) */
2871
2872#if defined(HAVE_SETGROUPS)
2873
2874PyDoc_STRVAR(os_setgroups__doc__,
2875"setgroups($module, groups, /)\n"
2876"--\n"
2877"\n"
2878"Set the groups of the current process to list.");
2879
2880#define OS_SETGROUPS_METHODDEF \
2881 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2882
2883#endif /* defined(HAVE_SETGROUPS) */
2884
2885#if defined(HAVE_WAIT3)
2886
2887PyDoc_STRVAR(os_wait3__doc__,
2888"wait3($module, /, options)\n"
2889"--\n"
2890"\n"
2891"Wait for completion of a child process.\n"
2892"\n"
2893"Returns a tuple of information about the child process:\n"
2894" (pid, status, rusage)");
2895
2896#define OS_WAIT3_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002897 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002898
2899static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002900os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002901
2902static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002903os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002904{
2905 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002906 static const char * const _keywords[] = {"options", NULL};
2907 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002908 int options;
2909
Victor Stinner3e1fad62017-01-17 01:29:01 +01002910 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002911 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002913 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002914 return_value = os_wait3_impl(module, options);
2915
2916exit:
2917 return return_value;
2918}
2919
2920#endif /* defined(HAVE_WAIT3) */
2921
2922#if defined(HAVE_WAIT4)
2923
2924PyDoc_STRVAR(os_wait4__doc__,
2925"wait4($module, /, pid, options)\n"
2926"--\n"
2927"\n"
2928"Wait for completion of a specific child process.\n"
2929"\n"
2930"Returns a tuple of information about the child process:\n"
2931" (pid, status, rusage)");
2932
2933#define OS_WAIT4_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002934 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002935
2936static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002937os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002938
2939static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002940os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002941{
2942 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002943 static const char * const _keywords[] = {"pid", "options", NULL};
2944 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002945 pid_t pid;
2946 int options;
2947
Victor Stinner3e1fad62017-01-17 01:29:01 +01002948 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002949 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002951 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002952 return_value = os_wait4_impl(module, pid, options);
2953
2954exit:
2955 return return_value;
2956}
2957
2958#endif /* defined(HAVE_WAIT4) */
2959
2960#if (defined(HAVE_WAITID) && !defined(__APPLE__))
2961
2962PyDoc_STRVAR(os_waitid__doc__,
2963"waitid($module, idtype, id, options, /)\n"
2964"--\n"
2965"\n"
2966"Returns the result of waiting for a process or processes.\n"
2967"\n"
2968" idtype\n"
2969" Must be one of be P_PID, P_PGID or P_ALL.\n"
2970" id\n"
2971" The id to wait on.\n"
2972" options\n"
2973" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
2974" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
2975"\n"
2976"Returns either waitid_result or None if WNOHANG is specified and there are\n"
2977"no children in a waitable state.");
2978
2979#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002980 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002981
2982static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002983os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002984
2985static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002986os_waitid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002987{
2988 PyObject *return_value = NULL;
2989 idtype_t idtype;
2990 id_t id;
2991 int options;
2992
Victor Stinner259f0e42017-01-17 01:35:17 +01002993 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002994 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002996 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002997
2998 if (!_PyArg_NoStackKeywords("waitid", kwnames)) {
2999 goto exit;
3000 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003001 return_value = os_waitid_impl(module, idtype, id, options);
3002
3003exit:
3004 return return_value;
3005}
3006
3007#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3008
3009#if defined(HAVE_WAITPID)
3010
3011PyDoc_STRVAR(os_waitpid__doc__,
3012"waitpid($module, pid, options, /)\n"
3013"--\n"
3014"\n"
3015"Wait for completion of a given child process.\n"
3016"\n"
3017"Returns a tuple of information regarding the child process:\n"
3018" (pid, status)\n"
3019"\n"
3020"The options argument is ignored on Windows.");
3021
3022#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003023 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003024
3025static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003026os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003027
3028static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003029os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003030{
3031 PyObject *return_value = NULL;
3032 pid_t pid;
3033 int options;
3034
Victor Stinner259f0e42017-01-17 01:35:17 +01003035 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003036 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003037 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003038 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003039
3040 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3041 goto exit;
3042 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003043 return_value = os_waitpid_impl(module, pid, options);
3044
3045exit:
3046 return return_value;
3047}
3048
3049#endif /* defined(HAVE_WAITPID) */
3050
3051#if defined(HAVE_CWAIT)
3052
3053PyDoc_STRVAR(os_waitpid__doc__,
3054"waitpid($module, pid, options, /)\n"
3055"--\n"
3056"\n"
3057"Wait for completion of a given process.\n"
3058"\n"
3059"Returns a tuple of information regarding the process:\n"
3060" (pid, status << 8)\n"
3061"\n"
3062"The options argument is ignored on Windows.");
3063
3064#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003065 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003066
3067static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003068os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003069
3070static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003071os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003072{
3073 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003074 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003075 int options;
3076
Victor Stinner259f0e42017-01-17 01:35:17 +01003077 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003078 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003079 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003080 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003081
3082 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3083 goto exit;
3084 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003085 return_value = os_waitpid_impl(module, pid, options);
3086
3087exit:
3088 return return_value;
3089}
3090
3091#endif /* defined(HAVE_CWAIT) */
3092
3093#if defined(HAVE_WAIT)
3094
3095PyDoc_STRVAR(os_wait__doc__,
3096"wait($module, /)\n"
3097"--\n"
3098"\n"
3099"Wait for completion of a child process.\n"
3100"\n"
3101"Returns a tuple of information about the child process:\n"
3102" (pid, status)");
3103
3104#define OS_WAIT_METHODDEF \
3105 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3106
3107static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003108os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003109
3110static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003111os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003112{
3113 return os_wait_impl(module);
3114}
3115
3116#endif /* defined(HAVE_WAIT) */
3117
3118#if defined(HAVE_SYMLINK)
3119
3120PyDoc_STRVAR(os_symlink__doc__,
3121"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3122"--\n"
3123"\n"
3124"Create a symbolic link pointing to src named dst.\n"
3125"\n"
3126"target_is_directory is required on Windows if the target is to be\n"
3127" interpreted as a directory. (On Windows, symlink requires\n"
3128" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3129" target_is_directory is ignored on non-Windows platforms.\n"
3130"\n"
3131"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3132" and path should be relative; path will then be relative to that directory.\n"
3133"dir_fd may not be implemented on your platform.\n"
3134" If it is unavailable, using it will raise a NotImplementedError.");
3135
3136#define OS_SYMLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003137 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003138
3139static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003140os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003141 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003142
3143static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003144os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003145{
3146 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003147 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3148 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003149 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3150 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3151 int target_is_directory = 0;
3152 int dir_fd = DEFAULT_DIR_FD;
3153
Victor Stinner3e1fad62017-01-17 01:29:01 +01003154 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003155 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003156 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003157 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003158 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3159
3160exit:
3161 /* Cleanup for src */
3162 path_cleanup(&src);
3163 /* Cleanup for dst */
3164 path_cleanup(&dst);
3165
3166 return return_value;
3167}
3168
3169#endif /* defined(HAVE_SYMLINK) */
3170
3171#if defined(HAVE_TIMES)
3172
3173PyDoc_STRVAR(os_times__doc__,
3174"times($module, /)\n"
3175"--\n"
3176"\n"
3177"Return a collection containing process timing information.\n"
3178"\n"
3179"The object returned behaves like a named tuple with these fields:\n"
3180" (utime, stime, cutime, cstime, elapsed_time)\n"
3181"All fields are floating point numbers.");
3182
3183#define OS_TIMES_METHODDEF \
3184 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3185
3186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003187os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003188
3189static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003190os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003191{
3192 return os_times_impl(module);
3193}
3194
3195#endif /* defined(HAVE_TIMES) */
3196
3197#if defined(HAVE_GETSID)
3198
3199PyDoc_STRVAR(os_getsid__doc__,
3200"getsid($module, pid, /)\n"
3201"--\n"
3202"\n"
3203"Call the system call getsid(pid) and return the result.");
3204
3205#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003206 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003207
3208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003209os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003210
3211static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003212os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003213{
3214 PyObject *return_value = NULL;
3215 pid_t pid;
3216
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003217 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003218 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003219 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003220 return_value = os_getsid_impl(module, pid);
3221
3222exit:
3223 return return_value;
3224}
3225
3226#endif /* defined(HAVE_GETSID) */
3227
3228#if defined(HAVE_SETSID)
3229
3230PyDoc_STRVAR(os_setsid__doc__,
3231"setsid($module, /)\n"
3232"--\n"
3233"\n"
3234"Call the system call setsid().");
3235
3236#define OS_SETSID_METHODDEF \
3237 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3238
3239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003240os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003241
3242static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003243os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003244{
3245 return os_setsid_impl(module);
3246}
3247
3248#endif /* defined(HAVE_SETSID) */
3249
3250#if defined(HAVE_SETPGID)
3251
3252PyDoc_STRVAR(os_setpgid__doc__,
3253"setpgid($module, pid, pgrp, /)\n"
3254"--\n"
3255"\n"
3256"Call the system call setpgid(pid, pgrp).");
3257
3258#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003259 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003260
3261static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003262os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003263
3264static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003265os_setpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003266{
3267 PyObject *return_value = NULL;
3268 pid_t pid;
3269 pid_t pgrp;
3270
Victor Stinner259f0e42017-01-17 01:35:17 +01003271 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003272 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003273 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003274 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003275
3276 if (!_PyArg_NoStackKeywords("setpgid", kwnames)) {
3277 goto exit;
3278 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003279 return_value = os_setpgid_impl(module, pid, pgrp);
3280
3281exit:
3282 return return_value;
3283}
3284
3285#endif /* defined(HAVE_SETPGID) */
3286
3287#if defined(HAVE_TCGETPGRP)
3288
3289PyDoc_STRVAR(os_tcgetpgrp__doc__,
3290"tcgetpgrp($module, fd, /)\n"
3291"--\n"
3292"\n"
3293"Return the process group associated with the terminal specified by fd.");
3294
3295#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003296 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003297
3298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003299os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003300
3301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003302os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003303{
3304 PyObject *return_value = NULL;
3305 int fd;
3306
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003307 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003308 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003309 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003310 return_value = os_tcgetpgrp_impl(module, fd);
3311
3312exit:
3313 return return_value;
3314}
3315
3316#endif /* defined(HAVE_TCGETPGRP) */
3317
3318#if defined(HAVE_TCSETPGRP)
3319
3320PyDoc_STRVAR(os_tcsetpgrp__doc__,
3321"tcsetpgrp($module, fd, pgid, /)\n"
3322"--\n"
3323"\n"
3324"Set the process group associated with the terminal specified by fd.");
3325
3326#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003327 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003328
3329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003330os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003331
3332static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003333os_tcsetpgrp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003334{
3335 PyObject *return_value = NULL;
3336 int fd;
3337 pid_t pgid;
3338
Victor Stinner259f0e42017-01-17 01:35:17 +01003339 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003340 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003341 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003342 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003343
3344 if (!_PyArg_NoStackKeywords("tcsetpgrp", kwnames)) {
3345 goto exit;
3346 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003347 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3348
3349exit:
3350 return return_value;
3351}
3352
3353#endif /* defined(HAVE_TCSETPGRP) */
3354
3355PyDoc_STRVAR(os_open__doc__,
3356"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3357"--\n"
3358"\n"
3359"Open a file for low level IO. Returns a file descriptor (integer).\n"
3360"\n"
3361"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3362" and path should be relative; path will then be relative to that directory.\n"
3363"dir_fd may not be implemented on your platform.\n"
3364" If it is unavailable, using it will raise a NotImplementedError.");
3365
3366#define OS_OPEN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003367 {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003368
3369static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003370os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003371
3372static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003373os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003374{
3375 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003376 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3377 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3379 int flags;
3380 int mode = 511;
3381 int dir_fd = DEFAULT_DIR_FD;
3382 int _return_value;
3383
Victor Stinner3e1fad62017-01-17 01:29:01 +01003384 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003385 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003386 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003387 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003388 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003389 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003390 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003391 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003392 return_value = PyLong_FromLong((long)_return_value);
3393
3394exit:
3395 /* Cleanup for path */
3396 path_cleanup(&path);
3397
3398 return return_value;
3399}
3400
3401PyDoc_STRVAR(os_close__doc__,
3402"close($module, /, fd)\n"
3403"--\n"
3404"\n"
3405"Close a file descriptor.");
3406
3407#define OS_CLOSE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003408 {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003409
3410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003411os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003412
3413static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003414os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003415{
3416 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003417 static const char * const _keywords[] = {"fd", NULL};
3418 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003419 int fd;
3420
Victor Stinner3e1fad62017-01-17 01:29:01 +01003421 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003422 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003423 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003424 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003425 return_value = os_close_impl(module, fd);
3426
3427exit:
3428 return return_value;
3429}
3430
3431PyDoc_STRVAR(os_closerange__doc__,
3432"closerange($module, fd_low, fd_high, /)\n"
3433"--\n"
3434"\n"
3435"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3436
3437#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003438 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003439
3440static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003441os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003442
3443static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003444os_closerange(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003445{
3446 PyObject *return_value = NULL;
3447 int fd_low;
3448 int fd_high;
3449
Victor Stinner259f0e42017-01-17 01:35:17 +01003450 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003451 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003452 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003453 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003454
3455 if (!_PyArg_NoStackKeywords("closerange", kwnames)) {
3456 goto exit;
3457 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003458 return_value = os_closerange_impl(module, fd_low, fd_high);
3459
3460exit:
3461 return return_value;
3462}
3463
3464PyDoc_STRVAR(os_dup__doc__,
3465"dup($module, fd, /)\n"
3466"--\n"
3467"\n"
3468"Return a duplicate of a file descriptor.");
3469
3470#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003471 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003472
3473static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003474os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003475
3476static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003477os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003478{
3479 PyObject *return_value = NULL;
3480 int fd;
3481 int _return_value;
3482
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003483 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003484 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003485 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003486 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003487 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003488 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003489 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003490 return_value = PyLong_FromLong((long)_return_value);
3491
3492exit:
3493 return return_value;
3494}
3495
3496PyDoc_STRVAR(os_dup2__doc__,
3497"dup2($module, /, fd, fd2, inheritable=True)\n"
3498"--\n"
3499"\n"
3500"Duplicate file descriptor.");
3501
3502#define OS_DUP2_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003503 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003504
3505static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003506os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003507
3508static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003509os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003510{
3511 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003512 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3513 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003514 int fd;
3515 int fd2;
3516 int inheritable = 1;
3517
Victor Stinner3e1fad62017-01-17 01:29:01 +01003518 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003519 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003520 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003521 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003522 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3523
3524exit:
3525 return return_value;
3526}
3527
3528#if defined(HAVE_LOCKF)
3529
3530PyDoc_STRVAR(os_lockf__doc__,
3531"lockf($module, fd, command, length, /)\n"
3532"--\n"
3533"\n"
3534"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3535"\n"
3536" fd\n"
3537" An open file descriptor.\n"
3538" command\n"
3539" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3540" length\n"
3541" The number of bytes to lock, starting at the current position.");
3542
3543#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003544 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003545
3546static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003547os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003548
3549static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003550os_lockf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003551{
3552 PyObject *return_value = NULL;
3553 int fd;
3554 int command;
3555 Py_off_t length;
3556
Victor Stinner259f0e42017-01-17 01:35:17 +01003557 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003558 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003559 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003560 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003561
3562 if (!_PyArg_NoStackKeywords("lockf", kwnames)) {
3563 goto exit;
3564 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003565 return_value = os_lockf_impl(module, fd, command, length);
3566
3567exit:
3568 return return_value;
3569}
3570
3571#endif /* defined(HAVE_LOCKF) */
3572
3573PyDoc_STRVAR(os_lseek__doc__,
3574"lseek($module, fd, position, how, /)\n"
3575"--\n"
3576"\n"
3577"Set the position of a file descriptor. Return the new position.\n"
3578"\n"
3579"Return the new cursor position in number of bytes\n"
3580"relative to the beginning of the file.");
3581
3582#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003583 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003584
3585static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003586os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003587
3588static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003589os_lseek(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003590{
3591 PyObject *return_value = NULL;
3592 int fd;
3593 Py_off_t position;
3594 int how;
3595 Py_off_t _return_value;
3596
Victor Stinner259f0e42017-01-17 01:35:17 +01003597 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003598 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003599 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003600 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003601
3602 if (!_PyArg_NoStackKeywords("lseek", kwnames)) {
3603 goto exit;
3604 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003605 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003606 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003607 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003608 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003609 return_value = PyLong_FromPy_off_t(_return_value);
3610
3611exit:
3612 return return_value;
3613}
3614
3615PyDoc_STRVAR(os_read__doc__,
3616"read($module, fd, length, /)\n"
3617"--\n"
3618"\n"
3619"Read from a file descriptor. Returns a bytes object.");
3620
3621#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003622 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003623
3624static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003625os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003626
3627static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003628os_read(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003629{
3630 PyObject *return_value = NULL;
3631 int fd;
3632 Py_ssize_t length;
3633
Victor Stinner259f0e42017-01-17 01:35:17 +01003634 if (!_PyArg_ParseStack(args, nargs, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003635 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003636 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003637 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003638
3639 if (!_PyArg_NoStackKeywords("read", kwnames)) {
3640 goto exit;
3641 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003642 return_value = os_read_impl(module, fd, length);
3643
3644exit:
3645 return return_value;
3646}
3647
3648#if defined(HAVE_READV)
3649
3650PyDoc_STRVAR(os_readv__doc__,
3651"readv($module, fd, buffers, /)\n"
3652"--\n"
3653"\n"
3654"Read from a file descriptor fd into an iterable of buffers.\n"
3655"\n"
3656"The buffers should be mutable buffers accepting bytes.\n"
3657"readv will transfer data into each buffer until it is full\n"
3658"and then move on to the next buffer in the sequence to hold\n"
3659"the rest of the data.\n"
3660"\n"
3661"readv returns the total number of bytes read,\n"
3662"which may be less than the total capacity of all the buffers.");
3663
3664#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003665 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003666
3667static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003668os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003669
3670static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003671os_readv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003672{
3673 PyObject *return_value = NULL;
3674 int fd;
3675 PyObject *buffers;
3676 Py_ssize_t _return_value;
3677
Victor Stinner259f0e42017-01-17 01:35:17 +01003678 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003679 &fd, &buffers)) {
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("readv", kwnames)) {
3684 goto exit;
3685 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003686 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003687 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003688 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003689 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003690 return_value = PyLong_FromSsize_t(_return_value);
3691
3692exit:
3693 return return_value;
3694}
3695
3696#endif /* defined(HAVE_READV) */
3697
3698#if defined(HAVE_PREAD)
3699
3700PyDoc_STRVAR(os_pread__doc__,
3701"pread($module, fd, length, offset, /)\n"
3702"--\n"
3703"\n"
3704"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3705"\n"
3706"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3707"the beginning of the file. The file offset remains unchanged.");
3708
3709#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003710 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003711
3712static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003713os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003714
3715static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003716os_pread(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717{
3718 PyObject *return_value = NULL;
3719 int fd;
3720 int length;
3721 Py_off_t offset;
3722
Victor Stinner259f0e42017-01-17 01:35:17 +01003723 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003724 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003725 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003726 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003727
3728 if (!_PyArg_NoStackKeywords("pread", kwnames)) {
3729 goto exit;
3730 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003731 return_value = os_pread_impl(module, fd, length, offset);
3732
3733exit:
3734 return return_value;
3735}
3736
3737#endif /* defined(HAVE_PREAD) */
3738
3739PyDoc_STRVAR(os_write__doc__,
3740"write($module, fd, data, /)\n"
3741"--\n"
3742"\n"
3743"Write a bytes object to a file descriptor.");
3744
3745#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003746 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003747
3748static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003749os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003750
3751static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003752os_write(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003753{
3754 PyObject *return_value = NULL;
3755 int fd;
3756 Py_buffer data = {NULL, NULL};
3757 Py_ssize_t _return_value;
3758
Victor Stinner259f0e42017-01-17 01:35:17 +01003759 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003760 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003761 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003762 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003763
3764 if (!_PyArg_NoStackKeywords("write", kwnames)) {
3765 goto exit;
3766 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003767 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003768 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003769 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003770 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003771 return_value = PyLong_FromSsize_t(_return_value);
3772
3773exit:
3774 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003775 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003776 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003777 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003778
3779 return return_value;
3780}
3781
3782PyDoc_STRVAR(os_fstat__doc__,
3783"fstat($module, /, fd)\n"
3784"--\n"
3785"\n"
3786"Perform a stat system call on the given file descriptor.\n"
3787"\n"
3788"Like stat(), but for an open file descriptor.\n"
3789"Equivalent to os.stat(fd).");
3790
3791#define OS_FSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003792 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003793
3794static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003795os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003796
3797static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003798os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003799{
3800 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003801 static const char * const _keywords[] = {"fd", NULL};
3802 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003803 int fd;
3804
Victor Stinner3e1fad62017-01-17 01:29:01 +01003805 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003806 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003807 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003808 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003809 return_value = os_fstat_impl(module, fd);
3810
3811exit:
3812 return return_value;
3813}
3814
3815PyDoc_STRVAR(os_isatty__doc__,
3816"isatty($module, fd, /)\n"
3817"--\n"
3818"\n"
3819"Return True if the fd is connected to a terminal.\n"
3820"\n"
3821"Return True if the file descriptor is an open file descriptor\n"
3822"connected to the slave end of a terminal.");
3823
3824#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003825 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003826
3827static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003828os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003829
3830static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003831os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003832{
3833 PyObject *return_value = NULL;
3834 int fd;
3835 int _return_value;
3836
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003837 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003838 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003839 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003840 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003841 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003842 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003843 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003844 return_value = PyBool_FromLong((long)_return_value);
3845
3846exit:
3847 return return_value;
3848}
3849
3850#if defined(HAVE_PIPE)
3851
3852PyDoc_STRVAR(os_pipe__doc__,
3853"pipe($module, /)\n"
3854"--\n"
3855"\n"
3856"Create a pipe.\n"
3857"\n"
3858"Returns a tuple of two file descriptors:\n"
3859" (read_fd, write_fd)");
3860
3861#define OS_PIPE_METHODDEF \
3862 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3863
3864static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003865os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003866
3867static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003868os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003869{
3870 return os_pipe_impl(module);
3871}
3872
3873#endif /* defined(HAVE_PIPE) */
3874
3875#if defined(HAVE_PIPE2)
3876
3877PyDoc_STRVAR(os_pipe2__doc__,
3878"pipe2($module, flags, /)\n"
3879"--\n"
3880"\n"
3881"Create a pipe with flags set atomically.\n"
3882"\n"
3883"Returns a tuple of two file descriptors:\n"
3884" (read_fd, write_fd)\n"
3885"\n"
3886"flags can be constructed by ORing together one or more of these values:\n"
3887"O_NONBLOCK, O_CLOEXEC.");
3888
3889#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003890 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003891
3892static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003893os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003894
3895static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003896os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003897{
3898 PyObject *return_value = NULL;
3899 int flags;
3900
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003901 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003902 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003903 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003904 return_value = os_pipe2_impl(module, flags);
3905
3906exit:
3907 return return_value;
3908}
3909
3910#endif /* defined(HAVE_PIPE2) */
3911
3912#if defined(HAVE_WRITEV)
3913
3914PyDoc_STRVAR(os_writev__doc__,
3915"writev($module, fd, buffers, /)\n"
3916"--\n"
3917"\n"
3918"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3919"\n"
3920"Returns the total number of bytes written.\n"
3921"buffers must be a sequence of bytes-like objects.");
3922
3923#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003924 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003925
3926static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003927os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003928
3929static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003930os_writev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003931{
3932 PyObject *return_value = NULL;
3933 int fd;
3934 PyObject *buffers;
3935 Py_ssize_t _return_value;
3936
Victor Stinner259f0e42017-01-17 01:35:17 +01003937 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003938 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003939 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003940 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003941
3942 if (!_PyArg_NoStackKeywords("writev", kwnames)) {
3943 goto exit;
3944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003945 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003946 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003947 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003948 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003949 return_value = PyLong_FromSsize_t(_return_value);
3950
3951exit:
3952 return return_value;
3953}
3954
3955#endif /* defined(HAVE_WRITEV) */
3956
3957#if defined(HAVE_PWRITE)
3958
3959PyDoc_STRVAR(os_pwrite__doc__,
3960"pwrite($module, fd, buffer, offset, /)\n"
3961"--\n"
3962"\n"
3963"Write bytes to a file descriptor starting at a particular offset.\n"
3964"\n"
3965"Write buffer to fd, starting at offset bytes from the beginning of\n"
3966"the file. Returns the number of bytes writte. Does not change the\n"
3967"current file offset.");
3968
3969#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003970 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003971
3972static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003973os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003974
3975static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003976os_pwrite(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003977{
3978 PyObject *return_value = NULL;
3979 int fd;
3980 Py_buffer buffer = {NULL, NULL};
3981 Py_off_t offset;
3982 Py_ssize_t _return_value;
3983
Victor Stinner259f0e42017-01-17 01:35:17 +01003984 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003985 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003986 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003987 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003988
3989 if (!_PyArg_NoStackKeywords("pwrite", kwnames)) {
3990 goto exit;
3991 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003992 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003993 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003994 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003995 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003996 return_value = PyLong_FromSsize_t(_return_value);
3997
3998exit:
3999 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004000 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004001 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004002 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004003
4004 return return_value;
4005}
4006
4007#endif /* defined(HAVE_PWRITE) */
4008
4009#if defined(HAVE_MKFIFO)
4010
4011PyDoc_STRVAR(os_mkfifo__doc__,
4012"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4013"--\n"
4014"\n"
4015"Create a \"fifo\" (a POSIX named pipe).\n"
4016"\n"
4017"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4018" and path should be relative; path will then be relative to that directory.\n"
4019"dir_fd may not be implemented on your platform.\n"
4020" If it is unavailable, using it will raise a NotImplementedError.");
4021
4022#define OS_MKFIFO_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004023 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004024
4025static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004026os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004027
4028static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004029os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004030{
4031 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004032 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4033 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004034 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4035 int mode = 438;
4036 int dir_fd = DEFAULT_DIR_FD;
4037
Victor Stinner3e1fad62017-01-17 01:29:01 +01004038 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004039 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004040 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004041 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004042 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4043
4044exit:
4045 /* Cleanup for path */
4046 path_cleanup(&path);
4047
4048 return return_value;
4049}
4050
4051#endif /* defined(HAVE_MKFIFO) */
4052
4053#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4054
4055PyDoc_STRVAR(os_mknod__doc__,
4056"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4057"--\n"
4058"\n"
4059"Create a node in the file system.\n"
4060"\n"
4061"Create a node in the file system (file, device special file or named pipe)\n"
4062"at path. mode specifies both the permissions to use and the\n"
4063"type of node to be created, being combined (bitwise OR) with one of\n"
4064"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4065"device defines the newly created device special file (probably using\n"
4066"os.makedev()). Otherwise device is ignored.\n"
4067"\n"
4068"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4069" and path should be relative; path will then be relative to that directory.\n"
4070"dir_fd may not be implemented on your platform.\n"
4071" If it is unavailable, using it will raise a NotImplementedError.");
4072
4073#define OS_MKNOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004074 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004075
4076static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004077os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004078 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004079
4080static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004081os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004082{
4083 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004084 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4085 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004086 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4087 int mode = 384;
4088 dev_t device = 0;
4089 int dir_fd = DEFAULT_DIR_FD;
4090
Victor Stinner3e1fad62017-01-17 01:29:01 +01004091 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004092 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004093 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004094 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004095 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4096
4097exit:
4098 /* Cleanup for path */
4099 path_cleanup(&path);
4100
4101 return return_value;
4102}
4103
4104#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4105
4106#if defined(HAVE_DEVICE_MACROS)
4107
4108PyDoc_STRVAR(os_major__doc__,
4109"major($module, device, /)\n"
4110"--\n"
4111"\n"
4112"Extracts a device major number from a raw device number.");
4113
4114#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004115 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004116
4117static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004118os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004119
4120static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004121os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004122{
4123 PyObject *return_value = NULL;
4124 dev_t device;
4125 unsigned int _return_value;
4126
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004127 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004128 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004129 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004130 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004131 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004132 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004133 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004134 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4135
4136exit:
4137 return return_value;
4138}
4139
4140#endif /* defined(HAVE_DEVICE_MACROS) */
4141
4142#if defined(HAVE_DEVICE_MACROS)
4143
4144PyDoc_STRVAR(os_minor__doc__,
4145"minor($module, device, /)\n"
4146"--\n"
4147"\n"
4148"Extracts a device minor number from a raw device number.");
4149
4150#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004151 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004152
4153static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004154os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004155
4156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004157os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004158{
4159 PyObject *return_value = NULL;
4160 dev_t device;
4161 unsigned int _return_value;
4162
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004163 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004164 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004165 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004166 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004167 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004168 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004169 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004170 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4171
4172exit:
4173 return return_value;
4174}
4175
4176#endif /* defined(HAVE_DEVICE_MACROS) */
4177
4178#if defined(HAVE_DEVICE_MACROS)
4179
4180PyDoc_STRVAR(os_makedev__doc__,
4181"makedev($module, major, minor, /)\n"
4182"--\n"
4183"\n"
4184"Composes a raw device number from the major and minor device numbers.");
4185
4186#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004187 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004188
4189static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004190os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004191
4192static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004193os_makedev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004194{
4195 PyObject *return_value = NULL;
4196 int major;
4197 int minor;
4198 dev_t _return_value;
4199
Victor Stinner259f0e42017-01-17 01:35:17 +01004200 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004201 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004202 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004203 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004204
4205 if (!_PyArg_NoStackKeywords("makedev", kwnames)) {
4206 goto exit;
4207 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004208 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004209 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004210 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004211 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004212 return_value = _PyLong_FromDev(_return_value);
4213
4214exit:
4215 return return_value;
4216}
4217
4218#endif /* defined(HAVE_DEVICE_MACROS) */
4219
Steve Dowerf7377032015-04-12 15:44:54 -04004220#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004221
4222PyDoc_STRVAR(os_ftruncate__doc__,
4223"ftruncate($module, fd, length, /)\n"
4224"--\n"
4225"\n"
4226"Truncate a file, specified by file descriptor, to a specific length.");
4227
4228#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004229 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004230
4231static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004232os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004233
4234static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004235os_ftruncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004236{
4237 PyObject *return_value = NULL;
4238 int fd;
4239 Py_off_t length;
4240
Victor Stinner259f0e42017-01-17 01:35:17 +01004241 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004242 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004243 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004244 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004245
4246 if (!_PyArg_NoStackKeywords("ftruncate", kwnames)) {
4247 goto exit;
4248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004249 return_value = os_ftruncate_impl(module, fd, length);
4250
4251exit:
4252 return return_value;
4253}
4254
Steve Dowerf7377032015-04-12 15:44:54 -04004255#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004256
Steve Dowerf7377032015-04-12 15:44:54 -04004257#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004258
4259PyDoc_STRVAR(os_truncate__doc__,
4260"truncate($module, /, path, length)\n"
4261"--\n"
4262"\n"
4263"Truncate a file, specified by path, to a specific length.\n"
4264"\n"
4265"On some platforms, path may also be specified as an open file descriptor.\n"
4266" If this functionality is unavailable, using it raises an exception.");
4267
4268#define OS_TRUNCATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004269 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004270
4271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004272os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004273
4274static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004275os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004276{
4277 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004278 static const char * const _keywords[] = {"path", "length", NULL};
4279 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004280 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4281 Py_off_t length;
4282
Victor Stinner3e1fad62017-01-17 01:29:01 +01004283 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004284 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004285 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004286 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004287 return_value = os_truncate_impl(module, &path, length);
4288
4289exit:
4290 /* Cleanup for path */
4291 path_cleanup(&path);
4292
4293 return return_value;
4294}
4295
Steve Dowerf7377032015-04-12 15:44:54 -04004296#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004297
4298#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4299
4300PyDoc_STRVAR(os_posix_fallocate__doc__,
4301"posix_fallocate($module, fd, offset, length, /)\n"
4302"--\n"
4303"\n"
4304"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4305"\n"
4306"Ensure that the file specified by fd encompasses a range of bytes\n"
4307"starting at offset bytes from the beginning and continuing for length bytes.");
4308
4309#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004310 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004311
4312static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004313os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004314 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004315
4316static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004317os_posix_fallocate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004318{
4319 PyObject *return_value = NULL;
4320 int fd;
4321 Py_off_t offset;
4322 Py_off_t length;
4323
Victor Stinner259f0e42017-01-17 01:35:17 +01004324 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004325 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004326 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004327 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004328
4329 if (!_PyArg_NoStackKeywords("posix_fallocate", kwnames)) {
4330 goto exit;
4331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004332 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4333
4334exit:
4335 return return_value;
4336}
4337
4338#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4339
4340#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4341
4342PyDoc_STRVAR(os_posix_fadvise__doc__,
4343"posix_fadvise($module, fd, offset, length, advice, /)\n"
4344"--\n"
4345"\n"
4346"Announce an intention to access data in a specific pattern.\n"
4347"\n"
4348"Announce an intention to access data in a specific pattern, thus allowing\n"
4349"the kernel to make optimizations.\n"
4350"The advice applies to the region of the file specified by fd starting at\n"
4351"offset and continuing for length bytes.\n"
4352"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4353"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4354"POSIX_FADV_DONTNEED.");
4355
4356#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004357 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004358
4359static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004360os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004361 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362
4363static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004364os_posix_fadvise(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004365{
4366 PyObject *return_value = NULL;
4367 int fd;
4368 Py_off_t offset;
4369 Py_off_t length;
4370 int advice;
4371
Victor Stinner259f0e42017-01-17 01:35:17 +01004372 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004373 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004374 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004375 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004376
4377 if (!_PyArg_NoStackKeywords("posix_fadvise", kwnames)) {
4378 goto exit;
4379 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004380 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4381
4382exit:
4383 return return_value;
4384}
4385
4386#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4387
4388#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4389
4390PyDoc_STRVAR(os_putenv__doc__,
4391"putenv($module, name, value, /)\n"
4392"--\n"
4393"\n"
4394"Change or add an environment variable.");
4395
4396#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004397 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004398
4399static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004400os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004401
4402static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004403os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004404{
4405 PyObject *return_value = NULL;
4406 PyObject *name;
4407 PyObject *value;
4408
Victor Stinner259f0e42017-01-17 01:35:17 +01004409 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004410 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004411 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004412 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004413
4414 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4415 goto exit;
4416 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004417 return_value = os_putenv_impl(module, name, value);
4418
4419exit:
4420 return return_value;
4421}
4422
4423#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4424
4425#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4426
4427PyDoc_STRVAR(os_putenv__doc__,
4428"putenv($module, name, value, /)\n"
4429"--\n"
4430"\n"
4431"Change or add an environment variable.");
4432
4433#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004434 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004435
4436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004437os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004438
4439static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004440os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004441{
4442 PyObject *return_value = NULL;
4443 PyObject *name = NULL;
4444 PyObject *value = NULL;
4445
Victor Stinner259f0e42017-01-17 01:35:17 +01004446 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004447 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004448 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004449 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004450
4451 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4452 goto exit;
4453 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004454 return_value = os_putenv_impl(module, name, value);
4455
4456exit:
4457 /* Cleanup for name */
4458 Py_XDECREF(name);
4459 /* Cleanup for value */
4460 Py_XDECREF(value);
4461
4462 return return_value;
4463}
4464
4465#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4466
4467#if defined(HAVE_UNSETENV)
4468
4469PyDoc_STRVAR(os_unsetenv__doc__,
4470"unsetenv($module, name, /)\n"
4471"--\n"
4472"\n"
4473"Delete an environment variable.");
4474
4475#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004476 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004477
4478static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004479os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004480
4481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004482os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004483{
4484 PyObject *return_value = NULL;
4485 PyObject *name = NULL;
4486
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004487 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004488 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004489 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004490 return_value = os_unsetenv_impl(module, name);
4491
4492exit:
4493 /* Cleanup for name */
4494 Py_XDECREF(name);
4495
4496 return return_value;
4497}
4498
4499#endif /* defined(HAVE_UNSETENV) */
4500
4501PyDoc_STRVAR(os_strerror__doc__,
4502"strerror($module, code, /)\n"
4503"--\n"
4504"\n"
4505"Translate an error code to a message string.");
4506
4507#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004508 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004509
4510static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004511os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004512
4513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004514os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004515{
4516 PyObject *return_value = NULL;
4517 int code;
4518
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004519 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004520 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004521 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004522 return_value = os_strerror_impl(module, code);
4523
4524exit:
4525 return return_value;
4526}
4527
4528#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4529
4530PyDoc_STRVAR(os_WCOREDUMP__doc__,
4531"WCOREDUMP($module, status, /)\n"
4532"--\n"
4533"\n"
4534"Return True if the process returning status was dumped to a core file.");
4535
4536#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004537 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004538
4539static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004540os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004541
4542static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004543os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004544{
4545 PyObject *return_value = NULL;
4546 int status;
4547 int _return_value;
4548
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004549 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004550 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004551 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004552 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004553 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004554 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004555 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004556 return_value = PyBool_FromLong((long)_return_value);
4557
4558exit:
4559 return return_value;
4560}
4561
4562#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4563
4564#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4565
4566PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4567"WIFCONTINUED($module, /, status)\n"
4568"--\n"
4569"\n"
4570"Return True if a particular process was continued from a job control stop.\n"
4571"\n"
4572"Return True if the process returning status was continued from a\n"
4573"job control stop.");
4574
4575#define OS_WIFCONTINUED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004576 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004577
4578static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004579os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004580
4581static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004582os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004583{
4584 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004585 static const char * const _keywords[] = {"status", NULL};
4586 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004587 int status;
4588 int _return_value;
4589
Victor Stinner3e1fad62017-01-17 01:29:01 +01004590 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004591 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004592 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004593 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004594 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004595 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004596 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004598 return_value = PyBool_FromLong((long)_return_value);
4599
4600exit:
4601 return return_value;
4602}
4603
4604#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4605
4606#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4607
4608PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4609"WIFSTOPPED($module, /, status)\n"
4610"--\n"
4611"\n"
4612"Return True if the process returning status was stopped.");
4613
4614#define OS_WIFSTOPPED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004615 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004616
4617static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004618os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004619
4620static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004621os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004622{
4623 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004624 static const char * const _keywords[] = {"status", NULL};
4625 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004626 int status;
4627 int _return_value;
4628
Victor Stinner3e1fad62017-01-17 01:29:01 +01004629 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004630 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004631 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004632 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004633 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004634 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004635 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004636 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004637 return_value = PyBool_FromLong((long)_return_value);
4638
4639exit:
4640 return return_value;
4641}
4642
4643#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4644
4645#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4646
4647PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4648"WIFSIGNALED($module, /, status)\n"
4649"--\n"
4650"\n"
4651"Return True if the process returning status was terminated by a signal.");
4652
4653#define OS_WIFSIGNALED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004654 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004655
4656static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004657os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004658
4659static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004660os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004661{
4662 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004663 static const char * const _keywords[] = {"status", NULL};
4664 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004665 int status;
4666 int _return_value;
4667
Victor Stinner3e1fad62017-01-17 01:29:01 +01004668 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004669 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004670 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004672 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004673 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004674 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004675 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004676 return_value = PyBool_FromLong((long)_return_value);
4677
4678exit:
4679 return return_value;
4680}
4681
4682#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4683
4684#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4685
4686PyDoc_STRVAR(os_WIFEXITED__doc__,
4687"WIFEXITED($module, /, status)\n"
4688"--\n"
4689"\n"
4690"Return True if the process returning status exited via the exit() system call.");
4691
4692#define OS_WIFEXITED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004693 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004694
4695static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004696os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004697
4698static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004699os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004700{
4701 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004702 static const char * const _keywords[] = {"status", NULL};
4703 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004704 int status;
4705 int _return_value;
4706
Victor Stinner3e1fad62017-01-17 01:29:01 +01004707 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004708 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004709 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004710 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004711 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004712 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004713 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004714 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004715 return_value = PyBool_FromLong((long)_return_value);
4716
4717exit:
4718 return return_value;
4719}
4720
4721#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4722
4723#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4724
4725PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4726"WEXITSTATUS($module, /, status)\n"
4727"--\n"
4728"\n"
4729"Return the process return code from status.");
4730
4731#define OS_WEXITSTATUS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004732 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004733
4734static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004735os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004736
4737static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004738os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004739{
4740 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004741 static const char * const _keywords[] = {"status", NULL};
4742 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004743 int status;
4744 int _return_value;
4745
Victor Stinner3e1fad62017-01-17 01:29:01 +01004746 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004747 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004748 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004749 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004750 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004751 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004753 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004754 return_value = PyLong_FromLong((long)_return_value);
4755
4756exit:
4757 return return_value;
4758}
4759
4760#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4761
4762#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4763
4764PyDoc_STRVAR(os_WTERMSIG__doc__,
4765"WTERMSIG($module, /, status)\n"
4766"--\n"
4767"\n"
4768"Return the signal that terminated the process that provided the status value.");
4769
4770#define OS_WTERMSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004771 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004772
4773static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004774os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004775
4776static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004777os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004778{
4779 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004780 static const char * const _keywords[] = {"status", NULL};
4781 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004782 int status;
4783 int _return_value;
4784
Victor Stinner3e1fad62017-01-17 01:29:01 +01004785 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004786 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004787 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004788 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004789 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004790 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004792 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004793 return_value = PyLong_FromLong((long)_return_value);
4794
4795exit:
4796 return return_value;
4797}
4798
4799#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4800
4801#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4802
4803PyDoc_STRVAR(os_WSTOPSIG__doc__,
4804"WSTOPSIG($module, /, status)\n"
4805"--\n"
4806"\n"
4807"Return the signal that stopped the process that provided the status value.");
4808
4809#define OS_WSTOPSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004810 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004811
4812static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004813os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004814
4815static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004816os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004817{
4818 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004819 static const char * const _keywords[] = {"status", NULL};
4820 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004821 int status;
4822 int _return_value;
4823
Victor Stinner3e1fad62017-01-17 01:29:01 +01004824 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004825 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004826 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004827 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004828 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004829 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004830 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004831 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004832 return_value = PyLong_FromLong((long)_return_value);
4833
4834exit:
4835 return return_value;
4836}
4837
4838#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4839
4840#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4841
4842PyDoc_STRVAR(os_fstatvfs__doc__,
4843"fstatvfs($module, fd, /)\n"
4844"--\n"
4845"\n"
4846"Perform an fstatvfs system call on the given fd.\n"
4847"\n"
4848"Equivalent to statvfs(fd).");
4849
4850#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004851 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004852
4853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004854os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004855
4856static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004857os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004858{
4859 PyObject *return_value = NULL;
4860 int fd;
4861
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004862 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004863 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004864 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004865 return_value = os_fstatvfs_impl(module, fd);
4866
4867exit:
4868 return return_value;
4869}
4870
4871#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4872
4873#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4874
4875PyDoc_STRVAR(os_statvfs__doc__,
4876"statvfs($module, /, path)\n"
4877"--\n"
4878"\n"
4879"Perform a statvfs system call on the given path.\n"
4880"\n"
4881"path may always be specified as a string.\n"
4882"On some platforms, path may also be specified as an open file descriptor.\n"
4883" If this functionality is unavailable, using it raises an exception.");
4884
4885#define OS_STATVFS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004886 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004887
4888static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004889os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004890
4891static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004892os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004893{
4894 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004895 static const char * const _keywords[] = {"path", NULL};
4896 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004897 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4898
Victor Stinner3e1fad62017-01-17 01:29:01 +01004899 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004900 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004901 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004902 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004903 return_value = os_statvfs_impl(module, &path);
4904
4905exit:
4906 /* Cleanup for path */
4907 path_cleanup(&path);
4908
4909 return return_value;
4910}
4911
4912#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4913
4914#if defined(MS_WINDOWS)
4915
4916PyDoc_STRVAR(os__getdiskusage__doc__,
4917"_getdiskusage($module, /, path)\n"
4918"--\n"
4919"\n"
4920"Return disk usage statistics about the given path as a (total, free) tuple.");
4921
4922#define OS__GETDISKUSAGE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004923 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004924
4925static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004926os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004927
4928static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004929os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004930{
4931 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004932 static const char * const _keywords[] = {"path", NULL};
4933 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004934 Py_UNICODE *path;
4935
Victor Stinner3e1fad62017-01-17 01:29:01 +01004936 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004937 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004938 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004939 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004940 return_value = os__getdiskusage_impl(module, path);
4941
4942exit:
4943 return return_value;
4944}
4945
4946#endif /* defined(MS_WINDOWS) */
4947
4948#if defined(HAVE_FPATHCONF)
4949
4950PyDoc_STRVAR(os_fpathconf__doc__,
4951"fpathconf($module, fd, name, /)\n"
4952"--\n"
4953"\n"
4954"Return the configuration limit name for the file descriptor fd.\n"
4955"\n"
4956"If there is no limit, return -1.");
4957
4958#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004959 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004960
4961static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004962os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004963
4964static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004965os_fpathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004966{
4967 PyObject *return_value = NULL;
4968 int fd;
4969 int name;
4970 long _return_value;
4971
Victor Stinner259f0e42017-01-17 01:35:17 +01004972 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004973 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004974 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004975 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004976
4977 if (!_PyArg_NoStackKeywords("fpathconf", kwnames)) {
4978 goto exit;
4979 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004980 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004981 if ((_return_value == -1) && PyErr_Occurred()) {
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 = PyLong_FromLong(_return_value);
4985
4986exit:
4987 return return_value;
4988}
4989
4990#endif /* defined(HAVE_FPATHCONF) */
4991
4992#if defined(HAVE_PATHCONF)
4993
4994PyDoc_STRVAR(os_pathconf__doc__,
4995"pathconf($module, /, path, name)\n"
4996"--\n"
4997"\n"
4998"Return the configuration limit name for the file or directory path.\n"
4999"\n"
5000"If there is no limit, return -1.\n"
5001"On some platforms, path may also be specified as an open file descriptor.\n"
5002" If this functionality is unavailable, using it raises an exception.");
5003
5004#define OS_PATHCONF_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005005 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005006
5007static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005008os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005009
5010static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005011os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005012{
5013 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005014 static const char * const _keywords[] = {"path", "name", NULL};
5015 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005016 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5017 int name;
5018 long _return_value;
5019
Victor Stinner3e1fad62017-01-17 01:29:01 +01005020 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005021 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005022 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005023 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005024 _return_value = os_pathconf_impl(module, &path, 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 /* Cleanup for path */
5032 path_cleanup(&path);
5033
5034 return return_value;
5035}
5036
5037#endif /* defined(HAVE_PATHCONF) */
5038
5039#if defined(HAVE_CONFSTR)
5040
5041PyDoc_STRVAR(os_confstr__doc__,
5042"confstr($module, name, /)\n"
5043"--\n"
5044"\n"
5045"Return a string-valued system configuration variable.");
5046
5047#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005048 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005049
5050static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005051os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005052
5053static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005054os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005055{
5056 PyObject *return_value = NULL;
5057 int name;
5058
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005059 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005061 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005062 return_value = os_confstr_impl(module, name);
5063
5064exit:
5065 return return_value;
5066}
5067
5068#endif /* defined(HAVE_CONFSTR) */
5069
5070#if defined(HAVE_SYSCONF)
5071
5072PyDoc_STRVAR(os_sysconf__doc__,
5073"sysconf($module, name, /)\n"
5074"--\n"
5075"\n"
5076"Return an integer-valued system configuration variable.");
5077
5078#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005079 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005080
5081static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005082os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005083
5084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005085os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005086{
5087 PyObject *return_value = NULL;
5088 int name;
5089 long _return_value;
5090
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005091 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005092 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005093 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005094 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005095 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005096 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005097 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005098 return_value = PyLong_FromLong(_return_value);
5099
5100exit:
5101 return return_value;
5102}
5103
5104#endif /* defined(HAVE_SYSCONF) */
5105
5106PyDoc_STRVAR(os_abort__doc__,
5107"abort($module, /)\n"
5108"--\n"
5109"\n"
5110"Abort the interpreter immediately.\n"
5111"\n"
5112"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5113"on the hosting operating system. This function never returns.");
5114
5115#define OS_ABORT_METHODDEF \
5116 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5117
5118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005119os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005120
5121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005122os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005123{
5124 return os_abort_impl(module);
5125}
5126
Steve Dowercc16be82016-09-08 10:35:16 -07005127#if defined(MS_WINDOWS)
5128
5129PyDoc_STRVAR(os_startfile__doc__,
5130"startfile($module, /, filepath, operation=None)\n"
5131"--\n"
5132"\n"
5133"startfile(filepath [, operation])\n"
5134"\n"
5135"Start a file with its associated application.\n"
5136"\n"
5137"When \"operation\" is not specified or \"open\", this acts like\n"
5138"double-clicking the file in Explorer, or giving the file name as an\n"
5139"argument to the DOS \"start\" command: the file is opened with whatever\n"
5140"application (if any) its extension is associated.\n"
5141"When another \"operation\" is given, it specifies what should be done with\n"
5142"the file. A typical operation is \"print\".\n"
5143"\n"
5144"startfile returns as soon as the associated application is launched.\n"
5145"There is no option to wait for the application to close, and no way\n"
5146"to retrieve the application\'s exit status.\n"
5147"\n"
5148"The filepath is relative to the current directory. If you want to use\n"
5149"an absolute path, make sure the first character is not a slash (\"/\");\n"
5150"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5151
5152#define OS_STARTFILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005153 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005154
5155static PyObject *
5156os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5157
5158static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005159os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005160{
5161 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005162 static const char * const _keywords[] = {"filepath", "operation", NULL};
5163 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005164 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5165 Py_UNICODE *operation = NULL;
5166
Victor Stinner3e1fad62017-01-17 01:29:01 +01005167 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005168 path_converter, &filepath, &operation)) {
5169 goto exit;
5170 }
5171 return_value = os_startfile_impl(module, &filepath, operation);
5172
5173exit:
5174 /* Cleanup for filepath */
5175 path_cleanup(&filepath);
5176
5177 return return_value;
5178}
5179
5180#endif /* defined(MS_WINDOWS) */
5181
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005182#if defined(HAVE_GETLOADAVG)
5183
5184PyDoc_STRVAR(os_getloadavg__doc__,
5185"getloadavg($module, /)\n"
5186"--\n"
5187"\n"
5188"Return average recent system load information.\n"
5189"\n"
5190"Return the number of processes in the system run queue averaged over\n"
5191"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5192"Raises OSError if the load average was unobtainable.");
5193
5194#define OS_GETLOADAVG_METHODDEF \
5195 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5196
5197static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005198os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005199
5200static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005201os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005202{
5203 return os_getloadavg_impl(module);
5204}
5205
5206#endif /* defined(HAVE_GETLOADAVG) */
5207
5208PyDoc_STRVAR(os_device_encoding__doc__,
5209"device_encoding($module, /, fd)\n"
5210"--\n"
5211"\n"
5212"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5213"\n"
5214"The file descriptor must be attached to a terminal.\n"
5215"If the device is not a terminal, return None.");
5216
5217#define OS_DEVICE_ENCODING_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005218 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005219
5220static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005221os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005222
5223static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005224os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005225{
5226 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005227 static const char * const _keywords[] = {"fd", NULL};
5228 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005229 int fd;
5230
Victor Stinner3e1fad62017-01-17 01:29:01 +01005231 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005232 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005233 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005234 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005235 return_value = os_device_encoding_impl(module, fd);
5236
5237exit:
5238 return return_value;
5239}
5240
5241#if defined(HAVE_SETRESUID)
5242
5243PyDoc_STRVAR(os_setresuid__doc__,
5244"setresuid($module, ruid, euid, suid, /)\n"
5245"--\n"
5246"\n"
5247"Set the current process\'s real, effective, and saved user ids.");
5248
5249#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005250 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005251
5252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005253os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005254
5255static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005256os_setresuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005257{
5258 PyObject *return_value = NULL;
5259 uid_t ruid;
5260 uid_t euid;
5261 uid_t suid;
5262
Victor Stinner259f0e42017-01-17 01:35:17 +01005263 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005264 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005265 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005266 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005267
5268 if (!_PyArg_NoStackKeywords("setresuid", kwnames)) {
5269 goto exit;
5270 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005271 return_value = os_setresuid_impl(module, ruid, euid, suid);
5272
5273exit:
5274 return return_value;
5275}
5276
5277#endif /* defined(HAVE_SETRESUID) */
5278
5279#if defined(HAVE_SETRESGID)
5280
5281PyDoc_STRVAR(os_setresgid__doc__,
5282"setresgid($module, rgid, egid, sgid, /)\n"
5283"--\n"
5284"\n"
5285"Set the current process\'s real, effective, and saved group ids.");
5286
5287#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005288 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005289
5290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005291os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005292
5293static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005294os_setresgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005295{
5296 PyObject *return_value = NULL;
5297 gid_t rgid;
5298 gid_t egid;
5299 gid_t sgid;
5300
Victor Stinner259f0e42017-01-17 01:35:17 +01005301 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005302 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005303 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005304 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005305
5306 if (!_PyArg_NoStackKeywords("setresgid", kwnames)) {
5307 goto exit;
5308 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005309 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5310
5311exit:
5312 return return_value;
5313}
5314
5315#endif /* defined(HAVE_SETRESGID) */
5316
5317#if defined(HAVE_GETRESUID)
5318
5319PyDoc_STRVAR(os_getresuid__doc__,
5320"getresuid($module, /)\n"
5321"--\n"
5322"\n"
5323"Return a tuple of the current process\'s real, effective, and saved user ids.");
5324
5325#define OS_GETRESUID_METHODDEF \
5326 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5327
5328static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005329os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005330
5331static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005332os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005333{
5334 return os_getresuid_impl(module);
5335}
5336
5337#endif /* defined(HAVE_GETRESUID) */
5338
5339#if defined(HAVE_GETRESGID)
5340
5341PyDoc_STRVAR(os_getresgid__doc__,
5342"getresgid($module, /)\n"
5343"--\n"
5344"\n"
5345"Return a tuple of the current process\'s real, effective, and saved group ids.");
5346
5347#define OS_GETRESGID_METHODDEF \
5348 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5349
5350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005351os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005352
5353static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005354os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005355{
5356 return os_getresgid_impl(module);
5357}
5358
5359#endif /* defined(HAVE_GETRESGID) */
5360
5361#if defined(USE_XATTRS)
5362
5363PyDoc_STRVAR(os_getxattr__doc__,
5364"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5365"--\n"
5366"\n"
5367"Return the value of extended attribute attribute on path.\n"
5368"\n"
5369"path may be either a string or an open file descriptor.\n"
5370"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5371" link, getxattr will examine the symbolic link itself instead of the file\n"
5372" the link points to.");
5373
5374#define OS_GETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005375 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005376
5377static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005378os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005379 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005380
5381static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005382os_getxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005383{
5384 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005385 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5386 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005387 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5388 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5389 int follow_symlinks = 1;
5390
Victor Stinner3e1fad62017-01-17 01:29:01 +01005391 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005392 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005393 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005394 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005395 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5396
5397exit:
5398 /* Cleanup for path */
5399 path_cleanup(&path);
5400 /* Cleanup for attribute */
5401 path_cleanup(&attribute);
5402
5403 return return_value;
5404}
5405
5406#endif /* defined(USE_XATTRS) */
5407
5408#if defined(USE_XATTRS)
5409
5410PyDoc_STRVAR(os_setxattr__doc__,
5411"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5412" follow_symlinks=True)\n"
5413"--\n"
5414"\n"
5415"Set extended attribute attribute on path to value.\n"
5416"\n"
5417"path may be either a string or an open file descriptor.\n"
5418"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5419" link, setxattr will modify the symbolic link itself instead of the file\n"
5420" the link points to.");
5421
5422#define OS_SETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005423 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005424
5425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005426os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005427 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005428
5429static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005430os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431{
5432 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005433 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5434 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005435 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5436 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5437 Py_buffer value = {NULL, NULL};
5438 int flags = 0;
5439 int follow_symlinks = 1;
5440
Victor Stinner3e1fad62017-01-17 01:29:01 +01005441 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005442 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005443 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005444 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005445 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5446
5447exit:
5448 /* Cleanup for path */
5449 path_cleanup(&path);
5450 /* Cleanup for attribute */
5451 path_cleanup(&attribute);
5452 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005453 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005454 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005455 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005456
5457 return return_value;
5458}
5459
5460#endif /* defined(USE_XATTRS) */
5461
5462#if defined(USE_XATTRS)
5463
5464PyDoc_STRVAR(os_removexattr__doc__,
5465"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5466"--\n"
5467"\n"
5468"Remove extended attribute attribute on path.\n"
5469"\n"
5470"path may be either a string or an open file descriptor.\n"
5471"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5472" link, removexattr will modify the symbolic link itself instead of the file\n"
5473" the link points to.");
5474
5475#define OS_REMOVEXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005476 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005477
5478static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005479os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005480 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005481
5482static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005483os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005484{
5485 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005486 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5487 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005488 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5489 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5490 int follow_symlinks = 1;
5491
Victor Stinner3e1fad62017-01-17 01:29:01 +01005492 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005493 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005494 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005496 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5497
5498exit:
5499 /* Cleanup for path */
5500 path_cleanup(&path);
5501 /* Cleanup for attribute */
5502 path_cleanup(&attribute);
5503
5504 return return_value;
5505}
5506
5507#endif /* defined(USE_XATTRS) */
5508
5509#if defined(USE_XATTRS)
5510
5511PyDoc_STRVAR(os_listxattr__doc__,
5512"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5513"--\n"
5514"\n"
5515"Return a list of extended attributes on path.\n"
5516"\n"
5517"path may be either None, a string, or an open file descriptor.\n"
5518"if path is None, listxattr will examine the current directory.\n"
5519"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5520" link, listxattr will examine the symbolic link itself instead of the file\n"
5521" the link points to.");
5522
5523#define OS_LISTXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005524 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005525
5526static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005527os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005528
5529static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005530os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005531{
5532 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005533 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5534 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005535 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5536 int follow_symlinks = 1;
5537
Victor Stinner3e1fad62017-01-17 01:29:01 +01005538 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005539 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005540 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005541 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5543
5544exit:
5545 /* Cleanup for path */
5546 path_cleanup(&path);
5547
5548 return return_value;
5549}
5550
5551#endif /* defined(USE_XATTRS) */
5552
5553PyDoc_STRVAR(os_urandom__doc__,
5554"urandom($module, size, /)\n"
5555"--\n"
5556"\n"
5557"Return a bytes object containing random bytes suitable for cryptographic use.");
5558
5559#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005560 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005561
5562static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005563os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005564
5565static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005566os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005567{
5568 PyObject *return_value = NULL;
5569 Py_ssize_t size;
5570
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005571 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005572 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005573 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005574 return_value = os_urandom_impl(module, size);
5575
5576exit:
5577 return return_value;
5578}
5579
5580PyDoc_STRVAR(os_cpu_count__doc__,
5581"cpu_count($module, /)\n"
5582"--\n"
5583"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005584"Return the number of CPUs in the system; return None if indeterminable.\n"
5585"\n"
5586"This number is not equivalent to the number of CPUs the current process can\n"
5587"use. The number of usable CPUs can be obtained with\n"
5588"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005589
5590#define OS_CPU_COUNT_METHODDEF \
5591 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5592
5593static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005594os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005595
5596static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005597os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005598{
5599 return os_cpu_count_impl(module);
5600}
5601
5602PyDoc_STRVAR(os_get_inheritable__doc__,
5603"get_inheritable($module, fd, /)\n"
5604"--\n"
5605"\n"
5606"Get the close-on-exe flag of the specified file descriptor.");
5607
5608#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005609 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005610
5611static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005612os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005613
5614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005615os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005616{
5617 PyObject *return_value = NULL;
5618 int fd;
5619 int _return_value;
5620
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005621 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005622 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005623 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005624 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005625 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005626 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005627 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005628 return_value = PyBool_FromLong((long)_return_value);
5629
5630exit:
5631 return return_value;
5632}
5633
5634PyDoc_STRVAR(os_set_inheritable__doc__,
5635"set_inheritable($module, fd, inheritable, /)\n"
5636"--\n"
5637"\n"
5638"Set the inheritable flag of the specified file descriptor.");
5639
5640#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005641 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005642
5643static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005644os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005645
5646static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005647os_set_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005648{
5649 PyObject *return_value = NULL;
5650 int fd;
5651 int inheritable;
5652
Victor Stinner259f0e42017-01-17 01:35:17 +01005653 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005654 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005655 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005656 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005657
5658 if (!_PyArg_NoStackKeywords("set_inheritable", kwnames)) {
5659 goto exit;
5660 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005661 return_value = os_set_inheritable_impl(module, fd, inheritable);
5662
5663exit:
5664 return return_value;
5665}
5666
5667#if defined(MS_WINDOWS)
5668
5669PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5670"get_handle_inheritable($module, handle, /)\n"
5671"--\n"
5672"\n"
5673"Get the close-on-exe flag of the specified file descriptor.");
5674
5675#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005676 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005677
5678static int
Victor Stinner581139c2016-09-06 15:54:20 -07005679os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005680
5681static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005682os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005683{
5684 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005685 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005686 int _return_value;
5687
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005688 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005689 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005690 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005691 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005692 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005693 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005694 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005695 return_value = PyBool_FromLong((long)_return_value);
5696
5697exit:
5698 return return_value;
5699}
5700
5701#endif /* defined(MS_WINDOWS) */
5702
5703#if defined(MS_WINDOWS)
5704
5705PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5706"set_handle_inheritable($module, handle, inheritable, /)\n"
5707"--\n"
5708"\n"
5709"Set the inheritable flag of the specified handle.");
5710
5711#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005712 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005713
5714static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005715os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005716 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005717
5718static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005719os_set_handle_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005720{
5721 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005722 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005723 int inheritable;
5724
Victor Stinner259f0e42017-01-17 01:35:17 +01005725 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005726 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005727 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005728 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005729
5730 if (!_PyArg_NoStackKeywords("set_handle_inheritable", kwnames)) {
5731 goto exit;
5732 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005733 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5734
5735exit:
5736 return return_value;
5737}
5738
5739#endif /* defined(MS_WINDOWS) */
5740
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005741PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5742"is_symlink($self, /)\n"
5743"--\n"
5744"\n"
5745"Return True if the entry is a symbolic link; cached per entry.");
5746
5747#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5748 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5749
5750static int
5751os_DirEntry_is_symlink_impl(DirEntry *self);
5752
5753static PyObject *
5754os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5755{
5756 PyObject *return_value = NULL;
5757 int _return_value;
5758
5759 _return_value = os_DirEntry_is_symlink_impl(self);
5760 if ((_return_value == -1) && PyErr_Occurred()) {
5761 goto exit;
5762 }
5763 return_value = PyBool_FromLong((long)_return_value);
5764
5765exit:
5766 return return_value;
5767}
5768
5769PyDoc_STRVAR(os_DirEntry_stat__doc__,
5770"stat($self, /, *, follow_symlinks=True)\n"
5771"--\n"
5772"\n"
5773"Return stat_result object for the entry; cached per entry.");
5774
5775#define OS_DIRENTRY_STAT_METHODDEF \
5776 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL, os_DirEntry_stat__doc__},
5777
5778static PyObject *
5779os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5780
5781static PyObject *
5782os_DirEntry_stat(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5783{
5784 PyObject *return_value = NULL;
5785 static const char * const _keywords[] = {"follow_symlinks", NULL};
5786 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5787 int follow_symlinks = 1;
5788
Victor Stinner3e1fad62017-01-17 01:29:01 +01005789 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005790 &follow_symlinks)) {
5791 goto exit;
5792 }
5793 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5794
5795exit:
5796 return return_value;
5797}
5798
5799PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5800"is_dir($self, /, *, follow_symlinks=True)\n"
5801"--\n"
5802"\n"
5803"Return True if the entry is a directory; cached per entry.");
5804
5805#define OS_DIRENTRY_IS_DIR_METHODDEF \
5806 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL, os_DirEntry_is_dir__doc__},
5807
5808static int
5809os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5810
5811static PyObject *
5812os_DirEntry_is_dir(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5813{
5814 PyObject *return_value = NULL;
5815 static const char * const _keywords[] = {"follow_symlinks", NULL};
5816 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5817 int follow_symlinks = 1;
5818 int _return_value;
5819
Victor Stinner3e1fad62017-01-17 01:29:01 +01005820 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005821 &follow_symlinks)) {
5822 goto exit;
5823 }
5824 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5825 if ((_return_value == -1) && PyErr_Occurred()) {
5826 goto exit;
5827 }
5828 return_value = PyBool_FromLong((long)_return_value);
5829
5830exit:
5831 return return_value;
5832}
5833
5834PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5835"is_file($self, /, *, follow_symlinks=True)\n"
5836"--\n"
5837"\n"
5838"Return True if the entry is a file; cached per entry.");
5839
5840#define OS_DIRENTRY_IS_FILE_METHODDEF \
5841 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL, os_DirEntry_is_file__doc__},
5842
5843static int
5844os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5845
5846static PyObject *
5847os_DirEntry_is_file(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5848{
5849 PyObject *return_value = NULL;
5850 static const char * const _keywords[] = {"follow_symlinks", NULL};
5851 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5852 int follow_symlinks = 1;
5853 int _return_value;
5854
Victor Stinner3e1fad62017-01-17 01:29:01 +01005855 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005856 &follow_symlinks)) {
5857 goto exit;
5858 }
5859 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5860 if ((_return_value == -1) && PyErr_Occurred()) {
5861 goto exit;
5862 }
5863 return_value = PyBool_FromLong((long)_return_value);
5864
5865exit:
5866 return return_value;
5867}
5868
5869PyDoc_STRVAR(os_DirEntry_inode__doc__,
5870"inode($self, /)\n"
5871"--\n"
5872"\n"
5873"Return inode of the entry; cached per entry.");
5874
5875#define OS_DIRENTRY_INODE_METHODDEF \
5876 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5877
5878static PyObject *
5879os_DirEntry_inode_impl(DirEntry *self);
5880
5881static PyObject *
5882os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5883{
5884 return os_DirEntry_inode_impl(self);
5885}
5886
5887PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5888"__fspath__($self, /)\n"
5889"--\n"
5890"\n"
5891"Returns the path for the entry.");
5892
5893#define OS_DIRENTRY___FSPATH___METHODDEF \
5894 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5895
5896static PyObject *
5897os_DirEntry___fspath___impl(DirEntry *self);
5898
5899static PyObject *
5900os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5901{
5902 return os_DirEntry___fspath___impl(self);
5903}
5904
5905PyDoc_STRVAR(os_scandir__doc__,
5906"scandir($module, /, path=None)\n"
5907"--\n"
5908"\n"
5909"Return an iterator of DirEntry objects for given path.\n"
5910"\n"
5911"path can be specified as either str, bytes or path-like object. If path\n"
5912"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5913"all other circumstances they will be str.\n"
5914"\n"
5915"If path is None, uses the path=\'.\'.");
5916
5917#define OS_SCANDIR_METHODDEF \
5918 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL, os_scandir__doc__},
5919
5920static PyObject *
5921os_scandir_impl(PyObject *module, path_t *path);
5922
5923static PyObject *
5924os_scandir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5925{
5926 PyObject *return_value = NULL;
5927 static const char * const _keywords[] = {"path", NULL};
5928 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03005929 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005930
Victor Stinner3e1fad62017-01-17 01:29:01 +01005931 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005932 path_converter, &path)) {
5933 goto exit;
5934 }
5935 return_value = os_scandir_impl(module, &path);
5936
5937exit:
5938 /* Cleanup for path */
5939 path_cleanup(&path);
5940
5941 return return_value;
5942}
5943
Ethan Furman410ef8e2016-06-04 12:06:26 -07005944PyDoc_STRVAR(os_fspath__doc__,
5945"fspath($module, /, path)\n"
5946"--\n"
5947"\n"
5948"Return the file system path representation of the object.\n"
5949"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005950"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5951"object defines __fspath__(), then return the result of that method. All other\n"
5952"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07005953
5954#define OS_FSPATH_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005955 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07005956
5957static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03005958os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07005959
5960static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005961os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07005962{
5963 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005964 static const char * const _keywords[] = {"path", NULL};
5965 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07005966 PyObject *path;
5967
Victor Stinner3e1fad62017-01-17 01:29:01 +01005968 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005969 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07005970 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005971 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07005972 return_value = os_fspath_impl(module, path);
5973
5974exit:
5975 return return_value;
5976}
5977
Victor Stinner9b1f4742016-09-06 16:18:52 -07005978#if defined(HAVE_GETRANDOM_SYSCALL)
5979
5980PyDoc_STRVAR(os_getrandom__doc__,
5981"getrandom($module, /, size, flags=0)\n"
5982"--\n"
5983"\n"
5984"Obtain a series of random bytes.");
5985
5986#define OS_GETRANDOM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005987 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07005988
5989static PyObject *
5990os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
5991
5992static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005993os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07005994{
5995 PyObject *return_value = NULL;
5996 static const char * const _keywords[] = {"size", "flags", NULL};
5997 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
5998 Py_ssize_t size;
5999 int flags = 0;
6000
Victor Stinner3e1fad62017-01-17 01:29:01 +01006001 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006002 &size, &flags)) {
6003 goto exit;
6004 }
6005 return_value = os_getrandom_impl(module, size, flags);
6006
6007exit:
6008 return return_value;
6009}
6010
6011#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6012
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006013#ifndef OS_TTYNAME_METHODDEF
6014 #define OS_TTYNAME_METHODDEF
6015#endif /* !defined(OS_TTYNAME_METHODDEF) */
6016
6017#ifndef OS_CTERMID_METHODDEF
6018 #define OS_CTERMID_METHODDEF
6019#endif /* !defined(OS_CTERMID_METHODDEF) */
6020
6021#ifndef OS_FCHDIR_METHODDEF
6022 #define OS_FCHDIR_METHODDEF
6023#endif /* !defined(OS_FCHDIR_METHODDEF) */
6024
6025#ifndef OS_FCHMOD_METHODDEF
6026 #define OS_FCHMOD_METHODDEF
6027#endif /* !defined(OS_FCHMOD_METHODDEF) */
6028
6029#ifndef OS_LCHMOD_METHODDEF
6030 #define OS_LCHMOD_METHODDEF
6031#endif /* !defined(OS_LCHMOD_METHODDEF) */
6032
6033#ifndef OS_CHFLAGS_METHODDEF
6034 #define OS_CHFLAGS_METHODDEF
6035#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6036
6037#ifndef OS_LCHFLAGS_METHODDEF
6038 #define OS_LCHFLAGS_METHODDEF
6039#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6040
6041#ifndef OS_CHROOT_METHODDEF
6042 #define OS_CHROOT_METHODDEF
6043#endif /* !defined(OS_CHROOT_METHODDEF) */
6044
6045#ifndef OS_FSYNC_METHODDEF
6046 #define OS_FSYNC_METHODDEF
6047#endif /* !defined(OS_FSYNC_METHODDEF) */
6048
6049#ifndef OS_SYNC_METHODDEF
6050 #define OS_SYNC_METHODDEF
6051#endif /* !defined(OS_SYNC_METHODDEF) */
6052
6053#ifndef OS_FDATASYNC_METHODDEF
6054 #define OS_FDATASYNC_METHODDEF
6055#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6056
6057#ifndef OS_CHOWN_METHODDEF
6058 #define OS_CHOWN_METHODDEF
6059#endif /* !defined(OS_CHOWN_METHODDEF) */
6060
6061#ifndef OS_FCHOWN_METHODDEF
6062 #define OS_FCHOWN_METHODDEF
6063#endif /* !defined(OS_FCHOWN_METHODDEF) */
6064
6065#ifndef OS_LCHOWN_METHODDEF
6066 #define OS_LCHOWN_METHODDEF
6067#endif /* !defined(OS_LCHOWN_METHODDEF) */
6068
6069#ifndef OS_LINK_METHODDEF
6070 #define OS_LINK_METHODDEF
6071#endif /* !defined(OS_LINK_METHODDEF) */
6072
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006073#ifndef OS__GETFULLPATHNAME_METHODDEF
6074 #define OS__GETFULLPATHNAME_METHODDEF
6075#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6076
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006077#ifndef OS__GETFINALPATHNAME_METHODDEF
6078 #define OS__GETFINALPATHNAME_METHODDEF
6079#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6080
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006081#ifndef OS__ISDIR_METHODDEF
6082 #define OS__ISDIR_METHODDEF
6083#endif /* !defined(OS__ISDIR_METHODDEF) */
6084
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006085#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6086 #define OS__GETVOLUMEPATHNAME_METHODDEF
6087#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6088
6089#ifndef OS_NICE_METHODDEF
6090 #define OS_NICE_METHODDEF
6091#endif /* !defined(OS_NICE_METHODDEF) */
6092
6093#ifndef OS_GETPRIORITY_METHODDEF
6094 #define OS_GETPRIORITY_METHODDEF
6095#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6096
6097#ifndef OS_SETPRIORITY_METHODDEF
6098 #define OS_SETPRIORITY_METHODDEF
6099#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6100
6101#ifndef OS_SYSTEM_METHODDEF
6102 #define OS_SYSTEM_METHODDEF
6103#endif /* !defined(OS_SYSTEM_METHODDEF) */
6104
6105#ifndef OS_UNAME_METHODDEF
6106 #define OS_UNAME_METHODDEF
6107#endif /* !defined(OS_UNAME_METHODDEF) */
6108
6109#ifndef OS_EXECV_METHODDEF
6110 #define OS_EXECV_METHODDEF
6111#endif /* !defined(OS_EXECV_METHODDEF) */
6112
6113#ifndef OS_EXECVE_METHODDEF
6114 #define OS_EXECVE_METHODDEF
6115#endif /* !defined(OS_EXECVE_METHODDEF) */
6116
6117#ifndef OS_SPAWNV_METHODDEF
6118 #define OS_SPAWNV_METHODDEF
6119#endif /* !defined(OS_SPAWNV_METHODDEF) */
6120
6121#ifndef OS_SPAWNVE_METHODDEF
6122 #define OS_SPAWNVE_METHODDEF
6123#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6124
6125#ifndef OS_FORK1_METHODDEF
6126 #define OS_FORK1_METHODDEF
6127#endif /* !defined(OS_FORK1_METHODDEF) */
6128
6129#ifndef OS_FORK_METHODDEF
6130 #define OS_FORK_METHODDEF
6131#endif /* !defined(OS_FORK_METHODDEF) */
6132
6133#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6134 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6135#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6136
6137#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6138 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6139#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6140
6141#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6142 #define OS_SCHED_GETSCHEDULER_METHODDEF
6143#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6144
6145#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6146 #define OS_SCHED_SETSCHEDULER_METHODDEF
6147#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6148
6149#ifndef OS_SCHED_GETPARAM_METHODDEF
6150 #define OS_SCHED_GETPARAM_METHODDEF
6151#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6152
6153#ifndef OS_SCHED_SETPARAM_METHODDEF
6154 #define OS_SCHED_SETPARAM_METHODDEF
6155#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6156
6157#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6158 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6159#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6160
6161#ifndef OS_SCHED_YIELD_METHODDEF
6162 #define OS_SCHED_YIELD_METHODDEF
6163#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6164
6165#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6166 #define OS_SCHED_SETAFFINITY_METHODDEF
6167#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6168
6169#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6170 #define OS_SCHED_GETAFFINITY_METHODDEF
6171#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6172
6173#ifndef OS_OPENPTY_METHODDEF
6174 #define OS_OPENPTY_METHODDEF
6175#endif /* !defined(OS_OPENPTY_METHODDEF) */
6176
6177#ifndef OS_FORKPTY_METHODDEF
6178 #define OS_FORKPTY_METHODDEF
6179#endif /* !defined(OS_FORKPTY_METHODDEF) */
6180
6181#ifndef OS_GETEGID_METHODDEF
6182 #define OS_GETEGID_METHODDEF
6183#endif /* !defined(OS_GETEGID_METHODDEF) */
6184
6185#ifndef OS_GETEUID_METHODDEF
6186 #define OS_GETEUID_METHODDEF
6187#endif /* !defined(OS_GETEUID_METHODDEF) */
6188
6189#ifndef OS_GETGID_METHODDEF
6190 #define OS_GETGID_METHODDEF
6191#endif /* !defined(OS_GETGID_METHODDEF) */
6192
Berker Peksag39404992016-09-15 20:45:16 +03006193#ifndef OS_GETPID_METHODDEF
6194 #define OS_GETPID_METHODDEF
6195#endif /* !defined(OS_GETPID_METHODDEF) */
6196
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006197#ifndef OS_GETGROUPS_METHODDEF
6198 #define OS_GETGROUPS_METHODDEF
6199#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6200
6201#ifndef OS_GETPGID_METHODDEF
6202 #define OS_GETPGID_METHODDEF
6203#endif /* !defined(OS_GETPGID_METHODDEF) */
6204
6205#ifndef OS_GETPGRP_METHODDEF
6206 #define OS_GETPGRP_METHODDEF
6207#endif /* !defined(OS_GETPGRP_METHODDEF) */
6208
6209#ifndef OS_SETPGRP_METHODDEF
6210 #define OS_SETPGRP_METHODDEF
6211#endif /* !defined(OS_SETPGRP_METHODDEF) */
6212
6213#ifndef OS_GETPPID_METHODDEF
6214 #define OS_GETPPID_METHODDEF
6215#endif /* !defined(OS_GETPPID_METHODDEF) */
6216
6217#ifndef OS_GETLOGIN_METHODDEF
6218 #define OS_GETLOGIN_METHODDEF
6219#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6220
6221#ifndef OS_GETUID_METHODDEF
6222 #define OS_GETUID_METHODDEF
6223#endif /* !defined(OS_GETUID_METHODDEF) */
6224
6225#ifndef OS_KILL_METHODDEF
6226 #define OS_KILL_METHODDEF
6227#endif /* !defined(OS_KILL_METHODDEF) */
6228
6229#ifndef OS_KILLPG_METHODDEF
6230 #define OS_KILLPG_METHODDEF
6231#endif /* !defined(OS_KILLPG_METHODDEF) */
6232
6233#ifndef OS_PLOCK_METHODDEF
6234 #define OS_PLOCK_METHODDEF
6235#endif /* !defined(OS_PLOCK_METHODDEF) */
6236
6237#ifndef OS_SETUID_METHODDEF
6238 #define OS_SETUID_METHODDEF
6239#endif /* !defined(OS_SETUID_METHODDEF) */
6240
6241#ifndef OS_SETEUID_METHODDEF
6242 #define OS_SETEUID_METHODDEF
6243#endif /* !defined(OS_SETEUID_METHODDEF) */
6244
6245#ifndef OS_SETEGID_METHODDEF
6246 #define OS_SETEGID_METHODDEF
6247#endif /* !defined(OS_SETEGID_METHODDEF) */
6248
6249#ifndef OS_SETREUID_METHODDEF
6250 #define OS_SETREUID_METHODDEF
6251#endif /* !defined(OS_SETREUID_METHODDEF) */
6252
6253#ifndef OS_SETREGID_METHODDEF
6254 #define OS_SETREGID_METHODDEF
6255#endif /* !defined(OS_SETREGID_METHODDEF) */
6256
6257#ifndef OS_SETGID_METHODDEF
6258 #define OS_SETGID_METHODDEF
6259#endif /* !defined(OS_SETGID_METHODDEF) */
6260
6261#ifndef OS_SETGROUPS_METHODDEF
6262 #define OS_SETGROUPS_METHODDEF
6263#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6264
6265#ifndef OS_WAIT3_METHODDEF
6266 #define OS_WAIT3_METHODDEF
6267#endif /* !defined(OS_WAIT3_METHODDEF) */
6268
6269#ifndef OS_WAIT4_METHODDEF
6270 #define OS_WAIT4_METHODDEF
6271#endif /* !defined(OS_WAIT4_METHODDEF) */
6272
6273#ifndef OS_WAITID_METHODDEF
6274 #define OS_WAITID_METHODDEF
6275#endif /* !defined(OS_WAITID_METHODDEF) */
6276
6277#ifndef OS_WAITPID_METHODDEF
6278 #define OS_WAITPID_METHODDEF
6279#endif /* !defined(OS_WAITPID_METHODDEF) */
6280
6281#ifndef OS_WAIT_METHODDEF
6282 #define OS_WAIT_METHODDEF
6283#endif /* !defined(OS_WAIT_METHODDEF) */
6284
6285#ifndef OS_SYMLINK_METHODDEF
6286 #define OS_SYMLINK_METHODDEF
6287#endif /* !defined(OS_SYMLINK_METHODDEF) */
6288
6289#ifndef OS_TIMES_METHODDEF
6290 #define OS_TIMES_METHODDEF
6291#endif /* !defined(OS_TIMES_METHODDEF) */
6292
6293#ifndef OS_GETSID_METHODDEF
6294 #define OS_GETSID_METHODDEF
6295#endif /* !defined(OS_GETSID_METHODDEF) */
6296
6297#ifndef OS_SETSID_METHODDEF
6298 #define OS_SETSID_METHODDEF
6299#endif /* !defined(OS_SETSID_METHODDEF) */
6300
6301#ifndef OS_SETPGID_METHODDEF
6302 #define OS_SETPGID_METHODDEF
6303#endif /* !defined(OS_SETPGID_METHODDEF) */
6304
6305#ifndef OS_TCGETPGRP_METHODDEF
6306 #define OS_TCGETPGRP_METHODDEF
6307#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6308
6309#ifndef OS_TCSETPGRP_METHODDEF
6310 #define OS_TCSETPGRP_METHODDEF
6311#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6312
6313#ifndef OS_LOCKF_METHODDEF
6314 #define OS_LOCKF_METHODDEF
6315#endif /* !defined(OS_LOCKF_METHODDEF) */
6316
6317#ifndef OS_READV_METHODDEF
6318 #define OS_READV_METHODDEF
6319#endif /* !defined(OS_READV_METHODDEF) */
6320
6321#ifndef OS_PREAD_METHODDEF
6322 #define OS_PREAD_METHODDEF
6323#endif /* !defined(OS_PREAD_METHODDEF) */
6324
6325#ifndef OS_PIPE_METHODDEF
6326 #define OS_PIPE_METHODDEF
6327#endif /* !defined(OS_PIPE_METHODDEF) */
6328
6329#ifndef OS_PIPE2_METHODDEF
6330 #define OS_PIPE2_METHODDEF
6331#endif /* !defined(OS_PIPE2_METHODDEF) */
6332
6333#ifndef OS_WRITEV_METHODDEF
6334 #define OS_WRITEV_METHODDEF
6335#endif /* !defined(OS_WRITEV_METHODDEF) */
6336
6337#ifndef OS_PWRITE_METHODDEF
6338 #define OS_PWRITE_METHODDEF
6339#endif /* !defined(OS_PWRITE_METHODDEF) */
6340
6341#ifndef OS_MKFIFO_METHODDEF
6342 #define OS_MKFIFO_METHODDEF
6343#endif /* !defined(OS_MKFIFO_METHODDEF) */
6344
6345#ifndef OS_MKNOD_METHODDEF
6346 #define OS_MKNOD_METHODDEF
6347#endif /* !defined(OS_MKNOD_METHODDEF) */
6348
6349#ifndef OS_MAJOR_METHODDEF
6350 #define OS_MAJOR_METHODDEF
6351#endif /* !defined(OS_MAJOR_METHODDEF) */
6352
6353#ifndef OS_MINOR_METHODDEF
6354 #define OS_MINOR_METHODDEF
6355#endif /* !defined(OS_MINOR_METHODDEF) */
6356
6357#ifndef OS_MAKEDEV_METHODDEF
6358 #define OS_MAKEDEV_METHODDEF
6359#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6360
6361#ifndef OS_FTRUNCATE_METHODDEF
6362 #define OS_FTRUNCATE_METHODDEF
6363#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6364
6365#ifndef OS_TRUNCATE_METHODDEF
6366 #define OS_TRUNCATE_METHODDEF
6367#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6368
6369#ifndef OS_POSIX_FALLOCATE_METHODDEF
6370 #define OS_POSIX_FALLOCATE_METHODDEF
6371#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6372
6373#ifndef OS_POSIX_FADVISE_METHODDEF
6374 #define OS_POSIX_FADVISE_METHODDEF
6375#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6376
6377#ifndef OS_PUTENV_METHODDEF
6378 #define OS_PUTENV_METHODDEF
6379#endif /* !defined(OS_PUTENV_METHODDEF) */
6380
6381#ifndef OS_UNSETENV_METHODDEF
6382 #define OS_UNSETENV_METHODDEF
6383#endif /* !defined(OS_UNSETENV_METHODDEF) */
6384
6385#ifndef OS_WCOREDUMP_METHODDEF
6386 #define OS_WCOREDUMP_METHODDEF
6387#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6388
6389#ifndef OS_WIFCONTINUED_METHODDEF
6390 #define OS_WIFCONTINUED_METHODDEF
6391#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6392
6393#ifndef OS_WIFSTOPPED_METHODDEF
6394 #define OS_WIFSTOPPED_METHODDEF
6395#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6396
6397#ifndef OS_WIFSIGNALED_METHODDEF
6398 #define OS_WIFSIGNALED_METHODDEF
6399#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6400
6401#ifndef OS_WIFEXITED_METHODDEF
6402 #define OS_WIFEXITED_METHODDEF
6403#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6404
6405#ifndef OS_WEXITSTATUS_METHODDEF
6406 #define OS_WEXITSTATUS_METHODDEF
6407#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6408
6409#ifndef OS_WTERMSIG_METHODDEF
6410 #define OS_WTERMSIG_METHODDEF
6411#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6412
6413#ifndef OS_WSTOPSIG_METHODDEF
6414 #define OS_WSTOPSIG_METHODDEF
6415#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6416
6417#ifndef OS_FSTATVFS_METHODDEF
6418 #define OS_FSTATVFS_METHODDEF
6419#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6420
6421#ifndef OS_STATVFS_METHODDEF
6422 #define OS_STATVFS_METHODDEF
6423#endif /* !defined(OS_STATVFS_METHODDEF) */
6424
6425#ifndef OS__GETDISKUSAGE_METHODDEF
6426 #define OS__GETDISKUSAGE_METHODDEF
6427#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6428
6429#ifndef OS_FPATHCONF_METHODDEF
6430 #define OS_FPATHCONF_METHODDEF
6431#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6432
6433#ifndef OS_PATHCONF_METHODDEF
6434 #define OS_PATHCONF_METHODDEF
6435#endif /* !defined(OS_PATHCONF_METHODDEF) */
6436
6437#ifndef OS_CONFSTR_METHODDEF
6438 #define OS_CONFSTR_METHODDEF
6439#endif /* !defined(OS_CONFSTR_METHODDEF) */
6440
6441#ifndef OS_SYSCONF_METHODDEF
6442 #define OS_SYSCONF_METHODDEF
6443#endif /* !defined(OS_SYSCONF_METHODDEF) */
6444
Steve Dowercc16be82016-09-08 10:35:16 -07006445#ifndef OS_STARTFILE_METHODDEF
6446 #define OS_STARTFILE_METHODDEF
6447#endif /* !defined(OS_STARTFILE_METHODDEF) */
6448
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006449#ifndef OS_GETLOADAVG_METHODDEF
6450 #define OS_GETLOADAVG_METHODDEF
6451#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6452
6453#ifndef OS_SETRESUID_METHODDEF
6454 #define OS_SETRESUID_METHODDEF
6455#endif /* !defined(OS_SETRESUID_METHODDEF) */
6456
6457#ifndef OS_SETRESGID_METHODDEF
6458 #define OS_SETRESGID_METHODDEF
6459#endif /* !defined(OS_SETRESGID_METHODDEF) */
6460
6461#ifndef OS_GETRESUID_METHODDEF
6462 #define OS_GETRESUID_METHODDEF
6463#endif /* !defined(OS_GETRESUID_METHODDEF) */
6464
6465#ifndef OS_GETRESGID_METHODDEF
6466 #define OS_GETRESGID_METHODDEF
6467#endif /* !defined(OS_GETRESGID_METHODDEF) */
6468
6469#ifndef OS_GETXATTR_METHODDEF
6470 #define OS_GETXATTR_METHODDEF
6471#endif /* !defined(OS_GETXATTR_METHODDEF) */
6472
6473#ifndef OS_SETXATTR_METHODDEF
6474 #define OS_SETXATTR_METHODDEF
6475#endif /* !defined(OS_SETXATTR_METHODDEF) */
6476
6477#ifndef OS_REMOVEXATTR_METHODDEF
6478 #define OS_REMOVEXATTR_METHODDEF
6479#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6480
6481#ifndef OS_LISTXATTR_METHODDEF
6482 #define OS_LISTXATTR_METHODDEF
6483#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6484
6485#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6486 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6487#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6488
6489#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6490 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6491#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006492
6493#ifndef OS_GETRANDOM_METHODDEF
6494 #define OS_GETRANDOM_METHODDEF
6495#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006496/*[clinic end generated code: output=5529857101c08b49 input=a9049054013a1b77]*/