blob: 8e1b55a57ddc14123e99c48066f24577a797a73c [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(os_stat__doc__,
6"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
7"--\n"
8"\n"
9"Perform a stat system call on the given path.\n"
10"\n"
11" path\n"
Xiang Zhang4459e002017-01-22 13:04:17 +080012" Path to be examined; can be string, bytes, path-like object or\n"
13" open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030014" dir_fd\n"
15" If not None, it should be a file descriptor open to a directory,\n"
16" and path should be a relative string; path will then be relative to\n"
17" that directory.\n"
18" follow_symlinks\n"
19" If False, and the last element of the path is a symbolic link,\n"
20" stat will examine the symbolic link itself instead of the file\n"
21" the link points to.\n"
22"\n"
23"dir_fd and follow_symlinks may not be implemented\n"
24" on your platform. If they are unavailable, using them will raise a\n"
25" NotImplementedError.\n"
26"\n"
27"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
28" an open file descriptor.");
29
30#define OS_STAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070031 {"stat", (PyCFunction)os_stat, METH_FASTCALL, os_stat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030032
33static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030035
36static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070037os_stat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030038{
39 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030040 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
41 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030042 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
43 int dir_fd = DEFAULT_DIR_FD;
44 int follow_symlinks = 1;
45
Victor Stinner3e1fad62017-01-17 01:29:01 +010046 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030047 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030048 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030049 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
51
52exit:
53 /* Cleanup for path */
54 path_cleanup(&path);
55
56 return return_value;
57}
58
59PyDoc_STRVAR(os_lstat__doc__,
60"lstat($module, /, path, *, dir_fd=None)\n"
61"--\n"
62"\n"
63"Perform a stat system call on the given path, without following symbolic links.\n"
64"\n"
65"Like stat(), but do not follow symbolic links.\n"
66"Equivalent to stat(path, follow_symlinks=False).");
67
68#define OS_LSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070069 {"lstat", (PyCFunction)os_lstat, METH_FASTCALL, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070
71static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030072os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030073
74static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070075os_lstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"path", "dir_fd", NULL};
79 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030080 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
81 int dir_fd = DEFAULT_DIR_FD;
82
Victor Stinner3e1fad62017-01-17 01:29:01 +010083 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087 return_value = os_lstat_impl(module, &path, dir_fd);
88
89exit:
90 /* Cleanup for path */
91 path_cleanup(&path);
92
93 return return_value;
94}
95
96PyDoc_STRVAR(os_access__doc__,
97"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
98" follow_symlinks=True)\n"
99"--\n"
100"\n"
101"Use the real uid/gid to test for access to a path.\n"
102"\n"
103" path\n"
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700104" Path to be tested; can be string or bytes\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105" mode\n"
106" Operating-system mode bitfield. Can be F_OK to test existence,\n"
107" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
108" dir_fd\n"
109" If not None, it should be a file descriptor open to a directory,\n"
110" and path should be relative; path will then be relative to that\n"
111" directory.\n"
112" effective_ids\n"
113" If True, access will use the effective uid/gid instead of\n"
114" the real uid/gid.\n"
115" follow_symlinks\n"
116" If False, and the last element of the path is a symbolic link,\n"
117" access will examine the symbolic link itself instead of the file\n"
118" the link points to.\n"
119"\n"
120"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
121" on your platform. If they are unavailable, using them will raise a\n"
122" NotImplementedError.\n"
123"\n"
124"Note that most operations will use the effective uid/gid, therefore this\n"
125" routine can be used in a suid/sgid environment to test if the invoking user\n"
126" has the specified access to the path.");
127
128#define OS_ACCESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700129 {"access", (PyCFunction)os_access, METH_FASTCALL, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400133 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300134
135static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700136os_access(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300137{
138 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300139 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
140 static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700141 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300142 int mode;
143 int dir_fd = DEFAULT_DIR_FD;
144 int effective_ids = 0;
145 int follow_symlinks = 1;
146 int _return_value;
147
Victor Stinner3e1fad62017-01-17 01:29:01 +0100148 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300153 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156 return_value = PyBool_FromLong((long)_return_value);
157
158exit:
159 /* Cleanup for path */
160 path_cleanup(&path);
161
162 return return_value;
163}
164
165#if defined(HAVE_TTYNAME)
166
167PyDoc_STRVAR(os_ttyname__doc__,
168"ttyname($module, fd, /)\n"
169"--\n"
170"\n"
171"Return the name of the terminal device connected to \'fd\'.\n"
172"\n"
173" fd\n"
174" Integer file descriptor handle.");
175
176#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300177 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300178
179static char *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300180os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181
182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300183os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300184{
185 PyObject *return_value = NULL;
186 int fd;
187 char *_return_value;
188
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300189 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300190 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192 _return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300193 if (_return_value == NULL) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300195 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196 return_value = PyUnicode_DecodeFSDefault(_return_value);
197
198exit:
199 return return_value;
200}
201
202#endif /* defined(HAVE_TTYNAME) */
203
204#if defined(HAVE_CTERMID)
205
206PyDoc_STRVAR(os_ctermid__doc__,
207"ctermid($module, /)\n"
208"--\n"
209"\n"
210"Return the name of the controlling terminal for this process.");
211
212#define OS_CTERMID_METHODDEF \
213 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
214
215static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300216os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300217
218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300219os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220{
221 return os_ctermid_impl(module);
222}
223
224#endif /* defined(HAVE_CTERMID) */
225
226PyDoc_STRVAR(os_chdir__doc__,
227"chdir($module, /, path)\n"
228"--\n"
229"\n"
230"Change the current working directory to the specified path.\n"
231"\n"
232"path may always be specified as a string.\n"
233"On some platforms, path may also be specified as an open file descriptor.\n"
234" If this functionality is unavailable, using it raises an exception.");
235
236#define OS_CHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700237 {"chdir", (PyCFunction)os_chdir, METH_FASTCALL, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238
239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300240os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300241
242static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700243os_chdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300244{
245 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300246 static const char * const _keywords[] = {"path", NULL};
247 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300248 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
249
Victor Stinner3e1fad62017-01-17 01:29:01 +0100250 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300251 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300252 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300253 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300254 return_value = os_chdir_impl(module, &path);
255
256exit:
257 /* Cleanup for path */
258 path_cleanup(&path);
259
260 return return_value;
261}
262
263#if defined(HAVE_FCHDIR)
264
265PyDoc_STRVAR(os_fchdir__doc__,
266"fchdir($module, /, fd)\n"
267"--\n"
268"\n"
269"Change to the directory of the given file descriptor.\n"
270"\n"
271"fd must be opened on a directory, not a file.\n"
272"Equivalent to os.chdir(fd).");
273
274#define OS_FCHDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700275 {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300276
277static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300278os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279
280static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700281os_fchdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300282{
283 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300284 static const char * const _keywords[] = {"fd", NULL};
285 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300286 int fd;
287
Victor Stinner3e1fad62017-01-17 01:29:01 +0100288 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300289 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300292 return_value = os_fchdir_impl(module, fd);
293
294exit:
295 return return_value;
296}
297
298#endif /* defined(HAVE_FCHDIR) */
299
300PyDoc_STRVAR(os_chmod__doc__,
301"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
302"--\n"
303"\n"
304"Change the access permissions of a file.\n"
305"\n"
306" path\n"
307" Path to be modified. May always be specified as a str or bytes.\n"
308" On some platforms, path may also be specified as an open file descriptor.\n"
309" If this functionality is unavailable, using it raises an exception.\n"
310" mode\n"
311" Operating-system mode bitfield.\n"
312" dir_fd\n"
313" If not None, it should be a file descriptor open to a directory,\n"
314" and path should be relative; path will then be relative to that\n"
315" directory.\n"
316" follow_symlinks\n"
317" If False, and the last element of the path is a symbolic link,\n"
318" chmod will modify the symbolic link itself instead of the file\n"
319" the link points to.\n"
320"\n"
321"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
322" an open file descriptor.\n"
323"dir_fd and follow_symlinks may not be implemented on your platform.\n"
324" If they are unavailable, using them will raise a NotImplementedError.");
325
326#define OS_CHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700327 {"chmod", (PyCFunction)os_chmod, METH_FASTCALL, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300328
329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300330os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400331 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300332
333static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700334os_chmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300335{
336 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300337 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
338 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300339 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
340 int mode;
341 int dir_fd = DEFAULT_DIR_FD;
342 int follow_symlinks = 1;
343
Victor Stinner3e1fad62017-01-17 01:29:01 +0100344 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300345 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300347 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300348 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
349
350exit:
351 /* Cleanup for path */
352 path_cleanup(&path);
353
354 return return_value;
355}
356
357#if defined(HAVE_FCHMOD)
358
359PyDoc_STRVAR(os_fchmod__doc__,
360"fchmod($module, /, fd, mode)\n"
361"--\n"
362"\n"
363"Change the access permissions of the file given by file descriptor fd.\n"
364"\n"
365"Equivalent to os.chmod(fd, mode).");
366
367#define OS_FCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700368 {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369
370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300371os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300372
373static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700374os_fchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300375{
376 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300377 static const char * const _keywords[] = {"fd", "mode", NULL};
378 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 int fd;
380 int mode;
381
Victor Stinner3e1fad62017-01-17 01:29:01 +0100382 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300383 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300386 return_value = os_fchmod_impl(module, fd, mode);
387
388exit:
389 return return_value;
390}
391
392#endif /* defined(HAVE_FCHMOD) */
393
394#if defined(HAVE_LCHMOD)
395
396PyDoc_STRVAR(os_lchmod__doc__,
397"lchmod($module, /, path, mode)\n"
398"--\n"
399"\n"
400"Change the access permissions of a file, without following symbolic links.\n"
401"\n"
402"If path is a symlink, this affects the link itself rather than the target.\n"
403"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
404
405#define OS_LCHMOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700406 {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300407
408static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300409os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410
411static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700412os_lchmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300413{
414 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300415 static const char * const _keywords[] = {"path", "mode", NULL};
416 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300417 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
418 int mode;
419
Victor Stinner3e1fad62017-01-17 01:29:01 +0100420 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300421 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300424 return_value = os_lchmod_impl(module, &path, mode);
425
426exit:
427 /* Cleanup for path */
428 path_cleanup(&path);
429
430 return return_value;
431}
432
433#endif /* defined(HAVE_LCHMOD) */
434
435#if defined(HAVE_CHFLAGS)
436
437PyDoc_STRVAR(os_chflags__doc__,
438"chflags($module, /, path, flags, follow_symlinks=True)\n"
439"--\n"
440"\n"
441"Set file flags.\n"
442"\n"
443"If follow_symlinks is False, and the last element of the path is a symbolic\n"
444" link, chflags will change flags on the symbolic link itself instead of the\n"
445" file the link points to.\n"
446"follow_symlinks may not be implemented on your platform. If it is\n"
447"unavailable, using it will raise a NotImplementedError.");
448
449#define OS_CHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700450 {"chflags", (PyCFunction)os_chflags, METH_FASTCALL, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300451
452static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300453os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400454 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300455
456static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700457os_chflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300458{
459 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300460 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
461 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300462 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
463 unsigned long flags;
464 int follow_symlinks = 1;
465
Victor Stinner3e1fad62017-01-17 01:29:01 +0100466 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300467 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300468 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300469 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300470 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
471
472exit:
473 /* Cleanup for path */
474 path_cleanup(&path);
475
476 return return_value;
477}
478
479#endif /* defined(HAVE_CHFLAGS) */
480
481#if defined(HAVE_LCHFLAGS)
482
483PyDoc_STRVAR(os_lchflags__doc__,
484"lchflags($module, /, path, flags)\n"
485"--\n"
486"\n"
487"Set file flags.\n"
488"\n"
489"This function will not follow symbolic links.\n"
490"Equivalent to chflags(path, flags, follow_symlinks=False).");
491
492#define OS_LCHFLAGS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700493 {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300494
495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300496os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300497
498static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700499os_lchflags(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300500{
501 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300502 static const char * const _keywords[] = {"path", "flags", NULL};
503 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
505 unsigned long flags;
506
Victor Stinner3e1fad62017-01-17 01:29:01 +0100507 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300508 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300509 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300510 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511 return_value = os_lchflags_impl(module, &path, flags);
512
513exit:
514 /* Cleanup for path */
515 path_cleanup(&path);
516
517 return return_value;
518}
519
520#endif /* defined(HAVE_LCHFLAGS) */
521
522#if defined(HAVE_CHROOT)
523
524PyDoc_STRVAR(os_chroot__doc__,
525"chroot($module, /, path)\n"
526"--\n"
527"\n"
528"Change root directory to path.");
529
530#define OS_CHROOT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700531 {"chroot", (PyCFunction)os_chroot, METH_FASTCALL, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300532
533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300534os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535
536static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700537os_chroot(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300538{
539 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300540 static const char * const _keywords[] = {"path", NULL};
541 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300542 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
543
Victor Stinner3e1fad62017-01-17 01:29:01 +0100544 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300545 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300546 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300547 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 return_value = os_chroot_impl(module, &path);
549
550exit:
551 /* Cleanup for path */
552 path_cleanup(&path);
553
554 return return_value;
555}
556
557#endif /* defined(HAVE_CHROOT) */
558
559#if defined(HAVE_FSYNC)
560
561PyDoc_STRVAR(os_fsync__doc__,
562"fsync($module, /, fd)\n"
563"--\n"
564"\n"
565"Force write of fd to disk.");
566
567#define OS_FSYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700568 {"fsync", (PyCFunction)os_fsync, METH_FASTCALL, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300569
570static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300571os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300572
573static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700574os_fsync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300575{
576 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300577 static const char * const _keywords[] = {"fd", NULL};
578 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300579 int fd;
580
Victor Stinner3e1fad62017-01-17 01:29:01 +0100581 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300582 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585 return_value = os_fsync_impl(module, fd);
586
587exit:
588 return return_value;
589}
590
591#endif /* defined(HAVE_FSYNC) */
592
593#if defined(HAVE_SYNC)
594
595PyDoc_STRVAR(os_sync__doc__,
596"sync($module, /)\n"
597"--\n"
598"\n"
599"Force write of everything to disk.");
600
601#define OS_SYNC_METHODDEF \
602 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
603
604static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300605os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300606
607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300608os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300609{
610 return os_sync_impl(module);
611}
612
613#endif /* defined(HAVE_SYNC) */
614
615#if defined(HAVE_FDATASYNC)
616
617PyDoc_STRVAR(os_fdatasync__doc__,
618"fdatasync($module, /, fd)\n"
619"--\n"
620"\n"
621"Force write of fd to disk without forcing update of metadata.");
622
623#define OS_FDATASYNC_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700624 {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300625
626static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300627os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300628
629static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700630os_fdatasync(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631{
632 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300633 static const char * const _keywords[] = {"fd", NULL};
634 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300635 int fd;
636
Victor Stinner3e1fad62017-01-17 01:29:01 +0100637 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300638 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300639 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300640 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300641 return_value = os_fdatasync_impl(module, fd);
642
643exit:
644 return return_value;
645}
646
647#endif /* defined(HAVE_FDATASYNC) */
648
649#if defined(HAVE_CHOWN)
650
651PyDoc_STRVAR(os_chown__doc__,
652"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
653"--\n"
654"\n"
655"Change the owner and group id of path to the numeric uid and gid.\\\n"
656"\n"
657" path\n"
658" Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
659" dir_fd\n"
660" If not None, it should be a file descriptor open to a directory,\n"
661" and path should be relative; path will then be relative to that\n"
662" directory.\n"
663" follow_symlinks\n"
664" If False, and the last element of the path is a symbolic link,\n"
665" stat will examine the symbolic link itself instead of the file\n"
666" the link points to.\n"
667"\n"
668"path may always be specified as a string.\n"
669"On some platforms, path may also be specified as an open file descriptor.\n"
670" If this functionality is unavailable, using it raises an exception.\n"
671"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
672" and path should be relative; path will then be relative to that directory.\n"
673"If follow_symlinks is False, and the last element of the path is a symbolic\n"
674" link, chown will modify the symbolic link itself instead of the file the\n"
675" link points to.\n"
676"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
677" an open file descriptor.\n"
678"dir_fd and follow_symlinks may not be implemented on your platform.\n"
679" If they are unavailable, using them will raise a NotImplementedError.");
680
681#define OS_CHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700682 {"chown", (PyCFunction)os_chown, METH_FASTCALL, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300683
684static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300685os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400686 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300687
688static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700689os_chown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300690{
691 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300692 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
693 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300694 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
695 uid_t uid;
696 gid_t gid;
697 int dir_fd = DEFAULT_DIR_FD;
698 int follow_symlinks = 1;
699
Victor Stinner3e1fad62017-01-17 01:29:01 +0100700 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300701 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300703 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300704 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
705
706exit:
707 /* Cleanup for path */
708 path_cleanup(&path);
709
710 return return_value;
711}
712
713#endif /* defined(HAVE_CHOWN) */
714
715#if defined(HAVE_FCHOWN)
716
717PyDoc_STRVAR(os_fchown__doc__,
718"fchown($module, /, fd, uid, gid)\n"
719"--\n"
720"\n"
721"Change the owner and group id of the file specified by file descriptor.\n"
722"\n"
723"Equivalent to os.chown(fd, uid, gid).");
724
725#define OS_FCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700726 {"fchown", (PyCFunction)os_fchown, METH_FASTCALL, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300727
728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300729os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300730
731static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700732os_fchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300733{
734 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300735 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
736 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300737 int fd;
738 uid_t uid;
739 gid_t gid;
740
Victor Stinner3e1fad62017-01-17 01:29:01 +0100741 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300742 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300745 return_value = os_fchown_impl(module, fd, uid, gid);
746
747exit:
748 return return_value;
749}
750
751#endif /* defined(HAVE_FCHOWN) */
752
753#if defined(HAVE_LCHOWN)
754
755PyDoc_STRVAR(os_lchown__doc__,
756"lchown($module, /, path, uid, gid)\n"
757"--\n"
758"\n"
759"Change the owner and group id of path to the numeric uid and gid.\n"
760"\n"
761"This function will not follow symbolic links.\n"
762"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
763
764#define OS_LCHOWN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700765 {"lchown", (PyCFunction)os_lchown, METH_FASTCALL, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300766
767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300768os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300769
770static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700771os_lchown(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300772{
773 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300774 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
775 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300776 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
777 uid_t uid;
778 gid_t gid;
779
Victor Stinner3e1fad62017-01-17 01:29:01 +0100780 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300781 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300782 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300783 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300784 return_value = os_lchown_impl(module, &path, uid, gid);
785
786exit:
787 /* Cleanup for path */
788 path_cleanup(&path);
789
790 return return_value;
791}
792
793#endif /* defined(HAVE_LCHOWN) */
794
795PyDoc_STRVAR(os_getcwd__doc__,
796"getcwd($module, /)\n"
797"--\n"
798"\n"
799"Return a unicode string representing the current working directory.");
800
801#define OS_GETCWD_METHODDEF \
802 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
803
804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300805os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300806
807static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300808os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300809{
810 return os_getcwd_impl(module);
811}
812
813PyDoc_STRVAR(os_getcwdb__doc__,
814"getcwdb($module, /)\n"
815"--\n"
816"\n"
817"Return a bytes string representing the current working directory.");
818
819#define OS_GETCWDB_METHODDEF \
820 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
821
822static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300823os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300824
825static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300826os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300827{
828 return os_getcwdb_impl(module);
829}
830
831#if defined(HAVE_LINK)
832
833PyDoc_STRVAR(os_link__doc__,
834"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
835" follow_symlinks=True)\n"
836"--\n"
837"\n"
838"Create a hard link to a file.\n"
839"\n"
840"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
841" descriptor open to a directory, and the respective path string (src or dst)\n"
842" should be relative; the path will then be relative to that directory.\n"
843"If follow_symlinks is False, and the last element of src is a symbolic\n"
844" link, link will create a link to the symbolic link itself instead of the\n"
845" file the link points to.\n"
846"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
847" platform. If they are unavailable, using them will raise a\n"
848" NotImplementedError.");
849
850#define OS_LINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700851 {"link", (PyCFunction)os_link, METH_FASTCALL, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300852
853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300854os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400855 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300856
857static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700858os_link(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300859{
860 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300861 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
862 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300863 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
864 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
865 int src_dir_fd = DEFAULT_DIR_FD;
866 int dst_dir_fd = DEFAULT_DIR_FD;
867 int follow_symlinks = 1;
868
Victor Stinner3e1fad62017-01-17 01:29:01 +0100869 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300870 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300871 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300873 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
874
875exit:
876 /* Cleanup for src */
877 path_cleanup(&src);
878 /* Cleanup for dst */
879 path_cleanup(&dst);
880
881 return return_value;
882}
883
884#endif /* defined(HAVE_LINK) */
885
886PyDoc_STRVAR(os_listdir__doc__,
887"listdir($module, /, path=None)\n"
888"--\n"
889"\n"
890"Return a list containing the names of the files in the directory.\n"
891"\n"
892"path can be specified as either str or bytes. If path is bytes,\n"
893" the filenames returned will also be bytes; in all other circumstances\n"
894" the filenames returned will be str.\n"
895"If path is None, uses the path=\'.\'.\n"
896"On some platforms, path may also be specified as an open file descriptor;\\\n"
897" the file descriptor must refer to a directory.\n"
898" If this functionality is unavailable, using it raises NotImplementedError.\n"
899"\n"
900"The list is in arbitrary order. It does not include the special\n"
901"entries \'.\' and \'..\' even if they are present in the directory.");
902
903#define OS_LISTDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700904 {"listdir", (PyCFunction)os_listdir, METH_FASTCALL, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300905
906static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300907os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300908
909static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700910os_listdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300911{
912 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300913 static const char * const _keywords[] = {"path", NULL};
914 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300915 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
916
Victor Stinner3e1fad62017-01-17 01:29:01 +0100917 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300918 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300921 return_value = os_listdir_impl(module, &path);
922
923exit:
924 /* Cleanup for path */
925 path_cleanup(&path);
926
927 return return_value;
928}
929
930#if defined(MS_WINDOWS)
931
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300932PyDoc_STRVAR(os__getfullpathname__doc__,
933"_getfullpathname($module, path, /)\n"
934"--\n"
935"\n");
936
937#define OS__GETFULLPATHNAME_METHODDEF \
938 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
939
940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300941os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300942
943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300944os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300945{
946 PyObject *return_value = NULL;
947 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
948
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300949 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300951 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300952 return_value = os__getfullpathname_impl(module, &path);
953
954exit:
955 /* Cleanup for path */
956 path_cleanup(&path);
957
958 return return_value;
959}
960
961#endif /* defined(MS_WINDOWS) */
962
963#if defined(MS_WINDOWS)
964
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300965PyDoc_STRVAR(os__getfinalpathname__doc__,
966"_getfinalpathname($module, path, /)\n"
967"--\n"
968"\n"
969"A helper function for samepath on windows.");
970
971#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300972 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300973
974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300975os__getfinalpathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300976
977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300978os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979{
980 PyObject *return_value = NULL;
981 PyObject *path;
982
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300983 if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300986 return_value = os__getfinalpathname_impl(module, path);
987
988exit:
989 return return_value;
990}
991
992#endif /* defined(MS_WINDOWS) */
993
994#if defined(MS_WINDOWS)
995
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300996PyDoc_STRVAR(os__isdir__doc__,
997"_isdir($module, path, /)\n"
998"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200999"\n"
1000"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001001
1002#define OS__ISDIR_METHODDEF \
1003 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1004
1005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001006os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010{
1011 PyObject *return_value = NULL;
1012 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1013
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001014 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001016 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001017 return_value = os__isdir_impl(module, &path);
1018
1019exit:
1020 /* Cleanup for path */
1021 path_cleanup(&path);
1022
1023 return return_value;
1024}
1025
1026#endif /* defined(MS_WINDOWS) */
1027
1028#if defined(MS_WINDOWS)
1029
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001030PyDoc_STRVAR(os__getvolumepathname__doc__,
1031"_getvolumepathname($module, /, path)\n"
1032"--\n"
1033"\n"
1034"A helper function for ismount on Win32.");
1035
1036#define OS__GETVOLUMEPATHNAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001037 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038
1039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001040os__getvolumepathname_impl(PyObject *module, PyObject *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001043os__getvolumepathname(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044{
1045 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001046 static const char * const _keywords[] = {"path", NULL};
1047 static _PyArg_Parser _parser = {"U:_getvolumepathname", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001048 PyObject *path;
1049
Victor Stinner3e1fad62017-01-17 01:29:01 +01001050 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001051 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001053 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001054 return_value = os__getvolumepathname_impl(module, path);
1055
1056exit:
1057 return return_value;
1058}
1059
1060#endif /* defined(MS_WINDOWS) */
1061
1062PyDoc_STRVAR(os_mkdir__doc__,
1063"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1064"--\n"
1065"\n"
1066"Create a directory.\n"
1067"\n"
1068"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1069" and path should be relative; path will then be relative to that directory.\n"
1070"dir_fd may not be implemented on your platform.\n"
1071" If it is unavailable, using it will raise a NotImplementedError.\n"
1072"\n"
1073"The mode argument is ignored on Windows.");
1074
1075#define OS_MKDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001076 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001077
1078static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001079os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001080
1081static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001082os_mkdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083{
1084 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001085 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1086 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001087 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1088 int mode = 511;
1089 int dir_fd = DEFAULT_DIR_FD;
1090
Victor Stinner3e1fad62017-01-17 01:29:01 +01001091 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001094 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001095 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1096
1097exit:
1098 /* Cleanup for path */
1099 path_cleanup(&path);
1100
1101 return return_value;
1102}
1103
1104#if defined(HAVE_NICE)
1105
1106PyDoc_STRVAR(os_nice__doc__,
1107"nice($module, increment, /)\n"
1108"--\n"
1109"\n"
1110"Add increment to the priority of process and return the new priority.");
1111
1112#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001113 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001114
1115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001116os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001117
1118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001119os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120{
1121 PyObject *return_value = NULL;
1122 int increment;
1123
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001124 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001127 return_value = os_nice_impl(module, increment);
1128
1129exit:
1130 return return_value;
1131}
1132
1133#endif /* defined(HAVE_NICE) */
1134
1135#if defined(HAVE_GETPRIORITY)
1136
1137PyDoc_STRVAR(os_getpriority__doc__,
1138"getpriority($module, /, which, who)\n"
1139"--\n"
1140"\n"
1141"Return program scheduling priority.");
1142
1143#define OS_GETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001144 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001145
1146static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001147os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001148
1149static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001150os_getpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151{
1152 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001153 static const char * const _keywords[] = {"which", "who", NULL};
1154 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001155 int which;
1156 int who;
1157
Victor Stinner3e1fad62017-01-17 01:29:01 +01001158 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001159 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001162 return_value = os_getpriority_impl(module, which, who);
1163
1164exit:
1165 return return_value;
1166}
1167
1168#endif /* defined(HAVE_GETPRIORITY) */
1169
1170#if defined(HAVE_SETPRIORITY)
1171
1172PyDoc_STRVAR(os_setpriority__doc__,
1173"setpriority($module, /, which, who, priority)\n"
1174"--\n"
1175"\n"
1176"Set program scheduling priority.");
1177
1178#define OS_SETPRIORITY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001179 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001180
1181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001182os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001183
1184static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001185os_setpriority(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186{
1187 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001188 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1189 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001190 int which;
1191 int who;
1192 int priority;
1193
Victor Stinner3e1fad62017-01-17 01:29:01 +01001194 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001197 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001198 return_value = os_setpriority_impl(module, which, who, priority);
1199
1200exit:
1201 return return_value;
1202}
1203
1204#endif /* defined(HAVE_SETPRIORITY) */
1205
1206PyDoc_STRVAR(os_rename__doc__,
1207"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1208"--\n"
1209"\n"
1210"Rename a file or directory.\n"
1211"\n"
1212"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1213" descriptor open to a directory, and the respective path string (src or dst)\n"
1214" should be relative; the path will then be relative to that directory.\n"
1215"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1216" If they are unavailable, using them will raise a NotImplementedError.");
1217
1218#define OS_RENAME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001219 {"rename", (PyCFunction)os_rename, METH_FASTCALL, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001220
1221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001222os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001223 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001224
1225static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001226os_rename(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001227{
1228 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001229 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1230 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001231 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1232 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1233 int src_dir_fd = DEFAULT_DIR_FD;
1234 int dst_dir_fd = DEFAULT_DIR_FD;
1235
Victor Stinner3e1fad62017-01-17 01:29:01 +01001236 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001237 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001240 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1241
1242exit:
1243 /* Cleanup for src */
1244 path_cleanup(&src);
1245 /* Cleanup for dst */
1246 path_cleanup(&dst);
1247
1248 return return_value;
1249}
1250
1251PyDoc_STRVAR(os_replace__doc__,
1252"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1253"--\n"
1254"\n"
1255"Rename a file or directory, overwriting the destination.\n"
1256"\n"
1257"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1258" descriptor open to a directory, and the respective path string (src or dst)\n"
1259" should be relative; the path will then be relative to that directory.\n"
1260"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1261" If they are unavailable, using them will raise a NotImplementedError.\"");
1262
1263#define OS_REPLACE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001264 {"replace", (PyCFunction)os_replace, METH_FASTCALL, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001265
1266static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001267os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1268 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001269
1270static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001271os_replace(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001272{
1273 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001274 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1275 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001276 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1277 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1278 int src_dir_fd = DEFAULT_DIR_FD;
1279 int dst_dir_fd = DEFAULT_DIR_FD;
1280
Victor Stinner3e1fad62017-01-17 01:29:01 +01001281 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001282 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001285 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1286
1287exit:
1288 /* Cleanup for src */
1289 path_cleanup(&src);
1290 /* Cleanup for dst */
1291 path_cleanup(&dst);
1292
1293 return return_value;
1294}
1295
1296PyDoc_STRVAR(os_rmdir__doc__,
1297"rmdir($module, /, path, *, dir_fd=None)\n"
1298"--\n"
1299"\n"
1300"Remove a directory.\n"
1301"\n"
1302"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1303" and path should be relative; path will then be relative to that directory.\n"
1304"dir_fd may not be implemented on your platform.\n"
1305" If it is unavailable, using it will raise a NotImplementedError.");
1306
1307#define OS_RMDIR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001308 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001309
1310static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001311os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001312
1313static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001314os_rmdir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315{
1316 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001317 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1318 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001319 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1320 int dir_fd = DEFAULT_DIR_FD;
1321
Victor Stinner3e1fad62017-01-17 01:29:01 +01001322 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001323 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001324 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001325 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001326 return_value = os_rmdir_impl(module, &path, dir_fd);
1327
1328exit:
1329 /* Cleanup for path */
1330 path_cleanup(&path);
1331
1332 return return_value;
1333}
1334
1335#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1336
1337PyDoc_STRVAR(os_system__doc__,
1338"system($module, /, command)\n"
1339"--\n"
1340"\n"
1341"Execute the command in a subshell.");
1342
1343#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001344 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001345
1346static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001347os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348
1349static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001350os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351{
1352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001353 static const char * const _keywords[] = {"command", NULL};
1354 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001355 Py_UNICODE *command;
1356 long _return_value;
1357
Victor Stinner3e1fad62017-01-17 01:29:01 +01001358 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001359 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001362 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 return_value = PyLong_FromLong(_return_value);
1367
1368exit:
1369 return return_value;
1370}
1371
1372#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1373
1374#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1375
1376PyDoc_STRVAR(os_system__doc__,
1377"system($module, /, command)\n"
1378"--\n"
1379"\n"
1380"Execute the command in a subshell.");
1381
1382#define OS_SYSTEM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001383 {"system", (PyCFunction)os_system, METH_FASTCALL, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001384
1385static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001386os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001387
1388static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001389os_system(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390{
1391 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001392 static const char * const _keywords[] = {"command", NULL};
1393 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001394 PyObject *command = NULL;
1395 long _return_value;
1396
Victor Stinner3e1fad62017-01-17 01:29:01 +01001397 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001398 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001399 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001400 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001401 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001402 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 return_value = PyLong_FromLong(_return_value);
1406
1407exit:
1408 /* Cleanup for command */
1409 Py_XDECREF(command);
1410
1411 return return_value;
1412}
1413
1414#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1415
1416PyDoc_STRVAR(os_umask__doc__,
1417"umask($module, mask, /)\n"
1418"--\n"
1419"\n"
1420"Set the current numeric umask and return the previous umask.");
1421
1422#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001423 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001424
1425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001426os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001427
1428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001429os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430{
1431 PyObject *return_value = NULL;
1432 int mask;
1433
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001437 return_value = os_umask_impl(module, mask);
1438
1439exit:
1440 return return_value;
1441}
1442
1443PyDoc_STRVAR(os_unlink__doc__,
1444"unlink($module, /, path, *, dir_fd=None)\n"
1445"--\n"
1446"\n"
1447"Remove a file (same as remove()).\n"
1448"\n"
1449"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1450" and path should be relative; path will then be relative to that directory.\n"
1451"dir_fd may not be implemented on your platform.\n"
1452" If it is unavailable, using it will raise a NotImplementedError.");
1453
1454#define OS_UNLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001455 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001456
1457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001458os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001459
1460static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001461os_unlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462{
1463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001464 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1465 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001466 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1467 int dir_fd = DEFAULT_DIR_FD;
1468
Victor Stinner3e1fad62017-01-17 01:29:01 +01001469 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001473 return_value = os_unlink_impl(module, &path, dir_fd);
1474
1475exit:
1476 /* Cleanup for path */
1477 path_cleanup(&path);
1478
1479 return return_value;
1480}
1481
1482PyDoc_STRVAR(os_remove__doc__,
1483"remove($module, /, path, *, dir_fd=None)\n"
1484"--\n"
1485"\n"
1486"Remove a file (same as unlink()).\n"
1487"\n"
1488"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1489" and path should be relative; path will then be relative to that directory.\n"
1490"dir_fd may not be implemented on your platform.\n"
1491" If it is unavailable, using it will raise a NotImplementedError.");
1492
1493#define OS_REMOVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001494 {"remove", (PyCFunction)os_remove, METH_FASTCALL, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001495
1496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001497os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001498
1499static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001500os_remove(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501{
1502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001503 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1504 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001505 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1506 int dir_fd = DEFAULT_DIR_FD;
1507
Victor Stinner3e1fad62017-01-17 01:29:01 +01001508 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001512 return_value = os_remove_impl(module, &path, dir_fd);
1513
1514exit:
1515 /* Cleanup for path */
1516 path_cleanup(&path);
1517
1518 return return_value;
1519}
1520
1521#if defined(HAVE_UNAME)
1522
1523PyDoc_STRVAR(os_uname__doc__,
1524"uname($module, /)\n"
1525"--\n"
1526"\n"
1527"Return an object identifying the current operating system.\n"
1528"\n"
1529"The object behaves like a named tuple with the following fields:\n"
1530" (sysname, nodename, release, version, machine)");
1531
1532#define OS_UNAME_METHODDEF \
1533 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1534
1535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001536os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001537
1538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001539os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001540{
1541 return os_uname_impl(module);
1542}
1543
1544#endif /* defined(HAVE_UNAME) */
1545
1546PyDoc_STRVAR(os_utime__doc__,
1547"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1548" follow_symlinks=True)\n"
1549"--\n"
1550"\n"
1551"Set the access and modified time of path.\n"
1552"\n"
1553"path may always be specified as a string.\n"
1554"On some platforms, path may also be specified as an open file descriptor.\n"
1555" If this functionality is unavailable, using it raises an exception.\n"
1556"\n"
1557"If times is not None, it must be a tuple (atime, mtime);\n"
1558" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001559"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001560" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1561" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001562"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001563"Specifying tuples for both times and ns is an error.\n"
1564"\n"
1565"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1566" and path should be relative; path will then be relative to that directory.\n"
1567"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1568" link, utime will modify the symbolic link itself instead of the file the\n"
1569" link points to.\n"
1570"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1571" as an open file descriptor.\n"
1572"dir_fd and follow_symlinks may not be available on your platform.\n"
1573" If they are unavailable, using them will raise a NotImplementedError.");
1574
1575#define OS_UTIME_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001576 {"utime", (PyCFunction)os_utime, METH_FASTCALL, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001577
1578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001579os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1580 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581
1582static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001583os_utime(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001584{
1585 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001586 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1587 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001588 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1589 PyObject *times = NULL;
1590 PyObject *ns = NULL;
1591 int dir_fd = DEFAULT_DIR_FD;
1592 int follow_symlinks = 1;
1593
Victor Stinner3e1fad62017-01-17 01:29:01 +01001594 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001597 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001598 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1599
1600exit:
1601 /* Cleanup for path */
1602 path_cleanup(&path);
1603
1604 return return_value;
1605}
1606
1607PyDoc_STRVAR(os__exit__doc__,
1608"_exit($module, /, status)\n"
1609"--\n"
1610"\n"
1611"Exit to the system with specified status, without normal exit processing.");
1612
1613#define OS__EXIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001614 {"_exit", (PyCFunction)os__exit, METH_FASTCALL, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001615
1616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001617os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001618
1619static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001620os__exit(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621{
1622 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001623 static const char * const _keywords[] = {"status", NULL};
1624 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001625 int status;
1626
Victor Stinner3e1fad62017-01-17 01:29:01 +01001627 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001630 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 return_value = os__exit_impl(module, status);
1632
1633exit:
1634 return return_value;
1635}
1636
1637#if defined(HAVE_EXECV)
1638
1639PyDoc_STRVAR(os_execv__doc__,
1640"execv($module, path, argv, /)\n"
1641"--\n"
1642"\n"
1643"Execute an executable path with arguments, replacing current process.\n"
1644"\n"
1645" path\n"
1646" Path of executable file.\n"
1647" argv\n"
1648" Tuple or list of strings.");
1649
1650#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001651 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001652
1653static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001654os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001655
1656static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001657os_execv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658{
1659 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001660 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661 PyObject *argv;
1662
Victor Stinner259f0e42017-01-17 01:35:17 +01001663 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
Steve Dowercc16be82016-09-08 10:35:16 -07001664 path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001665 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001666 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001667
1668 if (!_PyArg_NoStackKeywords("execv", kwnames)) {
1669 goto exit;
1670 }
Steve Dowercc16be82016-09-08 10:35:16 -07001671 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001672
1673exit:
1674 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001675 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001676
1677 return return_value;
1678}
1679
1680#endif /* defined(HAVE_EXECV) */
1681
1682#if defined(HAVE_EXECV)
1683
1684PyDoc_STRVAR(os_execve__doc__,
1685"execve($module, /, path, argv, env)\n"
1686"--\n"
1687"\n"
1688"Execute an executable path with arguments, replacing current process.\n"
1689"\n"
1690" path\n"
1691" Path of executable file.\n"
1692" argv\n"
1693" Tuple or list of strings.\n"
1694" env\n"
1695" Dictionary of strings mapping to strings.");
1696
1697#define OS_EXECVE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001698 {"execve", (PyCFunction)os_execve, METH_FASTCALL, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001699
1700static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001701os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001702
1703static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001704os_execve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001705{
1706 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001707 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1708 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001709 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1710 PyObject *argv;
1711 PyObject *env;
1712
Victor Stinner3e1fad62017-01-17 01:29:01 +01001713 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001714 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001715 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001716 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001717 return_value = os_execve_impl(module, &path, argv, env);
1718
1719exit:
1720 /* Cleanup for path */
1721 path_cleanup(&path);
1722
1723 return return_value;
1724}
1725
1726#endif /* defined(HAVE_EXECV) */
1727
Steve Dowercc16be82016-09-08 10:35:16 -07001728#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001729
1730PyDoc_STRVAR(os_spawnv__doc__,
1731"spawnv($module, mode, path, argv, /)\n"
1732"--\n"
1733"\n"
1734"Execute the program specified by path in a new process.\n"
1735"\n"
1736" mode\n"
1737" Mode of process creation.\n"
1738" path\n"
1739" Path of executable file.\n"
1740" argv\n"
1741" Tuple or list of strings.");
1742
1743#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001744 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001745
1746static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001747os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001748
1749static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001750os_spawnv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001751{
1752 PyObject *return_value = NULL;
1753 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001754 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001755 PyObject *argv;
1756
Victor Stinner259f0e42017-01-17 01:35:17 +01001757 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
Steve Dowercc16be82016-09-08 10:35:16 -07001758 &mode, path_converter, &path, &argv)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001759 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001760 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001761
1762 if (!_PyArg_NoStackKeywords("spawnv", kwnames)) {
1763 goto exit;
1764 }
Steve Dowercc16be82016-09-08 10:35:16 -07001765 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001766
1767exit:
1768 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001769 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001770
1771 return return_value;
1772}
1773
Steve Dowercc16be82016-09-08 10:35:16 -07001774#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001775
Steve Dowercc16be82016-09-08 10:35:16 -07001776#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001777
1778PyDoc_STRVAR(os_spawnve__doc__,
1779"spawnve($module, mode, path, argv, env, /)\n"
1780"--\n"
1781"\n"
1782"Execute the program specified by path in a new process.\n"
1783"\n"
1784" mode\n"
1785" Mode of process creation.\n"
1786" path\n"
1787" Path of executable file.\n"
1788" argv\n"
1789" Tuple or list of strings.\n"
1790" env\n"
1791" Dictionary of strings mapping to strings.");
1792
1793#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001794 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001795
1796static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001797os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001798 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001799
1800static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001801os_spawnve(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001802{
1803 PyObject *return_value = NULL;
1804 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001805 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001806 PyObject *argv;
1807 PyObject *env;
1808
Victor Stinner259f0e42017-01-17 01:35:17 +01001809 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
Steve Dowercc16be82016-09-08 10:35:16 -07001810 &mode, path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001811 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001812 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001813
1814 if (!_PyArg_NoStackKeywords("spawnve", kwnames)) {
1815 goto exit;
1816 }
Steve Dowercc16be82016-09-08 10:35:16 -07001817 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001818
1819exit:
1820 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001821 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001822
1823 return return_value;
1824}
1825
Steve Dowercc16be82016-09-08 10:35:16 -07001826#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001827
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001828#if defined(HAVE_FORK)
1829
1830PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001831"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1832" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001833"--\n"
1834"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001835"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001836"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001837" before\n"
1838" A callable to be called in the parent before the fork() syscall.\n"
1839" after_in_child\n"
1840" A callable to be called in the child after fork().\n"
1841" after_in_parent\n"
1842" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001843"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001844"\'before\' callbacks are called in reverse order.\n"
1845"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001846
1847#define OS_REGISTER_AT_FORK_METHODDEF \
1848 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL, os_register_at_fork__doc__},
1849
1850static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001851os_register_at_fork_impl(PyObject *module, PyObject *before,
1852 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001853
1854static PyObject *
1855os_register_at_fork(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
1856{
1857 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001858 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1859 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1860 PyObject *before = NULL;
1861 PyObject *after_in_child = NULL;
1862 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001863
1864 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001865 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001866 goto exit;
1867 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001868 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001869
1870exit:
1871 return return_value;
1872}
1873
1874#endif /* defined(HAVE_FORK) */
1875
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001876#if defined(HAVE_FORK1)
1877
1878PyDoc_STRVAR(os_fork1__doc__,
1879"fork1($module, /)\n"
1880"--\n"
1881"\n"
1882"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1883"\n"
1884"Return 0 to child process and PID of child to parent process.");
1885
1886#define OS_FORK1_METHODDEF \
1887 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1888
1889static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001890os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001891
1892static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001893os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001894{
1895 return os_fork1_impl(module);
1896}
1897
1898#endif /* defined(HAVE_FORK1) */
1899
1900#if defined(HAVE_FORK)
1901
1902PyDoc_STRVAR(os_fork__doc__,
1903"fork($module, /)\n"
1904"--\n"
1905"\n"
1906"Fork a child process.\n"
1907"\n"
1908"Return 0 to child process and PID of child to parent process.");
1909
1910#define OS_FORK_METHODDEF \
1911 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1912
1913static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001914os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001915
1916static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001917os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001918{
1919 return os_fork_impl(module);
1920}
1921
1922#endif /* defined(HAVE_FORK) */
1923
1924#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1925
1926PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1927"sched_get_priority_max($module, /, policy)\n"
1928"--\n"
1929"\n"
1930"Get the maximum scheduling priority for policy.");
1931
1932#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001933 {"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 +03001934
1935static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001936os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001937
1938static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001939os_sched_get_priority_max(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001940{
1941 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001942 static const char * const _keywords[] = {"policy", NULL};
1943 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001944 int policy;
1945
Victor Stinner3e1fad62017-01-17 01:29:01 +01001946 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001947 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001948 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001949 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001950 return_value = os_sched_get_priority_max_impl(module, policy);
1951
1952exit:
1953 return return_value;
1954}
1955
1956#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1957
1958#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1959
1960PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1961"sched_get_priority_min($module, /, policy)\n"
1962"--\n"
1963"\n"
1964"Get the minimum scheduling priority for policy.");
1965
1966#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07001967 {"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 +03001968
1969static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001970os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001971
1972static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07001973os_sched_get_priority_min(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001974{
1975 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001976 static const char * const _keywords[] = {"policy", NULL};
1977 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001978 int policy;
1979
Victor Stinner3e1fad62017-01-17 01:29:01 +01001980 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001981 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001982 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001983 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001984 return_value = os_sched_get_priority_min_impl(module, policy);
1985
1986exit:
1987 return return_value;
1988}
1989
1990#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1991
1992#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
1993
1994PyDoc_STRVAR(os_sched_getscheduler__doc__,
1995"sched_getscheduler($module, pid, /)\n"
1996"--\n"
1997"\n"
1998"Get the scheduling policy for the process identifiedy by pid.\n"
1999"\n"
2000"Passing 0 for pid returns the scheduling policy for the calling process.");
2001
2002#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002003 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002004
2005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002006os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002007
2008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002009os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002010{
2011 PyObject *return_value = NULL;
2012 pid_t pid;
2013
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002014 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002016 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002017 return_value = os_sched_getscheduler_impl(module, pid);
2018
2019exit:
2020 return return_value;
2021}
2022
2023#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2024
2025#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2026
2027PyDoc_STRVAR(os_sched_param__doc__,
2028"sched_param(sched_priority)\n"
2029"--\n"
2030"\n"
2031"Current has only one field: sched_priority\");\n"
2032"\n"
2033" sched_priority\n"
2034" A scheduling parameter.");
2035
2036static PyObject *
2037os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2038
2039static PyObject *
2040os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2041{
2042 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002043 static const char * const _keywords[] = {"sched_priority", NULL};
2044 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002045 PyObject *sched_priority;
2046
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002047 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002048 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002049 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002050 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002051 return_value = os_sched_param_impl(type, sched_priority);
2052
2053exit:
2054 return return_value;
2055}
2056
2057#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2058
2059#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2060
2061PyDoc_STRVAR(os_sched_setscheduler__doc__,
2062"sched_setscheduler($module, pid, policy, param, /)\n"
2063"--\n"
2064"\n"
2065"Set the scheduling policy for the process identified by pid.\n"
2066"\n"
2067"If pid is 0, the calling process is changed.\n"
2068"param is an instance of sched_param.");
2069
2070#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002071 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002072
2073static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002074os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002075 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002076
2077static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002078os_sched_setscheduler(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002079{
2080 PyObject *return_value = NULL;
2081 pid_t pid;
2082 int policy;
2083 struct sched_param param;
2084
Victor Stinner259f0e42017-01-17 01:35:17 +01002085 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002086 &pid, &policy, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002087 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002088 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002089
2090 if (!_PyArg_NoStackKeywords("sched_setscheduler", kwnames)) {
2091 goto exit;
2092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002093 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2094
2095exit:
2096 return return_value;
2097}
2098
2099#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2100
2101#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2102
2103PyDoc_STRVAR(os_sched_getparam__doc__,
2104"sched_getparam($module, pid, /)\n"
2105"--\n"
2106"\n"
2107"Returns scheduling parameters for the process identified by pid.\n"
2108"\n"
2109"If pid is 0, returns parameters for the calling process.\n"
2110"Return value is an instance of sched_param.");
2111
2112#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002113 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002114
2115static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002116os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002117
2118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002119os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002120{
2121 PyObject *return_value = NULL;
2122 pid_t pid;
2123
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002124 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002125 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002127 return_value = os_sched_getparam_impl(module, pid);
2128
2129exit:
2130 return return_value;
2131}
2132
2133#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2134
2135#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2136
2137PyDoc_STRVAR(os_sched_setparam__doc__,
2138"sched_setparam($module, pid, param, /)\n"
2139"--\n"
2140"\n"
2141"Set scheduling parameters for the process identified by pid.\n"
2142"\n"
2143"If pid is 0, sets parameters for the calling process.\n"
2144"param should be an instance of sched_param.");
2145
2146#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002147 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002148
2149static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002150os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002151 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002152
2153static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002154os_sched_setparam(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002155{
2156 PyObject *return_value = NULL;
2157 pid_t pid;
2158 struct sched_param param;
2159
Victor Stinner259f0e42017-01-17 01:35:17 +01002160 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002161 &pid, convert_sched_param, &param)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002162 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002163 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002164
2165 if (!_PyArg_NoStackKeywords("sched_setparam", kwnames)) {
2166 goto exit;
2167 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002168 return_value = os_sched_setparam_impl(module, pid, &param);
2169
2170exit:
2171 return return_value;
2172}
2173
2174#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2175
2176#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2177
2178PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2179"sched_rr_get_interval($module, pid, /)\n"
2180"--\n"
2181"\n"
2182"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2183"\n"
2184"Value returned is a float.");
2185
2186#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002187 {"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 +03002188
2189static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002190os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002191
2192static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002193os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002194{
2195 PyObject *return_value = NULL;
2196 pid_t pid;
2197 double _return_value;
2198
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002199 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002201 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002202 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002203 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002204 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002205 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002206 return_value = PyFloat_FromDouble(_return_value);
2207
2208exit:
2209 return return_value;
2210}
2211
2212#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2213
2214#if defined(HAVE_SCHED_H)
2215
2216PyDoc_STRVAR(os_sched_yield__doc__,
2217"sched_yield($module, /)\n"
2218"--\n"
2219"\n"
2220"Voluntarily relinquish the CPU.");
2221
2222#define OS_SCHED_YIELD_METHODDEF \
2223 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2224
2225static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002226os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002227
2228static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002229os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002230{
2231 return os_sched_yield_impl(module);
2232}
2233
2234#endif /* defined(HAVE_SCHED_H) */
2235
2236#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2237
2238PyDoc_STRVAR(os_sched_setaffinity__doc__,
2239"sched_setaffinity($module, pid, mask, /)\n"
2240"--\n"
2241"\n"
2242"Set the CPU affinity of the process identified by pid to mask.\n"
2243"\n"
2244"mask should be an iterable of integers identifying CPUs.");
2245
2246#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002247 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002248
2249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002250os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002251
2252static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002253os_sched_setaffinity(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002254{
2255 PyObject *return_value = NULL;
2256 pid_t pid;
2257 PyObject *mask;
2258
Victor Stinner259f0e42017-01-17 01:35:17 +01002259 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002260 &pid, &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002261 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002262 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002263
2264 if (!_PyArg_NoStackKeywords("sched_setaffinity", kwnames)) {
2265 goto exit;
2266 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002267 return_value = os_sched_setaffinity_impl(module, pid, mask);
2268
2269exit:
2270 return return_value;
2271}
2272
2273#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2274
2275#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2276
2277PyDoc_STRVAR(os_sched_getaffinity__doc__,
2278"sched_getaffinity($module, pid, /)\n"
2279"--\n"
2280"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002281"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002282"\n"
2283"The affinity is returned as a set of CPU identifiers.");
2284
2285#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002286 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002287
2288static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002289os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002290
2291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002292os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002293{
2294 PyObject *return_value = NULL;
2295 pid_t pid;
2296
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002297 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002298 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002299 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002300 return_value = os_sched_getaffinity_impl(module, pid);
2301
2302exit:
2303 return return_value;
2304}
2305
2306#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2307
2308#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2309
2310PyDoc_STRVAR(os_openpty__doc__,
2311"openpty($module, /)\n"
2312"--\n"
2313"\n"
2314"Open a pseudo-terminal.\n"
2315"\n"
2316"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2317"for both the master and slave ends.");
2318
2319#define OS_OPENPTY_METHODDEF \
2320 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2321
2322static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002323os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002324
2325static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002326os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002327{
2328 return os_openpty_impl(module);
2329}
2330
2331#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2332
2333#if defined(HAVE_FORKPTY)
2334
2335PyDoc_STRVAR(os_forkpty__doc__,
2336"forkpty($module, /)\n"
2337"--\n"
2338"\n"
2339"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2340"\n"
2341"Returns a tuple of (pid, master_fd).\n"
2342"Like fork(), return pid of 0 to the child process,\n"
2343"and pid of child to the parent process.\n"
2344"To both, return fd of newly opened pseudo-terminal.");
2345
2346#define OS_FORKPTY_METHODDEF \
2347 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2348
2349static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002350os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002351
2352static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002353os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002354{
2355 return os_forkpty_impl(module);
2356}
2357
2358#endif /* defined(HAVE_FORKPTY) */
2359
2360#if defined(HAVE_GETEGID)
2361
2362PyDoc_STRVAR(os_getegid__doc__,
2363"getegid($module, /)\n"
2364"--\n"
2365"\n"
2366"Return the current process\'s effective group id.");
2367
2368#define OS_GETEGID_METHODDEF \
2369 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2370
2371static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002372os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002373
2374static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002375os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002376{
2377 return os_getegid_impl(module);
2378}
2379
2380#endif /* defined(HAVE_GETEGID) */
2381
2382#if defined(HAVE_GETEUID)
2383
2384PyDoc_STRVAR(os_geteuid__doc__,
2385"geteuid($module, /)\n"
2386"--\n"
2387"\n"
2388"Return the current process\'s effective user id.");
2389
2390#define OS_GETEUID_METHODDEF \
2391 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2392
2393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002394os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002395
2396static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002397os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002398{
2399 return os_geteuid_impl(module);
2400}
2401
2402#endif /* defined(HAVE_GETEUID) */
2403
2404#if defined(HAVE_GETGID)
2405
2406PyDoc_STRVAR(os_getgid__doc__,
2407"getgid($module, /)\n"
2408"--\n"
2409"\n"
2410"Return the current process\'s group id.");
2411
2412#define OS_GETGID_METHODDEF \
2413 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2414
2415static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002416os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002417
2418static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002419os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002420{
2421 return os_getgid_impl(module);
2422}
2423
2424#endif /* defined(HAVE_GETGID) */
2425
Berker Peksag39404992016-09-15 20:45:16 +03002426#if defined(HAVE_GETPID)
2427
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002428PyDoc_STRVAR(os_getpid__doc__,
2429"getpid($module, /)\n"
2430"--\n"
2431"\n"
2432"Return the current process id.");
2433
2434#define OS_GETPID_METHODDEF \
2435 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2436
2437static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002438os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002439
2440static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002441os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002442{
2443 return os_getpid_impl(module);
2444}
2445
Berker Peksag39404992016-09-15 20:45:16 +03002446#endif /* defined(HAVE_GETPID) */
2447
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002448#if defined(HAVE_GETGROUPS)
2449
2450PyDoc_STRVAR(os_getgroups__doc__,
2451"getgroups($module, /)\n"
2452"--\n"
2453"\n"
2454"Return list of supplemental group IDs for the process.");
2455
2456#define OS_GETGROUPS_METHODDEF \
2457 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2458
2459static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002460os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002461
2462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002463os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002464{
2465 return os_getgroups_impl(module);
2466}
2467
2468#endif /* defined(HAVE_GETGROUPS) */
2469
2470#if defined(HAVE_GETPGID)
2471
2472PyDoc_STRVAR(os_getpgid__doc__,
2473"getpgid($module, /, pid)\n"
2474"--\n"
2475"\n"
2476"Call the system call getpgid(), and return the result.");
2477
2478#define OS_GETPGID_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002479 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002480
2481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002482os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002483
2484static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002485os_getpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002486{
2487 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002488 static const char * const _keywords[] = {"pid", NULL};
2489 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002490 pid_t pid;
2491
Victor Stinner3e1fad62017-01-17 01:29:01 +01002492 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002493 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002494 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002496 return_value = os_getpgid_impl(module, pid);
2497
2498exit:
2499 return return_value;
2500}
2501
2502#endif /* defined(HAVE_GETPGID) */
2503
2504#if defined(HAVE_GETPGRP)
2505
2506PyDoc_STRVAR(os_getpgrp__doc__,
2507"getpgrp($module, /)\n"
2508"--\n"
2509"\n"
2510"Return the current process group id.");
2511
2512#define OS_GETPGRP_METHODDEF \
2513 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2514
2515static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002516os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002517
2518static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002519os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002520{
2521 return os_getpgrp_impl(module);
2522}
2523
2524#endif /* defined(HAVE_GETPGRP) */
2525
2526#if defined(HAVE_SETPGRP)
2527
2528PyDoc_STRVAR(os_setpgrp__doc__,
2529"setpgrp($module, /)\n"
2530"--\n"
2531"\n"
2532"Make the current process the leader of its process group.");
2533
2534#define OS_SETPGRP_METHODDEF \
2535 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2536
2537static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002538os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002539
2540static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002541os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002542{
2543 return os_setpgrp_impl(module);
2544}
2545
2546#endif /* defined(HAVE_SETPGRP) */
2547
2548#if defined(HAVE_GETPPID)
2549
2550PyDoc_STRVAR(os_getppid__doc__,
2551"getppid($module, /)\n"
2552"--\n"
2553"\n"
2554"Return the parent\'s process id.\n"
2555"\n"
2556"If the parent process has already exited, Windows machines will still\n"
2557"return its id; others systems will return the id of the \'init\' process (1).");
2558
2559#define OS_GETPPID_METHODDEF \
2560 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2561
2562static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002563os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002564
2565static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002566os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002567{
2568 return os_getppid_impl(module);
2569}
2570
2571#endif /* defined(HAVE_GETPPID) */
2572
2573#if defined(HAVE_GETLOGIN)
2574
2575PyDoc_STRVAR(os_getlogin__doc__,
2576"getlogin($module, /)\n"
2577"--\n"
2578"\n"
2579"Return the actual login name.");
2580
2581#define OS_GETLOGIN_METHODDEF \
2582 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2583
2584static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002585os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002586
2587static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002588os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002589{
2590 return os_getlogin_impl(module);
2591}
2592
2593#endif /* defined(HAVE_GETLOGIN) */
2594
2595#if defined(HAVE_GETUID)
2596
2597PyDoc_STRVAR(os_getuid__doc__,
2598"getuid($module, /)\n"
2599"--\n"
2600"\n"
2601"Return the current process\'s user id.");
2602
2603#define OS_GETUID_METHODDEF \
2604 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2605
2606static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002607os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002608
2609static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002610os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002611{
2612 return os_getuid_impl(module);
2613}
2614
2615#endif /* defined(HAVE_GETUID) */
2616
2617#if defined(HAVE_KILL)
2618
2619PyDoc_STRVAR(os_kill__doc__,
2620"kill($module, pid, signal, /)\n"
2621"--\n"
2622"\n"
2623"Kill a process with a signal.");
2624
2625#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002626 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002627
2628static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002629os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002630
2631static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002632os_kill(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002633{
2634 PyObject *return_value = NULL;
2635 pid_t pid;
2636 Py_ssize_t signal;
2637
Victor Stinner259f0e42017-01-17 01:35:17 +01002638 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002639 &pid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002640 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002641 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002642
2643 if (!_PyArg_NoStackKeywords("kill", kwnames)) {
2644 goto exit;
2645 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002646 return_value = os_kill_impl(module, pid, signal);
2647
2648exit:
2649 return return_value;
2650}
2651
2652#endif /* defined(HAVE_KILL) */
2653
2654#if defined(HAVE_KILLPG)
2655
2656PyDoc_STRVAR(os_killpg__doc__,
2657"killpg($module, pgid, signal, /)\n"
2658"--\n"
2659"\n"
2660"Kill a process group with a signal.");
2661
2662#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002663 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002664
2665static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002666os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002667
2668static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002669os_killpg(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002670{
2671 PyObject *return_value = NULL;
2672 pid_t pgid;
2673 int signal;
2674
Victor Stinner259f0e42017-01-17 01:35:17 +01002675 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002676 &pgid, &signal)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002677 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002678 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002679
2680 if (!_PyArg_NoStackKeywords("killpg", kwnames)) {
2681 goto exit;
2682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002683 return_value = os_killpg_impl(module, pgid, signal);
2684
2685exit:
2686 return return_value;
2687}
2688
2689#endif /* defined(HAVE_KILLPG) */
2690
2691#if defined(HAVE_PLOCK)
2692
2693PyDoc_STRVAR(os_plock__doc__,
2694"plock($module, op, /)\n"
2695"--\n"
2696"\n"
2697"Lock program segments into memory.\");");
2698
2699#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002700 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002701
2702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002703os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002704
2705static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002706os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002707{
2708 PyObject *return_value = NULL;
2709 int op;
2710
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002711 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002712 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002713 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002714 return_value = os_plock_impl(module, op);
2715
2716exit:
2717 return return_value;
2718}
2719
2720#endif /* defined(HAVE_PLOCK) */
2721
2722#if defined(HAVE_SETUID)
2723
2724PyDoc_STRVAR(os_setuid__doc__,
2725"setuid($module, uid, /)\n"
2726"--\n"
2727"\n"
2728"Set the current process\'s user id.");
2729
2730#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002731 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002732
2733static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002734os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002735
2736static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002737os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002738{
2739 PyObject *return_value = NULL;
2740 uid_t uid;
2741
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002742 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002743 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002744 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002745 return_value = os_setuid_impl(module, uid);
2746
2747exit:
2748 return return_value;
2749}
2750
2751#endif /* defined(HAVE_SETUID) */
2752
2753#if defined(HAVE_SETEUID)
2754
2755PyDoc_STRVAR(os_seteuid__doc__,
2756"seteuid($module, euid, /)\n"
2757"--\n"
2758"\n"
2759"Set the current process\'s effective user id.");
2760
2761#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002762 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002763
2764static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002765os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002766
2767static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002768os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002769{
2770 PyObject *return_value = NULL;
2771 uid_t euid;
2772
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002773 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002774 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002775 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002776 return_value = os_seteuid_impl(module, euid);
2777
2778exit:
2779 return return_value;
2780}
2781
2782#endif /* defined(HAVE_SETEUID) */
2783
2784#if defined(HAVE_SETEGID)
2785
2786PyDoc_STRVAR(os_setegid__doc__,
2787"setegid($module, egid, /)\n"
2788"--\n"
2789"\n"
2790"Set the current process\'s effective group id.");
2791
2792#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002793 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002794
2795static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002796os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002797
2798static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002799os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002800{
2801 PyObject *return_value = NULL;
2802 gid_t egid;
2803
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002804 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002805 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002806 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002807 return_value = os_setegid_impl(module, egid);
2808
2809exit:
2810 return return_value;
2811}
2812
2813#endif /* defined(HAVE_SETEGID) */
2814
2815#if defined(HAVE_SETREUID)
2816
2817PyDoc_STRVAR(os_setreuid__doc__,
2818"setreuid($module, ruid, euid, /)\n"
2819"--\n"
2820"\n"
2821"Set the current process\'s real and effective user ids.");
2822
2823#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002824 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002825
2826static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002827os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002828
2829static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002830os_setreuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002831{
2832 PyObject *return_value = NULL;
2833 uid_t ruid;
2834 uid_t euid;
2835
Victor Stinner259f0e42017-01-17 01:35:17 +01002836 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002837 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002838 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002839 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002840
2841 if (!_PyArg_NoStackKeywords("setreuid", kwnames)) {
2842 goto exit;
2843 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002844 return_value = os_setreuid_impl(module, ruid, euid);
2845
2846exit:
2847 return return_value;
2848}
2849
2850#endif /* defined(HAVE_SETREUID) */
2851
2852#if defined(HAVE_SETREGID)
2853
2854PyDoc_STRVAR(os_setregid__doc__,
2855"setregid($module, rgid, egid, /)\n"
2856"--\n"
2857"\n"
2858"Set the current process\'s real and effective group ids.");
2859
2860#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002861 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002862
2863static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002864os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002865
2866static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01002867os_setregid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002868{
2869 PyObject *return_value = NULL;
2870 gid_t rgid;
2871 gid_t egid;
2872
Victor Stinner259f0e42017-01-17 01:35:17 +01002873 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002874 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002875 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002876 }
Victor Stinner259f0e42017-01-17 01:35:17 +01002877
2878 if (!_PyArg_NoStackKeywords("setregid", kwnames)) {
2879 goto exit;
2880 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002881 return_value = os_setregid_impl(module, rgid, egid);
2882
2883exit:
2884 return return_value;
2885}
2886
2887#endif /* defined(HAVE_SETREGID) */
2888
2889#if defined(HAVE_SETGID)
2890
2891PyDoc_STRVAR(os_setgid__doc__,
2892"setgid($module, gid, /)\n"
2893"--\n"
2894"\n"
2895"Set the current process\'s group id.");
2896
2897#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002898 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002899
2900static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002901os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002902
2903static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002904os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002905{
2906 PyObject *return_value = NULL;
2907 gid_t gid;
2908
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002909 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002910 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002911 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912 return_value = os_setgid_impl(module, gid);
2913
2914exit:
2915 return return_value;
2916}
2917
2918#endif /* defined(HAVE_SETGID) */
2919
2920#if defined(HAVE_SETGROUPS)
2921
2922PyDoc_STRVAR(os_setgroups__doc__,
2923"setgroups($module, groups, /)\n"
2924"--\n"
2925"\n"
2926"Set the groups of the current process to list.");
2927
2928#define OS_SETGROUPS_METHODDEF \
2929 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2930
2931#endif /* defined(HAVE_SETGROUPS) */
2932
2933#if defined(HAVE_WAIT3)
2934
2935PyDoc_STRVAR(os_wait3__doc__,
2936"wait3($module, /, options)\n"
2937"--\n"
2938"\n"
2939"Wait for completion of a child process.\n"
2940"\n"
2941"Returns a tuple of information about the child process:\n"
2942" (pid, status, rusage)");
2943
2944#define OS_WAIT3_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002945 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002946
2947static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002948os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002949
2950static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002951os_wait3(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002952{
2953 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002954 static const char * const _keywords[] = {"options", NULL};
2955 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002956 int options;
2957
Victor Stinner3e1fad62017-01-17 01:29:01 +01002958 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002959 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002960 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002961 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002962 return_value = os_wait3_impl(module, options);
2963
2964exit:
2965 return return_value;
2966}
2967
2968#endif /* defined(HAVE_WAIT3) */
2969
2970#if defined(HAVE_WAIT4)
2971
2972PyDoc_STRVAR(os_wait4__doc__,
2973"wait4($module, /, pid, options)\n"
2974"--\n"
2975"\n"
2976"Wait for completion of a specific child process.\n"
2977"\n"
2978"Returns a tuple of information about the child process:\n"
2979" (pid, status, rusage)");
2980
2981#define OS_WAIT4_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07002982 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002983
2984static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002985os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002986
2987static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07002988os_wait4(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002989{
2990 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002991 static const char * const _keywords[] = {"pid", "options", NULL};
2992 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002993 pid_t pid;
2994 int options;
2995
Victor Stinner3e1fad62017-01-17 01:29:01 +01002996 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002997 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002998 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002999 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003000 return_value = os_wait4_impl(module, pid, options);
3001
3002exit:
3003 return return_value;
3004}
3005
3006#endif /* defined(HAVE_WAIT4) */
3007
3008#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3009
3010PyDoc_STRVAR(os_waitid__doc__,
3011"waitid($module, idtype, id, options, /)\n"
3012"--\n"
3013"\n"
3014"Returns the result of waiting for a process or processes.\n"
3015"\n"
3016" idtype\n"
3017" Must be one of be P_PID, P_PGID or P_ALL.\n"
3018" id\n"
3019" The id to wait on.\n"
3020" options\n"
3021" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3022" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3023"\n"
3024"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3025"no children in a waitable state.");
3026
3027#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003028 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003029
3030static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003031os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003032
3033static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003034os_waitid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003035{
3036 PyObject *return_value = NULL;
3037 idtype_t idtype;
3038 id_t id;
3039 int options;
3040
Victor Stinner259f0e42017-01-17 01:35:17 +01003041 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003042 &idtype, &id, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003043 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003044 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003045
3046 if (!_PyArg_NoStackKeywords("waitid", kwnames)) {
3047 goto exit;
3048 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003049 return_value = os_waitid_impl(module, idtype, id, options);
3050
3051exit:
3052 return return_value;
3053}
3054
3055#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3056
3057#if defined(HAVE_WAITPID)
3058
3059PyDoc_STRVAR(os_waitpid__doc__,
3060"waitpid($module, pid, options, /)\n"
3061"--\n"
3062"\n"
3063"Wait for completion of a given child process.\n"
3064"\n"
3065"Returns a tuple of information regarding the child process:\n"
3066" (pid, status)\n"
3067"\n"
3068"The options argument is ignored on Windows.");
3069
3070#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003071 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003072
3073static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003074os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003075
3076static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003077os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003078{
3079 PyObject *return_value = NULL;
3080 pid_t pid;
3081 int options;
3082
Victor Stinner259f0e42017-01-17 01:35:17 +01003083 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003084 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003086 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003087
3088 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3089 goto exit;
3090 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003091 return_value = os_waitpid_impl(module, pid, options);
3092
3093exit:
3094 return return_value;
3095}
3096
3097#endif /* defined(HAVE_WAITPID) */
3098
3099#if defined(HAVE_CWAIT)
3100
3101PyDoc_STRVAR(os_waitpid__doc__,
3102"waitpid($module, pid, options, /)\n"
3103"--\n"
3104"\n"
3105"Wait for completion of a given process.\n"
3106"\n"
3107"Returns a tuple of information regarding the process:\n"
3108" (pid, status << 8)\n"
3109"\n"
3110"The options argument is ignored on Windows.");
3111
3112#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003113 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003114
3115static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003116os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003117
3118static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003119os_waitpid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003120{
3121 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003122 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123 int options;
3124
Victor Stinner259f0e42017-01-17 01:35:17 +01003125 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003126 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003127 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003128 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003129
3130 if (!_PyArg_NoStackKeywords("waitpid", kwnames)) {
3131 goto exit;
3132 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003133 return_value = os_waitpid_impl(module, pid, options);
3134
3135exit:
3136 return return_value;
3137}
3138
3139#endif /* defined(HAVE_CWAIT) */
3140
3141#if defined(HAVE_WAIT)
3142
3143PyDoc_STRVAR(os_wait__doc__,
3144"wait($module, /)\n"
3145"--\n"
3146"\n"
3147"Wait for completion of a child process.\n"
3148"\n"
3149"Returns a tuple of information about the child process:\n"
3150" (pid, status)");
3151
3152#define OS_WAIT_METHODDEF \
3153 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3154
3155static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003156os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003157
3158static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003159os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003160{
3161 return os_wait_impl(module);
3162}
3163
3164#endif /* defined(HAVE_WAIT) */
3165
3166#if defined(HAVE_SYMLINK)
3167
3168PyDoc_STRVAR(os_symlink__doc__,
3169"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3170"--\n"
3171"\n"
3172"Create a symbolic link pointing to src named dst.\n"
3173"\n"
3174"target_is_directory is required on Windows if the target is to be\n"
3175" interpreted as a directory. (On Windows, symlink requires\n"
3176" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3177" target_is_directory is ignored on non-Windows platforms.\n"
3178"\n"
3179"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3180" and path should be relative; path will then be relative to that directory.\n"
3181"dir_fd may not be implemented on your platform.\n"
3182" If it is unavailable, using it will raise a NotImplementedError.");
3183
3184#define OS_SYMLINK_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003185 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003186
3187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003188os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003189 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003190
3191static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003192os_symlink(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003193{
3194 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003195 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3196 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003197 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3198 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3199 int target_is_directory = 0;
3200 int dir_fd = DEFAULT_DIR_FD;
3201
Victor Stinner3e1fad62017-01-17 01:29:01 +01003202 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003203 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003204 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003205 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003206 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3207
3208exit:
3209 /* Cleanup for src */
3210 path_cleanup(&src);
3211 /* Cleanup for dst */
3212 path_cleanup(&dst);
3213
3214 return return_value;
3215}
3216
3217#endif /* defined(HAVE_SYMLINK) */
3218
3219#if defined(HAVE_TIMES)
3220
3221PyDoc_STRVAR(os_times__doc__,
3222"times($module, /)\n"
3223"--\n"
3224"\n"
3225"Return a collection containing process timing information.\n"
3226"\n"
3227"The object returned behaves like a named tuple with these fields:\n"
3228" (utime, stime, cutime, cstime, elapsed_time)\n"
3229"All fields are floating point numbers.");
3230
3231#define OS_TIMES_METHODDEF \
3232 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3233
3234static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003235os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003236
3237static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003238os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003239{
3240 return os_times_impl(module);
3241}
3242
3243#endif /* defined(HAVE_TIMES) */
3244
3245#if defined(HAVE_GETSID)
3246
3247PyDoc_STRVAR(os_getsid__doc__,
3248"getsid($module, pid, /)\n"
3249"--\n"
3250"\n"
3251"Call the system call getsid(pid) and return the result.");
3252
3253#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003254 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003255
3256static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003257os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003258
3259static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003260os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003261{
3262 PyObject *return_value = NULL;
3263 pid_t pid;
3264
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003265 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003266 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003267 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003268 return_value = os_getsid_impl(module, pid);
3269
3270exit:
3271 return return_value;
3272}
3273
3274#endif /* defined(HAVE_GETSID) */
3275
3276#if defined(HAVE_SETSID)
3277
3278PyDoc_STRVAR(os_setsid__doc__,
3279"setsid($module, /)\n"
3280"--\n"
3281"\n"
3282"Call the system call setsid().");
3283
3284#define OS_SETSID_METHODDEF \
3285 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3286
3287static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003288os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003289
3290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003291os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003292{
3293 return os_setsid_impl(module);
3294}
3295
3296#endif /* defined(HAVE_SETSID) */
3297
3298#if defined(HAVE_SETPGID)
3299
3300PyDoc_STRVAR(os_setpgid__doc__,
3301"setpgid($module, pid, pgrp, /)\n"
3302"--\n"
3303"\n"
3304"Call the system call setpgid(pid, pgrp).");
3305
3306#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003307 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003308
3309static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003310os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003311
3312static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003313os_setpgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003314{
3315 PyObject *return_value = NULL;
3316 pid_t pid;
3317 pid_t pgrp;
3318
Victor Stinner259f0e42017-01-17 01:35:17 +01003319 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003320 &pid, &pgrp)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003321 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003322 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003323
3324 if (!_PyArg_NoStackKeywords("setpgid", kwnames)) {
3325 goto exit;
3326 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003327 return_value = os_setpgid_impl(module, pid, pgrp);
3328
3329exit:
3330 return return_value;
3331}
3332
3333#endif /* defined(HAVE_SETPGID) */
3334
3335#if defined(HAVE_TCGETPGRP)
3336
3337PyDoc_STRVAR(os_tcgetpgrp__doc__,
3338"tcgetpgrp($module, fd, /)\n"
3339"--\n"
3340"\n"
3341"Return the process group associated with the terminal specified by fd.");
3342
3343#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003344 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003345
3346static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003347os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003348
3349static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003350os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003351{
3352 PyObject *return_value = NULL;
3353 int fd;
3354
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003355 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003356 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003357 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003358 return_value = os_tcgetpgrp_impl(module, fd);
3359
3360exit:
3361 return return_value;
3362}
3363
3364#endif /* defined(HAVE_TCGETPGRP) */
3365
3366#if defined(HAVE_TCSETPGRP)
3367
3368PyDoc_STRVAR(os_tcsetpgrp__doc__,
3369"tcsetpgrp($module, fd, pgid, /)\n"
3370"--\n"
3371"\n"
3372"Set the process group associated with the terminal specified by fd.");
3373
3374#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003375 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003376
3377static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003378os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003379
3380static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003381os_tcsetpgrp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003382{
3383 PyObject *return_value = NULL;
3384 int fd;
3385 pid_t pgid;
3386
Victor Stinner259f0e42017-01-17 01:35:17 +01003387 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003388 &fd, &pgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003389 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003390 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003391
3392 if (!_PyArg_NoStackKeywords("tcsetpgrp", kwnames)) {
3393 goto exit;
3394 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003395 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3396
3397exit:
3398 return return_value;
3399}
3400
3401#endif /* defined(HAVE_TCSETPGRP) */
3402
3403PyDoc_STRVAR(os_open__doc__,
3404"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3405"--\n"
3406"\n"
3407"Open a file for low level IO. Returns a file descriptor (integer).\n"
3408"\n"
3409"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3410" and path should be relative; path will then be relative to that directory.\n"
3411"dir_fd may not be implemented on your platform.\n"
3412" If it is unavailable, using it will raise a NotImplementedError.");
3413
3414#define OS_OPEN_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003415 {"open", (PyCFunction)os_open, METH_FASTCALL, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003416
3417static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003418os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003419
3420static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003421os_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003422{
3423 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003424 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3425 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003426 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3427 int flags;
3428 int mode = 511;
3429 int dir_fd = DEFAULT_DIR_FD;
3430 int _return_value;
3431
Victor Stinner3e1fad62017-01-17 01:29:01 +01003432 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003433 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003435 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003436 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003437 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003438 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003440 return_value = PyLong_FromLong((long)_return_value);
3441
3442exit:
3443 /* Cleanup for path */
3444 path_cleanup(&path);
3445
3446 return return_value;
3447}
3448
3449PyDoc_STRVAR(os_close__doc__,
3450"close($module, /, fd)\n"
3451"--\n"
3452"\n"
3453"Close a file descriptor.");
3454
3455#define OS_CLOSE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003456 {"close", (PyCFunction)os_close, METH_FASTCALL, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003457
3458static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003459os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003460
3461static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003462os_close(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003463{
3464 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003465 static const char * const _keywords[] = {"fd", NULL};
3466 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003467 int fd;
3468
Victor Stinner3e1fad62017-01-17 01:29:01 +01003469 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003470 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003473 return_value = os_close_impl(module, fd);
3474
3475exit:
3476 return return_value;
3477}
3478
3479PyDoc_STRVAR(os_closerange__doc__,
3480"closerange($module, fd_low, fd_high, /)\n"
3481"--\n"
3482"\n"
3483"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3484
3485#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003486 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003487
3488static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003489os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003490
3491static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003492os_closerange(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003493{
3494 PyObject *return_value = NULL;
3495 int fd_low;
3496 int fd_high;
3497
Victor Stinner259f0e42017-01-17 01:35:17 +01003498 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003499 &fd_low, &fd_high)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003500 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003501 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003502
3503 if (!_PyArg_NoStackKeywords("closerange", kwnames)) {
3504 goto exit;
3505 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003506 return_value = os_closerange_impl(module, fd_low, fd_high);
3507
3508exit:
3509 return return_value;
3510}
3511
3512PyDoc_STRVAR(os_dup__doc__,
3513"dup($module, fd, /)\n"
3514"--\n"
3515"\n"
3516"Return a duplicate of a file descriptor.");
3517
3518#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003519 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003520
3521static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003522os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003523
3524static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003525os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003526{
3527 PyObject *return_value = NULL;
3528 int fd;
3529 int _return_value;
3530
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003531 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003532 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003533 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003534 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003535 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003536 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003537 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003538 return_value = PyLong_FromLong((long)_return_value);
3539
3540exit:
3541 return return_value;
3542}
3543
3544PyDoc_STRVAR(os_dup2__doc__,
3545"dup2($module, /, fd, fd2, inheritable=True)\n"
3546"--\n"
3547"\n"
3548"Duplicate file descriptor.");
3549
3550#define OS_DUP2_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003551 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003552
3553static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003554os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003555
3556static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003557os_dup2(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003558{
3559 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003560 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3561 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003562 int fd;
3563 int fd2;
3564 int inheritable = 1;
3565
Victor Stinner3e1fad62017-01-17 01:29:01 +01003566 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003567 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003568 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003569 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003570 return_value = os_dup2_impl(module, fd, fd2, inheritable);
3571
3572exit:
3573 return return_value;
3574}
3575
3576#if defined(HAVE_LOCKF)
3577
3578PyDoc_STRVAR(os_lockf__doc__,
3579"lockf($module, fd, command, length, /)\n"
3580"--\n"
3581"\n"
3582"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3583"\n"
3584" fd\n"
3585" An open file descriptor.\n"
3586" command\n"
3587" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3588" length\n"
3589" The number of bytes to lock, starting at the current position.");
3590
3591#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003592 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003593
3594static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003595os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003596
3597static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003598os_lockf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003599{
3600 PyObject *return_value = NULL;
3601 int fd;
3602 int command;
3603 Py_off_t length;
3604
Victor Stinner259f0e42017-01-17 01:35:17 +01003605 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003606 &fd, &command, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003607 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003608 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003609
3610 if (!_PyArg_NoStackKeywords("lockf", kwnames)) {
3611 goto exit;
3612 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003613 return_value = os_lockf_impl(module, fd, command, length);
3614
3615exit:
3616 return return_value;
3617}
3618
3619#endif /* defined(HAVE_LOCKF) */
3620
3621PyDoc_STRVAR(os_lseek__doc__,
3622"lseek($module, fd, position, how, /)\n"
3623"--\n"
3624"\n"
3625"Set the position of a file descriptor. Return the new position.\n"
3626"\n"
3627"Return the new cursor position in number of bytes\n"
3628"relative to the beginning of the file.");
3629
3630#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003631 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003632
3633static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003634os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003635
3636static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003637os_lseek(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003638{
3639 PyObject *return_value = NULL;
3640 int fd;
3641 Py_off_t position;
3642 int how;
3643 Py_off_t _return_value;
3644
Victor Stinner259f0e42017-01-17 01:35:17 +01003645 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003646 &fd, Py_off_t_converter, &position, &how)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003647 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003648 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003649
3650 if (!_PyArg_NoStackKeywords("lseek", kwnames)) {
3651 goto exit;
3652 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003653 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003654 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003655 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003656 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003657 return_value = PyLong_FromPy_off_t(_return_value);
3658
3659exit:
3660 return return_value;
3661}
3662
3663PyDoc_STRVAR(os_read__doc__,
3664"read($module, fd, length, /)\n"
3665"--\n"
3666"\n"
3667"Read from a file descriptor. Returns a bytes object.");
3668
3669#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003670 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003671
3672static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003673os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003674
3675static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003676os_read(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003677{
3678 PyObject *return_value = NULL;
3679 int fd;
3680 Py_ssize_t length;
3681
Victor Stinner259f0e42017-01-17 01:35:17 +01003682 if (!_PyArg_ParseStack(args, nargs, "in:read",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003683 &fd, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003684 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003685 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003686
3687 if (!_PyArg_NoStackKeywords("read", kwnames)) {
3688 goto exit;
3689 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003690 return_value = os_read_impl(module, fd, length);
3691
3692exit:
3693 return return_value;
3694}
3695
3696#if defined(HAVE_READV)
3697
3698PyDoc_STRVAR(os_readv__doc__,
3699"readv($module, fd, buffers, /)\n"
3700"--\n"
3701"\n"
3702"Read from a file descriptor fd into an iterable of buffers.\n"
3703"\n"
3704"The buffers should be mutable buffers accepting bytes.\n"
3705"readv will transfer data into each buffer until it is full\n"
3706"and then move on to the next buffer in the sequence to hold\n"
3707"the rest of the data.\n"
3708"\n"
3709"readv returns the total number of bytes read,\n"
3710"which may be less than the total capacity of all the buffers.");
3711
3712#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003713 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003714
3715static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003716os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717
3718static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003719os_readv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003720{
3721 PyObject *return_value = NULL;
3722 int fd;
3723 PyObject *buffers;
3724 Py_ssize_t _return_value;
3725
Victor Stinner259f0e42017-01-17 01:35:17 +01003726 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003727 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003728 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003729 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003730
3731 if (!_PyArg_NoStackKeywords("readv", kwnames)) {
3732 goto exit;
3733 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003734 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003735 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003736 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003737 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738 return_value = PyLong_FromSsize_t(_return_value);
3739
3740exit:
3741 return return_value;
3742}
3743
3744#endif /* defined(HAVE_READV) */
3745
3746#if defined(HAVE_PREAD)
3747
3748PyDoc_STRVAR(os_pread__doc__,
3749"pread($module, fd, length, offset, /)\n"
3750"--\n"
3751"\n"
3752"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3753"\n"
3754"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3755"the beginning of the file. The file offset remains unchanged.");
3756
3757#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003758 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003759
3760static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003761os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003762
3763static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003764os_pread(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003765{
3766 PyObject *return_value = NULL;
3767 int fd;
3768 int length;
3769 Py_off_t offset;
3770
Victor Stinner259f0e42017-01-17 01:35:17 +01003771 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003772 &fd, &length, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003773 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003774 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003775
3776 if (!_PyArg_NoStackKeywords("pread", kwnames)) {
3777 goto exit;
3778 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003779 return_value = os_pread_impl(module, fd, length, offset);
3780
3781exit:
3782 return return_value;
3783}
3784
3785#endif /* defined(HAVE_PREAD) */
3786
3787PyDoc_STRVAR(os_write__doc__,
3788"write($module, fd, data, /)\n"
3789"--\n"
3790"\n"
3791"Write a bytes object to a file descriptor.");
3792
3793#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003794 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003795
3796static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003797os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003798
3799static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003800os_write(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003801{
3802 PyObject *return_value = NULL;
3803 int fd;
3804 Py_buffer data = {NULL, NULL};
3805 Py_ssize_t _return_value;
3806
Victor Stinner259f0e42017-01-17 01:35:17 +01003807 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003808 &fd, &data)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003809 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003810 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003811
3812 if (!_PyArg_NoStackKeywords("write", kwnames)) {
3813 goto exit;
3814 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003815 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003816 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003817 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003818 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003819 return_value = PyLong_FromSsize_t(_return_value);
3820
3821exit:
3822 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003823 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003824 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003825 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003826
3827 return return_value;
3828}
3829
3830PyDoc_STRVAR(os_fstat__doc__,
3831"fstat($module, /, fd)\n"
3832"--\n"
3833"\n"
3834"Perform a stat system call on the given file descriptor.\n"
3835"\n"
3836"Like stat(), but for an open file descriptor.\n"
3837"Equivalent to os.stat(fd).");
3838
3839#define OS_FSTAT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07003840 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003841
3842static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003843os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003844
3845static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07003846os_fstat(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003847{
3848 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003849 static const char * const _keywords[] = {"fd", NULL};
3850 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003851 int fd;
3852
Victor Stinner3e1fad62017-01-17 01:29:01 +01003853 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003854 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003855 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003856 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003857 return_value = os_fstat_impl(module, fd);
3858
3859exit:
3860 return return_value;
3861}
3862
3863PyDoc_STRVAR(os_isatty__doc__,
3864"isatty($module, fd, /)\n"
3865"--\n"
3866"\n"
3867"Return True if the fd is connected to a terminal.\n"
3868"\n"
3869"Return True if the file descriptor is an open file descriptor\n"
3870"connected to the slave end of a terminal.");
3871
3872#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003873 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003874
3875static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003876os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003877
3878static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003879os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003880{
3881 PyObject *return_value = NULL;
3882 int fd;
3883 int _return_value;
3884
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003885 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003886 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003887 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003888 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003889 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003890 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003891 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003892 return_value = PyBool_FromLong((long)_return_value);
3893
3894exit:
3895 return return_value;
3896}
3897
3898#if defined(HAVE_PIPE)
3899
3900PyDoc_STRVAR(os_pipe__doc__,
3901"pipe($module, /)\n"
3902"--\n"
3903"\n"
3904"Create a pipe.\n"
3905"\n"
3906"Returns a tuple of two file descriptors:\n"
3907" (read_fd, write_fd)");
3908
3909#define OS_PIPE_METHODDEF \
3910 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3911
3912static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003913os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003914
3915static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003916os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003917{
3918 return os_pipe_impl(module);
3919}
3920
3921#endif /* defined(HAVE_PIPE) */
3922
3923#if defined(HAVE_PIPE2)
3924
3925PyDoc_STRVAR(os_pipe2__doc__,
3926"pipe2($module, flags, /)\n"
3927"--\n"
3928"\n"
3929"Create a pipe with flags set atomically.\n"
3930"\n"
3931"Returns a tuple of two file descriptors:\n"
3932" (read_fd, write_fd)\n"
3933"\n"
3934"flags can be constructed by ORing together one or more of these values:\n"
3935"O_NONBLOCK, O_CLOEXEC.");
3936
3937#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003938 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003939
3940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003941os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003942
3943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003944os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003945{
3946 PyObject *return_value = NULL;
3947 int flags;
3948
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003949 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003950 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003951 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003952 return_value = os_pipe2_impl(module, flags);
3953
3954exit:
3955 return return_value;
3956}
3957
3958#endif /* defined(HAVE_PIPE2) */
3959
3960#if defined(HAVE_WRITEV)
3961
3962PyDoc_STRVAR(os_writev__doc__,
3963"writev($module, fd, buffers, /)\n"
3964"--\n"
3965"\n"
3966"Iterate over buffers, and write the contents of each to a file descriptor.\n"
3967"\n"
3968"Returns the total number of bytes written.\n"
3969"buffers must be a sequence of bytes-like objects.");
3970
3971#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003972 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003973
3974static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003975os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976
3977static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01003978os_writev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003979{
3980 PyObject *return_value = NULL;
3981 int fd;
3982 PyObject *buffers;
3983 Py_ssize_t _return_value;
3984
Victor Stinner259f0e42017-01-17 01:35:17 +01003985 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003986 &fd, &buffers)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003987 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003988 }
Victor Stinner259f0e42017-01-17 01:35:17 +01003989
3990 if (!_PyArg_NoStackKeywords("writev", kwnames)) {
3991 goto exit;
3992 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003993 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003994 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003995 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003996 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003997 return_value = PyLong_FromSsize_t(_return_value);
3998
3999exit:
4000 return return_value;
4001}
4002
4003#endif /* defined(HAVE_WRITEV) */
4004
4005#if defined(HAVE_PWRITE)
4006
4007PyDoc_STRVAR(os_pwrite__doc__,
4008"pwrite($module, fd, buffer, offset, /)\n"
4009"--\n"
4010"\n"
4011"Write bytes to a file descriptor starting at a particular offset.\n"
4012"\n"
4013"Write buffer to fd, starting at offset bytes from the beginning of\n"
4014"the file. Returns the number of bytes writte. Does not change the\n"
4015"current file offset.");
4016
4017#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004018 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004019
4020static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004021os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004022
4023static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004024os_pwrite(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004025{
4026 PyObject *return_value = NULL;
4027 int fd;
4028 Py_buffer buffer = {NULL, NULL};
4029 Py_off_t offset;
4030 Py_ssize_t _return_value;
4031
Victor Stinner259f0e42017-01-17 01:35:17 +01004032 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004033 &fd, &buffer, Py_off_t_converter, &offset)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004034 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004035 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004036
4037 if (!_PyArg_NoStackKeywords("pwrite", kwnames)) {
4038 goto exit;
4039 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004040 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004041 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004042 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004043 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004044 return_value = PyLong_FromSsize_t(_return_value);
4045
4046exit:
4047 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004048 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004049 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004050 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004051
4052 return return_value;
4053}
4054
4055#endif /* defined(HAVE_PWRITE) */
4056
4057#if defined(HAVE_MKFIFO)
4058
4059PyDoc_STRVAR(os_mkfifo__doc__,
4060"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4061"--\n"
4062"\n"
4063"Create a \"fifo\" (a POSIX named pipe).\n"
4064"\n"
4065"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4066" and path should be relative; path will then be relative to that directory.\n"
4067"dir_fd may not be implemented on your platform.\n"
4068" If it is unavailable, using it will raise a NotImplementedError.");
4069
4070#define OS_MKFIFO_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004071 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004072
4073static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004074os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004075
4076static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004077os_mkfifo(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004078{
4079 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004080 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4081 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004082 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4083 int mode = 438;
4084 int dir_fd = DEFAULT_DIR_FD;
4085
Victor Stinner3e1fad62017-01-17 01:29:01 +01004086 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004087 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004088 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004089 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004090 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4091
4092exit:
4093 /* Cleanup for path */
4094 path_cleanup(&path);
4095
4096 return return_value;
4097}
4098
4099#endif /* defined(HAVE_MKFIFO) */
4100
4101#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4102
4103PyDoc_STRVAR(os_mknod__doc__,
4104"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4105"--\n"
4106"\n"
4107"Create a node in the file system.\n"
4108"\n"
4109"Create a node in the file system (file, device special file or named pipe)\n"
4110"at path. mode specifies both the permissions to use and the\n"
4111"type of node to be created, being combined (bitwise OR) with one of\n"
4112"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4113"device defines the newly created device special file (probably using\n"
4114"os.makedev()). Otherwise device is ignored.\n"
4115"\n"
4116"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4117" and path should be relative; path will then be relative to that directory.\n"
4118"dir_fd may not be implemented on your platform.\n"
4119" If it is unavailable, using it will raise a NotImplementedError.");
4120
4121#define OS_MKNOD_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004122 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004123
4124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004125os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004126 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004127
4128static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004129os_mknod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004130{
4131 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004132 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4133 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004134 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4135 int mode = 384;
4136 dev_t device = 0;
4137 int dir_fd = DEFAULT_DIR_FD;
4138
Victor Stinner3e1fad62017-01-17 01:29:01 +01004139 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004140 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004141 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004142 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004143 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4144
4145exit:
4146 /* Cleanup for path */
4147 path_cleanup(&path);
4148
4149 return return_value;
4150}
4151
4152#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4153
4154#if defined(HAVE_DEVICE_MACROS)
4155
4156PyDoc_STRVAR(os_major__doc__,
4157"major($module, device, /)\n"
4158"--\n"
4159"\n"
4160"Extracts a device major number from a raw device number.");
4161
4162#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004163 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004164
4165static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004166os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004167
4168static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004169os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004170{
4171 PyObject *return_value = NULL;
4172 dev_t device;
4173 unsigned int _return_value;
4174
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004175 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004176 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004177 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004178 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004179 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004180 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004181 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004182 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4183
4184exit:
4185 return return_value;
4186}
4187
4188#endif /* defined(HAVE_DEVICE_MACROS) */
4189
4190#if defined(HAVE_DEVICE_MACROS)
4191
4192PyDoc_STRVAR(os_minor__doc__,
4193"minor($module, device, /)\n"
4194"--\n"
4195"\n"
4196"Extracts a device minor number from a raw device number.");
4197
4198#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004199 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004200
4201static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004202os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004203
4204static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004205os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004206{
4207 PyObject *return_value = NULL;
4208 dev_t device;
4209 unsigned int _return_value;
4210
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004211 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004212 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004213 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004214 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004215 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004216 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004217 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004218 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4219
4220exit:
4221 return return_value;
4222}
4223
4224#endif /* defined(HAVE_DEVICE_MACROS) */
4225
4226#if defined(HAVE_DEVICE_MACROS)
4227
4228PyDoc_STRVAR(os_makedev__doc__,
4229"makedev($module, major, minor, /)\n"
4230"--\n"
4231"\n"
4232"Composes a raw device number from the major and minor device numbers.");
4233
4234#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004235 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004236
4237static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004238os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004239
4240static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004241os_makedev(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004242{
4243 PyObject *return_value = NULL;
4244 int major;
4245 int minor;
4246 dev_t _return_value;
4247
Victor Stinner259f0e42017-01-17 01:35:17 +01004248 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004249 &major, &minor)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004250 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004251 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004252
4253 if (!_PyArg_NoStackKeywords("makedev", kwnames)) {
4254 goto exit;
4255 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004256 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004257 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004258 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004259 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004260 return_value = _PyLong_FromDev(_return_value);
4261
4262exit:
4263 return return_value;
4264}
4265
4266#endif /* defined(HAVE_DEVICE_MACROS) */
4267
Steve Dowerf7377032015-04-12 15:44:54 -04004268#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004269
4270PyDoc_STRVAR(os_ftruncate__doc__,
4271"ftruncate($module, fd, length, /)\n"
4272"--\n"
4273"\n"
4274"Truncate a file, specified by file descriptor, to a specific length.");
4275
4276#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004277 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004278
4279static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004280os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004281
4282static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004283os_ftruncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004284{
4285 PyObject *return_value = NULL;
4286 int fd;
4287 Py_off_t length;
4288
Victor Stinner259f0e42017-01-17 01:35:17 +01004289 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004290 &fd, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004291 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004292 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004293
4294 if (!_PyArg_NoStackKeywords("ftruncate", kwnames)) {
4295 goto exit;
4296 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004297 return_value = os_ftruncate_impl(module, fd, length);
4298
4299exit:
4300 return return_value;
4301}
4302
Steve Dowerf7377032015-04-12 15:44:54 -04004303#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004304
Steve Dowerf7377032015-04-12 15:44:54 -04004305#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004306
4307PyDoc_STRVAR(os_truncate__doc__,
4308"truncate($module, /, path, length)\n"
4309"--\n"
4310"\n"
4311"Truncate a file, specified by path, to a specific length.\n"
4312"\n"
4313"On some platforms, path may also be specified as an open file descriptor.\n"
4314" If this functionality is unavailable, using it raises an exception.");
4315
4316#define OS_TRUNCATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004317 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004318
4319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004320os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321
4322static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004323os_truncate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004324{
4325 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004326 static const char * const _keywords[] = {"path", "length", NULL};
4327 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004328 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4329 Py_off_t length;
4330
Victor Stinner3e1fad62017-01-17 01:29:01 +01004331 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004332 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004333 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004334 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004335 return_value = os_truncate_impl(module, &path, length);
4336
4337exit:
4338 /* Cleanup for path */
4339 path_cleanup(&path);
4340
4341 return return_value;
4342}
4343
Steve Dowerf7377032015-04-12 15:44:54 -04004344#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004345
4346#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4347
4348PyDoc_STRVAR(os_posix_fallocate__doc__,
4349"posix_fallocate($module, fd, offset, length, /)\n"
4350"--\n"
4351"\n"
4352"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4353"\n"
4354"Ensure that the file specified by fd encompasses a range of bytes\n"
4355"starting at offset bytes from the beginning and continuing for length bytes.");
4356
4357#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004358 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004359
4360static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004361os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004362 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004363
4364static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004365os_posix_fallocate(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004366{
4367 PyObject *return_value = NULL;
4368 int fd;
4369 Py_off_t offset;
4370 Py_off_t length;
4371
Victor Stinner259f0e42017-01-17 01:35:17 +01004372 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004373 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
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_fallocate", kwnames)) {
4378 goto exit;
4379 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004380 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4381
4382exit:
4383 return return_value;
4384}
4385
4386#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4387
4388#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4389
4390PyDoc_STRVAR(os_posix_fadvise__doc__,
4391"posix_fadvise($module, fd, offset, length, advice, /)\n"
4392"--\n"
4393"\n"
4394"Announce an intention to access data in a specific pattern.\n"
4395"\n"
4396"Announce an intention to access data in a specific pattern, thus allowing\n"
4397"the kernel to make optimizations.\n"
4398"The advice applies to the region of the file specified by fd starting at\n"
4399"offset and continuing for length bytes.\n"
4400"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4401"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4402"POSIX_FADV_DONTNEED.");
4403
4404#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004405 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004406
4407static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004408os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004409 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004410
4411static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004412os_posix_fadvise(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004413{
4414 PyObject *return_value = NULL;
4415 int fd;
4416 Py_off_t offset;
4417 Py_off_t length;
4418 int advice;
4419
Victor Stinner259f0e42017-01-17 01:35:17 +01004420 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004421 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004423 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004424
4425 if (!_PyArg_NoStackKeywords("posix_fadvise", kwnames)) {
4426 goto exit;
4427 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004428 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4429
4430exit:
4431 return return_value;
4432}
4433
4434#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4435
4436#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4437
4438PyDoc_STRVAR(os_putenv__doc__,
4439"putenv($module, name, value, /)\n"
4440"--\n"
4441"\n"
4442"Change or add an environment variable.");
4443
4444#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004445 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004446
4447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004448os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004449
4450static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004451os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004452{
4453 PyObject *return_value = NULL;
4454 PyObject *name;
4455 PyObject *value;
4456
Victor Stinner259f0e42017-01-17 01:35:17 +01004457 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004458 &name, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004459 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004460 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004461
4462 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4463 goto exit;
4464 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004465 return_value = os_putenv_impl(module, name, value);
4466
4467exit:
4468 return return_value;
4469}
4470
4471#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4472
4473#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4474
4475PyDoc_STRVAR(os_putenv__doc__,
4476"putenv($module, name, value, /)\n"
4477"--\n"
4478"\n"
4479"Change or add an environment variable.");
4480
4481#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004482 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004483
4484static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004485os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004486
4487static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01004488os_putenv(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004489{
4490 PyObject *return_value = NULL;
4491 PyObject *name = NULL;
4492 PyObject *value = NULL;
4493
Victor Stinner259f0e42017-01-17 01:35:17 +01004494 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004495 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004496 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004497 }
Victor Stinner259f0e42017-01-17 01:35:17 +01004498
4499 if (!_PyArg_NoStackKeywords("putenv", kwnames)) {
4500 goto exit;
4501 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004502 return_value = os_putenv_impl(module, name, value);
4503
4504exit:
4505 /* Cleanup for name */
4506 Py_XDECREF(name);
4507 /* Cleanup for value */
4508 Py_XDECREF(value);
4509
4510 return return_value;
4511}
4512
4513#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4514
4515#if defined(HAVE_UNSETENV)
4516
4517PyDoc_STRVAR(os_unsetenv__doc__,
4518"unsetenv($module, name, /)\n"
4519"--\n"
4520"\n"
4521"Delete an environment variable.");
4522
4523#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004524 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004525
4526static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004527os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004528
4529static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004530os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004531{
4532 PyObject *return_value = NULL;
4533 PyObject *name = NULL;
4534
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004535 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004536 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004537 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004538 return_value = os_unsetenv_impl(module, name);
4539
4540exit:
4541 /* Cleanup for name */
4542 Py_XDECREF(name);
4543
4544 return return_value;
4545}
4546
4547#endif /* defined(HAVE_UNSETENV) */
4548
4549PyDoc_STRVAR(os_strerror__doc__,
4550"strerror($module, code, /)\n"
4551"--\n"
4552"\n"
4553"Translate an error code to a message string.");
4554
4555#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004556 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004557
4558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004559os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004560
4561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004562os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004563{
4564 PyObject *return_value = NULL;
4565 int code;
4566
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004567 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004568 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004569 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004570 return_value = os_strerror_impl(module, code);
4571
4572exit:
4573 return return_value;
4574}
4575
4576#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4577
4578PyDoc_STRVAR(os_WCOREDUMP__doc__,
4579"WCOREDUMP($module, status, /)\n"
4580"--\n"
4581"\n"
4582"Return True if the process returning status was dumped to a core file.");
4583
4584#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004585 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004586
4587static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004588os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004589
4590static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004591os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004592{
4593 PyObject *return_value = NULL;
4594 int status;
4595 int _return_value;
4596
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004597 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004598 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004599 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004600 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004601 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004604 return_value = PyBool_FromLong((long)_return_value);
4605
4606exit:
4607 return return_value;
4608}
4609
4610#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4611
4612#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4613
4614PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4615"WIFCONTINUED($module, /, status)\n"
4616"--\n"
4617"\n"
4618"Return True if a particular process was continued from a job control stop.\n"
4619"\n"
4620"Return True if the process returning status was continued from a\n"
4621"job control stop.");
4622
4623#define OS_WIFCONTINUED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004624 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004625
4626static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004627os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004628
4629static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004630os_WIFCONTINUED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004631{
4632 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004633 static const char * const _keywords[] = {"status", NULL};
4634 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004635 int status;
4636 int _return_value;
4637
Victor Stinner3e1fad62017-01-17 01:29:01 +01004638 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004639 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004640 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004641 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004642 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004643 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004644 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004645 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004646 return_value = PyBool_FromLong((long)_return_value);
4647
4648exit:
4649 return return_value;
4650}
4651
4652#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4653
4654#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4655
4656PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4657"WIFSTOPPED($module, /, status)\n"
4658"--\n"
4659"\n"
4660"Return True if the process returning status was stopped.");
4661
4662#define OS_WIFSTOPPED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004663 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004664
4665static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004666os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004667
4668static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004669os_WIFSTOPPED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004670{
4671 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004672 static const char * const _keywords[] = {"status", NULL};
4673 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004674 int status;
4675 int _return_value;
4676
Victor Stinner3e1fad62017-01-17 01:29:01 +01004677 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004678 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004679 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004680 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004681 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004682 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004683 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004684 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004685 return_value = PyBool_FromLong((long)_return_value);
4686
4687exit:
4688 return return_value;
4689}
4690
4691#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4692
4693#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4694
4695PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4696"WIFSIGNALED($module, /, status)\n"
4697"--\n"
4698"\n"
4699"Return True if the process returning status was terminated by a signal.");
4700
4701#define OS_WIFSIGNALED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004702 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004703
4704static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004705os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706
4707static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004708os_WIFSIGNALED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004709{
4710 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004711 static const char * const _keywords[] = {"status", NULL};
4712 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004713 int status;
4714 int _return_value;
4715
Victor Stinner3e1fad62017-01-17 01:29:01 +01004716 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004717 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004718 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004719 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004720 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004721 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004722 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004723 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004724 return_value = PyBool_FromLong((long)_return_value);
4725
4726exit:
4727 return return_value;
4728}
4729
4730#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4731
4732#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4733
4734PyDoc_STRVAR(os_WIFEXITED__doc__,
4735"WIFEXITED($module, /, status)\n"
4736"--\n"
4737"\n"
4738"Return True if the process returning status exited via the exit() system call.");
4739
4740#define OS_WIFEXITED_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004741 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004742
4743static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004744os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004745
4746static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004747os_WIFEXITED(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004748{
4749 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004750 static const char * const _keywords[] = {"status", NULL};
4751 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752 int status;
4753 int _return_value;
4754
Victor Stinner3e1fad62017-01-17 01:29:01 +01004755 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004756 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004757 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004758 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004759 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004760 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004761 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004762 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004763 return_value = PyBool_FromLong((long)_return_value);
4764
4765exit:
4766 return return_value;
4767}
4768
4769#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4770
4771#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4772
4773PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4774"WEXITSTATUS($module, /, status)\n"
4775"--\n"
4776"\n"
4777"Return the process return code from status.");
4778
4779#define OS_WEXITSTATUS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004780 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004781
4782static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004783os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004784
4785static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004786os_WEXITSTATUS(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004787{
4788 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004789 static const char * const _keywords[] = {"status", NULL};
4790 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791 int status;
4792 int _return_value;
4793
Victor Stinner3e1fad62017-01-17 01:29:01 +01004794 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004795 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004796 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004797 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004798 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004799 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004800 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004801 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004802 return_value = PyLong_FromLong((long)_return_value);
4803
4804exit:
4805 return return_value;
4806}
4807
4808#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4809
4810#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4811
4812PyDoc_STRVAR(os_WTERMSIG__doc__,
4813"WTERMSIG($module, /, status)\n"
4814"--\n"
4815"\n"
4816"Return the signal that terminated the process that provided the status value.");
4817
4818#define OS_WTERMSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004819 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004820
4821static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004822os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004823
4824static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004825os_WTERMSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004826{
4827 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004828 static const char * const _keywords[] = {"status", NULL};
4829 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004830 int status;
4831 int _return_value;
4832
Victor Stinner3e1fad62017-01-17 01:29:01 +01004833 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004834 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004835 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004836 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004837 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004838 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004839 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004840 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004841 return_value = PyLong_FromLong((long)_return_value);
4842
4843exit:
4844 return return_value;
4845}
4846
4847#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4848
4849#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4850
4851PyDoc_STRVAR(os_WSTOPSIG__doc__,
4852"WSTOPSIG($module, /, status)\n"
4853"--\n"
4854"\n"
4855"Return the signal that stopped the process that provided the status value.");
4856
4857#define OS_WSTOPSIG_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004858 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004859
4860static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004861os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004862
4863static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004864os_WSTOPSIG(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004865{
4866 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004867 static const char * const _keywords[] = {"status", NULL};
4868 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004869 int status;
4870 int _return_value;
4871
Victor Stinner3e1fad62017-01-17 01:29:01 +01004872 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004873 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004874 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004875 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004876 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004877 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004878 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004879 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004880 return_value = PyLong_FromLong((long)_return_value);
4881
4882exit:
4883 return return_value;
4884}
4885
4886#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4887
4888#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4889
4890PyDoc_STRVAR(os_fstatvfs__doc__,
4891"fstatvfs($module, fd, /)\n"
4892"--\n"
4893"\n"
4894"Perform an fstatvfs system call on the given fd.\n"
4895"\n"
4896"Equivalent to statvfs(fd).");
4897
4898#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004899 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004900
4901static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004902os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004903
4904static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004905os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004906{
4907 PyObject *return_value = NULL;
4908 int fd;
4909
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004910 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004911 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004912 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004913 return_value = os_fstatvfs_impl(module, fd);
4914
4915exit:
4916 return return_value;
4917}
4918
4919#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4920
4921#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
4922
4923PyDoc_STRVAR(os_statvfs__doc__,
4924"statvfs($module, /, path)\n"
4925"--\n"
4926"\n"
4927"Perform a statvfs system call on the given path.\n"
4928"\n"
4929"path may always be specified as a string.\n"
4930"On some platforms, path may also be specified as an open file descriptor.\n"
4931" If this functionality is unavailable, using it raises an exception.");
4932
4933#define OS_STATVFS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004934 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004935
4936static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004937os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004938
4939static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004940os_statvfs(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004941{
4942 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004943 static const char * const _keywords[] = {"path", NULL};
4944 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004945 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
4946
Victor Stinner3e1fad62017-01-17 01:29:01 +01004947 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004948 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004949 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004950 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004951 return_value = os_statvfs_impl(module, &path);
4952
4953exit:
4954 /* Cleanup for path */
4955 path_cleanup(&path);
4956
4957 return return_value;
4958}
4959
4960#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
4961
4962#if defined(MS_WINDOWS)
4963
4964PyDoc_STRVAR(os__getdiskusage__doc__,
4965"_getdiskusage($module, /, path)\n"
4966"--\n"
4967"\n"
4968"Return disk usage statistics about the given path as a (total, free) tuple.");
4969
4970#define OS__GETDISKUSAGE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07004971 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004972
4973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004974os__getdiskusage_impl(PyObject *module, Py_UNICODE *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004975
4976static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07004977os__getdiskusage(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978{
4979 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004980 static const char * const _keywords[] = {"path", NULL};
4981 static _PyArg_Parser _parser = {"u:_getdiskusage", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004982 Py_UNICODE *path;
4983
Victor Stinner3e1fad62017-01-17 01:29:01 +01004984 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004985 &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004986 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004987 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004988 return_value = os__getdiskusage_impl(module, path);
4989
4990exit:
4991 return return_value;
4992}
4993
4994#endif /* defined(MS_WINDOWS) */
4995
4996#if defined(HAVE_FPATHCONF)
4997
4998PyDoc_STRVAR(os_fpathconf__doc__,
4999"fpathconf($module, fd, name, /)\n"
5000"--\n"
5001"\n"
5002"Return the configuration limit name for the file descriptor fd.\n"
5003"\n"
5004"If there is no limit, return -1.");
5005
5006#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005007 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005008
5009static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005010os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005011
5012static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005013os_fpathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005014{
5015 PyObject *return_value = NULL;
5016 int fd;
5017 int name;
5018 long _return_value;
5019
Victor Stinner259f0e42017-01-17 01:35:17 +01005020 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005021 &fd, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005022 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005023 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005024
5025 if (!_PyArg_NoStackKeywords("fpathconf", kwnames)) {
5026 goto exit;
5027 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005028 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005029 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005030 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005031 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005032 return_value = PyLong_FromLong(_return_value);
5033
5034exit:
5035 return return_value;
5036}
5037
5038#endif /* defined(HAVE_FPATHCONF) */
5039
5040#if defined(HAVE_PATHCONF)
5041
5042PyDoc_STRVAR(os_pathconf__doc__,
5043"pathconf($module, /, path, name)\n"
5044"--\n"
5045"\n"
5046"Return the configuration limit name for the file or directory path.\n"
5047"\n"
5048"If there is no limit, return -1.\n"
5049"On some platforms, path may also be specified as an open file descriptor.\n"
5050" If this functionality is unavailable, using it raises an exception.");
5051
5052#define OS_PATHCONF_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005053 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005054
5055static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005056os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005057
5058static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005059os_pathconf(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060{
5061 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005062 static const char * const _keywords[] = {"path", "name", NULL};
5063 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005064 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5065 int name;
5066 long _return_value;
5067
Victor Stinner3e1fad62017-01-17 01:29:01 +01005068 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005069 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005070 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005071 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005072 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005073 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005074 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005075 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005076 return_value = PyLong_FromLong(_return_value);
5077
5078exit:
5079 /* Cleanup for path */
5080 path_cleanup(&path);
5081
5082 return return_value;
5083}
5084
5085#endif /* defined(HAVE_PATHCONF) */
5086
5087#if defined(HAVE_CONFSTR)
5088
5089PyDoc_STRVAR(os_confstr__doc__,
5090"confstr($module, name, /)\n"
5091"--\n"
5092"\n"
5093"Return a string-valued system configuration variable.");
5094
5095#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005096 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005097
5098static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005099os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005100
5101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005102os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005103{
5104 PyObject *return_value = NULL;
5105 int name;
5106
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005107 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005110 return_value = os_confstr_impl(module, name);
5111
5112exit:
5113 return return_value;
5114}
5115
5116#endif /* defined(HAVE_CONFSTR) */
5117
5118#if defined(HAVE_SYSCONF)
5119
5120PyDoc_STRVAR(os_sysconf__doc__,
5121"sysconf($module, name, /)\n"
5122"--\n"
5123"\n"
5124"Return an integer-valued system configuration variable.");
5125
5126#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005127 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005128
5129static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005130os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005131
5132static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005133os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005134{
5135 PyObject *return_value = NULL;
5136 int name;
5137 long _return_value;
5138
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005139 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005140 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005141 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005142 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005143 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005144 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005145 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005146 return_value = PyLong_FromLong(_return_value);
5147
5148exit:
5149 return return_value;
5150}
5151
5152#endif /* defined(HAVE_SYSCONF) */
5153
5154PyDoc_STRVAR(os_abort__doc__,
5155"abort($module, /)\n"
5156"--\n"
5157"\n"
5158"Abort the interpreter immediately.\n"
5159"\n"
5160"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5161"on the hosting operating system. This function never returns.");
5162
5163#define OS_ABORT_METHODDEF \
5164 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5165
5166static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005167os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005168
5169static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005170os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005171{
5172 return os_abort_impl(module);
5173}
5174
Steve Dowercc16be82016-09-08 10:35:16 -07005175#if defined(MS_WINDOWS)
5176
5177PyDoc_STRVAR(os_startfile__doc__,
5178"startfile($module, /, filepath, operation=None)\n"
5179"--\n"
5180"\n"
5181"startfile(filepath [, operation])\n"
5182"\n"
5183"Start a file with its associated application.\n"
5184"\n"
5185"When \"operation\" is not specified or \"open\", this acts like\n"
5186"double-clicking the file in Explorer, or giving the file name as an\n"
5187"argument to the DOS \"start\" command: the file is opened with whatever\n"
5188"application (if any) its extension is associated.\n"
5189"When another \"operation\" is given, it specifies what should be done with\n"
5190"the file. A typical operation is \"print\".\n"
5191"\n"
5192"startfile returns as soon as the associated application is launched.\n"
5193"There is no option to wait for the application to close, and no way\n"
5194"to retrieve the application\'s exit status.\n"
5195"\n"
5196"The filepath is relative to the current directory. If you want to use\n"
5197"an absolute path, make sure the first character is not a slash (\"/\");\n"
5198"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5199
5200#define OS_STARTFILE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005201 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005202
5203static PyObject *
5204os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5205
5206static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005207os_startfile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005208{
5209 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005210 static const char * const _keywords[] = {"filepath", "operation", NULL};
5211 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005212 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5213 Py_UNICODE *operation = NULL;
5214
Victor Stinner3e1fad62017-01-17 01:29:01 +01005215 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005216 path_converter, &filepath, &operation)) {
5217 goto exit;
5218 }
5219 return_value = os_startfile_impl(module, &filepath, operation);
5220
5221exit:
5222 /* Cleanup for filepath */
5223 path_cleanup(&filepath);
5224
5225 return return_value;
5226}
5227
5228#endif /* defined(MS_WINDOWS) */
5229
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005230#if defined(HAVE_GETLOADAVG)
5231
5232PyDoc_STRVAR(os_getloadavg__doc__,
5233"getloadavg($module, /)\n"
5234"--\n"
5235"\n"
5236"Return average recent system load information.\n"
5237"\n"
5238"Return the number of processes in the system run queue averaged over\n"
5239"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5240"Raises OSError if the load average was unobtainable.");
5241
5242#define OS_GETLOADAVG_METHODDEF \
5243 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5244
5245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005246os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247
5248static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005249os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005250{
5251 return os_getloadavg_impl(module);
5252}
5253
5254#endif /* defined(HAVE_GETLOADAVG) */
5255
5256PyDoc_STRVAR(os_device_encoding__doc__,
5257"device_encoding($module, /, fd)\n"
5258"--\n"
5259"\n"
5260"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5261"\n"
5262"The file descriptor must be attached to a terminal.\n"
5263"If the device is not a terminal, return None.");
5264
5265#define OS_DEVICE_ENCODING_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005266 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005267
5268static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005269os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005270
5271static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005272os_device_encoding(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005273{
5274 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005275 static const char * const _keywords[] = {"fd", NULL};
5276 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005277 int fd;
5278
Victor Stinner3e1fad62017-01-17 01:29:01 +01005279 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005280 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005281 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005282 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005283 return_value = os_device_encoding_impl(module, fd);
5284
5285exit:
5286 return return_value;
5287}
5288
5289#if defined(HAVE_SETRESUID)
5290
5291PyDoc_STRVAR(os_setresuid__doc__,
5292"setresuid($module, ruid, euid, suid, /)\n"
5293"--\n"
5294"\n"
5295"Set the current process\'s real, effective, and saved user ids.");
5296
5297#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005298 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005299
5300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005301os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005302
5303static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005304os_setresuid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005305{
5306 PyObject *return_value = NULL;
5307 uid_t ruid;
5308 uid_t euid;
5309 uid_t suid;
5310
Victor Stinner259f0e42017-01-17 01:35:17 +01005311 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005312 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005313 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005314 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005315
5316 if (!_PyArg_NoStackKeywords("setresuid", kwnames)) {
5317 goto exit;
5318 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005319 return_value = os_setresuid_impl(module, ruid, euid, suid);
5320
5321exit:
5322 return return_value;
5323}
5324
5325#endif /* defined(HAVE_SETRESUID) */
5326
5327#if defined(HAVE_SETRESGID)
5328
5329PyDoc_STRVAR(os_setresgid__doc__,
5330"setresgid($module, rgid, egid, sgid, /)\n"
5331"--\n"
5332"\n"
5333"Set the current process\'s real, effective, and saved group ids.");
5334
5335#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005336 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005337
5338static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005339os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005340
5341static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005342os_setresgid(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005343{
5344 PyObject *return_value = NULL;
5345 gid_t rgid;
5346 gid_t egid;
5347 gid_t sgid;
5348
Victor Stinner259f0e42017-01-17 01:35:17 +01005349 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005350 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005351 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005352 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005353
5354 if (!_PyArg_NoStackKeywords("setresgid", kwnames)) {
5355 goto exit;
5356 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005357 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5358
5359exit:
5360 return return_value;
5361}
5362
5363#endif /* defined(HAVE_SETRESGID) */
5364
5365#if defined(HAVE_GETRESUID)
5366
5367PyDoc_STRVAR(os_getresuid__doc__,
5368"getresuid($module, /)\n"
5369"--\n"
5370"\n"
5371"Return a tuple of the current process\'s real, effective, and saved user ids.");
5372
5373#define OS_GETRESUID_METHODDEF \
5374 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5375
5376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005377os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005378
5379static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005380os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005381{
5382 return os_getresuid_impl(module);
5383}
5384
5385#endif /* defined(HAVE_GETRESUID) */
5386
5387#if defined(HAVE_GETRESGID)
5388
5389PyDoc_STRVAR(os_getresgid__doc__,
5390"getresgid($module, /)\n"
5391"--\n"
5392"\n"
5393"Return a tuple of the current process\'s real, effective, and saved group ids.");
5394
5395#define OS_GETRESGID_METHODDEF \
5396 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5397
5398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005399os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005400
5401static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005402os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005403{
5404 return os_getresgid_impl(module);
5405}
5406
5407#endif /* defined(HAVE_GETRESGID) */
5408
5409#if defined(USE_XATTRS)
5410
5411PyDoc_STRVAR(os_getxattr__doc__,
5412"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5413"--\n"
5414"\n"
5415"Return the value of extended attribute attribute on path.\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, getxattr will examine the symbolic link itself instead of the file\n"
5420" the link points to.");
5421
5422#define OS_GETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005423 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005424
5425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005426os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005427 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005428
5429static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005430os_getxattr(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", "follow_symlinks", NULL};
5434 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005435 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5436 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5437 int follow_symlinks = 1;
5438
Victor Stinner3e1fad62017-01-17 01:29:01 +01005439 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005440 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005441 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005442 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005443 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5444
5445exit:
5446 /* Cleanup for path */
5447 path_cleanup(&path);
5448 /* Cleanup for attribute */
5449 path_cleanup(&attribute);
5450
5451 return return_value;
5452}
5453
5454#endif /* defined(USE_XATTRS) */
5455
5456#if defined(USE_XATTRS)
5457
5458PyDoc_STRVAR(os_setxattr__doc__,
5459"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5460" follow_symlinks=True)\n"
5461"--\n"
5462"\n"
5463"Set extended attribute attribute on path to value.\n"
5464"\n"
5465"path may be either a string or an open file descriptor.\n"
5466"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5467" link, setxattr will modify the symbolic link itself instead of the file\n"
5468" the link points to.");
5469
5470#define OS_SETXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005471 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005472
5473static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005474os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005475 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005476
5477static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005478os_setxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005479{
5480 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005481 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5482 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5484 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5485 Py_buffer value = {NULL, NULL};
5486 int flags = 0;
5487 int follow_symlinks = 1;
5488
Victor Stinner3e1fad62017-01-17 01:29:01 +01005489 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005490 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005491 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005492 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005493 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5494
5495exit:
5496 /* Cleanup for path */
5497 path_cleanup(&path);
5498 /* Cleanup for attribute */
5499 path_cleanup(&attribute);
5500 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005501 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005502 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005503 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005504
5505 return return_value;
5506}
5507
5508#endif /* defined(USE_XATTRS) */
5509
5510#if defined(USE_XATTRS)
5511
5512PyDoc_STRVAR(os_removexattr__doc__,
5513"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5514"--\n"
5515"\n"
5516"Remove extended attribute attribute on path.\n"
5517"\n"
5518"path may be either a string or an open file descriptor.\n"
5519"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5520" link, removexattr will modify the symbolic link itself instead of the file\n"
5521" the link points to.");
5522
5523#define OS_REMOVEXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005524 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005525
5526static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005527os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005528 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005529
5530static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005531os_removexattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005532{
5533 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005534 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5535 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005536 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5537 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5538 int follow_symlinks = 1;
5539
Victor Stinner3e1fad62017-01-17 01:29:01 +01005540 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005541 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005543 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005544 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5545
5546exit:
5547 /* Cleanup for path */
5548 path_cleanup(&path);
5549 /* Cleanup for attribute */
5550 path_cleanup(&attribute);
5551
5552 return return_value;
5553}
5554
5555#endif /* defined(USE_XATTRS) */
5556
5557#if defined(USE_XATTRS)
5558
5559PyDoc_STRVAR(os_listxattr__doc__,
5560"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5561"--\n"
5562"\n"
5563"Return a list of extended attributes on path.\n"
5564"\n"
5565"path may be either None, a string, or an open file descriptor.\n"
5566"if path is None, listxattr will examine the current directory.\n"
5567"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5568" link, listxattr will examine the symbolic link itself instead of the file\n"
5569" the link points to.");
5570
5571#define OS_LISTXATTR_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07005572 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005573
5574static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005575os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005576
5577static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07005578os_listxattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005579{
5580 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005581 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5582 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005583 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5584 int follow_symlinks = 1;
5585
Victor Stinner3e1fad62017-01-17 01:29:01 +01005586 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005587 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005588 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005589 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005590 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5591
5592exit:
5593 /* Cleanup for path */
5594 path_cleanup(&path);
5595
5596 return return_value;
5597}
5598
5599#endif /* defined(USE_XATTRS) */
5600
5601PyDoc_STRVAR(os_urandom__doc__,
5602"urandom($module, size, /)\n"
5603"--\n"
5604"\n"
5605"Return a bytes object containing random bytes suitable for cryptographic use.");
5606
5607#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005608 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005609
5610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005611os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005612
5613static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005614os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005615{
5616 PyObject *return_value = NULL;
5617 Py_ssize_t size;
5618
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005619 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005620 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005621 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005622 return_value = os_urandom_impl(module, size);
5623
5624exit:
5625 return return_value;
5626}
5627
5628PyDoc_STRVAR(os_cpu_count__doc__,
5629"cpu_count($module, /)\n"
5630"--\n"
5631"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005632"Return the number of CPUs in the system; return None if indeterminable.\n"
5633"\n"
5634"This number is not equivalent to the number of CPUs the current process can\n"
5635"use. The number of usable CPUs can be obtained with\n"
5636"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005637
5638#define OS_CPU_COUNT_METHODDEF \
5639 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5640
5641static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005642os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005643
5644static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005645os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005646{
5647 return os_cpu_count_impl(module);
5648}
5649
5650PyDoc_STRVAR(os_get_inheritable__doc__,
5651"get_inheritable($module, fd, /)\n"
5652"--\n"
5653"\n"
5654"Get the close-on-exe flag of the specified file descriptor.");
5655
5656#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005657 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005658
5659static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005660os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005661
5662static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005663os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005664{
5665 PyObject *return_value = NULL;
5666 int fd;
5667 int _return_value;
5668
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005669 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005670 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005672 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005673 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005674 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005675 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005676 return_value = PyBool_FromLong((long)_return_value);
5677
5678exit:
5679 return return_value;
5680}
5681
5682PyDoc_STRVAR(os_set_inheritable__doc__,
5683"set_inheritable($module, fd, inheritable, /)\n"
5684"--\n"
5685"\n"
5686"Set the inheritable flag of the specified file descriptor.");
5687
5688#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005689 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005690
5691static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005692os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005693
5694static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005695os_set_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005696{
5697 PyObject *return_value = NULL;
5698 int fd;
5699 int inheritable;
5700
Victor Stinner259f0e42017-01-17 01:35:17 +01005701 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005702 &fd, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005703 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005704 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005705
5706 if (!_PyArg_NoStackKeywords("set_inheritable", kwnames)) {
5707 goto exit;
5708 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005709 return_value = os_set_inheritable_impl(module, fd, inheritable);
5710
5711exit:
5712 return return_value;
5713}
5714
5715#if defined(MS_WINDOWS)
5716
5717PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5718"get_handle_inheritable($module, handle, /)\n"
5719"--\n"
5720"\n"
5721"Get the close-on-exe flag of the specified file descriptor.");
5722
5723#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005724 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005725
5726static int
Victor Stinner581139c2016-09-06 15:54:20 -07005727os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005728
5729static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005730os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005731{
5732 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005733 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005734 int _return_value;
5735
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005736 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005737 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005738 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005739 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005740 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005741 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005742 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005743 return_value = PyBool_FromLong((long)_return_value);
5744
5745exit:
5746 return return_value;
5747}
5748
5749#endif /* defined(MS_WINDOWS) */
5750
5751#if defined(MS_WINDOWS)
5752
5753PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5754"set_handle_inheritable($module, handle, inheritable, /)\n"
5755"--\n"
5756"\n"
5757"Set the inheritable flag of the specified handle.");
5758
5759#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005760 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761
5762static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005763os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005764 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005765
5766static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01005767os_set_handle_inheritable(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005768{
5769 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005770 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005771 int inheritable;
5772
Victor Stinner259f0e42017-01-17 01:35:17 +01005773 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005774 &handle, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005775 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005776 }
Victor Stinner259f0e42017-01-17 01:35:17 +01005777
5778 if (!_PyArg_NoStackKeywords("set_handle_inheritable", kwnames)) {
5779 goto exit;
5780 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005781 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5782
5783exit:
5784 return return_value;
5785}
5786
5787#endif /* defined(MS_WINDOWS) */
5788
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005789PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5790"is_symlink($self, /)\n"
5791"--\n"
5792"\n"
5793"Return True if the entry is a symbolic link; cached per entry.");
5794
5795#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5796 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5797
5798static int
5799os_DirEntry_is_symlink_impl(DirEntry *self);
5800
5801static PyObject *
5802os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5803{
5804 PyObject *return_value = NULL;
5805 int _return_value;
5806
5807 _return_value = os_DirEntry_is_symlink_impl(self);
5808 if ((_return_value == -1) && PyErr_Occurred()) {
5809 goto exit;
5810 }
5811 return_value = PyBool_FromLong((long)_return_value);
5812
5813exit:
5814 return return_value;
5815}
5816
5817PyDoc_STRVAR(os_DirEntry_stat__doc__,
5818"stat($self, /, *, follow_symlinks=True)\n"
5819"--\n"
5820"\n"
5821"Return stat_result object for the entry; cached per entry.");
5822
5823#define OS_DIRENTRY_STAT_METHODDEF \
5824 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL, os_DirEntry_stat__doc__},
5825
5826static PyObject *
5827os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5828
5829static PyObject *
5830os_DirEntry_stat(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5831{
5832 PyObject *return_value = NULL;
5833 static const char * const _keywords[] = {"follow_symlinks", NULL};
5834 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5835 int follow_symlinks = 1;
5836
Victor Stinner3e1fad62017-01-17 01:29:01 +01005837 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005838 &follow_symlinks)) {
5839 goto exit;
5840 }
5841 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5842
5843exit:
5844 return return_value;
5845}
5846
5847PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5848"is_dir($self, /, *, follow_symlinks=True)\n"
5849"--\n"
5850"\n"
5851"Return True if the entry is a directory; cached per entry.");
5852
5853#define OS_DIRENTRY_IS_DIR_METHODDEF \
5854 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL, os_DirEntry_is_dir__doc__},
5855
5856static int
5857os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5858
5859static PyObject *
5860os_DirEntry_is_dir(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5861{
5862 PyObject *return_value = NULL;
5863 static const char * const _keywords[] = {"follow_symlinks", NULL};
5864 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5865 int follow_symlinks = 1;
5866 int _return_value;
5867
Victor Stinner3e1fad62017-01-17 01:29:01 +01005868 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005869 &follow_symlinks)) {
5870 goto exit;
5871 }
5872 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5873 if ((_return_value == -1) && PyErr_Occurred()) {
5874 goto exit;
5875 }
5876 return_value = PyBool_FromLong((long)_return_value);
5877
5878exit:
5879 return return_value;
5880}
5881
5882PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5883"is_file($self, /, *, follow_symlinks=True)\n"
5884"--\n"
5885"\n"
5886"Return True if the entry is a file; cached per entry.");
5887
5888#define OS_DIRENTRY_IS_FILE_METHODDEF \
5889 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL, os_DirEntry_is_file__doc__},
5890
5891static int
5892os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5893
5894static PyObject *
5895os_DirEntry_is_file(DirEntry *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5896{
5897 PyObject *return_value = NULL;
5898 static const char * const _keywords[] = {"follow_symlinks", NULL};
5899 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5900 int follow_symlinks = 1;
5901 int _return_value;
5902
Victor Stinner3e1fad62017-01-17 01:29:01 +01005903 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005904 &follow_symlinks)) {
5905 goto exit;
5906 }
5907 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5908 if ((_return_value == -1) && PyErr_Occurred()) {
5909 goto exit;
5910 }
5911 return_value = PyBool_FromLong((long)_return_value);
5912
5913exit:
5914 return return_value;
5915}
5916
5917PyDoc_STRVAR(os_DirEntry_inode__doc__,
5918"inode($self, /)\n"
5919"--\n"
5920"\n"
5921"Return inode of the entry; cached per entry.");
5922
5923#define OS_DIRENTRY_INODE_METHODDEF \
5924 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
5925
5926static PyObject *
5927os_DirEntry_inode_impl(DirEntry *self);
5928
5929static PyObject *
5930os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
5931{
5932 return os_DirEntry_inode_impl(self);
5933}
5934
5935PyDoc_STRVAR(os_DirEntry___fspath____doc__,
5936"__fspath__($self, /)\n"
5937"--\n"
5938"\n"
5939"Returns the path for the entry.");
5940
5941#define OS_DIRENTRY___FSPATH___METHODDEF \
5942 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
5943
5944static PyObject *
5945os_DirEntry___fspath___impl(DirEntry *self);
5946
5947static PyObject *
5948os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
5949{
5950 return os_DirEntry___fspath___impl(self);
5951}
5952
5953PyDoc_STRVAR(os_scandir__doc__,
5954"scandir($module, /, path=None)\n"
5955"--\n"
5956"\n"
5957"Return an iterator of DirEntry objects for given path.\n"
5958"\n"
5959"path can be specified as either str, bytes or path-like object. If path\n"
5960"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
5961"all other circumstances they will be str.\n"
5962"\n"
5963"If path is None, uses the path=\'.\'.");
5964
5965#define OS_SCANDIR_METHODDEF \
5966 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL, os_scandir__doc__},
5967
5968static PyObject *
5969os_scandir_impl(PyObject *module, path_t *path);
5970
5971static PyObject *
5972os_scandir(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
5973{
5974 PyObject *return_value = NULL;
5975 static const char * const _keywords[] = {"path", NULL};
5976 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03005977 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005978
Victor Stinner3e1fad62017-01-17 01:29:01 +01005979 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005980 path_converter, &path)) {
5981 goto exit;
5982 }
5983 return_value = os_scandir_impl(module, &path);
5984
5985exit:
5986 /* Cleanup for path */
5987 path_cleanup(&path);
5988
5989 return return_value;
5990}
5991
Ethan Furman410ef8e2016-06-04 12:06:26 -07005992PyDoc_STRVAR(os_fspath__doc__,
5993"fspath($module, /, path)\n"
5994"--\n"
5995"\n"
5996"Return the file system path representation of the object.\n"
5997"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07005998"If the object is str or bytes, then allow it to pass through as-is. If the\n"
5999"object defines __fspath__(), then return the result of that method. All other\n"
6000"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006001
6002#define OS_FSPATH_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07006003 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006004
6005static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006006os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006007
6008static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07006009os_fspath(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006010{
6011 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006012 static const char * const _keywords[] = {"path", NULL};
6013 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006014 PyObject *path;
6015
Victor Stinner3e1fad62017-01-17 01:29:01 +01006016 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006017 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006018 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006019 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006020 return_value = os_fspath_impl(module, path);
6021
6022exit:
6023 return return_value;
6024}
6025
Victor Stinner9b1f4742016-09-06 16:18:52 -07006026#if defined(HAVE_GETRANDOM_SYSCALL)
6027
6028PyDoc_STRVAR(os_getrandom__doc__,
6029"getrandom($module, /, size, flags=0)\n"
6030"--\n"
6031"\n"
6032"Obtain a series of random bytes.");
6033
6034#define OS_GETRANDOM_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -07006035 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006036
6037static PyObject *
6038os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6039
6040static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -07006041os_getrandom(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006042{
6043 PyObject *return_value = NULL;
6044 static const char * const _keywords[] = {"size", "flags", NULL};
6045 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6046 Py_ssize_t size;
6047 int flags = 0;
6048
Victor Stinner3e1fad62017-01-17 01:29:01 +01006049 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006050 &size, &flags)) {
6051 goto exit;
6052 }
6053 return_value = os_getrandom_impl(module, size, flags);
6054
6055exit:
6056 return return_value;
6057}
6058
6059#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6060
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006061#ifndef OS_TTYNAME_METHODDEF
6062 #define OS_TTYNAME_METHODDEF
6063#endif /* !defined(OS_TTYNAME_METHODDEF) */
6064
6065#ifndef OS_CTERMID_METHODDEF
6066 #define OS_CTERMID_METHODDEF
6067#endif /* !defined(OS_CTERMID_METHODDEF) */
6068
6069#ifndef OS_FCHDIR_METHODDEF
6070 #define OS_FCHDIR_METHODDEF
6071#endif /* !defined(OS_FCHDIR_METHODDEF) */
6072
6073#ifndef OS_FCHMOD_METHODDEF
6074 #define OS_FCHMOD_METHODDEF
6075#endif /* !defined(OS_FCHMOD_METHODDEF) */
6076
6077#ifndef OS_LCHMOD_METHODDEF
6078 #define OS_LCHMOD_METHODDEF
6079#endif /* !defined(OS_LCHMOD_METHODDEF) */
6080
6081#ifndef OS_CHFLAGS_METHODDEF
6082 #define OS_CHFLAGS_METHODDEF
6083#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6084
6085#ifndef OS_LCHFLAGS_METHODDEF
6086 #define OS_LCHFLAGS_METHODDEF
6087#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6088
6089#ifndef OS_CHROOT_METHODDEF
6090 #define OS_CHROOT_METHODDEF
6091#endif /* !defined(OS_CHROOT_METHODDEF) */
6092
6093#ifndef OS_FSYNC_METHODDEF
6094 #define OS_FSYNC_METHODDEF
6095#endif /* !defined(OS_FSYNC_METHODDEF) */
6096
6097#ifndef OS_SYNC_METHODDEF
6098 #define OS_SYNC_METHODDEF
6099#endif /* !defined(OS_SYNC_METHODDEF) */
6100
6101#ifndef OS_FDATASYNC_METHODDEF
6102 #define OS_FDATASYNC_METHODDEF
6103#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6104
6105#ifndef OS_CHOWN_METHODDEF
6106 #define OS_CHOWN_METHODDEF
6107#endif /* !defined(OS_CHOWN_METHODDEF) */
6108
6109#ifndef OS_FCHOWN_METHODDEF
6110 #define OS_FCHOWN_METHODDEF
6111#endif /* !defined(OS_FCHOWN_METHODDEF) */
6112
6113#ifndef OS_LCHOWN_METHODDEF
6114 #define OS_LCHOWN_METHODDEF
6115#endif /* !defined(OS_LCHOWN_METHODDEF) */
6116
6117#ifndef OS_LINK_METHODDEF
6118 #define OS_LINK_METHODDEF
6119#endif /* !defined(OS_LINK_METHODDEF) */
6120
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006121#ifndef OS__GETFULLPATHNAME_METHODDEF
6122 #define OS__GETFULLPATHNAME_METHODDEF
6123#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6124
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006125#ifndef OS__GETFINALPATHNAME_METHODDEF
6126 #define OS__GETFINALPATHNAME_METHODDEF
6127#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6128
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006129#ifndef OS__ISDIR_METHODDEF
6130 #define OS__ISDIR_METHODDEF
6131#endif /* !defined(OS__ISDIR_METHODDEF) */
6132
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006133#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6134 #define OS__GETVOLUMEPATHNAME_METHODDEF
6135#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6136
6137#ifndef OS_NICE_METHODDEF
6138 #define OS_NICE_METHODDEF
6139#endif /* !defined(OS_NICE_METHODDEF) */
6140
6141#ifndef OS_GETPRIORITY_METHODDEF
6142 #define OS_GETPRIORITY_METHODDEF
6143#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6144
6145#ifndef OS_SETPRIORITY_METHODDEF
6146 #define OS_SETPRIORITY_METHODDEF
6147#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6148
6149#ifndef OS_SYSTEM_METHODDEF
6150 #define OS_SYSTEM_METHODDEF
6151#endif /* !defined(OS_SYSTEM_METHODDEF) */
6152
6153#ifndef OS_UNAME_METHODDEF
6154 #define OS_UNAME_METHODDEF
6155#endif /* !defined(OS_UNAME_METHODDEF) */
6156
6157#ifndef OS_EXECV_METHODDEF
6158 #define OS_EXECV_METHODDEF
6159#endif /* !defined(OS_EXECV_METHODDEF) */
6160
6161#ifndef OS_EXECVE_METHODDEF
6162 #define OS_EXECVE_METHODDEF
6163#endif /* !defined(OS_EXECVE_METHODDEF) */
6164
6165#ifndef OS_SPAWNV_METHODDEF
6166 #define OS_SPAWNV_METHODDEF
6167#endif /* !defined(OS_SPAWNV_METHODDEF) */
6168
6169#ifndef OS_SPAWNVE_METHODDEF
6170 #define OS_SPAWNVE_METHODDEF
6171#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6172
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006173#ifndef OS_REGISTER_AT_FORK_METHODDEF
6174 #define OS_REGISTER_AT_FORK_METHODDEF
6175#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6176
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006177#ifndef OS_FORK1_METHODDEF
6178 #define OS_FORK1_METHODDEF
6179#endif /* !defined(OS_FORK1_METHODDEF) */
6180
6181#ifndef OS_FORK_METHODDEF
6182 #define OS_FORK_METHODDEF
6183#endif /* !defined(OS_FORK_METHODDEF) */
6184
6185#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6186 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6187#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6188
6189#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6190 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6191#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6192
6193#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6194 #define OS_SCHED_GETSCHEDULER_METHODDEF
6195#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6196
6197#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6198 #define OS_SCHED_SETSCHEDULER_METHODDEF
6199#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6200
6201#ifndef OS_SCHED_GETPARAM_METHODDEF
6202 #define OS_SCHED_GETPARAM_METHODDEF
6203#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6204
6205#ifndef OS_SCHED_SETPARAM_METHODDEF
6206 #define OS_SCHED_SETPARAM_METHODDEF
6207#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6208
6209#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6210 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6211#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6212
6213#ifndef OS_SCHED_YIELD_METHODDEF
6214 #define OS_SCHED_YIELD_METHODDEF
6215#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6216
6217#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6218 #define OS_SCHED_SETAFFINITY_METHODDEF
6219#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6220
6221#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6222 #define OS_SCHED_GETAFFINITY_METHODDEF
6223#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6224
6225#ifndef OS_OPENPTY_METHODDEF
6226 #define OS_OPENPTY_METHODDEF
6227#endif /* !defined(OS_OPENPTY_METHODDEF) */
6228
6229#ifndef OS_FORKPTY_METHODDEF
6230 #define OS_FORKPTY_METHODDEF
6231#endif /* !defined(OS_FORKPTY_METHODDEF) */
6232
6233#ifndef OS_GETEGID_METHODDEF
6234 #define OS_GETEGID_METHODDEF
6235#endif /* !defined(OS_GETEGID_METHODDEF) */
6236
6237#ifndef OS_GETEUID_METHODDEF
6238 #define OS_GETEUID_METHODDEF
6239#endif /* !defined(OS_GETEUID_METHODDEF) */
6240
6241#ifndef OS_GETGID_METHODDEF
6242 #define OS_GETGID_METHODDEF
6243#endif /* !defined(OS_GETGID_METHODDEF) */
6244
Berker Peksag39404992016-09-15 20:45:16 +03006245#ifndef OS_GETPID_METHODDEF
6246 #define OS_GETPID_METHODDEF
6247#endif /* !defined(OS_GETPID_METHODDEF) */
6248
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006249#ifndef OS_GETGROUPS_METHODDEF
6250 #define OS_GETGROUPS_METHODDEF
6251#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6252
6253#ifndef OS_GETPGID_METHODDEF
6254 #define OS_GETPGID_METHODDEF
6255#endif /* !defined(OS_GETPGID_METHODDEF) */
6256
6257#ifndef OS_GETPGRP_METHODDEF
6258 #define OS_GETPGRP_METHODDEF
6259#endif /* !defined(OS_GETPGRP_METHODDEF) */
6260
6261#ifndef OS_SETPGRP_METHODDEF
6262 #define OS_SETPGRP_METHODDEF
6263#endif /* !defined(OS_SETPGRP_METHODDEF) */
6264
6265#ifndef OS_GETPPID_METHODDEF
6266 #define OS_GETPPID_METHODDEF
6267#endif /* !defined(OS_GETPPID_METHODDEF) */
6268
6269#ifndef OS_GETLOGIN_METHODDEF
6270 #define OS_GETLOGIN_METHODDEF
6271#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6272
6273#ifndef OS_GETUID_METHODDEF
6274 #define OS_GETUID_METHODDEF
6275#endif /* !defined(OS_GETUID_METHODDEF) */
6276
6277#ifndef OS_KILL_METHODDEF
6278 #define OS_KILL_METHODDEF
6279#endif /* !defined(OS_KILL_METHODDEF) */
6280
6281#ifndef OS_KILLPG_METHODDEF
6282 #define OS_KILLPG_METHODDEF
6283#endif /* !defined(OS_KILLPG_METHODDEF) */
6284
6285#ifndef OS_PLOCK_METHODDEF
6286 #define OS_PLOCK_METHODDEF
6287#endif /* !defined(OS_PLOCK_METHODDEF) */
6288
6289#ifndef OS_SETUID_METHODDEF
6290 #define OS_SETUID_METHODDEF
6291#endif /* !defined(OS_SETUID_METHODDEF) */
6292
6293#ifndef OS_SETEUID_METHODDEF
6294 #define OS_SETEUID_METHODDEF
6295#endif /* !defined(OS_SETEUID_METHODDEF) */
6296
6297#ifndef OS_SETEGID_METHODDEF
6298 #define OS_SETEGID_METHODDEF
6299#endif /* !defined(OS_SETEGID_METHODDEF) */
6300
6301#ifndef OS_SETREUID_METHODDEF
6302 #define OS_SETREUID_METHODDEF
6303#endif /* !defined(OS_SETREUID_METHODDEF) */
6304
6305#ifndef OS_SETREGID_METHODDEF
6306 #define OS_SETREGID_METHODDEF
6307#endif /* !defined(OS_SETREGID_METHODDEF) */
6308
6309#ifndef OS_SETGID_METHODDEF
6310 #define OS_SETGID_METHODDEF
6311#endif /* !defined(OS_SETGID_METHODDEF) */
6312
6313#ifndef OS_SETGROUPS_METHODDEF
6314 #define OS_SETGROUPS_METHODDEF
6315#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6316
6317#ifndef OS_WAIT3_METHODDEF
6318 #define OS_WAIT3_METHODDEF
6319#endif /* !defined(OS_WAIT3_METHODDEF) */
6320
6321#ifndef OS_WAIT4_METHODDEF
6322 #define OS_WAIT4_METHODDEF
6323#endif /* !defined(OS_WAIT4_METHODDEF) */
6324
6325#ifndef OS_WAITID_METHODDEF
6326 #define OS_WAITID_METHODDEF
6327#endif /* !defined(OS_WAITID_METHODDEF) */
6328
6329#ifndef OS_WAITPID_METHODDEF
6330 #define OS_WAITPID_METHODDEF
6331#endif /* !defined(OS_WAITPID_METHODDEF) */
6332
6333#ifndef OS_WAIT_METHODDEF
6334 #define OS_WAIT_METHODDEF
6335#endif /* !defined(OS_WAIT_METHODDEF) */
6336
6337#ifndef OS_SYMLINK_METHODDEF
6338 #define OS_SYMLINK_METHODDEF
6339#endif /* !defined(OS_SYMLINK_METHODDEF) */
6340
6341#ifndef OS_TIMES_METHODDEF
6342 #define OS_TIMES_METHODDEF
6343#endif /* !defined(OS_TIMES_METHODDEF) */
6344
6345#ifndef OS_GETSID_METHODDEF
6346 #define OS_GETSID_METHODDEF
6347#endif /* !defined(OS_GETSID_METHODDEF) */
6348
6349#ifndef OS_SETSID_METHODDEF
6350 #define OS_SETSID_METHODDEF
6351#endif /* !defined(OS_SETSID_METHODDEF) */
6352
6353#ifndef OS_SETPGID_METHODDEF
6354 #define OS_SETPGID_METHODDEF
6355#endif /* !defined(OS_SETPGID_METHODDEF) */
6356
6357#ifndef OS_TCGETPGRP_METHODDEF
6358 #define OS_TCGETPGRP_METHODDEF
6359#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6360
6361#ifndef OS_TCSETPGRP_METHODDEF
6362 #define OS_TCSETPGRP_METHODDEF
6363#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6364
6365#ifndef OS_LOCKF_METHODDEF
6366 #define OS_LOCKF_METHODDEF
6367#endif /* !defined(OS_LOCKF_METHODDEF) */
6368
6369#ifndef OS_READV_METHODDEF
6370 #define OS_READV_METHODDEF
6371#endif /* !defined(OS_READV_METHODDEF) */
6372
6373#ifndef OS_PREAD_METHODDEF
6374 #define OS_PREAD_METHODDEF
6375#endif /* !defined(OS_PREAD_METHODDEF) */
6376
6377#ifndef OS_PIPE_METHODDEF
6378 #define OS_PIPE_METHODDEF
6379#endif /* !defined(OS_PIPE_METHODDEF) */
6380
6381#ifndef OS_PIPE2_METHODDEF
6382 #define OS_PIPE2_METHODDEF
6383#endif /* !defined(OS_PIPE2_METHODDEF) */
6384
6385#ifndef OS_WRITEV_METHODDEF
6386 #define OS_WRITEV_METHODDEF
6387#endif /* !defined(OS_WRITEV_METHODDEF) */
6388
6389#ifndef OS_PWRITE_METHODDEF
6390 #define OS_PWRITE_METHODDEF
6391#endif /* !defined(OS_PWRITE_METHODDEF) */
6392
6393#ifndef OS_MKFIFO_METHODDEF
6394 #define OS_MKFIFO_METHODDEF
6395#endif /* !defined(OS_MKFIFO_METHODDEF) */
6396
6397#ifndef OS_MKNOD_METHODDEF
6398 #define OS_MKNOD_METHODDEF
6399#endif /* !defined(OS_MKNOD_METHODDEF) */
6400
6401#ifndef OS_MAJOR_METHODDEF
6402 #define OS_MAJOR_METHODDEF
6403#endif /* !defined(OS_MAJOR_METHODDEF) */
6404
6405#ifndef OS_MINOR_METHODDEF
6406 #define OS_MINOR_METHODDEF
6407#endif /* !defined(OS_MINOR_METHODDEF) */
6408
6409#ifndef OS_MAKEDEV_METHODDEF
6410 #define OS_MAKEDEV_METHODDEF
6411#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6412
6413#ifndef OS_FTRUNCATE_METHODDEF
6414 #define OS_FTRUNCATE_METHODDEF
6415#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6416
6417#ifndef OS_TRUNCATE_METHODDEF
6418 #define OS_TRUNCATE_METHODDEF
6419#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6420
6421#ifndef OS_POSIX_FALLOCATE_METHODDEF
6422 #define OS_POSIX_FALLOCATE_METHODDEF
6423#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6424
6425#ifndef OS_POSIX_FADVISE_METHODDEF
6426 #define OS_POSIX_FADVISE_METHODDEF
6427#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6428
6429#ifndef OS_PUTENV_METHODDEF
6430 #define OS_PUTENV_METHODDEF
6431#endif /* !defined(OS_PUTENV_METHODDEF) */
6432
6433#ifndef OS_UNSETENV_METHODDEF
6434 #define OS_UNSETENV_METHODDEF
6435#endif /* !defined(OS_UNSETENV_METHODDEF) */
6436
6437#ifndef OS_WCOREDUMP_METHODDEF
6438 #define OS_WCOREDUMP_METHODDEF
6439#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6440
6441#ifndef OS_WIFCONTINUED_METHODDEF
6442 #define OS_WIFCONTINUED_METHODDEF
6443#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6444
6445#ifndef OS_WIFSTOPPED_METHODDEF
6446 #define OS_WIFSTOPPED_METHODDEF
6447#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6448
6449#ifndef OS_WIFSIGNALED_METHODDEF
6450 #define OS_WIFSIGNALED_METHODDEF
6451#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6452
6453#ifndef OS_WIFEXITED_METHODDEF
6454 #define OS_WIFEXITED_METHODDEF
6455#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6456
6457#ifndef OS_WEXITSTATUS_METHODDEF
6458 #define OS_WEXITSTATUS_METHODDEF
6459#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6460
6461#ifndef OS_WTERMSIG_METHODDEF
6462 #define OS_WTERMSIG_METHODDEF
6463#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6464
6465#ifndef OS_WSTOPSIG_METHODDEF
6466 #define OS_WSTOPSIG_METHODDEF
6467#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6468
6469#ifndef OS_FSTATVFS_METHODDEF
6470 #define OS_FSTATVFS_METHODDEF
6471#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6472
6473#ifndef OS_STATVFS_METHODDEF
6474 #define OS_STATVFS_METHODDEF
6475#endif /* !defined(OS_STATVFS_METHODDEF) */
6476
6477#ifndef OS__GETDISKUSAGE_METHODDEF
6478 #define OS__GETDISKUSAGE_METHODDEF
6479#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6480
6481#ifndef OS_FPATHCONF_METHODDEF
6482 #define OS_FPATHCONF_METHODDEF
6483#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6484
6485#ifndef OS_PATHCONF_METHODDEF
6486 #define OS_PATHCONF_METHODDEF
6487#endif /* !defined(OS_PATHCONF_METHODDEF) */
6488
6489#ifndef OS_CONFSTR_METHODDEF
6490 #define OS_CONFSTR_METHODDEF
6491#endif /* !defined(OS_CONFSTR_METHODDEF) */
6492
6493#ifndef OS_SYSCONF_METHODDEF
6494 #define OS_SYSCONF_METHODDEF
6495#endif /* !defined(OS_SYSCONF_METHODDEF) */
6496
Steve Dowercc16be82016-09-08 10:35:16 -07006497#ifndef OS_STARTFILE_METHODDEF
6498 #define OS_STARTFILE_METHODDEF
6499#endif /* !defined(OS_STARTFILE_METHODDEF) */
6500
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006501#ifndef OS_GETLOADAVG_METHODDEF
6502 #define OS_GETLOADAVG_METHODDEF
6503#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6504
6505#ifndef OS_SETRESUID_METHODDEF
6506 #define OS_SETRESUID_METHODDEF
6507#endif /* !defined(OS_SETRESUID_METHODDEF) */
6508
6509#ifndef OS_SETRESGID_METHODDEF
6510 #define OS_SETRESGID_METHODDEF
6511#endif /* !defined(OS_SETRESGID_METHODDEF) */
6512
6513#ifndef OS_GETRESUID_METHODDEF
6514 #define OS_GETRESUID_METHODDEF
6515#endif /* !defined(OS_GETRESUID_METHODDEF) */
6516
6517#ifndef OS_GETRESGID_METHODDEF
6518 #define OS_GETRESGID_METHODDEF
6519#endif /* !defined(OS_GETRESGID_METHODDEF) */
6520
6521#ifndef OS_GETXATTR_METHODDEF
6522 #define OS_GETXATTR_METHODDEF
6523#endif /* !defined(OS_GETXATTR_METHODDEF) */
6524
6525#ifndef OS_SETXATTR_METHODDEF
6526 #define OS_SETXATTR_METHODDEF
6527#endif /* !defined(OS_SETXATTR_METHODDEF) */
6528
6529#ifndef OS_REMOVEXATTR_METHODDEF
6530 #define OS_REMOVEXATTR_METHODDEF
6531#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6532
6533#ifndef OS_LISTXATTR_METHODDEF
6534 #define OS_LISTXATTR_METHODDEF
6535#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6536
6537#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6538 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6539#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6540
6541#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6542 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6543#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006544
6545#ifndef OS_GETRANDOM_METHODDEF
6546 #define OS_GETRANDOM_METHODDEF
6547#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Gregory P. Smith163468a2017-05-29 10:03:41 -07006548/*[clinic end generated code: output=dce741f527ddbfa4 input=a9049054013a1b77]*/