blob: 2c46d4bf172e08ebda0052dd2cb0c57ca1414f09 [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__,
Serhiy Storchakad700f972018-09-08 14:48:18 +03001733"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001734" 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;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001772 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL};
1773 static _PyArg_Parser _parser = {"O&OO|$OOiOOO: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;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001777 PyObject *file_actions = NULL;
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
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003189#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3190
3191PyDoc_STRVAR(os_readlink__doc__,
3192"readlink($module, /, path, *, dir_fd=None)\n"
3193"--\n"
3194"\n"
3195"Return a string representing the path to which the symbolic link points.\n"
3196"\n"
3197"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3198"and path should be relative; path will then be relative to that directory.\n"
3199"\n"
3200"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3201"using it will raise a NotImplementedError.");
3202
3203#define OS_READLINK_METHODDEF \
3204 {"readlink", (PyCFunction)os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
3205
3206static PyObject *
3207os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3208
3209static PyObject *
3210os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3211{
3212 PyObject *return_value = NULL;
3213 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3214 static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0};
3215 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3216 int dir_fd = DEFAULT_DIR_FD;
3217
3218 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3219 path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3220 goto exit;
3221 }
3222 return_value = os_readlink_impl(module, &path, dir_fd);
3223
3224exit:
3225 /* Cleanup for path */
3226 path_cleanup(&path);
3227
3228 return return_value;
3229}
3230
3231#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
3232
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003233#if defined(HAVE_SYMLINK)
3234
3235PyDoc_STRVAR(os_symlink__doc__,
3236"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3237"--\n"
3238"\n"
3239"Create a symbolic link pointing to src named dst.\n"
3240"\n"
3241"target_is_directory is required on Windows if the target is to be\n"
3242" interpreted as a directory. (On Windows, symlink requires\n"
3243" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3244" target_is_directory is ignored on non-Windows platforms.\n"
3245"\n"
3246"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3247" and path should be relative; path will then be relative to that directory.\n"
3248"dir_fd may not be implemented on your platform.\n"
3249" If it is unavailable, using it will raise a NotImplementedError.");
3250
3251#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003252 {"symlink", (PyCFunction)os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003253
3254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003255os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003256 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003257
3258static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003259os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003260{
3261 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003262 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3263 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003264 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3265 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3266 int target_is_directory = 0;
3267 int dir_fd = DEFAULT_DIR_FD;
3268
Victor Stinner3e1fad62017-01-17 01:29:01 +01003269 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003270 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003271 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003272 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003273 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3274
3275exit:
3276 /* Cleanup for src */
3277 path_cleanup(&src);
3278 /* Cleanup for dst */
3279 path_cleanup(&dst);
3280
3281 return return_value;
3282}
3283
3284#endif /* defined(HAVE_SYMLINK) */
3285
3286#if defined(HAVE_TIMES)
3287
3288PyDoc_STRVAR(os_times__doc__,
3289"times($module, /)\n"
3290"--\n"
3291"\n"
3292"Return a collection containing process timing information.\n"
3293"\n"
3294"The object returned behaves like a named tuple with these fields:\n"
3295" (utime, stime, cutime, cstime, elapsed_time)\n"
3296"All fields are floating point numbers.");
3297
3298#define OS_TIMES_METHODDEF \
3299 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3300
3301static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003302os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003303
3304static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003305os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003306{
3307 return os_times_impl(module);
3308}
3309
3310#endif /* defined(HAVE_TIMES) */
3311
3312#if defined(HAVE_GETSID)
3313
3314PyDoc_STRVAR(os_getsid__doc__,
3315"getsid($module, pid, /)\n"
3316"--\n"
3317"\n"
3318"Call the system call getsid(pid) and return the result.");
3319
3320#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003321 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003322
3323static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003324os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003325
3326static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003327os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003328{
3329 PyObject *return_value = NULL;
3330 pid_t pid;
3331
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003332 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003333 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003334 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003335 return_value = os_getsid_impl(module, pid);
3336
3337exit:
3338 return return_value;
3339}
3340
3341#endif /* defined(HAVE_GETSID) */
3342
3343#if defined(HAVE_SETSID)
3344
3345PyDoc_STRVAR(os_setsid__doc__,
3346"setsid($module, /)\n"
3347"--\n"
3348"\n"
3349"Call the system call setsid().");
3350
3351#define OS_SETSID_METHODDEF \
3352 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3353
3354static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003355os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003356
3357static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003358os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003359{
3360 return os_setsid_impl(module);
3361}
3362
3363#endif /* defined(HAVE_SETSID) */
3364
3365#if defined(HAVE_SETPGID)
3366
3367PyDoc_STRVAR(os_setpgid__doc__,
3368"setpgid($module, pid, pgrp, /)\n"
3369"--\n"
3370"\n"
3371"Call the system call setpgid(pid, pgrp).");
3372
3373#define OS_SETPGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003374 {"setpgid", (PyCFunction)os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003375
3376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003377os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378
3379static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003380os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003381{
3382 PyObject *return_value = NULL;
3383 pid_t pid;
3384 pid_t pgrp;
3385
Sylvain74453812017-06-10 06:51:48 +02003386 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3387 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003388 goto exit;
3389 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003390 return_value = os_setpgid_impl(module, pid, pgrp);
3391
3392exit:
3393 return return_value;
3394}
3395
3396#endif /* defined(HAVE_SETPGID) */
3397
3398#if defined(HAVE_TCGETPGRP)
3399
3400PyDoc_STRVAR(os_tcgetpgrp__doc__,
3401"tcgetpgrp($module, fd, /)\n"
3402"--\n"
3403"\n"
3404"Return the process group associated with the terminal specified by fd.");
3405
3406#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003407 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003408
3409static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003410os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411
3412static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003413os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003414{
3415 PyObject *return_value = NULL;
3416 int fd;
3417
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003418 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003419 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003420 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003421 return_value = os_tcgetpgrp_impl(module, fd);
3422
3423exit:
3424 return return_value;
3425}
3426
3427#endif /* defined(HAVE_TCGETPGRP) */
3428
3429#if defined(HAVE_TCSETPGRP)
3430
3431PyDoc_STRVAR(os_tcsetpgrp__doc__,
3432"tcsetpgrp($module, fd, pgid, /)\n"
3433"--\n"
3434"\n"
3435"Set the process group associated with the terminal specified by fd.");
3436
3437#define OS_TCSETPGRP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003438 {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003439
3440static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003441os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003442
3443static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003444os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003445{
3446 PyObject *return_value = NULL;
3447 int fd;
3448 pid_t pgid;
3449
Sylvain74453812017-06-10 06:51:48 +02003450 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3451 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003452 goto exit;
3453 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003454 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3455
3456exit:
3457 return return_value;
3458}
3459
3460#endif /* defined(HAVE_TCSETPGRP) */
3461
3462PyDoc_STRVAR(os_open__doc__,
3463"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3464"--\n"
3465"\n"
3466"Open a file for low level IO. Returns a file descriptor (integer).\n"
3467"\n"
3468"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3469" and path should be relative; path will then be relative to that directory.\n"
3470"dir_fd may not be implemented on your platform.\n"
3471" If it is unavailable, using it will raise a NotImplementedError.");
3472
3473#define OS_OPEN_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003474 {"open", (PyCFunction)os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003475
3476static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003477os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003478
3479static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003480os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003481{
3482 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003483 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3484 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003485 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3486 int flags;
3487 int mode = 511;
3488 int dir_fd = DEFAULT_DIR_FD;
3489 int _return_value;
3490
Victor Stinner3e1fad62017-01-17 01:29:01 +01003491 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003492 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003493 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003494 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003495 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003496 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003497 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003498 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003499 return_value = PyLong_FromLong((long)_return_value);
3500
3501exit:
3502 /* Cleanup for path */
3503 path_cleanup(&path);
3504
3505 return return_value;
3506}
3507
3508PyDoc_STRVAR(os_close__doc__,
3509"close($module, /, fd)\n"
3510"--\n"
3511"\n"
3512"Close a file descriptor.");
3513
3514#define OS_CLOSE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003515 {"close", (PyCFunction)os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003516
3517static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003518os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003519
3520static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003521os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003522{
3523 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003524 static const char * const _keywords[] = {"fd", NULL};
3525 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003526 int fd;
3527
Victor Stinner3e1fad62017-01-17 01:29:01 +01003528 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003529 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003530 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003531 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003532 return_value = os_close_impl(module, fd);
3533
3534exit:
3535 return return_value;
3536}
3537
3538PyDoc_STRVAR(os_closerange__doc__,
3539"closerange($module, fd_low, fd_high, /)\n"
3540"--\n"
3541"\n"
3542"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3543
3544#define OS_CLOSERANGE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003545 {"closerange", (PyCFunction)os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003546
3547static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003548os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003549
3550static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003551os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003552{
3553 PyObject *return_value = NULL;
3554 int fd_low;
3555 int fd_high;
3556
Sylvain74453812017-06-10 06:51:48 +02003557 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3558 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003559 goto exit;
3560 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003561 return_value = os_closerange_impl(module, fd_low, fd_high);
3562
3563exit:
3564 return return_value;
3565}
3566
3567PyDoc_STRVAR(os_dup__doc__,
3568"dup($module, fd, /)\n"
3569"--\n"
3570"\n"
3571"Return a duplicate of a file descriptor.");
3572
3573#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003574 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003575
3576static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003577os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003578
3579static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003580os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003581{
3582 PyObject *return_value = NULL;
3583 int fd;
3584 int _return_value;
3585
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003586 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003587 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003588 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003589 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003590 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003591 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003592 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003593 return_value = PyLong_FromLong((long)_return_value);
3594
3595exit:
3596 return return_value;
3597}
3598
3599PyDoc_STRVAR(os_dup2__doc__,
3600"dup2($module, /, fd, fd2, inheritable=True)\n"
3601"--\n"
3602"\n"
3603"Duplicate file descriptor.");
3604
3605#define OS_DUP2_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003606 {"dup2", (PyCFunction)os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003607
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003608static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003609os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003610
3611static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003612os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003613{
3614 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003615 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3616 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003617 int fd;
3618 int fd2;
3619 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003620 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003621
Victor Stinner3e1fad62017-01-17 01:29:01 +01003622 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003623 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003624 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003625 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003626 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3627 if ((_return_value == -1) && PyErr_Occurred()) {
3628 goto exit;
3629 }
3630 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003631
3632exit:
3633 return return_value;
3634}
3635
3636#if defined(HAVE_LOCKF)
3637
3638PyDoc_STRVAR(os_lockf__doc__,
3639"lockf($module, fd, command, length, /)\n"
3640"--\n"
3641"\n"
3642"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3643"\n"
3644" fd\n"
3645" An open file descriptor.\n"
3646" command\n"
3647" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3648" length\n"
3649" The number of bytes to lock, starting at the current position.");
3650
3651#define OS_LOCKF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003652 {"lockf", (PyCFunction)os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003653
3654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003655os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003656
3657static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003658os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003659{
3660 PyObject *return_value = NULL;
3661 int fd;
3662 int command;
3663 Py_off_t length;
3664
Sylvain74453812017-06-10 06:51:48 +02003665 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3666 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003667 goto exit;
3668 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003669 return_value = os_lockf_impl(module, fd, command, length);
3670
3671exit:
3672 return return_value;
3673}
3674
3675#endif /* defined(HAVE_LOCKF) */
3676
3677PyDoc_STRVAR(os_lseek__doc__,
3678"lseek($module, fd, position, how, /)\n"
3679"--\n"
3680"\n"
3681"Set the position of a file descriptor. Return the new position.\n"
3682"\n"
3683"Return the new cursor position in number of bytes\n"
3684"relative to the beginning of the file.");
3685
3686#define OS_LSEEK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003687 {"lseek", (PyCFunction)os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003688
3689static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003690os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003691
3692static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003693os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003694{
3695 PyObject *return_value = NULL;
3696 int fd;
3697 Py_off_t position;
3698 int how;
3699 Py_off_t _return_value;
3700
Sylvain74453812017-06-10 06:51:48 +02003701 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3702 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003703 goto exit;
3704 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003705 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003706 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003707 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003708 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003709 return_value = PyLong_FromPy_off_t(_return_value);
3710
3711exit:
3712 return return_value;
3713}
3714
3715PyDoc_STRVAR(os_read__doc__,
3716"read($module, fd, length, /)\n"
3717"--\n"
3718"\n"
3719"Read from a file descriptor. Returns a bytes object.");
3720
3721#define OS_READ_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003722 {"read", (PyCFunction)os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003723
3724static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003725os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003726
3727static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003728os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003729{
3730 PyObject *return_value = NULL;
3731 int fd;
3732 Py_ssize_t length;
3733
Sylvain74453812017-06-10 06:51:48 +02003734 if (!_PyArg_ParseStack(args, nargs, "in:read",
3735 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003736 goto exit;
3737 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003738 return_value = os_read_impl(module, fd, length);
3739
3740exit:
3741 return return_value;
3742}
3743
3744#if defined(HAVE_READV)
3745
3746PyDoc_STRVAR(os_readv__doc__,
3747"readv($module, fd, buffers, /)\n"
3748"--\n"
3749"\n"
3750"Read from a file descriptor fd into an iterable of buffers.\n"
3751"\n"
3752"The buffers should be mutable buffers accepting bytes.\n"
3753"readv will transfer data into each buffer until it is full\n"
3754"and then move on to the next buffer in the sequence to hold\n"
3755"the rest of the data.\n"
3756"\n"
3757"readv returns the total number of bytes read,\n"
3758"which may be less than the total capacity of all the buffers.");
3759
3760#define OS_READV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003761 {"readv", (PyCFunction)os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003762
3763static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003764os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003765
3766static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003767os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003768{
3769 PyObject *return_value = NULL;
3770 int fd;
3771 PyObject *buffers;
3772 Py_ssize_t _return_value;
3773
Sylvain74453812017-06-10 06:51:48 +02003774 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3775 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003776 goto exit;
3777 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003778 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003779 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003780 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003781 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003782 return_value = PyLong_FromSsize_t(_return_value);
3783
3784exit:
3785 return return_value;
3786}
3787
3788#endif /* defined(HAVE_READV) */
3789
3790#if defined(HAVE_PREAD)
3791
3792PyDoc_STRVAR(os_pread__doc__,
3793"pread($module, fd, length, offset, /)\n"
3794"--\n"
3795"\n"
3796"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3797"\n"
3798"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3799"the beginning of the file. The file offset remains unchanged.");
3800
3801#define OS_PREAD_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003802 {"pread", (PyCFunction)os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003803
3804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003805os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003806
3807static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003808os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003809{
3810 PyObject *return_value = NULL;
3811 int fd;
3812 int length;
3813 Py_off_t offset;
3814
Sylvain74453812017-06-10 06:51:48 +02003815 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3816 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003817 goto exit;
3818 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003819 return_value = os_pread_impl(module, fd, length, offset);
3820
3821exit:
3822 return return_value;
3823}
3824
3825#endif /* defined(HAVE_PREAD) */
3826
Pablo Galindo4defba32018-01-27 16:16:37 +00003827#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3828
3829PyDoc_STRVAR(os_preadv__doc__,
3830"preadv($module, fd, buffers, offset, flags=0, /)\n"
3831"--\n"
3832"\n"
3833"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3834"\n"
3835"Combines the functionality of readv() and pread(). As readv(), it will\n"
3836"transfer data into each buffer until it is full and then move on to the next\n"
3837"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3838"specifies the file offset at which the input operation is to be performed. It\n"
3839"will return the total number of bytes read (which can be less than the total\n"
3840"capacity of all the objects).\n"
3841"\n"
3842"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3843"\n"
3844"- RWF_HIPRI\n"
3845"- RWF_NOWAIT\n"
3846"\n"
3847"Using non-zero flags requires Linux 4.6 or newer.");
3848
3849#define OS_PREADV_METHODDEF \
3850 {"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
3851
3852static Py_ssize_t
3853os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3854 int flags);
3855
3856static PyObject *
3857os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3858{
3859 PyObject *return_value = NULL;
3860 int fd;
3861 PyObject *buffers;
3862 Py_off_t offset;
3863 int flags = 0;
3864 Py_ssize_t _return_value;
3865
3866 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3867 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3868 goto exit;
3869 }
3870 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3871 if ((_return_value == -1) && PyErr_Occurred()) {
3872 goto exit;
3873 }
3874 return_value = PyLong_FromSsize_t(_return_value);
3875
3876exit:
3877 return return_value;
3878}
3879
3880#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3881
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003882PyDoc_STRVAR(os_write__doc__,
3883"write($module, fd, data, /)\n"
3884"--\n"
3885"\n"
3886"Write a bytes object to a file descriptor.");
3887
3888#define OS_WRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01003889 {"write", (PyCFunction)os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003890
3891static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003892os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003893
3894static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003895os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003896{
3897 PyObject *return_value = NULL;
3898 int fd;
3899 Py_buffer data = {NULL, NULL};
3900 Py_ssize_t _return_value;
3901
Sylvain74453812017-06-10 06:51:48 +02003902 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3903 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003904 goto exit;
3905 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003906 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003907 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003908 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003909 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003910 return_value = PyLong_FromSsize_t(_return_value);
3911
3912exit:
3913 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003914 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003915 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003916 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003917
3918 return return_value;
3919}
3920
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003921#if defined(__APPLE__)
3922
3923PyDoc_STRVAR(os__fcopyfile__doc__,
3924"_fcopyfile($module, infd, outfd, flags, /)\n"
3925"--\n"
3926"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07003927"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003928
3929#define OS__FCOPYFILE_METHODDEF \
3930 {"_fcopyfile", (PyCFunction)os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
3931
3932static PyObject *
3933os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
3934
3935static PyObject *
3936os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3937{
3938 PyObject *return_value = NULL;
3939 int infd;
3940 int outfd;
3941 int flags;
3942
3943 if (!_PyArg_ParseStack(args, nargs, "iii:_fcopyfile",
3944 &infd, &outfd, &flags)) {
3945 goto exit;
3946 }
3947 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
3948
3949exit:
3950 return return_value;
3951}
3952
3953#endif /* defined(__APPLE__) */
3954
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003955PyDoc_STRVAR(os_fstat__doc__,
3956"fstat($module, /, fd)\n"
3957"--\n"
3958"\n"
3959"Perform a stat system call on the given file descriptor.\n"
3960"\n"
3961"Like stat(), but for an open file descriptor.\n"
3962"Equivalent to os.stat(fd).");
3963
3964#define OS_FSTAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03003965 {"fstat", (PyCFunction)os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003966
3967static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003968os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003969
3970static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003971os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003972{
3973 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003974 static const char * const _keywords[] = {"fd", NULL};
3975 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976 int fd;
3977
Victor Stinner3e1fad62017-01-17 01:29:01 +01003978 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003979 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003980 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003981 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003982 return_value = os_fstat_impl(module, fd);
3983
3984exit:
3985 return return_value;
3986}
3987
3988PyDoc_STRVAR(os_isatty__doc__,
3989"isatty($module, fd, /)\n"
3990"--\n"
3991"\n"
3992"Return True if the fd is connected to a terminal.\n"
3993"\n"
3994"Return True if the file descriptor is an open file descriptor\n"
3995"connected to the slave end of a terminal.");
3996
3997#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003998 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003999
4000static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004001os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004002
4003static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004004os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004005{
4006 PyObject *return_value = NULL;
4007 int fd;
4008 int _return_value;
4009
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004010 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004011 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004012 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004013 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004014 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004015 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004016 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004017 return_value = PyBool_FromLong((long)_return_value);
4018
4019exit:
4020 return return_value;
4021}
4022
4023#if defined(HAVE_PIPE)
4024
4025PyDoc_STRVAR(os_pipe__doc__,
4026"pipe($module, /)\n"
4027"--\n"
4028"\n"
4029"Create a pipe.\n"
4030"\n"
4031"Returns a tuple of two file descriptors:\n"
4032" (read_fd, write_fd)");
4033
4034#define OS_PIPE_METHODDEF \
4035 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
4036
4037static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004038os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004039
4040static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004041os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004042{
4043 return os_pipe_impl(module);
4044}
4045
4046#endif /* defined(HAVE_PIPE) */
4047
4048#if defined(HAVE_PIPE2)
4049
4050PyDoc_STRVAR(os_pipe2__doc__,
4051"pipe2($module, flags, /)\n"
4052"--\n"
4053"\n"
4054"Create a pipe with flags set atomically.\n"
4055"\n"
4056"Returns a tuple of two file descriptors:\n"
4057" (read_fd, write_fd)\n"
4058"\n"
4059"flags can be constructed by ORing together one or more of these values:\n"
4060"O_NONBLOCK, O_CLOEXEC.");
4061
4062#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004063 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004064
4065static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004066os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004067
4068static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004069os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004070{
4071 PyObject *return_value = NULL;
4072 int flags;
4073
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004074 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004075 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004076 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004077 return_value = os_pipe2_impl(module, flags);
4078
4079exit:
4080 return return_value;
4081}
4082
4083#endif /* defined(HAVE_PIPE2) */
4084
4085#if defined(HAVE_WRITEV)
4086
4087PyDoc_STRVAR(os_writev__doc__,
4088"writev($module, fd, buffers, /)\n"
4089"--\n"
4090"\n"
4091"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4092"\n"
4093"Returns the total number of bytes written.\n"
4094"buffers must be a sequence of bytes-like objects.");
4095
4096#define OS_WRITEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004097 {"writev", (PyCFunction)os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004098
4099static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004100os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004101
4102static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004103os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004104{
4105 PyObject *return_value = NULL;
4106 int fd;
4107 PyObject *buffers;
4108 Py_ssize_t _return_value;
4109
Sylvain74453812017-06-10 06:51:48 +02004110 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4111 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004112 goto exit;
4113 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004114 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004115 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004116 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004118 return_value = PyLong_FromSsize_t(_return_value);
4119
4120exit:
4121 return return_value;
4122}
4123
4124#endif /* defined(HAVE_WRITEV) */
4125
4126#if defined(HAVE_PWRITE)
4127
4128PyDoc_STRVAR(os_pwrite__doc__,
4129"pwrite($module, fd, buffer, offset, /)\n"
4130"--\n"
4131"\n"
4132"Write bytes to a file descriptor starting at a particular offset.\n"
4133"\n"
4134"Write buffer to fd, starting at offset bytes from the beginning of\n"
4135"the file. Returns the number of bytes writte. Does not change the\n"
4136"current file offset.");
4137
4138#define OS_PWRITE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004139 {"pwrite", (PyCFunction)os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004140
4141static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004142os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004143
4144static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004145os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004146{
4147 PyObject *return_value = NULL;
4148 int fd;
4149 Py_buffer buffer = {NULL, NULL};
4150 Py_off_t offset;
4151 Py_ssize_t _return_value;
4152
Sylvain74453812017-06-10 06:51:48 +02004153 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4154 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004155 goto exit;
4156 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004157 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004158 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004159 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004160 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004161 return_value = PyLong_FromSsize_t(_return_value);
4162
4163exit:
4164 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004165 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004166 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004167 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004168
4169 return return_value;
4170}
4171
4172#endif /* defined(HAVE_PWRITE) */
4173
Pablo Galindo4defba32018-01-27 16:16:37 +00004174#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4175
4176PyDoc_STRVAR(os_pwritev__doc__,
4177"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4178"--\n"
4179"\n"
4180"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4181"\n"
4182"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4183"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4184"buffer is written before proceeding to second, and so on. The operating system may\n"
4185"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4186"This function writes the contents of each object to the file descriptor and returns\n"
4187"the total number of bytes written.\n"
4188"\n"
4189"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4190"\n"
4191"- RWF_DSYNC\n"
4192"- RWF_SYNC\n"
4193"\n"
4194"Using non-zero flags requires Linux 4.7 or newer.");
4195
4196#define OS_PWRITEV_METHODDEF \
4197 {"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
4198
4199static Py_ssize_t
4200os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4201 int flags);
4202
4203static PyObject *
4204os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4205{
4206 PyObject *return_value = NULL;
4207 int fd;
4208 PyObject *buffers;
4209 Py_off_t offset;
4210 int flags = 0;
4211 Py_ssize_t _return_value;
4212
4213 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4214 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4215 goto exit;
4216 }
4217 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4218 if ((_return_value == -1) && PyErr_Occurred()) {
4219 goto exit;
4220 }
4221 return_value = PyLong_FromSsize_t(_return_value);
4222
4223exit:
4224 return return_value;
4225}
4226
4227#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4228
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004229#if defined(HAVE_MKFIFO)
4230
4231PyDoc_STRVAR(os_mkfifo__doc__,
4232"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4233"--\n"
4234"\n"
4235"Create a \"fifo\" (a POSIX named pipe).\n"
4236"\n"
4237"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4238" and path should be relative; path will then be relative to that directory.\n"
4239"dir_fd may not be implemented on your platform.\n"
4240" If it is unavailable, using it will raise a NotImplementedError.");
4241
4242#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004243 {"mkfifo", (PyCFunction)os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004244
4245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004246os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004247
4248static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004249os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004250{
4251 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004252 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4253 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004254 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4255 int mode = 438;
4256 int dir_fd = DEFAULT_DIR_FD;
4257
Victor Stinner3e1fad62017-01-17 01:29:01 +01004258 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004259 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004260 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004261 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004262 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4263
4264exit:
4265 /* Cleanup for path */
4266 path_cleanup(&path);
4267
4268 return return_value;
4269}
4270
4271#endif /* defined(HAVE_MKFIFO) */
4272
4273#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4274
4275PyDoc_STRVAR(os_mknod__doc__,
4276"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4277"--\n"
4278"\n"
4279"Create a node in the file system.\n"
4280"\n"
4281"Create a node in the file system (file, device special file or named pipe)\n"
4282"at path. mode specifies both the permissions to use and the\n"
4283"type of node to be created, being combined (bitwise OR) with one of\n"
4284"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4285"device defines the newly created device special file (probably using\n"
4286"os.makedev()). Otherwise device is ignored.\n"
4287"\n"
4288"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4289" and path should be relative; path will then be relative to that directory.\n"
4290"dir_fd may not be implemented on your platform.\n"
4291" If it is unavailable, using it will raise a NotImplementedError.");
4292
4293#define OS_MKNOD_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004294 {"mknod", (PyCFunction)os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004295
4296static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004297os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004298 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004299
4300static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004301os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004302{
4303 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004304 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4305 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004306 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4307 int mode = 384;
4308 dev_t device = 0;
4309 int dir_fd = DEFAULT_DIR_FD;
4310
Victor Stinner3e1fad62017-01-17 01:29:01 +01004311 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004312 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004313 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004314 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004315 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4316
4317exit:
4318 /* Cleanup for path */
4319 path_cleanup(&path);
4320
4321 return return_value;
4322}
4323
4324#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4325
4326#if defined(HAVE_DEVICE_MACROS)
4327
4328PyDoc_STRVAR(os_major__doc__,
4329"major($module, device, /)\n"
4330"--\n"
4331"\n"
4332"Extracts a device major number from a raw device number.");
4333
4334#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004335 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004336
4337static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004338os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004339
4340static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004341os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004342{
4343 PyObject *return_value = NULL;
4344 dev_t device;
4345 unsigned int _return_value;
4346
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004347 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004348 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004349 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004350 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004351 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004352 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004354 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4355
4356exit:
4357 return return_value;
4358}
4359
4360#endif /* defined(HAVE_DEVICE_MACROS) */
4361
4362#if defined(HAVE_DEVICE_MACROS)
4363
4364PyDoc_STRVAR(os_minor__doc__,
4365"minor($module, device, /)\n"
4366"--\n"
4367"\n"
4368"Extracts a device minor number from a raw device number.");
4369
4370#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004371 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004372
4373static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004374os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004375
4376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004377os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004378{
4379 PyObject *return_value = NULL;
4380 dev_t device;
4381 unsigned int _return_value;
4382
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004383 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004386 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004387 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004388 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004389 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004390 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4391
4392exit:
4393 return return_value;
4394}
4395
4396#endif /* defined(HAVE_DEVICE_MACROS) */
4397
4398#if defined(HAVE_DEVICE_MACROS)
4399
4400PyDoc_STRVAR(os_makedev__doc__,
4401"makedev($module, major, minor, /)\n"
4402"--\n"
4403"\n"
4404"Composes a raw device number from the major and minor device numbers.");
4405
4406#define OS_MAKEDEV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004407 {"makedev", (PyCFunction)os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004408
4409static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004410os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004411
4412static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004413os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004414{
4415 PyObject *return_value = NULL;
4416 int major;
4417 int minor;
4418 dev_t _return_value;
4419
Sylvain74453812017-06-10 06:51:48 +02004420 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4421 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004422 goto exit;
4423 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004424 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004425 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004426 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004427 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004428 return_value = _PyLong_FromDev(_return_value);
4429
4430exit:
4431 return return_value;
4432}
4433
4434#endif /* defined(HAVE_DEVICE_MACROS) */
4435
Steve Dowerf7377032015-04-12 15:44:54 -04004436#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004437
4438PyDoc_STRVAR(os_ftruncate__doc__,
4439"ftruncate($module, fd, length, /)\n"
4440"--\n"
4441"\n"
4442"Truncate a file, specified by file descriptor, to a specific length.");
4443
4444#define OS_FTRUNCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004445 {"ftruncate", (PyCFunction)os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004446
4447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004448os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004449
4450static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004451os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004452{
4453 PyObject *return_value = NULL;
4454 int fd;
4455 Py_off_t length;
4456
Sylvain74453812017-06-10 06:51:48 +02004457 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4458 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004459 goto exit;
4460 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461 return_value = os_ftruncate_impl(module, fd, length);
4462
4463exit:
4464 return return_value;
4465}
4466
Steve Dowerf7377032015-04-12 15:44:54 -04004467#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004468
Steve Dowerf7377032015-04-12 15:44:54 -04004469#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004470
4471PyDoc_STRVAR(os_truncate__doc__,
4472"truncate($module, /, path, length)\n"
4473"--\n"
4474"\n"
4475"Truncate a file, specified by path, to a specific length.\n"
4476"\n"
4477"On some platforms, path may also be specified as an open file descriptor.\n"
4478" If this functionality is unavailable, using it raises an exception.");
4479
4480#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004481 {"truncate", (PyCFunction)os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004482
4483static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004484os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004485
4486static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004487os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004488{
4489 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004490 static const char * const _keywords[] = {"path", "length", NULL};
4491 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004492 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4493 Py_off_t length;
4494
Victor Stinner3e1fad62017-01-17 01:29:01 +01004495 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004496 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004497 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004498 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004499 return_value = os_truncate_impl(module, &path, length);
4500
4501exit:
4502 /* Cleanup for path */
4503 path_cleanup(&path);
4504
4505 return return_value;
4506}
4507
Steve Dowerf7377032015-04-12 15:44:54 -04004508#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004509
4510#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4511
4512PyDoc_STRVAR(os_posix_fallocate__doc__,
4513"posix_fallocate($module, fd, offset, length, /)\n"
4514"--\n"
4515"\n"
4516"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4517"\n"
4518"Ensure that the file specified by fd encompasses a range of bytes\n"
4519"starting at offset bytes from the beginning and continuing for length bytes.");
4520
4521#define OS_POSIX_FALLOCATE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004522 {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004523
4524static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004525os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004526 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004527
4528static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004529os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004530{
4531 PyObject *return_value = NULL;
4532 int fd;
4533 Py_off_t offset;
4534 Py_off_t length;
4535
Sylvain74453812017-06-10 06:51:48 +02004536 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4537 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004538 goto exit;
4539 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004540 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4541
4542exit:
4543 return return_value;
4544}
4545
4546#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4547
4548#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4549
4550PyDoc_STRVAR(os_posix_fadvise__doc__,
4551"posix_fadvise($module, fd, offset, length, advice, /)\n"
4552"--\n"
4553"\n"
4554"Announce an intention to access data in a specific pattern.\n"
4555"\n"
4556"Announce an intention to access data in a specific pattern, thus allowing\n"
4557"the kernel to make optimizations.\n"
4558"The advice applies to the region of the file specified by fd starting at\n"
4559"offset and continuing for length bytes.\n"
4560"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4561"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4562"POSIX_FADV_DONTNEED.");
4563
4564#define OS_POSIX_FADVISE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004565 {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004566
4567static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004568os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004569 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004570
4571static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004572os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004573{
4574 PyObject *return_value = NULL;
4575 int fd;
4576 Py_off_t offset;
4577 Py_off_t length;
4578 int advice;
4579
Sylvain74453812017-06-10 06:51:48 +02004580 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4581 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004582 goto exit;
4583 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004584 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4585
4586exit:
4587 return return_value;
4588}
4589
4590#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4591
4592#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4593
4594PyDoc_STRVAR(os_putenv__doc__,
4595"putenv($module, name, value, /)\n"
4596"--\n"
4597"\n"
4598"Change or add an environment variable.");
4599
4600#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004601 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004602
4603static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004604os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004605
4606static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004607os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004608{
4609 PyObject *return_value = NULL;
4610 PyObject *name;
4611 PyObject *value;
4612
Sylvain74453812017-06-10 06:51:48 +02004613 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4614 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004615 goto exit;
4616 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004617 return_value = os_putenv_impl(module, name, value);
4618
4619exit:
4620 return return_value;
4621}
4622
4623#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4624
4625#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4626
4627PyDoc_STRVAR(os_putenv__doc__,
4628"putenv($module, name, value, /)\n"
4629"--\n"
4630"\n"
4631"Change or add an environment variable.");
4632
4633#define OS_PUTENV_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01004634 {"putenv", (PyCFunction)os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004635
4636static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004637os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004638
4639static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004640os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004641{
4642 PyObject *return_value = NULL;
4643 PyObject *name = NULL;
4644 PyObject *value = NULL;
4645
Sylvain74453812017-06-10 06:51:48 +02004646 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4647 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004648 goto exit;
4649 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004650 return_value = os_putenv_impl(module, name, value);
4651
4652exit:
4653 /* Cleanup for name */
4654 Py_XDECREF(name);
4655 /* Cleanup for value */
4656 Py_XDECREF(value);
4657
4658 return return_value;
4659}
4660
4661#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4662
4663#if defined(HAVE_UNSETENV)
4664
4665PyDoc_STRVAR(os_unsetenv__doc__,
4666"unsetenv($module, name, /)\n"
4667"--\n"
4668"\n"
4669"Delete an environment variable.");
4670
4671#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004672 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004673
4674static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004675os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004676
4677static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004678os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004679{
4680 PyObject *return_value = NULL;
4681 PyObject *name = NULL;
4682
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004683 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004684 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004685 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004686 return_value = os_unsetenv_impl(module, name);
4687
4688exit:
4689 /* Cleanup for name */
4690 Py_XDECREF(name);
4691
4692 return return_value;
4693}
4694
4695#endif /* defined(HAVE_UNSETENV) */
4696
4697PyDoc_STRVAR(os_strerror__doc__,
4698"strerror($module, code, /)\n"
4699"--\n"
4700"\n"
4701"Translate an error code to a message string.");
4702
4703#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004704 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004705
4706static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004707os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708
4709static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004710os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004711{
4712 PyObject *return_value = NULL;
4713 int code;
4714
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004715 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004716 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004717 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004718 return_value = os_strerror_impl(module, code);
4719
4720exit:
4721 return return_value;
4722}
4723
4724#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4725
4726PyDoc_STRVAR(os_WCOREDUMP__doc__,
4727"WCOREDUMP($module, status, /)\n"
4728"--\n"
4729"\n"
4730"Return True if the process returning status was dumped to a core file.");
4731
4732#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004733 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004734
4735static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004736os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004737
4738static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004739os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004740{
4741 PyObject *return_value = NULL;
4742 int status;
4743 int _return_value;
4744
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004745 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004746 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004747 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004748 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004749 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004750 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004751 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752 return_value = PyBool_FromLong((long)_return_value);
4753
4754exit:
4755 return return_value;
4756}
4757
4758#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4759
4760#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4761
4762PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4763"WIFCONTINUED($module, /, status)\n"
4764"--\n"
4765"\n"
4766"Return True if a particular process was continued from a job control stop.\n"
4767"\n"
4768"Return True if the process returning status was continued from a\n"
4769"job control stop.");
4770
4771#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004772 {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004773
4774static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004775os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004776
4777static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004778os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004779{
4780 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004781 static const char * const _keywords[] = {"status", NULL};
4782 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004783 int status;
4784 int _return_value;
4785
Victor Stinner3e1fad62017-01-17 01:29:01 +01004786 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004787 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004788 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004789 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004790 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004791 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004792 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004793 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004794 return_value = PyBool_FromLong((long)_return_value);
4795
4796exit:
4797 return return_value;
4798}
4799
4800#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4801
4802#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4803
4804PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4805"WIFSTOPPED($module, /, status)\n"
4806"--\n"
4807"\n"
4808"Return True if the process returning status was stopped.");
4809
4810#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004811 {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004812
4813static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004814os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004815
4816static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004817os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004818{
4819 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004820 static const char * const _keywords[] = {"status", NULL};
4821 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004822 int status;
4823 int _return_value;
4824
Victor Stinner3e1fad62017-01-17 01:29:01 +01004825 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004826 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004827 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004828 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004829 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004830 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004831 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004832 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004833 return_value = PyBool_FromLong((long)_return_value);
4834
4835exit:
4836 return return_value;
4837}
4838
4839#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4840
4841#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4842
4843PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4844"WIFSIGNALED($module, /, status)\n"
4845"--\n"
4846"\n"
4847"Return True if the process returning status was terminated by a signal.");
4848
4849#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004850 {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004851
4852static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004853os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004854
4855static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004856os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004857{
4858 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004859 static const char * const _keywords[] = {"status", NULL};
4860 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004861 int status;
4862 int _return_value;
4863
Victor Stinner3e1fad62017-01-17 01:29:01 +01004864 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004865 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004866 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004867 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004868 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004869 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004872 return_value = PyBool_FromLong((long)_return_value);
4873
4874exit:
4875 return return_value;
4876}
4877
4878#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4879
4880#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4881
4882PyDoc_STRVAR(os_WIFEXITED__doc__,
4883"WIFEXITED($module, /, status)\n"
4884"--\n"
4885"\n"
4886"Return True if the process returning status exited via the exit() system call.");
4887
4888#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004889 {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004890
4891static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004892os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004893
4894static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004895os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004896{
4897 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004898 static const char * const _keywords[] = {"status", NULL};
4899 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004900 int status;
4901 int _return_value;
4902
Victor Stinner3e1fad62017-01-17 01:29:01 +01004903 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004904 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004905 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004906 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004907 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004908 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004909 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004910 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004911 return_value = PyBool_FromLong((long)_return_value);
4912
4913exit:
4914 return return_value;
4915}
4916
4917#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4918
4919#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4920
4921PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4922"WEXITSTATUS($module, /, status)\n"
4923"--\n"
4924"\n"
4925"Return the process return code from status.");
4926
4927#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004928 {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004929
4930static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004931os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004932
4933static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004934os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004935{
4936 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004937 static const char * const _keywords[] = {"status", NULL};
4938 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004939 int status;
4940 int _return_value;
4941
Victor Stinner3e1fad62017-01-17 01:29:01 +01004942 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004943 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004944 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004945 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004946 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004947 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004948 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004949 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004950 return_value = PyLong_FromLong((long)_return_value);
4951
4952exit:
4953 return return_value;
4954}
4955
4956#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4957
4958#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4959
4960PyDoc_STRVAR(os_WTERMSIG__doc__,
4961"WTERMSIG($module, /, status)\n"
4962"--\n"
4963"\n"
4964"Return the signal that terminated the process that provided the status value.");
4965
4966#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03004967 {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004968
4969static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004970os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004971
4972static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004973os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004974{
4975 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004976 static const char * const _keywords[] = {"status", NULL};
4977 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978 int status;
4979 int _return_value;
4980
Victor Stinner3e1fad62017-01-17 01:29:01 +01004981 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004982 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004983 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004984 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004985 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004986 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004987 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004988 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004989 return_value = PyLong_FromLong((long)_return_value);
4990
4991exit:
4992 return return_value;
4993}
4994
4995#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4996
4997#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4998
4999PyDoc_STRVAR(os_WSTOPSIG__doc__,
5000"WSTOPSIG($module, /, status)\n"
5001"--\n"
5002"\n"
5003"Return the signal that stopped the process that provided the status value.");
5004
5005#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005006 {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005007
5008static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005009os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005010
5011static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005012os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005013{
5014 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005015 static const char * const _keywords[] = {"status", NULL};
5016 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005017 int status;
5018 int _return_value;
5019
Victor Stinner3e1fad62017-01-17 01:29:01 +01005020 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005021 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005022 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005023 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005024 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005025 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005026 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005027 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005028 return_value = PyLong_FromLong((long)_return_value);
5029
5030exit:
5031 return return_value;
5032}
5033
5034#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
5035
5036#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
5037
5038PyDoc_STRVAR(os_fstatvfs__doc__,
5039"fstatvfs($module, fd, /)\n"
5040"--\n"
5041"\n"
5042"Perform an fstatvfs system call on the given fd.\n"
5043"\n"
5044"Equivalent to statvfs(fd).");
5045
5046#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005047 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005048
5049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005050os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005051
5052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005053os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005054{
5055 PyObject *return_value = NULL;
5056 int fd;
5057
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005058 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005059 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005060 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005061 return_value = os_fstatvfs_impl(module, fd);
5062
5063exit:
5064 return return_value;
5065}
5066
5067#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5068
5069#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5070
5071PyDoc_STRVAR(os_statvfs__doc__,
5072"statvfs($module, /, path)\n"
5073"--\n"
5074"\n"
5075"Perform a statvfs system call on the given path.\n"
5076"\n"
5077"path may always be specified as a string.\n"
5078"On some platforms, path may also be specified as an open file descriptor.\n"
5079" If this functionality is unavailable, using it raises an exception.");
5080
5081#define OS_STATVFS_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005082 {"statvfs", (PyCFunction)os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005083
5084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005085os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005086
5087static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005088os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005089{
5090 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005091 static const char * const _keywords[] = {"path", NULL};
5092 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005093 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5094
Victor Stinner3e1fad62017-01-17 01:29:01 +01005095 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005096 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005097 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005098 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005099 return_value = os_statvfs_impl(module, &path);
5100
5101exit:
5102 /* Cleanup for path */
5103 path_cleanup(&path);
5104
5105 return return_value;
5106}
5107
5108#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5109
5110#if defined(MS_WINDOWS)
5111
5112PyDoc_STRVAR(os__getdiskusage__doc__,
5113"_getdiskusage($module, /, path)\n"
5114"--\n"
5115"\n"
5116"Return disk usage statistics about the given path as a (total, free) tuple.");
5117
5118#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005119 {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005120
5121static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005122os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005123
5124static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005125os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005126{
5127 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005128 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005129 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5130 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005131
Victor Stinner3e1fad62017-01-17 01:29:01 +01005132 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005133 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005134 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005135 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005136 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005137
5138exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005139 /* Cleanup for path */
5140 path_cleanup(&path);
5141
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005142 return return_value;
5143}
5144
5145#endif /* defined(MS_WINDOWS) */
5146
5147#if defined(HAVE_FPATHCONF)
5148
5149PyDoc_STRVAR(os_fpathconf__doc__,
5150"fpathconf($module, fd, name, /)\n"
5151"--\n"
5152"\n"
5153"Return the configuration limit name for the file descriptor fd.\n"
5154"\n"
5155"If there is no limit, return -1.");
5156
5157#define OS_FPATHCONF_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005158 {"fpathconf", (PyCFunction)os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005159
5160static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005161os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005162
5163static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005164os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005165{
5166 PyObject *return_value = NULL;
5167 int fd;
5168 int name;
5169 long _return_value;
5170
Sylvain74453812017-06-10 06:51:48 +02005171 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5172 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005173 goto exit;
5174 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175 _return_value = os_fpathconf_impl(module, fd, 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 return return_value;
5183}
5184
5185#endif /* defined(HAVE_FPATHCONF) */
5186
5187#if defined(HAVE_PATHCONF)
5188
5189PyDoc_STRVAR(os_pathconf__doc__,
5190"pathconf($module, /, path, name)\n"
5191"--\n"
5192"\n"
5193"Return the configuration limit name for the file or directory path.\n"
5194"\n"
5195"If there is no limit, return -1.\n"
5196"On some platforms, path may also be specified as an open file descriptor.\n"
5197" If this functionality is unavailable, using it raises an exception.");
5198
5199#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005200 {"pathconf", (PyCFunction)os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005201
5202static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005203os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005204
5205static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005206os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005207{
5208 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005209 static const char * const _keywords[] = {"path", "name", NULL};
5210 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005211 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5212 int name;
5213 long _return_value;
5214
Victor Stinner3e1fad62017-01-17 01:29:01 +01005215 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005216 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005217 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005218 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005219 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005220 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005221 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005222 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005223 return_value = PyLong_FromLong(_return_value);
5224
5225exit:
5226 /* Cleanup for path */
5227 path_cleanup(&path);
5228
5229 return return_value;
5230}
5231
5232#endif /* defined(HAVE_PATHCONF) */
5233
5234#if defined(HAVE_CONFSTR)
5235
5236PyDoc_STRVAR(os_confstr__doc__,
5237"confstr($module, name, /)\n"
5238"--\n"
5239"\n"
5240"Return a string-valued system configuration variable.");
5241
5242#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005243 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005244
5245static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005246os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247
5248static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005249os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005250{
5251 PyObject *return_value = NULL;
5252 int name;
5253
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005254 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005255 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005256 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005257 return_value = os_confstr_impl(module, name);
5258
5259exit:
5260 return return_value;
5261}
5262
5263#endif /* defined(HAVE_CONFSTR) */
5264
5265#if defined(HAVE_SYSCONF)
5266
5267PyDoc_STRVAR(os_sysconf__doc__,
5268"sysconf($module, name, /)\n"
5269"--\n"
5270"\n"
5271"Return an integer-valued system configuration variable.");
5272
5273#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005274 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005275
5276static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005277os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005278
5279static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005280os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005281{
5282 PyObject *return_value = NULL;
5283 int name;
5284 long _return_value;
5285
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005286 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005287 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005288 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005289 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005290 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005291 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005292 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005293 return_value = PyLong_FromLong(_return_value);
5294
5295exit:
5296 return return_value;
5297}
5298
5299#endif /* defined(HAVE_SYSCONF) */
5300
5301PyDoc_STRVAR(os_abort__doc__,
5302"abort($module, /)\n"
5303"--\n"
5304"\n"
5305"Abort the interpreter immediately.\n"
5306"\n"
5307"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5308"on the hosting operating system. This function never returns.");
5309
5310#define OS_ABORT_METHODDEF \
5311 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5312
5313static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005314os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005315
5316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005317os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005318{
5319 return os_abort_impl(module);
5320}
5321
Steve Dowercc16be82016-09-08 10:35:16 -07005322#if defined(MS_WINDOWS)
5323
5324PyDoc_STRVAR(os_startfile__doc__,
5325"startfile($module, /, filepath, operation=None)\n"
5326"--\n"
5327"\n"
5328"startfile(filepath [, operation])\n"
5329"\n"
5330"Start a file with its associated application.\n"
5331"\n"
5332"When \"operation\" is not specified or \"open\", this acts like\n"
5333"double-clicking the file in Explorer, or giving the file name as an\n"
5334"argument to the DOS \"start\" command: the file is opened with whatever\n"
5335"application (if any) its extension is associated.\n"
5336"When another \"operation\" is given, it specifies what should be done with\n"
5337"the file. A typical operation is \"print\".\n"
5338"\n"
5339"startfile returns as soon as the associated application is launched.\n"
5340"There is no option to wait for the application to close, and no way\n"
5341"to retrieve the application\'s exit status.\n"
5342"\n"
5343"The filepath is relative to the current directory. If you want to use\n"
5344"an absolute path, make sure the first character is not a slash (\"/\");\n"
5345"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5346
5347#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005348 {"startfile", (PyCFunction)os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005349
5350static PyObject *
5351os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation);
5352
5353static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005354os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005355{
5356 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005357 static const char * const _keywords[] = {"filepath", "operation", NULL};
5358 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005359 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
5360 Py_UNICODE *operation = NULL;
5361
Victor Stinner3e1fad62017-01-17 01:29:01 +01005362 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005363 path_converter, &filepath, &operation)) {
5364 goto exit;
5365 }
5366 return_value = os_startfile_impl(module, &filepath, operation);
5367
5368exit:
5369 /* Cleanup for filepath */
5370 path_cleanup(&filepath);
5371
5372 return return_value;
5373}
5374
5375#endif /* defined(MS_WINDOWS) */
5376
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005377#if defined(HAVE_GETLOADAVG)
5378
5379PyDoc_STRVAR(os_getloadavg__doc__,
5380"getloadavg($module, /)\n"
5381"--\n"
5382"\n"
5383"Return average recent system load information.\n"
5384"\n"
5385"Return the number of processes in the system run queue averaged over\n"
5386"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5387"Raises OSError if the load average was unobtainable.");
5388
5389#define OS_GETLOADAVG_METHODDEF \
5390 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5391
5392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005393os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005394
5395static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005396os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005397{
5398 return os_getloadavg_impl(module);
5399}
5400
5401#endif /* defined(HAVE_GETLOADAVG) */
5402
5403PyDoc_STRVAR(os_device_encoding__doc__,
5404"device_encoding($module, /, fd)\n"
5405"--\n"
5406"\n"
5407"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5408"\n"
5409"The file descriptor must be attached to a terminal.\n"
5410"If the device is not a terminal, return None.");
5411
5412#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005413 {"device_encoding", (PyCFunction)os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005414
5415static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005416os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005417
5418static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005419os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005420{
5421 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005422 static const char * const _keywords[] = {"fd", NULL};
5423 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005424 int fd;
5425
Victor Stinner3e1fad62017-01-17 01:29:01 +01005426 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005427 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005428 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005429 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005430 return_value = os_device_encoding_impl(module, fd);
5431
5432exit:
5433 return return_value;
5434}
5435
5436#if defined(HAVE_SETRESUID)
5437
5438PyDoc_STRVAR(os_setresuid__doc__,
5439"setresuid($module, ruid, euid, suid, /)\n"
5440"--\n"
5441"\n"
5442"Set the current process\'s real, effective, and saved user ids.");
5443
5444#define OS_SETRESUID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005445 {"setresuid", (PyCFunction)os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005446
5447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005448os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005449
5450static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005451os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005452{
5453 PyObject *return_value = NULL;
5454 uid_t ruid;
5455 uid_t euid;
5456 uid_t suid;
5457
Sylvain74453812017-06-10 06:51:48 +02005458 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5459 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005460 goto exit;
5461 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005462 return_value = os_setresuid_impl(module, ruid, euid, suid);
5463
5464exit:
5465 return return_value;
5466}
5467
5468#endif /* defined(HAVE_SETRESUID) */
5469
5470#if defined(HAVE_SETRESGID)
5471
5472PyDoc_STRVAR(os_setresgid__doc__,
5473"setresgid($module, rgid, egid, sgid, /)\n"
5474"--\n"
5475"\n"
5476"Set the current process\'s real, effective, and saved group ids.");
5477
5478#define OS_SETRESGID_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005479 {"setresgid", (PyCFunction)os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005480
5481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005482os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483
5484static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005485os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005486{
5487 PyObject *return_value = NULL;
5488 gid_t rgid;
5489 gid_t egid;
5490 gid_t sgid;
5491
Sylvain74453812017-06-10 06:51:48 +02005492 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5493 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005494 goto exit;
5495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005496 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5497
5498exit:
5499 return return_value;
5500}
5501
5502#endif /* defined(HAVE_SETRESGID) */
5503
5504#if defined(HAVE_GETRESUID)
5505
5506PyDoc_STRVAR(os_getresuid__doc__,
5507"getresuid($module, /)\n"
5508"--\n"
5509"\n"
5510"Return a tuple of the current process\'s real, effective, and saved user ids.");
5511
5512#define OS_GETRESUID_METHODDEF \
5513 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5514
5515static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005516os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005517
5518static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005519os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005520{
5521 return os_getresuid_impl(module);
5522}
5523
5524#endif /* defined(HAVE_GETRESUID) */
5525
5526#if defined(HAVE_GETRESGID)
5527
5528PyDoc_STRVAR(os_getresgid__doc__,
5529"getresgid($module, /)\n"
5530"--\n"
5531"\n"
5532"Return a tuple of the current process\'s real, effective, and saved group ids.");
5533
5534#define OS_GETRESGID_METHODDEF \
5535 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5536
5537static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005538os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005539
5540static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005541os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542{
5543 return os_getresgid_impl(module);
5544}
5545
5546#endif /* defined(HAVE_GETRESGID) */
5547
5548#if defined(USE_XATTRS)
5549
5550PyDoc_STRVAR(os_getxattr__doc__,
5551"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5552"--\n"
5553"\n"
5554"Return the value of extended attribute attribute on path.\n"
5555"\n"
5556"path may be either a string or an open file descriptor.\n"
5557"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5558" link, getxattr will examine the symbolic link itself instead of the file\n"
5559" the link points to.");
5560
5561#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005562 {"getxattr", (PyCFunction)os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005563
5564static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005565os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005566 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005567
5568static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005569os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005570{
5571 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005572 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5573 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005574 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5575 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5576 int follow_symlinks = 1;
5577
Victor Stinner3e1fad62017-01-17 01:29:01 +01005578 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005579 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005580 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005581 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005582 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5583
5584exit:
5585 /* Cleanup for path */
5586 path_cleanup(&path);
5587 /* Cleanup for attribute */
5588 path_cleanup(&attribute);
5589
5590 return return_value;
5591}
5592
5593#endif /* defined(USE_XATTRS) */
5594
5595#if defined(USE_XATTRS)
5596
5597PyDoc_STRVAR(os_setxattr__doc__,
5598"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5599" follow_symlinks=True)\n"
5600"--\n"
5601"\n"
5602"Set extended attribute attribute on path to value.\n"
5603"\n"
5604"path may be either a string or an open file descriptor.\n"
5605"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5606" link, setxattr will modify the symbolic link itself instead of the file\n"
5607" the link points to.");
5608
5609#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005610 {"setxattr", (PyCFunction)os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005611
5612static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005613os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005614 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005615
5616static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005617os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005618{
5619 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005620 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5621 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005622 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5623 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5624 Py_buffer value = {NULL, NULL};
5625 int flags = 0;
5626 int follow_symlinks = 1;
5627
Victor Stinner3e1fad62017-01-17 01:29:01 +01005628 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005629 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005630 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005631 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005632 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5633
5634exit:
5635 /* Cleanup for path */
5636 path_cleanup(&path);
5637 /* Cleanup for attribute */
5638 path_cleanup(&attribute);
5639 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005640 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005641 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005643
5644 return return_value;
5645}
5646
5647#endif /* defined(USE_XATTRS) */
5648
5649#if defined(USE_XATTRS)
5650
5651PyDoc_STRVAR(os_removexattr__doc__,
5652"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5653"--\n"
5654"\n"
5655"Remove extended attribute attribute on path.\n"
5656"\n"
5657"path may be either a string or an open file descriptor.\n"
5658"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5659" link, removexattr will modify the symbolic link itself instead of the file\n"
5660" the link points to.");
5661
5662#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005663 {"removexattr", (PyCFunction)os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005664
5665static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005666os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005667 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005668
5669static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005670os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005671{
5672 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005673 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5674 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005675 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5676 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5677 int follow_symlinks = 1;
5678
Victor Stinner3e1fad62017-01-17 01:29:01 +01005679 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005680 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005681 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005683 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5684
5685exit:
5686 /* Cleanup for path */
5687 path_cleanup(&path);
5688 /* Cleanup for attribute */
5689 path_cleanup(&attribute);
5690
5691 return return_value;
5692}
5693
5694#endif /* defined(USE_XATTRS) */
5695
5696#if defined(USE_XATTRS)
5697
5698PyDoc_STRVAR(os_listxattr__doc__,
5699"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5700"--\n"
5701"\n"
5702"Return a list of extended attributes on path.\n"
5703"\n"
5704"path may be either None, a string, or an open file descriptor.\n"
5705"if path is None, listxattr will examine the current directory.\n"
5706"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5707" link, listxattr will examine the symbolic link itself instead of the file\n"
5708" the link points to.");
5709
5710#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03005711 {"listxattr", (PyCFunction)os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005712
5713static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005714os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005715
5716static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005717os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005718{
5719 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005720 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5721 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005722 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5723 int follow_symlinks = 1;
5724
Victor Stinner3e1fad62017-01-17 01:29:01 +01005725 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005726 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005727 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005728 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005729 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5730
5731exit:
5732 /* Cleanup for path */
5733 path_cleanup(&path);
5734
5735 return return_value;
5736}
5737
5738#endif /* defined(USE_XATTRS) */
5739
5740PyDoc_STRVAR(os_urandom__doc__,
5741"urandom($module, size, /)\n"
5742"--\n"
5743"\n"
5744"Return a bytes object containing random bytes suitable for cryptographic use.");
5745
5746#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005747 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005748
5749static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005750os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005751
5752static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005753os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005754{
5755 PyObject *return_value = NULL;
5756 Py_ssize_t size;
5757
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005758 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005759 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005760 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761 return_value = os_urandom_impl(module, size);
5762
5763exit:
5764 return return_value;
5765}
5766
5767PyDoc_STRVAR(os_cpu_count__doc__,
5768"cpu_count($module, /)\n"
5769"--\n"
5770"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005771"Return the number of CPUs in the system; return None if indeterminable.\n"
5772"\n"
5773"This number is not equivalent to the number of CPUs the current process can\n"
5774"use. The number of usable CPUs can be obtained with\n"
5775"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005776
5777#define OS_CPU_COUNT_METHODDEF \
5778 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5779
5780static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005781os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005782
5783static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005784os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005785{
5786 return os_cpu_count_impl(module);
5787}
5788
5789PyDoc_STRVAR(os_get_inheritable__doc__,
5790"get_inheritable($module, fd, /)\n"
5791"--\n"
5792"\n"
5793"Get the close-on-exe flag of the specified file descriptor.");
5794
5795#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005796 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005797
5798static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005799os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005800
5801static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005802os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005803{
5804 PyObject *return_value = NULL;
5805 int fd;
5806 int _return_value;
5807
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005808 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005809 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005810 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005811 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005812 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005813 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005814 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005815 return_value = PyBool_FromLong((long)_return_value);
5816
5817exit:
5818 return return_value;
5819}
5820
5821PyDoc_STRVAR(os_set_inheritable__doc__,
5822"set_inheritable($module, fd, inheritable, /)\n"
5823"--\n"
5824"\n"
5825"Set the inheritable flag of the specified file descriptor.");
5826
5827#define OS_SET_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005828 {"set_inheritable", (PyCFunction)os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005829
5830static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005831os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005832
5833static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005834os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005835{
5836 PyObject *return_value = NULL;
5837 int fd;
5838 int inheritable;
5839
Sylvain74453812017-06-10 06:51:48 +02005840 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5841 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005842 goto exit;
5843 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005844 return_value = os_set_inheritable_impl(module, fd, inheritable);
5845
5846exit:
5847 return return_value;
5848}
5849
5850#if defined(MS_WINDOWS)
5851
5852PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5853"get_handle_inheritable($module, handle, /)\n"
5854"--\n"
5855"\n"
5856"Get the close-on-exe flag of the specified file descriptor.");
5857
5858#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005859 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005860
5861static int
Victor Stinner581139c2016-09-06 15:54:20 -07005862os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005863
5864static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005865os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005866{
5867 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005868 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005869 int _return_value;
5870
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005871 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005872 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005873 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005874 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005875 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005876 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005877 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005878 return_value = PyBool_FromLong((long)_return_value);
5879
5880exit:
5881 return return_value;
5882}
5883
5884#endif /* defined(MS_WINDOWS) */
5885
5886#if defined(MS_WINDOWS)
5887
5888PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5889"set_handle_inheritable($module, handle, inheritable, /)\n"
5890"--\n"
5891"\n"
5892"Set the inheritable flag of the specified handle.");
5893
5894#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01005895 {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005896
5897static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005898os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005899 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005900
5901static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005902os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005903{
5904 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005905 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005906 int inheritable;
5907
Sylvain74453812017-06-10 06:51:48 +02005908 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5909 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005910 goto exit;
5911 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005912 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5913
5914exit:
5915 return return_value;
5916}
5917
5918#endif /* defined(MS_WINDOWS) */
5919
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03005920#if !defined(MS_WINDOWS)
5921
5922PyDoc_STRVAR(os_get_blocking__doc__,
5923"get_blocking($module, fd, /)\n"
5924"--\n"
5925"\n"
5926"Get the blocking mode of the file descriptor.\n"
5927"\n"
5928"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
5929
5930#define OS_GET_BLOCKING_METHODDEF \
5931 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
5932
5933static int
5934os_get_blocking_impl(PyObject *module, int fd);
5935
5936static PyObject *
5937os_get_blocking(PyObject *module, PyObject *arg)
5938{
5939 PyObject *return_value = NULL;
5940 int fd;
5941 int _return_value;
5942
5943 if (!PyArg_Parse(arg, "i:get_blocking", &fd)) {
5944 goto exit;
5945 }
5946 _return_value = os_get_blocking_impl(module, fd);
5947 if ((_return_value == -1) && PyErr_Occurred()) {
5948 goto exit;
5949 }
5950 return_value = PyBool_FromLong((long)_return_value);
5951
5952exit:
5953 return return_value;
5954}
5955
5956#endif /* !defined(MS_WINDOWS) */
5957
5958#if !defined(MS_WINDOWS)
5959
5960PyDoc_STRVAR(os_set_blocking__doc__,
5961"set_blocking($module, fd, blocking, /)\n"
5962"--\n"
5963"\n"
5964"Set the blocking mode of the specified file descriptor.\n"
5965"\n"
5966"Set the O_NONBLOCK flag if blocking is False,\n"
5967"clear the O_NONBLOCK flag otherwise.");
5968
5969#define OS_SET_BLOCKING_METHODDEF \
5970 {"set_blocking", (PyCFunction)os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
5971
5972static PyObject *
5973os_set_blocking_impl(PyObject *module, int fd, int blocking);
5974
5975static PyObject *
5976os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5977{
5978 PyObject *return_value = NULL;
5979 int fd;
5980 int blocking;
5981
5982 if (!_PyArg_ParseStack(args, nargs, "ii:set_blocking",
5983 &fd, &blocking)) {
5984 goto exit;
5985 }
5986 return_value = os_set_blocking_impl(module, fd, blocking);
5987
5988exit:
5989 return return_value;
5990}
5991
5992#endif /* !defined(MS_WINDOWS) */
5993
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005994PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5995"is_symlink($self, /)\n"
5996"--\n"
5997"\n"
5998"Return True if the entry is a symbolic link; cached per entry.");
5999
6000#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
6001 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
6002
6003static int
6004os_DirEntry_is_symlink_impl(DirEntry *self);
6005
6006static PyObject *
6007os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
6008{
6009 PyObject *return_value = NULL;
6010 int _return_value;
6011
6012 _return_value = os_DirEntry_is_symlink_impl(self);
6013 if ((_return_value == -1) && PyErr_Occurred()) {
6014 goto exit;
6015 }
6016 return_value = PyBool_FromLong((long)_return_value);
6017
6018exit:
6019 return return_value;
6020}
6021
6022PyDoc_STRVAR(os_DirEntry_stat__doc__,
6023"stat($self, /, *, follow_symlinks=True)\n"
6024"--\n"
6025"\n"
6026"Return stat_result object for the entry; cached per entry.");
6027
6028#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006029 {"stat", (PyCFunction)os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006030
6031static PyObject *
6032os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
6033
6034static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006035os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006036{
6037 PyObject *return_value = NULL;
6038 static const char * const _keywords[] = {"follow_symlinks", NULL};
6039 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
6040 int follow_symlinks = 1;
6041
Victor Stinner3e1fad62017-01-17 01:29:01 +01006042 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006043 &follow_symlinks)) {
6044 goto exit;
6045 }
6046 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
6047
6048exit:
6049 return return_value;
6050}
6051
6052PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
6053"is_dir($self, /, *, follow_symlinks=True)\n"
6054"--\n"
6055"\n"
6056"Return True if the entry is a directory; cached per entry.");
6057
6058#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006059 {"is_dir", (PyCFunction)os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006060
6061static int
6062os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
6063
6064static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006065os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006066{
6067 PyObject *return_value = NULL;
6068 static const char * const _keywords[] = {"follow_symlinks", NULL};
6069 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
6070 int follow_symlinks = 1;
6071 int _return_value;
6072
Victor Stinner3e1fad62017-01-17 01:29:01 +01006073 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006074 &follow_symlinks)) {
6075 goto exit;
6076 }
6077 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
6078 if ((_return_value == -1) && PyErr_Occurred()) {
6079 goto exit;
6080 }
6081 return_value = PyBool_FromLong((long)_return_value);
6082
6083exit:
6084 return return_value;
6085}
6086
6087PyDoc_STRVAR(os_DirEntry_is_file__doc__,
6088"is_file($self, /, *, follow_symlinks=True)\n"
6089"--\n"
6090"\n"
6091"Return True if the entry is a file; cached per entry.");
6092
6093#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006094 {"is_file", (PyCFunction)os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006095
6096static int
6097os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
6098
6099static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006100os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006101{
6102 PyObject *return_value = NULL;
6103 static const char * const _keywords[] = {"follow_symlinks", NULL};
6104 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
6105 int follow_symlinks = 1;
6106 int _return_value;
6107
Victor Stinner3e1fad62017-01-17 01:29:01 +01006108 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006109 &follow_symlinks)) {
6110 goto exit;
6111 }
6112 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
6113 if ((_return_value == -1) && PyErr_Occurred()) {
6114 goto exit;
6115 }
6116 return_value = PyBool_FromLong((long)_return_value);
6117
6118exit:
6119 return return_value;
6120}
6121
6122PyDoc_STRVAR(os_DirEntry_inode__doc__,
6123"inode($self, /)\n"
6124"--\n"
6125"\n"
6126"Return inode of the entry; cached per entry.");
6127
6128#define OS_DIRENTRY_INODE_METHODDEF \
6129 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6130
6131static PyObject *
6132os_DirEntry_inode_impl(DirEntry *self);
6133
6134static PyObject *
6135os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6136{
6137 return os_DirEntry_inode_impl(self);
6138}
6139
6140PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6141"__fspath__($self, /)\n"
6142"--\n"
6143"\n"
6144"Returns the path for the entry.");
6145
6146#define OS_DIRENTRY___FSPATH___METHODDEF \
6147 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6148
6149static PyObject *
6150os_DirEntry___fspath___impl(DirEntry *self);
6151
6152static PyObject *
6153os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6154{
6155 return os_DirEntry___fspath___impl(self);
6156}
6157
6158PyDoc_STRVAR(os_scandir__doc__,
6159"scandir($module, /, path=None)\n"
6160"--\n"
6161"\n"
6162"Return an iterator of DirEntry objects for given path.\n"
6163"\n"
6164"path can be specified as either str, bytes or path-like object. If path\n"
6165"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6166"all other circumstances they will be str.\n"
6167"\n"
6168"If path is None, uses the path=\'.\'.");
6169
6170#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006171 {"scandir", (PyCFunction)os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006172
6173static PyObject *
6174os_scandir_impl(PyObject *module, path_t *path);
6175
6176static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006177os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006178{
6179 PyObject *return_value = NULL;
6180 static const char * const _keywords[] = {"path", NULL};
6181 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006182 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006183
Victor Stinner3e1fad62017-01-17 01:29:01 +01006184 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006185 path_converter, &path)) {
6186 goto exit;
6187 }
6188 return_value = os_scandir_impl(module, &path);
6189
6190exit:
6191 /* Cleanup for path */
6192 path_cleanup(&path);
6193
6194 return return_value;
6195}
6196
Ethan Furman410ef8e2016-06-04 12:06:26 -07006197PyDoc_STRVAR(os_fspath__doc__,
6198"fspath($module, /, path)\n"
6199"--\n"
6200"\n"
6201"Return the file system path representation of the object.\n"
6202"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006203"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6204"object defines __fspath__(), then return the result of that method. All other\n"
6205"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006206
6207#define OS_FSPATH_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006208 {"fspath", (PyCFunction)os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006209
6210static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006211os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006212
6213static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006214os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006215{
6216 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006217 static const char * const _keywords[] = {"path", NULL};
6218 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006219 PyObject *path;
6220
Victor Stinner3e1fad62017-01-17 01:29:01 +01006221 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006222 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006223 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006224 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006225 return_value = os_fspath_impl(module, path);
6226
6227exit:
6228 return return_value;
6229}
6230
Victor Stinner9b1f4742016-09-06 16:18:52 -07006231#if defined(HAVE_GETRANDOM_SYSCALL)
6232
6233PyDoc_STRVAR(os_getrandom__doc__,
6234"getrandom($module, /, size, flags=0)\n"
6235"--\n"
6236"\n"
6237"Obtain a series of random bytes.");
6238
6239#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +03006240 {"getrandom", (PyCFunction)os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006241
6242static PyObject *
6243os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6244
6245static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006246os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006247{
6248 PyObject *return_value = NULL;
6249 static const char * const _keywords[] = {"size", "flags", NULL};
6250 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6251 Py_ssize_t size;
6252 int flags = 0;
6253
Victor Stinner3e1fad62017-01-17 01:29:01 +01006254 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006255 &size, &flags)) {
6256 goto exit;
6257 }
6258 return_value = os_getrandom_impl(module, size, flags);
6259
6260exit:
6261 return return_value;
6262}
6263
6264#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6265
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006266#ifndef OS_TTYNAME_METHODDEF
6267 #define OS_TTYNAME_METHODDEF
6268#endif /* !defined(OS_TTYNAME_METHODDEF) */
6269
6270#ifndef OS_CTERMID_METHODDEF
6271 #define OS_CTERMID_METHODDEF
6272#endif /* !defined(OS_CTERMID_METHODDEF) */
6273
6274#ifndef OS_FCHDIR_METHODDEF
6275 #define OS_FCHDIR_METHODDEF
6276#endif /* !defined(OS_FCHDIR_METHODDEF) */
6277
6278#ifndef OS_FCHMOD_METHODDEF
6279 #define OS_FCHMOD_METHODDEF
6280#endif /* !defined(OS_FCHMOD_METHODDEF) */
6281
6282#ifndef OS_LCHMOD_METHODDEF
6283 #define OS_LCHMOD_METHODDEF
6284#endif /* !defined(OS_LCHMOD_METHODDEF) */
6285
6286#ifndef OS_CHFLAGS_METHODDEF
6287 #define OS_CHFLAGS_METHODDEF
6288#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6289
6290#ifndef OS_LCHFLAGS_METHODDEF
6291 #define OS_LCHFLAGS_METHODDEF
6292#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6293
6294#ifndef OS_CHROOT_METHODDEF
6295 #define OS_CHROOT_METHODDEF
6296#endif /* !defined(OS_CHROOT_METHODDEF) */
6297
6298#ifndef OS_FSYNC_METHODDEF
6299 #define OS_FSYNC_METHODDEF
6300#endif /* !defined(OS_FSYNC_METHODDEF) */
6301
6302#ifndef OS_SYNC_METHODDEF
6303 #define OS_SYNC_METHODDEF
6304#endif /* !defined(OS_SYNC_METHODDEF) */
6305
6306#ifndef OS_FDATASYNC_METHODDEF
6307 #define OS_FDATASYNC_METHODDEF
6308#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6309
6310#ifndef OS_CHOWN_METHODDEF
6311 #define OS_CHOWN_METHODDEF
6312#endif /* !defined(OS_CHOWN_METHODDEF) */
6313
6314#ifndef OS_FCHOWN_METHODDEF
6315 #define OS_FCHOWN_METHODDEF
6316#endif /* !defined(OS_FCHOWN_METHODDEF) */
6317
6318#ifndef OS_LCHOWN_METHODDEF
6319 #define OS_LCHOWN_METHODDEF
6320#endif /* !defined(OS_LCHOWN_METHODDEF) */
6321
6322#ifndef OS_LINK_METHODDEF
6323 #define OS_LINK_METHODDEF
6324#endif /* !defined(OS_LINK_METHODDEF) */
6325
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006326#ifndef OS__GETFULLPATHNAME_METHODDEF
6327 #define OS__GETFULLPATHNAME_METHODDEF
6328#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6329
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006330#ifndef OS__GETFINALPATHNAME_METHODDEF
6331 #define OS__GETFINALPATHNAME_METHODDEF
6332#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6333
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006334#ifndef OS__ISDIR_METHODDEF
6335 #define OS__ISDIR_METHODDEF
6336#endif /* !defined(OS__ISDIR_METHODDEF) */
6337
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006338#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6339 #define OS__GETVOLUMEPATHNAME_METHODDEF
6340#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6341
6342#ifndef OS_NICE_METHODDEF
6343 #define OS_NICE_METHODDEF
6344#endif /* !defined(OS_NICE_METHODDEF) */
6345
6346#ifndef OS_GETPRIORITY_METHODDEF
6347 #define OS_GETPRIORITY_METHODDEF
6348#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6349
6350#ifndef OS_SETPRIORITY_METHODDEF
6351 #define OS_SETPRIORITY_METHODDEF
6352#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6353
6354#ifndef OS_SYSTEM_METHODDEF
6355 #define OS_SYSTEM_METHODDEF
6356#endif /* !defined(OS_SYSTEM_METHODDEF) */
6357
6358#ifndef OS_UNAME_METHODDEF
6359 #define OS_UNAME_METHODDEF
6360#endif /* !defined(OS_UNAME_METHODDEF) */
6361
6362#ifndef OS_EXECV_METHODDEF
6363 #define OS_EXECV_METHODDEF
6364#endif /* !defined(OS_EXECV_METHODDEF) */
6365
6366#ifndef OS_EXECVE_METHODDEF
6367 #define OS_EXECVE_METHODDEF
6368#endif /* !defined(OS_EXECVE_METHODDEF) */
6369
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006370#ifndef OS_POSIX_SPAWN_METHODDEF
6371 #define OS_POSIX_SPAWN_METHODDEF
6372#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6373
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006374#ifndef OS_SPAWNV_METHODDEF
6375 #define OS_SPAWNV_METHODDEF
6376#endif /* !defined(OS_SPAWNV_METHODDEF) */
6377
6378#ifndef OS_SPAWNVE_METHODDEF
6379 #define OS_SPAWNVE_METHODDEF
6380#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6381
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006382#ifndef OS_REGISTER_AT_FORK_METHODDEF
6383 #define OS_REGISTER_AT_FORK_METHODDEF
6384#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6385
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006386#ifndef OS_FORK1_METHODDEF
6387 #define OS_FORK1_METHODDEF
6388#endif /* !defined(OS_FORK1_METHODDEF) */
6389
6390#ifndef OS_FORK_METHODDEF
6391 #define OS_FORK_METHODDEF
6392#endif /* !defined(OS_FORK_METHODDEF) */
6393
6394#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6395 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6396#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6397
6398#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6399 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6400#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6401
6402#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6403 #define OS_SCHED_GETSCHEDULER_METHODDEF
6404#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6405
6406#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6407 #define OS_SCHED_SETSCHEDULER_METHODDEF
6408#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6409
6410#ifndef OS_SCHED_GETPARAM_METHODDEF
6411 #define OS_SCHED_GETPARAM_METHODDEF
6412#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6413
6414#ifndef OS_SCHED_SETPARAM_METHODDEF
6415 #define OS_SCHED_SETPARAM_METHODDEF
6416#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6417
6418#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6419 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6420#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6421
6422#ifndef OS_SCHED_YIELD_METHODDEF
6423 #define OS_SCHED_YIELD_METHODDEF
6424#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6425
6426#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6427 #define OS_SCHED_SETAFFINITY_METHODDEF
6428#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6429
6430#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6431 #define OS_SCHED_GETAFFINITY_METHODDEF
6432#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6433
6434#ifndef OS_OPENPTY_METHODDEF
6435 #define OS_OPENPTY_METHODDEF
6436#endif /* !defined(OS_OPENPTY_METHODDEF) */
6437
6438#ifndef OS_FORKPTY_METHODDEF
6439 #define OS_FORKPTY_METHODDEF
6440#endif /* !defined(OS_FORKPTY_METHODDEF) */
6441
6442#ifndef OS_GETEGID_METHODDEF
6443 #define OS_GETEGID_METHODDEF
6444#endif /* !defined(OS_GETEGID_METHODDEF) */
6445
6446#ifndef OS_GETEUID_METHODDEF
6447 #define OS_GETEUID_METHODDEF
6448#endif /* !defined(OS_GETEUID_METHODDEF) */
6449
6450#ifndef OS_GETGID_METHODDEF
6451 #define OS_GETGID_METHODDEF
6452#endif /* !defined(OS_GETGID_METHODDEF) */
6453
Berker Peksag39404992016-09-15 20:45:16 +03006454#ifndef OS_GETPID_METHODDEF
6455 #define OS_GETPID_METHODDEF
6456#endif /* !defined(OS_GETPID_METHODDEF) */
6457
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006458#ifndef OS_GETGROUPS_METHODDEF
6459 #define OS_GETGROUPS_METHODDEF
6460#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6461
6462#ifndef OS_GETPGID_METHODDEF
6463 #define OS_GETPGID_METHODDEF
6464#endif /* !defined(OS_GETPGID_METHODDEF) */
6465
6466#ifndef OS_GETPGRP_METHODDEF
6467 #define OS_GETPGRP_METHODDEF
6468#endif /* !defined(OS_GETPGRP_METHODDEF) */
6469
6470#ifndef OS_SETPGRP_METHODDEF
6471 #define OS_SETPGRP_METHODDEF
6472#endif /* !defined(OS_SETPGRP_METHODDEF) */
6473
6474#ifndef OS_GETPPID_METHODDEF
6475 #define OS_GETPPID_METHODDEF
6476#endif /* !defined(OS_GETPPID_METHODDEF) */
6477
6478#ifndef OS_GETLOGIN_METHODDEF
6479 #define OS_GETLOGIN_METHODDEF
6480#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6481
6482#ifndef OS_GETUID_METHODDEF
6483 #define OS_GETUID_METHODDEF
6484#endif /* !defined(OS_GETUID_METHODDEF) */
6485
6486#ifndef OS_KILL_METHODDEF
6487 #define OS_KILL_METHODDEF
6488#endif /* !defined(OS_KILL_METHODDEF) */
6489
6490#ifndef OS_KILLPG_METHODDEF
6491 #define OS_KILLPG_METHODDEF
6492#endif /* !defined(OS_KILLPG_METHODDEF) */
6493
6494#ifndef OS_PLOCK_METHODDEF
6495 #define OS_PLOCK_METHODDEF
6496#endif /* !defined(OS_PLOCK_METHODDEF) */
6497
6498#ifndef OS_SETUID_METHODDEF
6499 #define OS_SETUID_METHODDEF
6500#endif /* !defined(OS_SETUID_METHODDEF) */
6501
6502#ifndef OS_SETEUID_METHODDEF
6503 #define OS_SETEUID_METHODDEF
6504#endif /* !defined(OS_SETEUID_METHODDEF) */
6505
6506#ifndef OS_SETEGID_METHODDEF
6507 #define OS_SETEGID_METHODDEF
6508#endif /* !defined(OS_SETEGID_METHODDEF) */
6509
6510#ifndef OS_SETREUID_METHODDEF
6511 #define OS_SETREUID_METHODDEF
6512#endif /* !defined(OS_SETREUID_METHODDEF) */
6513
6514#ifndef OS_SETREGID_METHODDEF
6515 #define OS_SETREGID_METHODDEF
6516#endif /* !defined(OS_SETREGID_METHODDEF) */
6517
6518#ifndef OS_SETGID_METHODDEF
6519 #define OS_SETGID_METHODDEF
6520#endif /* !defined(OS_SETGID_METHODDEF) */
6521
6522#ifndef OS_SETGROUPS_METHODDEF
6523 #define OS_SETGROUPS_METHODDEF
6524#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6525
6526#ifndef OS_WAIT3_METHODDEF
6527 #define OS_WAIT3_METHODDEF
6528#endif /* !defined(OS_WAIT3_METHODDEF) */
6529
6530#ifndef OS_WAIT4_METHODDEF
6531 #define OS_WAIT4_METHODDEF
6532#endif /* !defined(OS_WAIT4_METHODDEF) */
6533
6534#ifndef OS_WAITID_METHODDEF
6535 #define OS_WAITID_METHODDEF
6536#endif /* !defined(OS_WAITID_METHODDEF) */
6537
6538#ifndef OS_WAITPID_METHODDEF
6539 #define OS_WAITPID_METHODDEF
6540#endif /* !defined(OS_WAITPID_METHODDEF) */
6541
6542#ifndef OS_WAIT_METHODDEF
6543 #define OS_WAIT_METHODDEF
6544#endif /* !defined(OS_WAIT_METHODDEF) */
6545
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006546#ifndef OS_READLINK_METHODDEF
6547 #define OS_READLINK_METHODDEF
6548#endif /* !defined(OS_READLINK_METHODDEF) */
6549
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006550#ifndef OS_SYMLINK_METHODDEF
6551 #define OS_SYMLINK_METHODDEF
6552#endif /* !defined(OS_SYMLINK_METHODDEF) */
6553
6554#ifndef OS_TIMES_METHODDEF
6555 #define OS_TIMES_METHODDEF
6556#endif /* !defined(OS_TIMES_METHODDEF) */
6557
6558#ifndef OS_GETSID_METHODDEF
6559 #define OS_GETSID_METHODDEF
6560#endif /* !defined(OS_GETSID_METHODDEF) */
6561
6562#ifndef OS_SETSID_METHODDEF
6563 #define OS_SETSID_METHODDEF
6564#endif /* !defined(OS_SETSID_METHODDEF) */
6565
6566#ifndef OS_SETPGID_METHODDEF
6567 #define OS_SETPGID_METHODDEF
6568#endif /* !defined(OS_SETPGID_METHODDEF) */
6569
6570#ifndef OS_TCGETPGRP_METHODDEF
6571 #define OS_TCGETPGRP_METHODDEF
6572#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6573
6574#ifndef OS_TCSETPGRP_METHODDEF
6575 #define OS_TCSETPGRP_METHODDEF
6576#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6577
6578#ifndef OS_LOCKF_METHODDEF
6579 #define OS_LOCKF_METHODDEF
6580#endif /* !defined(OS_LOCKF_METHODDEF) */
6581
6582#ifndef OS_READV_METHODDEF
6583 #define OS_READV_METHODDEF
6584#endif /* !defined(OS_READV_METHODDEF) */
6585
6586#ifndef OS_PREAD_METHODDEF
6587 #define OS_PREAD_METHODDEF
6588#endif /* !defined(OS_PREAD_METHODDEF) */
6589
Pablo Galindo4defba32018-01-27 16:16:37 +00006590#ifndef OS_PREADV_METHODDEF
6591 #define OS_PREADV_METHODDEF
6592#endif /* !defined(OS_PREADV_METHODDEF) */
6593
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02006594#ifndef OS__FCOPYFILE_METHODDEF
6595 #define OS__FCOPYFILE_METHODDEF
6596#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
6597
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006598#ifndef OS_PIPE_METHODDEF
6599 #define OS_PIPE_METHODDEF
6600#endif /* !defined(OS_PIPE_METHODDEF) */
6601
6602#ifndef OS_PIPE2_METHODDEF
6603 #define OS_PIPE2_METHODDEF
6604#endif /* !defined(OS_PIPE2_METHODDEF) */
6605
6606#ifndef OS_WRITEV_METHODDEF
6607 #define OS_WRITEV_METHODDEF
6608#endif /* !defined(OS_WRITEV_METHODDEF) */
6609
6610#ifndef OS_PWRITE_METHODDEF
6611 #define OS_PWRITE_METHODDEF
6612#endif /* !defined(OS_PWRITE_METHODDEF) */
6613
Pablo Galindo4defba32018-01-27 16:16:37 +00006614#ifndef OS_PWRITEV_METHODDEF
6615 #define OS_PWRITEV_METHODDEF
6616#endif /* !defined(OS_PWRITEV_METHODDEF) */
6617
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006618#ifndef OS_MKFIFO_METHODDEF
6619 #define OS_MKFIFO_METHODDEF
6620#endif /* !defined(OS_MKFIFO_METHODDEF) */
6621
6622#ifndef OS_MKNOD_METHODDEF
6623 #define OS_MKNOD_METHODDEF
6624#endif /* !defined(OS_MKNOD_METHODDEF) */
6625
6626#ifndef OS_MAJOR_METHODDEF
6627 #define OS_MAJOR_METHODDEF
6628#endif /* !defined(OS_MAJOR_METHODDEF) */
6629
6630#ifndef OS_MINOR_METHODDEF
6631 #define OS_MINOR_METHODDEF
6632#endif /* !defined(OS_MINOR_METHODDEF) */
6633
6634#ifndef OS_MAKEDEV_METHODDEF
6635 #define OS_MAKEDEV_METHODDEF
6636#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6637
6638#ifndef OS_FTRUNCATE_METHODDEF
6639 #define OS_FTRUNCATE_METHODDEF
6640#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6641
6642#ifndef OS_TRUNCATE_METHODDEF
6643 #define OS_TRUNCATE_METHODDEF
6644#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6645
6646#ifndef OS_POSIX_FALLOCATE_METHODDEF
6647 #define OS_POSIX_FALLOCATE_METHODDEF
6648#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6649
6650#ifndef OS_POSIX_FADVISE_METHODDEF
6651 #define OS_POSIX_FADVISE_METHODDEF
6652#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6653
6654#ifndef OS_PUTENV_METHODDEF
6655 #define OS_PUTENV_METHODDEF
6656#endif /* !defined(OS_PUTENV_METHODDEF) */
6657
6658#ifndef OS_UNSETENV_METHODDEF
6659 #define OS_UNSETENV_METHODDEF
6660#endif /* !defined(OS_UNSETENV_METHODDEF) */
6661
6662#ifndef OS_WCOREDUMP_METHODDEF
6663 #define OS_WCOREDUMP_METHODDEF
6664#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6665
6666#ifndef OS_WIFCONTINUED_METHODDEF
6667 #define OS_WIFCONTINUED_METHODDEF
6668#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6669
6670#ifndef OS_WIFSTOPPED_METHODDEF
6671 #define OS_WIFSTOPPED_METHODDEF
6672#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6673
6674#ifndef OS_WIFSIGNALED_METHODDEF
6675 #define OS_WIFSIGNALED_METHODDEF
6676#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6677
6678#ifndef OS_WIFEXITED_METHODDEF
6679 #define OS_WIFEXITED_METHODDEF
6680#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6681
6682#ifndef OS_WEXITSTATUS_METHODDEF
6683 #define OS_WEXITSTATUS_METHODDEF
6684#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6685
6686#ifndef OS_WTERMSIG_METHODDEF
6687 #define OS_WTERMSIG_METHODDEF
6688#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6689
6690#ifndef OS_WSTOPSIG_METHODDEF
6691 #define OS_WSTOPSIG_METHODDEF
6692#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6693
6694#ifndef OS_FSTATVFS_METHODDEF
6695 #define OS_FSTATVFS_METHODDEF
6696#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6697
6698#ifndef OS_STATVFS_METHODDEF
6699 #define OS_STATVFS_METHODDEF
6700#endif /* !defined(OS_STATVFS_METHODDEF) */
6701
6702#ifndef OS__GETDISKUSAGE_METHODDEF
6703 #define OS__GETDISKUSAGE_METHODDEF
6704#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6705
6706#ifndef OS_FPATHCONF_METHODDEF
6707 #define OS_FPATHCONF_METHODDEF
6708#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6709
6710#ifndef OS_PATHCONF_METHODDEF
6711 #define OS_PATHCONF_METHODDEF
6712#endif /* !defined(OS_PATHCONF_METHODDEF) */
6713
6714#ifndef OS_CONFSTR_METHODDEF
6715 #define OS_CONFSTR_METHODDEF
6716#endif /* !defined(OS_CONFSTR_METHODDEF) */
6717
6718#ifndef OS_SYSCONF_METHODDEF
6719 #define OS_SYSCONF_METHODDEF
6720#endif /* !defined(OS_SYSCONF_METHODDEF) */
6721
Steve Dowercc16be82016-09-08 10:35:16 -07006722#ifndef OS_STARTFILE_METHODDEF
6723 #define OS_STARTFILE_METHODDEF
6724#endif /* !defined(OS_STARTFILE_METHODDEF) */
6725
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006726#ifndef OS_GETLOADAVG_METHODDEF
6727 #define OS_GETLOADAVG_METHODDEF
6728#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6729
6730#ifndef OS_SETRESUID_METHODDEF
6731 #define OS_SETRESUID_METHODDEF
6732#endif /* !defined(OS_SETRESUID_METHODDEF) */
6733
6734#ifndef OS_SETRESGID_METHODDEF
6735 #define OS_SETRESGID_METHODDEF
6736#endif /* !defined(OS_SETRESGID_METHODDEF) */
6737
6738#ifndef OS_GETRESUID_METHODDEF
6739 #define OS_GETRESUID_METHODDEF
6740#endif /* !defined(OS_GETRESUID_METHODDEF) */
6741
6742#ifndef OS_GETRESGID_METHODDEF
6743 #define OS_GETRESGID_METHODDEF
6744#endif /* !defined(OS_GETRESGID_METHODDEF) */
6745
6746#ifndef OS_GETXATTR_METHODDEF
6747 #define OS_GETXATTR_METHODDEF
6748#endif /* !defined(OS_GETXATTR_METHODDEF) */
6749
6750#ifndef OS_SETXATTR_METHODDEF
6751 #define OS_SETXATTR_METHODDEF
6752#endif /* !defined(OS_SETXATTR_METHODDEF) */
6753
6754#ifndef OS_REMOVEXATTR_METHODDEF
6755 #define OS_REMOVEXATTR_METHODDEF
6756#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6757
6758#ifndef OS_LISTXATTR_METHODDEF
6759 #define OS_LISTXATTR_METHODDEF
6760#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6761
6762#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6763 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6764#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6765
6766#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6767 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6768#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006769
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006770#ifndef OS_GET_BLOCKING_METHODDEF
6771 #define OS_GET_BLOCKING_METHODDEF
6772#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
6773
6774#ifndef OS_SET_BLOCKING_METHODDEF
6775 #define OS_SET_BLOCKING_METHODDEF
6776#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
6777
Victor Stinner9b1f4742016-09-06 16:18:52 -07006778#ifndef OS_GETRANDOM_METHODDEF
6779 #define OS_GETRANDOM_METHODDEF
6780#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006781/*[clinic end generated code: output=0f23518dd4482e66 input=a9049054013a1b77]*/