blob: eabfcf7fc83c3ff0f121700ab17bfe840714a135 [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"
BNMetricsb9427072018-11-02 15:20:19 +000012" Path to be examined; can be string, bytes, a path-like object or\n"
Xiang Zhang4459e002017-01-22 13:04:17 +080013" 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 Storchaka4a934d42018-11-27 11:27:36 +020031 {"stat", (PyCFunction)(void(*)(void))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 Storchaka4a934d42018-11-27 11:27:36 +020069 {"lstat", (PyCFunction)(void(*)(void))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"
BNMetricsb9427072018-11-02 15:20:19 +0000104" Path to be tested; can be string, bytes, or a path-like object.\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 Storchaka4a934d42018-11-27 11:27:36 +0200129 {"access", (PyCFunction)(void(*)(void))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
Serhiy Storchaka4db62e12018-12-17 16:47:45 +0200179static PyObject *
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;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300187
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300188 if (!PyArg_Parse(arg, "i:ttyname", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300189 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300190 }
Serhiy Storchaka4db62e12018-12-17 16:47:45 +0200191 return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192
193exit:
194 return return_value;
195}
196
197#endif /* defined(HAVE_TTYNAME) */
198
199#if defined(HAVE_CTERMID)
200
201PyDoc_STRVAR(os_ctermid__doc__,
202"ctermid($module, /)\n"
203"--\n"
204"\n"
205"Return the name of the controlling terminal for this process.");
206
207#define OS_CTERMID_METHODDEF \
208 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
209
210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300211os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300212
213static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300214os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300215{
216 return os_ctermid_impl(module);
217}
218
219#endif /* defined(HAVE_CTERMID) */
220
221PyDoc_STRVAR(os_chdir__doc__,
222"chdir($module, /, path)\n"
223"--\n"
224"\n"
225"Change the current working directory to the specified path.\n"
226"\n"
227"path may always be specified as a string.\n"
228"On some platforms, path may also be specified as an open file descriptor.\n"
229" If this functionality is unavailable, using it raises an exception.");
230
231#define OS_CHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200232 {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300233
234static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300235os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300236
237static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200238os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300239{
240 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300241 static const char * const _keywords[] = {"path", NULL};
242 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300243 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
244
Victor Stinner3e1fad62017-01-17 01:29:01 +0100245 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300246 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300247 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300249 return_value = os_chdir_impl(module, &path);
250
251exit:
252 /* Cleanup for path */
253 path_cleanup(&path);
254
255 return return_value;
256}
257
258#if defined(HAVE_FCHDIR)
259
260PyDoc_STRVAR(os_fchdir__doc__,
261"fchdir($module, /, fd)\n"
262"--\n"
263"\n"
264"Change to the directory of the given file descriptor.\n"
265"\n"
266"fd must be opened on a directory, not a file.\n"
267"Equivalent to os.chdir(fd).");
268
269#define OS_FCHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200270 {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300271
272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300273os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300274
275static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200276os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300277{
278 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300279 static const char * const _keywords[] = {"fd", NULL};
280 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300281 int fd;
282
Victor Stinner3e1fad62017-01-17 01:29:01 +0100283 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300284 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300285 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300286 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300287 return_value = os_fchdir_impl(module, fd);
288
289exit:
290 return return_value;
291}
292
293#endif /* defined(HAVE_FCHDIR) */
294
295PyDoc_STRVAR(os_chmod__doc__,
296"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
297"--\n"
298"\n"
299"Change the access permissions of a file.\n"
300"\n"
301" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000302" Path to be modified. May always be specified as a str, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300303" On some platforms, path may also be specified as an open file descriptor.\n"
304" If this functionality is unavailable, using it raises an exception.\n"
305" mode\n"
306" Operating-system mode bitfield.\n"
307" dir_fd\n"
308" If not None, it should be a file descriptor open to a directory,\n"
309" and path should be relative; path will then be relative to that\n"
310" directory.\n"
311" follow_symlinks\n"
312" If False, and the last element of the path is a symbolic link,\n"
313" chmod will modify the symbolic link itself instead of the file\n"
314" the link points to.\n"
315"\n"
316"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
317" an open file descriptor.\n"
318"dir_fd and follow_symlinks may not be implemented on your platform.\n"
319" If they are unavailable, using them will raise a NotImplementedError.");
320
321#define OS_CHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200322 {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300323
324static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300325os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400326 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300327
328static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200329os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300330{
331 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300332 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
333 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300334 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
335 int mode;
336 int dir_fd = DEFAULT_DIR_FD;
337 int follow_symlinks = 1;
338
Victor Stinner3e1fad62017-01-17 01:29:01 +0100339 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300340 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300341 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300342 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300343 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
344
345exit:
346 /* Cleanup for path */
347 path_cleanup(&path);
348
349 return return_value;
350}
351
352#if defined(HAVE_FCHMOD)
353
354PyDoc_STRVAR(os_fchmod__doc__,
355"fchmod($module, /, fd, mode)\n"
356"--\n"
357"\n"
358"Change the access permissions of the file given by file descriptor fd.\n"
359"\n"
360"Equivalent to os.chmod(fd, mode).");
361
362#define OS_FCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200363 {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300364
365static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300366os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300367
368static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200369os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300370{
371 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300372 static const char * const _keywords[] = {"fd", "mode", NULL};
373 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300374 int fd;
375 int mode;
376
Victor Stinner3e1fad62017-01-17 01:29:01 +0100377 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300378 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300379 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300380 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300381 return_value = os_fchmod_impl(module, fd, mode);
382
383exit:
384 return return_value;
385}
386
387#endif /* defined(HAVE_FCHMOD) */
388
389#if defined(HAVE_LCHMOD)
390
391PyDoc_STRVAR(os_lchmod__doc__,
392"lchmod($module, /, path, mode)\n"
393"--\n"
394"\n"
395"Change the access permissions of a file, without following symbolic links.\n"
396"\n"
397"If path is a symlink, this affects the link itself rather than the target.\n"
398"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
399
400#define OS_LCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200401 {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300402
403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300404os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300405
406static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200407os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300408{
409 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300410 static const char * const _keywords[] = {"path", "mode", NULL};
411 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300412 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
413 int mode;
414
Victor Stinner3e1fad62017-01-17 01:29:01 +0100415 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300416 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300417 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300418 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300419 return_value = os_lchmod_impl(module, &path, mode);
420
421exit:
422 /* Cleanup for path */
423 path_cleanup(&path);
424
425 return return_value;
426}
427
428#endif /* defined(HAVE_LCHMOD) */
429
430#if defined(HAVE_CHFLAGS)
431
432PyDoc_STRVAR(os_chflags__doc__,
433"chflags($module, /, path, flags, follow_symlinks=True)\n"
434"--\n"
435"\n"
436"Set file flags.\n"
437"\n"
438"If follow_symlinks is False, and the last element of the path is a symbolic\n"
439" link, chflags will change flags on the symbolic link itself instead of the\n"
440" file the link points to.\n"
441"follow_symlinks may not be implemented on your platform. If it is\n"
442"unavailable, using it will raise a NotImplementedError.");
443
444#define OS_CHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200445 {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300446
447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300448os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400449 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300450
451static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200452os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300453{
454 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300455 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
456 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300457 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
458 unsigned long flags;
459 int follow_symlinks = 1;
460
Victor Stinner3e1fad62017-01-17 01:29:01 +0100461 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300462 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300463 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300464 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300465 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
466
467exit:
468 /* Cleanup for path */
469 path_cleanup(&path);
470
471 return return_value;
472}
473
474#endif /* defined(HAVE_CHFLAGS) */
475
476#if defined(HAVE_LCHFLAGS)
477
478PyDoc_STRVAR(os_lchflags__doc__,
479"lchflags($module, /, path, flags)\n"
480"--\n"
481"\n"
482"Set file flags.\n"
483"\n"
484"This function will not follow symbolic links.\n"
485"Equivalent to chflags(path, flags, follow_symlinks=False).");
486
487#define OS_LCHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200488 {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300489
490static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300491os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300492
493static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200494os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300495{
496 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300497 static const char * const _keywords[] = {"path", "flags", NULL};
498 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300499 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
500 unsigned long flags;
501
Victor Stinner3e1fad62017-01-17 01:29:01 +0100502 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300503 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300505 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300506 return_value = os_lchflags_impl(module, &path, flags);
507
508exit:
509 /* Cleanup for path */
510 path_cleanup(&path);
511
512 return return_value;
513}
514
515#endif /* defined(HAVE_LCHFLAGS) */
516
517#if defined(HAVE_CHROOT)
518
519PyDoc_STRVAR(os_chroot__doc__,
520"chroot($module, /, path)\n"
521"--\n"
522"\n"
523"Change root directory to path.");
524
525#define OS_CHROOT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200526 {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300527
528static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300529os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300530
531static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200532os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300533{
534 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300535 static const char * const _keywords[] = {"path", NULL};
536 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
538
Victor Stinner3e1fad62017-01-17 01:29:01 +0100539 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300540 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300541 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300542 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300543 return_value = os_chroot_impl(module, &path);
544
545exit:
546 /* Cleanup for path */
547 path_cleanup(&path);
548
549 return return_value;
550}
551
552#endif /* defined(HAVE_CHROOT) */
553
554#if defined(HAVE_FSYNC)
555
556PyDoc_STRVAR(os_fsync__doc__,
557"fsync($module, /, fd)\n"
558"--\n"
559"\n"
560"Force write of fd to disk.");
561
562#define OS_FSYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200563 {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300564
565static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300566os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300567
568static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200569os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300570{
571 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300572 static const char * const _keywords[] = {"fd", NULL};
573 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300574 int fd;
575
Victor Stinner3e1fad62017-01-17 01:29:01 +0100576 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300577 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300578 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300579 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300580 return_value = os_fsync_impl(module, fd);
581
582exit:
583 return return_value;
584}
585
586#endif /* defined(HAVE_FSYNC) */
587
588#if defined(HAVE_SYNC)
589
590PyDoc_STRVAR(os_sync__doc__,
591"sync($module, /)\n"
592"--\n"
593"\n"
594"Force write of everything to disk.");
595
596#define OS_SYNC_METHODDEF \
597 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
598
599static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300600os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300601
602static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300603os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300604{
605 return os_sync_impl(module);
606}
607
608#endif /* defined(HAVE_SYNC) */
609
610#if defined(HAVE_FDATASYNC)
611
612PyDoc_STRVAR(os_fdatasync__doc__,
613"fdatasync($module, /, fd)\n"
614"--\n"
615"\n"
616"Force write of fd to disk without forcing update of metadata.");
617
618#define OS_FDATASYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200619 {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300620
621static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300622os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300623
624static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200625os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300626{
627 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300628 static const char * const _keywords[] = {"fd", NULL};
629 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300630 int fd;
631
Victor Stinner3e1fad62017-01-17 01:29:01 +0100632 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300633 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300634 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300635 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300636 return_value = os_fdatasync_impl(module, fd);
637
638exit:
639 return return_value;
640}
641
642#endif /* defined(HAVE_FDATASYNC) */
643
644#if defined(HAVE_CHOWN)
645
646PyDoc_STRVAR(os_chown__doc__,
647"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
648"--\n"
649"\n"
650"Change the owner and group id of path to the numeric uid and gid.\\\n"
651"\n"
652" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000653" Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300654" dir_fd\n"
655" If not None, it should be a file descriptor open to a directory,\n"
656" and path should be relative; path will then be relative to that\n"
657" directory.\n"
658" follow_symlinks\n"
659" If False, and the last element of the path is a symbolic link,\n"
660" stat will examine the symbolic link itself instead of the file\n"
661" the link points to.\n"
662"\n"
663"path may always be specified as a string.\n"
664"On some platforms, path may also be specified as an open file descriptor.\n"
665" If this functionality is unavailable, using it raises an exception.\n"
666"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
667" and path should be relative; path will then be relative to that directory.\n"
668"If follow_symlinks is False, and the last element of the path is a symbolic\n"
669" link, chown will modify the symbolic link itself instead of the file the\n"
670" link points to.\n"
671"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
672" an open file descriptor.\n"
673"dir_fd and follow_symlinks may not be implemented on your platform.\n"
674" If they are unavailable, using them will raise a NotImplementedError.");
675
676#define OS_CHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200677 {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300678
679static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300680os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400681 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300682
683static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200684os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300685{
686 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300687 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
688 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300689 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
690 uid_t uid;
691 gid_t gid;
692 int dir_fd = DEFAULT_DIR_FD;
693 int follow_symlinks = 1;
694
Victor Stinner3e1fad62017-01-17 01:29:01 +0100695 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300696 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 +0300697 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300698 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300699 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
700
701exit:
702 /* Cleanup for path */
703 path_cleanup(&path);
704
705 return return_value;
706}
707
708#endif /* defined(HAVE_CHOWN) */
709
710#if defined(HAVE_FCHOWN)
711
712PyDoc_STRVAR(os_fchown__doc__,
713"fchown($module, /, fd, uid, gid)\n"
714"--\n"
715"\n"
716"Change the owner and group id of the file specified by file descriptor.\n"
717"\n"
718"Equivalent to os.chown(fd, uid, gid).");
719
720#define OS_FCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200721 {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300722
723static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300724os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300725
726static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200727os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300728{
729 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300730 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
731 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300732 int fd;
733 uid_t uid;
734 gid_t gid;
735
Victor Stinner3e1fad62017-01-17 01:29:01 +0100736 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300737 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300738 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300739 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300740 return_value = os_fchown_impl(module, fd, uid, gid);
741
742exit:
743 return return_value;
744}
745
746#endif /* defined(HAVE_FCHOWN) */
747
748#if defined(HAVE_LCHOWN)
749
750PyDoc_STRVAR(os_lchown__doc__,
751"lchown($module, /, path, uid, gid)\n"
752"--\n"
753"\n"
754"Change the owner and group id of path to the numeric uid and gid.\n"
755"\n"
756"This function will not follow symbolic links.\n"
757"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
758
759#define OS_LCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200760 {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300761
762static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300763os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300764
765static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200766os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300767{
768 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300769 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
770 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300771 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
772 uid_t uid;
773 gid_t gid;
774
Victor Stinner3e1fad62017-01-17 01:29:01 +0100775 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300776 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300777 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300778 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300779 return_value = os_lchown_impl(module, &path, uid, gid);
780
781exit:
782 /* Cleanup for path */
783 path_cleanup(&path);
784
785 return return_value;
786}
787
788#endif /* defined(HAVE_LCHOWN) */
789
790PyDoc_STRVAR(os_getcwd__doc__,
791"getcwd($module, /)\n"
792"--\n"
793"\n"
794"Return a unicode string representing the current working directory.");
795
796#define OS_GETCWD_METHODDEF \
797 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
798
799static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300800os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300801
802static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300803os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300804{
805 return os_getcwd_impl(module);
806}
807
808PyDoc_STRVAR(os_getcwdb__doc__,
809"getcwdb($module, /)\n"
810"--\n"
811"\n"
812"Return a bytes string representing the current working directory.");
813
814#define OS_GETCWDB_METHODDEF \
815 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
816
817static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300818os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300819
820static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300821os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300822{
823 return os_getcwdb_impl(module);
824}
825
826#if defined(HAVE_LINK)
827
828PyDoc_STRVAR(os_link__doc__,
829"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
830" follow_symlinks=True)\n"
831"--\n"
832"\n"
833"Create a hard link to a file.\n"
834"\n"
835"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
836" descriptor open to a directory, and the respective path string (src or dst)\n"
837" should be relative; the path will then be relative to that directory.\n"
838"If follow_symlinks is False, and the last element of src is a symbolic\n"
839" link, link will create a link to the symbolic link itself instead of the\n"
840" file the link points to.\n"
841"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
842" platform. If they are unavailable, using them will raise a\n"
843" NotImplementedError.");
844
845#define OS_LINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200846 {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300847
848static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300849os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400850 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300851
852static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200853os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300854{
855 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300856 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
857 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300858 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
859 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
860 int src_dir_fd = DEFAULT_DIR_FD;
861 int dst_dir_fd = DEFAULT_DIR_FD;
862 int follow_symlinks = 1;
863
Victor Stinner3e1fad62017-01-17 01:29:01 +0100864 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300865 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 +0300866 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300867 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300868 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
869
870exit:
871 /* Cleanup for src */
872 path_cleanup(&src);
873 /* Cleanup for dst */
874 path_cleanup(&dst);
875
876 return return_value;
877}
878
879#endif /* defined(HAVE_LINK) */
880
881PyDoc_STRVAR(os_listdir__doc__,
882"listdir($module, /, path=None)\n"
883"--\n"
884"\n"
885"Return a list containing the names of the files in the directory.\n"
886"\n"
BNMetricsb9427072018-11-02 15:20:19 +0000887"path can be specified as either str, bytes, or a path-like object. If path is bytes,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300888" the filenames returned will also be bytes; in all other circumstances\n"
889" the filenames returned will be str.\n"
890"If path is None, uses the path=\'.\'.\n"
891"On some platforms, path may also be specified as an open file descriptor;\\\n"
892" the file descriptor must refer to a directory.\n"
893" If this functionality is unavailable, using it raises NotImplementedError.\n"
894"\n"
895"The list is in arbitrary order. It does not include the special\n"
896"entries \'.\' and \'..\' even if they are present in the directory.");
897
898#define OS_LISTDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200899 {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300900
901static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300902os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300903
904static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200905os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300906{
907 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300908 static const char * const _keywords[] = {"path", NULL};
909 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300910 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
911
Victor Stinner3e1fad62017-01-17 01:29:01 +0100912 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300913 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300914 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300915 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300916 return_value = os_listdir_impl(module, &path);
917
918exit:
919 /* Cleanup for path */
920 path_cleanup(&path);
921
922 return return_value;
923}
924
925#if defined(MS_WINDOWS)
926
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300927PyDoc_STRVAR(os__getfullpathname__doc__,
928"_getfullpathname($module, path, /)\n"
929"--\n"
930"\n");
931
932#define OS__GETFULLPATHNAME_METHODDEF \
933 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
934
935static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300936os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300937
938static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300939os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300940{
941 PyObject *return_value = NULL;
942 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
943
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300944 if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300945 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300946 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300947 return_value = os__getfullpathname_impl(module, &path);
948
949exit:
950 /* Cleanup for path */
951 path_cleanup(&path);
952
953 return return_value;
954}
955
956#endif /* defined(MS_WINDOWS) */
957
958#if defined(MS_WINDOWS)
959
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300960PyDoc_STRVAR(os__getfinalpathname__doc__,
961"_getfinalpathname($module, path, /)\n"
962"--\n"
963"\n"
964"A helper function for samepath on windows.");
965
966#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300967 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300968
969static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -0800970os__getfinalpathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300971
972static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300973os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300974{
975 PyObject *return_value = NULL;
Steve Dower23ad6d02018-02-22 10:39:10 -0800976 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300977
Steve Dower23ad6d02018-02-22 10:39:10 -0800978 if (!PyArg_Parse(arg, "O&:_getfinalpathname", path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300979 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300980 }
Steve Dower23ad6d02018-02-22 10:39:10 -0800981 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300982
983exit:
Steve Dower23ad6d02018-02-22 10:39:10 -0800984 /* Cleanup for path */
985 path_cleanup(&path);
986
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300987 return return_value;
988}
989
990#endif /* defined(MS_WINDOWS) */
991
992#if defined(MS_WINDOWS)
993
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300994PyDoc_STRVAR(os__isdir__doc__,
995"_isdir($module, path, /)\n"
996"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +0200997"\n"
998"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300999
1000#define OS__ISDIR_METHODDEF \
1001 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1002
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001003#endif /* defined(MS_WINDOWS) */
1004
1005#if defined(MS_WINDOWS)
1006
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001007PyDoc_STRVAR(os__getvolumepathname__doc__,
1008"_getvolumepathname($module, /, path)\n"
1009"--\n"
1010"\n"
1011"A helper function for ismount on Win32.");
1012
1013#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001014 {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001015
1016static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001017os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001018
1019static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001020os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001021{
1022 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001023 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08001024 static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1025 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001026
Victor Stinner3e1fad62017-01-17 01:29:01 +01001027 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08001028 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001029 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001030 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001031 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001032
1033exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001034 /* Cleanup for path */
1035 path_cleanup(&path);
1036
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001037 return return_value;
1038}
1039
1040#endif /* defined(MS_WINDOWS) */
1041
1042PyDoc_STRVAR(os_mkdir__doc__,
1043"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1044"--\n"
1045"\n"
1046"Create a directory.\n"
1047"\n"
1048"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1049" and path should be relative; path will then be relative to that directory.\n"
1050"dir_fd may not be implemented on your platform.\n"
1051" If it is unavailable, using it will raise a NotImplementedError.\n"
1052"\n"
1053"The mode argument is ignored on Windows.");
1054
1055#define OS_MKDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001056 {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001057
1058static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001059os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001060
1061static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001062os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001063{
1064 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001065 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1066 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001067 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1068 int mode = 511;
1069 int dir_fd = DEFAULT_DIR_FD;
1070
Victor Stinner3e1fad62017-01-17 01:29:01 +01001071 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001072 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001073 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001074 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001075 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1076
1077exit:
1078 /* Cleanup for path */
1079 path_cleanup(&path);
1080
1081 return return_value;
1082}
1083
1084#if defined(HAVE_NICE)
1085
1086PyDoc_STRVAR(os_nice__doc__,
1087"nice($module, increment, /)\n"
1088"--\n"
1089"\n"
1090"Add increment to the priority of process and return the new priority.");
1091
1092#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001093 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001094
1095static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001096os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001097
1098static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001099os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001100{
1101 PyObject *return_value = NULL;
1102 int increment;
1103
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001104 if (!PyArg_Parse(arg, "i:nice", &increment)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001105 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001106 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001107 return_value = os_nice_impl(module, increment);
1108
1109exit:
1110 return return_value;
1111}
1112
1113#endif /* defined(HAVE_NICE) */
1114
1115#if defined(HAVE_GETPRIORITY)
1116
1117PyDoc_STRVAR(os_getpriority__doc__,
1118"getpriority($module, /, which, who)\n"
1119"--\n"
1120"\n"
1121"Return program scheduling priority.");
1122
1123#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001124 {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001125
1126static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001127os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001128
1129static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001130os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001131{
1132 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001133 static const char * const _keywords[] = {"which", "who", NULL};
1134 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001135 int which;
1136 int who;
1137
Victor Stinner3e1fad62017-01-17 01:29:01 +01001138 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001139 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001140 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001141 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001142 return_value = os_getpriority_impl(module, which, who);
1143
1144exit:
1145 return return_value;
1146}
1147
1148#endif /* defined(HAVE_GETPRIORITY) */
1149
1150#if defined(HAVE_SETPRIORITY)
1151
1152PyDoc_STRVAR(os_setpriority__doc__,
1153"setpriority($module, /, which, who, priority)\n"
1154"--\n"
1155"\n"
1156"Set program scheduling priority.");
1157
1158#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001159 {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001160
1161static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001162os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001163
1164static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001165os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001166{
1167 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001168 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1169 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001170 int which;
1171 int who;
1172 int priority;
1173
Victor Stinner3e1fad62017-01-17 01:29:01 +01001174 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001175 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001176 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001177 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001178 return_value = os_setpriority_impl(module, which, who, priority);
1179
1180exit:
1181 return return_value;
1182}
1183
1184#endif /* defined(HAVE_SETPRIORITY) */
1185
1186PyDoc_STRVAR(os_rename__doc__,
1187"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1188"--\n"
1189"\n"
1190"Rename a file or directory.\n"
1191"\n"
1192"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1193" descriptor open to a directory, and the respective path string (src or dst)\n"
1194" should be relative; the path will then be relative to that directory.\n"
1195"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1196" If they are unavailable, using them will raise a NotImplementedError.");
1197
1198#define OS_RENAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001199 {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001200
1201static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001202os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001203 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001204
1205static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001206os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001207{
1208 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001209 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1210 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001211 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1212 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1213 int src_dir_fd = DEFAULT_DIR_FD;
1214 int dst_dir_fd = DEFAULT_DIR_FD;
1215
Victor Stinner3e1fad62017-01-17 01:29:01 +01001216 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001217 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 +03001218 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001219 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001220 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1221
1222exit:
1223 /* Cleanup for src */
1224 path_cleanup(&src);
1225 /* Cleanup for dst */
1226 path_cleanup(&dst);
1227
1228 return return_value;
1229}
1230
1231PyDoc_STRVAR(os_replace__doc__,
1232"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1233"--\n"
1234"\n"
1235"Rename a file or directory, overwriting the destination.\n"
1236"\n"
1237"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1238" descriptor open to a directory, and the respective path string (src or dst)\n"
1239" should be relative; the path will then be relative to that directory.\n"
1240"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1241" If they are unavailable, using them will raise a NotImplementedError.\"");
1242
1243#define OS_REPLACE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001244 {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001245
1246static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001247os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1248 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001249
1250static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001251os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001252{
1253 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001254 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1255 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001256 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1257 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1258 int src_dir_fd = DEFAULT_DIR_FD;
1259 int dst_dir_fd = DEFAULT_DIR_FD;
1260
Victor Stinner3e1fad62017-01-17 01:29:01 +01001261 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001262 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 +03001263 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001264 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001265 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1266
1267exit:
1268 /* Cleanup for src */
1269 path_cleanup(&src);
1270 /* Cleanup for dst */
1271 path_cleanup(&dst);
1272
1273 return return_value;
1274}
1275
1276PyDoc_STRVAR(os_rmdir__doc__,
1277"rmdir($module, /, path, *, dir_fd=None)\n"
1278"--\n"
1279"\n"
1280"Remove a directory.\n"
1281"\n"
1282"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1283" and path should be relative; path will then be relative to that directory.\n"
1284"dir_fd may not be implemented on your platform.\n"
1285" If it is unavailable, using it will raise a NotImplementedError.");
1286
1287#define OS_RMDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001288 {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001289
1290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001291os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001292
1293static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001294os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001295{
1296 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001297 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1298 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001299 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1300 int dir_fd = DEFAULT_DIR_FD;
1301
Victor Stinner3e1fad62017-01-17 01:29:01 +01001302 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001303 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001304 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001305 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001306 return_value = os_rmdir_impl(module, &path, dir_fd);
1307
1308exit:
1309 /* Cleanup for path */
1310 path_cleanup(&path);
1311
1312 return return_value;
1313}
1314
1315#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1316
1317PyDoc_STRVAR(os_system__doc__,
1318"system($module, /, command)\n"
1319"--\n"
1320"\n"
1321"Execute the command in a subshell.");
1322
1323#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001324 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001325
1326static long
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001327os_system_impl(PyObject *module, const Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001328
1329static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001330os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001331{
1332 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001333 static const char * const _keywords[] = {"command", NULL};
1334 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001335 const Py_UNICODE *command;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001336 long _return_value;
1337
Victor Stinner3e1fad62017-01-17 01:29:01 +01001338 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001339 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001340 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001341 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001342 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001343 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001344 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001345 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001346 return_value = PyLong_FromLong(_return_value);
1347
1348exit:
1349 return return_value;
1350}
1351
1352#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1353
1354#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1355
1356PyDoc_STRVAR(os_system__doc__,
1357"system($module, /, command)\n"
1358"--\n"
1359"\n"
1360"Execute the command in a subshell.");
1361
1362#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001363 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001364
1365static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001366os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001367
1368static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001369os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001370{
1371 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001372 static const char * const _keywords[] = {"command", NULL};
1373 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001374 PyObject *command = NULL;
1375 long _return_value;
1376
Victor Stinner3e1fad62017-01-17 01:29:01 +01001377 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001378 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001379 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001380 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001381 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001382 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001383 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001384 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001385 return_value = PyLong_FromLong(_return_value);
1386
1387exit:
1388 /* Cleanup for command */
1389 Py_XDECREF(command);
1390
1391 return return_value;
1392}
1393
1394#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1395
1396PyDoc_STRVAR(os_umask__doc__,
1397"umask($module, mask, /)\n"
1398"--\n"
1399"\n"
1400"Set the current numeric umask and return the previous umask.");
1401
1402#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001403 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001404
1405static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001406os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001407
1408static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001409os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001410{
1411 PyObject *return_value = NULL;
1412 int mask;
1413
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001414 if (!PyArg_Parse(arg, "i:umask", &mask)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001415 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001416 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001417 return_value = os_umask_impl(module, mask);
1418
1419exit:
1420 return return_value;
1421}
1422
1423PyDoc_STRVAR(os_unlink__doc__,
1424"unlink($module, /, path, *, dir_fd=None)\n"
1425"--\n"
1426"\n"
1427"Remove a file (same as remove()).\n"
1428"\n"
1429"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1430" and path should be relative; path will then be relative to that directory.\n"
1431"dir_fd may not be implemented on your platform.\n"
1432" If it is unavailable, using it will raise a NotImplementedError.");
1433
1434#define OS_UNLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001435 {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001436
1437static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001438os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001439
1440static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001441os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001442{
1443 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001444 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1445 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001446 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1447 int dir_fd = DEFAULT_DIR_FD;
1448
Victor Stinner3e1fad62017-01-17 01:29:01 +01001449 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001450 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001451 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001452 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001453 return_value = os_unlink_impl(module, &path, dir_fd);
1454
1455exit:
1456 /* Cleanup for path */
1457 path_cleanup(&path);
1458
1459 return return_value;
1460}
1461
1462PyDoc_STRVAR(os_remove__doc__,
1463"remove($module, /, path, *, dir_fd=None)\n"
1464"--\n"
1465"\n"
1466"Remove a file (same as unlink()).\n"
1467"\n"
1468"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1469" and path should be relative; path will then be relative to that directory.\n"
1470"dir_fd may not be implemented on your platform.\n"
1471" If it is unavailable, using it will raise a NotImplementedError.");
1472
1473#define OS_REMOVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001474 {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001475
1476static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001477os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001478
1479static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001480os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001481{
1482 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001483 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1484 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001485 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1486 int dir_fd = DEFAULT_DIR_FD;
1487
Victor Stinner3e1fad62017-01-17 01:29:01 +01001488 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001489 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001490 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001491 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001492 return_value = os_remove_impl(module, &path, dir_fd);
1493
1494exit:
1495 /* Cleanup for path */
1496 path_cleanup(&path);
1497
1498 return return_value;
1499}
1500
1501#if defined(HAVE_UNAME)
1502
1503PyDoc_STRVAR(os_uname__doc__,
1504"uname($module, /)\n"
1505"--\n"
1506"\n"
1507"Return an object identifying the current operating system.\n"
1508"\n"
1509"The object behaves like a named tuple with the following fields:\n"
1510" (sysname, nodename, release, version, machine)");
1511
1512#define OS_UNAME_METHODDEF \
1513 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1514
1515static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001516os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001517
1518static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001519os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001520{
1521 return os_uname_impl(module);
1522}
1523
1524#endif /* defined(HAVE_UNAME) */
1525
1526PyDoc_STRVAR(os_utime__doc__,
1527"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1528" follow_symlinks=True)\n"
1529"--\n"
1530"\n"
1531"Set the access and modified time of path.\n"
1532"\n"
1533"path may always be specified as a string.\n"
1534"On some platforms, path may also be specified as an open file descriptor.\n"
1535" If this functionality is unavailable, using it raises an exception.\n"
1536"\n"
1537"If times is not None, it must be a tuple (atime, mtime);\n"
1538" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001539"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001540" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1541" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001542"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001543"Specifying tuples for both times and ns is an error.\n"
1544"\n"
1545"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1546" and path should be relative; path will then be relative to that directory.\n"
1547"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1548" link, utime will modify the symbolic link itself instead of the file the\n"
1549" link points to.\n"
1550"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1551" as an open file descriptor.\n"
1552"dir_fd and follow_symlinks may not be available on your platform.\n"
1553" If they are unavailable, using them will raise a NotImplementedError.");
1554
1555#define OS_UTIME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001556 {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001557
1558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001559os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1560 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001561
1562static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001563os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001564{
1565 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001566 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1567 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001568 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1569 PyObject *times = NULL;
1570 PyObject *ns = NULL;
1571 int dir_fd = DEFAULT_DIR_FD;
1572 int follow_symlinks = 1;
1573
Victor Stinner3e1fad62017-01-17 01:29:01 +01001574 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001575 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001576 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001577 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001578 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1579
1580exit:
1581 /* Cleanup for path */
1582 path_cleanup(&path);
1583
1584 return return_value;
1585}
1586
1587PyDoc_STRVAR(os__exit__doc__,
1588"_exit($module, /, status)\n"
1589"--\n"
1590"\n"
1591"Exit to the system with specified status, without normal exit processing.");
1592
1593#define OS__EXIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001594 {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001595
1596static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001597os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001598
1599static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001600os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001601{
1602 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001603 static const char * const _keywords[] = {"status", NULL};
1604 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001605 int status;
1606
Victor Stinner3e1fad62017-01-17 01:29:01 +01001607 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001608 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001609 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001610 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001611 return_value = os__exit_impl(module, status);
1612
1613exit:
1614 return return_value;
1615}
1616
1617#if defined(HAVE_EXECV)
1618
1619PyDoc_STRVAR(os_execv__doc__,
1620"execv($module, path, argv, /)\n"
1621"--\n"
1622"\n"
1623"Execute an executable path with arguments, replacing current process.\n"
1624"\n"
1625" path\n"
1626" Path of executable file.\n"
1627" argv\n"
1628" Tuple or list of strings.");
1629
1630#define OS_EXECV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001631 {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001632
1633static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001634os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001635
1636static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001637os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001638{
1639 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001640 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001641 PyObject *argv;
1642
Sylvain74453812017-06-10 06:51:48 +02001643 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1644 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001645 goto exit;
1646 }
Steve Dowercc16be82016-09-08 10:35:16 -07001647 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001648
1649exit:
1650 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001651 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001652
1653 return return_value;
1654}
1655
1656#endif /* defined(HAVE_EXECV) */
1657
1658#if defined(HAVE_EXECV)
1659
1660PyDoc_STRVAR(os_execve__doc__,
1661"execve($module, /, path, argv, env)\n"
1662"--\n"
1663"\n"
1664"Execute an executable path with arguments, replacing current process.\n"
1665"\n"
1666" path\n"
1667" Path of executable file.\n"
1668" argv\n"
1669" Tuple or list of strings.\n"
1670" env\n"
1671" Dictionary of strings mapping to strings.");
1672
1673#define OS_EXECVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001674 {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001675
1676static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001677os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001678
1679static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001680os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001681{
1682 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001683 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1684 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001685 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1686 PyObject *argv;
1687 PyObject *env;
1688
Victor Stinner3e1fad62017-01-17 01:29:01 +01001689 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001690 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001691 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001692 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001693 return_value = os_execve_impl(module, &path, argv, env);
1694
1695exit:
1696 /* Cleanup for path */
1697 path_cleanup(&path);
1698
1699 return return_value;
1700}
1701
1702#endif /* defined(HAVE_EXECV) */
1703
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001704#if defined(HAVE_POSIX_SPAWN)
1705
1706PyDoc_STRVAR(os_posix_spawn__doc__,
Serhiy Storchakad700f972018-09-08 14:48:18 +03001707"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001708" setpgroup=None, resetids=False, setsigmask=(),\n"
1709" setsigdef=(), scheduler=None)\n"
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001710"--\n"
1711"\n"
1712"Execute the program specified by path in a new process.\n"
1713"\n"
1714" path\n"
1715" Path of executable file.\n"
1716" argv\n"
1717" Tuple or list of strings.\n"
1718" env\n"
1719" Dictionary of strings mapping to strings.\n"
1720" file_actions\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001721" A sequence of file action tuples.\n"
1722" setpgroup\n"
1723" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1724" resetids\n"
1725" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
1726" setsigmask\n"
1727" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1728" setsigdef\n"
1729" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1730" scheduler\n"
1731" A tuple with the scheduler policy (optional) and parameters.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001732
1733#define OS_POSIX_SPAWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001734 {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001735
1736static PyObject *
1737os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
Pablo Galindo254a4662018-09-07 16:44:24 +01001738 PyObject *env, PyObject *file_actions,
1739 PyObject *setpgroup, int resetids, PyObject *setsigmask,
1740 PyObject *setsigdef, PyObject *scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001741
1742static PyObject *
Pablo Galindo254a4662018-09-07 16:44:24 +01001743os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001744{
1745 PyObject *return_value = NULL;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001746 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL};
1747 static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawn", _keywords, 0};
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001748 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1749 PyObject *argv;
1750 PyObject *env;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001751 PyObject *file_actions = NULL;
Pablo Galindo254a4662018-09-07 16:44:24 +01001752 PyObject *setpgroup = NULL;
1753 int resetids = 0;
1754 PyObject *setsigmask = NULL;
1755 PyObject *setsigdef = NULL;
1756 PyObject *scheduler = NULL;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001757
Pablo Galindo254a4662018-09-07 16:44:24 +01001758 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1759 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) {
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001760 goto exit;
1761 }
Pablo Galindo254a4662018-09-07 16:44:24 +01001762 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001763
1764exit:
1765 /* Cleanup for path */
1766 path_cleanup(&path);
1767
1768 return return_value;
1769}
1770
1771#endif /* defined(HAVE_POSIX_SPAWN) */
1772
Steve Dowercc16be82016-09-08 10:35:16 -07001773#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001774
1775PyDoc_STRVAR(os_spawnv__doc__,
1776"spawnv($module, mode, path, argv, /)\n"
1777"--\n"
1778"\n"
1779"Execute the program specified by path in a new process.\n"
1780"\n"
1781" mode\n"
1782" Mode of process creation.\n"
1783" path\n"
1784" Path of executable file.\n"
1785" argv\n"
1786" Tuple or list of strings.");
1787
1788#define OS_SPAWNV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001789 {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001790
1791static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001792os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001793
1794static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001795os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001796{
1797 PyObject *return_value = NULL;
1798 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001799 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001800 PyObject *argv;
1801
Sylvain74453812017-06-10 06:51:48 +02001802 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1803 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001804 goto exit;
1805 }
Steve Dowercc16be82016-09-08 10:35:16 -07001806 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001807
1808exit:
1809 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001810 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001811
1812 return return_value;
1813}
1814
Steve Dowercc16be82016-09-08 10:35:16 -07001815#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001816
Steve Dowercc16be82016-09-08 10:35:16 -07001817#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001818
1819PyDoc_STRVAR(os_spawnve__doc__,
1820"spawnve($module, mode, path, argv, env, /)\n"
1821"--\n"
1822"\n"
1823"Execute the program specified by path in a new process.\n"
1824"\n"
1825" mode\n"
1826" Mode of process creation.\n"
1827" path\n"
1828" Path of executable file.\n"
1829" argv\n"
1830" Tuple or list of strings.\n"
1831" env\n"
1832" Dictionary of strings mapping to strings.");
1833
1834#define OS_SPAWNVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001835 {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001836
1837static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001838os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001839 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001840
1841static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001842os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001843{
1844 PyObject *return_value = NULL;
1845 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001846 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001847 PyObject *argv;
1848 PyObject *env;
1849
Sylvain74453812017-06-10 06:51:48 +02001850 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1851 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001852 goto exit;
1853 }
Steve Dowercc16be82016-09-08 10:35:16 -07001854 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001855
1856exit:
1857 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001858 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001859
1860 return return_value;
1861}
1862
Steve Dowercc16be82016-09-08 10:35:16 -07001863#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001864
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001865#if defined(HAVE_FORK)
1866
1867PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001868"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1869" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001870"--\n"
1871"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001872"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001873"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001874" before\n"
1875" A callable to be called in the parent before the fork() syscall.\n"
1876" after_in_child\n"
1877" A callable to be called in the child after fork().\n"
1878" after_in_parent\n"
1879" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001880"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001881"\'before\' callbacks are called in reverse order.\n"
1882"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001883
1884#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001885 {"register_at_fork", (PyCFunction)(void(*)(void))os_register_at_fork, METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001886
1887static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001888os_register_at_fork_impl(PyObject *module, PyObject *before,
1889 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001890
1891static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001892os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001893{
1894 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001895 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1896 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1897 PyObject *before = NULL;
1898 PyObject *after_in_child = NULL;
1899 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001900
1901 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001902 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001903 goto exit;
1904 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001905 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001906
1907exit:
1908 return return_value;
1909}
1910
1911#endif /* defined(HAVE_FORK) */
1912
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001913#if defined(HAVE_FORK1)
1914
1915PyDoc_STRVAR(os_fork1__doc__,
1916"fork1($module, /)\n"
1917"--\n"
1918"\n"
1919"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1920"\n"
1921"Return 0 to child process and PID of child to parent process.");
1922
1923#define OS_FORK1_METHODDEF \
1924 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1925
1926static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001927os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001928
1929static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001930os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001931{
1932 return os_fork1_impl(module);
1933}
1934
1935#endif /* defined(HAVE_FORK1) */
1936
1937#if defined(HAVE_FORK)
1938
1939PyDoc_STRVAR(os_fork__doc__,
1940"fork($module, /)\n"
1941"--\n"
1942"\n"
1943"Fork a child process.\n"
1944"\n"
1945"Return 0 to child process and PID of child to parent process.");
1946
1947#define OS_FORK_METHODDEF \
1948 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1949
1950static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001951os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001952
1953static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001954os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001955{
1956 return os_fork_impl(module);
1957}
1958
1959#endif /* defined(HAVE_FORK) */
1960
1961#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1962
1963PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1964"sched_get_priority_max($module, /, policy)\n"
1965"--\n"
1966"\n"
1967"Get the maximum scheduling priority for policy.");
1968
1969#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001970 {"sched_get_priority_max", (PyCFunction)(void(*)(void))os_sched_get_priority_max, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001971
1972static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001973os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001974
1975static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001976os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001977{
1978 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001979 static const char * const _keywords[] = {"policy", NULL};
1980 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001981 int policy;
1982
Victor Stinner3e1fad62017-01-17 01:29:01 +01001983 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001984 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001985 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001986 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001987 return_value = os_sched_get_priority_max_impl(module, policy);
1988
1989exit:
1990 return return_value;
1991}
1992
1993#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
1994
1995#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1996
1997PyDoc_STRVAR(os_sched_get_priority_min__doc__,
1998"sched_get_priority_min($module, /, policy)\n"
1999"--\n"
2000"\n"
2001"Get the minimum scheduling priority for policy.");
2002
2003#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002004 {"sched_get_priority_min", (PyCFunction)(void(*)(void))os_sched_get_priority_min, METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002005
2006static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002007os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002008
2009static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002010os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002011{
2012 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002013 static const char * const _keywords[] = {"policy", NULL};
2014 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002015 int policy;
2016
Victor Stinner3e1fad62017-01-17 01:29:01 +01002017 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002018 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002019 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002020 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002021 return_value = os_sched_get_priority_min_impl(module, policy);
2022
2023exit:
2024 return return_value;
2025}
2026
2027#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2028
2029#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2030
2031PyDoc_STRVAR(os_sched_getscheduler__doc__,
2032"sched_getscheduler($module, pid, /)\n"
2033"--\n"
2034"\n"
2035"Get the scheduling policy for the process identifiedy by pid.\n"
2036"\n"
2037"Passing 0 for pid returns the scheduling policy for the calling process.");
2038
2039#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002040 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002041
2042static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002043os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002044
2045static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002046os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002047{
2048 PyObject *return_value = NULL;
2049 pid_t pid;
2050
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002051 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002052 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002053 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002054 return_value = os_sched_getscheduler_impl(module, pid);
2055
2056exit:
2057 return return_value;
2058}
2059
2060#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2061
William Orr81574b82018-10-01 22:19:56 -07002062#if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002063
2064PyDoc_STRVAR(os_sched_param__doc__,
2065"sched_param(sched_priority)\n"
2066"--\n"
2067"\n"
2068"Current has only one field: sched_priority\");\n"
2069"\n"
2070" sched_priority\n"
2071" A scheduling parameter.");
2072
2073static PyObject *
2074os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2075
2076static PyObject *
2077os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2078{
2079 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002080 static const char * const _keywords[] = {"sched_priority", NULL};
2081 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002082 PyObject *sched_priority;
2083
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002084 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002085 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002086 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002087 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002088 return_value = os_sched_param_impl(type, sched_priority);
2089
2090exit:
2091 return return_value;
2092}
2093
William Orr81574b82018-10-01 22:19:56 -07002094#endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002095
2096#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2097
2098PyDoc_STRVAR(os_sched_setscheduler__doc__,
2099"sched_setscheduler($module, pid, policy, param, /)\n"
2100"--\n"
2101"\n"
2102"Set the scheduling policy for the process identified by pid.\n"
2103"\n"
2104"If pid is 0, the calling process is changed.\n"
2105"param is an instance of sched_param.");
2106
2107#define OS_SCHED_SETSCHEDULER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002108 {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002109
2110static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002111os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002112 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002113
2114static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002115os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002116{
2117 PyObject *return_value = NULL;
2118 pid_t pid;
2119 int policy;
2120 struct sched_param param;
2121
Sylvain74453812017-06-10 06:51:48 +02002122 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2123 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002124 goto exit;
2125 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002126 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2127
2128exit:
2129 return return_value;
2130}
2131
2132#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2133
2134#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2135
2136PyDoc_STRVAR(os_sched_getparam__doc__,
2137"sched_getparam($module, pid, /)\n"
2138"--\n"
2139"\n"
2140"Returns scheduling parameters for the process identified by pid.\n"
2141"\n"
2142"If pid is 0, returns parameters for the calling process.\n"
2143"Return value is an instance of sched_param.");
2144
2145#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002146 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002147
2148static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002149os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002150
2151static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002152os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002153{
2154 PyObject *return_value = NULL;
2155 pid_t pid;
2156
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002157 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002159 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002160 return_value = os_sched_getparam_impl(module, pid);
2161
2162exit:
2163 return return_value;
2164}
2165
2166#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2167
2168#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2169
2170PyDoc_STRVAR(os_sched_setparam__doc__,
2171"sched_setparam($module, pid, param, /)\n"
2172"--\n"
2173"\n"
2174"Set scheduling parameters for the process identified by pid.\n"
2175"\n"
2176"If pid is 0, sets parameters for the calling process.\n"
2177"param should be an instance of sched_param.");
2178
2179#define OS_SCHED_SETPARAM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002180 {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002181
2182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002183os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002184 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002185
2186static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002187os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002188{
2189 PyObject *return_value = NULL;
2190 pid_t pid;
2191 struct sched_param param;
2192
Sylvain74453812017-06-10 06:51:48 +02002193 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2194 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002195 goto exit;
2196 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002197 return_value = os_sched_setparam_impl(module, pid, &param);
2198
2199exit:
2200 return return_value;
2201}
2202
2203#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2204
2205#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2206
2207PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2208"sched_rr_get_interval($module, pid, /)\n"
2209"--\n"
2210"\n"
2211"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2212"\n"
2213"Value returned is a float.");
2214
2215#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002216 {"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 +03002217
2218static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002219os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002220
2221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002222os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002223{
2224 PyObject *return_value = NULL;
2225 pid_t pid;
2226 double _return_value;
2227
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002228 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002229 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002230 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002231 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002232 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002233 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002234 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002235 return_value = PyFloat_FromDouble(_return_value);
2236
2237exit:
2238 return return_value;
2239}
2240
2241#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2242
2243#if defined(HAVE_SCHED_H)
2244
2245PyDoc_STRVAR(os_sched_yield__doc__,
2246"sched_yield($module, /)\n"
2247"--\n"
2248"\n"
2249"Voluntarily relinquish the CPU.");
2250
2251#define OS_SCHED_YIELD_METHODDEF \
2252 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2253
2254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002255os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002256
2257static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002258os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002259{
2260 return os_sched_yield_impl(module);
2261}
2262
2263#endif /* defined(HAVE_SCHED_H) */
2264
2265#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2266
2267PyDoc_STRVAR(os_sched_setaffinity__doc__,
2268"sched_setaffinity($module, pid, mask, /)\n"
2269"--\n"
2270"\n"
2271"Set the CPU affinity of the process identified by pid to mask.\n"
2272"\n"
2273"mask should be an iterable of integers identifying CPUs.");
2274
2275#define OS_SCHED_SETAFFINITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002276 {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002277
2278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002279os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002280
2281static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002282os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002283{
2284 PyObject *return_value = NULL;
2285 pid_t pid;
2286 PyObject *mask;
2287
Sylvain74453812017-06-10 06:51:48 +02002288 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2289 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002290 goto exit;
2291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002292 return_value = os_sched_setaffinity_impl(module, pid, mask);
2293
2294exit:
2295 return return_value;
2296}
2297
2298#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2299
2300#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2301
2302PyDoc_STRVAR(os_sched_getaffinity__doc__,
2303"sched_getaffinity($module, pid, /)\n"
2304"--\n"
2305"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002306"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002307"\n"
2308"The affinity is returned as a set of CPU identifiers.");
2309
2310#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002311 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002312
2313static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002314os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002315
2316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002317os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002318{
2319 PyObject *return_value = NULL;
2320 pid_t pid;
2321
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002322 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002323 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002324 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002325 return_value = os_sched_getaffinity_impl(module, pid);
2326
2327exit:
2328 return return_value;
2329}
2330
2331#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2332
2333#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2334
2335PyDoc_STRVAR(os_openpty__doc__,
2336"openpty($module, /)\n"
2337"--\n"
2338"\n"
2339"Open a pseudo-terminal.\n"
2340"\n"
2341"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2342"for both the master and slave ends.");
2343
2344#define OS_OPENPTY_METHODDEF \
2345 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2346
2347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002348os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002349
2350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002351os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002352{
2353 return os_openpty_impl(module);
2354}
2355
2356#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2357
2358#if defined(HAVE_FORKPTY)
2359
2360PyDoc_STRVAR(os_forkpty__doc__,
2361"forkpty($module, /)\n"
2362"--\n"
2363"\n"
2364"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2365"\n"
2366"Returns a tuple of (pid, master_fd).\n"
2367"Like fork(), return pid of 0 to the child process,\n"
2368"and pid of child to the parent process.\n"
2369"To both, return fd of newly opened pseudo-terminal.");
2370
2371#define OS_FORKPTY_METHODDEF \
2372 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2373
2374static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002375os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002376
2377static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002378os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002379{
2380 return os_forkpty_impl(module);
2381}
2382
2383#endif /* defined(HAVE_FORKPTY) */
2384
2385#if defined(HAVE_GETEGID)
2386
2387PyDoc_STRVAR(os_getegid__doc__,
2388"getegid($module, /)\n"
2389"--\n"
2390"\n"
2391"Return the current process\'s effective group id.");
2392
2393#define OS_GETEGID_METHODDEF \
2394 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2395
2396static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002397os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002398
2399static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002400os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002401{
2402 return os_getegid_impl(module);
2403}
2404
2405#endif /* defined(HAVE_GETEGID) */
2406
2407#if defined(HAVE_GETEUID)
2408
2409PyDoc_STRVAR(os_geteuid__doc__,
2410"geteuid($module, /)\n"
2411"--\n"
2412"\n"
2413"Return the current process\'s effective user id.");
2414
2415#define OS_GETEUID_METHODDEF \
2416 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2417
2418static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002419os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002420
2421static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002422os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002423{
2424 return os_geteuid_impl(module);
2425}
2426
2427#endif /* defined(HAVE_GETEUID) */
2428
2429#if defined(HAVE_GETGID)
2430
2431PyDoc_STRVAR(os_getgid__doc__,
2432"getgid($module, /)\n"
2433"--\n"
2434"\n"
2435"Return the current process\'s group id.");
2436
2437#define OS_GETGID_METHODDEF \
2438 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2439
2440static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002441os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002442
2443static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002444os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002445{
2446 return os_getgid_impl(module);
2447}
2448
2449#endif /* defined(HAVE_GETGID) */
2450
Berker Peksag39404992016-09-15 20:45:16 +03002451#if defined(HAVE_GETPID)
2452
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002453PyDoc_STRVAR(os_getpid__doc__,
2454"getpid($module, /)\n"
2455"--\n"
2456"\n"
2457"Return the current process id.");
2458
2459#define OS_GETPID_METHODDEF \
2460 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2461
2462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002463os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002464
2465static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002466os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002467{
2468 return os_getpid_impl(module);
2469}
2470
Berker Peksag39404992016-09-15 20:45:16 +03002471#endif /* defined(HAVE_GETPID) */
2472
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002473#if defined(HAVE_GETGROUPS)
2474
2475PyDoc_STRVAR(os_getgroups__doc__,
2476"getgroups($module, /)\n"
2477"--\n"
2478"\n"
2479"Return list of supplemental group IDs for the process.");
2480
2481#define OS_GETGROUPS_METHODDEF \
2482 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2483
2484static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002485os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002486
2487static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002488os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002489{
2490 return os_getgroups_impl(module);
2491}
2492
2493#endif /* defined(HAVE_GETGROUPS) */
2494
2495#if defined(HAVE_GETPGID)
2496
2497PyDoc_STRVAR(os_getpgid__doc__,
2498"getpgid($module, /, pid)\n"
2499"--\n"
2500"\n"
2501"Call the system call getpgid(), and return the result.");
2502
2503#define OS_GETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002504 {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002505
2506static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002507os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002508
2509static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002510os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002511{
2512 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002513 static const char * const _keywords[] = {"pid", NULL};
2514 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002515 pid_t pid;
2516
Victor Stinner3e1fad62017-01-17 01:29:01 +01002517 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002518 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002519 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002520 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002521 return_value = os_getpgid_impl(module, pid);
2522
2523exit:
2524 return return_value;
2525}
2526
2527#endif /* defined(HAVE_GETPGID) */
2528
2529#if defined(HAVE_GETPGRP)
2530
2531PyDoc_STRVAR(os_getpgrp__doc__,
2532"getpgrp($module, /)\n"
2533"--\n"
2534"\n"
2535"Return the current process group id.");
2536
2537#define OS_GETPGRP_METHODDEF \
2538 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2539
2540static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002541os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002542
2543static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002544os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002545{
2546 return os_getpgrp_impl(module);
2547}
2548
2549#endif /* defined(HAVE_GETPGRP) */
2550
2551#if defined(HAVE_SETPGRP)
2552
2553PyDoc_STRVAR(os_setpgrp__doc__,
2554"setpgrp($module, /)\n"
2555"--\n"
2556"\n"
2557"Make the current process the leader of its process group.");
2558
2559#define OS_SETPGRP_METHODDEF \
2560 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2561
2562static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002563os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002564
2565static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002566os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002567{
2568 return os_setpgrp_impl(module);
2569}
2570
2571#endif /* defined(HAVE_SETPGRP) */
2572
2573#if defined(HAVE_GETPPID)
2574
2575PyDoc_STRVAR(os_getppid__doc__,
2576"getppid($module, /)\n"
2577"--\n"
2578"\n"
2579"Return the parent\'s process id.\n"
2580"\n"
2581"If the parent process has already exited, Windows machines will still\n"
2582"return its id; others systems will return the id of the \'init\' process (1).");
2583
2584#define OS_GETPPID_METHODDEF \
2585 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2586
2587static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002588os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002589
2590static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002591os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002592{
2593 return os_getppid_impl(module);
2594}
2595
2596#endif /* defined(HAVE_GETPPID) */
2597
2598#if defined(HAVE_GETLOGIN)
2599
2600PyDoc_STRVAR(os_getlogin__doc__,
2601"getlogin($module, /)\n"
2602"--\n"
2603"\n"
2604"Return the actual login name.");
2605
2606#define OS_GETLOGIN_METHODDEF \
2607 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2608
2609static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002610os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002611
2612static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002613os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002614{
2615 return os_getlogin_impl(module);
2616}
2617
2618#endif /* defined(HAVE_GETLOGIN) */
2619
2620#if defined(HAVE_GETUID)
2621
2622PyDoc_STRVAR(os_getuid__doc__,
2623"getuid($module, /)\n"
2624"--\n"
2625"\n"
2626"Return the current process\'s user id.");
2627
2628#define OS_GETUID_METHODDEF \
2629 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2630
2631static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002632os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002633
2634static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002635os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002636{
2637 return os_getuid_impl(module);
2638}
2639
2640#endif /* defined(HAVE_GETUID) */
2641
2642#if defined(HAVE_KILL)
2643
2644PyDoc_STRVAR(os_kill__doc__,
2645"kill($module, pid, signal, /)\n"
2646"--\n"
2647"\n"
2648"Kill a process with a signal.");
2649
2650#define OS_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002651 {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002652
2653static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002654os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002655
2656static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002657os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002658{
2659 PyObject *return_value = NULL;
2660 pid_t pid;
2661 Py_ssize_t signal;
2662
Sylvain74453812017-06-10 06:51:48 +02002663 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2664 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002665 goto exit;
2666 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002667 return_value = os_kill_impl(module, pid, signal);
2668
2669exit:
2670 return return_value;
2671}
2672
2673#endif /* defined(HAVE_KILL) */
2674
2675#if defined(HAVE_KILLPG)
2676
2677PyDoc_STRVAR(os_killpg__doc__,
2678"killpg($module, pgid, signal, /)\n"
2679"--\n"
2680"\n"
2681"Kill a process group with a signal.");
2682
2683#define OS_KILLPG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002684 {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002685
2686static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002687os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002688
2689static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002690os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002691{
2692 PyObject *return_value = NULL;
2693 pid_t pgid;
2694 int signal;
2695
Sylvain74453812017-06-10 06:51:48 +02002696 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2697 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002698 goto exit;
2699 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002700 return_value = os_killpg_impl(module, pgid, signal);
2701
2702exit:
2703 return return_value;
2704}
2705
2706#endif /* defined(HAVE_KILLPG) */
2707
2708#if defined(HAVE_PLOCK)
2709
2710PyDoc_STRVAR(os_plock__doc__,
2711"plock($module, op, /)\n"
2712"--\n"
2713"\n"
2714"Lock program segments into memory.\");");
2715
2716#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002717 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002718
2719static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002720os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002721
2722static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002723os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002724{
2725 PyObject *return_value = NULL;
2726 int op;
2727
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002728 if (!PyArg_Parse(arg, "i:plock", &op)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002729 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002730 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002731 return_value = os_plock_impl(module, op);
2732
2733exit:
2734 return return_value;
2735}
2736
2737#endif /* defined(HAVE_PLOCK) */
2738
2739#if defined(HAVE_SETUID)
2740
2741PyDoc_STRVAR(os_setuid__doc__,
2742"setuid($module, uid, /)\n"
2743"--\n"
2744"\n"
2745"Set the current process\'s user id.");
2746
2747#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002748 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002749
2750static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002751os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002752
2753static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002754os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002755{
2756 PyObject *return_value = NULL;
2757 uid_t uid;
2758
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002759 if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002760 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002761 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002762 return_value = os_setuid_impl(module, uid);
2763
2764exit:
2765 return return_value;
2766}
2767
2768#endif /* defined(HAVE_SETUID) */
2769
2770#if defined(HAVE_SETEUID)
2771
2772PyDoc_STRVAR(os_seteuid__doc__,
2773"seteuid($module, euid, /)\n"
2774"--\n"
2775"\n"
2776"Set the current process\'s effective user id.");
2777
2778#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002779 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002780
2781static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002782os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002783
2784static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002785os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002786{
2787 PyObject *return_value = NULL;
2788 uid_t euid;
2789
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002790 if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002791 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002792 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002793 return_value = os_seteuid_impl(module, euid);
2794
2795exit:
2796 return return_value;
2797}
2798
2799#endif /* defined(HAVE_SETEUID) */
2800
2801#if defined(HAVE_SETEGID)
2802
2803PyDoc_STRVAR(os_setegid__doc__,
2804"setegid($module, egid, /)\n"
2805"--\n"
2806"\n"
2807"Set the current process\'s effective group id.");
2808
2809#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002810 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002811
2812static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002813os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002814
2815static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002816os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002817{
2818 PyObject *return_value = NULL;
2819 gid_t egid;
2820
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002821 if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002822 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002823 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002824 return_value = os_setegid_impl(module, egid);
2825
2826exit:
2827 return return_value;
2828}
2829
2830#endif /* defined(HAVE_SETEGID) */
2831
2832#if defined(HAVE_SETREUID)
2833
2834PyDoc_STRVAR(os_setreuid__doc__,
2835"setreuid($module, ruid, euid, /)\n"
2836"--\n"
2837"\n"
2838"Set the current process\'s real and effective user ids.");
2839
2840#define OS_SETREUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002841 {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002842
2843static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002844os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002845
2846static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002847os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002848{
2849 PyObject *return_value = NULL;
2850 uid_t ruid;
2851 uid_t euid;
2852
Sylvain74453812017-06-10 06:51:48 +02002853 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2854 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002855 goto exit;
2856 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002857 return_value = os_setreuid_impl(module, ruid, euid);
2858
2859exit:
2860 return return_value;
2861}
2862
2863#endif /* defined(HAVE_SETREUID) */
2864
2865#if defined(HAVE_SETREGID)
2866
2867PyDoc_STRVAR(os_setregid__doc__,
2868"setregid($module, rgid, egid, /)\n"
2869"--\n"
2870"\n"
2871"Set the current process\'s real and effective group ids.");
2872
2873#define OS_SETREGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002874 {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002875
2876static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002877os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002878
2879static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002880os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002881{
2882 PyObject *return_value = NULL;
2883 gid_t rgid;
2884 gid_t egid;
2885
Sylvain74453812017-06-10 06:51:48 +02002886 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2887 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002888 goto exit;
2889 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002890 return_value = os_setregid_impl(module, rgid, egid);
2891
2892exit:
2893 return return_value;
2894}
2895
2896#endif /* defined(HAVE_SETREGID) */
2897
2898#if defined(HAVE_SETGID)
2899
2900PyDoc_STRVAR(os_setgid__doc__,
2901"setgid($module, gid, /)\n"
2902"--\n"
2903"\n"
2904"Set the current process\'s group id.");
2905
2906#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002907 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002908
2909static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002910os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002911
2912static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002913os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002914{
2915 PyObject *return_value = NULL;
2916 gid_t gid;
2917
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002918 if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002921 return_value = os_setgid_impl(module, gid);
2922
2923exit:
2924 return return_value;
2925}
2926
2927#endif /* defined(HAVE_SETGID) */
2928
2929#if defined(HAVE_SETGROUPS)
2930
2931PyDoc_STRVAR(os_setgroups__doc__,
2932"setgroups($module, groups, /)\n"
2933"--\n"
2934"\n"
2935"Set the groups of the current process to list.");
2936
2937#define OS_SETGROUPS_METHODDEF \
2938 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2939
2940#endif /* defined(HAVE_SETGROUPS) */
2941
2942#if defined(HAVE_WAIT3)
2943
2944PyDoc_STRVAR(os_wait3__doc__,
2945"wait3($module, /, options)\n"
2946"--\n"
2947"\n"
2948"Wait for completion of a child process.\n"
2949"\n"
2950"Returns a tuple of information about the child process:\n"
2951" (pid, status, rusage)");
2952
2953#define OS_WAIT3_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002954 {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002955
2956static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002957os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002958
2959static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002960os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002961{
2962 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002963 static const char * const _keywords[] = {"options", NULL};
2964 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002965 int options;
2966
Victor Stinner3e1fad62017-01-17 01:29:01 +01002967 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002968 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002969 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002970 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002971 return_value = os_wait3_impl(module, options);
2972
2973exit:
2974 return return_value;
2975}
2976
2977#endif /* defined(HAVE_WAIT3) */
2978
2979#if defined(HAVE_WAIT4)
2980
2981PyDoc_STRVAR(os_wait4__doc__,
2982"wait4($module, /, pid, options)\n"
2983"--\n"
2984"\n"
2985"Wait for completion of a specific child process.\n"
2986"\n"
2987"Returns a tuple of information about the child process:\n"
2988" (pid, status, rusage)");
2989
2990#define OS_WAIT4_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002991 {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002992
2993static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002994os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995
2996static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002997os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002998{
2999 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003000 static const char * const _keywords[] = {"pid", "options", NULL};
3001 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003002 pid_t pid;
3003 int options;
3004
Victor Stinner3e1fad62017-01-17 01:29:01 +01003005 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003006 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003007 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003008 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003009 return_value = os_wait4_impl(module, pid, options);
3010
3011exit:
3012 return return_value;
3013}
3014
3015#endif /* defined(HAVE_WAIT4) */
3016
3017#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3018
3019PyDoc_STRVAR(os_waitid__doc__,
3020"waitid($module, idtype, id, options, /)\n"
3021"--\n"
3022"\n"
3023"Returns the result of waiting for a process or processes.\n"
3024"\n"
3025" idtype\n"
3026" Must be one of be P_PID, P_PGID or P_ALL.\n"
3027" id\n"
3028" The id to wait on.\n"
3029" options\n"
3030" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3031" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3032"\n"
3033"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3034"no children in a waitable state.");
3035
3036#define OS_WAITID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003037 {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003038
3039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003040os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003041
3042static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003043os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003044{
3045 PyObject *return_value = NULL;
3046 idtype_t idtype;
3047 id_t id;
3048 int options;
3049
Sylvain74453812017-06-10 06:51:48 +02003050 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3051 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003052 goto exit;
3053 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003054 return_value = os_waitid_impl(module, idtype, id, options);
3055
3056exit:
3057 return return_value;
3058}
3059
3060#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3061
3062#if defined(HAVE_WAITPID)
3063
3064PyDoc_STRVAR(os_waitpid__doc__,
3065"waitpid($module, pid, options, /)\n"
3066"--\n"
3067"\n"
3068"Wait for completion of a given child process.\n"
3069"\n"
3070"Returns a tuple of information regarding the child process:\n"
3071" (pid, status)\n"
3072"\n"
3073"The options argument is ignored on Windows.");
3074
3075#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003076 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003077
3078static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003079os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003080
3081static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003082os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003083{
3084 PyObject *return_value = NULL;
3085 pid_t pid;
3086 int options;
3087
Sylvain74453812017-06-10 06:51:48 +02003088 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3089 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003090 goto exit;
3091 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003092 return_value = os_waitpid_impl(module, pid, options);
3093
3094exit:
3095 return return_value;
3096}
3097
3098#endif /* defined(HAVE_WAITPID) */
3099
3100#if defined(HAVE_CWAIT)
3101
3102PyDoc_STRVAR(os_waitpid__doc__,
3103"waitpid($module, pid, options, /)\n"
3104"--\n"
3105"\n"
3106"Wait for completion of a given process.\n"
3107"\n"
3108"Returns a tuple of information regarding the process:\n"
3109" (pid, status << 8)\n"
3110"\n"
3111"The options argument is ignored on Windows.");
3112
3113#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003114 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003115
3116static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003117os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003118
3119static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003120os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003121{
3122 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003123 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003124 int options;
3125
Sylvain74453812017-06-10 06:51:48 +02003126 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3127 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003128 goto exit;
3129 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003130 return_value = os_waitpid_impl(module, pid, options);
3131
3132exit:
3133 return return_value;
3134}
3135
3136#endif /* defined(HAVE_CWAIT) */
3137
3138#if defined(HAVE_WAIT)
3139
3140PyDoc_STRVAR(os_wait__doc__,
3141"wait($module, /)\n"
3142"--\n"
3143"\n"
3144"Wait for completion of a child process.\n"
3145"\n"
3146"Returns a tuple of information about the child process:\n"
3147" (pid, status)");
3148
3149#define OS_WAIT_METHODDEF \
3150 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3151
3152static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003153os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003154
3155static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003156os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003157{
3158 return os_wait_impl(module);
3159}
3160
3161#endif /* defined(HAVE_WAIT) */
3162
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003163#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3164
3165PyDoc_STRVAR(os_readlink__doc__,
3166"readlink($module, /, path, *, dir_fd=None)\n"
3167"--\n"
3168"\n"
3169"Return a string representing the path to which the symbolic link points.\n"
3170"\n"
3171"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3172"and path should be relative; path will then be relative to that directory.\n"
3173"\n"
3174"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3175"using it will raise a NotImplementedError.");
3176
3177#define OS_READLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003178 {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003179
3180static PyObject *
3181os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3182
3183static PyObject *
3184os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3185{
3186 PyObject *return_value = NULL;
3187 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3188 static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0};
3189 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3190 int dir_fd = DEFAULT_DIR_FD;
3191
3192 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3193 path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3194 goto exit;
3195 }
3196 return_value = os_readlink_impl(module, &path, dir_fd);
3197
3198exit:
3199 /* Cleanup for path */
3200 path_cleanup(&path);
3201
3202 return return_value;
3203}
3204
3205#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
3206
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003207#if defined(HAVE_SYMLINK)
3208
3209PyDoc_STRVAR(os_symlink__doc__,
3210"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3211"--\n"
3212"\n"
3213"Create a symbolic link pointing to src named dst.\n"
3214"\n"
3215"target_is_directory is required on Windows if the target is to be\n"
3216" interpreted as a directory. (On Windows, symlink requires\n"
3217" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3218" target_is_directory is ignored on non-Windows platforms.\n"
3219"\n"
3220"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3221" and path should be relative; path will then be relative to that directory.\n"
3222"dir_fd may not be implemented on your platform.\n"
3223" If it is unavailable, using it will raise a NotImplementedError.");
3224
3225#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003226 {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003227
3228static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003229os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003230 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003231
3232static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003233os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003234{
3235 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003236 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3237 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003238 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3239 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3240 int target_is_directory = 0;
3241 int dir_fd = DEFAULT_DIR_FD;
3242
Victor Stinner3e1fad62017-01-17 01:29:01 +01003243 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003244 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003245 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003246 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003247 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3248
3249exit:
3250 /* Cleanup for src */
3251 path_cleanup(&src);
3252 /* Cleanup for dst */
3253 path_cleanup(&dst);
3254
3255 return return_value;
3256}
3257
3258#endif /* defined(HAVE_SYMLINK) */
3259
3260#if defined(HAVE_TIMES)
3261
3262PyDoc_STRVAR(os_times__doc__,
3263"times($module, /)\n"
3264"--\n"
3265"\n"
3266"Return a collection containing process timing information.\n"
3267"\n"
3268"The object returned behaves like a named tuple with these fields:\n"
3269" (utime, stime, cutime, cstime, elapsed_time)\n"
3270"All fields are floating point numbers.");
3271
3272#define OS_TIMES_METHODDEF \
3273 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3274
3275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003276os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003277
3278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003279os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003280{
3281 return os_times_impl(module);
3282}
3283
3284#endif /* defined(HAVE_TIMES) */
3285
3286#if defined(HAVE_GETSID)
3287
3288PyDoc_STRVAR(os_getsid__doc__,
3289"getsid($module, pid, /)\n"
3290"--\n"
3291"\n"
3292"Call the system call getsid(pid) and return the result.");
3293
3294#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003295 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003296
3297static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003298os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003299
3300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003301os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003302{
3303 PyObject *return_value = NULL;
3304 pid_t pid;
3305
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003306 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003307 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003308 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003309 return_value = os_getsid_impl(module, pid);
3310
3311exit:
3312 return return_value;
3313}
3314
3315#endif /* defined(HAVE_GETSID) */
3316
3317#if defined(HAVE_SETSID)
3318
3319PyDoc_STRVAR(os_setsid__doc__,
3320"setsid($module, /)\n"
3321"--\n"
3322"\n"
3323"Call the system call setsid().");
3324
3325#define OS_SETSID_METHODDEF \
3326 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3327
3328static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003329os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003330
3331static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003332os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003333{
3334 return os_setsid_impl(module);
3335}
3336
3337#endif /* defined(HAVE_SETSID) */
3338
3339#if defined(HAVE_SETPGID)
3340
3341PyDoc_STRVAR(os_setpgid__doc__,
3342"setpgid($module, pid, pgrp, /)\n"
3343"--\n"
3344"\n"
3345"Call the system call setpgid(pid, pgrp).");
3346
3347#define OS_SETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003348 {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003349
3350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003351os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003352
3353static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003354os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003355{
3356 PyObject *return_value = NULL;
3357 pid_t pid;
3358 pid_t pgrp;
3359
Sylvain74453812017-06-10 06:51:48 +02003360 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3361 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003362 goto exit;
3363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003364 return_value = os_setpgid_impl(module, pid, pgrp);
3365
3366exit:
3367 return return_value;
3368}
3369
3370#endif /* defined(HAVE_SETPGID) */
3371
3372#if defined(HAVE_TCGETPGRP)
3373
3374PyDoc_STRVAR(os_tcgetpgrp__doc__,
3375"tcgetpgrp($module, fd, /)\n"
3376"--\n"
3377"\n"
3378"Return the process group associated with the terminal specified by fd.");
3379
3380#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003381 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003382
3383static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003384os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003385
3386static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003387os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003388{
3389 PyObject *return_value = NULL;
3390 int fd;
3391
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003392 if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003393 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003394 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003395 return_value = os_tcgetpgrp_impl(module, fd);
3396
3397exit:
3398 return return_value;
3399}
3400
3401#endif /* defined(HAVE_TCGETPGRP) */
3402
3403#if defined(HAVE_TCSETPGRP)
3404
3405PyDoc_STRVAR(os_tcsetpgrp__doc__,
3406"tcsetpgrp($module, fd, pgid, /)\n"
3407"--\n"
3408"\n"
3409"Set the process group associated with the terminal specified by fd.");
3410
3411#define OS_TCSETPGRP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003412 {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003413
3414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003415os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003416
3417static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003418os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003419{
3420 PyObject *return_value = NULL;
3421 int fd;
3422 pid_t pgid;
3423
Sylvain74453812017-06-10 06:51:48 +02003424 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3425 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003426 goto exit;
3427 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003428 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3429
3430exit:
3431 return return_value;
3432}
3433
3434#endif /* defined(HAVE_TCSETPGRP) */
3435
3436PyDoc_STRVAR(os_open__doc__,
3437"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3438"--\n"
3439"\n"
3440"Open a file for low level IO. Returns a file descriptor (integer).\n"
3441"\n"
3442"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3443" and path should be relative; path will then be relative to that directory.\n"
3444"dir_fd may not be implemented on your platform.\n"
3445" If it is unavailable, using it will raise a NotImplementedError.");
3446
3447#define OS_OPEN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003448 {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003449
3450static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003451os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003452
3453static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003454os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003455{
3456 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003457 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3458 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003459 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3460 int flags;
3461 int mode = 511;
3462 int dir_fd = DEFAULT_DIR_FD;
3463 int _return_value;
3464
Victor Stinner3e1fad62017-01-17 01:29:01 +01003465 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003466 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003467 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003468 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003469 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003470 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003473 return_value = PyLong_FromLong((long)_return_value);
3474
3475exit:
3476 /* Cleanup for path */
3477 path_cleanup(&path);
3478
3479 return return_value;
3480}
3481
3482PyDoc_STRVAR(os_close__doc__,
3483"close($module, /, fd)\n"
3484"--\n"
3485"\n"
3486"Close a file descriptor.");
3487
3488#define OS_CLOSE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003489 {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003490
3491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003492os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003493
3494static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003495os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003496{
3497 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003498 static const char * const _keywords[] = {"fd", NULL};
3499 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003500 int fd;
3501
Victor Stinner3e1fad62017-01-17 01:29:01 +01003502 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003503 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003504 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003505 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003506 return_value = os_close_impl(module, fd);
3507
3508exit:
3509 return return_value;
3510}
3511
3512PyDoc_STRVAR(os_closerange__doc__,
3513"closerange($module, fd_low, fd_high, /)\n"
3514"--\n"
3515"\n"
3516"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3517
3518#define OS_CLOSERANGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003519 {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003520
3521static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003522os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003523
3524static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003525os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003526{
3527 PyObject *return_value = NULL;
3528 int fd_low;
3529 int fd_high;
3530
Sylvain74453812017-06-10 06:51:48 +02003531 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3532 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003533 goto exit;
3534 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003535 return_value = os_closerange_impl(module, fd_low, fd_high);
3536
3537exit:
3538 return return_value;
3539}
3540
3541PyDoc_STRVAR(os_dup__doc__,
3542"dup($module, fd, /)\n"
3543"--\n"
3544"\n"
3545"Return a duplicate of a file descriptor.");
3546
3547#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003548 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003549
3550static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003551os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003552
3553static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003554os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003555{
3556 PyObject *return_value = NULL;
3557 int fd;
3558 int _return_value;
3559
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003560 if (!PyArg_Parse(arg, "i:dup", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003561 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003562 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003563 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003564 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003565 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003566 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003567 return_value = PyLong_FromLong((long)_return_value);
3568
3569exit:
3570 return return_value;
3571}
3572
3573PyDoc_STRVAR(os_dup2__doc__,
3574"dup2($module, /, fd, fd2, inheritable=True)\n"
3575"--\n"
3576"\n"
3577"Duplicate file descriptor.");
3578
3579#define OS_DUP2_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003580 {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003581
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003582static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003583os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003584
3585static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003586os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003587{
3588 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003589 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3590 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003591 int fd;
3592 int fd2;
3593 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003594 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003595
Victor Stinner3e1fad62017-01-17 01:29:01 +01003596 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003597 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003598 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003599 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003600 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3601 if ((_return_value == -1) && PyErr_Occurred()) {
3602 goto exit;
3603 }
3604 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003605
3606exit:
3607 return return_value;
3608}
3609
3610#if defined(HAVE_LOCKF)
3611
3612PyDoc_STRVAR(os_lockf__doc__,
3613"lockf($module, fd, command, length, /)\n"
3614"--\n"
3615"\n"
3616"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3617"\n"
3618" fd\n"
3619" An open file descriptor.\n"
3620" command\n"
3621" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3622" length\n"
3623" The number of bytes to lock, starting at the current position.");
3624
3625#define OS_LOCKF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003626 {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003627
3628static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003629os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003630
3631static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003632os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003633{
3634 PyObject *return_value = NULL;
3635 int fd;
3636 int command;
3637 Py_off_t length;
3638
Sylvain74453812017-06-10 06:51:48 +02003639 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3640 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003641 goto exit;
3642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003643 return_value = os_lockf_impl(module, fd, command, length);
3644
3645exit:
3646 return return_value;
3647}
3648
3649#endif /* defined(HAVE_LOCKF) */
3650
3651PyDoc_STRVAR(os_lseek__doc__,
3652"lseek($module, fd, position, how, /)\n"
3653"--\n"
3654"\n"
3655"Set the position of a file descriptor. Return the new position.\n"
3656"\n"
3657"Return the new cursor position in number of bytes\n"
3658"relative to the beginning of the file.");
3659
3660#define OS_LSEEK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003661 {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003662
3663static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003664os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003665
3666static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003667os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003668{
3669 PyObject *return_value = NULL;
3670 int fd;
3671 Py_off_t position;
3672 int how;
3673 Py_off_t _return_value;
3674
Sylvain74453812017-06-10 06:51:48 +02003675 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3676 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003677 goto exit;
3678 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003679 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003680 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003681 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003682 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003683 return_value = PyLong_FromPy_off_t(_return_value);
3684
3685exit:
3686 return return_value;
3687}
3688
3689PyDoc_STRVAR(os_read__doc__,
3690"read($module, fd, length, /)\n"
3691"--\n"
3692"\n"
3693"Read from a file descriptor. Returns a bytes object.");
3694
3695#define OS_READ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003696 {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003697
3698static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003699os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003700
3701static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003702os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003703{
3704 PyObject *return_value = NULL;
3705 int fd;
3706 Py_ssize_t length;
3707
Sylvain74453812017-06-10 06:51:48 +02003708 if (!_PyArg_ParseStack(args, nargs, "in:read",
3709 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003710 goto exit;
3711 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003712 return_value = os_read_impl(module, fd, length);
3713
3714exit:
3715 return return_value;
3716}
3717
3718#if defined(HAVE_READV)
3719
3720PyDoc_STRVAR(os_readv__doc__,
3721"readv($module, fd, buffers, /)\n"
3722"--\n"
3723"\n"
3724"Read from a file descriptor fd into an iterable of buffers.\n"
3725"\n"
3726"The buffers should be mutable buffers accepting bytes.\n"
3727"readv will transfer data into each buffer until it is full\n"
3728"and then move on to the next buffer in the sequence to hold\n"
3729"the rest of the data.\n"
3730"\n"
3731"readv returns the total number of bytes read,\n"
3732"which may be less than the total capacity of all the buffers.");
3733
3734#define OS_READV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003735 {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003736
3737static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003738os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003739
3740static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003741os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003742{
3743 PyObject *return_value = NULL;
3744 int fd;
3745 PyObject *buffers;
3746 Py_ssize_t _return_value;
3747
Sylvain74453812017-06-10 06:51:48 +02003748 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3749 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003750 goto exit;
3751 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003752 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003753 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003754 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003755 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003756 return_value = PyLong_FromSsize_t(_return_value);
3757
3758exit:
3759 return return_value;
3760}
3761
3762#endif /* defined(HAVE_READV) */
3763
3764#if defined(HAVE_PREAD)
3765
3766PyDoc_STRVAR(os_pread__doc__,
3767"pread($module, fd, length, offset, /)\n"
3768"--\n"
3769"\n"
3770"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3771"\n"
3772"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3773"the beginning of the file. The file offset remains unchanged.");
3774
3775#define OS_PREAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003776 {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003777
3778static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003779os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003780
3781static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003782os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003783{
3784 PyObject *return_value = NULL;
3785 int fd;
3786 int length;
3787 Py_off_t offset;
3788
Sylvain74453812017-06-10 06:51:48 +02003789 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3790 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003791 goto exit;
3792 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003793 return_value = os_pread_impl(module, fd, length, offset);
3794
3795exit:
3796 return return_value;
3797}
3798
3799#endif /* defined(HAVE_PREAD) */
3800
Pablo Galindo4defba32018-01-27 16:16:37 +00003801#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3802
3803PyDoc_STRVAR(os_preadv__doc__,
3804"preadv($module, fd, buffers, offset, flags=0, /)\n"
3805"--\n"
3806"\n"
3807"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3808"\n"
3809"Combines the functionality of readv() and pread(). As readv(), it will\n"
3810"transfer data into each buffer until it is full and then move on to the next\n"
3811"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3812"specifies the file offset at which the input operation is to be performed. It\n"
3813"will return the total number of bytes read (which can be less than the total\n"
3814"capacity of all the objects).\n"
3815"\n"
3816"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3817"\n"
3818"- RWF_HIPRI\n"
3819"- RWF_NOWAIT\n"
3820"\n"
3821"Using non-zero flags requires Linux 4.6 or newer.");
3822
3823#define OS_PREADV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003824 {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00003825
3826static Py_ssize_t
3827os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3828 int flags);
3829
3830static PyObject *
3831os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3832{
3833 PyObject *return_value = NULL;
3834 int fd;
3835 PyObject *buffers;
3836 Py_off_t offset;
3837 int flags = 0;
3838 Py_ssize_t _return_value;
3839
3840 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3841 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3842 goto exit;
3843 }
3844 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3845 if ((_return_value == -1) && PyErr_Occurred()) {
3846 goto exit;
3847 }
3848 return_value = PyLong_FromSsize_t(_return_value);
3849
3850exit:
3851 return return_value;
3852}
3853
3854#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3855
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003856PyDoc_STRVAR(os_write__doc__,
3857"write($module, fd, data, /)\n"
3858"--\n"
3859"\n"
3860"Write a bytes object to a file descriptor.");
3861
3862#define OS_WRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003863 {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003864
3865static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003866os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003867
3868static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003869os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003870{
3871 PyObject *return_value = NULL;
3872 int fd;
3873 Py_buffer data = {NULL, NULL};
3874 Py_ssize_t _return_value;
3875
Sylvain74453812017-06-10 06:51:48 +02003876 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3877 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003878 goto exit;
3879 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003880 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003881 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003882 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003883 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003884 return_value = PyLong_FromSsize_t(_return_value);
3885
3886exit:
3887 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003888 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003889 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003890 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003891
3892 return return_value;
3893}
3894
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003895#if defined(__APPLE__)
3896
3897PyDoc_STRVAR(os__fcopyfile__doc__,
3898"_fcopyfile($module, infd, outfd, flags, /)\n"
3899"--\n"
3900"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07003901"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003902
3903#define OS__FCOPYFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003904 {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003905
3906static PyObject *
3907os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
3908
3909static PyObject *
3910os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3911{
3912 PyObject *return_value = NULL;
3913 int infd;
3914 int outfd;
3915 int flags;
3916
3917 if (!_PyArg_ParseStack(args, nargs, "iii:_fcopyfile",
3918 &infd, &outfd, &flags)) {
3919 goto exit;
3920 }
3921 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
3922
3923exit:
3924 return return_value;
3925}
3926
3927#endif /* defined(__APPLE__) */
3928
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003929PyDoc_STRVAR(os_fstat__doc__,
3930"fstat($module, /, fd)\n"
3931"--\n"
3932"\n"
3933"Perform a stat system call on the given file descriptor.\n"
3934"\n"
3935"Like stat(), but for an open file descriptor.\n"
3936"Equivalent to os.stat(fd).");
3937
3938#define OS_FSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003939 {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003940
3941static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003942os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003943
3944static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003945os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003946{
3947 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003948 static const char * const _keywords[] = {"fd", NULL};
3949 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003950 int fd;
3951
Victor Stinner3e1fad62017-01-17 01:29:01 +01003952 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003953 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003954 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003955 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003956 return_value = os_fstat_impl(module, fd);
3957
3958exit:
3959 return return_value;
3960}
3961
3962PyDoc_STRVAR(os_isatty__doc__,
3963"isatty($module, fd, /)\n"
3964"--\n"
3965"\n"
3966"Return True if the fd is connected to a terminal.\n"
3967"\n"
3968"Return True if the file descriptor is an open file descriptor\n"
3969"connected to the slave end of a terminal.");
3970
3971#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003972 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003973
3974static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003975os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976
3977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003978os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003979{
3980 PyObject *return_value = NULL;
3981 int fd;
3982 int _return_value;
3983
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003984 if (!PyArg_Parse(arg, "i:isatty", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003985 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003986 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003987 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003988 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003989 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003990 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003991 return_value = PyBool_FromLong((long)_return_value);
3992
3993exit:
3994 return return_value;
3995}
3996
3997#if defined(HAVE_PIPE)
3998
3999PyDoc_STRVAR(os_pipe__doc__,
4000"pipe($module, /)\n"
4001"--\n"
4002"\n"
4003"Create a pipe.\n"
4004"\n"
4005"Returns a tuple of two file descriptors:\n"
4006" (read_fd, write_fd)");
4007
4008#define OS_PIPE_METHODDEF \
4009 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
4010
4011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004012os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004013
4014static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004015os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004016{
4017 return os_pipe_impl(module);
4018}
4019
4020#endif /* defined(HAVE_PIPE) */
4021
4022#if defined(HAVE_PIPE2)
4023
4024PyDoc_STRVAR(os_pipe2__doc__,
4025"pipe2($module, flags, /)\n"
4026"--\n"
4027"\n"
4028"Create a pipe with flags set atomically.\n"
4029"\n"
4030"Returns a tuple of two file descriptors:\n"
4031" (read_fd, write_fd)\n"
4032"\n"
4033"flags can be constructed by ORing together one or more of these values:\n"
4034"O_NONBLOCK, O_CLOEXEC.");
4035
4036#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004037 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004038
4039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004040os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004041
4042static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004043os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004044{
4045 PyObject *return_value = NULL;
4046 int flags;
4047
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004048 if (!PyArg_Parse(arg, "i:pipe2", &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004049 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004050 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004051 return_value = os_pipe2_impl(module, flags);
4052
4053exit:
4054 return return_value;
4055}
4056
4057#endif /* defined(HAVE_PIPE2) */
4058
4059#if defined(HAVE_WRITEV)
4060
4061PyDoc_STRVAR(os_writev__doc__,
4062"writev($module, fd, buffers, /)\n"
4063"--\n"
4064"\n"
4065"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4066"\n"
4067"Returns the total number of bytes written.\n"
4068"buffers must be a sequence of bytes-like objects.");
4069
4070#define OS_WRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004071 {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004072
4073static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004074os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004075
4076static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004077os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004078{
4079 PyObject *return_value = NULL;
4080 int fd;
4081 PyObject *buffers;
4082 Py_ssize_t _return_value;
4083
Sylvain74453812017-06-10 06:51:48 +02004084 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4085 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004086 goto exit;
4087 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004088 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004089 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004090 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004091 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004092 return_value = PyLong_FromSsize_t(_return_value);
4093
4094exit:
4095 return return_value;
4096}
4097
4098#endif /* defined(HAVE_WRITEV) */
4099
4100#if defined(HAVE_PWRITE)
4101
4102PyDoc_STRVAR(os_pwrite__doc__,
4103"pwrite($module, fd, buffer, offset, /)\n"
4104"--\n"
4105"\n"
4106"Write bytes to a file descriptor starting at a particular offset.\n"
4107"\n"
4108"Write buffer to fd, starting at offset bytes from the beginning of\n"
4109"the file. Returns the number of bytes writte. Does not change the\n"
4110"current file offset.");
4111
4112#define OS_PWRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004113 {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004114
4115static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004116os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004117
4118static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004119os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004120{
4121 PyObject *return_value = NULL;
4122 int fd;
4123 Py_buffer buffer = {NULL, NULL};
4124 Py_off_t offset;
4125 Py_ssize_t _return_value;
4126
Sylvain74453812017-06-10 06:51:48 +02004127 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4128 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004129 goto exit;
4130 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004131 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004132 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004133 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004134 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004135 return_value = PyLong_FromSsize_t(_return_value);
4136
4137exit:
4138 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004139 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004140 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004141 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004142
4143 return return_value;
4144}
4145
4146#endif /* defined(HAVE_PWRITE) */
4147
Pablo Galindo4defba32018-01-27 16:16:37 +00004148#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4149
4150PyDoc_STRVAR(os_pwritev__doc__,
4151"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4152"--\n"
4153"\n"
4154"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4155"\n"
4156"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4157"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4158"buffer is written before proceeding to second, and so on. The operating system may\n"
4159"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4160"This function writes the contents of each object to the file descriptor and returns\n"
4161"the total number of bytes written.\n"
4162"\n"
4163"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4164"\n"
4165"- RWF_DSYNC\n"
4166"- RWF_SYNC\n"
4167"\n"
4168"Using non-zero flags requires Linux 4.7 or newer.");
4169
4170#define OS_PWRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004171 {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004172
4173static Py_ssize_t
4174os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4175 int flags);
4176
4177static PyObject *
4178os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4179{
4180 PyObject *return_value = NULL;
4181 int fd;
4182 PyObject *buffers;
4183 Py_off_t offset;
4184 int flags = 0;
4185 Py_ssize_t _return_value;
4186
4187 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4188 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4189 goto exit;
4190 }
4191 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4192 if ((_return_value == -1) && PyErr_Occurred()) {
4193 goto exit;
4194 }
4195 return_value = PyLong_FromSsize_t(_return_value);
4196
4197exit:
4198 return return_value;
4199}
4200
4201#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4202
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004203#if defined(HAVE_MKFIFO)
4204
4205PyDoc_STRVAR(os_mkfifo__doc__,
4206"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4207"--\n"
4208"\n"
4209"Create a \"fifo\" (a POSIX named pipe).\n"
4210"\n"
4211"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4212" and path should be relative; path will then be relative to that directory.\n"
4213"dir_fd may not be implemented on your platform.\n"
4214" If it is unavailable, using it will raise a NotImplementedError.");
4215
4216#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004217 {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004218
4219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004220os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004221
4222static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004223os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004224{
4225 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004226 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4227 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004228 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4229 int mode = 438;
4230 int dir_fd = DEFAULT_DIR_FD;
4231
Victor Stinner3e1fad62017-01-17 01:29:01 +01004232 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004233 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004234 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004235 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004236 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4237
4238exit:
4239 /* Cleanup for path */
4240 path_cleanup(&path);
4241
4242 return return_value;
4243}
4244
4245#endif /* defined(HAVE_MKFIFO) */
4246
4247#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4248
4249PyDoc_STRVAR(os_mknod__doc__,
4250"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4251"--\n"
4252"\n"
4253"Create a node in the file system.\n"
4254"\n"
4255"Create a node in the file system (file, device special file or named pipe)\n"
4256"at path. mode specifies both the permissions to use and the\n"
4257"type of node to be created, being combined (bitwise OR) with one of\n"
4258"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4259"device defines the newly created device special file (probably using\n"
4260"os.makedev()). Otherwise device is ignored.\n"
4261"\n"
4262"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4263" and path should be relative; path will then be relative to that directory.\n"
4264"dir_fd may not be implemented on your platform.\n"
4265" If it is unavailable, using it will raise a NotImplementedError.");
4266
4267#define OS_MKNOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004268 {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004269
4270static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004271os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004272 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004273
4274static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004275os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004276{
4277 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004278 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4279 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004280 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4281 int mode = 384;
4282 dev_t device = 0;
4283 int dir_fd = DEFAULT_DIR_FD;
4284
Victor Stinner3e1fad62017-01-17 01:29:01 +01004285 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004286 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004287 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004288 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004289 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4290
4291exit:
4292 /* Cleanup for path */
4293 path_cleanup(&path);
4294
4295 return return_value;
4296}
4297
4298#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4299
4300#if defined(HAVE_DEVICE_MACROS)
4301
4302PyDoc_STRVAR(os_major__doc__,
4303"major($module, device, /)\n"
4304"--\n"
4305"\n"
4306"Extracts a device major number from a raw device number.");
4307
4308#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004309 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004310
4311static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004312os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004313
4314static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004315os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004316{
4317 PyObject *return_value = NULL;
4318 dev_t device;
4319 unsigned int _return_value;
4320
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004321 if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004322 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004323 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004324 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004325 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004326 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004327 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004328 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4329
4330exit:
4331 return return_value;
4332}
4333
4334#endif /* defined(HAVE_DEVICE_MACROS) */
4335
4336#if defined(HAVE_DEVICE_MACROS)
4337
4338PyDoc_STRVAR(os_minor__doc__,
4339"minor($module, device, /)\n"
4340"--\n"
4341"\n"
4342"Extracts a device minor number from a raw device number.");
4343
4344#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004345 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004346
4347static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004348os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004349
4350static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004351os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004352{
4353 PyObject *return_value = NULL;
4354 dev_t device;
4355 unsigned int _return_value;
4356
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004357 if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004358 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004359 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004360 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004361 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4365
4366exit:
4367 return return_value;
4368}
4369
4370#endif /* defined(HAVE_DEVICE_MACROS) */
4371
4372#if defined(HAVE_DEVICE_MACROS)
4373
4374PyDoc_STRVAR(os_makedev__doc__,
4375"makedev($module, major, minor, /)\n"
4376"--\n"
4377"\n"
4378"Composes a raw device number from the major and minor device numbers.");
4379
4380#define OS_MAKEDEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004381 {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004382
4383static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004384os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004385
4386static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004387os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004388{
4389 PyObject *return_value = NULL;
4390 int major;
4391 int minor;
4392 dev_t _return_value;
4393
Sylvain74453812017-06-10 06:51:48 +02004394 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4395 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004396 goto exit;
4397 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004398 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004399 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004400 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004401 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004402 return_value = _PyLong_FromDev(_return_value);
4403
4404exit:
4405 return return_value;
4406}
4407
4408#endif /* defined(HAVE_DEVICE_MACROS) */
4409
Steve Dowerf7377032015-04-12 15:44:54 -04004410#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004411
4412PyDoc_STRVAR(os_ftruncate__doc__,
4413"ftruncate($module, fd, length, /)\n"
4414"--\n"
4415"\n"
4416"Truncate a file, specified by file descriptor, to a specific length.");
4417
4418#define OS_FTRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004419 {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004420
4421static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004422os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004423
4424static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004425os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004426{
4427 PyObject *return_value = NULL;
4428 int fd;
4429 Py_off_t length;
4430
Sylvain74453812017-06-10 06:51:48 +02004431 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4432 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004433 goto exit;
4434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004435 return_value = os_ftruncate_impl(module, fd, length);
4436
4437exit:
4438 return return_value;
4439}
4440
Steve Dowerf7377032015-04-12 15:44:54 -04004441#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004442
Steve Dowerf7377032015-04-12 15:44:54 -04004443#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004444
4445PyDoc_STRVAR(os_truncate__doc__,
4446"truncate($module, /, path, length)\n"
4447"--\n"
4448"\n"
4449"Truncate a file, specified by path, to a specific length.\n"
4450"\n"
4451"On some platforms, path may also be specified as an open file descriptor.\n"
4452" If this functionality is unavailable, using it raises an exception.");
4453
4454#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004455 {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004456
4457static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004458os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004459
4460static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004461os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004462{
4463 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004464 static const char * const _keywords[] = {"path", "length", NULL};
4465 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004466 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4467 Py_off_t length;
4468
Victor Stinner3e1fad62017-01-17 01:29:01 +01004469 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004470 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004473 return_value = os_truncate_impl(module, &path, length);
4474
4475exit:
4476 /* Cleanup for path */
4477 path_cleanup(&path);
4478
4479 return return_value;
4480}
4481
Steve Dowerf7377032015-04-12 15:44:54 -04004482#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004483
4484#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4485
4486PyDoc_STRVAR(os_posix_fallocate__doc__,
4487"posix_fallocate($module, fd, offset, length, /)\n"
4488"--\n"
4489"\n"
4490"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4491"\n"
4492"Ensure that the file specified by fd encompasses a range of bytes\n"
4493"starting at offset bytes from the beginning and continuing for length bytes.");
4494
4495#define OS_POSIX_FALLOCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004496 {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004497
4498static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004499os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004500 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004501
4502static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004503os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004504{
4505 PyObject *return_value = NULL;
4506 int fd;
4507 Py_off_t offset;
4508 Py_off_t length;
4509
Sylvain74453812017-06-10 06:51:48 +02004510 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4511 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004512 goto exit;
4513 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004514 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4515
4516exit:
4517 return return_value;
4518}
4519
4520#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4521
4522#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4523
4524PyDoc_STRVAR(os_posix_fadvise__doc__,
4525"posix_fadvise($module, fd, offset, length, advice, /)\n"
4526"--\n"
4527"\n"
4528"Announce an intention to access data in a specific pattern.\n"
4529"\n"
4530"Announce an intention to access data in a specific pattern, thus allowing\n"
4531"the kernel to make optimizations.\n"
4532"The advice applies to the region of the file specified by fd starting at\n"
4533"offset and continuing for length bytes.\n"
4534"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4535"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4536"POSIX_FADV_DONTNEED.");
4537
4538#define OS_POSIX_FADVISE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004539 {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004540
4541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004542os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004543 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004544
4545static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004546os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004547{
4548 PyObject *return_value = NULL;
4549 int fd;
4550 Py_off_t offset;
4551 Py_off_t length;
4552 int advice;
4553
Sylvain74453812017-06-10 06:51:48 +02004554 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4555 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004556 goto exit;
4557 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004558 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4559
4560exit:
4561 return return_value;
4562}
4563
4564#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4565
4566#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4567
4568PyDoc_STRVAR(os_putenv__doc__,
4569"putenv($module, name, value, /)\n"
4570"--\n"
4571"\n"
4572"Change or add an environment variable.");
4573
4574#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004575 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004576
4577static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004578os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004579
4580static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004581os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004582{
4583 PyObject *return_value = NULL;
4584 PyObject *name;
4585 PyObject *value;
4586
Sylvain74453812017-06-10 06:51:48 +02004587 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4588 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004589 goto exit;
4590 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004591 return_value = os_putenv_impl(module, name, value);
4592
4593exit:
4594 return return_value;
4595}
4596
4597#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4598
4599#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4600
4601PyDoc_STRVAR(os_putenv__doc__,
4602"putenv($module, name, value, /)\n"
4603"--\n"
4604"\n"
4605"Change or add an environment variable.");
4606
4607#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004608 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004609
4610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004611os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004612
4613static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004614os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004615{
4616 PyObject *return_value = NULL;
4617 PyObject *name = NULL;
4618 PyObject *value = NULL;
4619
Sylvain74453812017-06-10 06:51:48 +02004620 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4621 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004622 goto exit;
4623 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004624 return_value = os_putenv_impl(module, name, value);
4625
4626exit:
4627 /* Cleanup for name */
4628 Py_XDECREF(name);
4629 /* Cleanup for value */
4630 Py_XDECREF(value);
4631
4632 return return_value;
4633}
4634
4635#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4636
4637#if defined(HAVE_UNSETENV)
4638
4639PyDoc_STRVAR(os_unsetenv__doc__,
4640"unsetenv($module, name, /)\n"
4641"--\n"
4642"\n"
4643"Delete an environment variable.");
4644
4645#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004646 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004647
4648static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004649os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004650
4651static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004652os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004653{
4654 PyObject *return_value = NULL;
4655 PyObject *name = NULL;
4656
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004657 if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004658 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004659 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004660 return_value = os_unsetenv_impl(module, name);
4661
4662exit:
4663 /* Cleanup for name */
4664 Py_XDECREF(name);
4665
4666 return return_value;
4667}
4668
4669#endif /* defined(HAVE_UNSETENV) */
4670
4671PyDoc_STRVAR(os_strerror__doc__,
4672"strerror($module, code, /)\n"
4673"--\n"
4674"\n"
4675"Translate an error code to a message string.");
4676
4677#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004678 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004679
4680static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004681os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004682
4683static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004684os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004685{
4686 PyObject *return_value = NULL;
4687 int code;
4688
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004689 if (!PyArg_Parse(arg, "i:strerror", &code)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004690 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004691 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004692 return_value = os_strerror_impl(module, code);
4693
4694exit:
4695 return return_value;
4696}
4697
4698#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4699
4700PyDoc_STRVAR(os_WCOREDUMP__doc__,
4701"WCOREDUMP($module, status, /)\n"
4702"--\n"
4703"\n"
4704"Return True if the process returning status was dumped to a core file.");
4705
4706#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004707 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708
4709static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004710os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004711
4712static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004713os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004714{
4715 PyObject *return_value = NULL;
4716 int status;
4717 int _return_value;
4718
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004719 if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004720 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004721 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004722 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004723 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004724 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004725 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004726 return_value = PyBool_FromLong((long)_return_value);
4727
4728exit:
4729 return return_value;
4730}
4731
4732#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4733
4734#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4735
4736PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4737"WIFCONTINUED($module, /, status)\n"
4738"--\n"
4739"\n"
4740"Return True if a particular process was continued from a job control stop.\n"
4741"\n"
4742"Return True if the process returning status was continued from a\n"
4743"job control stop.");
4744
4745#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004746 {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004747
4748static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004749os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004750
4751static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004752os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004753{
4754 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004755 static const char * const _keywords[] = {"status", NULL};
4756 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004757 int status;
4758 int _return_value;
4759
Victor Stinner3e1fad62017-01-17 01:29:01 +01004760 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004761 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004762 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004763 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004764 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004765 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004766 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004767 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004768 return_value = PyBool_FromLong((long)_return_value);
4769
4770exit:
4771 return return_value;
4772}
4773
4774#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4775
4776#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4777
4778PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4779"WIFSTOPPED($module, /, status)\n"
4780"--\n"
4781"\n"
4782"Return True if the process returning status was stopped.");
4783
4784#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004785 {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004786
4787static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004788os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004789
4790static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004791os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004792{
4793 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004794 static const char * const _keywords[] = {"status", NULL};
4795 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004796 int status;
4797 int _return_value;
4798
Victor Stinner3e1fad62017-01-17 01:29:01 +01004799 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004800 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004802 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004803 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004804 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004805 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004806 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004807 return_value = PyBool_FromLong((long)_return_value);
4808
4809exit:
4810 return return_value;
4811}
4812
4813#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4814
4815#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4816
4817PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4818"WIFSIGNALED($module, /, status)\n"
4819"--\n"
4820"\n"
4821"Return True if the process returning status was terminated by a signal.");
4822
4823#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004824 {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004825
4826static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004827os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004828
4829static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004830os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004831{
4832 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004833 static const char * const _keywords[] = {"status", NULL};
4834 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004835 int status;
4836 int _return_value;
4837
Victor Stinner3e1fad62017-01-17 01:29:01 +01004838 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004839 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004841 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004842 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004843 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004844 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004845 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004846 return_value = PyBool_FromLong((long)_return_value);
4847
4848exit:
4849 return return_value;
4850}
4851
4852#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4853
4854#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4855
4856PyDoc_STRVAR(os_WIFEXITED__doc__,
4857"WIFEXITED($module, /, status)\n"
4858"--\n"
4859"\n"
4860"Return True if the process returning status exited via the exit() system call.");
4861
4862#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004863 {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004864
4865static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004866os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004867
4868static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004869os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004870{
4871 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004872 static const char * const _keywords[] = {"status", NULL};
4873 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004874 int status;
4875 int _return_value;
4876
Victor Stinner3e1fad62017-01-17 01:29:01 +01004877 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004878 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004879 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004880 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004881 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004882 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004883 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004884 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004885 return_value = PyBool_FromLong((long)_return_value);
4886
4887exit:
4888 return return_value;
4889}
4890
4891#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4892
4893#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4894
4895PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4896"WEXITSTATUS($module, /, status)\n"
4897"--\n"
4898"\n"
4899"Return the process return code from status.");
4900
4901#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004902 {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004903
4904static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004905os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004906
4907static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004908os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004909{
4910 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004911 static const char * const _keywords[] = {"status", NULL};
4912 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004913 int status;
4914 int _return_value;
4915
Victor Stinner3e1fad62017-01-17 01:29:01 +01004916 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004917 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004918 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004919 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004920 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004921 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004922 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004923 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004924 return_value = PyLong_FromLong((long)_return_value);
4925
4926exit:
4927 return return_value;
4928}
4929
4930#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4931
4932#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4933
4934PyDoc_STRVAR(os_WTERMSIG__doc__,
4935"WTERMSIG($module, /, status)\n"
4936"--\n"
4937"\n"
4938"Return the signal that terminated the process that provided the status value.");
4939
4940#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004941 {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004942
4943static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004944os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004945
4946static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004947os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004948{
4949 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004950 static const char * const _keywords[] = {"status", NULL};
4951 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004952 int status;
4953 int _return_value;
4954
Victor Stinner3e1fad62017-01-17 01:29:01 +01004955 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004956 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004957 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004958 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004959 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004960 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004961 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004962 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004963 return_value = PyLong_FromLong((long)_return_value);
4964
4965exit:
4966 return return_value;
4967}
4968
4969#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
4970
4971#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
4972
4973PyDoc_STRVAR(os_WSTOPSIG__doc__,
4974"WSTOPSIG($module, /, status)\n"
4975"--\n"
4976"\n"
4977"Return the signal that stopped the process that provided the status value.");
4978
4979#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004980 {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004981
4982static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004983os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984
4985static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004986os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004987{
4988 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004989 static const char * const _keywords[] = {"status", NULL};
4990 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004991 int status;
4992 int _return_value;
4993
Victor Stinner3e1fad62017-01-17 01:29:01 +01004994 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004995 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004996 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004997 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004998 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004999 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005000 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005001 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005002 return_value = PyLong_FromLong((long)_return_value);
5003
5004exit:
5005 return return_value;
5006}
5007
5008#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
5009
5010#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
5011
5012PyDoc_STRVAR(os_fstatvfs__doc__,
5013"fstatvfs($module, fd, /)\n"
5014"--\n"
5015"\n"
5016"Perform an fstatvfs system call on the given fd.\n"
5017"\n"
5018"Equivalent to statvfs(fd).");
5019
5020#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005021 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005022
5023static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005024os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005025
5026static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005027os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005028{
5029 PyObject *return_value = NULL;
5030 int fd;
5031
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005032 if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005033 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005034 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005035 return_value = os_fstatvfs_impl(module, fd);
5036
5037exit:
5038 return return_value;
5039}
5040
5041#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5042
5043#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5044
5045PyDoc_STRVAR(os_statvfs__doc__,
5046"statvfs($module, /, path)\n"
5047"--\n"
5048"\n"
5049"Perform a statvfs system call on the given path.\n"
5050"\n"
5051"path may always be specified as a string.\n"
5052"On some platforms, path may also be specified as an open file descriptor.\n"
5053" If this functionality is unavailable, using it raises an exception.");
5054
5055#define OS_STATVFS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005056 {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005057
5058static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005059os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060
5061static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005062os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005063{
5064 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005065 static const char * const _keywords[] = {"path", NULL};
5066 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005067 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5068
Victor Stinner3e1fad62017-01-17 01:29:01 +01005069 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005070 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005071 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005072 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005073 return_value = os_statvfs_impl(module, &path);
5074
5075exit:
5076 /* Cleanup for path */
5077 path_cleanup(&path);
5078
5079 return return_value;
5080}
5081
5082#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5083
5084#if defined(MS_WINDOWS)
5085
5086PyDoc_STRVAR(os__getdiskusage__doc__,
5087"_getdiskusage($module, /, path)\n"
5088"--\n"
5089"\n"
5090"Return disk usage statistics about the given path as a (total, free) tuple.");
5091
5092#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005093 {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005094
5095static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005096os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005097
5098static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005099os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005100{
5101 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005102 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005103 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5104 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005105
Victor Stinner3e1fad62017-01-17 01:29:01 +01005106 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005107 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005109 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005110 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005111
5112exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005113 /* Cleanup for path */
5114 path_cleanup(&path);
5115
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005116 return return_value;
5117}
5118
5119#endif /* defined(MS_WINDOWS) */
5120
5121#if defined(HAVE_FPATHCONF)
5122
5123PyDoc_STRVAR(os_fpathconf__doc__,
5124"fpathconf($module, fd, name, /)\n"
5125"--\n"
5126"\n"
5127"Return the configuration limit name for the file descriptor fd.\n"
5128"\n"
5129"If there is no limit, return -1.");
5130
5131#define OS_FPATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005132 {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005133
5134static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005135os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005136
5137static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005138os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005139{
5140 PyObject *return_value = NULL;
5141 int fd;
5142 int name;
5143 long _return_value;
5144
Sylvain74453812017-06-10 06:51:48 +02005145 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5146 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005147 goto exit;
5148 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005149 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005150 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005151 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005152 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005153 return_value = PyLong_FromLong(_return_value);
5154
5155exit:
5156 return return_value;
5157}
5158
5159#endif /* defined(HAVE_FPATHCONF) */
5160
5161#if defined(HAVE_PATHCONF)
5162
5163PyDoc_STRVAR(os_pathconf__doc__,
5164"pathconf($module, /, path, name)\n"
5165"--\n"
5166"\n"
5167"Return the configuration limit name for the file or directory path.\n"
5168"\n"
5169"If there is no limit, return -1.\n"
5170"On some platforms, path may also be specified as an open file descriptor.\n"
5171" If this functionality is unavailable, using it raises an exception.");
5172
5173#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005174 {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175
5176static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005177os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005178
5179static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005180os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005181{
5182 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005183 static const char * const _keywords[] = {"path", "name", NULL};
5184 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005185 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5186 int name;
5187 long _return_value;
5188
Victor Stinner3e1fad62017-01-17 01:29:01 +01005189 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005190 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005191 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005193 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005194 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005195 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005196 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005197 return_value = PyLong_FromLong(_return_value);
5198
5199exit:
5200 /* Cleanup for path */
5201 path_cleanup(&path);
5202
5203 return return_value;
5204}
5205
5206#endif /* defined(HAVE_PATHCONF) */
5207
5208#if defined(HAVE_CONFSTR)
5209
5210PyDoc_STRVAR(os_confstr__doc__,
5211"confstr($module, name, /)\n"
5212"--\n"
5213"\n"
5214"Return a string-valued system configuration variable.");
5215
5216#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005217 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005218
5219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005220os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005221
5222static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005223os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005224{
5225 PyObject *return_value = NULL;
5226 int name;
5227
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005228 if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005229 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005230 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005231 return_value = os_confstr_impl(module, name);
5232
5233exit:
5234 return return_value;
5235}
5236
5237#endif /* defined(HAVE_CONFSTR) */
5238
5239#if defined(HAVE_SYSCONF)
5240
5241PyDoc_STRVAR(os_sysconf__doc__,
5242"sysconf($module, name, /)\n"
5243"--\n"
5244"\n"
5245"Return an integer-valued system configuration variable.");
5246
5247#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005248 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005249
5250static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005251os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005252
5253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005254os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005255{
5256 PyObject *return_value = NULL;
5257 int name;
5258 long _return_value;
5259
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005260 if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005261 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005262 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005263 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005264 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005265 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005266 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005267 return_value = PyLong_FromLong(_return_value);
5268
5269exit:
5270 return return_value;
5271}
5272
5273#endif /* defined(HAVE_SYSCONF) */
5274
5275PyDoc_STRVAR(os_abort__doc__,
5276"abort($module, /)\n"
5277"--\n"
5278"\n"
5279"Abort the interpreter immediately.\n"
5280"\n"
5281"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5282"on the hosting operating system. This function never returns.");
5283
5284#define OS_ABORT_METHODDEF \
5285 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5286
5287static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005288os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005289
5290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005291os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005292{
5293 return os_abort_impl(module);
5294}
5295
Steve Dowercc16be82016-09-08 10:35:16 -07005296#if defined(MS_WINDOWS)
5297
5298PyDoc_STRVAR(os_startfile__doc__,
5299"startfile($module, /, filepath, operation=None)\n"
5300"--\n"
5301"\n"
5302"startfile(filepath [, operation])\n"
5303"\n"
5304"Start a file with its associated application.\n"
5305"\n"
5306"When \"operation\" is not specified or \"open\", this acts like\n"
5307"double-clicking the file in Explorer, or giving the file name as an\n"
5308"argument to the DOS \"start\" command: the file is opened with whatever\n"
5309"application (if any) its extension is associated.\n"
5310"When another \"operation\" is given, it specifies what should be done with\n"
5311"the file. A typical operation is \"print\".\n"
5312"\n"
5313"startfile returns as soon as the associated application is launched.\n"
5314"There is no option to wait for the application to close, and no way\n"
5315"to retrieve the application\'s exit status.\n"
5316"\n"
5317"The filepath is relative to the current directory. If you want to use\n"
5318"an absolute path, make sure the first character is not a slash (\"/\");\n"
5319"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5320
5321#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005322 {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005323
5324static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005325os_startfile_impl(PyObject *module, path_t *filepath,
5326 const Py_UNICODE *operation);
Steve Dowercc16be82016-09-08 10:35:16 -07005327
5328static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005329os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005330{
5331 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005332 static const char * const _keywords[] = {"filepath", "operation", NULL};
5333 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005334 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005335 const Py_UNICODE *operation = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07005336
Victor Stinner3e1fad62017-01-17 01:29:01 +01005337 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005338 path_converter, &filepath, &operation)) {
5339 goto exit;
5340 }
5341 return_value = os_startfile_impl(module, &filepath, operation);
5342
5343exit:
5344 /* Cleanup for filepath */
5345 path_cleanup(&filepath);
5346
5347 return return_value;
5348}
5349
5350#endif /* defined(MS_WINDOWS) */
5351
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005352#if defined(HAVE_GETLOADAVG)
5353
5354PyDoc_STRVAR(os_getloadavg__doc__,
5355"getloadavg($module, /)\n"
5356"--\n"
5357"\n"
5358"Return average recent system load information.\n"
5359"\n"
5360"Return the number of processes in the system run queue averaged over\n"
5361"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5362"Raises OSError if the load average was unobtainable.");
5363
5364#define OS_GETLOADAVG_METHODDEF \
5365 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5366
5367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005368os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005369
5370static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005371os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005372{
5373 return os_getloadavg_impl(module);
5374}
5375
5376#endif /* defined(HAVE_GETLOADAVG) */
5377
5378PyDoc_STRVAR(os_device_encoding__doc__,
5379"device_encoding($module, /, fd)\n"
5380"--\n"
5381"\n"
5382"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5383"\n"
5384"The file descriptor must be attached to a terminal.\n"
5385"If the device is not a terminal, return None.");
5386
5387#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005388 {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005389
5390static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005391os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005392
5393static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005394os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005395{
5396 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005397 static const char * const _keywords[] = {"fd", NULL};
5398 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005399 int fd;
5400
Victor Stinner3e1fad62017-01-17 01:29:01 +01005401 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005402 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005405 return_value = os_device_encoding_impl(module, fd);
5406
5407exit:
5408 return return_value;
5409}
5410
5411#if defined(HAVE_SETRESUID)
5412
5413PyDoc_STRVAR(os_setresuid__doc__,
5414"setresuid($module, ruid, euid, suid, /)\n"
5415"--\n"
5416"\n"
5417"Set the current process\'s real, effective, and saved user ids.");
5418
5419#define OS_SETRESUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005420 {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005421
5422static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005423os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005424
5425static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005426os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005427{
5428 PyObject *return_value = NULL;
5429 uid_t ruid;
5430 uid_t euid;
5431 uid_t suid;
5432
Sylvain74453812017-06-10 06:51:48 +02005433 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5434 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005435 goto exit;
5436 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005437 return_value = os_setresuid_impl(module, ruid, euid, suid);
5438
5439exit:
5440 return return_value;
5441}
5442
5443#endif /* defined(HAVE_SETRESUID) */
5444
5445#if defined(HAVE_SETRESGID)
5446
5447PyDoc_STRVAR(os_setresgid__doc__,
5448"setresgid($module, rgid, egid, sgid, /)\n"
5449"--\n"
5450"\n"
5451"Set the current process\'s real, effective, and saved group ids.");
5452
5453#define OS_SETRESGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005454 {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005455
5456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005457os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005458
5459static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005460os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005461{
5462 PyObject *return_value = NULL;
5463 gid_t rgid;
5464 gid_t egid;
5465 gid_t sgid;
5466
Sylvain74453812017-06-10 06:51:48 +02005467 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5468 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005469 goto exit;
5470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005471 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5472
5473exit:
5474 return return_value;
5475}
5476
5477#endif /* defined(HAVE_SETRESGID) */
5478
5479#if defined(HAVE_GETRESUID)
5480
5481PyDoc_STRVAR(os_getresuid__doc__,
5482"getresuid($module, /)\n"
5483"--\n"
5484"\n"
5485"Return a tuple of the current process\'s real, effective, and saved user ids.");
5486
5487#define OS_GETRESUID_METHODDEF \
5488 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5489
5490static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005491os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005492
5493static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005494os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005495{
5496 return os_getresuid_impl(module);
5497}
5498
5499#endif /* defined(HAVE_GETRESUID) */
5500
5501#if defined(HAVE_GETRESGID)
5502
5503PyDoc_STRVAR(os_getresgid__doc__,
5504"getresgid($module, /)\n"
5505"--\n"
5506"\n"
5507"Return a tuple of the current process\'s real, effective, and saved group ids.");
5508
5509#define OS_GETRESGID_METHODDEF \
5510 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5511
5512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005513os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005514
5515static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005516os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005517{
5518 return os_getresgid_impl(module);
5519}
5520
5521#endif /* defined(HAVE_GETRESGID) */
5522
5523#if defined(USE_XATTRS)
5524
5525PyDoc_STRVAR(os_getxattr__doc__,
5526"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5527"--\n"
5528"\n"
5529"Return the value of extended attribute attribute on path.\n"
5530"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005531"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005532"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5533" link, getxattr will examine the symbolic link itself instead of the file\n"
5534" the link points to.");
5535
5536#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005537 {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005538
5539static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005540os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005541 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005542
5543static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005544os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005545{
5546 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005547 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5548 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005549 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5550 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5551 int follow_symlinks = 1;
5552
Victor Stinner3e1fad62017-01-17 01:29:01 +01005553 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005554 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005555 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005556 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005557 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5558
5559exit:
5560 /* Cleanup for path */
5561 path_cleanup(&path);
5562 /* Cleanup for attribute */
5563 path_cleanup(&attribute);
5564
5565 return return_value;
5566}
5567
5568#endif /* defined(USE_XATTRS) */
5569
5570#if defined(USE_XATTRS)
5571
5572PyDoc_STRVAR(os_setxattr__doc__,
5573"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5574" follow_symlinks=True)\n"
5575"--\n"
5576"\n"
5577"Set extended attribute attribute on path to value.\n"
5578"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005579"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005580"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5581" link, setxattr will modify the symbolic link itself instead of the file\n"
5582" the link points to.");
5583
5584#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005585 {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005586
5587static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005588os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005589 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005590
5591static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005592os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005593{
5594 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005595 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5596 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005597 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5598 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5599 Py_buffer value = {NULL, NULL};
5600 int flags = 0;
5601 int follow_symlinks = 1;
5602
Victor Stinner3e1fad62017-01-17 01:29:01 +01005603 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005604 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005605 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005606 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005607 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5608
5609exit:
5610 /* Cleanup for path */
5611 path_cleanup(&path);
5612 /* Cleanup for attribute */
5613 path_cleanup(&attribute);
5614 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005615 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005616 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005617 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005618
5619 return return_value;
5620}
5621
5622#endif /* defined(USE_XATTRS) */
5623
5624#if defined(USE_XATTRS)
5625
5626PyDoc_STRVAR(os_removexattr__doc__,
5627"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5628"--\n"
5629"\n"
5630"Remove extended attribute attribute on path.\n"
5631"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005632"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005633"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5634" link, removexattr will modify the symbolic link itself instead of the file\n"
5635" the link points to.");
5636
5637#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005638 {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005639
5640static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005641os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005642 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005643
5644static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005645os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005646{
5647 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005648 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5649 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005650 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5651 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5652 int follow_symlinks = 1;
5653
Victor Stinner3e1fad62017-01-17 01:29:01 +01005654 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005655 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005656 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005657 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005658 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5659
5660exit:
5661 /* Cleanup for path */
5662 path_cleanup(&path);
5663 /* Cleanup for attribute */
5664 path_cleanup(&attribute);
5665
5666 return return_value;
5667}
5668
5669#endif /* defined(USE_XATTRS) */
5670
5671#if defined(USE_XATTRS)
5672
5673PyDoc_STRVAR(os_listxattr__doc__,
5674"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5675"--\n"
5676"\n"
5677"Return a list of extended attributes on path.\n"
5678"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005679"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005680"if path is None, listxattr will examine the current directory.\n"
5681"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5682" link, listxattr will examine the symbolic link itself instead of the file\n"
5683" the link points to.");
5684
5685#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005686 {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005687
5688static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005689os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005690
5691static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005692os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005693{
5694 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005695 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5696 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005697 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5698 int follow_symlinks = 1;
5699
Victor Stinner3e1fad62017-01-17 01:29:01 +01005700 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005701 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005703 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005704 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5705
5706exit:
5707 /* Cleanup for path */
5708 path_cleanup(&path);
5709
5710 return return_value;
5711}
5712
5713#endif /* defined(USE_XATTRS) */
5714
5715PyDoc_STRVAR(os_urandom__doc__,
5716"urandom($module, size, /)\n"
5717"--\n"
5718"\n"
5719"Return a bytes object containing random bytes suitable for cryptographic use.");
5720
5721#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005722 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005723
5724static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005725os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005726
5727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005728os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005729{
5730 PyObject *return_value = NULL;
5731 Py_ssize_t size;
5732
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005733 if (!PyArg_Parse(arg, "n:urandom", &size)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005734 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005735 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005736 return_value = os_urandom_impl(module, size);
5737
5738exit:
5739 return return_value;
5740}
5741
5742PyDoc_STRVAR(os_cpu_count__doc__,
5743"cpu_count($module, /)\n"
5744"--\n"
5745"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005746"Return the number of CPUs in the system; return None if indeterminable.\n"
5747"\n"
5748"This number is not equivalent to the number of CPUs the current process can\n"
5749"use. The number of usable CPUs can be obtained with\n"
5750"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005751
5752#define OS_CPU_COUNT_METHODDEF \
5753 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5754
5755static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005756os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005757
5758static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005759os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005760{
5761 return os_cpu_count_impl(module);
5762}
5763
5764PyDoc_STRVAR(os_get_inheritable__doc__,
5765"get_inheritable($module, fd, /)\n"
5766"--\n"
5767"\n"
5768"Get the close-on-exe flag of the specified file descriptor.");
5769
5770#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005771 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005772
5773static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005774os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005775
5776static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005777os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005778{
5779 PyObject *return_value = NULL;
5780 int fd;
5781 int _return_value;
5782
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005783 if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005784 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005785 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005786 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005787 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005788 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005789 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005790 return_value = PyBool_FromLong((long)_return_value);
5791
5792exit:
5793 return return_value;
5794}
5795
5796PyDoc_STRVAR(os_set_inheritable__doc__,
5797"set_inheritable($module, fd, inheritable, /)\n"
5798"--\n"
5799"\n"
5800"Set the inheritable flag of the specified file descriptor.");
5801
5802#define OS_SET_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005803 {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005804
5805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005806os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005807
5808static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005809os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005810{
5811 PyObject *return_value = NULL;
5812 int fd;
5813 int inheritable;
5814
Sylvain74453812017-06-10 06:51:48 +02005815 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5816 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005817 goto exit;
5818 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005819 return_value = os_set_inheritable_impl(module, fd, inheritable);
5820
5821exit:
5822 return return_value;
5823}
5824
5825#if defined(MS_WINDOWS)
5826
5827PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5828"get_handle_inheritable($module, handle, /)\n"
5829"--\n"
5830"\n"
5831"Get the close-on-exe flag of the specified file descriptor.");
5832
5833#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005834 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005835
5836static int
Victor Stinner581139c2016-09-06 15:54:20 -07005837os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005838
5839static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005840os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005841{
5842 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005843 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005844 int _return_value;
5845
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005846 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005847 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005848 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005849 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005850 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005851 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005852 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005853 return_value = PyBool_FromLong((long)_return_value);
5854
5855exit:
5856 return return_value;
5857}
5858
5859#endif /* defined(MS_WINDOWS) */
5860
5861#if defined(MS_WINDOWS)
5862
5863PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5864"set_handle_inheritable($module, handle, inheritable, /)\n"
5865"--\n"
5866"\n"
5867"Set the inheritable flag of the specified handle.");
5868
5869#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005870 {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005871
5872static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005873os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005874 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005875
5876static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005877os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005878{
5879 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005880 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005881 int inheritable;
5882
Sylvain74453812017-06-10 06:51:48 +02005883 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5884 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005885 goto exit;
5886 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005887 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5888
5889exit:
5890 return return_value;
5891}
5892
5893#endif /* defined(MS_WINDOWS) */
5894
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03005895#if !defined(MS_WINDOWS)
5896
5897PyDoc_STRVAR(os_get_blocking__doc__,
5898"get_blocking($module, fd, /)\n"
5899"--\n"
5900"\n"
5901"Get the blocking mode of the file descriptor.\n"
5902"\n"
5903"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
5904
5905#define OS_GET_BLOCKING_METHODDEF \
5906 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
5907
5908static int
5909os_get_blocking_impl(PyObject *module, int fd);
5910
5911static PyObject *
5912os_get_blocking(PyObject *module, PyObject *arg)
5913{
5914 PyObject *return_value = NULL;
5915 int fd;
5916 int _return_value;
5917
5918 if (!PyArg_Parse(arg, "i:get_blocking", &fd)) {
5919 goto exit;
5920 }
5921 _return_value = os_get_blocking_impl(module, fd);
5922 if ((_return_value == -1) && PyErr_Occurred()) {
5923 goto exit;
5924 }
5925 return_value = PyBool_FromLong((long)_return_value);
5926
5927exit:
5928 return return_value;
5929}
5930
5931#endif /* !defined(MS_WINDOWS) */
5932
5933#if !defined(MS_WINDOWS)
5934
5935PyDoc_STRVAR(os_set_blocking__doc__,
5936"set_blocking($module, fd, blocking, /)\n"
5937"--\n"
5938"\n"
5939"Set the blocking mode of the specified file descriptor.\n"
5940"\n"
5941"Set the O_NONBLOCK flag if blocking is False,\n"
5942"clear the O_NONBLOCK flag otherwise.");
5943
5944#define OS_SET_BLOCKING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005945 {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03005946
5947static PyObject *
5948os_set_blocking_impl(PyObject *module, int fd, int blocking);
5949
5950static PyObject *
5951os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5952{
5953 PyObject *return_value = NULL;
5954 int fd;
5955 int blocking;
5956
5957 if (!_PyArg_ParseStack(args, nargs, "ii:set_blocking",
5958 &fd, &blocking)) {
5959 goto exit;
5960 }
5961 return_value = os_set_blocking_impl(module, fd, blocking);
5962
5963exit:
5964 return return_value;
5965}
5966
5967#endif /* !defined(MS_WINDOWS) */
5968
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02005969PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
5970"is_symlink($self, /)\n"
5971"--\n"
5972"\n"
5973"Return True if the entry is a symbolic link; cached per entry.");
5974
5975#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
5976 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
5977
5978static int
5979os_DirEntry_is_symlink_impl(DirEntry *self);
5980
5981static PyObject *
5982os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
5983{
5984 PyObject *return_value = NULL;
5985 int _return_value;
5986
5987 _return_value = os_DirEntry_is_symlink_impl(self);
5988 if ((_return_value == -1) && PyErr_Occurred()) {
5989 goto exit;
5990 }
5991 return_value = PyBool_FromLong((long)_return_value);
5992
5993exit:
5994 return return_value;
5995}
5996
5997PyDoc_STRVAR(os_DirEntry_stat__doc__,
5998"stat($self, /, *, follow_symlinks=True)\n"
5999"--\n"
6000"\n"
6001"Return stat_result object for the entry; cached per entry.");
6002
6003#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006004 {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006005
6006static PyObject *
6007os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
6008
6009static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006010os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006011{
6012 PyObject *return_value = NULL;
6013 static const char * const _keywords[] = {"follow_symlinks", NULL};
6014 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
6015 int follow_symlinks = 1;
6016
Victor Stinner3e1fad62017-01-17 01:29:01 +01006017 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006018 &follow_symlinks)) {
6019 goto exit;
6020 }
6021 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
6022
6023exit:
6024 return return_value;
6025}
6026
6027PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
6028"is_dir($self, /, *, follow_symlinks=True)\n"
6029"--\n"
6030"\n"
6031"Return True if the entry is a directory; cached per entry.");
6032
6033#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006034 {"is_dir", (PyCFunction)(void(*)(void))os_DirEntry_is_dir, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006035
6036static int
6037os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
6038
6039static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006040os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006041{
6042 PyObject *return_value = NULL;
6043 static const char * const _keywords[] = {"follow_symlinks", NULL};
6044 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
6045 int follow_symlinks = 1;
6046 int _return_value;
6047
Victor Stinner3e1fad62017-01-17 01:29:01 +01006048 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006049 &follow_symlinks)) {
6050 goto exit;
6051 }
6052 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
6053 if ((_return_value == -1) && PyErr_Occurred()) {
6054 goto exit;
6055 }
6056 return_value = PyBool_FromLong((long)_return_value);
6057
6058exit:
6059 return return_value;
6060}
6061
6062PyDoc_STRVAR(os_DirEntry_is_file__doc__,
6063"is_file($self, /, *, follow_symlinks=True)\n"
6064"--\n"
6065"\n"
6066"Return True if the entry is a file; cached per entry.");
6067
6068#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006069 {"is_file", (PyCFunction)(void(*)(void))os_DirEntry_is_file, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006070
6071static int
6072os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
6073
6074static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006075os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006076{
6077 PyObject *return_value = NULL;
6078 static const char * const _keywords[] = {"follow_symlinks", NULL};
6079 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
6080 int follow_symlinks = 1;
6081 int _return_value;
6082
Victor Stinner3e1fad62017-01-17 01:29:01 +01006083 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006084 &follow_symlinks)) {
6085 goto exit;
6086 }
6087 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
6088 if ((_return_value == -1) && PyErr_Occurred()) {
6089 goto exit;
6090 }
6091 return_value = PyBool_FromLong((long)_return_value);
6092
6093exit:
6094 return return_value;
6095}
6096
6097PyDoc_STRVAR(os_DirEntry_inode__doc__,
6098"inode($self, /)\n"
6099"--\n"
6100"\n"
6101"Return inode of the entry; cached per entry.");
6102
6103#define OS_DIRENTRY_INODE_METHODDEF \
6104 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6105
6106static PyObject *
6107os_DirEntry_inode_impl(DirEntry *self);
6108
6109static PyObject *
6110os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6111{
6112 return os_DirEntry_inode_impl(self);
6113}
6114
6115PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6116"__fspath__($self, /)\n"
6117"--\n"
6118"\n"
6119"Returns the path for the entry.");
6120
6121#define OS_DIRENTRY___FSPATH___METHODDEF \
6122 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6123
6124static PyObject *
6125os_DirEntry___fspath___impl(DirEntry *self);
6126
6127static PyObject *
6128os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6129{
6130 return os_DirEntry___fspath___impl(self);
6131}
6132
6133PyDoc_STRVAR(os_scandir__doc__,
6134"scandir($module, /, path=None)\n"
6135"--\n"
6136"\n"
6137"Return an iterator of DirEntry objects for given path.\n"
6138"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006139"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006140"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6141"all other circumstances they will be str.\n"
6142"\n"
6143"If path is None, uses the path=\'.\'.");
6144
6145#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006146 {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006147
6148static PyObject *
6149os_scandir_impl(PyObject *module, path_t *path);
6150
6151static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006152os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006153{
6154 PyObject *return_value = NULL;
6155 static const char * const _keywords[] = {"path", NULL};
6156 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006157 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006158
Victor Stinner3e1fad62017-01-17 01:29:01 +01006159 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006160 path_converter, &path)) {
6161 goto exit;
6162 }
6163 return_value = os_scandir_impl(module, &path);
6164
6165exit:
6166 /* Cleanup for path */
6167 path_cleanup(&path);
6168
6169 return return_value;
6170}
6171
Ethan Furman410ef8e2016-06-04 12:06:26 -07006172PyDoc_STRVAR(os_fspath__doc__,
6173"fspath($module, /, path)\n"
6174"--\n"
6175"\n"
6176"Return the file system path representation of the object.\n"
6177"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006178"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6179"object defines __fspath__(), then return the result of that method. All other\n"
6180"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006181
6182#define OS_FSPATH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006183 {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006184
6185static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006186os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006187
6188static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006189os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006190{
6191 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006192 static const char * const _keywords[] = {"path", NULL};
6193 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006194 PyObject *path;
6195
Victor Stinner3e1fad62017-01-17 01:29:01 +01006196 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006197 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006198 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006199 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006200 return_value = os_fspath_impl(module, path);
6201
6202exit:
6203 return return_value;
6204}
6205
Victor Stinner9b1f4742016-09-06 16:18:52 -07006206#if defined(HAVE_GETRANDOM_SYSCALL)
6207
6208PyDoc_STRVAR(os_getrandom__doc__,
6209"getrandom($module, /, size, flags=0)\n"
6210"--\n"
6211"\n"
6212"Obtain a series of random bytes.");
6213
6214#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006215 {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006216
6217static PyObject *
6218os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6219
6220static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006221os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006222{
6223 PyObject *return_value = NULL;
6224 static const char * const _keywords[] = {"size", "flags", NULL};
6225 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6226 Py_ssize_t size;
6227 int flags = 0;
6228
Victor Stinner3e1fad62017-01-17 01:29:01 +01006229 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006230 &size, &flags)) {
6231 goto exit;
6232 }
6233 return_value = os_getrandom_impl(module, size, flags);
6234
6235exit:
6236 return return_value;
6237}
6238
6239#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6240
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006241#ifndef OS_TTYNAME_METHODDEF
6242 #define OS_TTYNAME_METHODDEF
6243#endif /* !defined(OS_TTYNAME_METHODDEF) */
6244
6245#ifndef OS_CTERMID_METHODDEF
6246 #define OS_CTERMID_METHODDEF
6247#endif /* !defined(OS_CTERMID_METHODDEF) */
6248
6249#ifndef OS_FCHDIR_METHODDEF
6250 #define OS_FCHDIR_METHODDEF
6251#endif /* !defined(OS_FCHDIR_METHODDEF) */
6252
6253#ifndef OS_FCHMOD_METHODDEF
6254 #define OS_FCHMOD_METHODDEF
6255#endif /* !defined(OS_FCHMOD_METHODDEF) */
6256
6257#ifndef OS_LCHMOD_METHODDEF
6258 #define OS_LCHMOD_METHODDEF
6259#endif /* !defined(OS_LCHMOD_METHODDEF) */
6260
6261#ifndef OS_CHFLAGS_METHODDEF
6262 #define OS_CHFLAGS_METHODDEF
6263#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6264
6265#ifndef OS_LCHFLAGS_METHODDEF
6266 #define OS_LCHFLAGS_METHODDEF
6267#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6268
6269#ifndef OS_CHROOT_METHODDEF
6270 #define OS_CHROOT_METHODDEF
6271#endif /* !defined(OS_CHROOT_METHODDEF) */
6272
6273#ifndef OS_FSYNC_METHODDEF
6274 #define OS_FSYNC_METHODDEF
6275#endif /* !defined(OS_FSYNC_METHODDEF) */
6276
6277#ifndef OS_SYNC_METHODDEF
6278 #define OS_SYNC_METHODDEF
6279#endif /* !defined(OS_SYNC_METHODDEF) */
6280
6281#ifndef OS_FDATASYNC_METHODDEF
6282 #define OS_FDATASYNC_METHODDEF
6283#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6284
6285#ifndef OS_CHOWN_METHODDEF
6286 #define OS_CHOWN_METHODDEF
6287#endif /* !defined(OS_CHOWN_METHODDEF) */
6288
6289#ifndef OS_FCHOWN_METHODDEF
6290 #define OS_FCHOWN_METHODDEF
6291#endif /* !defined(OS_FCHOWN_METHODDEF) */
6292
6293#ifndef OS_LCHOWN_METHODDEF
6294 #define OS_LCHOWN_METHODDEF
6295#endif /* !defined(OS_LCHOWN_METHODDEF) */
6296
6297#ifndef OS_LINK_METHODDEF
6298 #define OS_LINK_METHODDEF
6299#endif /* !defined(OS_LINK_METHODDEF) */
6300
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006301#ifndef OS__GETFULLPATHNAME_METHODDEF
6302 #define OS__GETFULLPATHNAME_METHODDEF
6303#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6304
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006305#ifndef OS__GETFINALPATHNAME_METHODDEF
6306 #define OS__GETFINALPATHNAME_METHODDEF
6307#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6308
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006309#ifndef OS__ISDIR_METHODDEF
6310 #define OS__ISDIR_METHODDEF
6311#endif /* !defined(OS__ISDIR_METHODDEF) */
6312
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006313#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6314 #define OS__GETVOLUMEPATHNAME_METHODDEF
6315#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6316
6317#ifndef OS_NICE_METHODDEF
6318 #define OS_NICE_METHODDEF
6319#endif /* !defined(OS_NICE_METHODDEF) */
6320
6321#ifndef OS_GETPRIORITY_METHODDEF
6322 #define OS_GETPRIORITY_METHODDEF
6323#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6324
6325#ifndef OS_SETPRIORITY_METHODDEF
6326 #define OS_SETPRIORITY_METHODDEF
6327#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6328
6329#ifndef OS_SYSTEM_METHODDEF
6330 #define OS_SYSTEM_METHODDEF
6331#endif /* !defined(OS_SYSTEM_METHODDEF) */
6332
6333#ifndef OS_UNAME_METHODDEF
6334 #define OS_UNAME_METHODDEF
6335#endif /* !defined(OS_UNAME_METHODDEF) */
6336
6337#ifndef OS_EXECV_METHODDEF
6338 #define OS_EXECV_METHODDEF
6339#endif /* !defined(OS_EXECV_METHODDEF) */
6340
6341#ifndef OS_EXECVE_METHODDEF
6342 #define OS_EXECVE_METHODDEF
6343#endif /* !defined(OS_EXECVE_METHODDEF) */
6344
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006345#ifndef OS_POSIX_SPAWN_METHODDEF
6346 #define OS_POSIX_SPAWN_METHODDEF
6347#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6348
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006349#ifndef OS_SPAWNV_METHODDEF
6350 #define OS_SPAWNV_METHODDEF
6351#endif /* !defined(OS_SPAWNV_METHODDEF) */
6352
6353#ifndef OS_SPAWNVE_METHODDEF
6354 #define OS_SPAWNVE_METHODDEF
6355#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6356
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006357#ifndef OS_REGISTER_AT_FORK_METHODDEF
6358 #define OS_REGISTER_AT_FORK_METHODDEF
6359#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6360
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006361#ifndef OS_FORK1_METHODDEF
6362 #define OS_FORK1_METHODDEF
6363#endif /* !defined(OS_FORK1_METHODDEF) */
6364
6365#ifndef OS_FORK_METHODDEF
6366 #define OS_FORK_METHODDEF
6367#endif /* !defined(OS_FORK_METHODDEF) */
6368
6369#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6370 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6371#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6372
6373#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6374 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6375#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6376
6377#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6378 #define OS_SCHED_GETSCHEDULER_METHODDEF
6379#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6380
6381#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6382 #define OS_SCHED_SETSCHEDULER_METHODDEF
6383#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6384
6385#ifndef OS_SCHED_GETPARAM_METHODDEF
6386 #define OS_SCHED_GETPARAM_METHODDEF
6387#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6388
6389#ifndef OS_SCHED_SETPARAM_METHODDEF
6390 #define OS_SCHED_SETPARAM_METHODDEF
6391#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6392
6393#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6394 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6395#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6396
6397#ifndef OS_SCHED_YIELD_METHODDEF
6398 #define OS_SCHED_YIELD_METHODDEF
6399#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6400
6401#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6402 #define OS_SCHED_SETAFFINITY_METHODDEF
6403#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6404
6405#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6406 #define OS_SCHED_GETAFFINITY_METHODDEF
6407#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6408
6409#ifndef OS_OPENPTY_METHODDEF
6410 #define OS_OPENPTY_METHODDEF
6411#endif /* !defined(OS_OPENPTY_METHODDEF) */
6412
6413#ifndef OS_FORKPTY_METHODDEF
6414 #define OS_FORKPTY_METHODDEF
6415#endif /* !defined(OS_FORKPTY_METHODDEF) */
6416
6417#ifndef OS_GETEGID_METHODDEF
6418 #define OS_GETEGID_METHODDEF
6419#endif /* !defined(OS_GETEGID_METHODDEF) */
6420
6421#ifndef OS_GETEUID_METHODDEF
6422 #define OS_GETEUID_METHODDEF
6423#endif /* !defined(OS_GETEUID_METHODDEF) */
6424
6425#ifndef OS_GETGID_METHODDEF
6426 #define OS_GETGID_METHODDEF
6427#endif /* !defined(OS_GETGID_METHODDEF) */
6428
Berker Peksag39404992016-09-15 20:45:16 +03006429#ifndef OS_GETPID_METHODDEF
6430 #define OS_GETPID_METHODDEF
6431#endif /* !defined(OS_GETPID_METHODDEF) */
6432
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006433#ifndef OS_GETGROUPS_METHODDEF
6434 #define OS_GETGROUPS_METHODDEF
6435#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6436
6437#ifndef OS_GETPGID_METHODDEF
6438 #define OS_GETPGID_METHODDEF
6439#endif /* !defined(OS_GETPGID_METHODDEF) */
6440
6441#ifndef OS_GETPGRP_METHODDEF
6442 #define OS_GETPGRP_METHODDEF
6443#endif /* !defined(OS_GETPGRP_METHODDEF) */
6444
6445#ifndef OS_SETPGRP_METHODDEF
6446 #define OS_SETPGRP_METHODDEF
6447#endif /* !defined(OS_SETPGRP_METHODDEF) */
6448
6449#ifndef OS_GETPPID_METHODDEF
6450 #define OS_GETPPID_METHODDEF
6451#endif /* !defined(OS_GETPPID_METHODDEF) */
6452
6453#ifndef OS_GETLOGIN_METHODDEF
6454 #define OS_GETLOGIN_METHODDEF
6455#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6456
6457#ifndef OS_GETUID_METHODDEF
6458 #define OS_GETUID_METHODDEF
6459#endif /* !defined(OS_GETUID_METHODDEF) */
6460
6461#ifndef OS_KILL_METHODDEF
6462 #define OS_KILL_METHODDEF
6463#endif /* !defined(OS_KILL_METHODDEF) */
6464
6465#ifndef OS_KILLPG_METHODDEF
6466 #define OS_KILLPG_METHODDEF
6467#endif /* !defined(OS_KILLPG_METHODDEF) */
6468
6469#ifndef OS_PLOCK_METHODDEF
6470 #define OS_PLOCK_METHODDEF
6471#endif /* !defined(OS_PLOCK_METHODDEF) */
6472
6473#ifndef OS_SETUID_METHODDEF
6474 #define OS_SETUID_METHODDEF
6475#endif /* !defined(OS_SETUID_METHODDEF) */
6476
6477#ifndef OS_SETEUID_METHODDEF
6478 #define OS_SETEUID_METHODDEF
6479#endif /* !defined(OS_SETEUID_METHODDEF) */
6480
6481#ifndef OS_SETEGID_METHODDEF
6482 #define OS_SETEGID_METHODDEF
6483#endif /* !defined(OS_SETEGID_METHODDEF) */
6484
6485#ifndef OS_SETREUID_METHODDEF
6486 #define OS_SETREUID_METHODDEF
6487#endif /* !defined(OS_SETREUID_METHODDEF) */
6488
6489#ifndef OS_SETREGID_METHODDEF
6490 #define OS_SETREGID_METHODDEF
6491#endif /* !defined(OS_SETREGID_METHODDEF) */
6492
6493#ifndef OS_SETGID_METHODDEF
6494 #define OS_SETGID_METHODDEF
6495#endif /* !defined(OS_SETGID_METHODDEF) */
6496
6497#ifndef OS_SETGROUPS_METHODDEF
6498 #define OS_SETGROUPS_METHODDEF
6499#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6500
6501#ifndef OS_WAIT3_METHODDEF
6502 #define OS_WAIT3_METHODDEF
6503#endif /* !defined(OS_WAIT3_METHODDEF) */
6504
6505#ifndef OS_WAIT4_METHODDEF
6506 #define OS_WAIT4_METHODDEF
6507#endif /* !defined(OS_WAIT4_METHODDEF) */
6508
6509#ifndef OS_WAITID_METHODDEF
6510 #define OS_WAITID_METHODDEF
6511#endif /* !defined(OS_WAITID_METHODDEF) */
6512
6513#ifndef OS_WAITPID_METHODDEF
6514 #define OS_WAITPID_METHODDEF
6515#endif /* !defined(OS_WAITPID_METHODDEF) */
6516
6517#ifndef OS_WAIT_METHODDEF
6518 #define OS_WAIT_METHODDEF
6519#endif /* !defined(OS_WAIT_METHODDEF) */
6520
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006521#ifndef OS_READLINK_METHODDEF
6522 #define OS_READLINK_METHODDEF
6523#endif /* !defined(OS_READLINK_METHODDEF) */
6524
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006525#ifndef OS_SYMLINK_METHODDEF
6526 #define OS_SYMLINK_METHODDEF
6527#endif /* !defined(OS_SYMLINK_METHODDEF) */
6528
6529#ifndef OS_TIMES_METHODDEF
6530 #define OS_TIMES_METHODDEF
6531#endif /* !defined(OS_TIMES_METHODDEF) */
6532
6533#ifndef OS_GETSID_METHODDEF
6534 #define OS_GETSID_METHODDEF
6535#endif /* !defined(OS_GETSID_METHODDEF) */
6536
6537#ifndef OS_SETSID_METHODDEF
6538 #define OS_SETSID_METHODDEF
6539#endif /* !defined(OS_SETSID_METHODDEF) */
6540
6541#ifndef OS_SETPGID_METHODDEF
6542 #define OS_SETPGID_METHODDEF
6543#endif /* !defined(OS_SETPGID_METHODDEF) */
6544
6545#ifndef OS_TCGETPGRP_METHODDEF
6546 #define OS_TCGETPGRP_METHODDEF
6547#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6548
6549#ifndef OS_TCSETPGRP_METHODDEF
6550 #define OS_TCSETPGRP_METHODDEF
6551#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6552
6553#ifndef OS_LOCKF_METHODDEF
6554 #define OS_LOCKF_METHODDEF
6555#endif /* !defined(OS_LOCKF_METHODDEF) */
6556
6557#ifndef OS_READV_METHODDEF
6558 #define OS_READV_METHODDEF
6559#endif /* !defined(OS_READV_METHODDEF) */
6560
6561#ifndef OS_PREAD_METHODDEF
6562 #define OS_PREAD_METHODDEF
6563#endif /* !defined(OS_PREAD_METHODDEF) */
6564
Pablo Galindo4defba32018-01-27 16:16:37 +00006565#ifndef OS_PREADV_METHODDEF
6566 #define OS_PREADV_METHODDEF
6567#endif /* !defined(OS_PREADV_METHODDEF) */
6568
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02006569#ifndef OS__FCOPYFILE_METHODDEF
6570 #define OS__FCOPYFILE_METHODDEF
6571#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
6572
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006573#ifndef OS_PIPE_METHODDEF
6574 #define OS_PIPE_METHODDEF
6575#endif /* !defined(OS_PIPE_METHODDEF) */
6576
6577#ifndef OS_PIPE2_METHODDEF
6578 #define OS_PIPE2_METHODDEF
6579#endif /* !defined(OS_PIPE2_METHODDEF) */
6580
6581#ifndef OS_WRITEV_METHODDEF
6582 #define OS_WRITEV_METHODDEF
6583#endif /* !defined(OS_WRITEV_METHODDEF) */
6584
6585#ifndef OS_PWRITE_METHODDEF
6586 #define OS_PWRITE_METHODDEF
6587#endif /* !defined(OS_PWRITE_METHODDEF) */
6588
Pablo Galindo4defba32018-01-27 16:16:37 +00006589#ifndef OS_PWRITEV_METHODDEF
6590 #define OS_PWRITEV_METHODDEF
6591#endif /* !defined(OS_PWRITEV_METHODDEF) */
6592
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006593#ifndef OS_MKFIFO_METHODDEF
6594 #define OS_MKFIFO_METHODDEF
6595#endif /* !defined(OS_MKFIFO_METHODDEF) */
6596
6597#ifndef OS_MKNOD_METHODDEF
6598 #define OS_MKNOD_METHODDEF
6599#endif /* !defined(OS_MKNOD_METHODDEF) */
6600
6601#ifndef OS_MAJOR_METHODDEF
6602 #define OS_MAJOR_METHODDEF
6603#endif /* !defined(OS_MAJOR_METHODDEF) */
6604
6605#ifndef OS_MINOR_METHODDEF
6606 #define OS_MINOR_METHODDEF
6607#endif /* !defined(OS_MINOR_METHODDEF) */
6608
6609#ifndef OS_MAKEDEV_METHODDEF
6610 #define OS_MAKEDEV_METHODDEF
6611#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6612
6613#ifndef OS_FTRUNCATE_METHODDEF
6614 #define OS_FTRUNCATE_METHODDEF
6615#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6616
6617#ifndef OS_TRUNCATE_METHODDEF
6618 #define OS_TRUNCATE_METHODDEF
6619#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6620
6621#ifndef OS_POSIX_FALLOCATE_METHODDEF
6622 #define OS_POSIX_FALLOCATE_METHODDEF
6623#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6624
6625#ifndef OS_POSIX_FADVISE_METHODDEF
6626 #define OS_POSIX_FADVISE_METHODDEF
6627#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6628
6629#ifndef OS_PUTENV_METHODDEF
6630 #define OS_PUTENV_METHODDEF
6631#endif /* !defined(OS_PUTENV_METHODDEF) */
6632
6633#ifndef OS_UNSETENV_METHODDEF
6634 #define OS_UNSETENV_METHODDEF
6635#endif /* !defined(OS_UNSETENV_METHODDEF) */
6636
6637#ifndef OS_WCOREDUMP_METHODDEF
6638 #define OS_WCOREDUMP_METHODDEF
6639#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6640
6641#ifndef OS_WIFCONTINUED_METHODDEF
6642 #define OS_WIFCONTINUED_METHODDEF
6643#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6644
6645#ifndef OS_WIFSTOPPED_METHODDEF
6646 #define OS_WIFSTOPPED_METHODDEF
6647#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6648
6649#ifndef OS_WIFSIGNALED_METHODDEF
6650 #define OS_WIFSIGNALED_METHODDEF
6651#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6652
6653#ifndef OS_WIFEXITED_METHODDEF
6654 #define OS_WIFEXITED_METHODDEF
6655#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6656
6657#ifndef OS_WEXITSTATUS_METHODDEF
6658 #define OS_WEXITSTATUS_METHODDEF
6659#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6660
6661#ifndef OS_WTERMSIG_METHODDEF
6662 #define OS_WTERMSIG_METHODDEF
6663#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6664
6665#ifndef OS_WSTOPSIG_METHODDEF
6666 #define OS_WSTOPSIG_METHODDEF
6667#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6668
6669#ifndef OS_FSTATVFS_METHODDEF
6670 #define OS_FSTATVFS_METHODDEF
6671#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6672
6673#ifndef OS_STATVFS_METHODDEF
6674 #define OS_STATVFS_METHODDEF
6675#endif /* !defined(OS_STATVFS_METHODDEF) */
6676
6677#ifndef OS__GETDISKUSAGE_METHODDEF
6678 #define OS__GETDISKUSAGE_METHODDEF
6679#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6680
6681#ifndef OS_FPATHCONF_METHODDEF
6682 #define OS_FPATHCONF_METHODDEF
6683#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6684
6685#ifndef OS_PATHCONF_METHODDEF
6686 #define OS_PATHCONF_METHODDEF
6687#endif /* !defined(OS_PATHCONF_METHODDEF) */
6688
6689#ifndef OS_CONFSTR_METHODDEF
6690 #define OS_CONFSTR_METHODDEF
6691#endif /* !defined(OS_CONFSTR_METHODDEF) */
6692
6693#ifndef OS_SYSCONF_METHODDEF
6694 #define OS_SYSCONF_METHODDEF
6695#endif /* !defined(OS_SYSCONF_METHODDEF) */
6696
Steve Dowercc16be82016-09-08 10:35:16 -07006697#ifndef OS_STARTFILE_METHODDEF
6698 #define OS_STARTFILE_METHODDEF
6699#endif /* !defined(OS_STARTFILE_METHODDEF) */
6700
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006701#ifndef OS_GETLOADAVG_METHODDEF
6702 #define OS_GETLOADAVG_METHODDEF
6703#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6704
6705#ifndef OS_SETRESUID_METHODDEF
6706 #define OS_SETRESUID_METHODDEF
6707#endif /* !defined(OS_SETRESUID_METHODDEF) */
6708
6709#ifndef OS_SETRESGID_METHODDEF
6710 #define OS_SETRESGID_METHODDEF
6711#endif /* !defined(OS_SETRESGID_METHODDEF) */
6712
6713#ifndef OS_GETRESUID_METHODDEF
6714 #define OS_GETRESUID_METHODDEF
6715#endif /* !defined(OS_GETRESUID_METHODDEF) */
6716
6717#ifndef OS_GETRESGID_METHODDEF
6718 #define OS_GETRESGID_METHODDEF
6719#endif /* !defined(OS_GETRESGID_METHODDEF) */
6720
6721#ifndef OS_GETXATTR_METHODDEF
6722 #define OS_GETXATTR_METHODDEF
6723#endif /* !defined(OS_GETXATTR_METHODDEF) */
6724
6725#ifndef OS_SETXATTR_METHODDEF
6726 #define OS_SETXATTR_METHODDEF
6727#endif /* !defined(OS_SETXATTR_METHODDEF) */
6728
6729#ifndef OS_REMOVEXATTR_METHODDEF
6730 #define OS_REMOVEXATTR_METHODDEF
6731#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6732
6733#ifndef OS_LISTXATTR_METHODDEF
6734 #define OS_LISTXATTR_METHODDEF
6735#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6736
6737#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6738 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6739#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6740
6741#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6742 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6743#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006744
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006745#ifndef OS_GET_BLOCKING_METHODDEF
6746 #define OS_GET_BLOCKING_METHODDEF
6747#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
6748
6749#ifndef OS_SET_BLOCKING_METHODDEF
6750 #define OS_SET_BLOCKING_METHODDEF
6751#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
6752
Victor Stinner9b1f4742016-09-06 16:18:52 -07006753#ifndef OS_GETRANDOM_METHODDEF
6754 #define OS_GETRANDOM_METHODDEF
6755#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Serhiy Storchaka4db62e12018-12-17 16:47:45 +02006756/*[clinic end generated code: output=87a3ebadb91bc46b input=a9049054013a1b77]*/