blob: f7767c4af0bb8150b38c6776262fab2de0704c0e [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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030031 {"stat", (PyCFunction)os_stat, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020037os_stat(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030069 {"lstat", (PyCFunction)os_lstat, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020075os_lstat(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300129 {"access", (PyCFunction)os_access, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200136os_access(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300237 {"chdir", (PyCFunction)os_chdir, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200243os_chdir(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300275 {"fchdir", (PyCFunction)os_fchdir, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200281os_fchdir(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300327 {"chmod", (PyCFunction)os_chmod, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200334os_chmod(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300368 {"fchmod", (PyCFunction)os_fchmod, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200374os_fchmod(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300406 {"lchmod", (PyCFunction)os_lchmod, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200412os_lchmod(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300450 {"chflags", (PyCFunction)os_chflags, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200457os_chflags(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300493 {"lchflags", (PyCFunction)os_lchflags, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200499os_lchflags(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300531 {"chroot", (PyCFunction)os_chroot, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200537os_chroot(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300568 {"fsync", (PyCFunction)os_fsync, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200574os_fsync(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300624 {"fdatasync", (PyCFunction)os_fdatasync, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200630os_fdatasync(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300682 {"chown", (PyCFunction)os_chown, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200689os_chown(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300726 {"fchown", (PyCFunction)os_fchown, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200732os_fchown(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300765 {"lchown", (PyCFunction)os_lchown, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200771os_lchown(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300851 {"link", (PyCFunction)os_link, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200858os_link(PyObject *module, PyObject *const *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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300904 {"listdir", (PyCFunction)os_listdir, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200910os_listdir(PyObject *module, PyObject *const *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 *
Steve Dower23ad6d02018-02-22 10:39:10 -0800975os__getfinalpathname_impl(PyObject *module, path_t *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;
Steve Dower23ad6d02018-02-22 10:39:10 -0800981 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300982
Steve Dower23ad6d02018-02-22 10:39:10 -0800983 if (!PyArg_Parse(arg, "O&:_getfinalpathname", path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300984 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300985 }
Steve Dower23ad6d02018-02-22 10:39:10 -0800986 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300987
988exit:
Steve Dower23ad6d02018-02-22 10:39:10 -0800989 /* Cleanup for path */
990 path_cleanup(&path);
991
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300992 return return_value;
993}
994
995#endif /* defined(MS_WINDOWS) */
996
997#if defined(MS_WINDOWS)
998
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300999PyDoc_STRVAR(os__isdir__doc__,
1000"_isdir($module, path, /)\n"
1001"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +02001002"\n"
1003"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001004
1005#define OS__ISDIR_METHODDEF \
1006 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1007
1008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001009os__isdir_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001010
1011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001012os__isdir(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001013{
1014 PyObject *return_value = NULL;
1015 path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
1016
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001017 if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001018 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001019 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001020 return_value = os__isdir_impl(module, &path);
1021
1022exit:
1023 /* Cleanup for path */
1024 path_cleanup(&path);
1025
1026 return return_value;
1027}
1028
1029#endif /* defined(MS_WINDOWS) */
1030
1031#if defined(MS_WINDOWS)
1032
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001033PyDoc_STRVAR(os__getvolumepathname__doc__,
1034"_getvolumepathname($module, /, path)\n"
1035"--\n"
1036"\n"
1037"A helper function for ismount on Win32.");
1038
1039#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001040 {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001043os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044
1045static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001046os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001047{
1048 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001049 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08001050 static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1051 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001052
Victor Stinner3e1fad62017-01-17 01:29:01 +01001053 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08001054 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001055 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001056 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001057 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001058
1059exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001060 /* Cleanup for path */
1061 path_cleanup(&path);
1062
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001063 return return_value;
1064}
1065
1066#endif /* defined(MS_WINDOWS) */
1067
1068PyDoc_STRVAR(os_mkdir__doc__,
1069"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1070"--\n"
1071"\n"
1072"Create a directory.\n"
1073"\n"
1074"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1075" and path should be relative; path will then be relative to that directory.\n"
1076"dir_fd may not be implemented on your platform.\n"
1077" If it is unavailable, using it will raise a NotImplementedError.\n"
1078"\n"
1079"The mode argument is ignored on Windows.");
1080
1081#define OS_MKDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001082 {"mkdir", (PyCFunction)os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001083
1084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001085os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001086
1087static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001088os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001089{
1090 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001091 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1092 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001093 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1094 int mode = 511;
1095 int dir_fd = DEFAULT_DIR_FD;
1096
Victor Stinner3e1fad62017-01-17 01:29:01 +01001097 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001098 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001099 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001100 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001101 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1102
1103exit:
1104 /* Cleanup for path */
1105 path_cleanup(&path);
1106
1107 return return_value;
1108}
1109
1110#if defined(HAVE_NICE)
1111
1112PyDoc_STRVAR(os_nice__doc__,
1113"nice($module, increment, /)\n"
1114"--\n"
1115"\n"
1116"Add increment to the priority of process and return the new priority.");
1117
1118#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001119 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001120
1121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001122os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001123
1124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001125os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001126{
1127 PyObject *return_value = NULL;
1128 int increment;
1129
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001130 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001131 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001132 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001133 return_value = os_nice_impl(module, increment);
1134
1135exit:
1136 return return_value;
1137}
1138
1139#endif /* defined(HAVE_NICE) */
1140
1141#if defined(HAVE_GETPRIORITY)
1142
1143PyDoc_STRVAR(os_getpriority__doc__,
1144"getpriority($module, /, which, who)\n"
1145"--\n"
1146"\n"
1147"Return program scheduling priority.");
1148
1149#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001150 {"getpriority", (PyCFunction)os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001151
1152static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001153os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001154
1155static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001156os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001157{
1158 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001159 static const char * const _keywords[] = {"which", "who", NULL};
1160 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001161 int which;
1162 int who;
1163
Victor Stinner3e1fad62017-01-17 01:29:01 +01001164 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001165 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001166 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001167 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001168 return_value = os_getpriority_impl(module, which, who);
1169
1170exit:
1171 return return_value;
1172}
1173
1174#endif /* defined(HAVE_GETPRIORITY) */
1175
1176#if defined(HAVE_SETPRIORITY)
1177
1178PyDoc_STRVAR(os_setpriority__doc__,
1179"setpriority($module, /, which, who, priority)\n"
1180"--\n"
1181"\n"
1182"Set program scheduling priority.");
1183
1184#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001185 {"setpriority", (PyCFunction)os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001186
1187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001188os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001189
1190static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001191os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001192{
1193 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001194 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1195 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001196 int which;
1197 int who;
1198 int priority;
1199
Victor Stinner3e1fad62017-01-17 01:29:01 +01001200 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001201 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001202 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001203 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001204 return_value = os_setpriority_impl(module, which, who, priority);
1205
1206exit:
1207 return return_value;
1208}
1209
1210#endif /* defined(HAVE_SETPRIORITY) */
1211
1212PyDoc_STRVAR(os_rename__doc__,
1213"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1214"--\n"
1215"\n"
1216"Rename a file or directory.\n"
1217"\n"
1218"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1219" descriptor open to a directory, and the respective path string (src or dst)\n"
1220" should be relative; the path will then be relative to that directory.\n"
1221"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1222" If they are unavailable, using them will raise a NotImplementedError.");
1223
1224#define OS_RENAME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001225 {"rename", (PyCFunction)os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001226
1227static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001228os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001229 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001230
1231static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001232os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001233{
1234 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001235 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1236 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001237 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1238 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1239 int src_dir_fd = DEFAULT_DIR_FD;
1240 int dst_dir_fd = DEFAULT_DIR_FD;
1241
Victor Stinner3e1fad62017-01-17 01:29:01 +01001242 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001243 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 +03001244 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001245 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001246 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1247
1248exit:
1249 /* Cleanup for src */
1250 path_cleanup(&src);
1251 /* Cleanup for dst */
1252 path_cleanup(&dst);
1253
1254 return return_value;
1255}
1256
1257PyDoc_STRVAR(os_replace__doc__,
1258"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1259"--\n"
1260"\n"
1261"Rename a file or directory, overwriting the destination.\n"
1262"\n"
1263"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1264" descriptor open to a directory, and the respective path string (src or dst)\n"
1265" should be relative; the path will then be relative to that directory.\n"
1266"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1267" If they are unavailable, using them will raise a NotImplementedError.\"");
1268
1269#define OS_REPLACE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001270 {"replace", (PyCFunction)os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001271
1272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001273os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1274 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001275
1276static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001277os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001278{
1279 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001280 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1281 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001282 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1283 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1284 int src_dir_fd = DEFAULT_DIR_FD;
1285 int dst_dir_fd = DEFAULT_DIR_FD;
1286
Victor Stinner3e1fad62017-01-17 01:29:01 +01001287 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001288 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 +03001289 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001291 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1292
1293exit:
1294 /* Cleanup for src */
1295 path_cleanup(&src);
1296 /* Cleanup for dst */
1297 path_cleanup(&dst);
1298
1299 return return_value;
1300}
1301
1302PyDoc_STRVAR(os_rmdir__doc__,
1303"rmdir($module, /, path, *, dir_fd=None)\n"
1304"--\n"
1305"\n"
1306"Remove a directory.\n"
1307"\n"
1308"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1309" and path should be relative; path will then be relative to that directory.\n"
1310"dir_fd may not be implemented on your platform.\n"
1311" If it is unavailable, using it will raise a NotImplementedError.");
1312
1313#define OS_RMDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001314 {"rmdir", (PyCFunction)os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001315
1316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001317os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001318
1319static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001320os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001321{
1322 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001323 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1324 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001325 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1326 int dir_fd = DEFAULT_DIR_FD;
1327
Victor Stinner3e1fad62017-01-17 01:29:01 +01001328 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001329 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001332 return_value = os_rmdir_impl(module, &path, dir_fd);
1333
1334exit:
1335 /* Cleanup for path */
1336 path_cleanup(&path);
1337
1338 return return_value;
1339}
1340
1341#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1342
1343PyDoc_STRVAR(os_system__doc__,
1344"system($module, /, command)\n"
1345"--\n"
1346"\n"
1347"Execute the command in a subshell.");
1348
1349#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001350 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001351
1352static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001353os_system_impl(PyObject *module, Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354
1355static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001356os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001357{
1358 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001359 static const char * const _keywords[] = {"command", NULL};
1360 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001361 Py_UNICODE *command;
1362 long _return_value;
1363
Victor Stinner3e1fad62017-01-17 01:29:01 +01001364 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001366 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001367 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001368 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001369 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001370 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001371 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001372 return_value = PyLong_FromLong(_return_value);
1373
1374exit:
1375 return return_value;
1376}
1377
1378#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1379
1380#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1381
1382PyDoc_STRVAR(os_system__doc__,
1383"system($module, /, command)\n"
1384"--\n"
1385"\n"
1386"Execute the command in a subshell.");
1387
1388#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001389 {"system", (PyCFunction)os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390
1391static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001392os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393
1394static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001395os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001396{
1397 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001398 static const char * const _keywords[] = {"command", NULL};
1399 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001400 PyObject *command = NULL;
1401 long _return_value;
1402
Victor Stinner3e1fad62017-01-17 01:29:01 +01001403 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001404 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001405 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001406 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001407 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001408 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001409 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001410 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001411 return_value = PyLong_FromLong(_return_value);
1412
1413exit:
1414 /* Cleanup for command */
1415 Py_XDECREF(command);
1416
1417 return return_value;
1418}
1419
1420#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1421
1422PyDoc_STRVAR(os_umask__doc__,
1423"umask($module, mask, /)\n"
1424"--\n"
1425"\n"
1426"Set the current numeric umask and return the previous umask.");
1427
1428#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001429 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001430
1431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001432os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433
1434static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001435os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001436{
1437 PyObject *return_value = NULL;
1438 int mask;
1439
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001440 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001441 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001442 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001443 return_value = os_umask_impl(module, mask);
1444
1445exit:
1446 return return_value;
1447}
1448
1449PyDoc_STRVAR(os_unlink__doc__,
1450"unlink($module, /, path, *, dir_fd=None)\n"
1451"--\n"
1452"\n"
1453"Remove a file (same as remove()).\n"
1454"\n"
1455"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1456" and path should be relative; path will then be relative to that directory.\n"
1457"dir_fd may not be implemented on your platform.\n"
1458" If it is unavailable, using it will raise a NotImplementedError.");
1459
1460#define OS_UNLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001461 {"unlink", (PyCFunction)os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001462
1463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001464os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001465
1466static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001467os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001468{
1469 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001470 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1471 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001472 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1473 int dir_fd = DEFAULT_DIR_FD;
1474
Victor Stinner3e1fad62017-01-17 01:29:01 +01001475 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001476 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001477 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001478 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001479 return_value = os_unlink_impl(module, &path, dir_fd);
1480
1481exit:
1482 /* Cleanup for path */
1483 path_cleanup(&path);
1484
1485 return return_value;
1486}
1487
1488PyDoc_STRVAR(os_remove__doc__,
1489"remove($module, /, path, *, dir_fd=None)\n"
1490"--\n"
1491"\n"
1492"Remove a file (same as unlink()).\n"
1493"\n"
1494"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1495" and path should be relative; path will then be relative to that directory.\n"
1496"dir_fd may not be implemented on your platform.\n"
1497" If it is unavailable, using it will raise a NotImplementedError.");
1498
1499#define OS_REMOVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001500 {"remove", (PyCFunction)os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001501
1502static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001503os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001504
1505static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001506os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001507{
1508 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001509 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1510 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001511 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1512 int dir_fd = DEFAULT_DIR_FD;
1513
Victor Stinner3e1fad62017-01-17 01:29:01 +01001514 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001515 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001516 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001517 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001518 return_value = os_remove_impl(module, &path, dir_fd);
1519
1520exit:
1521 /* Cleanup for path */
1522 path_cleanup(&path);
1523
1524 return return_value;
1525}
1526
1527#if defined(HAVE_UNAME)
1528
1529PyDoc_STRVAR(os_uname__doc__,
1530"uname($module, /)\n"
1531"--\n"
1532"\n"
1533"Return an object identifying the current operating system.\n"
1534"\n"
1535"The object behaves like a named tuple with the following fields:\n"
1536" (sysname, nodename, release, version, machine)");
1537
1538#define OS_UNAME_METHODDEF \
1539 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1540
1541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001542os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001543
1544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001545os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001546{
1547 return os_uname_impl(module);
1548}
1549
1550#endif /* defined(HAVE_UNAME) */
1551
1552PyDoc_STRVAR(os_utime__doc__,
1553"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1554" follow_symlinks=True)\n"
1555"--\n"
1556"\n"
1557"Set the access and modified time of path.\n"
1558"\n"
1559"path may always be specified as a string.\n"
1560"On some platforms, path may also be specified as an open file descriptor.\n"
1561" If this functionality is unavailable, using it raises an exception.\n"
1562"\n"
1563"If times is not None, it must be a tuple (atime, mtime);\n"
1564" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001565"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001566" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1567" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001568"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001569"Specifying tuples for both times and ns is an error.\n"
1570"\n"
1571"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1572" and path should be relative; path will then be relative to that directory.\n"
1573"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1574" link, utime will modify the symbolic link itself instead of the file the\n"
1575" link points to.\n"
1576"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1577" as an open file descriptor.\n"
1578"dir_fd and follow_symlinks may not be available on your platform.\n"
1579" If they are unavailable, using them will raise a NotImplementedError.");
1580
1581#define OS_UTIME_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001582 {"utime", (PyCFunction)os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001583
1584static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001585os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1586 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001587
1588static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001589os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001590{
1591 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001592 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1593 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001594 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1595 PyObject *times = NULL;
1596 PyObject *ns = NULL;
1597 int dir_fd = DEFAULT_DIR_FD;
1598 int follow_symlinks = 1;
1599
Victor Stinner3e1fad62017-01-17 01:29:01 +01001600 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001601 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001604 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1605
1606exit:
1607 /* Cleanup for path */
1608 path_cleanup(&path);
1609
1610 return return_value;
1611}
1612
1613PyDoc_STRVAR(os__exit__doc__,
1614"_exit($module, /, status)\n"
1615"--\n"
1616"\n"
1617"Exit to the system with specified status, without normal exit processing.");
1618
1619#define OS__EXIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001620 {"_exit", (PyCFunction)os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001621
1622static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001623os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001624
1625static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001626os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627{
1628 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001629 static const char * const _keywords[] = {"status", NULL};
1630 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001631 int status;
1632
Victor Stinner3e1fad62017-01-17 01:29:01 +01001633 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001634 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001635 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001636 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001637 return_value = os__exit_impl(module, status);
1638
1639exit:
1640 return return_value;
1641}
1642
1643#if defined(HAVE_EXECV)
1644
1645PyDoc_STRVAR(os_execv__doc__,
1646"execv($module, path, argv, /)\n"
1647"--\n"
1648"\n"
1649"Execute an executable path with arguments, replacing current process.\n"
1650"\n"
1651" path\n"
1652" Path of executable file.\n"
1653" argv\n"
1654" Tuple or list of strings.");
1655
1656#define OS_EXECV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001657 {"execv", (PyCFunction)os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001658
1659static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001660os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001661
1662static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001663os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001664{
1665 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001666 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001667 PyObject *argv;
1668
Sylvain74453812017-06-10 06:51:48 +02001669 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1670 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001671 goto exit;
1672 }
Steve Dowercc16be82016-09-08 10:35:16 -07001673 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001674
1675exit:
1676 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001677 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001678
1679 return return_value;
1680}
1681
1682#endif /* defined(HAVE_EXECV) */
1683
1684#if defined(HAVE_EXECV)
1685
1686PyDoc_STRVAR(os_execve__doc__,
1687"execve($module, /, path, argv, env)\n"
1688"--\n"
1689"\n"
1690"Execute an executable path with arguments, replacing current process.\n"
1691"\n"
1692" path\n"
1693" Path of executable file.\n"
1694" argv\n"
1695" Tuple or list of strings.\n"
1696" env\n"
1697" Dictionary of strings mapping to strings.");
1698
1699#define OS_EXECVE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001700 {"execve", (PyCFunction)os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001701
1702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001703os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001704
1705static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001706os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001707{
1708 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001709 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1710 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1712 PyObject *argv;
1713 PyObject *env;
1714
Victor Stinner3e1fad62017-01-17 01:29:01 +01001715 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001716 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001717 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001718 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001719 return_value = os_execve_impl(module, &path, argv, env);
1720
1721exit:
1722 /* Cleanup for path */
1723 path_cleanup(&path);
1724
1725 return return_value;
1726}
1727
1728#endif /* defined(HAVE_EXECV) */
1729
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001730#if defined(HAVE_POSIX_SPAWN)
1731
1732PyDoc_STRVAR(os_posix_spawn__doc__,
Pablo Galindo254a4662018-09-07 16:44:24 +01001733"posix_spawn($module, path, argv, env, file_actions=None, /, *,\n"
1734" setpgroup=None, resetids=False, setsigmask=(),\n"
1735" setsigdef=(), scheduler=None)\n"
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001736"--\n"
1737"\n"
1738"Execute the program specified by path in a new process.\n"
1739"\n"
1740" path\n"
1741" Path of executable file.\n"
1742" argv\n"
1743" Tuple or list of strings.\n"
1744" env\n"
1745" Dictionary of strings mapping to strings.\n"
1746" file_actions\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001747" A sequence of file action tuples.\n"
1748" setpgroup\n"
1749" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1750" resetids\n"
1751" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
1752" setsigmask\n"
1753" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1754" setsigdef\n"
1755" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1756" scheduler\n"
1757" A tuple with the scheduler policy (optional) and parameters.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001758
1759#define OS_POSIX_SPAWN_METHODDEF \
Pablo Galindo254a4662018-09-07 16:44:24 +01001760 {"posix_spawn", (PyCFunction)os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001761
1762static PyObject *
1763os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
Pablo Galindo254a4662018-09-07 16:44:24 +01001764 PyObject *env, PyObject *file_actions,
1765 PyObject *setpgroup, int resetids, PyObject *setsigmask,
1766 PyObject *setsigdef, PyObject *scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001767
1768static PyObject *
Pablo Galindo254a4662018-09-07 16:44:24 +01001769os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001770{
1771 PyObject *return_value = NULL;
Pablo Galindo254a4662018-09-07 16:44:24 +01001772 static const char * const _keywords[] = {"", "", "", "", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL};
1773 static _PyArg_Parser _parser = {"O&OO|O$OiOOO:posix_spawn", _keywords, 0};
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001774 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1775 PyObject *argv;
1776 PyObject *env;
1777 PyObject *file_actions = Py_None;
Pablo Galindo254a4662018-09-07 16:44:24 +01001778 PyObject *setpgroup = NULL;
1779 int resetids = 0;
1780 PyObject *setsigmask = NULL;
1781 PyObject *setsigdef = NULL;
1782 PyObject *scheduler = NULL;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001783
Pablo Galindo254a4662018-09-07 16:44:24 +01001784 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1785 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) {
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001786 goto exit;
1787 }
Pablo Galindo254a4662018-09-07 16:44:24 +01001788 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001789
1790exit:
1791 /* Cleanup for path */
1792 path_cleanup(&path);
1793
1794 return return_value;
1795}
1796
1797#endif /* defined(HAVE_POSIX_SPAWN) */
1798
Steve Dowercc16be82016-09-08 10:35:16 -07001799#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001800
1801PyDoc_STRVAR(os_spawnv__doc__,
1802"spawnv($module, mode, path, argv, /)\n"
1803"--\n"
1804"\n"
1805"Execute the program specified by path in a new process.\n"
1806"\n"
1807" mode\n"
1808" Mode of process creation.\n"
1809" path\n"
1810" Path of executable file.\n"
1811" argv\n"
1812" Tuple or list of strings.");
1813
1814#define OS_SPAWNV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001815 {"spawnv", (PyCFunction)os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001816
1817static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001818os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001819
1820static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001821os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001822{
1823 PyObject *return_value = NULL;
1824 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001825 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001826 PyObject *argv;
1827
Sylvain74453812017-06-10 06:51:48 +02001828 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1829 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001830 goto exit;
1831 }
Steve Dowercc16be82016-09-08 10:35:16 -07001832 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001833
1834exit:
1835 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001836 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001837
1838 return return_value;
1839}
1840
Steve Dowercc16be82016-09-08 10:35:16 -07001841#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001842
Steve Dowercc16be82016-09-08 10:35:16 -07001843#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001844
1845PyDoc_STRVAR(os_spawnve__doc__,
1846"spawnve($module, mode, path, argv, env, /)\n"
1847"--\n"
1848"\n"
1849"Execute the program specified by path in a new process.\n"
1850"\n"
1851" mode\n"
1852" Mode of process creation.\n"
1853" path\n"
1854" Path of executable file.\n"
1855" argv\n"
1856" Tuple or list of strings.\n"
1857" env\n"
1858" Dictionary of strings mapping to strings.");
1859
1860#define OS_SPAWNVE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001861 {"spawnve", (PyCFunction)os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001862
1863static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001864os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001865 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001866
1867static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001868os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001869{
1870 PyObject *return_value = NULL;
1871 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001872 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001873 PyObject *argv;
1874 PyObject *env;
1875
Sylvain74453812017-06-10 06:51:48 +02001876 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1877 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001878 goto exit;
1879 }
Steve Dowercc16be82016-09-08 10:35:16 -07001880 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001881
1882exit:
1883 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001884 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001885
1886 return return_value;
1887}
1888
Steve Dowercc16be82016-09-08 10:35:16 -07001889#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001890
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001891#if defined(HAVE_FORK)
1892
1893PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001894"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1895" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001896"--\n"
1897"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001898"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001899"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001900" before\n"
1901" A callable to be called in the parent before the fork() syscall.\n"
1902" after_in_child\n"
1903" A callable to be called in the child after fork().\n"
1904" after_in_parent\n"
1905" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001906"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001907"\'before\' callbacks are called in reverse order.\n"
1908"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001909
1910#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001911 {"register_at_fork", (PyCFunction)os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001912
1913static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001914os_register_at_fork_impl(PyObject *module, PyObject *before,
1915 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001916
1917static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001918os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001919{
1920 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001921 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1922 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1923 PyObject *before = NULL;
1924 PyObject *after_in_child = NULL;
1925 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001926
1927 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001928 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001929 goto exit;
1930 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001931 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001932
1933exit:
1934 return return_value;
1935}
1936
1937#endif /* defined(HAVE_FORK) */
1938
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001939#if defined(HAVE_FORK1)
1940
1941PyDoc_STRVAR(os_fork1__doc__,
1942"fork1($module, /)\n"
1943"--\n"
1944"\n"
1945"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1946"\n"
1947"Return 0 to child process and PID of child to parent process.");
1948
1949#define OS_FORK1_METHODDEF \
1950 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1951
1952static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001953os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001954
1955static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001956os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001957{
1958 return os_fork1_impl(module);
1959}
1960
1961#endif /* defined(HAVE_FORK1) */
1962
1963#if defined(HAVE_FORK)
1964
1965PyDoc_STRVAR(os_fork__doc__,
1966"fork($module, /)\n"
1967"--\n"
1968"\n"
1969"Fork a child process.\n"
1970"\n"
1971"Return 0 to child process and PID of child to parent process.");
1972
1973#define OS_FORK_METHODDEF \
1974 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1975
1976static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001977os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001978
1979static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001980os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001981{
1982 return os_fork_impl(module);
1983}
1984
1985#endif /* defined(HAVE_FORK) */
1986
1987#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1988
1989PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1990"sched_get_priority_max($module, /, policy)\n"
1991"--\n"
1992"\n"
1993"Get the maximum scheduling priority for policy.");
1994
1995#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03001996 {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001997
1998static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001999os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002000
2001static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002002os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003{
2004 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002005 static const char * const _keywords[] = {"policy", NULL};
2006 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002007 int policy;
2008
Victor Stinner3e1fad62017-01-17 01:29:01 +01002009 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002010 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002011 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002012 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002013 return_value = os_sched_get_priority_max_impl(module, policy);
2014
2015exit:
2016 return return_value;
2017}
2018
2019#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2020
2021#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2022
2023PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2024"sched_get_priority_min($module, /, policy)\n"
2025"--\n"
2026"\n"
2027"Get the minimum scheduling priority for policy.");
2028
2029#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002030 {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002031
2032static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002033os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002034
2035static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002036os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002037{
2038 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002039 static const char * const _keywords[] = {"policy", NULL};
2040 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002041 int policy;
2042
Victor Stinner3e1fad62017-01-17 01:29:01 +01002043 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002044 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002045 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002046 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002047 return_value = os_sched_get_priority_min_impl(module, policy);
2048
2049exit:
2050 return return_value;
2051}
2052
2053#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2054
2055#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2056
2057PyDoc_STRVAR(os_sched_getscheduler__doc__,
2058"sched_getscheduler($module, pid, /)\n"
2059"--\n"
2060"\n"
2061"Get the scheduling policy for the process identifiedy by pid.\n"
2062"\n"
2063"Passing 0 for pid returns the scheduling policy for the calling process.");
2064
2065#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002066 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002067
2068static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002069os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002070
2071static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002072os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002073{
2074 PyObject *return_value = NULL;
2075 pid_t pid;
2076
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002077 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002078 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002079 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002080 return_value = os_sched_getscheduler_impl(module, pid);
2081
2082exit:
2083 return return_value;
2084}
2085
2086#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2087
2088#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM))
2089
2090PyDoc_STRVAR(os_sched_param__doc__,
2091"sched_param(sched_priority)\n"
2092"--\n"
2093"\n"
2094"Current has only one field: sched_priority\");\n"
2095"\n"
2096" sched_priority\n"
2097" A scheduling parameter.");
2098
2099static PyObject *
2100os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2101
2102static PyObject *
2103os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2104{
2105 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002106 static const char * const _keywords[] = {"sched_priority", NULL};
2107 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002108 PyObject *sched_priority;
2109
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002110 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002111 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002112 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002113 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002114 return_value = os_sched_param_impl(type, sched_priority);
2115
2116exit:
2117 return return_value;
2118}
2119
2120#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)) */
2121
2122#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2123
2124PyDoc_STRVAR(os_sched_setscheduler__doc__,
2125"sched_setscheduler($module, pid, policy, param, /)\n"
2126"--\n"
2127"\n"
2128"Set the scheduling policy for the process identified by pid.\n"
2129"\n"
2130"If pid is 0, the calling process is changed.\n"
2131"param is an instance of sched_param.");
2132
2133#define OS_SCHED_SETSCHEDULER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002134 {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002135
2136static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002137os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002138 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002139
2140static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002141os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002142{
2143 PyObject *return_value = NULL;
2144 pid_t pid;
2145 int policy;
2146 struct sched_param param;
2147
Sylvain74453812017-06-10 06:51:48 +02002148 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2149 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002150 goto exit;
2151 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002152 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2153
2154exit:
2155 return return_value;
2156}
2157
2158#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2159
2160#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2161
2162PyDoc_STRVAR(os_sched_getparam__doc__,
2163"sched_getparam($module, pid, /)\n"
2164"--\n"
2165"\n"
2166"Returns scheduling parameters for the process identified by pid.\n"
2167"\n"
2168"If pid is 0, returns parameters for the calling process.\n"
2169"Return value is an instance of sched_param.");
2170
2171#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002172 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002173
2174static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002175os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002176
2177static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002178os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002179{
2180 PyObject *return_value = NULL;
2181 pid_t pid;
2182
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002183 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002184 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002185 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002186 return_value = os_sched_getparam_impl(module, pid);
2187
2188exit:
2189 return return_value;
2190}
2191
2192#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2193
2194#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2195
2196PyDoc_STRVAR(os_sched_setparam__doc__,
2197"sched_setparam($module, pid, param, /)\n"
2198"--\n"
2199"\n"
2200"Set scheduling parameters for the process identified by pid.\n"
2201"\n"
2202"If pid is 0, sets parameters for the calling process.\n"
2203"param should be an instance of sched_param.");
2204
2205#define OS_SCHED_SETPARAM_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002206 {"sched_setparam", (PyCFunction)os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002207
2208static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002209os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002210 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002211
2212static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002213os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002214{
2215 PyObject *return_value = NULL;
2216 pid_t pid;
2217 struct sched_param param;
2218
Sylvain74453812017-06-10 06:51:48 +02002219 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2220 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002221 goto exit;
2222 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002223 return_value = os_sched_setparam_impl(module, pid, &param);
2224
2225exit:
2226 return return_value;
2227}
2228
2229#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2230
2231#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2232
2233PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2234"sched_rr_get_interval($module, pid, /)\n"
2235"--\n"
2236"\n"
2237"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2238"\n"
2239"Value returned is a float.");
2240
2241#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002242 {"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 +03002243
2244static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002245os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002246
2247static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002248os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002249{
2250 PyObject *return_value = NULL;
2251 pid_t pid;
2252 double _return_value;
2253
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002254 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002255 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002256 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002257 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002258 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002259 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002260 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002261 return_value = PyFloat_FromDouble(_return_value);
2262
2263exit:
2264 return return_value;
2265}
2266
2267#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2268
2269#if defined(HAVE_SCHED_H)
2270
2271PyDoc_STRVAR(os_sched_yield__doc__,
2272"sched_yield($module, /)\n"
2273"--\n"
2274"\n"
2275"Voluntarily relinquish the CPU.");
2276
2277#define OS_SCHED_YIELD_METHODDEF \
2278 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2279
2280static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002281os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002282
2283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002284os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002285{
2286 return os_sched_yield_impl(module);
2287}
2288
2289#endif /* defined(HAVE_SCHED_H) */
2290
2291#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2292
2293PyDoc_STRVAR(os_sched_setaffinity__doc__,
2294"sched_setaffinity($module, pid, mask, /)\n"
2295"--\n"
2296"\n"
2297"Set the CPU affinity of the process identified by pid to mask.\n"
2298"\n"
2299"mask should be an iterable of integers identifying CPUs.");
2300
2301#define OS_SCHED_SETAFFINITY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002302 {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002303
2304static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002305os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002306
2307static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002308os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002309{
2310 PyObject *return_value = NULL;
2311 pid_t pid;
2312 PyObject *mask;
2313
Sylvain74453812017-06-10 06:51:48 +02002314 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2315 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002316 goto exit;
2317 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002318 return_value = os_sched_setaffinity_impl(module, pid, mask);
2319
2320exit:
2321 return return_value;
2322}
2323
2324#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2325
2326#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2327
2328PyDoc_STRVAR(os_sched_getaffinity__doc__,
2329"sched_getaffinity($module, pid, /)\n"
2330"--\n"
2331"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002332"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002333"\n"
2334"The affinity is returned as a set of CPU identifiers.");
2335
2336#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002337 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002338
2339static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002340os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002341
2342static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002343os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002344{
2345 PyObject *return_value = NULL;
2346 pid_t pid;
2347
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002348 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002349 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002350 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002351 return_value = os_sched_getaffinity_impl(module, pid);
2352
2353exit:
2354 return return_value;
2355}
2356
2357#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2358
2359#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2360
2361PyDoc_STRVAR(os_openpty__doc__,
2362"openpty($module, /)\n"
2363"--\n"
2364"\n"
2365"Open a pseudo-terminal.\n"
2366"\n"
2367"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2368"for both the master and slave ends.");
2369
2370#define OS_OPENPTY_METHODDEF \
2371 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2372
2373static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002374os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002375
2376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002377os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002378{
2379 return os_openpty_impl(module);
2380}
2381
2382#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2383
2384#if defined(HAVE_FORKPTY)
2385
2386PyDoc_STRVAR(os_forkpty__doc__,
2387"forkpty($module, /)\n"
2388"--\n"
2389"\n"
2390"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2391"\n"
2392"Returns a tuple of (pid, master_fd).\n"
2393"Like fork(), return pid of 0 to the child process,\n"
2394"and pid of child to the parent process.\n"
2395"To both, return fd of newly opened pseudo-terminal.");
2396
2397#define OS_FORKPTY_METHODDEF \
2398 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2399
2400static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002401os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002402
2403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002404os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002405{
2406 return os_forkpty_impl(module);
2407}
2408
2409#endif /* defined(HAVE_FORKPTY) */
2410
2411#if defined(HAVE_GETEGID)
2412
2413PyDoc_STRVAR(os_getegid__doc__,
2414"getegid($module, /)\n"
2415"--\n"
2416"\n"
2417"Return the current process\'s effective group id.");
2418
2419#define OS_GETEGID_METHODDEF \
2420 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2421
2422static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002423os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002424
2425static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002426os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002427{
2428 return os_getegid_impl(module);
2429}
2430
2431#endif /* defined(HAVE_GETEGID) */
2432
2433#if defined(HAVE_GETEUID)
2434
2435PyDoc_STRVAR(os_geteuid__doc__,
2436"geteuid($module, /)\n"
2437"--\n"
2438"\n"
2439"Return the current process\'s effective user id.");
2440
2441#define OS_GETEUID_METHODDEF \
2442 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2443
2444static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002445os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002446
2447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002448os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002449{
2450 return os_geteuid_impl(module);
2451}
2452
2453#endif /* defined(HAVE_GETEUID) */
2454
2455#if defined(HAVE_GETGID)
2456
2457PyDoc_STRVAR(os_getgid__doc__,
2458"getgid($module, /)\n"
2459"--\n"
2460"\n"
2461"Return the current process\'s group id.");
2462
2463#define OS_GETGID_METHODDEF \
2464 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2465
2466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002467os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002468
2469static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002470os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002471{
2472 return os_getgid_impl(module);
2473}
2474
2475#endif /* defined(HAVE_GETGID) */
2476
Berker Peksag39404992016-09-15 20:45:16 +03002477#if defined(HAVE_GETPID)
2478
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002479PyDoc_STRVAR(os_getpid__doc__,
2480"getpid($module, /)\n"
2481"--\n"
2482"\n"
2483"Return the current process id.");
2484
2485#define OS_GETPID_METHODDEF \
2486 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2487
2488static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002489os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002490
2491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002492os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002493{
2494 return os_getpid_impl(module);
2495}
2496
Berker Peksag39404992016-09-15 20:45:16 +03002497#endif /* defined(HAVE_GETPID) */
2498
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002499#if defined(HAVE_GETGROUPS)
2500
2501PyDoc_STRVAR(os_getgroups__doc__,
2502"getgroups($module, /)\n"
2503"--\n"
2504"\n"
2505"Return list of supplemental group IDs for the process.");
2506
2507#define OS_GETGROUPS_METHODDEF \
2508 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2509
2510static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002511os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002512
2513static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002514os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002515{
2516 return os_getgroups_impl(module);
2517}
2518
2519#endif /* defined(HAVE_GETGROUPS) */
2520
2521#if defined(HAVE_GETPGID)
2522
2523PyDoc_STRVAR(os_getpgid__doc__,
2524"getpgid($module, /, pid)\n"
2525"--\n"
2526"\n"
2527"Call the system call getpgid(), and return the result.");
2528
2529#define OS_GETPGID_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002530 {"getpgid", (PyCFunction)os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002531
2532static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002533os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002534
2535static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002536os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002537{
2538 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002539 static const char * const _keywords[] = {"pid", NULL};
2540 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002541 pid_t pid;
2542
Victor Stinner3e1fad62017-01-17 01:29:01 +01002543 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002544 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002545 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002546 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002547 return_value = os_getpgid_impl(module, pid);
2548
2549exit:
2550 return return_value;
2551}
2552
2553#endif /* defined(HAVE_GETPGID) */
2554
2555#if defined(HAVE_GETPGRP)
2556
2557PyDoc_STRVAR(os_getpgrp__doc__,
2558"getpgrp($module, /)\n"
2559"--\n"
2560"\n"
2561"Return the current process group id.");
2562
2563#define OS_GETPGRP_METHODDEF \
2564 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2565
2566static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002567os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002568
2569static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002570os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002571{
2572 return os_getpgrp_impl(module);
2573}
2574
2575#endif /* defined(HAVE_GETPGRP) */
2576
2577#if defined(HAVE_SETPGRP)
2578
2579PyDoc_STRVAR(os_setpgrp__doc__,
2580"setpgrp($module, /)\n"
2581"--\n"
2582"\n"
2583"Make the current process the leader of its process group.");
2584
2585#define OS_SETPGRP_METHODDEF \
2586 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2587
2588static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002589os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002590
2591static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002592os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002593{
2594 return os_setpgrp_impl(module);
2595}
2596
2597#endif /* defined(HAVE_SETPGRP) */
2598
2599#if defined(HAVE_GETPPID)
2600
2601PyDoc_STRVAR(os_getppid__doc__,
2602"getppid($module, /)\n"
2603"--\n"
2604"\n"
2605"Return the parent\'s process id.\n"
2606"\n"
2607"If the parent process has already exited, Windows machines will still\n"
2608"return its id; others systems will return the id of the \'init\' process (1).");
2609
2610#define OS_GETPPID_METHODDEF \
2611 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2612
2613static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002614os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002615
2616static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002617os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002618{
2619 return os_getppid_impl(module);
2620}
2621
2622#endif /* defined(HAVE_GETPPID) */
2623
2624#if defined(HAVE_GETLOGIN)
2625
2626PyDoc_STRVAR(os_getlogin__doc__,
2627"getlogin($module, /)\n"
2628"--\n"
2629"\n"
2630"Return the actual login name.");
2631
2632#define OS_GETLOGIN_METHODDEF \
2633 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2634
2635static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002636os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002637
2638static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002639os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002640{
2641 return os_getlogin_impl(module);
2642}
2643
2644#endif /* defined(HAVE_GETLOGIN) */
2645
2646#if defined(HAVE_GETUID)
2647
2648PyDoc_STRVAR(os_getuid__doc__,
2649"getuid($module, /)\n"
2650"--\n"
2651"\n"
2652"Return the current process\'s user id.");
2653
2654#define OS_GETUID_METHODDEF \
2655 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2656
2657static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002658os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002659
2660static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002661os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002662{
2663 return os_getuid_impl(module);
2664}
2665
2666#endif /* defined(HAVE_GETUID) */
2667
2668#if defined(HAVE_KILL)
2669
2670PyDoc_STRVAR(os_kill__doc__,
2671"kill($module, pid, signal, /)\n"
2672"--\n"
2673"\n"
2674"Kill a process with a signal.");
2675
2676#define OS_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002677 {"kill", (PyCFunction)os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002678
2679static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002680os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002681
2682static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002683os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002684{
2685 PyObject *return_value = NULL;
2686 pid_t pid;
2687 Py_ssize_t signal;
2688
Sylvain74453812017-06-10 06:51:48 +02002689 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2690 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002691 goto exit;
2692 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002693 return_value = os_kill_impl(module, pid, signal);
2694
2695exit:
2696 return return_value;
2697}
2698
2699#endif /* defined(HAVE_KILL) */
2700
2701#if defined(HAVE_KILLPG)
2702
2703PyDoc_STRVAR(os_killpg__doc__,
2704"killpg($module, pgid, signal, /)\n"
2705"--\n"
2706"\n"
2707"Kill a process group with a signal.");
2708
2709#define OS_KILLPG_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002710 {"killpg", (PyCFunction)os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002711
2712static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002713os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002714
2715static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002716os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002717{
2718 PyObject *return_value = NULL;
2719 pid_t pgid;
2720 int signal;
2721
Sylvain74453812017-06-10 06:51:48 +02002722 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2723 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002724 goto exit;
2725 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002726 return_value = os_killpg_impl(module, pgid, signal);
2727
2728exit:
2729 return return_value;
2730}
2731
2732#endif /* defined(HAVE_KILLPG) */
2733
2734#if defined(HAVE_PLOCK)
2735
2736PyDoc_STRVAR(os_plock__doc__,
2737"plock($module, op, /)\n"
2738"--\n"
2739"\n"
2740"Lock program segments into memory.\");");
2741
2742#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002743 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002744
2745static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002746os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002747
2748static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002749os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002750{
2751 PyObject *return_value = NULL;
2752 int op;
2753
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002754 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002755 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002756 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002757 return_value = os_plock_impl(module, op);
2758
2759exit:
2760 return return_value;
2761}
2762
2763#endif /* defined(HAVE_PLOCK) */
2764
2765#if defined(HAVE_SETUID)
2766
2767PyDoc_STRVAR(os_setuid__doc__,
2768"setuid($module, uid, /)\n"
2769"--\n"
2770"\n"
2771"Set the current process\'s user id.");
2772
2773#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002774 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002775
2776static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002777os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002778
2779static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002780os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002781{
2782 PyObject *return_value = NULL;
2783 uid_t uid;
2784
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002785 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002786 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002787 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002788 return_value = os_setuid_impl(module, uid);
2789
2790exit:
2791 return return_value;
2792}
2793
2794#endif /* defined(HAVE_SETUID) */
2795
2796#if defined(HAVE_SETEUID)
2797
2798PyDoc_STRVAR(os_seteuid__doc__,
2799"seteuid($module, euid, /)\n"
2800"--\n"
2801"\n"
2802"Set the current process\'s effective user id.");
2803
2804#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002805 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002806
2807static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002808os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002809
2810static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002811os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002812{
2813 PyObject *return_value = NULL;
2814 uid_t euid;
2815
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002816 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002817 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002818 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002819 return_value = os_seteuid_impl(module, euid);
2820
2821exit:
2822 return return_value;
2823}
2824
2825#endif /* defined(HAVE_SETEUID) */
2826
2827#if defined(HAVE_SETEGID)
2828
2829PyDoc_STRVAR(os_setegid__doc__,
2830"setegid($module, egid, /)\n"
2831"--\n"
2832"\n"
2833"Set the current process\'s effective group id.");
2834
2835#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002836 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002837
2838static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002839os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002840
2841static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002842os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002843{
2844 PyObject *return_value = NULL;
2845 gid_t egid;
2846
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002847 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002848 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002849 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002850 return_value = os_setegid_impl(module, egid);
2851
2852exit:
2853 return return_value;
2854}
2855
2856#endif /* defined(HAVE_SETEGID) */
2857
2858#if defined(HAVE_SETREUID)
2859
2860PyDoc_STRVAR(os_setreuid__doc__,
2861"setreuid($module, ruid, euid, /)\n"
2862"--\n"
2863"\n"
2864"Set the current process\'s real and effective user ids.");
2865
2866#define OS_SETREUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002867 {"setreuid", (PyCFunction)os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002868
2869static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002870os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002871
2872static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002873os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002874{
2875 PyObject *return_value = NULL;
2876 uid_t ruid;
2877 uid_t euid;
2878
Sylvain74453812017-06-10 06:51:48 +02002879 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2880 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002881 goto exit;
2882 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002883 return_value = os_setreuid_impl(module, ruid, euid);
2884
2885exit:
2886 return return_value;
2887}
2888
2889#endif /* defined(HAVE_SETREUID) */
2890
2891#if defined(HAVE_SETREGID)
2892
2893PyDoc_STRVAR(os_setregid__doc__,
2894"setregid($module, rgid, egid, /)\n"
2895"--\n"
2896"\n"
2897"Set the current process\'s real and effective group ids.");
2898
2899#define OS_SETREGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01002900 {"setregid", (PyCFunction)os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002901
2902static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002903os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002904
2905static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002906os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002907{
2908 PyObject *return_value = NULL;
2909 gid_t rgid;
2910 gid_t egid;
2911
Sylvain74453812017-06-10 06:51:48 +02002912 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2913 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002914 goto exit;
2915 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002916 return_value = os_setregid_impl(module, rgid, egid);
2917
2918exit:
2919 return return_value;
2920}
2921
2922#endif /* defined(HAVE_SETREGID) */
2923
2924#if defined(HAVE_SETGID)
2925
2926PyDoc_STRVAR(os_setgid__doc__,
2927"setgid($module, gid, /)\n"
2928"--\n"
2929"\n"
2930"Set the current process\'s group id.");
2931
2932#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002933 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002934
2935static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002936os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002937
2938static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002939os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002940{
2941 PyObject *return_value = NULL;
2942 gid_t gid;
2943
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002944 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002945 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002946 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002947 return_value = os_setgid_impl(module, gid);
2948
2949exit:
2950 return return_value;
2951}
2952
2953#endif /* defined(HAVE_SETGID) */
2954
2955#if defined(HAVE_SETGROUPS)
2956
2957PyDoc_STRVAR(os_setgroups__doc__,
2958"setgroups($module, groups, /)\n"
2959"--\n"
2960"\n"
2961"Set the groups of the current process to list.");
2962
2963#define OS_SETGROUPS_METHODDEF \
2964 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2965
2966#endif /* defined(HAVE_SETGROUPS) */
2967
2968#if defined(HAVE_WAIT3)
2969
2970PyDoc_STRVAR(os_wait3__doc__,
2971"wait3($module, /, options)\n"
2972"--\n"
2973"\n"
2974"Wait for completion of a child process.\n"
2975"\n"
2976"Returns a tuple of information about the child process:\n"
2977" (pid, status, rusage)");
2978
2979#define OS_WAIT3_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03002980 {"wait3", (PyCFunction)os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002981
2982static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002983os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002984
2985static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002986os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002987{
2988 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002989 static const char * const _keywords[] = {"options", NULL};
2990 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002991 int options;
2992
Victor Stinner3e1fad62017-01-17 01:29:01 +01002993 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002994 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002996 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002997 return_value = os_wait3_impl(module, options);
2998
2999exit:
3000 return return_value;
3001}
3002
3003#endif /* defined(HAVE_WAIT3) */
3004
3005#if defined(HAVE_WAIT4)
3006
3007PyDoc_STRVAR(os_wait4__doc__,
3008"wait4($module, /, pid, options)\n"
3009"--\n"
3010"\n"
3011"Wait for completion of a specific child process.\n"
3012"\n"
3013"Returns a tuple of information about the child process:\n"
3014" (pid, status, rusage)");
3015
3016#define OS_WAIT4_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003017 {"wait4", (PyCFunction)os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003018
3019static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003020os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003021
3022static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003023os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003024{
3025 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003026 static const char * const _keywords[] = {"pid", "options", NULL};
3027 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003028 pid_t pid;
3029 int options;
3030
Victor Stinner3e1fad62017-01-17 01:29:01 +01003031 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003032 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003033 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003034 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003035 return_value = os_wait4_impl(module, pid, options);
3036
3037exit:
3038 return return_value;
3039}
3040
3041#endif /* defined(HAVE_WAIT4) */
3042
3043#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3044
3045PyDoc_STRVAR(os_waitid__doc__,
3046"waitid($module, idtype, id, options, /)\n"
3047"--\n"
3048"\n"
3049"Returns the result of waiting for a process or processes.\n"
3050"\n"
3051" idtype\n"
3052" Must be one of be P_PID, P_PGID or P_ALL.\n"
3053" id\n"
3054" The id to wait on.\n"
3055" options\n"
3056" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3057" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3058"\n"
3059"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3060"no children in a waitable state.");
3061
3062#define OS_WAITID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003063 {"waitid", (PyCFunction)os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003064
3065static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003066os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003067
3068static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003069os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003070{
3071 PyObject *return_value = NULL;
3072 idtype_t idtype;
3073 id_t id;
3074 int options;
3075
Sylvain74453812017-06-10 06:51:48 +02003076 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3077 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003078 goto exit;
3079 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003080 return_value = os_waitid_impl(module, idtype, id, options);
3081
3082exit:
3083 return return_value;
3084}
3085
3086#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3087
3088#if defined(HAVE_WAITPID)
3089
3090PyDoc_STRVAR(os_waitpid__doc__,
3091"waitpid($module, pid, options, /)\n"
3092"--\n"
3093"\n"
3094"Wait for completion of a given child process.\n"
3095"\n"
3096"Returns a tuple of information regarding the child process:\n"
3097" (pid, status)\n"
3098"\n"
3099"The options argument is ignored on Windows.");
3100
3101#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003102 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003103
3104static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003105os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003106
3107static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003108os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003109{
3110 PyObject *return_value = NULL;
3111 pid_t pid;
3112 int options;
3113
Sylvain74453812017-06-10 06:51:48 +02003114 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3115 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003116 goto exit;
3117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003118 return_value = os_waitpid_impl(module, pid, options);
3119
3120exit:
3121 return return_value;
3122}
3123
3124#endif /* defined(HAVE_WAITPID) */
3125
3126#if defined(HAVE_CWAIT)
3127
3128PyDoc_STRVAR(os_waitpid__doc__,
3129"waitpid($module, pid, options, /)\n"
3130"--\n"
3131"\n"
3132"Wait for completion of a given process.\n"
3133"\n"
3134"Returns a tuple of information regarding the process:\n"
3135" (pid, status << 8)\n"
3136"\n"
3137"The options argument is ignored on Windows.");
3138
3139#define OS_WAITPID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003140 {"waitpid", (PyCFunction)os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003141
3142static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003143os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003144
3145static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003146os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003147{
3148 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003149 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003150 int options;
3151
Sylvain74453812017-06-10 06:51:48 +02003152 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3153 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003154 goto exit;
3155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003156 return_value = os_waitpid_impl(module, pid, options);
3157
3158exit:
3159 return return_value;
3160}
3161
3162#endif /* defined(HAVE_CWAIT) */
3163
3164#if defined(HAVE_WAIT)
3165
3166PyDoc_STRVAR(os_wait__doc__,
3167"wait($module, /)\n"
3168"--\n"
3169"\n"
3170"Wait for completion of a child process.\n"
3171"\n"
3172"Returns a tuple of information about the child process:\n"
3173" (pid, status)");
3174
3175#define OS_WAIT_METHODDEF \
3176 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3177
3178static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003179os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003180
3181static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003182os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003183{
3184 return os_wait_impl(module);
3185}
3186
3187#endif /* defined(HAVE_WAIT) */
3188
3189#if defined(HAVE_SYMLINK)
3190
3191PyDoc_STRVAR(os_symlink__doc__,
3192"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3193"--\n"
3194"\n"
3195"Create a symbolic link pointing to src named dst.\n"
3196"\n"
3197"target_is_directory is required on Windows if the target is to be\n"
3198" interpreted as a directory. (On Windows, symlink requires\n"
3199" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3200" target_is_directory is ignored on non-Windows platforms.\n"
3201"\n"
3202"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3203" and path should be relative; path will then be relative to that directory.\n"
3204"dir_fd may not be implemented on your platform.\n"
3205" If it is unavailable, using it will raise a NotImplementedError.");
3206
3207#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003208 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209
3210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003211os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003212 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003213
3214static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003215os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003216{
3217 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003218 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3219 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003220 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3221 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3222 int target_is_directory = 0;
3223 int dir_fd = DEFAULT_DIR_FD;
3224
Victor Stinner3e1fad62017-01-17 01:29:01 +01003225 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003226 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003227 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003228 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003229 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3230
3231exit:
3232 /* Cleanup for src */
3233 path_cleanup(&src);
3234 /* Cleanup for dst */
3235 path_cleanup(&dst);
3236
3237 return return_value;
3238}
3239
3240#endif /* defined(HAVE_SYMLINK) */
3241
3242#if defined(HAVE_TIMES)
3243
3244PyDoc_STRVAR(os_times__doc__,
3245"times($module, /)\n"
3246"--\n"
3247"\n"
3248"Return a collection containing process timing information.\n"
3249"\n"
3250"The object returned behaves like a named tuple with these fields:\n"
3251" (utime, stime, cutime, cstime, elapsed_time)\n"
3252"All fields are floating point numbers.");
3253
3254#define OS_TIMES_METHODDEF \
3255 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3256
3257static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003258os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003259
3260static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003261os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262{
3263 return os_times_impl(module);
3264}
3265
3266#endif /* defined(HAVE_TIMES) */
3267
3268#if defined(HAVE_GETSID)
3269
3270PyDoc_STRVAR(os_getsid__doc__,
3271"getsid($module, pid, /)\n"
3272"--\n"
3273"\n"
3274"Call the system call getsid(pid) and return the result.");
3275
3276#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003277 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003278
3279static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003280os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003281
3282static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003283os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003284{
3285 PyObject *return_value = NULL;
3286 pid_t pid;
3287
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003288 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003289 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003290 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003291 return_value = os_getsid_impl(module, pid);
3292
3293exit:
3294 return return_value;
3295}
3296
3297#endif /* defined(HAVE_GETSID) */
3298
3299#if defined(HAVE_SETSID)
3300
3301PyDoc_STRVAR(os_setsid__doc__,
3302"setsid($module, /)\n"
3303"--\n"
3304"\n"
3305"Call the system call setsid().");
3306
3307#define OS_SETSID_METHODDEF \
3308 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3309
3310static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003311os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003312
3313static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003314os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003315{
3316 return os_setsid_impl(module);
3317}
3318
3319#endif /* defined(HAVE_SETSID) */
3320
3321#if defined(HAVE_SETPGID)
3322
3323PyDoc_STRVAR(os_setpgid__doc__,
3324"setpgid($module, pid, pgrp, /)\n"
3325"--\n"
3326"\n"
3327"Call the system call setpgid(pid, pgrp).");
3328
3329#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003330 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003331
3332static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003333os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003334
3335static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003336os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003337{
3338 PyObject *return_value = NULL;
3339 pid_t pid;
3340 pid_t pgrp;
3341
Sylvain74453812017-06-10 06:51:48 +02003342 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3343 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003344 goto exit;
3345 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003346 return_value = os_setpgid_impl(module, pid, pgrp);
3347
3348exit:
3349 return return_value;
3350}
3351
3352#endif /* defined(HAVE_SETPGID) */
3353
3354#if defined(HAVE_TCGETPGRP)
3355
3356PyDoc_STRVAR(os_tcgetpgrp__doc__,
3357"tcgetpgrp($module, fd, /)\n"
3358"--\n"
3359"\n"
3360"Return the process group associated with the terminal specified by fd.");
3361
3362#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003363 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003364
3365static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003366os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003367
3368static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003369os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003370{
3371 PyObject *return_value = NULL;
3372 int fd;
3373
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003374 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003375 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003376 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003377 return_value = os_tcgetpgrp_impl(module, fd);
3378
3379exit:
3380 return return_value;
3381}
3382
3383#endif /* defined(HAVE_TCGETPGRP) */
3384
3385#if defined(HAVE_TCSETPGRP)
3386
3387PyDoc_STRVAR(os_tcsetpgrp__doc__,
3388"tcsetpgrp($module, fd, pgid, /)\n"
3389"--\n"
3390"\n"
3391"Set the process group associated with the terminal specified by fd.");
3392
3393#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003394 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003395
3396static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003397os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003398
3399static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003400os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003401{
3402 PyObject *return_value = NULL;
3403 int fd;
3404 pid_t pgid;
3405
Sylvain74453812017-06-10 06:51:48 +02003406 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3407 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003408 goto exit;
3409 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003410 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3411
3412exit:
3413 return return_value;
3414}
3415
3416#endif /* defined(HAVE_TCSETPGRP) */
3417
3418PyDoc_STRVAR(os_open__doc__,
3419"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3420"--\n"
3421"\n"
3422"Open a file for low level IO. Returns a file descriptor (integer).\n"
3423"\n"
3424"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3425" and path should be relative; path will then be relative to that directory.\n"
3426"dir_fd may not be implemented on your platform.\n"
3427" If it is unavailable, using it will raise a NotImplementedError.");
3428
3429#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003430 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003431
3432static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003433os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003434
3435static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003436os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003437{
3438 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003439 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3440 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003441 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3442 int flags;
3443 int mode = 511;
3444 int dir_fd = DEFAULT_DIR_FD;
3445 int _return_value;
3446
Victor Stinner3e1fad62017-01-17 01:29:01 +01003447 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003448 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003449 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003450 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003451 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003452 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003453 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003454 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003455 return_value = PyLong_FromLong((long)_return_value);
3456
3457exit:
3458 /* Cleanup for path */
3459 path_cleanup(&path);
3460
3461 return return_value;
3462}
3463
3464PyDoc_STRVAR(os_close__doc__,
3465"close($module, /, fd)\n"
3466"--\n"
3467"\n"
3468"Close a file descriptor.");
3469
3470#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003471 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003472
3473static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003474os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003475
3476static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003477os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003478{
3479 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003480 static const char * const _keywords[] = {"fd", NULL};
3481 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003482 int fd;
3483
Victor Stinner3e1fad62017-01-17 01:29:01 +01003484 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003485 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003486 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003487 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003488 return_value = os_close_impl(module, fd);
3489
3490exit:
3491 return return_value;
3492}
3493
3494PyDoc_STRVAR(os_closerange__doc__,
3495"closerange($module, fd_low, fd_high, /)\n"
3496"--\n"
3497"\n"
3498"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3499
3500#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003501 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003502
3503static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003504os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003505
3506static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003507os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003508{
3509 PyObject *return_value = NULL;
3510 int fd_low;
3511 int fd_high;
3512
Sylvain74453812017-06-10 06:51:48 +02003513 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3514 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003515 goto exit;
3516 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003517 return_value = os_closerange_impl(module, fd_low, fd_high);
3518
3519exit:
3520 return return_value;
3521}
3522
3523PyDoc_STRVAR(os_dup__doc__,
3524"dup($module, fd, /)\n"
3525"--\n"
3526"\n"
3527"Return a duplicate of a file descriptor.");
3528
3529#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003530 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003531
3532static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003533os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003534
3535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003536os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003537{
3538 PyObject *return_value = NULL;
3539 int fd;
3540 int _return_value;
3541
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003542 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003543 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003544 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003545 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003546 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003547 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003548 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003549 return_value = PyLong_FromLong((long)_return_value);
3550
3551exit:
3552 return return_value;
3553}
3554
3555PyDoc_STRVAR(os_dup2__doc__,
3556"dup2($module, /, fd, fd2, inheritable=True)\n"
3557"--\n"
3558"\n"
3559"Duplicate file descriptor.");
3560
3561#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003562 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003563
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003564static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003565os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003566
3567static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003568os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003569{
3570 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003571 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3572 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003573 int fd;
3574 int fd2;
3575 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003576 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003577
Victor Stinner3e1fad62017-01-17 01:29:01 +01003578 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003579 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003580 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003581 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003582 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3583 if ((_return_value == -1) && PyErr_Occurred()) {
3584 goto exit;
3585 }
3586 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003587
3588exit:
3589 return return_value;
3590}
3591
3592#if defined(HAVE_LOCKF)
3593
3594PyDoc_STRVAR(os_lockf__doc__,
3595"lockf($module, fd, command, length, /)\n"
3596"--\n"
3597"\n"
3598"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3599"\n"
3600" fd\n"
3601" An open file descriptor.\n"
3602" command\n"
3603" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3604" length\n"
3605" The number of bytes to lock, starting at the current position.");
3606
3607#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003608 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003609
3610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003611os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003612
3613static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003614os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003615{
3616 PyObject *return_value = NULL;
3617 int fd;
3618 int command;
3619 Py_off_t length;
3620
Sylvain74453812017-06-10 06:51:48 +02003621 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3622 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003623 goto exit;
3624 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003625 return_value = os_lockf_impl(module, fd, command, length);
3626
3627exit:
3628 return return_value;
3629}
3630
3631#endif /* defined(HAVE_LOCKF) */
3632
3633PyDoc_STRVAR(os_lseek__doc__,
3634"lseek($module, fd, position, how, /)\n"
3635"--\n"
3636"\n"
3637"Set the position of a file descriptor. Return the new position.\n"
3638"\n"
3639"Return the new cursor position in number of bytes\n"
3640"relative to the beginning of the file.");
3641
3642#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003643 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003644
3645static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003646os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003647
3648static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003649os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003650{
3651 PyObject *return_value = NULL;
3652 int fd;
3653 Py_off_t position;
3654 int how;
3655 Py_off_t _return_value;
3656
Sylvain74453812017-06-10 06:51:48 +02003657 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3658 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003659 goto exit;
3660 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003661 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003662 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003664 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003665 return_value = PyLong_FromPy_off_t(_return_value);
3666
3667exit:
3668 return return_value;
3669}
3670
3671PyDoc_STRVAR(os_read__doc__,
3672"read($module, fd, length, /)\n"
3673"--\n"
3674"\n"
3675"Read from a file descriptor. Returns a bytes object.");
3676
3677#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003678 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003679
3680static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003681os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003682
3683static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003684os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003685{
3686 PyObject *return_value = NULL;
3687 int fd;
3688 Py_ssize_t length;
3689
Sylvain74453812017-06-10 06:51:48 +02003690 if (!_PyArg_ParseStack(args, nargs, "in:read",
3691 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003692 goto exit;
3693 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003694 return_value = os_read_impl(module, fd, length);
3695
3696exit:
3697 return return_value;
3698}
3699
3700#if defined(HAVE_READV)
3701
3702PyDoc_STRVAR(os_readv__doc__,
3703"readv($module, fd, buffers, /)\n"
3704"--\n"
3705"\n"
3706"Read from a file descriptor fd into an iterable of buffers.\n"
3707"\n"
3708"The buffers should be mutable buffers accepting bytes.\n"
3709"readv will transfer data into each buffer until it is full\n"
3710"and then move on to the next buffer in the sequence to hold\n"
3711"the rest of the data.\n"
3712"\n"
3713"readv returns the total number of bytes read,\n"
3714"which may be less than the total capacity of all the buffers.");
3715
3716#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003717 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003718
3719static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003720os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003721
3722static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003723os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003724{
3725 PyObject *return_value = NULL;
3726 int fd;
3727 PyObject *buffers;
3728 Py_ssize_t _return_value;
3729
Sylvain74453812017-06-10 06:51:48 +02003730 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3731 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003732 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 *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003764os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
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
Sylvain74453812017-06-10 06:51:48 +02003771 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3772 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003773 goto exit;
3774 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003775 return_value = os_pread_impl(module, fd, length, offset);
3776
3777exit:
3778 return return_value;
3779}
3780
3781#endif /* defined(HAVE_PREAD) */
3782
Pablo Galindo4defba32018-01-27 16:16:37 +00003783#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3784
3785PyDoc_STRVAR(os_preadv__doc__,
3786"preadv($module, fd, buffers, offset, flags=0, /)\n"
3787"--\n"
3788"\n"
3789"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3790"\n"
3791"Combines the functionality of readv() and pread(). As readv(), it will\n"
3792"transfer data into each buffer until it is full and then move on to the next\n"
3793"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3794"specifies the file offset at which the input operation is to be performed. It\n"
3795"will return the total number of bytes read (which can be less than the total\n"
3796"capacity of all the objects).\n"
3797"\n"
3798"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3799"\n"
3800"- RWF_HIPRI\n"
3801"- RWF_NOWAIT\n"
3802"\n"
3803"Using non-zero flags requires Linux 4.6 or newer.");
3804
3805#define OS_PREADV_METHODDEF \
3806 {"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
3807
3808static Py_ssize_t
3809os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3810 int flags);
3811
3812static PyObject *
3813os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3814{
3815 PyObject *return_value = NULL;
3816 int fd;
3817 PyObject *buffers;
3818 Py_off_t offset;
3819 int flags = 0;
3820 Py_ssize_t _return_value;
3821
3822 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3823 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3824 goto exit;
3825 }
3826 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3827 if ((_return_value == -1) && PyErr_Occurred()) {
3828 goto exit;
3829 }
3830 return_value = PyLong_FromSsize_t(_return_value);
3831
3832exit:
3833 return return_value;
3834}
3835
3836#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3837
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003838PyDoc_STRVAR(os_write__doc__,
3839"write($module, fd, data, /)\n"
3840"--\n"
3841"\n"
3842"Write a bytes object to a file descriptor.");
3843
3844#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003845 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003846
3847static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003848os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003849
3850static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003851os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003852{
3853 PyObject *return_value = NULL;
3854 int fd;
3855 Py_buffer data = {NULL, NULL};
3856 Py_ssize_t _return_value;
3857
Sylvain74453812017-06-10 06:51:48 +02003858 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3859 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003860 goto exit;
3861 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003862 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003863 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003864 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003865 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003866 return_value = PyLong_FromSsize_t(_return_value);
3867
3868exit:
3869 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003870 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003871 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003872 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003873
3874 return return_value;
3875}
3876
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003877#if defined(__APPLE__)
3878
3879PyDoc_STRVAR(os__fcopyfile__doc__,
3880"_fcopyfile($module, infd, outfd, flags, /)\n"
3881"--\n"
3882"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07003883"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003884
3885#define OS__FCOPYFILE_METHODDEF \
3886 {"_fcopyfile", (PyCFunction)os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
3887
3888static PyObject *
3889os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
3890
3891static PyObject *
3892os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3893{
3894 PyObject *return_value = NULL;
3895 int infd;
3896 int outfd;
3897 int flags;
3898
3899 if (!_PyArg_ParseStack(args, nargs, "iii:_fcopyfile",
3900 &infd, &outfd, &flags)) {
3901 goto exit;
3902 }
3903 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
3904
3905exit:
3906 return return_value;
3907}
3908
3909#endif /* defined(__APPLE__) */
3910
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003911PyDoc_STRVAR(os_fstat__doc__,
3912"fstat($module, /, fd)\n"
3913"--\n"
3914"\n"
3915"Perform a stat system call on the given file descriptor.\n"
3916"\n"
3917"Like stat(), but for an open file descriptor.\n"
3918"Equivalent to os.stat(fd).");
3919
3920#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003921 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003922
3923static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003924os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003925
3926static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003927os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003928{
3929 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003930 static const char * const _keywords[] = {"fd", NULL};
3931 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003932 int fd;
3933
Victor Stinner3e1fad62017-01-17 01:29:01 +01003934 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003935 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003936 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003937 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003938 return_value = os_fstat_impl(module, fd);
3939
3940exit:
3941 return return_value;
3942}
3943
3944PyDoc_STRVAR(os_isatty__doc__,
3945"isatty($module, fd, /)\n"
3946"--\n"
3947"\n"
3948"Return True if the fd is connected to a terminal.\n"
3949"\n"
3950"Return True if the file descriptor is an open file descriptor\n"
3951"connected to the slave end of a terminal.");
3952
3953#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003954 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003955
3956static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003957os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003958
3959static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003960os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003961{
3962 PyObject *return_value = NULL;
3963 int fd;
3964 int _return_value;
3965
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003966 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003967 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003968 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003969 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003970 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003971 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003972 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003973 return_value = PyBool_FromLong((long)_return_value);
3974
3975exit:
3976 return return_value;
3977}
3978
3979#if defined(HAVE_PIPE)
3980
3981PyDoc_STRVAR(os_pipe__doc__,
3982"pipe($module, /)\n"
3983"--\n"
3984"\n"
3985"Create a pipe.\n"
3986"\n"
3987"Returns a tuple of two file descriptors:\n"
3988" (read_fd, write_fd)");
3989
3990#define OS_PIPE_METHODDEF \
3991 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
3992
3993static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003994os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003995
3996static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003997os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003998{
3999 return os_pipe_impl(module);
4000}
4001
4002#endif /* defined(HAVE_PIPE) */
4003
4004#if defined(HAVE_PIPE2)
4005
4006PyDoc_STRVAR(os_pipe2__doc__,
4007"pipe2($module, flags, /)\n"
4008"--\n"
4009"\n"
4010"Create a pipe with flags set atomically.\n"
4011"\n"
4012"Returns a tuple of two file descriptors:\n"
4013" (read_fd, write_fd)\n"
4014"\n"
4015"flags can be constructed by ORing together one or more of these values:\n"
4016"O_NONBLOCK, O_CLOEXEC.");
4017
4018#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004019 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004020
4021static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004022os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004023
4024static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004025os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004026{
4027 PyObject *return_value = NULL;
4028 int flags;
4029
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004030 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004031 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004032 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004033 return_value = os_pipe2_impl(module, flags);
4034
4035exit:
4036 return return_value;
4037}
4038
4039#endif /* defined(HAVE_PIPE2) */
4040
4041#if defined(HAVE_WRITEV)
4042
4043PyDoc_STRVAR(os_writev__doc__,
4044"writev($module, fd, buffers, /)\n"
4045"--\n"
4046"\n"
4047"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4048"\n"
4049"Returns the total number of bytes written.\n"
4050"buffers must be a sequence of bytes-like objects.");
4051
4052#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004053 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004054
4055static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004056os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004057
4058static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004059os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004060{
4061 PyObject *return_value = NULL;
4062 int fd;
4063 PyObject *buffers;
4064 Py_ssize_t _return_value;
4065
Sylvain74453812017-06-10 06:51:48 +02004066 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4067 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004068 goto exit;
4069 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004070 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004071 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004072 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004073 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074 return_value = PyLong_FromSsize_t(_return_value);
4075
4076exit:
4077 return return_value;
4078}
4079
4080#endif /* defined(HAVE_WRITEV) */
4081
4082#if defined(HAVE_PWRITE)
4083
4084PyDoc_STRVAR(os_pwrite__doc__,
4085"pwrite($module, fd, buffer, offset, /)\n"
4086"--\n"
4087"\n"
4088"Write bytes to a file descriptor starting at a particular offset.\n"
4089"\n"
4090"Write buffer to fd, starting at offset bytes from the beginning of\n"
4091"the file. Returns the number of bytes writte. Does not change the\n"
4092"current file offset.");
4093
4094#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004095 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004096
4097static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004098os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004099
4100static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004101os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004102{
4103 PyObject *return_value = NULL;
4104 int fd;
4105 Py_buffer buffer = {NULL, NULL};
4106 Py_off_t offset;
4107 Py_ssize_t _return_value;
4108
Sylvain74453812017-06-10 06:51:48 +02004109 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4110 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004111 goto exit;
4112 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004113 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004114 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004115 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004116 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004117 return_value = PyLong_FromSsize_t(_return_value);
4118
4119exit:
4120 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004121 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004122 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004123 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004124
4125 return return_value;
4126}
4127
4128#endif /* defined(HAVE_PWRITE) */
4129
Pablo Galindo4defba32018-01-27 16:16:37 +00004130#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4131
4132PyDoc_STRVAR(os_pwritev__doc__,
4133"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4134"--\n"
4135"\n"
4136"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4137"\n"
4138"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4139"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4140"buffer is written before proceeding to second, and so on. The operating system may\n"
4141"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4142"This function writes the contents of each object to the file descriptor and returns\n"
4143"the total number of bytes written.\n"
4144"\n"
4145"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4146"\n"
4147"- RWF_DSYNC\n"
4148"- RWF_SYNC\n"
4149"\n"
4150"Using non-zero flags requires Linux 4.7 or newer.");
4151
4152#define OS_PWRITEV_METHODDEF \
4153 {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4154
4155static Py_ssize_t
4156os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4157 int flags);
4158
4159static PyObject *
4160os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4161{
4162 PyObject *return_value = NULL;
4163 int fd;
4164 PyObject *buffers;
4165 Py_off_t offset;
4166 int flags = 0;
4167 Py_ssize_t _return_value;
4168
4169 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4170 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4171 goto exit;
4172 }
4173 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4174 if ((_return_value == -1) && PyErr_Occurred()) {
4175 goto exit;
4176 }
4177 return_value = PyLong_FromSsize_t(_return_value);
4178
4179exit:
4180 return return_value;
4181}
4182
4183#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4184
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004185#if defined(HAVE_MKFIFO)
4186
4187PyDoc_STRVAR(os_mkfifo__doc__,
4188"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4189"--\n"
4190"\n"
4191"Create a \"fifo\" (a POSIX named pipe).\n"
4192"\n"
4193"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4194" and path should be relative; path will then be relative to that directory.\n"
4195"dir_fd may not be implemented on your platform.\n"
4196" If it is unavailable, using it will raise a NotImplementedError.");
4197
4198#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004199 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004200
4201static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004202os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004203
4204static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004205os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004206{
4207 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004208 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4209 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004210 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4211 int mode = 438;
4212 int dir_fd = DEFAULT_DIR_FD;
4213
Victor Stinner3e1fad62017-01-17 01:29:01 +01004214 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004215 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
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 = os_mkfifo_impl(module, &path, mode, dir_fd);
4219
4220exit:
4221 /* Cleanup for path */
4222 path_cleanup(&path);
4223
4224 return return_value;
4225}
4226
4227#endif /* defined(HAVE_MKFIFO) */
4228
4229#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4230
4231PyDoc_STRVAR(os_mknod__doc__,
4232"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4233"--\n"
4234"\n"
4235"Create a node in the file system.\n"
4236"\n"
4237"Create a node in the file system (file, device special file or named pipe)\n"
4238"at path. mode specifies both the permissions to use and the\n"
4239"type of node to be created, being combined (bitwise OR) with one of\n"
4240"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4241"device defines the newly created device special file (probably using\n"
4242"os.makedev()). Otherwise device is ignored.\n"
4243"\n"
4244"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4245" and path should be relative; path will then be relative to that directory.\n"
4246"dir_fd may not be implemented on your platform.\n"
4247" If it is unavailable, using it will raise a NotImplementedError.");
4248
4249#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004250 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004251
4252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004253os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004254 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004255
4256static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004257os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004258{
4259 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004260 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4261 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004262 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4263 int mode = 384;
4264 dev_t device = 0;
4265 int dir_fd = DEFAULT_DIR_FD;
4266
Victor Stinner3e1fad62017-01-17 01:29:01 +01004267 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004268 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004269 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004270 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004271 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4272
4273exit:
4274 /* Cleanup for path */
4275 path_cleanup(&path);
4276
4277 return return_value;
4278}
4279
4280#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4281
4282#if defined(HAVE_DEVICE_MACROS)
4283
4284PyDoc_STRVAR(os_major__doc__,
4285"major($module, device, /)\n"
4286"--\n"
4287"\n"
4288"Extracts a device major number from a raw device number.");
4289
4290#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004291 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004292
4293static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004294os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004295
4296static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004297os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004298{
4299 PyObject *return_value = NULL;
4300 dev_t device;
4301 unsigned int _return_value;
4302
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004303 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004304 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004305 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004306 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004307 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004308 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004309 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004310 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4311
4312exit:
4313 return return_value;
4314}
4315
4316#endif /* defined(HAVE_DEVICE_MACROS) */
4317
4318#if defined(HAVE_DEVICE_MACROS)
4319
4320PyDoc_STRVAR(os_minor__doc__,
4321"minor($module, device, /)\n"
4322"--\n"
4323"\n"
4324"Extracts a device minor number from a raw device number.");
4325
4326#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004327 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004328
4329static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004330os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004331
4332static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004333os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004334{
4335 PyObject *return_value = NULL;
4336 dev_t device;
4337 unsigned int _return_value;
4338
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004339 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004340 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004341 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004342 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004343 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004344 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004345 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004346 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4347
4348exit:
4349 return return_value;
4350}
4351
4352#endif /* defined(HAVE_DEVICE_MACROS) */
4353
4354#if defined(HAVE_DEVICE_MACROS)
4355
4356PyDoc_STRVAR(os_makedev__doc__,
4357"makedev($module, major, minor, /)\n"
4358"--\n"
4359"\n"
4360"Composes a raw device number from the major and minor device numbers.");
4361
4362#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004363 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364
4365static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004366os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004367
4368static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004369os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370{
4371 PyObject *return_value = NULL;
4372 int major;
4373 int minor;
4374 dev_t _return_value;
4375
Sylvain74453812017-06-10 06:51:48 +02004376 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4377 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004378 goto exit;
4379 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004380 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004381 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004382 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004383 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004384 return_value = _PyLong_FromDev(_return_value);
4385
4386exit:
4387 return return_value;
4388}
4389
4390#endif /* defined(HAVE_DEVICE_MACROS) */
4391
Steve Dowerf7377032015-04-12 15:44:54 -04004392#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004393
4394PyDoc_STRVAR(os_ftruncate__doc__,
4395"ftruncate($module, fd, length, /)\n"
4396"--\n"
4397"\n"
4398"Truncate a file, specified by file descriptor, to a specific length.");
4399
4400#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004401 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004402
4403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004404os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004405
4406static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004407os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004408{
4409 PyObject *return_value = NULL;
4410 int fd;
4411 Py_off_t length;
4412
Sylvain74453812017-06-10 06:51:48 +02004413 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4414 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004415 goto exit;
4416 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004417 return_value = os_ftruncate_impl(module, fd, length);
4418
4419exit:
4420 return return_value;
4421}
4422
Steve Dowerf7377032015-04-12 15:44:54 -04004423#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004424
Steve Dowerf7377032015-04-12 15:44:54 -04004425#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004426
4427PyDoc_STRVAR(os_truncate__doc__,
4428"truncate($module, /, path, length)\n"
4429"--\n"
4430"\n"
4431"Truncate a file, specified by path, to a specific length.\n"
4432"\n"
4433"On some platforms, path may also be specified as an open file descriptor.\n"
4434" If this functionality is unavailable, using it raises an exception.");
4435
4436#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004437 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004438
4439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004440os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004441
4442static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004443os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004444{
4445 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004446 static const char * const _keywords[] = {"path", "length", NULL};
4447 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004448 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4449 Py_off_t length;
4450
Victor Stinner3e1fad62017-01-17 01:29:01 +01004451 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004452 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004453 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004454 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004455 return_value = os_truncate_impl(module, &path, length);
4456
4457exit:
4458 /* Cleanup for path */
4459 path_cleanup(&path);
4460
4461 return return_value;
4462}
4463
Steve Dowerf7377032015-04-12 15:44:54 -04004464#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004465
4466#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4467
4468PyDoc_STRVAR(os_posix_fallocate__doc__,
4469"posix_fallocate($module, fd, offset, length, /)\n"
4470"--\n"
4471"\n"
4472"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4473"\n"
4474"Ensure that the file specified by fd encompasses a range of bytes\n"
4475"starting at offset bytes from the beginning and continuing for length bytes.");
4476
4477#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004478 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004479
4480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004481os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004482 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004483
4484static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004485os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004486{
4487 PyObject *return_value = NULL;
4488 int fd;
4489 Py_off_t offset;
4490 Py_off_t length;
4491
Sylvain74453812017-06-10 06:51:48 +02004492 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4493 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004494 goto exit;
4495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004496 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4497
4498exit:
4499 return return_value;
4500}
4501
4502#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4503
4504#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4505
4506PyDoc_STRVAR(os_posix_fadvise__doc__,
4507"posix_fadvise($module, fd, offset, length, advice, /)\n"
4508"--\n"
4509"\n"
4510"Announce an intention to access data in a specific pattern.\n"
4511"\n"
4512"Announce an intention to access data in a specific pattern, thus allowing\n"
4513"the kernel to make optimizations.\n"
4514"The advice applies to the region of the file specified by fd starting at\n"
4515"offset and continuing for length bytes.\n"
4516"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4517"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4518"POSIX_FADV_DONTNEED.");
4519
4520#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004521 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004522
4523static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004524os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004525 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004526
4527static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004528os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004529{
4530 PyObject *return_value = NULL;
4531 int fd;
4532 Py_off_t offset;
4533 Py_off_t length;
4534 int advice;
4535
Sylvain74453812017-06-10 06:51:48 +02004536 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4537 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004538 goto exit;
4539 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004540 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4541
4542exit:
4543 return return_value;
4544}
4545
4546#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4547
4548#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4549
4550PyDoc_STRVAR(os_putenv__doc__,
4551"putenv($module, name, value, /)\n"
4552"--\n"
4553"\n"
4554"Change or add an environment variable.");
4555
4556#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004557 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004558
4559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004560os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004561
4562static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004563os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004564{
4565 PyObject *return_value = NULL;
4566 PyObject *name;
4567 PyObject *value;
4568
Sylvain74453812017-06-10 06:51:48 +02004569 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4570 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004571 goto exit;
4572 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004573 return_value = os_putenv_impl(module, name, value);
4574
4575exit:
4576 return return_value;
4577}
4578
4579#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4580
4581#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4582
4583PyDoc_STRVAR(os_putenv__doc__,
4584"putenv($module, name, value, /)\n"
4585"--\n"
4586"\n"
4587"Change or add an environment variable.");
4588
4589#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004590 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004591
4592static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004593os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004594
4595static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004596os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004597{
4598 PyObject *return_value = NULL;
4599 PyObject *name = NULL;
4600 PyObject *value = NULL;
4601
Sylvain74453812017-06-10 06:51:48 +02004602 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4603 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004604 goto exit;
4605 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004606 return_value = os_putenv_impl(module, name, value);
4607
4608exit:
4609 /* Cleanup for name */
4610 Py_XDECREF(name);
4611 /* Cleanup for value */
4612 Py_XDECREF(value);
4613
4614 return return_value;
4615}
4616
4617#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4618
4619#if defined(HAVE_UNSETENV)
4620
4621PyDoc_STRVAR(os_unsetenv__doc__,
4622"unsetenv($module, name, /)\n"
4623"--\n"
4624"\n"
4625"Delete an environment variable.");
4626
4627#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004628 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004629
4630static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004631os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004632
4633static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004634os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004635{
4636 PyObject *return_value = NULL;
4637 PyObject *name = NULL;
4638
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004639 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
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_unsetenv_impl(module, name);
4643
4644exit:
4645 /* Cleanup for name */
4646 Py_XDECREF(name);
4647
4648 return return_value;
4649}
4650
4651#endif /* defined(HAVE_UNSETENV) */
4652
4653PyDoc_STRVAR(os_strerror__doc__,
4654"strerror($module, code, /)\n"
4655"--\n"
4656"\n"
4657"Translate an error code to a message string.");
4658
4659#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004660 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004661
4662static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004663os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004664
4665static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004666os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004667{
4668 PyObject *return_value = NULL;
4669 int code;
4670
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004671 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004672 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004673 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004674 return_value = os_strerror_impl(module, code);
4675
4676exit:
4677 return return_value;
4678}
4679
4680#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4681
4682PyDoc_STRVAR(os_WCOREDUMP__doc__,
4683"WCOREDUMP($module, status, /)\n"
4684"--\n"
4685"\n"
4686"Return True if the process returning status was dumped to a core file.");
4687
4688#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004689 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004690
4691static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004692os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004693
4694static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004695os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004696{
4697 PyObject *return_value = NULL;
4698 int status;
4699 int _return_value;
4700
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004701 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004703 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004704 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004705 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004707 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708 return_value = PyBool_FromLong((long)_return_value);
4709
4710exit:
4711 return return_value;
4712}
4713
4714#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4715
4716#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4717
4718PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4719"WIFCONTINUED($module, /, status)\n"
4720"--\n"
4721"\n"
4722"Return True if a particular process was continued from a job control stop.\n"
4723"\n"
4724"Return True if the process returning status was continued from a\n"
4725"job control stop.");
4726
4727#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004728 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004729
4730static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004731os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004732
4733static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004734os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004735{
4736 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004737 static const char * const _keywords[] = {"status", NULL};
4738 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004739 int status;
4740 int _return_value;
4741
Victor Stinner3e1fad62017-01-17 01:29:01 +01004742 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004743 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004744 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004745 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004746 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004747 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004748 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004749 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004750 return_value = PyBool_FromLong((long)_return_value);
4751
4752exit:
4753 return return_value;
4754}
4755
4756#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4757
4758#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4759
4760PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4761"WIFSTOPPED($module, /, status)\n"
4762"--\n"
4763"\n"
4764"Return True if the process returning status was stopped.");
4765
4766#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004767 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004768
4769static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004770os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004771
4772static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004773os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004774{
4775 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004776 static const char * const _keywords[] = {"status", NULL};
4777 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004778 int status;
4779 int _return_value;
4780
Victor Stinner3e1fad62017-01-17 01:29:01 +01004781 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004782 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004783 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004784 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004785 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004786 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004787 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004788 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004789 return_value = PyBool_FromLong((long)_return_value);
4790
4791exit:
4792 return return_value;
4793}
4794
4795#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4796
4797#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4798
4799PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4800"WIFSIGNALED($module, /, status)\n"
4801"--\n"
4802"\n"
4803"Return True if the process returning status was terminated by a signal.");
4804
4805#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004806 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004807
4808static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004809os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004810
4811static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004812os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004813{
4814 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004815 static const char * const _keywords[] = {"status", NULL};
4816 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004817 int status;
4818 int _return_value;
4819
Victor Stinner3e1fad62017-01-17 01:29:01 +01004820 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004821 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004822 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004823 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004824 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004825 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004826 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004827 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004828 return_value = PyBool_FromLong((long)_return_value);
4829
4830exit:
4831 return return_value;
4832}
4833
4834#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4835
4836#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4837
4838PyDoc_STRVAR(os_WIFEXITED__doc__,
4839"WIFEXITED($module, /, status)\n"
4840"--\n"
4841"\n"
4842"Return True if the process returning status exited via the exit() system call.");
4843
4844#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004845 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004846
4847static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004848os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004849
4850static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004851os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004852{
4853 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004854 static const char * const _keywords[] = {"status", NULL};
4855 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004856 int status;
4857 int _return_value;
4858
Victor Stinner3e1fad62017-01-17 01:29:01 +01004859 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004860 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004861 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004862 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004863 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004864 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004865 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004866 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004867 return_value = PyBool_FromLong((long)_return_value);
4868
4869exit:
4870 return return_value;
4871}
4872
4873#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4874
4875#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4876
4877PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4878"WEXITSTATUS($module, /, status)\n"
4879"--\n"
4880"\n"
4881"Return the process return code from status.");
4882
4883#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004884 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004885
4886static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004887os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004888
4889static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004890os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004891{
4892 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004893 static const char * const _keywords[] = {"status", NULL};
4894 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004895 int status;
4896 int _return_value;
4897
Victor Stinner3e1fad62017-01-17 01:29:01 +01004898 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004899 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004900 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004901 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004902 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004903 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004905 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004906 return_value = PyLong_FromLong((long)_return_value);
4907
4908exit:
4909 return return_value;
4910}
4911
4912#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4913
4914#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4915
4916PyDoc_STRVAR(os_WTERMSIG__doc__,
4917"WTERMSIG($module, /, status)\n"
4918"--\n"
4919"\n"
4920"Return the signal that terminated the process that provided the status value.");
4921
4922#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004923 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004924
4925static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004926os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004927
4928static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004929os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004930{
4931 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004932 static const char * const _keywords[] = {"status", NULL};
4933 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004934 int status;
4935 int _return_value;
4936
Victor Stinner3e1fad62017-01-17 01:29:01 +01004937 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004938 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004939 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004940 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004941 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004942 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004943 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004945 return_value = PyLong_FromLong((long)_return_value);
4946
4947exit:
4948 return return_value;
4949}
4950
4951#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4952
4953#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4954
4955PyDoc_STRVAR(os_WSTOPSIG__doc__,
4956"WSTOPSIG($module, /, status)\n"
4957"--\n"
4958"\n"
4959"Return the signal that stopped the process that provided the status value.");
4960
4961#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004962 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004963
4964static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004965os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004966
4967static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004968os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004969{
4970 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004971 static const char * const _keywords[] = {"status", NULL};
4972 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004973 int status;
4974 int _return_value;
4975
Victor Stinner3e1fad62017-01-17 01:29:01 +01004976 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004977 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004979 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004980 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004981 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004982 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004983 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984 return_value = PyLong_FromLong((long)_return_value);
4985
4986exit:
4987 return return_value;
4988}
4989
4990#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
4991
4992#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
4993
4994PyDoc_STRVAR(os_fstatvfs__doc__,
4995"fstatvfs($module, fd, /)\n"
4996"--\n"
4997"\n"
4998"Perform an fstatvfs system call on the given fd.\n"
4999"\n"
5000"Equivalent to statvfs(fd).");
5001
5002#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005003 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005004
5005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005006os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005007
5008static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005009os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005010{
5011 PyObject *return_value = NULL;
5012 int fd;
5013
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005014 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005016 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005017 return_value = os_fstatvfs_impl(module, fd);
5018
5019exit:
5020 return return_value;
5021}
5022
5023#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5024
5025#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5026
5027PyDoc_STRVAR(os_statvfs__doc__,
5028"statvfs($module, /, path)\n"
5029"--\n"
5030"\n"
5031"Perform a statvfs system call on the given path.\n"
5032"\n"
5033"path may always be specified as a string.\n"
5034"On some platforms, path may also be specified as an open file descriptor.\n"
5035" If this functionality is unavailable, using it raises an exception.");
5036
5037#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005038 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005039
5040static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005041os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005042
5043static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005044os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005045{
5046 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005047 static const char * const _keywords[] = {"path", NULL};
5048 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005049 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5050
Victor Stinner3e1fad62017-01-17 01:29:01 +01005051 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005052 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005053 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005054 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005055 return_value = os_statvfs_impl(module, &path);
5056
5057exit:
5058 /* Cleanup for path */
5059 path_cleanup(&path);
5060
5061 return return_value;
5062}
5063
5064#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5065
5066#if defined(MS_WINDOWS)
5067
5068PyDoc_STRVAR(os__getdiskusage__doc__,
5069"_getdiskusage($module, /, path)\n"
5070"--\n"
5071"\n"
5072"Return disk usage statistics about the given path as a (total, free) tuple.");
5073
5074#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005075 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005076
5077static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005078os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005079
5080static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005081os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005082{
5083 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005084 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005085 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5086 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005087
Victor Stinner3e1fad62017-01-17 01:29:01 +01005088 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005089 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005090 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005091 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005092 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005093
5094exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005095 /* Cleanup for path */
5096 path_cleanup(&path);
5097
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005098 return return_value;
5099}
5100
5101#endif /* defined(MS_WINDOWS) */
5102
5103#if defined(HAVE_FPATHCONF)
5104
5105PyDoc_STRVAR(os_fpathconf__doc__,
5106"fpathconf($module, fd, name, /)\n"
5107"--\n"
5108"\n"
5109"Return the configuration limit name for the file descriptor fd.\n"
5110"\n"
5111"If there is no limit, return -1.");
5112
5113#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005114 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005115
5116static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005117os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005118
5119static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005120os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005121{
5122 PyObject *return_value = NULL;
5123 int fd;
5124 int name;
5125 long _return_value;
5126
Sylvain74453812017-06-10 06:51:48 +02005127 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5128 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005129 goto exit;
5130 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005131 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005132 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005133 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005134 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005135 return_value = PyLong_FromLong(_return_value);
5136
5137exit:
5138 return return_value;
5139}
5140
5141#endif /* defined(HAVE_FPATHCONF) */
5142
5143#if defined(HAVE_PATHCONF)
5144
5145PyDoc_STRVAR(os_pathconf__doc__,
5146"pathconf($module, /, path, name)\n"
5147"--\n"
5148"\n"
5149"Return the configuration limit name for the file or directory path.\n"
5150"\n"
5151"If there is no limit, return -1.\n"
5152"On some platforms, path may also be specified as an open file descriptor.\n"
5153" If this functionality is unavailable, using it raises an exception.");
5154
5155#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005156 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005157
5158static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005159os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005160
5161static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005162os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005163{
5164 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005165 static const char * const _keywords[] = {"path", "name", NULL};
5166 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005167 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5168 int name;
5169 long _return_value;
5170
Victor Stinner3e1fad62017-01-17 01:29:01 +01005171 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005172 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005173 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005174 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005176 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005177 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005178 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005179 return_value = PyLong_FromLong(_return_value);
5180
5181exit:
5182 /* Cleanup for path */
5183 path_cleanup(&path);
5184
5185 return return_value;
5186}
5187
5188#endif /* defined(HAVE_PATHCONF) */
5189
5190#if defined(HAVE_CONFSTR)
5191
5192PyDoc_STRVAR(os_confstr__doc__,
5193"confstr($module, name, /)\n"
5194"--\n"
5195"\n"
5196"Return a string-valued system configuration variable.");
5197
5198#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005199 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005200
5201static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005202os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005203
5204static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005205os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005206{
5207 PyObject *return_value = NULL;
5208 int name;
5209
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005210 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005211 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005212 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005213 return_value = os_confstr_impl(module, name);
5214
5215exit:
5216 return return_value;
5217}
5218
5219#endif /* defined(HAVE_CONFSTR) */
5220
5221#if defined(HAVE_SYSCONF)
5222
5223PyDoc_STRVAR(os_sysconf__doc__,
5224"sysconf($module, name, /)\n"
5225"--\n"
5226"\n"
5227"Return an integer-valued system configuration variable.");
5228
5229#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005230 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005231
5232static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005233os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005234
5235static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005236os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005237{
5238 PyObject *return_value = NULL;
5239 int name;
5240 long _return_value;
5241
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005242 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005243 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005244 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005245 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005246 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005249 return_value = PyLong_FromLong(_return_value);
5250
5251exit:
5252 return return_value;
5253}
5254
5255#endif /* defined(HAVE_SYSCONF) */
5256
5257PyDoc_STRVAR(os_abort__doc__,
5258"abort($module, /)\n"
5259"--\n"
5260"\n"
5261"Abort the interpreter immediately.\n"
5262"\n"
5263"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5264"on the hosting operating system. This function never returns.");
5265
5266#define OS_ABORT_METHODDEF \
5267 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5268
5269static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005270os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005271
5272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005273os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005274{
5275 return os_abort_impl(module);
5276}
5277
Steve Dowercc16be82016-09-08 10:35:16 -07005278#if defined(MS_WINDOWS)
5279
5280PyDoc_STRVAR(os_startfile__doc__,
5281"startfile($module, /, filepath, operation=None)\n"
5282"--\n"
5283"\n"
5284"startfile(filepath [, operation])\n"
5285"\n"
5286"Start a file with its associated application.\n"
5287"\n"
5288"When \"operation\" is not specified or \"open\", this acts like\n"
5289"double-clicking the file in Explorer, or giving the file name as an\n"
5290"argument to the DOS \"start\" command: the file is opened with whatever\n"
5291"application (if any) its extension is associated.\n"
5292"When another \"operation\" is given, it specifies what should be done with\n"
5293"the file. A typical operation is \"print\".\n"
5294"\n"
5295"startfile returns as soon as the associated application is launched.\n"
5296"There is no option to wait for the application to close, and no way\n"
5297"to retrieve the application\'s exit status.\n"
5298"\n"
5299"The filepath is relative to the current directory. If you want to use\n"
5300"an absolute path, make sure the first character is not a slash (\"/\");\n"
5301"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5302
5303#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005304 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005305
5306static PyObject *
5307os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5308
5309static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005310os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005311{
5312 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005313 static const char * const _keywords[] = {"filepath", "operation", NULL};
5314 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005315 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5316 Py_UNICODE *operation = NULL;
5317
Victor Stinner3e1fad62017-01-17 01:29:01 +01005318 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005319 path_converter, &filepath, &operation)) {
5320 goto exit;
5321 }
5322 return_value = os_startfile_impl(module, &filepath, operation);
5323
5324exit:
5325 /* Cleanup for filepath */
5326 path_cleanup(&filepath);
5327
5328 return return_value;
5329}
5330
5331#endif /* defined(MS_WINDOWS) */
5332
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005333#if defined(HAVE_GETLOADAVG)
5334
5335PyDoc_STRVAR(os_getloadavg__doc__,
5336"getloadavg($module, /)\n"
5337"--\n"
5338"\n"
5339"Return average recent system load information.\n"
5340"\n"
5341"Return the number of processes in the system run queue averaged over\n"
5342"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5343"Raises OSError if the load average was unobtainable.");
5344
5345#define OS_GETLOADAVG_METHODDEF \
5346 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5347
5348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005349os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005350
5351static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005352os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005353{
5354 return os_getloadavg_impl(module);
5355}
5356
5357#endif /* defined(HAVE_GETLOADAVG) */
5358
5359PyDoc_STRVAR(os_device_encoding__doc__,
5360"device_encoding($module, /, fd)\n"
5361"--\n"
5362"\n"
5363"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5364"\n"
5365"The file descriptor must be attached to a terminal.\n"
5366"If the device is not a terminal, return None.");
5367
5368#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005369 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005370
5371static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005372os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005373
5374static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005375os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005376{
5377 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005378 static const char * const _keywords[] = {"fd", NULL};
5379 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005380 int fd;
5381
Victor Stinner3e1fad62017-01-17 01:29:01 +01005382 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005383 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005386 return_value = os_device_encoding_impl(module, fd);
5387
5388exit:
5389 return return_value;
5390}
5391
5392#if defined(HAVE_SETRESUID)
5393
5394PyDoc_STRVAR(os_setresuid__doc__,
5395"setresuid($module, ruid, euid, suid, /)\n"
5396"--\n"
5397"\n"
5398"Set the current process\'s real, effective, and saved user ids.");
5399
5400#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005401 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005402
5403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005404os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005405
5406static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005407os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005408{
5409 PyObject *return_value = NULL;
5410 uid_t ruid;
5411 uid_t euid;
5412 uid_t suid;
5413
Sylvain74453812017-06-10 06:51:48 +02005414 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5415 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005416 goto exit;
5417 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005418 return_value = os_setresuid_impl(module, ruid, euid, suid);
5419
5420exit:
5421 return return_value;
5422}
5423
5424#endif /* defined(HAVE_SETRESUID) */
5425
5426#if defined(HAVE_SETRESGID)
5427
5428PyDoc_STRVAR(os_setresgid__doc__,
5429"setresgid($module, rgid, egid, sgid, /)\n"
5430"--\n"
5431"\n"
5432"Set the current process\'s real, effective, and saved group ids.");
5433
5434#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005435 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005436
5437static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005438os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005439
5440static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005441os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005442{
5443 PyObject *return_value = NULL;
5444 gid_t rgid;
5445 gid_t egid;
5446 gid_t sgid;
5447
Sylvain74453812017-06-10 06:51:48 +02005448 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5449 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005450 goto exit;
5451 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005452 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5453
5454exit:
5455 return return_value;
5456}
5457
5458#endif /* defined(HAVE_SETRESGID) */
5459
5460#if defined(HAVE_GETRESUID)
5461
5462PyDoc_STRVAR(os_getresuid__doc__,
5463"getresuid($module, /)\n"
5464"--\n"
5465"\n"
5466"Return a tuple of the current process\'s real, effective, and saved user ids.");
5467
5468#define OS_GETRESUID_METHODDEF \
5469 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5470
5471static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005472os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005473
5474static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005475os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005476{
5477 return os_getresuid_impl(module);
5478}
5479
5480#endif /* defined(HAVE_GETRESUID) */
5481
5482#if defined(HAVE_GETRESGID)
5483
5484PyDoc_STRVAR(os_getresgid__doc__,
5485"getresgid($module, /)\n"
5486"--\n"
5487"\n"
5488"Return a tuple of the current process\'s real, effective, and saved group ids.");
5489
5490#define OS_GETRESGID_METHODDEF \
5491 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5492
5493static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005494os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005495
5496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005497os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005498{
5499 return os_getresgid_impl(module);
5500}
5501
5502#endif /* defined(HAVE_GETRESGID) */
5503
5504#if defined(USE_XATTRS)
5505
5506PyDoc_STRVAR(os_getxattr__doc__,
5507"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5508"--\n"
5509"\n"
5510"Return the value of extended attribute attribute on path.\n"
5511"\n"
5512"path may be either a string or an open file descriptor.\n"
5513"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5514" link, getxattr will examine the symbolic link itself instead of the file\n"
5515" the link points to.");
5516
5517#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005518 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005519
5520static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005521os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005522 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005523
5524static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005525os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005526{
5527 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005528 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5529 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005530 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5531 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5532 int follow_symlinks = 1;
5533
Victor Stinner3e1fad62017-01-17 01:29:01 +01005534 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005535 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005536 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005537 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005538 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5539
5540exit:
5541 /* Cleanup for path */
5542 path_cleanup(&path);
5543 /* Cleanup for attribute */
5544 path_cleanup(&attribute);
5545
5546 return return_value;
5547}
5548
5549#endif /* defined(USE_XATTRS) */
5550
5551#if defined(USE_XATTRS)
5552
5553PyDoc_STRVAR(os_setxattr__doc__,
5554"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5555" follow_symlinks=True)\n"
5556"--\n"
5557"\n"
5558"Set extended attribute attribute on path to value.\n"
5559"\n"
5560"path may be either a string or an open file descriptor.\n"
5561"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5562" link, setxattr will modify the symbolic link itself instead of the file\n"
5563" the link points to.");
5564
5565#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005566 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005567
5568static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005569os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005570 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005571
5572static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005573os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005574{
5575 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005576 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5577 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005578 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5579 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5580 Py_buffer value = {NULL, NULL};
5581 int flags = 0;
5582 int follow_symlinks = 1;
5583
Victor Stinner3e1fad62017-01-17 01:29:01 +01005584 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005585 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005586 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005587 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005588 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5589
5590exit:
5591 /* Cleanup for path */
5592 path_cleanup(&path);
5593 /* Cleanup for attribute */
5594 path_cleanup(&attribute);
5595 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005596 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005597 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005598 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005599
5600 return return_value;
5601}
5602
5603#endif /* defined(USE_XATTRS) */
5604
5605#if defined(USE_XATTRS)
5606
5607PyDoc_STRVAR(os_removexattr__doc__,
5608"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5609"--\n"
5610"\n"
5611"Remove extended attribute attribute on path.\n"
5612"\n"
5613"path may be either a string or an open file descriptor.\n"
5614"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5615" link, removexattr will modify the symbolic link itself instead of the file\n"
5616" the link points to.");
5617
5618#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005619 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005620
5621static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005622os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005623 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005624
5625static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005626os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005627{
5628 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005629 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5630 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005631 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5632 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5633 int follow_symlinks = 1;
5634
Victor Stinner3e1fad62017-01-17 01:29:01 +01005635 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005636 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005637 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005638 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005639 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5640
5641exit:
5642 /* Cleanup for path */
5643 path_cleanup(&path);
5644 /* Cleanup for attribute */
5645 path_cleanup(&attribute);
5646
5647 return return_value;
5648}
5649
5650#endif /* defined(USE_XATTRS) */
5651
5652#if defined(USE_XATTRS)
5653
5654PyDoc_STRVAR(os_listxattr__doc__,
5655"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5656"--\n"
5657"\n"
5658"Return a list of extended attributes on path.\n"
5659"\n"
5660"path may be either None, a string, or an open file descriptor.\n"
5661"if path is None, listxattr will examine the current directory.\n"
5662"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5663" link, listxattr will examine the symbolic link itself instead of the file\n"
5664" the link points to.");
5665
5666#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005667 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005668
5669static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005670os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005671
5672static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005673os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005674{
5675 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005676 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5677 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005678 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5679 int follow_symlinks = 1;
5680
Victor Stinner3e1fad62017-01-17 01:29:01 +01005681 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005682 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005683 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005684 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005685 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5686
5687exit:
5688 /* Cleanup for path */
5689 path_cleanup(&path);
5690
5691 return return_value;
5692}
5693
5694#endif /* defined(USE_XATTRS) */
5695
5696PyDoc_STRVAR(os_urandom__doc__,
5697"urandom($module, size, /)\n"
5698"--\n"
5699"\n"
5700"Return a bytes object containing random bytes suitable for cryptographic use.");
5701
5702#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005703 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005704
5705static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005706os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005707
5708static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005709os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005710{
5711 PyObject *return_value = NULL;
5712 Py_ssize_t size;
5713
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005714 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005715 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005716 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005717 return_value = os_urandom_impl(module, size);
5718
5719exit:
5720 return return_value;
5721}
5722
5723PyDoc_STRVAR(os_cpu_count__doc__,
5724"cpu_count($module, /)\n"
5725"--\n"
5726"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005727"Return the number of CPUs in the system; return None if indeterminable.\n"
5728"\n"
5729"This number is not equivalent to the number of CPUs the current process can\n"
5730"use. The number of usable CPUs can be obtained with\n"
5731"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005732
5733#define OS_CPU_COUNT_METHODDEF \
5734 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5735
5736static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005737os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005738
5739static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005740os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005741{
5742 return os_cpu_count_impl(module);
5743}
5744
5745PyDoc_STRVAR(os_get_inheritable__doc__,
5746"get_inheritable($module, fd, /)\n"
5747"--\n"
5748"\n"
5749"Get the close-on-exe flag of the specified file descriptor.");
5750
5751#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005752 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005753
5754static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005755os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005756
5757static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005758os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005759{
5760 PyObject *return_value = NULL;
5761 int fd;
5762 int _return_value;
5763
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005764 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005765 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005766 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005767 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005768 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005769 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005770 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005771 return_value = PyBool_FromLong((long)_return_value);
5772
5773exit:
5774 return return_value;
5775}
5776
5777PyDoc_STRVAR(os_set_inheritable__doc__,
5778"set_inheritable($module, fd, inheritable, /)\n"
5779"--\n"
5780"\n"
5781"Set the inheritable flag of the specified file descriptor.");
5782
5783#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005784 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005785
5786static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005787os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005788
5789static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005790os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005791{
5792 PyObject *return_value = NULL;
5793 int fd;
5794 int inheritable;
5795
Sylvain74453812017-06-10 06:51:48 +02005796 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5797 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005798 goto exit;
5799 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005800 return_value = os_set_inheritable_impl(module, fd, inheritable);
5801
5802exit:
5803 return return_value;
5804}
5805
5806#if defined(MS_WINDOWS)
5807
5808PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5809"get_handle_inheritable($module, handle, /)\n"
5810"--\n"
5811"\n"
5812"Get the close-on-exe flag of the specified file descriptor.");
5813
5814#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005815 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005816
5817static int
Victor Stinner581139c2016-09-06 15:54:20 -07005818os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005819
5820static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005821os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005822{
5823 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005824 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005825 int _return_value;
5826
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005827 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005828 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005829 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005830 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005831 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005832 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005833 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005834 return_value = PyBool_FromLong((long)_return_value);
5835
5836exit:
5837 return return_value;
5838}
5839
5840#endif /* defined(MS_WINDOWS) */
5841
5842#if defined(MS_WINDOWS)
5843
5844PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5845"set_handle_inheritable($module, handle, inheritable, /)\n"
5846"--\n"
5847"\n"
5848"Set the inheritable flag of the specified handle.");
5849
5850#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005851 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005852
5853static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005854os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005855 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005856
5857static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005858os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005859{
5860 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005861 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005862 int inheritable;
5863
Sylvain74453812017-06-10 06:51:48 +02005864 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5865 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005866 goto exit;
5867 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005868 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5869
5870exit:
5871 return return_value;
5872}
5873
5874#endif /* defined(MS_WINDOWS) */
5875
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005876PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5877"is_symlink($self, /)\n"
5878"--\n"
5879"\n"
5880"Return True if the entry is a symbolic link; cached per entry.");
5881
5882#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5883 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5884
5885static int
5886os_DirEntry_is_symlink_impl(DirEntry *self);
5887
5888static PyObject *
5889os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5890{
5891 PyObject *return_value = NULL;
5892 int _return_value;
5893
5894 _return_value = os_DirEntry_is_symlink_impl(self);
5895 if ((_return_value == -1) && PyErr_Occurred()) {
5896 goto exit;
5897 }
5898 return_value = PyBool_FromLong((long)_return_value);
5899
5900exit:
5901 return return_value;
5902}
5903
5904PyDoc_STRVAR(os_DirEntry_stat__doc__,
5905"stat($self, /, *, follow_symlinks=True)\n"
5906"--\n"
5907"\n"
5908"Return stat_result object for the entry; cached per entry.");
5909
5910#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005911 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005912
5913static PyObject *
5914os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
5915
5916static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005917os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005918{
5919 PyObject *return_value = NULL;
5920 static const char * const _keywords[] = {"follow_symlinks", NULL};
5921 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
5922 int follow_symlinks = 1;
5923
Victor Stinner3e1fad62017-01-17 01:29:01 +01005924 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005925 &follow_symlinks)) {
5926 goto exit;
5927 }
5928 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
5929
5930exit:
5931 return return_value;
5932}
5933
5934PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
5935"is_dir($self, /, *, follow_symlinks=True)\n"
5936"--\n"
5937"\n"
5938"Return True if the entry is a directory; cached per entry.");
5939
5940#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005941 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005942
5943static int
5944os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
5945
5946static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005947os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005948{
5949 PyObject *return_value = NULL;
5950 static const char * const _keywords[] = {"follow_symlinks", NULL};
5951 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
5952 int follow_symlinks = 1;
5953 int _return_value;
5954
Victor Stinner3e1fad62017-01-17 01:29:01 +01005955 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005956 &follow_symlinks)) {
5957 goto exit;
5958 }
5959 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
5960 if ((_return_value == -1) && PyErr_Occurred()) {
5961 goto exit;
5962 }
5963 return_value = PyBool_FromLong((long)_return_value);
5964
5965exit:
5966 return return_value;
5967}
5968
5969PyDoc_STRVAR(os_DirEntry_is_file__doc__,
5970"is_file($self, /, *, follow_symlinks=True)\n"
5971"--\n"
5972"\n"
5973"Return True if the entry is a file; cached per entry.");
5974
5975#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005976 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005977
5978static int
5979os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
5980
5981static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005982os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005983{
5984 PyObject *return_value = NULL;
5985 static const char * const _keywords[] = {"follow_symlinks", NULL};
5986 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
5987 int follow_symlinks = 1;
5988 int _return_value;
5989
Victor Stinner3e1fad62017-01-17 01:29:01 +01005990 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005991 &follow_symlinks)) {
5992 goto exit;
5993 }
5994 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
5995 if ((_return_value == -1) && PyErr_Occurred()) {
5996 goto exit;
5997 }
5998 return_value = PyBool_FromLong((long)_return_value);
5999
6000exit:
6001 return return_value;
6002}
6003
6004PyDoc_STRVAR(os_DirEntry_inode__doc__,
6005"inode($self, /)\n"
6006"--\n"
6007"\n"
6008"Return inode of the entry; cached per entry.");
6009
6010#define OS_DIRENTRY_INODE_METHODDEF \
6011 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6012
6013static PyObject *
6014os_DirEntry_inode_impl(DirEntry *self);
6015
6016static PyObject *
6017os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6018{
6019 return os_DirEntry_inode_impl(self);
6020}
6021
6022PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6023"__fspath__($self, /)\n"
6024"--\n"
6025"\n"
6026"Returns the path for the entry.");
6027
6028#define OS_DIRENTRY___FSPATH___METHODDEF \
6029 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6030
6031static PyObject *
6032os_DirEntry___fspath___impl(DirEntry *self);
6033
6034static PyObject *
6035os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6036{
6037 return os_DirEntry___fspath___impl(self);
6038}
6039
6040PyDoc_STRVAR(os_scandir__doc__,
6041"scandir($module, /, path=None)\n"
6042"--\n"
6043"\n"
6044"Return an iterator of DirEntry objects for given path.\n"
6045"\n"
6046"path can be specified as either str, bytes or path-like object. If path\n"
6047"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6048"all other circumstances they will be str.\n"
6049"\n"
6050"If path is None, uses the path=\'.\'.");
6051
6052#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006053 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006054
6055static PyObject *
6056os_scandir_impl(PyObject *module, path_t *path);
6057
6058static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006059os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006060{
6061 PyObject *return_value = NULL;
6062 static const char * const _keywords[] = {"path", NULL};
6063 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006064 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006065
Victor Stinner3e1fad62017-01-17 01:29:01 +01006066 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006067 path_converter, &path)) {
6068 goto exit;
6069 }
6070 return_value = os_scandir_impl(module, &path);
6071
6072exit:
6073 /* Cleanup for path */
6074 path_cleanup(&path);
6075
6076 return return_value;
6077}
6078
Ethan Furman410ef8e2016-06-04 12:06:26 -07006079PyDoc_STRVAR(os_fspath__doc__,
6080"fspath($module, /, path)\n"
6081"--\n"
6082"\n"
6083"Return the file system path representation of the object.\n"
6084"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006085"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6086"object defines __fspath__(), then return the result of that method. All other\n"
6087"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006088
6089#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006090 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006091
6092static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006093os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006094
6095static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006096os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006097{
6098 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006099 static const char * const _keywords[] = {"path", NULL};
6100 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006101 PyObject *path;
6102
Victor Stinner3e1fad62017-01-17 01:29:01 +01006103 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006104 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006105 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006106 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006107 return_value = os_fspath_impl(module, path);
6108
6109exit:
6110 return return_value;
6111}
6112
Victor Stinner9b1f4742016-09-06 16:18:52 -07006113#if defined(HAVE_GETRANDOM_SYSCALL)
6114
6115PyDoc_STRVAR(os_getrandom__doc__,
6116"getrandom($module, /, size, flags=0)\n"
6117"--\n"
6118"\n"
6119"Obtain a series of random bytes.");
6120
6121#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006122 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006123
6124static PyObject *
6125os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6126
6127static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006128os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006129{
6130 PyObject *return_value = NULL;
6131 static const char * const _keywords[] = {"size", "flags", NULL};
6132 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6133 Py_ssize_t size;
6134 int flags = 0;
6135
Victor Stinner3e1fad62017-01-17 01:29:01 +01006136 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006137 &size, &flags)) {
6138 goto exit;
6139 }
6140 return_value = os_getrandom_impl(module, size, flags);
6141
6142exit:
6143 return return_value;
6144}
6145
6146#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6147
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006148#ifndef OS_TTYNAME_METHODDEF
6149 #define OS_TTYNAME_METHODDEF
6150#endif /* !defined(OS_TTYNAME_METHODDEF) */
6151
6152#ifndef OS_CTERMID_METHODDEF
6153 #define OS_CTERMID_METHODDEF
6154#endif /* !defined(OS_CTERMID_METHODDEF) */
6155
6156#ifndef OS_FCHDIR_METHODDEF
6157 #define OS_FCHDIR_METHODDEF
6158#endif /* !defined(OS_FCHDIR_METHODDEF) */
6159
6160#ifndef OS_FCHMOD_METHODDEF
6161 #define OS_FCHMOD_METHODDEF
6162#endif /* !defined(OS_FCHMOD_METHODDEF) */
6163
6164#ifndef OS_LCHMOD_METHODDEF
6165 #define OS_LCHMOD_METHODDEF
6166#endif /* !defined(OS_LCHMOD_METHODDEF) */
6167
6168#ifndef OS_CHFLAGS_METHODDEF
6169 #define OS_CHFLAGS_METHODDEF
6170#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6171
6172#ifndef OS_LCHFLAGS_METHODDEF
6173 #define OS_LCHFLAGS_METHODDEF
6174#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6175
6176#ifndef OS_CHROOT_METHODDEF
6177 #define OS_CHROOT_METHODDEF
6178#endif /* !defined(OS_CHROOT_METHODDEF) */
6179
6180#ifndef OS_FSYNC_METHODDEF
6181 #define OS_FSYNC_METHODDEF
6182#endif /* !defined(OS_FSYNC_METHODDEF) */
6183
6184#ifndef OS_SYNC_METHODDEF
6185 #define OS_SYNC_METHODDEF
6186#endif /* !defined(OS_SYNC_METHODDEF) */
6187
6188#ifndef OS_FDATASYNC_METHODDEF
6189 #define OS_FDATASYNC_METHODDEF
6190#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6191
6192#ifndef OS_CHOWN_METHODDEF
6193 #define OS_CHOWN_METHODDEF
6194#endif /* !defined(OS_CHOWN_METHODDEF) */
6195
6196#ifndef OS_FCHOWN_METHODDEF
6197 #define OS_FCHOWN_METHODDEF
6198#endif /* !defined(OS_FCHOWN_METHODDEF) */
6199
6200#ifndef OS_LCHOWN_METHODDEF
6201 #define OS_LCHOWN_METHODDEF
6202#endif /* !defined(OS_LCHOWN_METHODDEF) */
6203
6204#ifndef OS_LINK_METHODDEF
6205 #define OS_LINK_METHODDEF
6206#endif /* !defined(OS_LINK_METHODDEF) */
6207
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006208#ifndef OS__GETFULLPATHNAME_METHODDEF
6209 #define OS__GETFULLPATHNAME_METHODDEF
6210#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6211
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006212#ifndef OS__GETFINALPATHNAME_METHODDEF
6213 #define OS__GETFINALPATHNAME_METHODDEF
6214#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6215
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006216#ifndef OS__ISDIR_METHODDEF
6217 #define OS__ISDIR_METHODDEF
6218#endif /* !defined(OS__ISDIR_METHODDEF) */
6219
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006220#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6221 #define OS__GETVOLUMEPATHNAME_METHODDEF
6222#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6223
6224#ifndef OS_NICE_METHODDEF
6225 #define OS_NICE_METHODDEF
6226#endif /* !defined(OS_NICE_METHODDEF) */
6227
6228#ifndef OS_GETPRIORITY_METHODDEF
6229 #define OS_GETPRIORITY_METHODDEF
6230#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6231
6232#ifndef OS_SETPRIORITY_METHODDEF
6233 #define OS_SETPRIORITY_METHODDEF
6234#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6235
6236#ifndef OS_SYSTEM_METHODDEF
6237 #define OS_SYSTEM_METHODDEF
6238#endif /* !defined(OS_SYSTEM_METHODDEF) */
6239
6240#ifndef OS_UNAME_METHODDEF
6241 #define OS_UNAME_METHODDEF
6242#endif /* !defined(OS_UNAME_METHODDEF) */
6243
6244#ifndef OS_EXECV_METHODDEF
6245 #define OS_EXECV_METHODDEF
6246#endif /* !defined(OS_EXECV_METHODDEF) */
6247
6248#ifndef OS_EXECVE_METHODDEF
6249 #define OS_EXECVE_METHODDEF
6250#endif /* !defined(OS_EXECVE_METHODDEF) */
6251
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006252#ifndef OS_POSIX_SPAWN_METHODDEF
6253 #define OS_POSIX_SPAWN_METHODDEF
6254#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6255
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006256#ifndef OS_SPAWNV_METHODDEF
6257 #define OS_SPAWNV_METHODDEF
6258#endif /* !defined(OS_SPAWNV_METHODDEF) */
6259
6260#ifndef OS_SPAWNVE_METHODDEF
6261 #define OS_SPAWNVE_METHODDEF
6262#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6263
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006264#ifndef OS_REGISTER_AT_FORK_METHODDEF
6265 #define OS_REGISTER_AT_FORK_METHODDEF
6266#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6267
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006268#ifndef OS_FORK1_METHODDEF
6269 #define OS_FORK1_METHODDEF
6270#endif /* !defined(OS_FORK1_METHODDEF) */
6271
6272#ifndef OS_FORK_METHODDEF
6273 #define OS_FORK_METHODDEF
6274#endif /* !defined(OS_FORK_METHODDEF) */
6275
6276#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6277 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6278#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6279
6280#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6281 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6282#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6283
6284#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6285 #define OS_SCHED_GETSCHEDULER_METHODDEF
6286#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6287
6288#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6289 #define OS_SCHED_SETSCHEDULER_METHODDEF
6290#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6291
6292#ifndef OS_SCHED_GETPARAM_METHODDEF
6293 #define OS_SCHED_GETPARAM_METHODDEF
6294#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6295
6296#ifndef OS_SCHED_SETPARAM_METHODDEF
6297 #define OS_SCHED_SETPARAM_METHODDEF
6298#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6299
6300#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6301 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6302#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6303
6304#ifndef OS_SCHED_YIELD_METHODDEF
6305 #define OS_SCHED_YIELD_METHODDEF
6306#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6307
6308#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6309 #define OS_SCHED_SETAFFINITY_METHODDEF
6310#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6311
6312#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6313 #define OS_SCHED_GETAFFINITY_METHODDEF
6314#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6315
6316#ifndef OS_OPENPTY_METHODDEF
6317 #define OS_OPENPTY_METHODDEF
6318#endif /* !defined(OS_OPENPTY_METHODDEF) */
6319
6320#ifndef OS_FORKPTY_METHODDEF
6321 #define OS_FORKPTY_METHODDEF
6322#endif /* !defined(OS_FORKPTY_METHODDEF) */
6323
6324#ifndef OS_GETEGID_METHODDEF
6325 #define OS_GETEGID_METHODDEF
6326#endif /* !defined(OS_GETEGID_METHODDEF) */
6327
6328#ifndef OS_GETEUID_METHODDEF
6329 #define OS_GETEUID_METHODDEF
6330#endif /* !defined(OS_GETEUID_METHODDEF) */
6331
6332#ifndef OS_GETGID_METHODDEF
6333 #define OS_GETGID_METHODDEF
6334#endif /* !defined(OS_GETGID_METHODDEF) */
6335
Berker Peksag39404992016-09-15 20:45:16 +03006336#ifndef OS_GETPID_METHODDEF
6337 #define OS_GETPID_METHODDEF
6338#endif /* !defined(OS_GETPID_METHODDEF) */
6339
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006340#ifndef OS_GETGROUPS_METHODDEF
6341 #define OS_GETGROUPS_METHODDEF
6342#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6343
6344#ifndef OS_GETPGID_METHODDEF
6345 #define OS_GETPGID_METHODDEF
6346#endif /* !defined(OS_GETPGID_METHODDEF) */
6347
6348#ifndef OS_GETPGRP_METHODDEF
6349 #define OS_GETPGRP_METHODDEF
6350#endif /* !defined(OS_GETPGRP_METHODDEF) */
6351
6352#ifndef OS_SETPGRP_METHODDEF
6353 #define OS_SETPGRP_METHODDEF
6354#endif /* !defined(OS_SETPGRP_METHODDEF) */
6355
6356#ifndef OS_GETPPID_METHODDEF
6357 #define OS_GETPPID_METHODDEF
6358#endif /* !defined(OS_GETPPID_METHODDEF) */
6359
6360#ifndef OS_GETLOGIN_METHODDEF
6361 #define OS_GETLOGIN_METHODDEF
6362#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6363
6364#ifndef OS_GETUID_METHODDEF
6365 #define OS_GETUID_METHODDEF
6366#endif /* !defined(OS_GETUID_METHODDEF) */
6367
6368#ifndef OS_KILL_METHODDEF
6369 #define OS_KILL_METHODDEF
6370#endif /* !defined(OS_KILL_METHODDEF) */
6371
6372#ifndef OS_KILLPG_METHODDEF
6373 #define OS_KILLPG_METHODDEF
6374#endif /* !defined(OS_KILLPG_METHODDEF) */
6375
6376#ifndef OS_PLOCK_METHODDEF
6377 #define OS_PLOCK_METHODDEF
6378#endif /* !defined(OS_PLOCK_METHODDEF) */
6379
6380#ifndef OS_SETUID_METHODDEF
6381 #define OS_SETUID_METHODDEF
6382#endif /* !defined(OS_SETUID_METHODDEF) */
6383
6384#ifndef OS_SETEUID_METHODDEF
6385 #define OS_SETEUID_METHODDEF
6386#endif /* !defined(OS_SETEUID_METHODDEF) */
6387
6388#ifndef OS_SETEGID_METHODDEF
6389 #define OS_SETEGID_METHODDEF
6390#endif /* !defined(OS_SETEGID_METHODDEF) */
6391
6392#ifndef OS_SETREUID_METHODDEF
6393 #define OS_SETREUID_METHODDEF
6394#endif /* !defined(OS_SETREUID_METHODDEF) */
6395
6396#ifndef OS_SETREGID_METHODDEF
6397 #define OS_SETREGID_METHODDEF
6398#endif /* !defined(OS_SETREGID_METHODDEF) */
6399
6400#ifndef OS_SETGID_METHODDEF
6401 #define OS_SETGID_METHODDEF
6402#endif /* !defined(OS_SETGID_METHODDEF) */
6403
6404#ifndef OS_SETGROUPS_METHODDEF
6405 #define OS_SETGROUPS_METHODDEF
6406#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6407
6408#ifndef OS_WAIT3_METHODDEF
6409 #define OS_WAIT3_METHODDEF
6410#endif /* !defined(OS_WAIT3_METHODDEF) */
6411
6412#ifndef OS_WAIT4_METHODDEF
6413 #define OS_WAIT4_METHODDEF
6414#endif /* !defined(OS_WAIT4_METHODDEF) */
6415
6416#ifndef OS_WAITID_METHODDEF
6417 #define OS_WAITID_METHODDEF
6418#endif /* !defined(OS_WAITID_METHODDEF) */
6419
6420#ifndef OS_WAITPID_METHODDEF
6421 #define OS_WAITPID_METHODDEF
6422#endif /* !defined(OS_WAITPID_METHODDEF) */
6423
6424#ifndef OS_WAIT_METHODDEF
6425 #define OS_WAIT_METHODDEF
6426#endif /* !defined(OS_WAIT_METHODDEF) */
6427
6428#ifndef OS_SYMLINK_METHODDEF
6429 #define OS_SYMLINK_METHODDEF
6430#endif /* !defined(OS_SYMLINK_METHODDEF) */
6431
6432#ifndef OS_TIMES_METHODDEF
6433 #define OS_TIMES_METHODDEF
6434#endif /* !defined(OS_TIMES_METHODDEF) */
6435
6436#ifndef OS_GETSID_METHODDEF
6437 #define OS_GETSID_METHODDEF
6438#endif /* !defined(OS_GETSID_METHODDEF) */
6439
6440#ifndef OS_SETSID_METHODDEF
6441 #define OS_SETSID_METHODDEF
6442#endif /* !defined(OS_SETSID_METHODDEF) */
6443
6444#ifndef OS_SETPGID_METHODDEF
6445 #define OS_SETPGID_METHODDEF
6446#endif /* !defined(OS_SETPGID_METHODDEF) */
6447
6448#ifndef OS_TCGETPGRP_METHODDEF
6449 #define OS_TCGETPGRP_METHODDEF
6450#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6451
6452#ifndef OS_TCSETPGRP_METHODDEF
6453 #define OS_TCSETPGRP_METHODDEF
6454#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6455
6456#ifndef OS_LOCKF_METHODDEF
6457 #define OS_LOCKF_METHODDEF
6458#endif /* !defined(OS_LOCKF_METHODDEF) */
6459
6460#ifndef OS_READV_METHODDEF
6461 #define OS_READV_METHODDEF
6462#endif /* !defined(OS_READV_METHODDEF) */
6463
6464#ifndef OS_PREAD_METHODDEF
6465 #define OS_PREAD_METHODDEF
6466#endif /* !defined(OS_PREAD_METHODDEF) */
6467
Pablo Galindo4defba32018-01-27 16:16:37 +00006468#ifndef OS_PREADV_METHODDEF
6469 #define OS_PREADV_METHODDEF
6470#endif /* !defined(OS_PREADV_METHODDEF) */
6471
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02006472#ifndef OS__FCOPYFILE_METHODDEF
6473 #define OS__FCOPYFILE_METHODDEF
6474#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
6475
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006476#ifndef OS_PIPE_METHODDEF
6477 #define OS_PIPE_METHODDEF
6478#endif /* !defined(OS_PIPE_METHODDEF) */
6479
6480#ifndef OS_PIPE2_METHODDEF
6481 #define OS_PIPE2_METHODDEF
6482#endif /* !defined(OS_PIPE2_METHODDEF) */
6483
6484#ifndef OS_WRITEV_METHODDEF
6485 #define OS_WRITEV_METHODDEF
6486#endif /* !defined(OS_WRITEV_METHODDEF) */
6487
6488#ifndef OS_PWRITE_METHODDEF
6489 #define OS_PWRITE_METHODDEF
6490#endif /* !defined(OS_PWRITE_METHODDEF) */
6491
Pablo Galindo4defba32018-01-27 16:16:37 +00006492#ifndef OS_PWRITEV_METHODDEF
6493 #define OS_PWRITEV_METHODDEF
6494#endif /* !defined(OS_PWRITEV_METHODDEF) */
6495
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006496#ifndef OS_MKFIFO_METHODDEF
6497 #define OS_MKFIFO_METHODDEF
6498#endif /* !defined(OS_MKFIFO_METHODDEF) */
6499
6500#ifndef OS_MKNOD_METHODDEF
6501 #define OS_MKNOD_METHODDEF
6502#endif /* !defined(OS_MKNOD_METHODDEF) */
6503
6504#ifndef OS_MAJOR_METHODDEF
6505 #define OS_MAJOR_METHODDEF
6506#endif /* !defined(OS_MAJOR_METHODDEF) */
6507
6508#ifndef OS_MINOR_METHODDEF
6509 #define OS_MINOR_METHODDEF
6510#endif /* !defined(OS_MINOR_METHODDEF) */
6511
6512#ifndef OS_MAKEDEV_METHODDEF
6513 #define OS_MAKEDEV_METHODDEF
6514#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6515
6516#ifndef OS_FTRUNCATE_METHODDEF
6517 #define OS_FTRUNCATE_METHODDEF
6518#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6519
6520#ifndef OS_TRUNCATE_METHODDEF
6521 #define OS_TRUNCATE_METHODDEF
6522#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6523
6524#ifndef OS_POSIX_FALLOCATE_METHODDEF
6525 #define OS_POSIX_FALLOCATE_METHODDEF
6526#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6527
6528#ifndef OS_POSIX_FADVISE_METHODDEF
6529 #define OS_POSIX_FADVISE_METHODDEF
6530#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6531
6532#ifndef OS_PUTENV_METHODDEF
6533 #define OS_PUTENV_METHODDEF
6534#endif /* !defined(OS_PUTENV_METHODDEF) */
6535
6536#ifndef OS_UNSETENV_METHODDEF
6537 #define OS_UNSETENV_METHODDEF
6538#endif /* !defined(OS_UNSETENV_METHODDEF) */
6539
6540#ifndef OS_WCOREDUMP_METHODDEF
6541 #define OS_WCOREDUMP_METHODDEF
6542#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6543
6544#ifndef OS_WIFCONTINUED_METHODDEF
6545 #define OS_WIFCONTINUED_METHODDEF
6546#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6547
6548#ifndef OS_WIFSTOPPED_METHODDEF
6549 #define OS_WIFSTOPPED_METHODDEF
6550#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6551
6552#ifndef OS_WIFSIGNALED_METHODDEF
6553 #define OS_WIFSIGNALED_METHODDEF
6554#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6555
6556#ifndef OS_WIFEXITED_METHODDEF
6557 #define OS_WIFEXITED_METHODDEF
6558#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6559
6560#ifndef OS_WEXITSTATUS_METHODDEF
6561 #define OS_WEXITSTATUS_METHODDEF
6562#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6563
6564#ifndef OS_WTERMSIG_METHODDEF
6565 #define OS_WTERMSIG_METHODDEF
6566#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6567
6568#ifndef OS_WSTOPSIG_METHODDEF
6569 #define OS_WSTOPSIG_METHODDEF
6570#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6571
6572#ifndef OS_FSTATVFS_METHODDEF
6573 #define OS_FSTATVFS_METHODDEF
6574#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6575
6576#ifndef OS_STATVFS_METHODDEF
6577 #define OS_STATVFS_METHODDEF
6578#endif /* !defined(OS_STATVFS_METHODDEF) */
6579
6580#ifndef OS__GETDISKUSAGE_METHODDEF
6581 #define OS__GETDISKUSAGE_METHODDEF
6582#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6583
6584#ifndef OS_FPATHCONF_METHODDEF
6585 #define OS_FPATHCONF_METHODDEF
6586#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6587
6588#ifndef OS_PATHCONF_METHODDEF
6589 #define OS_PATHCONF_METHODDEF
6590#endif /* !defined(OS_PATHCONF_METHODDEF) */
6591
6592#ifndef OS_CONFSTR_METHODDEF
6593 #define OS_CONFSTR_METHODDEF
6594#endif /* !defined(OS_CONFSTR_METHODDEF) */
6595
6596#ifndef OS_SYSCONF_METHODDEF
6597 #define OS_SYSCONF_METHODDEF
6598#endif /* !defined(OS_SYSCONF_METHODDEF) */
6599
Steve Dowercc16be82016-09-08 10:35:16 -07006600#ifndef OS_STARTFILE_METHODDEF
6601 #define OS_STARTFILE_METHODDEF
6602#endif /* !defined(OS_STARTFILE_METHODDEF) */
6603
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006604#ifndef OS_GETLOADAVG_METHODDEF
6605 #define OS_GETLOADAVG_METHODDEF
6606#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6607
6608#ifndef OS_SETRESUID_METHODDEF
6609 #define OS_SETRESUID_METHODDEF
6610#endif /* !defined(OS_SETRESUID_METHODDEF) */
6611
6612#ifndef OS_SETRESGID_METHODDEF
6613 #define OS_SETRESGID_METHODDEF
6614#endif /* !defined(OS_SETRESGID_METHODDEF) */
6615
6616#ifndef OS_GETRESUID_METHODDEF
6617 #define OS_GETRESUID_METHODDEF
6618#endif /* !defined(OS_GETRESUID_METHODDEF) */
6619
6620#ifndef OS_GETRESGID_METHODDEF
6621 #define OS_GETRESGID_METHODDEF
6622#endif /* !defined(OS_GETRESGID_METHODDEF) */
6623
6624#ifndef OS_GETXATTR_METHODDEF
6625 #define OS_GETXATTR_METHODDEF
6626#endif /* !defined(OS_GETXATTR_METHODDEF) */
6627
6628#ifndef OS_SETXATTR_METHODDEF
6629 #define OS_SETXATTR_METHODDEF
6630#endif /* !defined(OS_SETXATTR_METHODDEF) */
6631
6632#ifndef OS_REMOVEXATTR_METHODDEF
6633 #define OS_REMOVEXATTR_METHODDEF
6634#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6635
6636#ifndef OS_LISTXATTR_METHODDEF
6637 #define OS_LISTXATTR_METHODDEF
6638#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6639
6640#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6641 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6642#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6643
6644#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6645 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6646#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006647
6648#ifndef OS_GETRANDOM_METHODDEF
6649 #define OS_GETRANDOM_METHODDEF
6650#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Pablo Galindo254a4662018-09-07 16:44:24 +01006651/*[clinic end generated code: output=ef78384ae88712e1 input=a9049054013a1b77]*/