blob: d47618ce25c0c0a51b5cdadf384806d8b51c3f1a [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 Storchaka32d96a22018-12-25 13:23:47 +0200188 if (PyFloat_Check(arg)) {
189 PyErr_SetString(PyExc_TypeError,
190 "integer argument expected, got float" );
191 goto exit;
192 }
193 fd = _PyLong_AsInt(arg);
194 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300195 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300196 }
Serhiy Storchaka4db62e12018-12-17 16:47:45 +0200197 return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300198
199exit:
200 return return_value;
201}
202
203#endif /* defined(HAVE_TTYNAME) */
204
205#if defined(HAVE_CTERMID)
206
207PyDoc_STRVAR(os_ctermid__doc__,
208"ctermid($module, /)\n"
209"--\n"
210"\n"
211"Return the name of the controlling terminal for this process.");
212
213#define OS_CTERMID_METHODDEF \
214 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
215
216static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300217os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300218
219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300220os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300221{
222 return os_ctermid_impl(module);
223}
224
225#endif /* defined(HAVE_CTERMID) */
226
227PyDoc_STRVAR(os_chdir__doc__,
228"chdir($module, /, path)\n"
229"--\n"
230"\n"
231"Change the current working directory to the specified path.\n"
232"\n"
233"path may always be specified as a string.\n"
234"On some platforms, path may also be specified as an open file descriptor.\n"
235" If this functionality is unavailable, using it raises an exception.");
236
237#define OS_CHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200238 {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300239
240static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300241os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300242
243static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200244os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300245{
246 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300247 static const char * const _keywords[] = {"path", NULL};
248 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300249 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
250
Victor Stinner3e1fad62017-01-17 01:29:01 +0100251 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300252 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300253 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300254 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300255 return_value = os_chdir_impl(module, &path);
256
257exit:
258 /* Cleanup for path */
259 path_cleanup(&path);
260
261 return return_value;
262}
263
264#if defined(HAVE_FCHDIR)
265
266PyDoc_STRVAR(os_fchdir__doc__,
267"fchdir($module, /, fd)\n"
268"--\n"
269"\n"
270"Change to the directory of the given file descriptor.\n"
271"\n"
272"fd must be opened on a directory, not a file.\n"
273"Equivalent to os.chdir(fd).");
274
275#define OS_FCHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200276 {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300277
278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300279os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300280
281static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200282os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300283{
284 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300285 static const char * const _keywords[] = {"fd", NULL};
286 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300287 int fd;
288
Victor Stinner3e1fad62017-01-17 01:29:01 +0100289 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300290 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300291 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300292 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300293 return_value = os_fchdir_impl(module, fd);
294
295exit:
296 return return_value;
297}
298
299#endif /* defined(HAVE_FCHDIR) */
300
301PyDoc_STRVAR(os_chmod__doc__,
302"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
303"--\n"
304"\n"
305"Change the access permissions of a file.\n"
306"\n"
307" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000308" 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 +0300309" On some platforms, path may also be specified as an open file descriptor.\n"
310" If this functionality is unavailable, using it raises an exception.\n"
311" mode\n"
312" Operating-system mode bitfield.\n"
313" dir_fd\n"
314" If not None, it should be a file descriptor open to a directory,\n"
315" and path should be relative; path will then be relative to that\n"
316" directory.\n"
317" follow_symlinks\n"
318" If False, and the last element of the path is a symbolic link,\n"
319" chmod will modify the symbolic link itself instead of the file\n"
320" the link points to.\n"
321"\n"
322"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
323" an open file descriptor.\n"
324"dir_fd and follow_symlinks may not be implemented on your platform.\n"
325" If they are unavailable, using them will raise a NotImplementedError.");
326
327#define OS_CHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200328 {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300329
330static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300331os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400332 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300333
334static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200335os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300336{
337 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300338 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
339 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300340 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
341 int mode;
342 int dir_fd = DEFAULT_DIR_FD;
343 int follow_symlinks = 1;
344
Victor Stinner3e1fad62017-01-17 01:29:01 +0100345 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300346 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300347 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300348 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300349 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
350
351exit:
352 /* Cleanup for path */
353 path_cleanup(&path);
354
355 return return_value;
356}
357
358#if defined(HAVE_FCHMOD)
359
360PyDoc_STRVAR(os_fchmod__doc__,
361"fchmod($module, /, fd, mode)\n"
362"--\n"
363"\n"
364"Change the access permissions of the file given by file descriptor fd.\n"
365"\n"
366"Equivalent to os.chmod(fd, mode).");
367
368#define OS_FCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200369 {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300370
371static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300372os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300373
374static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200375os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300376{
377 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300378 static const char * const _keywords[] = {"fd", "mode", NULL};
379 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300380 int fd;
381 int mode;
382
Victor Stinner3e1fad62017-01-17 01:29:01 +0100383 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300384 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300385 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300386 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300387 return_value = os_fchmod_impl(module, fd, mode);
388
389exit:
390 return return_value;
391}
392
393#endif /* defined(HAVE_FCHMOD) */
394
395#if defined(HAVE_LCHMOD)
396
397PyDoc_STRVAR(os_lchmod__doc__,
398"lchmod($module, /, path, mode)\n"
399"--\n"
400"\n"
401"Change the access permissions of a file, without following symbolic links.\n"
402"\n"
403"If path is a symlink, this affects the link itself rather than the target.\n"
404"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
405
406#define OS_LCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200407 {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300408
409static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300410os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300411
412static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200413os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300414{
415 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300416 static const char * const _keywords[] = {"path", "mode", NULL};
417 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300418 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
419 int mode;
420
Victor Stinner3e1fad62017-01-17 01:29:01 +0100421 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300422 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300423 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300424 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300425 return_value = os_lchmod_impl(module, &path, mode);
426
427exit:
428 /* Cleanup for path */
429 path_cleanup(&path);
430
431 return return_value;
432}
433
434#endif /* defined(HAVE_LCHMOD) */
435
436#if defined(HAVE_CHFLAGS)
437
438PyDoc_STRVAR(os_chflags__doc__,
439"chflags($module, /, path, flags, follow_symlinks=True)\n"
440"--\n"
441"\n"
442"Set file flags.\n"
443"\n"
444"If follow_symlinks is False, and the last element of the path is a symbolic\n"
445" link, chflags will change flags on the symbolic link itself instead of the\n"
446" file the link points to.\n"
447"follow_symlinks may not be implemented on your platform. If it is\n"
448"unavailable, using it will raise a NotImplementedError.");
449
450#define OS_CHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200451 {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300452
453static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300454os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400455 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300456
457static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200458os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300459{
460 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300461 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
462 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300463 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
464 unsigned long flags;
465 int follow_symlinks = 1;
466
Victor Stinner3e1fad62017-01-17 01:29:01 +0100467 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300468 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300469 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300471 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
472
473exit:
474 /* Cleanup for path */
475 path_cleanup(&path);
476
477 return return_value;
478}
479
480#endif /* defined(HAVE_CHFLAGS) */
481
482#if defined(HAVE_LCHFLAGS)
483
484PyDoc_STRVAR(os_lchflags__doc__,
485"lchflags($module, /, path, flags)\n"
486"--\n"
487"\n"
488"Set file flags.\n"
489"\n"
490"This function will not follow symbolic links.\n"
491"Equivalent to chflags(path, flags, follow_symlinks=False).");
492
493#define OS_LCHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200494 {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300495
496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300497os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300498
499static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200500os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300501{
502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300503 static const char * const _keywords[] = {"path", "flags", NULL};
504 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300505 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
506 unsigned long flags;
507
Victor Stinner3e1fad62017-01-17 01:29:01 +0100508 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300509 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300512 return_value = os_lchflags_impl(module, &path, flags);
513
514exit:
515 /* Cleanup for path */
516 path_cleanup(&path);
517
518 return return_value;
519}
520
521#endif /* defined(HAVE_LCHFLAGS) */
522
523#if defined(HAVE_CHROOT)
524
525PyDoc_STRVAR(os_chroot__doc__,
526"chroot($module, /, path)\n"
527"--\n"
528"\n"
529"Change root directory to path.");
530
531#define OS_CHROOT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200532 {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300533
534static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300535os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300536
537static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200538os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300539{
540 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300541 static const char * const _keywords[] = {"path", NULL};
542 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300543 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
544
Victor Stinner3e1fad62017-01-17 01:29:01 +0100545 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300546 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300547 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300548 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300549 return_value = os_chroot_impl(module, &path);
550
551exit:
552 /* Cleanup for path */
553 path_cleanup(&path);
554
555 return return_value;
556}
557
558#endif /* defined(HAVE_CHROOT) */
559
560#if defined(HAVE_FSYNC)
561
562PyDoc_STRVAR(os_fsync__doc__,
563"fsync($module, /, fd)\n"
564"--\n"
565"\n"
566"Force write of fd to disk.");
567
568#define OS_FSYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200569 {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300570
571static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300572os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300573
574static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200575os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300576{
577 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300578 static const char * const _keywords[] = {"fd", NULL};
579 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300580 int fd;
581
Victor Stinner3e1fad62017-01-17 01:29:01 +0100582 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300583 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300584 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300585 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300586 return_value = os_fsync_impl(module, fd);
587
588exit:
589 return return_value;
590}
591
592#endif /* defined(HAVE_FSYNC) */
593
594#if defined(HAVE_SYNC)
595
596PyDoc_STRVAR(os_sync__doc__,
597"sync($module, /)\n"
598"--\n"
599"\n"
600"Force write of everything to disk.");
601
602#define OS_SYNC_METHODDEF \
603 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
604
605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300606os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300607
608static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300609os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300610{
611 return os_sync_impl(module);
612}
613
614#endif /* defined(HAVE_SYNC) */
615
616#if defined(HAVE_FDATASYNC)
617
618PyDoc_STRVAR(os_fdatasync__doc__,
619"fdatasync($module, /, fd)\n"
620"--\n"
621"\n"
622"Force write of fd to disk without forcing update of metadata.");
623
624#define OS_FDATASYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200625 {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300626
627static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300628os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300629
630static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200631os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300632{
633 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300634 static const char * const _keywords[] = {"fd", NULL};
635 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300636 int fd;
637
Victor Stinner3e1fad62017-01-17 01:29:01 +0100638 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300639 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300640 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300641 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300642 return_value = os_fdatasync_impl(module, fd);
643
644exit:
645 return return_value;
646}
647
648#endif /* defined(HAVE_FDATASYNC) */
649
650#if defined(HAVE_CHOWN)
651
652PyDoc_STRVAR(os_chown__doc__,
653"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
654"--\n"
655"\n"
656"Change the owner and group id of path to the numeric uid and gid.\\\n"
657"\n"
658" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000659" 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 +0300660" dir_fd\n"
661" If not None, it should be a file descriptor open to a directory,\n"
662" and path should be relative; path will then be relative to that\n"
663" directory.\n"
664" follow_symlinks\n"
665" If False, and the last element of the path is a symbolic link,\n"
666" stat will examine the symbolic link itself instead of the file\n"
667" the link points to.\n"
668"\n"
669"path may always be specified as a string.\n"
670"On some platforms, path may also be specified as an open file descriptor.\n"
671" If this functionality is unavailable, using it raises an exception.\n"
672"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
673" and path should be relative; path will then be relative to that directory.\n"
674"If follow_symlinks is False, and the last element of the path is a symbolic\n"
675" link, chown will modify the symbolic link itself instead of the file the\n"
676" link points to.\n"
677"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
678" an open file descriptor.\n"
679"dir_fd and follow_symlinks may not be implemented on your platform.\n"
680" If they are unavailable, using them will raise a NotImplementedError.");
681
682#define OS_CHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200683 {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300684
685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300686os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400687 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300688
689static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200690os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300691{
692 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300693 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
694 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300695 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
696 uid_t uid;
697 gid_t gid;
698 int dir_fd = DEFAULT_DIR_FD;
699 int follow_symlinks = 1;
700
Victor Stinner3e1fad62017-01-17 01:29:01 +0100701 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300702 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 +0300703 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300704 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
706
707exit:
708 /* Cleanup for path */
709 path_cleanup(&path);
710
711 return return_value;
712}
713
714#endif /* defined(HAVE_CHOWN) */
715
716#if defined(HAVE_FCHOWN)
717
718PyDoc_STRVAR(os_fchown__doc__,
719"fchown($module, /, fd, uid, gid)\n"
720"--\n"
721"\n"
722"Change the owner and group id of the file specified by file descriptor.\n"
723"\n"
724"Equivalent to os.chown(fd, uid, gid).");
725
726#define OS_FCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200727 {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300728
729static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300730os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300731
732static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200733os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300734{
735 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300736 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
737 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300738 int fd;
739 uid_t uid;
740 gid_t gid;
741
Victor Stinner3e1fad62017-01-17 01:29:01 +0100742 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300743 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300744 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300745 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300746 return_value = os_fchown_impl(module, fd, uid, gid);
747
748exit:
749 return return_value;
750}
751
752#endif /* defined(HAVE_FCHOWN) */
753
754#if defined(HAVE_LCHOWN)
755
756PyDoc_STRVAR(os_lchown__doc__,
757"lchown($module, /, path, uid, gid)\n"
758"--\n"
759"\n"
760"Change the owner and group id of path to the numeric uid and gid.\n"
761"\n"
762"This function will not follow symbolic links.\n"
763"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
764
765#define OS_LCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200766 {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300767
768static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300769os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300770
771static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200772os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300773{
774 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300775 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
776 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300777 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
778 uid_t uid;
779 gid_t gid;
780
Victor Stinner3e1fad62017-01-17 01:29:01 +0100781 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300782 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300783 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300784 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300785 return_value = os_lchown_impl(module, &path, uid, gid);
786
787exit:
788 /* Cleanup for path */
789 path_cleanup(&path);
790
791 return return_value;
792}
793
794#endif /* defined(HAVE_LCHOWN) */
795
796PyDoc_STRVAR(os_getcwd__doc__,
797"getcwd($module, /)\n"
798"--\n"
799"\n"
800"Return a unicode string representing the current working directory.");
801
802#define OS_GETCWD_METHODDEF \
803 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
804
805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300806os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300807
808static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300809os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300810{
811 return os_getcwd_impl(module);
812}
813
814PyDoc_STRVAR(os_getcwdb__doc__,
815"getcwdb($module, /)\n"
816"--\n"
817"\n"
818"Return a bytes string representing the current working directory.");
819
820#define OS_GETCWDB_METHODDEF \
821 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
822
823static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300824os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300825
826static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300827os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300828{
829 return os_getcwdb_impl(module);
830}
831
832#if defined(HAVE_LINK)
833
834PyDoc_STRVAR(os_link__doc__,
835"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
836" follow_symlinks=True)\n"
837"--\n"
838"\n"
839"Create a hard link to a file.\n"
840"\n"
841"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
842" descriptor open to a directory, and the respective path string (src or dst)\n"
843" should be relative; the path will then be relative to that directory.\n"
844"If follow_symlinks is False, and the last element of src is a symbolic\n"
845" link, link will create a link to the symbolic link itself instead of the\n"
846" file the link points to.\n"
847"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
848" platform. If they are unavailable, using them will raise a\n"
849" NotImplementedError.");
850
851#define OS_LINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200852 {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300853
854static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300855os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400856 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300857
858static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200859os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300860{
861 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300862 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
863 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300864 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
865 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
866 int src_dir_fd = DEFAULT_DIR_FD;
867 int dst_dir_fd = DEFAULT_DIR_FD;
868 int follow_symlinks = 1;
869
Victor Stinner3e1fad62017-01-17 01:29:01 +0100870 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300871 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 +0300872 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300873 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300874 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
875
876exit:
877 /* Cleanup for src */
878 path_cleanup(&src);
879 /* Cleanup for dst */
880 path_cleanup(&dst);
881
882 return return_value;
883}
884
885#endif /* defined(HAVE_LINK) */
886
887PyDoc_STRVAR(os_listdir__doc__,
888"listdir($module, /, path=None)\n"
889"--\n"
890"\n"
891"Return a list containing the names of the files in the directory.\n"
892"\n"
BNMetricsb9427072018-11-02 15:20:19 +0000893"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 +0300894" the filenames returned will also be bytes; in all other circumstances\n"
895" the filenames returned will be str.\n"
896"If path is None, uses the path=\'.\'.\n"
897"On some platforms, path may also be specified as an open file descriptor;\\\n"
898" the file descriptor must refer to a directory.\n"
899" If this functionality is unavailable, using it raises NotImplementedError.\n"
900"\n"
901"The list is in arbitrary order. It does not include the special\n"
902"entries \'.\' and \'..\' even if they are present in the directory.");
903
904#define OS_LISTDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200905 {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300906
907static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300908os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300909
910static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200911os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300912{
913 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300914 static const char * const _keywords[] = {"path", NULL};
915 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300916 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
917
Victor Stinner3e1fad62017-01-17 01:29:01 +0100918 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300919 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300921 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300922 return_value = os_listdir_impl(module, &path);
923
924exit:
925 /* Cleanup for path */
926 path_cleanup(&path);
927
928 return return_value;
929}
930
931#if defined(MS_WINDOWS)
932
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300933PyDoc_STRVAR(os__getfullpathname__doc__,
934"_getfullpathname($module, path, /)\n"
935"--\n"
936"\n");
937
938#define OS__GETFULLPATHNAME_METHODDEF \
939 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
940
941static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300942os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300943
944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300945os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300946{
947 PyObject *return_value = NULL;
948 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
949
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200950 if (!path_converter(arg, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300951 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300952 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300953 return_value = os__getfullpathname_impl(module, &path);
954
955exit:
956 /* Cleanup for path */
957 path_cleanup(&path);
958
959 return return_value;
960}
961
962#endif /* defined(MS_WINDOWS) */
963
964#if defined(MS_WINDOWS)
965
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300966PyDoc_STRVAR(os__getfinalpathname__doc__,
967"_getfinalpathname($module, path, /)\n"
968"--\n"
969"\n"
970"A helper function for samepath on windows.");
971
972#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300973 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300974
975static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -0800976os__getfinalpathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300977
978static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300979os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300980{
981 PyObject *return_value = NULL;
Steve Dower23ad6d02018-02-22 10:39:10 -0800982 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300983
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200984 if (!path_converter(arg, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300985 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300986 }
Steve Dower23ad6d02018-02-22 10:39:10 -0800987 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300988
989exit:
Steve Dower23ad6d02018-02-22 10:39:10 -0800990 /* Cleanup for path */
991 path_cleanup(&path);
992
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300993 return return_value;
994}
995
996#endif /* defined(MS_WINDOWS) */
997
998#if defined(MS_WINDOWS)
999
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001000PyDoc_STRVAR(os__isdir__doc__,
1001"_isdir($module, path, /)\n"
1002"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +02001003"\n"
1004"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001005
1006#define OS__ISDIR_METHODDEF \
1007 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1008
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001009#endif /* defined(MS_WINDOWS) */
1010
1011#if defined(MS_WINDOWS)
1012
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001013PyDoc_STRVAR(os__getvolumepathname__doc__,
1014"_getvolumepathname($module, /, path)\n"
1015"--\n"
1016"\n"
1017"A helper function for ismount on Win32.");
1018
1019#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001020 {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001021
1022static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001023os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001024
1025static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001026os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001027{
1028 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001029 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08001030 static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1031 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001032
Victor Stinner3e1fad62017-01-17 01:29:01 +01001033 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08001034 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001035 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001036 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001037 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038
1039exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001040 /* Cleanup for path */
1041 path_cleanup(&path);
1042
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001043 return return_value;
1044}
1045
1046#endif /* defined(MS_WINDOWS) */
1047
1048PyDoc_STRVAR(os_mkdir__doc__,
1049"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1050"--\n"
1051"\n"
1052"Create a directory.\n"
1053"\n"
1054"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1055" and path should be relative; path will then be relative to that directory.\n"
1056"dir_fd may not be implemented on your platform.\n"
1057" If it is unavailable, using it will raise a NotImplementedError.\n"
1058"\n"
1059"The mode argument is ignored on Windows.");
1060
1061#define OS_MKDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001062 {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001063
1064static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001065os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001066
1067static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001068os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001069{
1070 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001071 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1072 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001073 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1074 int mode = 511;
1075 int dir_fd = DEFAULT_DIR_FD;
1076
Victor Stinner3e1fad62017-01-17 01:29:01 +01001077 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001078 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001079 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001080 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001081 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1082
1083exit:
1084 /* Cleanup for path */
1085 path_cleanup(&path);
1086
1087 return return_value;
1088}
1089
1090#if defined(HAVE_NICE)
1091
1092PyDoc_STRVAR(os_nice__doc__,
1093"nice($module, increment, /)\n"
1094"--\n"
1095"\n"
1096"Add increment to the priority of process and return the new priority.");
1097
1098#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001099 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001100
1101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001102os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001103
1104static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001105os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001106{
1107 PyObject *return_value = NULL;
1108 int increment;
1109
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001110 if (PyFloat_Check(arg)) {
1111 PyErr_SetString(PyExc_TypeError,
1112 "integer argument expected, got float" );
1113 goto exit;
1114 }
1115 increment = _PyLong_AsInt(arg);
1116 if (increment == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001117 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001118 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001119 return_value = os_nice_impl(module, increment);
1120
1121exit:
1122 return return_value;
1123}
1124
1125#endif /* defined(HAVE_NICE) */
1126
1127#if defined(HAVE_GETPRIORITY)
1128
1129PyDoc_STRVAR(os_getpriority__doc__,
1130"getpriority($module, /, which, who)\n"
1131"--\n"
1132"\n"
1133"Return program scheduling priority.");
1134
1135#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001136 {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001137
1138static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001139os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001140
1141static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001142os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001143{
1144 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001145 static const char * const _keywords[] = {"which", "who", NULL};
1146 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001147 int which;
1148 int who;
1149
Victor Stinner3e1fad62017-01-17 01:29:01 +01001150 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001151 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001152 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001154 return_value = os_getpriority_impl(module, which, who);
1155
1156exit:
1157 return return_value;
1158}
1159
1160#endif /* defined(HAVE_GETPRIORITY) */
1161
1162#if defined(HAVE_SETPRIORITY)
1163
1164PyDoc_STRVAR(os_setpriority__doc__,
1165"setpriority($module, /, which, who, priority)\n"
1166"--\n"
1167"\n"
1168"Set program scheduling priority.");
1169
1170#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001171 {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001172
1173static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001174os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001175
1176static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001177os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001178{
1179 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001180 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1181 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001182 int which;
1183 int who;
1184 int priority;
1185
Victor Stinner3e1fad62017-01-17 01:29:01 +01001186 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001187 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001188 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001189 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001190 return_value = os_setpriority_impl(module, which, who, priority);
1191
1192exit:
1193 return return_value;
1194}
1195
1196#endif /* defined(HAVE_SETPRIORITY) */
1197
1198PyDoc_STRVAR(os_rename__doc__,
1199"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1200"--\n"
1201"\n"
1202"Rename a file or directory.\n"
1203"\n"
1204"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1205" descriptor open to a directory, and the respective path string (src or dst)\n"
1206" should be relative; the path will then be relative to that directory.\n"
1207"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1208" If they are unavailable, using them will raise a NotImplementedError.");
1209
1210#define OS_RENAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001211 {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001212
1213static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001214os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001215 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001216
1217static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001218os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001219{
1220 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001221 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1222 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001223 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1224 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1225 int src_dir_fd = DEFAULT_DIR_FD;
1226 int dst_dir_fd = DEFAULT_DIR_FD;
1227
Victor Stinner3e1fad62017-01-17 01:29:01 +01001228 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001229 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 +03001230 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001231 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001232 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1233
1234exit:
1235 /* Cleanup for src */
1236 path_cleanup(&src);
1237 /* Cleanup for dst */
1238 path_cleanup(&dst);
1239
1240 return return_value;
1241}
1242
1243PyDoc_STRVAR(os_replace__doc__,
1244"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1245"--\n"
1246"\n"
1247"Rename a file or directory, overwriting the destination.\n"
1248"\n"
1249"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1250" descriptor open to a directory, and the respective path string (src or dst)\n"
1251" should be relative; the path will then be relative to that directory.\n"
1252"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1253" If they are unavailable, using them will raise a NotImplementedError.\"");
1254
1255#define OS_REPLACE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001256 {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001257
1258static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001259os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1260 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001261
1262static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001263os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001264{
1265 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001266 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1267 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001268 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1269 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1270 int src_dir_fd = DEFAULT_DIR_FD;
1271 int dst_dir_fd = DEFAULT_DIR_FD;
1272
Victor Stinner3e1fad62017-01-17 01:29:01 +01001273 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001274 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 +03001275 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001276 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001277 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1278
1279exit:
1280 /* Cleanup for src */
1281 path_cleanup(&src);
1282 /* Cleanup for dst */
1283 path_cleanup(&dst);
1284
1285 return return_value;
1286}
1287
1288PyDoc_STRVAR(os_rmdir__doc__,
1289"rmdir($module, /, path, *, dir_fd=None)\n"
1290"--\n"
1291"\n"
1292"Remove a directory.\n"
1293"\n"
1294"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1295" and path should be relative; path will then be relative to that directory.\n"
1296"dir_fd may not be implemented on your platform.\n"
1297" If it is unavailable, using it will raise a NotImplementedError.");
1298
1299#define OS_RMDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001300 {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001301
1302static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001303os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001304
1305static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001306os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001307{
1308 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001309 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1310 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001311 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1312 int dir_fd = DEFAULT_DIR_FD;
1313
Victor Stinner3e1fad62017-01-17 01:29:01 +01001314 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001315 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001316 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001317 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001318 return_value = os_rmdir_impl(module, &path, dir_fd);
1319
1320exit:
1321 /* Cleanup for path */
1322 path_cleanup(&path);
1323
1324 return return_value;
1325}
1326
1327#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1328
1329PyDoc_STRVAR(os_system__doc__,
1330"system($module, /, command)\n"
1331"--\n"
1332"\n"
1333"Execute the command in a subshell.");
1334
1335#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001336 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001337
1338static long
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001339os_system_impl(PyObject *module, const Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001340
1341static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001342os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001343{
1344 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001345 static const char * const _keywords[] = {"command", NULL};
1346 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001347 const Py_UNICODE *command;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348 long _return_value;
1349
Victor Stinner3e1fad62017-01-17 01:29:01 +01001350 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001351 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001352 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001355 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001356 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001357 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001358 return_value = PyLong_FromLong(_return_value);
1359
1360exit:
1361 return return_value;
1362}
1363
1364#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1365
1366#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1367
1368PyDoc_STRVAR(os_system__doc__,
1369"system($module, /, command)\n"
1370"--\n"
1371"\n"
1372"Execute the command in a subshell.");
1373
1374#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001375 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001376
1377static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001378os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001379
1380static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001381os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001382{
1383 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001384 static const char * const _keywords[] = {"command", NULL};
1385 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001386 PyObject *command = NULL;
1387 long _return_value;
1388
Victor Stinner3e1fad62017-01-17 01:29:01 +01001389 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001390 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001391 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001392 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001394 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001395 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001396 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001397 return_value = PyLong_FromLong(_return_value);
1398
1399exit:
1400 /* Cleanup for command */
1401 Py_XDECREF(command);
1402
1403 return return_value;
1404}
1405
1406#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1407
1408PyDoc_STRVAR(os_umask__doc__,
1409"umask($module, mask, /)\n"
1410"--\n"
1411"\n"
1412"Set the current numeric umask and return the previous umask.");
1413
1414#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001415 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001416
1417static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001418os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001419
1420static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001421os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001422{
1423 PyObject *return_value = NULL;
1424 int mask;
1425
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001426 if (PyFloat_Check(arg)) {
1427 PyErr_SetString(PyExc_TypeError,
1428 "integer argument expected, got float" );
1429 goto exit;
1430 }
1431 mask = _PyLong_AsInt(arg);
1432 if (mask == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 return_value = os_umask_impl(module, mask);
1436
1437exit:
1438 return return_value;
1439}
1440
1441PyDoc_STRVAR(os_unlink__doc__,
1442"unlink($module, /, path, *, dir_fd=None)\n"
1443"--\n"
1444"\n"
1445"Remove a file (same as remove()).\n"
1446"\n"
1447"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1448" and path should be relative; path will then be relative to that directory.\n"
1449"dir_fd may not be implemented on your platform.\n"
1450" If it is unavailable, using it will raise a NotImplementedError.");
1451
1452#define OS_UNLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001453 {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001454
1455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001456os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001457
1458static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001459os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001460{
1461 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001462 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1463 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001464 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1465 int dir_fd = DEFAULT_DIR_FD;
1466
Victor Stinner3e1fad62017-01-17 01:29:01 +01001467 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001468 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001469 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 return_value = os_unlink_impl(module, &path, dir_fd);
1472
1473exit:
1474 /* Cleanup for path */
1475 path_cleanup(&path);
1476
1477 return return_value;
1478}
1479
1480PyDoc_STRVAR(os_remove__doc__,
1481"remove($module, /, path, *, dir_fd=None)\n"
1482"--\n"
1483"\n"
1484"Remove a file (same as unlink()).\n"
1485"\n"
1486"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1487" and path should be relative; path will then be relative to that directory.\n"
1488"dir_fd may not be implemented on your platform.\n"
1489" If it is unavailable, using it will raise a NotImplementedError.");
1490
1491#define OS_REMOVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001492 {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001493
1494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001495os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001496
1497static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001498os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001499{
1500 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001501 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1502 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001503 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1504 int dir_fd = DEFAULT_DIR_FD;
1505
Victor Stinner3e1fad62017-01-17 01:29:01 +01001506 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001507 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001508 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 return_value = os_remove_impl(module, &path, dir_fd);
1511
1512exit:
1513 /* Cleanup for path */
1514 path_cleanup(&path);
1515
1516 return return_value;
1517}
1518
1519#if defined(HAVE_UNAME)
1520
1521PyDoc_STRVAR(os_uname__doc__,
1522"uname($module, /)\n"
1523"--\n"
1524"\n"
1525"Return an object identifying the current operating system.\n"
1526"\n"
1527"The object behaves like a named tuple with the following fields:\n"
1528" (sysname, nodename, release, version, machine)");
1529
1530#define OS_UNAME_METHODDEF \
1531 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1532
1533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001534os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001535
1536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001537os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001538{
1539 return os_uname_impl(module);
1540}
1541
1542#endif /* defined(HAVE_UNAME) */
1543
1544PyDoc_STRVAR(os_utime__doc__,
1545"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1546" follow_symlinks=True)\n"
1547"--\n"
1548"\n"
1549"Set the access and modified time of path.\n"
1550"\n"
1551"path may always be specified as a string.\n"
1552"On some platforms, path may also be specified as an open file descriptor.\n"
1553" If this functionality is unavailable, using it raises an exception.\n"
1554"\n"
1555"If times is not None, it must be a tuple (atime, mtime);\n"
1556" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001557"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001558" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1559" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001560"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001561"Specifying tuples for both times and ns is an error.\n"
1562"\n"
1563"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1564" and path should be relative; path will then be relative to that directory.\n"
1565"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1566" link, utime will modify the symbolic link itself instead of the file the\n"
1567" link points to.\n"
1568"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1569" as an open file descriptor.\n"
1570"dir_fd and follow_symlinks may not be available on your platform.\n"
1571" If they are unavailable, using them will raise a NotImplementedError.");
1572
1573#define OS_UTIME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001574 {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001575
1576static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001577os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1578 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001579
1580static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001581os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001582{
1583 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001584 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1585 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001586 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1587 PyObject *times = NULL;
1588 PyObject *ns = NULL;
1589 int dir_fd = DEFAULT_DIR_FD;
1590 int follow_symlinks = 1;
1591
Victor Stinner3e1fad62017-01-17 01:29:01 +01001592 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001593 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001594 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1597
1598exit:
1599 /* Cleanup for path */
1600 path_cleanup(&path);
1601
1602 return return_value;
1603}
1604
1605PyDoc_STRVAR(os__exit__doc__,
1606"_exit($module, /, status)\n"
1607"--\n"
1608"\n"
1609"Exit to the system with specified status, without normal exit processing.");
1610
1611#define OS__EXIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001612 {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001613
1614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001615os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001616
1617static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001618os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001619{
1620 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001621 static const char * const _keywords[] = {"status", NULL};
1622 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001623 int status;
1624
Victor Stinner3e1fad62017-01-17 01:29:01 +01001625 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001626 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 return_value = os__exit_impl(module, status);
1630
1631exit:
1632 return return_value;
1633}
1634
1635#if defined(HAVE_EXECV)
1636
1637PyDoc_STRVAR(os_execv__doc__,
1638"execv($module, path, argv, /)\n"
1639"--\n"
1640"\n"
1641"Execute an executable path with arguments, replacing current process.\n"
1642"\n"
1643" path\n"
1644" Path of executable file.\n"
1645" argv\n"
1646" Tuple or list of strings.");
1647
1648#define OS_EXECV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001649 {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001650
1651static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001652os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001653
1654static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001655os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001656{
1657 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001658 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001659 PyObject *argv;
1660
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001661 if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001662 goto exit;
1663 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001664 if (!path_converter(args[0], &path)) {
1665 goto exit;
1666 }
1667 argv = args[1];
Steve Dowercc16be82016-09-08 10:35:16 -07001668 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001669
1670exit:
1671 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001672 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001673
1674 return return_value;
1675}
1676
1677#endif /* defined(HAVE_EXECV) */
1678
1679#if defined(HAVE_EXECV)
1680
1681PyDoc_STRVAR(os_execve__doc__,
1682"execve($module, /, path, argv, env)\n"
1683"--\n"
1684"\n"
1685"Execute an executable path with arguments, replacing current process.\n"
1686"\n"
1687" path\n"
1688" Path of executable file.\n"
1689" argv\n"
1690" Tuple or list of strings.\n"
1691" env\n"
1692" Dictionary of strings mapping to strings.");
1693
1694#define OS_EXECVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001695 {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001696
1697static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001698os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001699
1700static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001701os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001702{
1703 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001704 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1705 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001706 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1707 PyObject *argv;
1708 PyObject *env;
1709
Victor Stinner3e1fad62017-01-17 01:29:01 +01001710 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001711 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001712 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001713 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001714 return_value = os_execve_impl(module, &path, argv, env);
1715
1716exit:
1717 /* Cleanup for path */
1718 path_cleanup(&path);
1719
1720 return return_value;
1721}
1722
1723#endif /* defined(HAVE_EXECV) */
1724
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001725#if defined(HAVE_POSIX_SPAWN)
1726
1727PyDoc_STRVAR(os_posix_spawn__doc__,
Serhiy Storchakad700f972018-09-08 14:48:18 +03001728"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001729" setpgroup=None, resetids=False, setsid=False,\n"
1730" setsigmask=(), setsigdef=(), scheduler=None)\n"
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001731"--\n"
1732"\n"
1733"Execute the program specified by path in a new process.\n"
1734"\n"
1735" path\n"
1736" Path of executable file.\n"
1737" argv\n"
1738" Tuple or list of strings.\n"
1739" env\n"
1740" Dictionary of strings mapping to strings.\n"
1741" file_actions\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001742" A sequence of file action tuples.\n"
1743" setpgroup\n"
1744" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1745" resetids\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001746" If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
1747" setsid\n"
1748" If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001749" setsigmask\n"
1750" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1751" setsigdef\n"
1752" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1753" scheduler\n"
1754" A tuple with the scheduler policy (optional) and parameters.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001755
1756#define OS_POSIX_SPAWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001757 {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001758
1759static PyObject *
1760os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
Pablo Galindo254a4662018-09-07 16:44:24 +01001761 PyObject *env, PyObject *file_actions,
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001762 PyObject *setpgroup, int resetids, int setsid,
1763 PyObject *setsigmask, PyObject *setsigdef,
1764 PyObject *scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001765
1766static PyObject *
Pablo Galindo254a4662018-09-07 16:44:24 +01001767os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001768{
1769 PyObject *return_value = NULL;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001770 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
1771 static _PyArg_Parser _parser = {"O&OO|$OOiiOOO:posix_spawn", _keywords, 0};
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001772 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1773 PyObject *argv;
1774 PyObject *env;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001775 PyObject *file_actions = NULL;
Pablo Galindo254a4662018-09-07 16:44:24 +01001776 PyObject *setpgroup = NULL;
1777 int resetids = 0;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001778 int setsid = 0;
Pablo Galindo254a4662018-09-07 16:44:24 +01001779 PyObject *setsigmask = NULL;
1780 PyObject *setsigdef = NULL;
1781 PyObject *scheduler = NULL;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001782
Pablo Galindo254a4662018-09-07 16:44:24 +01001783 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001784 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsid, &setsigmask, &setsigdef, &scheduler)) {
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001785 goto exit;
1786 }
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001787 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001788
1789exit:
1790 /* Cleanup for path */
1791 path_cleanup(&path);
1792
1793 return return_value;
1794}
1795
1796#endif /* defined(HAVE_POSIX_SPAWN) */
1797
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001798#if defined(HAVE_POSIX_SPAWNP)
1799
1800PyDoc_STRVAR(os_posix_spawnp__doc__,
1801"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001802" setpgroup=None, resetids=False, setsid=False,\n"
1803" setsigmask=(), setsigdef=(), scheduler=None)\n"
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001804"--\n"
1805"\n"
1806"Execute the program specified by path in a new process.\n"
1807"\n"
1808" path\n"
1809" Path of executable file.\n"
1810" argv\n"
1811" Tuple or list of strings.\n"
1812" env\n"
1813" Dictionary of strings mapping to strings.\n"
1814" file_actions\n"
1815" A sequence of file action tuples.\n"
1816" setpgroup\n"
1817" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1818" resetids\n"
1819" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001820" setsid\n"
1821" If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001822" setsigmask\n"
1823" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1824" setsigdef\n"
1825" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1826" scheduler\n"
1827" A tuple with the scheduler policy (optional) and parameters.");
1828
1829#define OS_POSIX_SPAWNP_METHODDEF \
1830 {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
1831
1832static PyObject *
1833os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
1834 PyObject *env, PyObject *file_actions,
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001835 PyObject *setpgroup, int resetids, int setsid,
1836 PyObject *setsigmask, PyObject *setsigdef,
1837 PyObject *scheduler);
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001838
1839static PyObject *
1840os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1841{
1842 PyObject *return_value = NULL;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001843 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
1844 static _PyArg_Parser _parser = {"O&OO|$OOiiOOO:posix_spawnp", _keywords, 0};
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001845 path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0);
1846 PyObject *argv;
1847 PyObject *env;
1848 PyObject *file_actions = NULL;
1849 PyObject *setpgroup = NULL;
1850 int resetids = 0;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001851 int setsid = 0;
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001852 PyObject *setsigmask = NULL;
1853 PyObject *setsigdef = NULL;
1854 PyObject *scheduler = NULL;
1855
1856 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001857 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsid, &setsigmask, &setsigdef, &scheduler)) {
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001858 goto exit;
1859 }
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03001860 return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001861
1862exit:
1863 /* Cleanup for path */
1864 path_cleanup(&path);
1865
1866 return return_value;
1867}
1868
1869#endif /* defined(HAVE_POSIX_SPAWNP) */
1870
Steve Dowercc16be82016-09-08 10:35:16 -07001871#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001872
1873PyDoc_STRVAR(os_spawnv__doc__,
1874"spawnv($module, mode, path, argv, /)\n"
1875"--\n"
1876"\n"
1877"Execute the program specified by path in a new process.\n"
1878"\n"
1879" mode\n"
1880" Mode of process creation.\n"
1881" path\n"
1882" Path of executable file.\n"
1883" argv\n"
1884" Tuple or list of strings.");
1885
1886#define OS_SPAWNV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001887 {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001888
1889static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001890os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001891
1892static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001893os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001894{
1895 PyObject *return_value = NULL;
1896 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001897 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001898 PyObject *argv;
1899
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001900 if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001901 goto exit;
1902 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001903 if (PyFloat_Check(args[0])) {
1904 PyErr_SetString(PyExc_TypeError,
1905 "integer argument expected, got float" );
1906 goto exit;
1907 }
1908 mode = _PyLong_AsInt(args[0]);
1909 if (mode == -1 && PyErr_Occurred()) {
1910 goto exit;
1911 }
1912 if (!path_converter(args[1], &path)) {
1913 goto exit;
1914 }
1915 argv = args[2];
Steve Dowercc16be82016-09-08 10:35:16 -07001916 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001917
1918exit:
1919 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001920 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001921
1922 return return_value;
1923}
1924
Steve Dowercc16be82016-09-08 10:35:16 -07001925#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001926
Steve Dowercc16be82016-09-08 10:35:16 -07001927#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001928
1929PyDoc_STRVAR(os_spawnve__doc__,
1930"spawnve($module, mode, path, argv, env, /)\n"
1931"--\n"
1932"\n"
1933"Execute the program specified by path in a new process.\n"
1934"\n"
1935" mode\n"
1936" Mode of process creation.\n"
1937" path\n"
1938" Path of executable file.\n"
1939" argv\n"
1940" Tuple or list of strings.\n"
1941" env\n"
1942" Dictionary of strings mapping to strings.");
1943
1944#define OS_SPAWNVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001945 {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001946
1947static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001948os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001949 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001950
1951static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001952os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001953{
1954 PyObject *return_value = NULL;
1955 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001956 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001957 PyObject *argv;
1958 PyObject *env;
1959
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001960 if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001961 goto exit;
1962 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001963 if (PyFloat_Check(args[0])) {
1964 PyErr_SetString(PyExc_TypeError,
1965 "integer argument expected, got float" );
1966 goto exit;
1967 }
1968 mode = _PyLong_AsInt(args[0]);
1969 if (mode == -1 && PyErr_Occurred()) {
1970 goto exit;
1971 }
1972 if (!path_converter(args[1], &path)) {
1973 goto exit;
1974 }
1975 argv = args[2];
1976 env = args[3];
Steve Dowercc16be82016-09-08 10:35:16 -07001977 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001978
1979exit:
1980 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001981 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001982
1983 return return_value;
1984}
1985
Steve Dowercc16be82016-09-08 10:35:16 -07001986#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001987
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001988#if defined(HAVE_FORK)
1989
1990PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001991"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1992" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001993"--\n"
1994"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001995"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001996"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001997" before\n"
1998" A callable to be called in the parent before the fork() syscall.\n"
1999" after_in_child\n"
2000" A callable to be called in the child after fork().\n"
2001" after_in_parent\n"
2002" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002003"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07002004"\'before\' callbacks are called in reverse order.\n"
2005"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002006
2007#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002008 {"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 +02002009
2010static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07002011os_register_at_fork_impl(PyObject *module, PyObject *before,
2012 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002013
2014static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002015os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002016{
2017 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07002018 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
2019 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
2020 PyObject *before = NULL;
2021 PyObject *after_in_child = NULL;
2022 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002023
2024 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07002025 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002026 goto exit;
2027 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07002028 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002029
2030exit:
2031 return return_value;
2032}
2033
2034#endif /* defined(HAVE_FORK) */
2035
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002036#if defined(HAVE_FORK1)
2037
2038PyDoc_STRVAR(os_fork1__doc__,
2039"fork1($module, /)\n"
2040"--\n"
2041"\n"
2042"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
2043"\n"
2044"Return 0 to child process and PID of child to parent process.");
2045
2046#define OS_FORK1_METHODDEF \
2047 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
2048
2049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002050os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002051
2052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002053os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002054{
2055 return os_fork1_impl(module);
2056}
2057
2058#endif /* defined(HAVE_FORK1) */
2059
2060#if defined(HAVE_FORK)
2061
2062PyDoc_STRVAR(os_fork__doc__,
2063"fork($module, /)\n"
2064"--\n"
2065"\n"
2066"Fork a child process.\n"
2067"\n"
2068"Return 0 to child process and PID of child to parent process.");
2069
2070#define OS_FORK_METHODDEF \
2071 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
2072
2073static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002074os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002075
2076static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002077os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002078{
2079 return os_fork_impl(module);
2080}
2081
2082#endif /* defined(HAVE_FORK) */
2083
2084#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2085
2086PyDoc_STRVAR(os_sched_get_priority_max__doc__,
2087"sched_get_priority_max($module, /, policy)\n"
2088"--\n"
2089"\n"
2090"Get the maximum scheduling priority for policy.");
2091
2092#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002093 {"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 +03002094
2095static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002096os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002097
2098static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002099os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002100{
2101 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002102 static const char * const _keywords[] = {"policy", NULL};
2103 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002104 int policy;
2105
Victor Stinner3e1fad62017-01-17 01:29:01 +01002106 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002107 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002110 return_value = os_sched_get_priority_max_impl(module, policy);
2111
2112exit:
2113 return return_value;
2114}
2115
2116#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2117
2118#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2119
2120PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2121"sched_get_priority_min($module, /, policy)\n"
2122"--\n"
2123"\n"
2124"Get the minimum scheduling priority for policy.");
2125
2126#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002127 {"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 +03002128
2129static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002130os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002131
2132static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002133os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134{
2135 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002136 static const char * const _keywords[] = {"policy", NULL};
2137 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002138 int policy;
2139
Victor Stinner3e1fad62017-01-17 01:29:01 +01002140 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002141 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002142 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002143 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002144 return_value = os_sched_get_priority_min_impl(module, policy);
2145
2146exit:
2147 return return_value;
2148}
2149
2150#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2151
2152#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2153
2154PyDoc_STRVAR(os_sched_getscheduler__doc__,
2155"sched_getscheduler($module, pid, /)\n"
2156"--\n"
2157"\n"
2158"Get the scheduling policy for the process identifiedy by pid.\n"
2159"\n"
2160"Passing 0 for pid returns the scheduling policy for the calling process.");
2161
2162#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002163 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002164
2165static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002166os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002167
2168static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002169os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002170{
2171 PyObject *return_value = NULL;
2172 pid_t pid;
2173
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002174 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002175 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002176 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002177 return_value = os_sched_getscheduler_impl(module, pid);
2178
2179exit:
2180 return return_value;
2181}
2182
2183#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2184
William Orr81574b82018-10-01 22:19:56 -07002185#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 +03002186
2187PyDoc_STRVAR(os_sched_param__doc__,
2188"sched_param(sched_priority)\n"
2189"--\n"
2190"\n"
2191"Current has only one field: sched_priority\");\n"
2192"\n"
2193" sched_priority\n"
2194" A scheduling parameter.");
2195
2196static PyObject *
2197os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2198
2199static PyObject *
2200os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2201{
2202 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002203 static const char * const _keywords[] = {"sched_priority", NULL};
2204 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002205 PyObject *sched_priority;
2206
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002207 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002208 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002209 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002210 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002211 return_value = os_sched_param_impl(type, sched_priority);
2212
2213exit:
2214 return return_value;
2215}
2216
William Orr81574b82018-10-01 22:19:56 -07002217#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 +03002218
2219#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2220
2221PyDoc_STRVAR(os_sched_setscheduler__doc__,
2222"sched_setscheduler($module, pid, policy, param, /)\n"
2223"--\n"
2224"\n"
2225"Set the scheduling policy for the process identified by pid.\n"
2226"\n"
2227"If pid is 0, the calling process is changed.\n"
2228"param is an instance of sched_param.");
2229
2230#define OS_SCHED_SETSCHEDULER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002231 {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002232
2233static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002234os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002235 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002236
2237static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002238os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002239{
2240 PyObject *return_value = NULL;
2241 pid_t pid;
2242 int policy;
2243 struct sched_param param;
2244
Sylvain74453812017-06-10 06:51:48 +02002245 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2246 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002247 goto exit;
2248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002249 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2250
2251exit:
2252 return return_value;
2253}
2254
2255#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2256
2257#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2258
2259PyDoc_STRVAR(os_sched_getparam__doc__,
2260"sched_getparam($module, pid, /)\n"
2261"--\n"
2262"\n"
2263"Returns scheduling parameters for the process identified by pid.\n"
2264"\n"
2265"If pid is 0, returns parameters for the calling process.\n"
2266"Return value is an instance of sched_param.");
2267
2268#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002269 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002270
2271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002272os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002273
2274static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002275os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002276{
2277 PyObject *return_value = NULL;
2278 pid_t pid;
2279
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002280 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002281 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002282 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002283 return_value = os_sched_getparam_impl(module, pid);
2284
2285exit:
2286 return return_value;
2287}
2288
2289#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2290
2291#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2292
2293PyDoc_STRVAR(os_sched_setparam__doc__,
2294"sched_setparam($module, pid, param, /)\n"
2295"--\n"
2296"\n"
2297"Set scheduling parameters for the process identified by pid.\n"
2298"\n"
2299"If pid is 0, sets parameters for the calling process.\n"
2300"param should be an instance of sched_param.");
2301
2302#define OS_SCHED_SETPARAM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002303 {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002304
2305static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002306os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002307 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002308
2309static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002310os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002311{
2312 PyObject *return_value = NULL;
2313 pid_t pid;
2314 struct sched_param param;
2315
Sylvain74453812017-06-10 06:51:48 +02002316 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2317 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002318 goto exit;
2319 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002320 return_value = os_sched_setparam_impl(module, pid, &param);
2321
2322exit:
2323 return return_value;
2324}
2325
2326#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2327
2328#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2329
2330PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2331"sched_rr_get_interval($module, pid, /)\n"
2332"--\n"
2333"\n"
2334"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2335"\n"
2336"Value returned is a float.");
2337
2338#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002339 {"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 +03002340
2341static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002342os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002343
2344static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002345os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002346{
2347 PyObject *return_value = NULL;
2348 pid_t pid;
2349 double _return_value;
2350
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002351 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002352 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002354 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002355 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002356 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002357 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002358 return_value = PyFloat_FromDouble(_return_value);
2359
2360exit:
2361 return return_value;
2362}
2363
2364#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2365
2366#if defined(HAVE_SCHED_H)
2367
2368PyDoc_STRVAR(os_sched_yield__doc__,
2369"sched_yield($module, /)\n"
2370"--\n"
2371"\n"
2372"Voluntarily relinquish the CPU.");
2373
2374#define OS_SCHED_YIELD_METHODDEF \
2375 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2376
2377static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002378os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002379
2380static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002381os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002382{
2383 return os_sched_yield_impl(module);
2384}
2385
2386#endif /* defined(HAVE_SCHED_H) */
2387
2388#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2389
2390PyDoc_STRVAR(os_sched_setaffinity__doc__,
2391"sched_setaffinity($module, pid, mask, /)\n"
2392"--\n"
2393"\n"
2394"Set the CPU affinity of the process identified by pid to mask.\n"
2395"\n"
2396"mask should be an iterable of integers identifying CPUs.");
2397
2398#define OS_SCHED_SETAFFINITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002399 {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002400
2401static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002402os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002403
2404static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002405os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002406{
2407 PyObject *return_value = NULL;
2408 pid_t pid;
2409 PyObject *mask;
2410
Sylvain74453812017-06-10 06:51:48 +02002411 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2412 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002413 goto exit;
2414 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002415 return_value = os_sched_setaffinity_impl(module, pid, mask);
2416
2417exit:
2418 return return_value;
2419}
2420
2421#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2422
2423#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2424
2425PyDoc_STRVAR(os_sched_getaffinity__doc__,
2426"sched_getaffinity($module, pid, /)\n"
2427"--\n"
2428"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002429"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002430"\n"
2431"The affinity is returned as a set of CPU identifiers.");
2432
2433#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002434 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002435
2436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002437os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002438
2439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002440os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002441{
2442 PyObject *return_value = NULL;
2443 pid_t pid;
2444
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002445 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002446 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002447 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002448 return_value = os_sched_getaffinity_impl(module, pid);
2449
2450exit:
2451 return return_value;
2452}
2453
2454#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2455
2456#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2457
2458PyDoc_STRVAR(os_openpty__doc__,
2459"openpty($module, /)\n"
2460"--\n"
2461"\n"
2462"Open a pseudo-terminal.\n"
2463"\n"
2464"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2465"for both the master and slave ends.");
2466
2467#define OS_OPENPTY_METHODDEF \
2468 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2469
2470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002471os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002472
2473static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002474os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002475{
2476 return os_openpty_impl(module);
2477}
2478
2479#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2480
2481#if defined(HAVE_FORKPTY)
2482
2483PyDoc_STRVAR(os_forkpty__doc__,
2484"forkpty($module, /)\n"
2485"--\n"
2486"\n"
2487"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2488"\n"
2489"Returns a tuple of (pid, master_fd).\n"
2490"Like fork(), return pid of 0 to the child process,\n"
2491"and pid of child to the parent process.\n"
2492"To both, return fd of newly opened pseudo-terminal.");
2493
2494#define OS_FORKPTY_METHODDEF \
2495 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2496
2497static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002498os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002499
2500static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002501os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002502{
2503 return os_forkpty_impl(module);
2504}
2505
2506#endif /* defined(HAVE_FORKPTY) */
2507
2508#if defined(HAVE_GETEGID)
2509
2510PyDoc_STRVAR(os_getegid__doc__,
2511"getegid($module, /)\n"
2512"--\n"
2513"\n"
2514"Return the current process\'s effective group id.");
2515
2516#define OS_GETEGID_METHODDEF \
2517 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2518
2519static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002520os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002521
2522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002523os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002524{
2525 return os_getegid_impl(module);
2526}
2527
2528#endif /* defined(HAVE_GETEGID) */
2529
2530#if defined(HAVE_GETEUID)
2531
2532PyDoc_STRVAR(os_geteuid__doc__,
2533"geteuid($module, /)\n"
2534"--\n"
2535"\n"
2536"Return the current process\'s effective user id.");
2537
2538#define OS_GETEUID_METHODDEF \
2539 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2540
2541static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002542os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002543
2544static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002545os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002546{
2547 return os_geteuid_impl(module);
2548}
2549
2550#endif /* defined(HAVE_GETEUID) */
2551
2552#if defined(HAVE_GETGID)
2553
2554PyDoc_STRVAR(os_getgid__doc__,
2555"getgid($module, /)\n"
2556"--\n"
2557"\n"
2558"Return the current process\'s group id.");
2559
2560#define OS_GETGID_METHODDEF \
2561 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2562
2563static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002564os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002565
2566static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002567os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002568{
2569 return os_getgid_impl(module);
2570}
2571
2572#endif /* defined(HAVE_GETGID) */
2573
Berker Peksag39404992016-09-15 20:45:16 +03002574#if defined(HAVE_GETPID)
2575
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002576PyDoc_STRVAR(os_getpid__doc__,
2577"getpid($module, /)\n"
2578"--\n"
2579"\n"
2580"Return the current process id.");
2581
2582#define OS_GETPID_METHODDEF \
2583 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2584
2585static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002586os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002587
2588static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002589os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002590{
2591 return os_getpid_impl(module);
2592}
2593
Berker Peksag39404992016-09-15 20:45:16 +03002594#endif /* defined(HAVE_GETPID) */
2595
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002596#if defined(HAVE_GETGROUPS)
2597
2598PyDoc_STRVAR(os_getgroups__doc__,
2599"getgroups($module, /)\n"
2600"--\n"
2601"\n"
2602"Return list of supplemental group IDs for the process.");
2603
2604#define OS_GETGROUPS_METHODDEF \
2605 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2606
2607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002608os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002609
2610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002611os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002612{
2613 return os_getgroups_impl(module);
2614}
2615
2616#endif /* defined(HAVE_GETGROUPS) */
2617
2618#if defined(HAVE_GETPGID)
2619
2620PyDoc_STRVAR(os_getpgid__doc__,
2621"getpgid($module, /, pid)\n"
2622"--\n"
2623"\n"
2624"Call the system call getpgid(), and return the result.");
2625
2626#define OS_GETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002627 {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002628
2629static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002630os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002631
2632static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002633os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002634{
2635 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002636 static const char * const _keywords[] = {"pid", NULL};
2637 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002638 pid_t pid;
2639
Victor Stinner3e1fad62017-01-17 01:29:01 +01002640 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002641 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002642 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002643 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002644 return_value = os_getpgid_impl(module, pid);
2645
2646exit:
2647 return return_value;
2648}
2649
2650#endif /* defined(HAVE_GETPGID) */
2651
2652#if defined(HAVE_GETPGRP)
2653
2654PyDoc_STRVAR(os_getpgrp__doc__,
2655"getpgrp($module, /)\n"
2656"--\n"
2657"\n"
2658"Return the current process group id.");
2659
2660#define OS_GETPGRP_METHODDEF \
2661 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2662
2663static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002664os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002665
2666static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002667os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002668{
2669 return os_getpgrp_impl(module);
2670}
2671
2672#endif /* defined(HAVE_GETPGRP) */
2673
2674#if defined(HAVE_SETPGRP)
2675
2676PyDoc_STRVAR(os_setpgrp__doc__,
2677"setpgrp($module, /)\n"
2678"--\n"
2679"\n"
2680"Make the current process the leader of its process group.");
2681
2682#define OS_SETPGRP_METHODDEF \
2683 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2684
2685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002686os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002687
2688static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002689os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002690{
2691 return os_setpgrp_impl(module);
2692}
2693
2694#endif /* defined(HAVE_SETPGRP) */
2695
2696#if defined(HAVE_GETPPID)
2697
2698PyDoc_STRVAR(os_getppid__doc__,
2699"getppid($module, /)\n"
2700"--\n"
2701"\n"
2702"Return the parent\'s process id.\n"
2703"\n"
2704"If the parent process has already exited, Windows machines will still\n"
2705"return its id; others systems will return the id of the \'init\' process (1).");
2706
2707#define OS_GETPPID_METHODDEF \
2708 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2709
2710static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002711os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002712
2713static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002714os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002715{
2716 return os_getppid_impl(module);
2717}
2718
2719#endif /* defined(HAVE_GETPPID) */
2720
2721#if defined(HAVE_GETLOGIN)
2722
2723PyDoc_STRVAR(os_getlogin__doc__,
2724"getlogin($module, /)\n"
2725"--\n"
2726"\n"
2727"Return the actual login name.");
2728
2729#define OS_GETLOGIN_METHODDEF \
2730 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2731
2732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002733os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002734
2735static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002736os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002737{
2738 return os_getlogin_impl(module);
2739}
2740
2741#endif /* defined(HAVE_GETLOGIN) */
2742
2743#if defined(HAVE_GETUID)
2744
2745PyDoc_STRVAR(os_getuid__doc__,
2746"getuid($module, /)\n"
2747"--\n"
2748"\n"
2749"Return the current process\'s user id.");
2750
2751#define OS_GETUID_METHODDEF \
2752 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2753
2754static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002755os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002756
2757static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002758os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002759{
2760 return os_getuid_impl(module);
2761}
2762
2763#endif /* defined(HAVE_GETUID) */
2764
2765#if defined(HAVE_KILL)
2766
2767PyDoc_STRVAR(os_kill__doc__,
2768"kill($module, pid, signal, /)\n"
2769"--\n"
2770"\n"
2771"Kill a process with a signal.");
2772
2773#define OS_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002774 {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002775
2776static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002777os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002778
2779static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002780os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002781{
2782 PyObject *return_value = NULL;
2783 pid_t pid;
2784 Py_ssize_t signal;
2785
Sylvain74453812017-06-10 06:51:48 +02002786 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2787 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002788 goto exit;
2789 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002790 return_value = os_kill_impl(module, pid, signal);
2791
2792exit:
2793 return return_value;
2794}
2795
2796#endif /* defined(HAVE_KILL) */
2797
2798#if defined(HAVE_KILLPG)
2799
2800PyDoc_STRVAR(os_killpg__doc__,
2801"killpg($module, pgid, signal, /)\n"
2802"--\n"
2803"\n"
2804"Kill a process group with a signal.");
2805
2806#define OS_KILLPG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002807 {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002808
2809static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002810os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002811
2812static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002813os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002814{
2815 PyObject *return_value = NULL;
2816 pid_t pgid;
2817 int signal;
2818
Sylvain74453812017-06-10 06:51:48 +02002819 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2820 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002821 goto exit;
2822 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002823 return_value = os_killpg_impl(module, pgid, signal);
2824
2825exit:
2826 return return_value;
2827}
2828
2829#endif /* defined(HAVE_KILLPG) */
2830
2831#if defined(HAVE_PLOCK)
2832
2833PyDoc_STRVAR(os_plock__doc__,
2834"plock($module, op, /)\n"
2835"--\n"
2836"\n"
2837"Lock program segments into memory.\");");
2838
2839#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002840 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002841
2842static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002843os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002844
2845static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002846os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002847{
2848 PyObject *return_value = NULL;
2849 int op;
2850
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002851 if (PyFloat_Check(arg)) {
2852 PyErr_SetString(PyExc_TypeError,
2853 "integer argument expected, got float" );
2854 goto exit;
2855 }
2856 op = _PyLong_AsInt(arg);
2857 if (op == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002858 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002859 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002860 return_value = os_plock_impl(module, op);
2861
2862exit:
2863 return return_value;
2864}
2865
2866#endif /* defined(HAVE_PLOCK) */
2867
2868#if defined(HAVE_SETUID)
2869
2870PyDoc_STRVAR(os_setuid__doc__,
2871"setuid($module, uid, /)\n"
2872"--\n"
2873"\n"
2874"Set the current process\'s user id.");
2875
2876#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002877 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002878
2879static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002880os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002881
2882static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002883os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002884{
2885 PyObject *return_value = NULL;
2886 uid_t uid;
2887
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002888 if (!_Py_Uid_Converter(arg, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002889 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002890 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002891 return_value = os_setuid_impl(module, uid);
2892
2893exit:
2894 return return_value;
2895}
2896
2897#endif /* defined(HAVE_SETUID) */
2898
2899#if defined(HAVE_SETEUID)
2900
2901PyDoc_STRVAR(os_seteuid__doc__,
2902"seteuid($module, euid, /)\n"
2903"--\n"
2904"\n"
2905"Set the current process\'s effective user id.");
2906
2907#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002908 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002909
2910static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002911os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912
2913static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002914os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002915{
2916 PyObject *return_value = NULL;
2917 uid_t euid;
2918
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002919 if (!_Py_Uid_Converter(arg, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002921 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002922 return_value = os_seteuid_impl(module, euid);
2923
2924exit:
2925 return return_value;
2926}
2927
2928#endif /* defined(HAVE_SETEUID) */
2929
2930#if defined(HAVE_SETEGID)
2931
2932PyDoc_STRVAR(os_setegid__doc__,
2933"setegid($module, egid, /)\n"
2934"--\n"
2935"\n"
2936"Set the current process\'s effective group id.");
2937
2938#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002939 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002940
2941static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002942os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002943
2944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002945os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002946{
2947 PyObject *return_value = NULL;
2948 gid_t egid;
2949
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002950 if (!_Py_Gid_Converter(arg, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002951 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002952 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002953 return_value = os_setegid_impl(module, egid);
2954
2955exit:
2956 return return_value;
2957}
2958
2959#endif /* defined(HAVE_SETEGID) */
2960
2961#if defined(HAVE_SETREUID)
2962
2963PyDoc_STRVAR(os_setreuid__doc__,
2964"setreuid($module, ruid, euid, /)\n"
2965"--\n"
2966"\n"
2967"Set the current process\'s real and effective user ids.");
2968
2969#define OS_SETREUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002970 {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002971
2972static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002973os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002974
2975static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002976os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002977{
2978 PyObject *return_value = NULL;
2979 uid_t ruid;
2980 uid_t euid;
2981
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002982 if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
2983 goto exit;
2984 }
2985 if (!_Py_Uid_Converter(args[0], &ruid)) {
2986 goto exit;
2987 }
2988 if (!_Py_Uid_Converter(args[1], &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002989 goto exit;
2990 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002991 return_value = os_setreuid_impl(module, ruid, euid);
2992
2993exit:
2994 return return_value;
2995}
2996
2997#endif /* defined(HAVE_SETREUID) */
2998
2999#if defined(HAVE_SETREGID)
3000
3001PyDoc_STRVAR(os_setregid__doc__,
3002"setregid($module, rgid, egid, /)\n"
3003"--\n"
3004"\n"
3005"Set the current process\'s real and effective group ids.");
3006
3007#define OS_SETREGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003008 {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003009
3010static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003011os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003012
3013static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003014os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003015{
3016 PyObject *return_value = NULL;
3017 gid_t rgid;
3018 gid_t egid;
3019
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003020 if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
3021 goto exit;
3022 }
3023 if (!_Py_Gid_Converter(args[0], &rgid)) {
3024 goto exit;
3025 }
3026 if (!_Py_Gid_Converter(args[1], &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003027 goto exit;
3028 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003029 return_value = os_setregid_impl(module, rgid, egid);
3030
3031exit:
3032 return return_value;
3033}
3034
3035#endif /* defined(HAVE_SETREGID) */
3036
3037#if defined(HAVE_SETGID)
3038
3039PyDoc_STRVAR(os_setgid__doc__,
3040"setgid($module, gid, /)\n"
3041"--\n"
3042"\n"
3043"Set the current process\'s group id.");
3044
3045#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003046 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003047
3048static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003049os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003050
3051static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003052os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003053{
3054 PyObject *return_value = NULL;
3055 gid_t gid;
3056
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003057 if (!_Py_Gid_Converter(arg, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003058 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003059 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003060 return_value = os_setgid_impl(module, gid);
3061
3062exit:
3063 return return_value;
3064}
3065
3066#endif /* defined(HAVE_SETGID) */
3067
3068#if defined(HAVE_SETGROUPS)
3069
3070PyDoc_STRVAR(os_setgroups__doc__,
3071"setgroups($module, groups, /)\n"
3072"--\n"
3073"\n"
3074"Set the groups of the current process to list.");
3075
3076#define OS_SETGROUPS_METHODDEF \
3077 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
3078
3079#endif /* defined(HAVE_SETGROUPS) */
3080
3081#if defined(HAVE_WAIT3)
3082
3083PyDoc_STRVAR(os_wait3__doc__,
3084"wait3($module, /, options)\n"
3085"--\n"
3086"\n"
3087"Wait for completion of a child process.\n"
3088"\n"
3089"Returns a tuple of information about the child process:\n"
3090" (pid, status, rusage)");
3091
3092#define OS_WAIT3_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003093 {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003094
3095static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003096os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003097
3098static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003099os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003100{
3101 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003102 static const char * const _keywords[] = {"options", NULL};
3103 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003104 int options;
3105
Victor Stinner3e1fad62017-01-17 01:29:01 +01003106 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003107 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003110 return_value = os_wait3_impl(module, options);
3111
3112exit:
3113 return return_value;
3114}
3115
3116#endif /* defined(HAVE_WAIT3) */
3117
3118#if defined(HAVE_WAIT4)
3119
3120PyDoc_STRVAR(os_wait4__doc__,
3121"wait4($module, /, pid, options)\n"
3122"--\n"
3123"\n"
3124"Wait for completion of a specific child process.\n"
3125"\n"
3126"Returns a tuple of information about the child process:\n"
3127" (pid, status, rusage)");
3128
3129#define OS_WAIT4_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003130 {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003131
3132static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003133os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003134
3135static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003136os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003137{
3138 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003139 static const char * const _keywords[] = {"pid", "options", NULL};
3140 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003141 pid_t pid;
3142 int options;
3143
Victor Stinner3e1fad62017-01-17 01:29:01 +01003144 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003145 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003146 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003147 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003148 return_value = os_wait4_impl(module, pid, options);
3149
3150exit:
3151 return return_value;
3152}
3153
3154#endif /* defined(HAVE_WAIT4) */
3155
3156#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3157
3158PyDoc_STRVAR(os_waitid__doc__,
3159"waitid($module, idtype, id, options, /)\n"
3160"--\n"
3161"\n"
3162"Returns the result of waiting for a process or processes.\n"
3163"\n"
3164" idtype\n"
3165" Must be one of be P_PID, P_PGID or P_ALL.\n"
3166" id\n"
3167" The id to wait on.\n"
3168" options\n"
3169" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3170" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3171"\n"
3172"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3173"no children in a waitable state.");
3174
3175#define OS_WAITID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003176 {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003177
3178static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003179os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003180
3181static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003182os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003183{
3184 PyObject *return_value = NULL;
3185 idtype_t idtype;
3186 id_t id;
3187 int options;
3188
Sylvain74453812017-06-10 06:51:48 +02003189 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3190 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003191 goto exit;
3192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003193 return_value = os_waitid_impl(module, idtype, id, options);
3194
3195exit:
3196 return return_value;
3197}
3198
3199#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3200
3201#if defined(HAVE_WAITPID)
3202
3203PyDoc_STRVAR(os_waitpid__doc__,
3204"waitpid($module, pid, options, /)\n"
3205"--\n"
3206"\n"
3207"Wait for completion of a given child process.\n"
3208"\n"
3209"Returns a tuple of information regarding the child process:\n"
3210" (pid, status)\n"
3211"\n"
3212"The options argument is ignored on Windows.");
3213
3214#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003215 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003216
3217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003218os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003219
3220static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003221os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003222{
3223 PyObject *return_value = NULL;
3224 pid_t pid;
3225 int options;
3226
Sylvain74453812017-06-10 06:51:48 +02003227 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3228 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003229 goto exit;
3230 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003231 return_value = os_waitpid_impl(module, pid, options);
3232
3233exit:
3234 return return_value;
3235}
3236
3237#endif /* defined(HAVE_WAITPID) */
3238
3239#if defined(HAVE_CWAIT)
3240
3241PyDoc_STRVAR(os_waitpid__doc__,
3242"waitpid($module, pid, options, /)\n"
3243"--\n"
3244"\n"
3245"Wait for completion of a given process.\n"
3246"\n"
3247"Returns a tuple of information regarding the process:\n"
3248" (pid, status << 8)\n"
3249"\n"
3250"The options argument is ignored on Windows.");
3251
3252#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003253 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003254
3255static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003256os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003257
3258static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003259os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003260{
3261 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003262 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003263 int options;
3264
Sylvain74453812017-06-10 06:51:48 +02003265 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3266 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003267 goto exit;
3268 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003269 return_value = os_waitpid_impl(module, pid, options);
3270
3271exit:
3272 return return_value;
3273}
3274
3275#endif /* defined(HAVE_CWAIT) */
3276
3277#if defined(HAVE_WAIT)
3278
3279PyDoc_STRVAR(os_wait__doc__,
3280"wait($module, /)\n"
3281"--\n"
3282"\n"
3283"Wait for completion of a child process.\n"
3284"\n"
3285"Returns a tuple of information about the child process:\n"
3286" (pid, status)");
3287
3288#define OS_WAIT_METHODDEF \
3289 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3290
3291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003292os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003293
3294static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003295os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003296{
3297 return os_wait_impl(module);
3298}
3299
3300#endif /* defined(HAVE_WAIT) */
3301
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003302#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3303
3304PyDoc_STRVAR(os_readlink__doc__,
3305"readlink($module, /, path, *, dir_fd=None)\n"
3306"--\n"
3307"\n"
3308"Return a string representing the path to which the symbolic link points.\n"
3309"\n"
3310"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3311"and path should be relative; path will then be relative to that directory.\n"
3312"\n"
3313"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3314"using it will raise a NotImplementedError.");
3315
3316#define OS_READLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003317 {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003318
3319static PyObject *
3320os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3321
3322static PyObject *
3323os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3324{
3325 PyObject *return_value = NULL;
3326 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3327 static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0};
3328 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3329 int dir_fd = DEFAULT_DIR_FD;
3330
3331 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3332 path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3333 goto exit;
3334 }
3335 return_value = os_readlink_impl(module, &path, dir_fd);
3336
3337exit:
3338 /* Cleanup for path */
3339 path_cleanup(&path);
3340
3341 return return_value;
3342}
3343
3344#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
3345
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003346#if defined(HAVE_SYMLINK)
3347
3348PyDoc_STRVAR(os_symlink__doc__,
3349"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3350"--\n"
3351"\n"
3352"Create a symbolic link pointing to src named dst.\n"
3353"\n"
3354"target_is_directory is required on Windows if the target is to be\n"
3355" interpreted as a directory. (On Windows, symlink requires\n"
3356" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3357" target_is_directory is ignored on non-Windows platforms.\n"
3358"\n"
3359"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3360" and path should be relative; path will then be relative to that directory.\n"
3361"dir_fd may not be implemented on your platform.\n"
3362" If it is unavailable, using it will raise a NotImplementedError.");
3363
3364#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003365 {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003366
3367static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003368os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003369 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003370
3371static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003372os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003373{
3374 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003375 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3376 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003377 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3378 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3379 int target_is_directory = 0;
3380 int dir_fd = DEFAULT_DIR_FD;
3381
Victor Stinner3e1fad62017-01-17 01:29:01 +01003382 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003383 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003386 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3387
3388exit:
3389 /* Cleanup for src */
3390 path_cleanup(&src);
3391 /* Cleanup for dst */
3392 path_cleanup(&dst);
3393
3394 return return_value;
3395}
3396
3397#endif /* defined(HAVE_SYMLINK) */
3398
3399#if defined(HAVE_TIMES)
3400
3401PyDoc_STRVAR(os_times__doc__,
3402"times($module, /)\n"
3403"--\n"
3404"\n"
3405"Return a collection containing process timing information.\n"
3406"\n"
3407"The object returned behaves like a named tuple with these fields:\n"
3408" (utime, stime, cutime, cstime, elapsed_time)\n"
3409"All fields are floating point numbers.");
3410
3411#define OS_TIMES_METHODDEF \
3412 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3413
3414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003415os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003416
3417static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003418os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003419{
3420 return os_times_impl(module);
3421}
3422
3423#endif /* defined(HAVE_TIMES) */
3424
3425#if defined(HAVE_GETSID)
3426
3427PyDoc_STRVAR(os_getsid__doc__,
3428"getsid($module, pid, /)\n"
3429"--\n"
3430"\n"
3431"Call the system call getsid(pid) and return the result.");
3432
3433#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003434 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003435
3436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003437os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003438
3439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003440os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003441{
3442 PyObject *return_value = NULL;
3443 pid_t pid;
3444
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003445 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003446 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003447 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003448 return_value = os_getsid_impl(module, pid);
3449
3450exit:
3451 return return_value;
3452}
3453
3454#endif /* defined(HAVE_GETSID) */
3455
3456#if defined(HAVE_SETSID)
3457
3458PyDoc_STRVAR(os_setsid__doc__,
3459"setsid($module, /)\n"
3460"--\n"
3461"\n"
3462"Call the system call setsid().");
3463
3464#define OS_SETSID_METHODDEF \
3465 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3466
3467static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003468os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003469
3470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003471os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003472{
3473 return os_setsid_impl(module);
3474}
3475
3476#endif /* defined(HAVE_SETSID) */
3477
3478#if defined(HAVE_SETPGID)
3479
3480PyDoc_STRVAR(os_setpgid__doc__,
3481"setpgid($module, pid, pgrp, /)\n"
3482"--\n"
3483"\n"
3484"Call the system call setpgid(pid, pgrp).");
3485
3486#define OS_SETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003487 {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003488
3489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003490os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003491
3492static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003493os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003494{
3495 PyObject *return_value = NULL;
3496 pid_t pid;
3497 pid_t pgrp;
3498
Sylvain74453812017-06-10 06:51:48 +02003499 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3500 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003501 goto exit;
3502 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003503 return_value = os_setpgid_impl(module, pid, pgrp);
3504
3505exit:
3506 return return_value;
3507}
3508
3509#endif /* defined(HAVE_SETPGID) */
3510
3511#if defined(HAVE_TCGETPGRP)
3512
3513PyDoc_STRVAR(os_tcgetpgrp__doc__,
3514"tcgetpgrp($module, fd, /)\n"
3515"--\n"
3516"\n"
3517"Return the process group associated with the terminal specified by fd.");
3518
3519#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003520 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003521
3522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003523os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003524
3525static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003526os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003527{
3528 PyObject *return_value = NULL;
3529 int fd;
3530
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003531 if (PyFloat_Check(arg)) {
3532 PyErr_SetString(PyExc_TypeError,
3533 "integer argument expected, got float" );
3534 goto exit;
3535 }
3536 fd = _PyLong_AsInt(arg);
3537 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003538 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003539 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003540 return_value = os_tcgetpgrp_impl(module, fd);
3541
3542exit:
3543 return return_value;
3544}
3545
3546#endif /* defined(HAVE_TCGETPGRP) */
3547
3548#if defined(HAVE_TCSETPGRP)
3549
3550PyDoc_STRVAR(os_tcsetpgrp__doc__,
3551"tcsetpgrp($module, fd, pgid, /)\n"
3552"--\n"
3553"\n"
3554"Set the process group associated with the terminal specified by fd.");
3555
3556#define OS_TCSETPGRP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003557 {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003558
3559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003560os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003561
3562static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003563os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003564{
3565 PyObject *return_value = NULL;
3566 int fd;
3567 pid_t pgid;
3568
Sylvain74453812017-06-10 06:51:48 +02003569 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3570 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003571 goto exit;
3572 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003573 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3574
3575exit:
3576 return return_value;
3577}
3578
3579#endif /* defined(HAVE_TCSETPGRP) */
3580
3581PyDoc_STRVAR(os_open__doc__,
3582"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3583"--\n"
3584"\n"
3585"Open a file for low level IO. Returns a file descriptor (integer).\n"
3586"\n"
3587"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3588" and path should be relative; path will then be relative to that directory.\n"
3589"dir_fd may not be implemented on your platform.\n"
3590" If it is unavailable, using it will raise a NotImplementedError.");
3591
3592#define OS_OPEN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003593 {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003594
3595static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003596os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003597
3598static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003599os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003600{
3601 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003602 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3603 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3605 int flags;
3606 int mode = 511;
3607 int dir_fd = DEFAULT_DIR_FD;
3608 int _return_value;
3609
Victor Stinner3e1fad62017-01-17 01:29:01 +01003610 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003611 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003612 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003613 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003614 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003615 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003616 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003617 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003618 return_value = PyLong_FromLong((long)_return_value);
3619
3620exit:
3621 /* Cleanup for path */
3622 path_cleanup(&path);
3623
3624 return return_value;
3625}
3626
3627PyDoc_STRVAR(os_close__doc__,
3628"close($module, /, fd)\n"
3629"--\n"
3630"\n"
3631"Close a file descriptor.");
3632
3633#define OS_CLOSE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003634 {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003635
3636static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003637os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003638
3639static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003640os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003641{
3642 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003643 static const char * const _keywords[] = {"fd", NULL};
3644 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003645 int fd;
3646
Victor Stinner3e1fad62017-01-17 01:29:01 +01003647 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003648 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003649 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003650 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003651 return_value = os_close_impl(module, fd);
3652
3653exit:
3654 return return_value;
3655}
3656
3657PyDoc_STRVAR(os_closerange__doc__,
3658"closerange($module, fd_low, fd_high, /)\n"
3659"--\n"
3660"\n"
3661"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3662
3663#define OS_CLOSERANGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003664 {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003665
3666static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003667os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003668
3669static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003670os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003671{
3672 PyObject *return_value = NULL;
3673 int fd_low;
3674 int fd_high;
3675
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003676 if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
3677 goto exit;
3678 }
3679 if (PyFloat_Check(args[0])) {
3680 PyErr_SetString(PyExc_TypeError,
3681 "integer argument expected, got float" );
3682 goto exit;
3683 }
3684 fd_low = _PyLong_AsInt(args[0]);
3685 if (fd_low == -1 && PyErr_Occurred()) {
3686 goto exit;
3687 }
3688 if (PyFloat_Check(args[1])) {
3689 PyErr_SetString(PyExc_TypeError,
3690 "integer argument expected, got float" );
3691 goto exit;
3692 }
3693 fd_high = _PyLong_AsInt(args[1]);
3694 if (fd_high == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003695 goto exit;
3696 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003697 return_value = os_closerange_impl(module, fd_low, fd_high);
3698
3699exit:
3700 return return_value;
3701}
3702
3703PyDoc_STRVAR(os_dup__doc__,
3704"dup($module, fd, /)\n"
3705"--\n"
3706"\n"
3707"Return a duplicate of a file descriptor.");
3708
3709#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003710 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003711
3712static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003713os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003714
3715static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003716os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717{
3718 PyObject *return_value = NULL;
3719 int fd;
3720 int _return_value;
3721
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003722 if (PyFloat_Check(arg)) {
3723 PyErr_SetString(PyExc_TypeError,
3724 "integer argument expected, got float" );
3725 goto exit;
3726 }
3727 fd = _PyLong_AsInt(arg);
3728 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003729 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003730 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003731 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003732 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003733 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003734 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003735 return_value = PyLong_FromLong((long)_return_value);
3736
3737exit:
3738 return return_value;
3739}
3740
3741PyDoc_STRVAR(os_dup2__doc__,
3742"dup2($module, /, fd, fd2, inheritable=True)\n"
3743"--\n"
3744"\n"
3745"Duplicate file descriptor.");
3746
3747#define OS_DUP2_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003748 {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003749
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003750static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003751os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003752
3753static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003754os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003755{
3756 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003757 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3758 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003759 int fd;
3760 int fd2;
3761 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003762 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003763
Victor Stinner3e1fad62017-01-17 01:29:01 +01003764 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003765 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003766 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003767 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003768 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3769 if ((_return_value == -1) && PyErr_Occurred()) {
3770 goto exit;
3771 }
3772 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003773
3774exit:
3775 return return_value;
3776}
3777
3778#if defined(HAVE_LOCKF)
3779
3780PyDoc_STRVAR(os_lockf__doc__,
3781"lockf($module, fd, command, length, /)\n"
3782"--\n"
3783"\n"
3784"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3785"\n"
3786" fd\n"
3787" An open file descriptor.\n"
3788" command\n"
3789" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3790" length\n"
3791" The number of bytes to lock, starting at the current position.");
3792
3793#define OS_LOCKF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003794 {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003795
3796static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003797os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003798
3799static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003800os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003801{
3802 PyObject *return_value = NULL;
3803 int fd;
3804 int command;
3805 Py_off_t length;
3806
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003807 if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
3808 goto exit;
3809 }
3810 if (PyFloat_Check(args[0])) {
3811 PyErr_SetString(PyExc_TypeError,
3812 "integer argument expected, got float" );
3813 goto exit;
3814 }
3815 fd = _PyLong_AsInt(args[0]);
3816 if (fd == -1 && PyErr_Occurred()) {
3817 goto exit;
3818 }
3819 if (PyFloat_Check(args[1])) {
3820 PyErr_SetString(PyExc_TypeError,
3821 "integer argument expected, got float" );
3822 goto exit;
3823 }
3824 command = _PyLong_AsInt(args[1]);
3825 if (command == -1 && PyErr_Occurred()) {
3826 goto exit;
3827 }
3828 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003829 goto exit;
3830 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003831 return_value = os_lockf_impl(module, fd, command, length);
3832
3833exit:
3834 return return_value;
3835}
3836
3837#endif /* defined(HAVE_LOCKF) */
3838
3839PyDoc_STRVAR(os_lseek__doc__,
3840"lseek($module, fd, position, how, /)\n"
3841"--\n"
3842"\n"
3843"Set the position of a file descriptor. Return the new position.\n"
3844"\n"
3845"Return the new cursor position in number of bytes\n"
3846"relative to the beginning of the file.");
3847
3848#define OS_LSEEK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003849 {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003850
3851static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003852os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003853
3854static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003855os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003856{
3857 PyObject *return_value = NULL;
3858 int fd;
3859 Py_off_t position;
3860 int how;
3861 Py_off_t _return_value;
3862
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003863 if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
3864 goto exit;
3865 }
3866 if (PyFloat_Check(args[0])) {
3867 PyErr_SetString(PyExc_TypeError,
3868 "integer argument expected, got float" );
3869 goto exit;
3870 }
3871 fd = _PyLong_AsInt(args[0]);
3872 if (fd == -1 && PyErr_Occurred()) {
3873 goto exit;
3874 }
3875 if (!Py_off_t_converter(args[1], &position)) {
3876 goto exit;
3877 }
3878 if (PyFloat_Check(args[2])) {
3879 PyErr_SetString(PyExc_TypeError,
3880 "integer argument expected, got float" );
3881 goto exit;
3882 }
3883 how = _PyLong_AsInt(args[2]);
3884 if (how == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003885 goto exit;
3886 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003887 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003888 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003889 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003890 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003891 return_value = PyLong_FromPy_off_t(_return_value);
3892
3893exit:
3894 return return_value;
3895}
3896
3897PyDoc_STRVAR(os_read__doc__,
3898"read($module, fd, length, /)\n"
3899"--\n"
3900"\n"
3901"Read from a file descriptor. Returns a bytes object.");
3902
3903#define OS_READ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003904 {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003905
3906static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003907os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003908
3909static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003910os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003911{
3912 PyObject *return_value = NULL;
3913 int fd;
3914 Py_ssize_t length;
3915
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003916 if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003917 goto exit;
3918 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003919 if (PyFloat_Check(args[0])) {
3920 PyErr_SetString(PyExc_TypeError,
3921 "integer argument expected, got float" );
3922 goto exit;
3923 }
3924 fd = _PyLong_AsInt(args[0]);
3925 if (fd == -1 && PyErr_Occurred()) {
3926 goto exit;
3927 }
3928 if (PyFloat_Check(args[1])) {
3929 PyErr_SetString(PyExc_TypeError,
3930 "integer argument expected, got float" );
3931 goto exit;
3932 }
3933 {
3934 Py_ssize_t ival = -1;
3935 PyObject *iobj = PyNumber_Index(args[1]);
3936 if (iobj != NULL) {
3937 ival = PyLong_AsSsize_t(iobj);
3938 Py_DECREF(iobj);
3939 }
3940 if (ival == -1 && PyErr_Occurred()) {
3941 goto exit;
3942 }
3943 length = ival;
3944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003945 return_value = os_read_impl(module, fd, length);
3946
3947exit:
3948 return return_value;
3949}
3950
3951#if defined(HAVE_READV)
3952
3953PyDoc_STRVAR(os_readv__doc__,
3954"readv($module, fd, buffers, /)\n"
3955"--\n"
3956"\n"
3957"Read from a file descriptor fd into an iterable of buffers.\n"
3958"\n"
3959"The buffers should be mutable buffers accepting bytes.\n"
3960"readv will transfer data into each buffer until it is full\n"
3961"and then move on to the next buffer in the sequence to hold\n"
3962"the rest of the data.\n"
3963"\n"
3964"readv returns the total number of bytes read,\n"
3965"which may be less than the total capacity of all the buffers.");
3966
3967#define OS_READV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003968 {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003969
3970static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003971os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003972
3973static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003974os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003975{
3976 PyObject *return_value = NULL;
3977 int fd;
3978 PyObject *buffers;
3979 Py_ssize_t _return_value;
3980
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003981 if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003982 goto exit;
3983 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003984 if (PyFloat_Check(args[0])) {
3985 PyErr_SetString(PyExc_TypeError,
3986 "integer argument expected, got float" );
3987 goto exit;
3988 }
3989 fd = _PyLong_AsInt(args[0]);
3990 if (fd == -1 && PyErr_Occurred()) {
3991 goto exit;
3992 }
3993 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003994 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003995 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003996 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003997 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003998 return_value = PyLong_FromSsize_t(_return_value);
3999
4000exit:
4001 return return_value;
4002}
4003
4004#endif /* defined(HAVE_READV) */
4005
4006#if defined(HAVE_PREAD)
4007
4008PyDoc_STRVAR(os_pread__doc__,
4009"pread($module, fd, length, offset, /)\n"
4010"--\n"
4011"\n"
4012"Read a number of bytes from a file descriptor starting at a particular offset.\n"
4013"\n"
4014"Read length bytes from file descriptor fd, starting at offset bytes from\n"
4015"the beginning of the file. The file offset remains unchanged.");
4016
4017#define OS_PREAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004018 {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004019
4020static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004021os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004022
4023static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004024os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004025{
4026 PyObject *return_value = NULL;
4027 int fd;
4028 int length;
4029 Py_off_t offset;
4030
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004031 if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
4032 goto exit;
4033 }
4034 if (PyFloat_Check(args[0])) {
4035 PyErr_SetString(PyExc_TypeError,
4036 "integer argument expected, got float" );
4037 goto exit;
4038 }
4039 fd = _PyLong_AsInt(args[0]);
4040 if (fd == -1 && PyErr_Occurred()) {
4041 goto exit;
4042 }
4043 if (PyFloat_Check(args[1])) {
4044 PyErr_SetString(PyExc_TypeError,
4045 "integer argument expected, got float" );
4046 goto exit;
4047 }
4048 length = _PyLong_AsInt(args[1]);
4049 if (length == -1 && PyErr_Occurred()) {
4050 goto exit;
4051 }
4052 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004053 goto exit;
4054 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004055 return_value = os_pread_impl(module, fd, length, offset);
4056
4057exit:
4058 return return_value;
4059}
4060
4061#endif /* defined(HAVE_PREAD) */
4062
Pablo Galindo4defba32018-01-27 16:16:37 +00004063#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
4064
4065PyDoc_STRVAR(os_preadv__doc__,
4066"preadv($module, fd, buffers, offset, flags=0, /)\n"
4067"--\n"
4068"\n"
4069"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
4070"\n"
4071"Combines the functionality of readv() and pread(). As readv(), it will\n"
4072"transfer data into each buffer until it is full and then move on to the next\n"
4073"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
4074"specifies the file offset at which the input operation is to be performed. It\n"
4075"will return the total number of bytes read (which can be less than the total\n"
4076"capacity of all the objects).\n"
4077"\n"
4078"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4079"\n"
4080"- RWF_HIPRI\n"
4081"- RWF_NOWAIT\n"
4082"\n"
4083"Using non-zero flags requires Linux 4.6 or newer.");
4084
4085#define OS_PREADV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004086 {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004087
4088static Py_ssize_t
4089os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4090 int flags);
4091
4092static PyObject *
4093os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4094{
4095 PyObject *return_value = NULL;
4096 int fd;
4097 PyObject *buffers;
4098 Py_off_t offset;
4099 int flags = 0;
4100 Py_ssize_t _return_value;
4101
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004102 if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00004103 goto exit;
4104 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004105 if (PyFloat_Check(args[0])) {
4106 PyErr_SetString(PyExc_TypeError,
4107 "integer argument expected, got float" );
4108 goto exit;
4109 }
4110 fd = _PyLong_AsInt(args[0]);
4111 if (fd == -1 && PyErr_Occurred()) {
4112 goto exit;
4113 }
4114 buffers = args[1];
4115 if (!Py_off_t_converter(args[2], &offset)) {
4116 goto exit;
4117 }
4118 if (nargs < 4) {
4119 goto skip_optional;
4120 }
4121 if (PyFloat_Check(args[3])) {
4122 PyErr_SetString(PyExc_TypeError,
4123 "integer argument expected, got float" );
4124 goto exit;
4125 }
4126 flags = _PyLong_AsInt(args[3]);
4127 if (flags == -1 && PyErr_Occurred()) {
4128 goto exit;
4129 }
4130skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00004131 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
4132 if ((_return_value == -1) && PyErr_Occurred()) {
4133 goto exit;
4134 }
4135 return_value = PyLong_FromSsize_t(_return_value);
4136
4137exit:
4138 return return_value;
4139}
4140
4141#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
4142
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004143PyDoc_STRVAR(os_write__doc__,
4144"write($module, fd, data, /)\n"
4145"--\n"
4146"\n"
4147"Write a bytes object to a file descriptor.");
4148
4149#define OS_WRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004150 {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004151
4152static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004153os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004154
4155static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004156os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004157{
4158 PyObject *return_value = NULL;
4159 int fd;
4160 Py_buffer data = {NULL, NULL};
4161 Py_ssize_t _return_value;
4162
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004163 if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
4164 goto exit;
4165 }
4166 if (PyFloat_Check(args[0])) {
4167 PyErr_SetString(PyExc_TypeError,
4168 "integer argument expected, got float" );
4169 goto exit;
4170 }
4171 fd = _PyLong_AsInt(args[0]);
4172 if (fd == -1 && PyErr_Occurred()) {
4173 goto exit;
4174 }
4175 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
4176 goto exit;
4177 }
4178 if (!PyBuffer_IsContiguous(&data, 'C')) {
4179 _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]);
Victor Stinner259f0e42017-01-17 01:35:17 +01004180 goto exit;
4181 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004182 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004183 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004184 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004185 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004186 return_value = PyLong_FromSsize_t(_return_value);
4187
4188exit:
4189 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004190 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004191 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004192 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004193
4194 return return_value;
4195}
4196
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004197#if defined(__APPLE__)
4198
4199PyDoc_STRVAR(os__fcopyfile__doc__,
4200"_fcopyfile($module, infd, outfd, flags, /)\n"
4201"--\n"
4202"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07004203"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004204
4205#define OS__FCOPYFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004206 {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004207
4208static PyObject *
4209os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
4210
4211static PyObject *
4212os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4213{
4214 PyObject *return_value = NULL;
4215 int infd;
4216 int outfd;
4217 int flags;
4218
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004219 if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
4220 goto exit;
4221 }
4222 if (PyFloat_Check(args[0])) {
4223 PyErr_SetString(PyExc_TypeError,
4224 "integer argument expected, got float" );
4225 goto exit;
4226 }
4227 infd = _PyLong_AsInt(args[0]);
4228 if (infd == -1 && PyErr_Occurred()) {
4229 goto exit;
4230 }
4231 if (PyFloat_Check(args[1])) {
4232 PyErr_SetString(PyExc_TypeError,
4233 "integer argument expected, got float" );
4234 goto exit;
4235 }
4236 outfd = _PyLong_AsInt(args[1]);
4237 if (outfd == -1 && PyErr_Occurred()) {
4238 goto exit;
4239 }
4240 if (PyFloat_Check(args[2])) {
4241 PyErr_SetString(PyExc_TypeError,
4242 "integer argument expected, got float" );
4243 goto exit;
4244 }
4245 flags = _PyLong_AsInt(args[2]);
4246 if (flags == -1 && PyErr_Occurred()) {
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004247 goto exit;
4248 }
4249 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
4250
4251exit:
4252 return return_value;
4253}
4254
4255#endif /* defined(__APPLE__) */
4256
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004257PyDoc_STRVAR(os_fstat__doc__,
4258"fstat($module, /, fd)\n"
4259"--\n"
4260"\n"
4261"Perform a stat system call on the given file descriptor.\n"
4262"\n"
4263"Like stat(), but for an open file descriptor.\n"
4264"Equivalent to os.stat(fd).");
4265
4266#define OS_FSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004267 {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004268
4269static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004270os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004271
4272static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004273os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004274{
4275 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004276 static const char * const _keywords[] = {"fd", NULL};
4277 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004278 int fd;
4279
Victor Stinner3e1fad62017-01-17 01:29:01 +01004280 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004281 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004282 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004283 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004284 return_value = os_fstat_impl(module, fd);
4285
4286exit:
4287 return return_value;
4288}
4289
4290PyDoc_STRVAR(os_isatty__doc__,
4291"isatty($module, fd, /)\n"
4292"--\n"
4293"\n"
4294"Return True if the fd is connected to a terminal.\n"
4295"\n"
4296"Return True if the file descriptor is an open file descriptor\n"
4297"connected to the slave end of a terminal.");
4298
4299#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004300 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004301
4302static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004303os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004304
4305static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004306os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004307{
4308 PyObject *return_value = NULL;
4309 int fd;
4310 int _return_value;
4311
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004312 if (PyFloat_Check(arg)) {
4313 PyErr_SetString(PyExc_TypeError,
4314 "integer argument expected, got float" );
4315 goto exit;
4316 }
4317 fd = _PyLong_AsInt(arg);
4318 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004319 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004320 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004322 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004323 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004324 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004325 return_value = PyBool_FromLong((long)_return_value);
4326
4327exit:
4328 return return_value;
4329}
4330
4331#if defined(HAVE_PIPE)
4332
4333PyDoc_STRVAR(os_pipe__doc__,
4334"pipe($module, /)\n"
4335"--\n"
4336"\n"
4337"Create a pipe.\n"
4338"\n"
4339"Returns a tuple of two file descriptors:\n"
4340" (read_fd, write_fd)");
4341
4342#define OS_PIPE_METHODDEF \
4343 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
4344
4345static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004346os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004347
4348static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004349os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004350{
4351 return os_pipe_impl(module);
4352}
4353
4354#endif /* defined(HAVE_PIPE) */
4355
4356#if defined(HAVE_PIPE2)
4357
4358PyDoc_STRVAR(os_pipe2__doc__,
4359"pipe2($module, flags, /)\n"
4360"--\n"
4361"\n"
4362"Create a pipe with flags set atomically.\n"
4363"\n"
4364"Returns a tuple of two file descriptors:\n"
4365" (read_fd, write_fd)\n"
4366"\n"
4367"flags can be constructed by ORing together one or more of these values:\n"
4368"O_NONBLOCK, O_CLOEXEC.");
4369
4370#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004371 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004372
4373static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004374os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004375
4376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004377os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004378{
4379 PyObject *return_value = NULL;
4380 int flags;
4381
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004382 if (PyFloat_Check(arg)) {
4383 PyErr_SetString(PyExc_TypeError,
4384 "integer argument expected, got float" );
4385 goto exit;
4386 }
4387 flags = _PyLong_AsInt(arg);
4388 if (flags == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004389 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004390 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004391 return_value = os_pipe2_impl(module, flags);
4392
4393exit:
4394 return return_value;
4395}
4396
4397#endif /* defined(HAVE_PIPE2) */
4398
4399#if defined(HAVE_WRITEV)
4400
4401PyDoc_STRVAR(os_writev__doc__,
4402"writev($module, fd, buffers, /)\n"
4403"--\n"
4404"\n"
4405"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4406"\n"
4407"Returns the total number of bytes written.\n"
4408"buffers must be a sequence of bytes-like objects.");
4409
4410#define OS_WRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004411 {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004412
4413static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004414os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004415
4416static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004417os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004418{
4419 PyObject *return_value = NULL;
4420 int fd;
4421 PyObject *buffers;
4422 Py_ssize_t _return_value;
4423
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004424 if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004425 goto exit;
4426 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004427 if (PyFloat_Check(args[0])) {
4428 PyErr_SetString(PyExc_TypeError,
4429 "integer argument expected, got float" );
4430 goto exit;
4431 }
4432 fd = _PyLong_AsInt(args[0]);
4433 if (fd == -1 && PyErr_Occurred()) {
4434 goto exit;
4435 }
4436 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004437 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004438 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004439 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004440 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004441 return_value = PyLong_FromSsize_t(_return_value);
4442
4443exit:
4444 return return_value;
4445}
4446
4447#endif /* defined(HAVE_WRITEV) */
4448
4449#if defined(HAVE_PWRITE)
4450
4451PyDoc_STRVAR(os_pwrite__doc__,
4452"pwrite($module, fd, buffer, offset, /)\n"
4453"--\n"
4454"\n"
4455"Write bytes to a file descriptor starting at a particular offset.\n"
4456"\n"
4457"Write buffer to fd, starting at offset bytes from the beginning of\n"
4458"the file. Returns the number of bytes writte. Does not change the\n"
4459"current file offset.");
4460
4461#define OS_PWRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004462 {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004463
4464static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004465os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004466
4467static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004468os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004469{
4470 PyObject *return_value = NULL;
4471 int fd;
4472 Py_buffer buffer = {NULL, NULL};
4473 Py_off_t offset;
4474 Py_ssize_t _return_value;
4475
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004476 if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
4477 goto exit;
4478 }
4479 if (PyFloat_Check(args[0])) {
4480 PyErr_SetString(PyExc_TypeError,
4481 "integer argument expected, got float" );
4482 goto exit;
4483 }
4484 fd = _PyLong_AsInt(args[0]);
4485 if (fd == -1 && PyErr_Occurred()) {
4486 goto exit;
4487 }
4488 if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
4489 goto exit;
4490 }
4491 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
4492 _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]);
4493 goto exit;
4494 }
4495 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004496 goto exit;
4497 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004498 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004499 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004500 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004501 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004502 return_value = PyLong_FromSsize_t(_return_value);
4503
4504exit:
4505 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004506 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004507 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004508 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004509
4510 return return_value;
4511}
4512
4513#endif /* defined(HAVE_PWRITE) */
4514
Pablo Galindo4defba32018-01-27 16:16:37 +00004515#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4516
4517PyDoc_STRVAR(os_pwritev__doc__,
4518"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4519"--\n"
4520"\n"
4521"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4522"\n"
4523"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4524"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4525"buffer is written before proceeding to second, and so on. The operating system may\n"
4526"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4527"This function writes the contents of each object to the file descriptor and returns\n"
4528"the total number of bytes written.\n"
4529"\n"
4530"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4531"\n"
4532"- RWF_DSYNC\n"
4533"- RWF_SYNC\n"
4534"\n"
4535"Using non-zero flags requires Linux 4.7 or newer.");
4536
4537#define OS_PWRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004538 {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004539
4540static Py_ssize_t
4541os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4542 int flags);
4543
4544static PyObject *
4545os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4546{
4547 PyObject *return_value = NULL;
4548 int fd;
4549 PyObject *buffers;
4550 Py_off_t offset;
4551 int flags = 0;
4552 Py_ssize_t _return_value;
4553
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004554 if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00004555 goto exit;
4556 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004557 if (PyFloat_Check(args[0])) {
4558 PyErr_SetString(PyExc_TypeError,
4559 "integer argument expected, got float" );
4560 goto exit;
4561 }
4562 fd = _PyLong_AsInt(args[0]);
4563 if (fd == -1 && PyErr_Occurred()) {
4564 goto exit;
4565 }
4566 buffers = args[1];
4567 if (!Py_off_t_converter(args[2], &offset)) {
4568 goto exit;
4569 }
4570 if (nargs < 4) {
4571 goto skip_optional;
4572 }
4573 if (PyFloat_Check(args[3])) {
4574 PyErr_SetString(PyExc_TypeError,
4575 "integer argument expected, got float" );
4576 goto exit;
4577 }
4578 flags = _PyLong_AsInt(args[3]);
4579 if (flags == -1 && PyErr_Occurred()) {
4580 goto exit;
4581 }
4582skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00004583 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4584 if ((_return_value == -1) && PyErr_Occurred()) {
4585 goto exit;
4586 }
4587 return_value = PyLong_FromSsize_t(_return_value);
4588
4589exit:
4590 return return_value;
4591}
4592
4593#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4594
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004595#if defined(HAVE_MKFIFO)
4596
4597PyDoc_STRVAR(os_mkfifo__doc__,
4598"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4599"--\n"
4600"\n"
4601"Create a \"fifo\" (a POSIX named pipe).\n"
4602"\n"
4603"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4604" and path should be relative; path will then be relative to that directory.\n"
4605"dir_fd may not be implemented on your platform.\n"
4606" If it is unavailable, using it will raise a NotImplementedError.");
4607
4608#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004609 {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004610
4611static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004612os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004613
4614static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004615os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004616{
4617 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004618 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4619 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004620 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4621 int mode = 438;
4622 int dir_fd = DEFAULT_DIR_FD;
4623
Victor Stinner3e1fad62017-01-17 01:29:01 +01004624 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004625 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004626 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004627 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004628 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4629
4630exit:
4631 /* Cleanup for path */
4632 path_cleanup(&path);
4633
4634 return return_value;
4635}
4636
4637#endif /* defined(HAVE_MKFIFO) */
4638
4639#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4640
4641PyDoc_STRVAR(os_mknod__doc__,
4642"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4643"--\n"
4644"\n"
4645"Create a node in the file system.\n"
4646"\n"
4647"Create a node in the file system (file, device special file or named pipe)\n"
4648"at path. mode specifies both the permissions to use and the\n"
4649"type of node to be created, being combined (bitwise OR) with one of\n"
4650"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4651"device defines the newly created device special file (probably using\n"
4652"os.makedev()). Otherwise device is ignored.\n"
4653"\n"
4654"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4655" and path should be relative; path will then be relative to that directory.\n"
4656"dir_fd may not be implemented on your platform.\n"
4657" If it is unavailable, using it will raise a NotImplementedError.");
4658
4659#define OS_MKNOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004660 {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004661
4662static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004663os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004664 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004665
4666static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004667os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004668{
4669 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004670 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4671 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004672 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4673 int mode = 384;
4674 dev_t device = 0;
4675 int dir_fd = DEFAULT_DIR_FD;
4676
Victor Stinner3e1fad62017-01-17 01:29:01 +01004677 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004678 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004679 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004680 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004681 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4682
4683exit:
4684 /* Cleanup for path */
4685 path_cleanup(&path);
4686
4687 return return_value;
4688}
4689
4690#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4691
4692#if defined(HAVE_DEVICE_MACROS)
4693
4694PyDoc_STRVAR(os_major__doc__,
4695"major($module, device, /)\n"
4696"--\n"
4697"\n"
4698"Extracts a device major number from a raw device number.");
4699
4700#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004701 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004702
4703static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004704os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004705
4706static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004707os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708{
4709 PyObject *return_value = NULL;
4710 dev_t device;
4711 unsigned int _return_value;
4712
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004713 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004714 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004715 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004716 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004717 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004718 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004719 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004720 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4721
4722exit:
4723 return return_value;
4724}
4725
4726#endif /* defined(HAVE_DEVICE_MACROS) */
4727
4728#if defined(HAVE_DEVICE_MACROS)
4729
4730PyDoc_STRVAR(os_minor__doc__,
4731"minor($module, device, /)\n"
4732"--\n"
4733"\n"
4734"Extracts a device minor number from a raw device number.");
4735
4736#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004737 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004738
4739static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004740os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004741
4742static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004743os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004744{
4745 PyObject *return_value = NULL;
4746 dev_t device;
4747 unsigned int _return_value;
4748
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004749 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004750 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004751 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004753 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004754 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004755 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004756 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4757
4758exit:
4759 return return_value;
4760}
4761
4762#endif /* defined(HAVE_DEVICE_MACROS) */
4763
4764#if defined(HAVE_DEVICE_MACROS)
4765
4766PyDoc_STRVAR(os_makedev__doc__,
4767"makedev($module, major, minor, /)\n"
4768"--\n"
4769"\n"
4770"Composes a raw device number from the major and minor device numbers.");
4771
4772#define OS_MAKEDEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004773 {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004774
4775static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004776os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004777
4778static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004779os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004780{
4781 PyObject *return_value = NULL;
4782 int major;
4783 int minor;
4784 dev_t _return_value;
4785
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004786 if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
4787 goto exit;
4788 }
4789 if (PyFloat_Check(args[0])) {
4790 PyErr_SetString(PyExc_TypeError,
4791 "integer argument expected, got float" );
4792 goto exit;
4793 }
4794 major = _PyLong_AsInt(args[0]);
4795 if (major == -1 && PyErr_Occurred()) {
4796 goto exit;
4797 }
4798 if (PyFloat_Check(args[1])) {
4799 PyErr_SetString(PyExc_TypeError,
4800 "integer argument expected, got float" );
4801 goto exit;
4802 }
4803 minor = _PyLong_AsInt(args[1]);
4804 if (minor == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004805 goto exit;
4806 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004807 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004808 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004809 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004810 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004811 return_value = _PyLong_FromDev(_return_value);
4812
4813exit:
4814 return return_value;
4815}
4816
4817#endif /* defined(HAVE_DEVICE_MACROS) */
4818
Steve Dowerf7377032015-04-12 15:44:54 -04004819#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004820
4821PyDoc_STRVAR(os_ftruncate__doc__,
4822"ftruncate($module, fd, length, /)\n"
4823"--\n"
4824"\n"
4825"Truncate a file, specified by file descriptor, to a specific length.");
4826
4827#define OS_FTRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004828 {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004829
4830static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004831os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004832
4833static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004834os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004835{
4836 PyObject *return_value = NULL;
4837 int fd;
4838 Py_off_t length;
4839
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004840 if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
4841 goto exit;
4842 }
4843 if (PyFloat_Check(args[0])) {
4844 PyErr_SetString(PyExc_TypeError,
4845 "integer argument expected, got float" );
4846 goto exit;
4847 }
4848 fd = _PyLong_AsInt(args[0]);
4849 if (fd == -1 && PyErr_Occurred()) {
4850 goto exit;
4851 }
4852 if (!Py_off_t_converter(args[1], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004853 goto exit;
4854 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004855 return_value = os_ftruncate_impl(module, fd, length);
4856
4857exit:
4858 return return_value;
4859}
4860
Steve Dowerf7377032015-04-12 15:44:54 -04004861#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004862
Steve Dowerf7377032015-04-12 15:44:54 -04004863#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004864
4865PyDoc_STRVAR(os_truncate__doc__,
4866"truncate($module, /, path, length)\n"
4867"--\n"
4868"\n"
4869"Truncate a file, specified by path, to a specific length.\n"
4870"\n"
4871"On some platforms, path may also be specified as an open file descriptor.\n"
4872" If this functionality is unavailable, using it raises an exception.");
4873
4874#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004875 {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004876
4877static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004878os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004879
4880static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004881os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004882{
4883 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004884 static const char * const _keywords[] = {"path", "length", NULL};
4885 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004886 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4887 Py_off_t length;
4888
Victor Stinner3e1fad62017-01-17 01:29:01 +01004889 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004890 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004891 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004892 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004893 return_value = os_truncate_impl(module, &path, length);
4894
4895exit:
4896 /* Cleanup for path */
4897 path_cleanup(&path);
4898
4899 return return_value;
4900}
4901
Steve Dowerf7377032015-04-12 15:44:54 -04004902#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004903
4904#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4905
4906PyDoc_STRVAR(os_posix_fallocate__doc__,
4907"posix_fallocate($module, fd, offset, length, /)\n"
4908"--\n"
4909"\n"
4910"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4911"\n"
4912"Ensure that the file specified by fd encompasses a range of bytes\n"
4913"starting at offset bytes from the beginning and continuing for length bytes.");
4914
4915#define OS_POSIX_FALLOCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004916 {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004917
4918static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004919os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004920 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004921
4922static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004923os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004924{
4925 PyObject *return_value = NULL;
4926 int fd;
4927 Py_off_t offset;
4928 Py_off_t length;
4929
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004930 if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
4931 goto exit;
4932 }
4933 if (PyFloat_Check(args[0])) {
4934 PyErr_SetString(PyExc_TypeError,
4935 "integer argument expected, got float" );
4936 goto exit;
4937 }
4938 fd = _PyLong_AsInt(args[0]);
4939 if (fd == -1 && PyErr_Occurred()) {
4940 goto exit;
4941 }
4942 if (!Py_off_t_converter(args[1], &offset)) {
4943 goto exit;
4944 }
4945 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004946 goto exit;
4947 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004948 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4949
4950exit:
4951 return return_value;
4952}
4953
4954#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4955
4956#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4957
4958PyDoc_STRVAR(os_posix_fadvise__doc__,
4959"posix_fadvise($module, fd, offset, length, advice, /)\n"
4960"--\n"
4961"\n"
4962"Announce an intention to access data in a specific pattern.\n"
4963"\n"
4964"Announce an intention to access data in a specific pattern, thus allowing\n"
4965"the kernel to make optimizations.\n"
4966"The advice applies to the region of the file specified by fd starting at\n"
4967"offset and continuing for length bytes.\n"
4968"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4969"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4970"POSIX_FADV_DONTNEED.");
4971
4972#define OS_POSIX_FADVISE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004973 {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004974
4975static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004976os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004977 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978
4979static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004980os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004981{
4982 PyObject *return_value = NULL;
4983 int fd;
4984 Py_off_t offset;
4985 Py_off_t length;
4986 int advice;
4987
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004988 if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
4989 goto exit;
4990 }
4991 if (PyFloat_Check(args[0])) {
4992 PyErr_SetString(PyExc_TypeError,
4993 "integer argument expected, got float" );
4994 goto exit;
4995 }
4996 fd = _PyLong_AsInt(args[0]);
4997 if (fd == -1 && PyErr_Occurred()) {
4998 goto exit;
4999 }
5000 if (!Py_off_t_converter(args[1], &offset)) {
5001 goto exit;
5002 }
5003 if (!Py_off_t_converter(args[2], &length)) {
5004 goto exit;
5005 }
5006 if (PyFloat_Check(args[3])) {
5007 PyErr_SetString(PyExc_TypeError,
5008 "integer argument expected, got float" );
5009 goto exit;
5010 }
5011 advice = _PyLong_AsInt(args[3]);
5012 if (advice == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005013 goto exit;
5014 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005015 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
5016
5017exit:
5018 return return_value;
5019}
5020
5021#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
5022
5023#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
5024
5025PyDoc_STRVAR(os_putenv__doc__,
5026"putenv($module, name, value, /)\n"
5027"--\n"
5028"\n"
5029"Change or add an environment variable.");
5030
5031#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005032 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005033
5034static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005035os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005036
5037static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005038os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005039{
5040 PyObject *return_value = NULL;
5041 PyObject *name;
5042 PyObject *value;
5043
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005044 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005045 goto exit;
5046 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005047 if (!PyUnicode_Check(args[0])) {
5048 _PyArg_BadArgument("putenv", 1, "str", args[0]);
5049 goto exit;
5050 }
5051 if (PyUnicode_READY(args[0]) == -1) {
5052 goto exit;
5053 }
5054 name = args[0];
5055 if (!PyUnicode_Check(args[1])) {
5056 _PyArg_BadArgument("putenv", 2, "str", args[1]);
5057 goto exit;
5058 }
5059 if (PyUnicode_READY(args[1]) == -1) {
5060 goto exit;
5061 }
5062 value = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005063 return_value = os_putenv_impl(module, name, value);
5064
5065exit:
5066 return return_value;
5067}
5068
5069#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
5070
5071#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
5072
5073PyDoc_STRVAR(os_putenv__doc__,
5074"putenv($module, name, value, /)\n"
5075"--\n"
5076"\n"
5077"Change or add an environment variable.");
5078
5079#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005080 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005081
5082static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005083os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005084
5085static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005086os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005087{
5088 PyObject *return_value = NULL;
5089 PyObject *name = NULL;
5090 PyObject *value = NULL;
5091
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005092 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
5093 goto exit;
5094 }
5095 if (!PyUnicode_FSConverter(args[0], &name)) {
5096 goto exit;
5097 }
5098 if (!PyUnicode_FSConverter(args[1], &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005099 goto exit;
5100 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005101 return_value = os_putenv_impl(module, name, value);
5102
5103exit:
5104 /* Cleanup for name */
5105 Py_XDECREF(name);
5106 /* Cleanup for value */
5107 Py_XDECREF(value);
5108
5109 return return_value;
5110}
5111
5112#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
5113
5114#if defined(HAVE_UNSETENV)
5115
5116PyDoc_STRVAR(os_unsetenv__doc__,
5117"unsetenv($module, name, /)\n"
5118"--\n"
5119"\n"
5120"Delete an environment variable.");
5121
5122#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005123 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005124
5125static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005126os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005127
5128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005129os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005130{
5131 PyObject *return_value = NULL;
5132 PyObject *name = NULL;
5133
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005134 if (!PyUnicode_FSConverter(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005135 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005136 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005137 return_value = os_unsetenv_impl(module, name);
5138
5139exit:
5140 /* Cleanup for name */
5141 Py_XDECREF(name);
5142
5143 return return_value;
5144}
5145
5146#endif /* defined(HAVE_UNSETENV) */
5147
5148PyDoc_STRVAR(os_strerror__doc__,
5149"strerror($module, code, /)\n"
5150"--\n"
5151"\n"
5152"Translate an error code to a message string.");
5153
5154#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005155 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005156
5157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005158os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005159
5160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005161os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005162{
5163 PyObject *return_value = NULL;
5164 int code;
5165
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005166 if (PyFloat_Check(arg)) {
5167 PyErr_SetString(PyExc_TypeError,
5168 "integer argument expected, got float" );
5169 goto exit;
5170 }
5171 code = _PyLong_AsInt(arg);
5172 if (code == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005173 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005174 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175 return_value = os_strerror_impl(module, code);
5176
5177exit:
5178 return return_value;
5179}
5180
5181#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
5182
5183PyDoc_STRVAR(os_WCOREDUMP__doc__,
5184"WCOREDUMP($module, status, /)\n"
5185"--\n"
5186"\n"
5187"Return True if the process returning status was dumped to a core file.");
5188
5189#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005190 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005191
5192static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005193os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005194
5195static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005196os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005197{
5198 PyObject *return_value = NULL;
5199 int status;
5200 int _return_value;
5201
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005202 if (PyFloat_Check(arg)) {
5203 PyErr_SetString(PyExc_TypeError,
5204 "integer argument expected, got float" );
5205 goto exit;
5206 }
5207 status = _PyLong_AsInt(arg);
5208 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005209 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005210 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005211 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005212 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005213 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005214 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005215 return_value = PyBool_FromLong((long)_return_value);
5216
5217exit:
5218 return return_value;
5219}
5220
5221#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
5222
5223#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
5224
5225PyDoc_STRVAR(os_WIFCONTINUED__doc__,
5226"WIFCONTINUED($module, /, status)\n"
5227"--\n"
5228"\n"
5229"Return True if a particular process was continued from a job control stop.\n"
5230"\n"
5231"Return True if the process returning status was continued from a\n"
5232"job control stop.");
5233
5234#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005235 {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005236
5237static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005238os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005239
5240static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005241os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005242{
5243 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005244 static const char * const _keywords[] = {"status", NULL};
5245 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005246 int status;
5247 int _return_value;
5248
Victor Stinner3e1fad62017-01-17 01:29:01 +01005249 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005250 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005251 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005252 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005253 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005254 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005255 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005256 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005257 return_value = PyBool_FromLong((long)_return_value);
5258
5259exit:
5260 return return_value;
5261}
5262
5263#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
5264
5265#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
5266
5267PyDoc_STRVAR(os_WIFSTOPPED__doc__,
5268"WIFSTOPPED($module, /, status)\n"
5269"--\n"
5270"\n"
5271"Return True if the process returning status was stopped.");
5272
5273#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005274 {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005275
5276static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005277os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005278
5279static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005280os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005281{
5282 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005283 static const char * const _keywords[] = {"status", NULL};
5284 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005285 int status;
5286 int _return_value;
5287
Victor Stinner3e1fad62017-01-17 01:29:01 +01005288 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005289 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005292 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005293 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005294 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005295 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005296 return_value = PyBool_FromLong((long)_return_value);
5297
5298exit:
5299 return return_value;
5300}
5301
5302#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
5303
5304#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
5305
5306PyDoc_STRVAR(os_WIFSIGNALED__doc__,
5307"WIFSIGNALED($module, /, status)\n"
5308"--\n"
5309"\n"
5310"Return True if the process returning status was terminated by a signal.");
5311
5312#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005313 {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005314
5315static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005316os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005317
5318static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005319os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005320{
5321 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005322 static const char * const _keywords[] = {"status", NULL};
5323 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005324 int status;
5325 int _return_value;
5326
Victor Stinner3e1fad62017-01-17 01:29:01 +01005327 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005328 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005329 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005330 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005331 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005332 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005333 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005334 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005335 return_value = PyBool_FromLong((long)_return_value);
5336
5337exit:
5338 return return_value;
5339}
5340
5341#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
5342
5343#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
5344
5345PyDoc_STRVAR(os_WIFEXITED__doc__,
5346"WIFEXITED($module, /, status)\n"
5347"--\n"
5348"\n"
5349"Return True if the process returning status exited via the exit() system call.");
5350
5351#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005352 {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005353
5354static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005355os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005356
5357static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005358os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005359{
5360 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005361 static const char * const _keywords[] = {"status", NULL};
5362 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005363 int status;
5364 int _return_value;
5365
Victor Stinner3e1fad62017-01-17 01:29:01 +01005366 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005367 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005368 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005369 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005370 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005371 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005372 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005373 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005374 return_value = PyBool_FromLong((long)_return_value);
5375
5376exit:
5377 return return_value;
5378}
5379
5380#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
5381
5382#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
5383
5384PyDoc_STRVAR(os_WEXITSTATUS__doc__,
5385"WEXITSTATUS($module, /, status)\n"
5386"--\n"
5387"\n"
5388"Return the process return code from status.");
5389
5390#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005391 {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005392
5393static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005394os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005395
5396static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005397os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005398{
5399 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005400 static const char * const _keywords[] = {"status", NULL};
5401 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005402 int status;
5403 int _return_value;
5404
Victor Stinner3e1fad62017-01-17 01:29:01 +01005405 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005406 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005407 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005408 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005409 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005410 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005411 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005412 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005413 return_value = PyLong_FromLong((long)_return_value);
5414
5415exit:
5416 return return_value;
5417}
5418
5419#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
5420
5421#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
5422
5423PyDoc_STRVAR(os_WTERMSIG__doc__,
5424"WTERMSIG($module, /, status)\n"
5425"--\n"
5426"\n"
5427"Return the signal that terminated the process that provided the status value.");
5428
5429#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005430 {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431
5432static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005433os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005434
5435static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005436os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005437{
5438 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005439 static const char * const _keywords[] = {"status", NULL};
5440 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005441 int status;
5442 int _return_value;
5443
Victor Stinner3e1fad62017-01-17 01:29:01 +01005444 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005445 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005446 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005447 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005448 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005449 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005450 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005451 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005452 return_value = PyLong_FromLong((long)_return_value);
5453
5454exit:
5455 return return_value;
5456}
5457
5458#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
5459
5460#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
5461
5462PyDoc_STRVAR(os_WSTOPSIG__doc__,
5463"WSTOPSIG($module, /, status)\n"
5464"--\n"
5465"\n"
5466"Return the signal that stopped the process that provided the status value.");
5467
5468#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005469 {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005470
5471static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005472os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005473
5474static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005475os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005476{
5477 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005478 static const char * const _keywords[] = {"status", NULL};
5479 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005480 int status;
5481 int _return_value;
5482
Victor Stinner3e1fad62017-01-17 01:29:01 +01005483 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005484 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005485 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005486 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005487 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005488 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005489 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005490 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005491 return_value = PyLong_FromLong((long)_return_value);
5492
5493exit:
5494 return return_value;
5495}
5496
5497#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
5498
5499#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
5500
5501PyDoc_STRVAR(os_fstatvfs__doc__,
5502"fstatvfs($module, fd, /)\n"
5503"--\n"
5504"\n"
5505"Perform an fstatvfs system call on the given fd.\n"
5506"\n"
5507"Equivalent to statvfs(fd).");
5508
5509#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005510 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005511
5512static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005513os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005514
5515static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005516os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005517{
5518 PyObject *return_value = NULL;
5519 int fd;
5520
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005521 if (PyFloat_Check(arg)) {
5522 PyErr_SetString(PyExc_TypeError,
5523 "integer argument expected, got float" );
5524 goto exit;
5525 }
5526 fd = _PyLong_AsInt(arg);
5527 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005528 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005529 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005530 return_value = os_fstatvfs_impl(module, fd);
5531
5532exit:
5533 return return_value;
5534}
5535
5536#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5537
5538#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5539
5540PyDoc_STRVAR(os_statvfs__doc__,
5541"statvfs($module, /, path)\n"
5542"--\n"
5543"\n"
5544"Perform a statvfs system call on the given path.\n"
5545"\n"
5546"path may always be specified as a string.\n"
5547"On some platforms, path may also be specified as an open file descriptor.\n"
5548" If this functionality is unavailable, using it raises an exception.");
5549
5550#define OS_STATVFS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005551 {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005552
5553static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005554os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005555
5556static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005557os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005558{
5559 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005560 static const char * const _keywords[] = {"path", NULL};
5561 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005562 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5563
Victor Stinner3e1fad62017-01-17 01:29:01 +01005564 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005565 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005566 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005567 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005568 return_value = os_statvfs_impl(module, &path);
5569
5570exit:
5571 /* Cleanup for path */
5572 path_cleanup(&path);
5573
5574 return return_value;
5575}
5576
5577#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5578
5579#if defined(MS_WINDOWS)
5580
5581PyDoc_STRVAR(os__getdiskusage__doc__,
5582"_getdiskusage($module, /, path)\n"
5583"--\n"
5584"\n"
5585"Return disk usage statistics about the given path as a (total, free) tuple.");
5586
5587#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005588 {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005589
5590static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005591os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005592
5593static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005594os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005595{
5596 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005597 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005598 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5599 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005600
Victor Stinner3e1fad62017-01-17 01:29:01 +01005601 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005602 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005603 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005604 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005605 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005606
5607exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005608 /* Cleanup for path */
5609 path_cleanup(&path);
5610
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005611 return return_value;
5612}
5613
5614#endif /* defined(MS_WINDOWS) */
5615
5616#if defined(HAVE_FPATHCONF)
5617
5618PyDoc_STRVAR(os_fpathconf__doc__,
5619"fpathconf($module, fd, name, /)\n"
5620"--\n"
5621"\n"
5622"Return the configuration limit name for the file descriptor fd.\n"
5623"\n"
5624"If there is no limit, return -1.");
5625
5626#define OS_FPATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005627 {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005628
5629static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005630os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005631
5632static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005633os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005634{
5635 PyObject *return_value = NULL;
5636 int fd;
5637 int name;
5638 long _return_value;
5639
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005640 if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
5641 goto exit;
5642 }
5643 if (PyFloat_Check(args[0])) {
5644 PyErr_SetString(PyExc_TypeError,
5645 "integer argument expected, got float" );
5646 goto exit;
5647 }
5648 fd = _PyLong_AsInt(args[0]);
5649 if (fd == -1 && PyErr_Occurred()) {
5650 goto exit;
5651 }
5652 if (!conv_path_confname(args[1], &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005653 goto exit;
5654 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005655 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005656 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005657 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005658 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005659 return_value = PyLong_FromLong(_return_value);
5660
5661exit:
5662 return return_value;
5663}
5664
5665#endif /* defined(HAVE_FPATHCONF) */
5666
5667#if defined(HAVE_PATHCONF)
5668
5669PyDoc_STRVAR(os_pathconf__doc__,
5670"pathconf($module, /, path, name)\n"
5671"--\n"
5672"\n"
5673"Return the configuration limit name for the file or directory path.\n"
5674"\n"
5675"If there is no limit, return -1.\n"
5676"On some platforms, path may also be specified as an open file descriptor.\n"
5677" If this functionality is unavailable, using it raises an exception.");
5678
5679#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005680 {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005681
5682static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005683os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005684
5685static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005686os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005687{
5688 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005689 static const char * const _keywords[] = {"path", "name", NULL};
5690 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005691 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5692 int name;
5693 long _return_value;
5694
Victor Stinner3e1fad62017-01-17 01:29:01 +01005695 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005696 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005697 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005698 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005699 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005700 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005701 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005702 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005703 return_value = PyLong_FromLong(_return_value);
5704
5705exit:
5706 /* Cleanup for path */
5707 path_cleanup(&path);
5708
5709 return return_value;
5710}
5711
5712#endif /* defined(HAVE_PATHCONF) */
5713
5714#if defined(HAVE_CONFSTR)
5715
5716PyDoc_STRVAR(os_confstr__doc__,
5717"confstr($module, name, /)\n"
5718"--\n"
5719"\n"
5720"Return a string-valued system configuration variable.");
5721
5722#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005723 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005724
5725static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005726os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005727
5728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005729os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005730{
5731 PyObject *return_value = NULL;
5732 int name;
5733
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005734 if (!conv_confstr_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005735 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005736 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005737 return_value = os_confstr_impl(module, name);
5738
5739exit:
5740 return return_value;
5741}
5742
5743#endif /* defined(HAVE_CONFSTR) */
5744
5745#if defined(HAVE_SYSCONF)
5746
5747PyDoc_STRVAR(os_sysconf__doc__,
5748"sysconf($module, name, /)\n"
5749"--\n"
5750"\n"
5751"Return an integer-valued system configuration variable.");
5752
5753#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005754 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005755
5756static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005757os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005758
5759static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005760os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761{
5762 PyObject *return_value = NULL;
5763 int name;
5764 long _return_value;
5765
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005766 if (!conv_sysconf_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005767 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005768 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005769 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005770 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005771 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005772 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005773 return_value = PyLong_FromLong(_return_value);
5774
5775exit:
5776 return return_value;
5777}
5778
5779#endif /* defined(HAVE_SYSCONF) */
5780
5781PyDoc_STRVAR(os_abort__doc__,
5782"abort($module, /)\n"
5783"--\n"
5784"\n"
5785"Abort the interpreter immediately.\n"
5786"\n"
5787"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5788"on the hosting operating system. This function never returns.");
5789
5790#define OS_ABORT_METHODDEF \
5791 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5792
5793static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005794os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005795
5796static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005797os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005798{
5799 return os_abort_impl(module);
5800}
5801
Steve Dowercc16be82016-09-08 10:35:16 -07005802#if defined(MS_WINDOWS)
5803
5804PyDoc_STRVAR(os_startfile__doc__,
5805"startfile($module, /, filepath, operation=None)\n"
5806"--\n"
5807"\n"
5808"startfile(filepath [, operation])\n"
5809"\n"
5810"Start a file with its associated application.\n"
5811"\n"
5812"When \"operation\" is not specified or \"open\", this acts like\n"
5813"double-clicking the file in Explorer, or giving the file name as an\n"
5814"argument to the DOS \"start\" command: the file is opened with whatever\n"
5815"application (if any) its extension is associated.\n"
5816"When another \"operation\" is given, it specifies what should be done with\n"
5817"the file. A typical operation is \"print\".\n"
5818"\n"
5819"startfile returns as soon as the associated application is launched.\n"
5820"There is no option to wait for the application to close, and no way\n"
5821"to retrieve the application\'s exit status.\n"
5822"\n"
5823"The filepath is relative to the current directory. If you want to use\n"
5824"an absolute path, make sure the first character is not a slash (\"/\");\n"
5825"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5826
5827#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005828 {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005829
5830static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005831os_startfile_impl(PyObject *module, path_t *filepath,
5832 const Py_UNICODE *operation);
Steve Dowercc16be82016-09-08 10:35:16 -07005833
5834static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005835os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005836{
5837 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005838 static const char * const _keywords[] = {"filepath", "operation", NULL};
5839 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005840 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005841 const Py_UNICODE *operation = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07005842
Victor Stinner3e1fad62017-01-17 01:29:01 +01005843 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005844 path_converter, &filepath, &operation)) {
5845 goto exit;
5846 }
5847 return_value = os_startfile_impl(module, &filepath, operation);
5848
5849exit:
5850 /* Cleanup for filepath */
5851 path_cleanup(&filepath);
5852
5853 return return_value;
5854}
5855
5856#endif /* defined(MS_WINDOWS) */
5857
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005858#if defined(HAVE_GETLOADAVG)
5859
5860PyDoc_STRVAR(os_getloadavg__doc__,
5861"getloadavg($module, /)\n"
5862"--\n"
5863"\n"
5864"Return average recent system load information.\n"
5865"\n"
5866"Return the number of processes in the system run queue averaged over\n"
5867"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5868"Raises OSError if the load average was unobtainable.");
5869
5870#define OS_GETLOADAVG_METHODDEF \
5871 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5872
5873static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005874os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005875
5876static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005877os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005878{
5879 return os_getloadavg_impl(module);
5880}
5881
5882#endif /* defined(HAVE_GETLOADAVG) */
5883
5884PyDoc_STRVAR(os_device_encoding__doc__,
5885"device_encoding($module, /, fd)\n"
5886"--\n"
5887"\n"
5888"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5889"\n"
5890"The file descriptor must be attached to a terminal.\n"
5891"If the device is not a terminal, return None.");
5892
5893#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005894 {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005895
5896static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005897os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005898
5899static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005900os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005901{
5902 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005903 static const char * const _keywords[] = {"fd", NULL};
5904 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005905 int fd;
5906
Victor Stinner3e1fad62017-01-17 01:29:01 +01005907 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005908 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005909 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005910 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005911 return_value = os_device_encoding_impl(module, fd);
5912
5913exit:
5914 return return_value;
5915}
5916
5917#if defined(HAVE_SETRESUID)
5918
5919PyDoc_STRVAR(os_setresuid__doc__,
5920"setresuid($module, ruid, euid, suid, /)\n"
5921"--\n"
5922"\n"
5923"Set the current process\'s real, effective, and saved user ids.");
5924
5925#define OS_SETRESUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005926 {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005927
5928static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005929os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005930
5931static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005932os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005933{
5934 PyObject *return_value = NULL;
5935 uid_t ruid;
5936 uid_t euid;
5937 uid_t suid;
5938
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005939 if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
5940 goto exit;
5941 }
5942 if (!_Py_Uid_Converter(args[0], &ruid)) {
5943 goto exit;
5944 }
5945 if (!_Py_Uid_Converter(args[1], &euid)) {
5946 goto exit;
5947 }
5948 if (!_Py_Uid_Converter(args[2], &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005949 goto exit;
5950 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005951 return_value = os_setresuid_impl(module, ruid, euid, suid);
5952
5953exit:
5954 return return_value;
5955}
5956
5957#endif /* defined(HAVE_SETRESUID) */
5958
5959#if defined(HAVE_SETRESGID)
5960
5961PyDoc_STRVAR(os_setresgid__doc__,
5962"setresgid($module, rgid, egid, sgid, /)\n"
5963"--\n"
5964"\n"
5965"Set the current process\'s real, effective, and saved group ids.");
5966
5967#define OS_SETRESGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005968 {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005969
5970static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005971os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005972
5973static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005974os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005975{
5976 PyObject *return_value = NULL;
5977 gid_t rgid;
5978 gid_t egid;
5979 gid_t sgid;
5980
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005981 if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
5982 goto exit;
5983 }
5984 if (!_Py_Gid_Converter(args[0], &rgid)) {
5985 goto exit;
5986 }
5987 if (!_Py_Gid_Converter(args[1], &egid)) {
5988 goto exit;
5989 }
5990 if (!_Py_Gid_Converter(args[2], &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005991 goto exit;
5992 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005993 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5994
5995exit:
5996 return return_value;
5997}
5998
5999#endif /* defined(HAVE_SETRESGID) */
6000
6001#if defined(HAVE_GETRESUID)
6002
6003PyDoc_STRVAR(os_getresuid__doc__,
6004"getresuid($module, /)\n"
6005"--\n"
6006"\n"
6007"Return a tuple of the current process\'s real, effective, and saved user ids.");
6008
6009#define OS_GETRESUID_METHODDEF \
6010 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
6011
6012static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006013os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006014
6015static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006016os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006017{
6018 return os_getresuid_impl(module);
6019}
6020
6021#endif /* defined(HAVE_GETRESUID) */
6022
6023#if defined(HAVE_GETRESGID)
6024
6025PyDoc_STRVAR(os_getresgid__doc__,
6026"getresgid($module, /)\n"
6027"--\n"
6028"\n"
6029"Return a tuple of the current process\'s real, effective, and saved group ids.");
6030
6031#define OS_GETRESGID_METHODDEF \
6032 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
6033
6034static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006035os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006036
6037static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006038os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006039{
6040 return os_getresgid_impl(module);
6041}
6042
6043#endif /* defined(HAVE_GETRESGID) */
6044
6045#if defined(USE_XATTRS)
6046
6047PyDoc_STRVAR(os_getxattr__doc__,
6048"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
6049"--\n"
6050"\n"
6051"Return the value of extended attribute attribute on path.\n"
6052"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006053"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006054"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6055" link, getxattr will examine the symbolic link itself instead of the file\n"
6056" the link points to.");
6057
6058#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006059 {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006060
6061static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006062os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006063 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006064
6065static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006066os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006067{
6068 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006069 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
6070 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006071 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
6072 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
6073 int follow_symlinks = 1;
6074
Victor Stinner3e1fad62017-01-17 01:29:01 +01006075 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006076 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006077 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006078 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006079 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
6080
6081exit:
6082 /* Cleanup for path */
6083 path_cleanup(&path);
6084 /* Cleanup for attribute */
6085 path_cleanup(&attribute);
6086
6087 return return_value;
6088}
6089
6090#endif /* defined(USE_XATTRS) */
6091
6092#if defined(USE_XATTRS)
6093
6094PyDoc_STRVAR(os_setxattr__doc__,
6095"setxattr($module, /, path, attribute, value, flags=0, *,\n"
6096" follow_symlinks=True)\n"
6097"--\n"
6098"\n"
6099"Set extended attribute attribute on path to value.\n"
6100"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006101"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006102"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6103" link, setxattr will modify the symbolic link itself instead of the file\n"
6104" the link points to.");
6105
6106#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006107 {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006108
6109static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006110os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006111 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006112
6113static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006114os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006115{
6116 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006117 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
6118 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006119 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
6120 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
6121 Py_buffer value = {NULL, NULL};
6122 int flags = 0;
6123 int follow_symlinks = 1;
6124
Victor Stinner3e1fad62017-01-17 01:29:01 +01006125 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006126 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006127 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006128 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006129 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
6130
6131exit:
6132 /* Cleanup for path */
6133 path_cleanup(&path);
6134 /* Cleanup for attribute */
6135 path_cleanup(&attribute);
6136 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006137 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006138 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006139 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006140
6141 return return_value;
6142}
6143
6144#endif /* defined(USE_XATTRS) */
6145
6146#if defined(USE_XATTRS)
6147
6148PyDoc_STRVAR(os_removexattr__doc__,
6149"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
6150"--\n"
6151"\n"
6152"Remove extended attribute attribute on path.\n"
6153"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006154"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006155"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6156" link, removexattr will modify the symbolic link itself instead of the file\n"
6157" the link points to.");
6158
6159#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006160 {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006161
6162static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006163os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006164 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006165
6166static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006167os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006168{
6169 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006170 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
6171 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006172 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
6173 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
6174 int follow_symlinks = 1;
6175
Victor Stinner3e1fad62017-01-17 01:29:01 +01006176 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006177 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006178 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006179 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006180 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
6181
6182exit:
6183 /* Cleanup for path */
6184 path_cleanup(&path);
6185 /* Cleanup for attribute */
6186 path_cleanup(&attribute);
6187
6188 return return_value;
6189}
6190
6191#endif /* defined(USE_XATTRS) */
6192
6193#if defined(USE_XATTRS)
6194
6195PyDoc_STRVAR(os_listxattr__doc__,
6196"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
6197"--\n"
6198"\n"
6199"Return a list of extended attributes on path.\n"
6200"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006201"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006202"if path is None, listxattr will examine the current directory.\n"
6203"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6204" link, listxattr will examine the symbolic link itself instead of the file\n"
6205" the link points to.");
6206
6207#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006208 {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006209
6210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006211os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006212
6213static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006214os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006215{
6216 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006217 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
6218 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006219 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
6220 int follow_symlinks = 1;
6221
Victor Stinner3e1fad62017-01-17 01:29:01 +01006222 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006223 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006224 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006225 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006226 return_value = os_listxattr_impl(module, &path, follow_symlinks);
6227
6228exit:
6229 /* Cleanup for path */
6230 path_cleanup(&path);
6231
6232 return return_value;
6233}
6234
6235#endif /* defined(USE_XATTRS) */
6236
6237PyDoc_STRVAR(os_urandom__doc__,
6238"urandom($module, size, /)\n"
6239"--\n"
6240"\n"
6241"Return a bytes object containing random bytes suitable for cryptographic use.");
6242
6243#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006244 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006245
6246static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006247os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006248
6249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006250os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006251{
6252 PyObject *return_value = NULL;
6253 Py_ssize_t size;
6254
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006255 if (PyFloat_Check(arg)) {
6256 PyErr_SetString(PyExc_TypeError,
6257 "integer argument expected, got float" );
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006258 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006259 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006260 {
6261 Py_ssize_t ival = -1;
6262 PyObject *iobj = PyNumber_Index(arg);
6263 if (iobj != NULL) {
6264 ival = PyLong_AsSsize_t(iobj);
6265 Py_DECREF(iobj);
6266 }
6267 if (ival == -1 && PyErr_Occurred()) {
6268 goto exit;
6269 }
6270 size = ival;
6271 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006272 return_value = os_urandom_impl(module, size);
6273
6274exit:
6275 return return_value;
6276}
6277
6278PyDoc_STRVAR(os_cpu_count__doc__,
6279"cpu_count($module, /)\n"
6280"--\n"
6281"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01006282"Return the number of CPUs in the system; return None if indeterminable.\n"
6283"\n"
6284"This number is not equivalent to the number of CPUs the current process can\n"
6285"use. The number of usable CPUs can be obtained with\n"
6286"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006287
6288#define OS_CPU_COUNT_METHODDEF \
6289 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
6290
6291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006292os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006293
6294static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006295os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006296{
6297 return os_cpu_count_impl(module);
6298}
6299
6300PyDoc_STRVAR(os_get_inheritable__doc__,
6301"get_inheritable($module, fd, /)\n"
6302"--\n"
6303"\n"
6304"Get the close-on-exe flag of the specified file descriptor.");
6305
6306#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006307 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006308
6309static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006310os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006311
6312static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006313os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006314{
6315 PyObject *return_value = NULL;
6316 int fd;
6317 int _return_value;
6318
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006319 if (PyFloat_Check(arg)) {
6320 PyErr_SetString(PyExc_TypeError,
6321 "integer argument expected, got float" );
6322 goto exit;
6323 }
6324 fd = _PyLong_AsInt(arg);
6325 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006326 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006327 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006328 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006329 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006332 return_value = PyBool_FromLong((long)_return_value);
6333
6334exit:
6335 return return_value;
6336}
6337
6338PyDoc_STRVAR(os_set_inheritable__doc__,
6339"set_inheritable($module, fd, inheritable, /)\n"
6340"--\n"
6341"\n"
6342"Set the inheritable flag of the specified file descriptor.");
6343
6344#define OS_SET_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006345 {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006346
6347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006348os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006349
6350static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006351os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006352{
6353 PyObject *return_value = NULL;
6354 int fd;
6355 int inheritable;
6356
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006357 if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
6358 goto exit;
6359 }
6360 if (PyFloat_Check(args[0])) {
6361 PyErr_SetString(PyExc_TypeError,
6362 "integer argument expected, got float" );
6363 goto exit;
6364 }
6365 fd = _PyLong_AsInt(args[0]);
6366 if (fd == -1 && PyErr_Occurred()) {
6367 goto exit;
6368 }
6369 if (PyFloat_Check(args[1])) {
6370 PyErr_SetString(PyExc_TypeError,
6371 "integer argument expected, got float" );
6372 goto exit;
6373 }
6374 inheritable = _PyLong_AsInt(args[1]);
6375 if (inheritable == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006376 goto exit;
6377 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006378 return_value = os_set_inheritable_impl(module, fd, inheritable);
6379
6380exit:
6381 return return_value;
6382}
6383
6384#if defined(MS_WINDOWS)
6385
6386PyDoc_STRVAR(os_get_handle_inheritable__doc__,
6387"get_handle_inheritable($module, handle, /)\n"
6388"--\n"
6389"\n"
6390"Get the close-on-exe flag of the specified file descriptor.");
6391
6392#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006393 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006394
6395static int
Victor Stinner581139c2016-09-06 15:54:20 -07006396os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006397
6398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006399os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006400{
6401 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07006402 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006403 int _return_value;
6404
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006405 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006406 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006407 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006408 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006409 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006410 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006411 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006412 return_value = PyBool_FromLong((long)_return_value);
6413
6414exit:
6415 return return_value;
6416}
6417
6418#endif /* defined(MS_WINDOWS) */
6419
6420#if defined(MS_WINDOWS)
6421
6422PyDoc_STRVAR(os_set_handle_inheritable__doc__,
6423"set_handle_inheritable($module, handle, inheritable, /)\n"
6424"--\n"
6425"\n"
6426"Set the inheritable flag of the specified handle.");
6427
6428#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006429 {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006430
6431static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07006432os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04006433 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006434
6435static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006436os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006437{
6438 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07006439 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006440 int inheritable;
6441
Sylvain74453812017-06-10 06:51:48 +02006442 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
6443 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006444 goto exit;
6445 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006446 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
6447
6448exit:
6449 return return_value;
6450}
6451
6452#endif /* defined(MS_WINDOWS) */
6453
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006454#if !defined(MS_WINDOWS)
6455
6456PyDoc_STRVAR(os_get_blocking__doc__,
6457"get_blocking($module, fd, /)\n"
6458"--\n"
6459"\n"
6460"Get the blocking mode of the file descriptor.\n"
6461"\n"
6462"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
6463
6464#define OS_GET_BLOCKING_METHODDEF \
6465 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
6466
6467static int
6468os_get_blocking_impl(PyObject *module, int fd);
6469
6470static PyObject *
6471os_get_blocking(PyObject *module, PyObject *arg)
6472{
6473 PyObject *return_value = NULL;
6474 int fd;
6475 int _return_value;
6476
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006477 if (PyFloat_Check(arg)) {
6478 PyErr_SetString(PyExc_TypeError,
6479 "integer argument expected, got float" );
6480 goto exit;
6481 }
6482 fd = _PyLong_AsInt(arg);
6483 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006484 goto exit;
6485 }
6486 _return_value = os_get_blocking_impl(module, fd);
6487 if ((_return_value == -1) && PyErr_Occurred()) {
6488 goto exit;
6489 }
6490 return_value = PyBool_FromLong((long)_return_value);
6491
6492exit:
6493 return return_value;
6494}
6495
6496#endif /* !defined(MS_WINDOWS) */
6497
6498#if !defined(MS_WINDOWS)
6499
6500PyDoc_STRVAR(os_set_blocking__doc__,
6501"set_blocking($module, fd, blocking, /)\n"
6502"--\n"
6503"\n"
6504"Set the blocking mode of the specified file descriptor.\n"
6505"\n"
6506"Set the O_NONBLOCK flag if blocking is False,\n"
6507"clear the O_NONBLOCK flag otherwise.");
6508
6509#define OS_SET_BLOCKING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006510 {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006511
6512static PyObject *
6513os_set_blocking_impl(PyObject *module, int fd, int blocking);
6514
6515static PyObject *
6516os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6517{
6518 PyObject *return_value = NULL;
6519 int fd;
6520 int blocking;
6521
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006522 if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
6523 goto exit;
6524 }
6525 if (PyFloat_Check(args[0])) {
6526 PyErr_SetString(PyExc_TypeError,
6527 "integer argument expected, got float" );
6528 goto exit;
6529 }
6530 fd = _PyLong_AsInt(args[0]);
6531 if (fd == -1 && PyErr_Occurred()) {
6532 goto exit;
6533 }
6534 if (PyFloat_Check(args[1])) {
6535 PyErr_SetString(PyExc_TypeError,
6536 "integer argument expected, got float" );
6537 goto exit;
6538 }
6539 blocking = _PyLong_AsInt(args[1]);
6540 if (blocking == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006541 goto exit;
6542 }
6543 return_value = os_set_blocking_impl(module, fd, blocking);
6544
6545exit:
6546 return return_value;
6547}
6548
6549#endif /* !defined(MS_WINDOWS) */
6550
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006551PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
6552"is_symlink($self, /)\n"
6553"--\n"
6554"\n"
6555"Return True if the entry is a symbolic link; cached per entry.");
6556
6557#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
6558 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
6559
6560static int
6561os_DirEntry_is_symlink_impl(DirEntry *self);
6562
6563static PyObject *
6564os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
6565{
6566 PyObject *return_value = NULL;
6567 int _return_value;
6568
6569 _return_value = os_DirEntry_is_symlink_impl(self);
6570 if ((_return_value == -1) && PyErr_Occurred()) {
6571 goto exit;
6572 }
6573 return_value = PyBool_FromLong((long)_return_value);
6574
6575exit:
6576 return return_value;
6577}
6578
6579PyDoc_STRVAR(os_DirEntry_stat__doc__,
6580"stat($self, /, *, follow_symlinks=True)\n"
6581"--\n"
6582"\n"
6583"Return stat_result object for the entry; cached per entry.");
6584
6585#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006586 {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006587
6588static PyObject *
6589os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
6590
6591static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006592os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006593{
6594 PyObject *return_value = NULL;
6595 static const char * const _keywords[] = {"follow_symlinks", NULL};
6596 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
6597 int follow_symlinks = 1;
6598
Victor Stinner3e1fad62017-01-17 01:29:01 +01006599 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006600 &follow_symlinks)) {
6601 goto exit;
6602 }
6603 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
6604
6605exit:
6606 return return_value;
6607}
6608
6609PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
6610"is_dir($self, /, *, follow_symlinks=True)\n"
6611"--\n"
6612"\n"
6613"Return True if the entry is a directory; cached per entry.");
6614
6615#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006616 {"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 +02006617
6618static int
6619os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
6620
6621static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006622os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006623{
6624 PyObject *return_value = NULL;
6625 static const char * const _keywords[] = {"follow_symlinks", NULL};
6626 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
6627 int follow_symlinks = 1;
6628 int _return_value;
6629
Victor Stinner3e1fad62017-01-17 01:29:01 +01006630 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006631 &follow_symlinks)) {
6632 goto exit;
6633 }
6634 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
6635 if ((_return_value == -1) && PyErr_Occurred()) {
6636 goto exit;
6637 }
6638 return_value = PyBool_FromLong((long)_return_value);
6639
6640exit:
6641 return return_value;
6642}
6643
6644PyDoc_STRVAR(os_DirEntry_is_file__doc__,
6645"is_file($self, /, *, follow_symlinks=True)\n"
6646"--\n"
6647"\n"
6648"Return True if the entry is a file; cached per entry.");
6649
6650#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006651 {"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 +02006652
6653static int
6654os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
6655
6656static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006657os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006658{
6659 PyObject *return_value = NULL;
6660 static const char * const _keywords[] = {"follow_symlinks", NULL};
6661 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
6662 int follow_symlinks = 1;
6663 int _return_value;
6664
Victor Stinner3e1fad62017-01-17 01:29:01 +01006665 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006666 &follow_symlinks)) {
6667 goto exit;
6668 }
6669 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
6670 if ((_return_value == -1) && PyErr_Occurred()) {
6671 goto exit;
6672 }
6673 return_value = PyBool_FromLong((long)_return_value);
6674
6675exit:
6676 return return_value;
6677}
6678
6679PyDoc_STRVAR(os_DirEntry_inode__doc__,
6680"inode($self, /)\n"
6681"--\n"
6682"\n"
6683"Return inode of the entry; cached per entry.");
6684
6685#define OS_DIRENTRY_INODE_METHODDEF \
6686 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6687
6688static PyObject *
6689os_DirEntry_inode_impl(DirEntry *self);
6690
6691static PyObject *
6692os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6693{
6694 return os_DirEntry_inode_impl(self);
6695}
6696
6697PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6698"__fspath__($self, /)\n"
6699"--\n"
6700"\n"
6701"Returns the path for the entry.");
6702
6703#define OS_DIRENTRY___FSPATH___METHODDEF \
6704 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6705
6706static PyObject *
6707os_DirEntry___fspath___impl(DirEntry *self);
6708
6709static PyObject *
6710os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6711{
6712 return os_DirEntry___fspath___impl(self);
6713}
6714
6715PyDoc_STRVAR(os_scandir__doc__,
6716"scandir($module, /, path=None)\n"
6717"--\n"
6718"\n"
6719"Return an iterator of DirEntry objects for given path.\n"
6720"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006721"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006722"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6723"all other circumstances they will be str.\n"
6724"\n"
6725"If path is None, uses the path=\'.\'.");
6726
6727#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006728 {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006729
6730static PyObject *
6731os_scandir_impl(PyObject *module, path_t *path);
6732
6733static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006734os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006735{
6736 PyObject *return_value = NULL;
6737 static const char * const _keywords[] = {"path", NULL};
6738 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006739 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006740
Victor Stinner3e1fad62017-01-17 01:29:01 +01006741 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006742 path_converter, &path)) {
6743 goto exit;
6744 }
6745 return_value = os_scandir_impl(module, &path);
6746
6747exit:
6748 /* Cleanup for path */
6749 path_cleanup(&path);
6750
6751 return return_value;
6752}
6753
Ethan Furman410ef8e2016-06-04 12:06:26 -07006754PyDoc_STRVAR(os_fspath__doc__,
6755"fspath($module, /, path)\n"
6756"--\n"
6757"\n"
6758"Return the file system path representation of the object.\n"
6759"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006760"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6761"object defines __fspath__(), then return the result of that method. All other\n"
6762"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006763
6764#define OS_FSPATH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006765 {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006766
6767static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006768os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006769
6770static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006771os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006772{
6773 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006774 static const char * const _keywords[] = {"path", NULL};
6775 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006776 PyObject *path;
6777
Victor Stinner3e1fad62017-01-17 01:29:01 +01006778 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006779 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006780 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006781 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006782 return_value = os_fspath_impl(module, path);
6783
6784exit:
6785 return return_value;
6786}
6787
Victor Stinner9b1f4742016-09-06 16:18:52 -07006788#if defined(HAVE_GETRANDOM_SYSCALL)
6789
6790PyDoc_STRVAR(os_getrandom__doc__,
6791"getrandom($module, /, size, flags=0)\n"
6792"--\n"
6793"\n"
6794"Obtain a series of random bytes.");
6795
6796#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006797 {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006798
6799static PyObject *
6800os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6801
6802static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006803os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006804{
6805 PyObject *return_value = NULL;
6806 static const char * const _keywords[] = {"size", "flags", NULL};
6807 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6808 Py_ssize_t size;
6809 int flags = 0;
6810
Victor Stinner3e1fad62017-01-17 01:29:01 +01006811 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006812 &size, &flags)) {
6813 goto exit;
6814 }
6815 return_value = os_getrandom_impl(module, size, flags);
6816
6817exit:
6818 return return_value;
6819}
6820
6821#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6822
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006823#ifndef OS_TTYNAME_METHODDEF
6824 #define OS_TTYNAME_METHODDEF
6825#endif /* !defined(OS_TTYNAME_METHODDEF) */
6826
6827#ifndef OS_CTERMID_METHODDEF
6828 #define OS_CTERMID_METHODDEF
6829#endif /* !defined(OS_CTERMID_METHODDEF) */
6830
6831#ifndef OS_FCHDIR_METHODDEF
6832 #define OS_FCHDIR_METHODDEF
6833#endif /* !defined(OS_FCHDIR_METHODDEF) */
6834
6835#ifndef OS_FCHMOD_METHODDEF
6836 #define OS_FCHMOD_METHODDEF
6837#endif /* !defined(OS_FCHMOD_METHODDEF) */
6838
6839#ifndef OS_LCHMOD_METHODDEF
6840 #define OS_LCHMOD_METHODDEF
6841#endif /* !defined(OS_LCHMOD_METHODDEF) */
6842
6843#ifndef OS_CHFLAGS_METHODDEF
6844 #define OS_CHFLAGS_METHODDEF
6845#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6846
6847#ifndef OS_LCHFLAGS_METHODDEF
6848 #define OS_LCHFLAGS_METHODDEF
6849#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6850
6851#ifndef OS_CHROOT_METHODDEF
6852 #define OS_CHROOT_METHODDEF
6853#endif /* !defined(OS_CHROOT_METHODDEF) */
6854
6855#ifndef OS_FSYNC_METHODDEF
6856 #define OS_FSYNC_METHODDEF
6857#endif /* !defined(OS_FSYNC_METHODDEF) */
6858
6859#ifndef OS_SYNC_METHODDEF
6860 #define OS_SYNC_METHODDEF
6861#endif /* !defined(OS_SYNC_METHODDEF) */
6862
6863#ifndef OS_FDATASYNC_METHODDEF
6864 #define OS_FDATASYNC_METHODDEF
6865#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6866
6867#ifndef OS_CHOWN_METHODDEF
6868 #define OS_CHOWN_METHODDEF
6869#endif /* !defined(OS_CHOWN_METHODDEF) */
6870
6871#ifndef OS_FCHOWN_METHODDEF
6872 #define OS_FCHOWN_METHODDEF
6873#endif /* !defined(OS_FCHOWN_METHODDEF) */
6874
6875#ifndef OS_LCHOWN_METHODDEF
6876 #define OS_LCHOWN_METHODDEF
6877#endif /* !defined(OS_LCHOWN_METHODDEF) */
6878
6879#ifndef OS_LINK_METHODDEF
6880 #define OS_LINK_METHODDEF
6881#endif /* !defined(OS_LINK_METHODDEF) */
6882
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006883#ifndef OS__GETFULLPATHNAME_METHODDEF
6884 #define OS__GETFULLPATHNAME_METHODDEF
6885#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6886
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006887#ifndef OS__GETFINALPATHNAME_METHODDEF
6888 #define OS__GETFINALPATHNAME_METHODDEF
6889#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6890
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006891#ifndef OS__ISDIR_METHODDEF
6892 #define OS__ISDIR_METHODDEF
6893#endif /* !defined(OS__ISDIR_METHODDEF) */
6894
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006895#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6896 #define OS__GETVOLUMEPATHNAME_METHODDEF
6897#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6898
6899#ifndef OS_NICE_METHODDEF
6900 #define OS_NICE_METHODDEF
6901#endif /* !defined(OS_NICE_METHODDEF) */
6902
6903#ifndef OS_GETPRIORITY_METHODDEF
6904 #define OS_GETPRIORITY_METHODDEF
6905#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6906
6907#ifndef OS_SETPRIORITY_METHODDEF
6908 #define OS_SETPRIORITY_METHODDEF
6909#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6910
6911#ifndef OS_SYSTEM_METHODDEF
6912 #define OS_SYSTEM_METHODDEF
6913#endif /* !defined(OS_SYSTEM_METHODDEF) */
6914
6915#ifndef OS_UNAME_METHODDEF
6916 #define OS_UNAME_METHODDEF
6917#endif /* !defined(OS_UNAME_METHODDEF) */
6918
6919#ifndef OS_EXECV_METHODDEF
6920 #define OS_EXECV_METHODDEF
6921#endif /* !defined(OS_EXECV_METHODDEF) */
6922
6923#ifndef OS_EXECVE_METHODDEF
6924 #define OS_EXECVE_METHODDEF
6925#endif /* !defined(OS_EXECVE_METHODDEF) */
6926
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006927#ifndef OS_POSIX_SPAWN_METHODDEF
6928 #define OS_POSIX_SPAWN_METHODDEF
6929#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6930
Joannah Nanjekye92b83222019-01-16 16:29:26 +03006931#ifndef OS_POSIX_SPAWNP_METHODDEF
6932 #define OS_POSIX_SPAWNP_METHODDEF
6933#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
6934
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006935#ifndef OS_SPAWNV_METHODDEF
6936 #define OS_SPAWNV_METHODDEF
6937#endif /* !defined(OS_SPAWNV_METHODDEF) */
6938
6939#ifndef OS_SPAWNVE_METHODDEF
6940 #define OS_SPAWNVE_METHODDEF
6941#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6942
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006943#ifndef OS_REGISTER_AT_FORK_METHODDEF
6944 #define OS_REGISTER_AT_FORK_METHODDEF
6945#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6946
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006947#ifndef OS_FORK1_METHODDEF
6948 #define OS_FORK1_METHODDEF
6949#endif /* !defined(OS_FORK1_METHODDEF) */
6950
6951#ifndef OS_FORK_METHODDEF
6952 #define OS_FORK_METHODDEF
6953#endif /* !defined(OS_FORK_METHODDEF) */
6954
6955#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6956 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6957#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6958
6959#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6960 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6961#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6962
6963#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6964 #define OS_SCHED_GETSCHEDULER_METHODDEF
6965#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6966
6967#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6968 #define OS_SCHED_SETSCHEDULER_METHODDEF
6969#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6970
6971#ifndef OS_SCHED_GETPARAM_METHODDEF
6972 #define OS_SCHED_GETPARAM_METHODDEF
6973#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6974
6975#ifndef OS_SCHED_SETPARAM_METHODDEF
6976 #define OS_SCHED_SETPARAM_METHODDEF
6977#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6978
6979#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6980 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6981#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6982
6983#ifndef OS_SCHED_YIELD_METHODDEF
6984 #define OS_SCHED_YIELD_METHODDEF
6985#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6986
6987#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6988 #define OS_SCHED_SETAFFINITY_METHODDEF
6989#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6990
6991#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6992 #define OS_SCHED_GETAFFINITY_METHODDEF
6993#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6994
6995#ifndef OS_OPENPTY_METHODDEF
6996 #define OS_OPENPTY_METHODDEF
6997#endif /* !defined(OS_OPENPTY_METHODDEF) */
6998
6999#ifndef OS_FORKPTY_METHODDEF
7000 #define OS_FORKPTY_METHODDEF
7001#endif /* !defined(OS_FORKPTY_METHODDEF) */
7002
7003#ifndef OS_GETEGID_METHODDEF
7004 #define OS_GETEGID_METHODDEF
7005#endif /* !defined(OS_GETEGID_METHODDEF) */
7006
7007#ifndef OS_GETEUID_METHODDEF
7008 #define OS_GETEUID_METHODDEF
7009#endif /* !defined(OS_GETEUID_METHODDEF) */
7010
7011#ifndef OS_GETGID_METHODDEF
7012 #define OS_GETGID_METHODDEF
7013#endif /* !defined(OS_GETGID_METHODDEF) */
7014
Berker Peksag39404992016-09-15 20:45:16 +03007015#ifndef OS_GETPID_METHODDEF
7016 #define OS_GETPID_METHODDEF
7017#endif /* !defined(OS_GETPID_METHODDEF) */
7018
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007019#ifndef OS_GETGROUPS_METHODDEF
7020 #define OS_GETGROUPS_METHODDEF
7021#endif /* !defined(OS_GETGROUPS_METHODDEF) */
7022
7023#ifndef OS_GETPGID_METHODDEF
7024 #define OS_GETPGID_METHODDEF
7025#endif /* !defined(OS_GETPGID_METHODDEF) */
7026
7027#ifndef OS_GETPGRP_METHODDEF
7028 #define OS_GETPGRP_METHODDEF
7029#endif /* !defined(OS_GETPGRP_METHODDEF) */
7030
7031#ifndef OS_SETPGRP_METHODDEF
7032 #define OS_SETPGRP_METHODDEF
7033#endif /* !defined(OS_SETPGRP_METHODDEF) */
7034
7035#ifndef OS_GETPPID_METHODDEF
7036 #define OS_GETPPID_METHODDEF
7037#endif /* !defined(OS_GETPPID_METHODDEF) */
7038
7039#ifndef OS_GETLOGIN_METHODDEF
7040 #define OS_GETLOGIN_METHODDEF
7041#endif /* !defined(OS_GETLOGIN_METHODDEF) */
7042
7043#ifndef OS_GETUID_METHODDEF
7044 #define OS_GETUID_METHODDEF
7045#endif /* !defined(OS_GETUID_METHODDEF) */
7046
7047#ifndef OS_KILL_METHODDEF
7048 #define OS_KILL_METHODDEF
7049#endif /* !defined(OS_KILL_METHODDEF) */
7050
7051#ifndef OS_KILLPG_METHODDEF
7052 #define OS_KILLPG_METHODDEF
7053#endif /* !defined(OS_KILLPG_METHODDEF) */
7054
7055#ifndef OS_PLOCK_METHODDEF
7056 #define OS_PLOCK_METHODDEF
7057#endif /* !defined(OS_PLOCK_METHODDEF) */
7058
7059#ifndef OS_SETUID_METHODDEF
7060 #define OS_SETUID_METHODDEF
7061#endif /* !defined(OS_SETUID_METHODDEF) */
7062
7063#ifndef OS_SETEUID_METHODDEF
7064 #define OS_SETEUID_METHODDEF
7065#endif /* !defined(OS_SETEUID_METHODDEF) */
7066
7067#ifndef OS_SETEGID_METHODDEF
7068 #define OS_SETEGID_METHODDEF
7069#endif /* !defined(OS_SETEGID_METHODDEF) */
7070
7071#ifndef OS_SETREUID_METHODDEF
7072 #define OS_SETREUID_METHODDEF
7073#endif /* !defined(OS_SETREUID_METHODDEF) */
7074
7075#ifndef OS_SETREGID_METHODDEF
7076 #define OS_SETREGID_METHODDEF
7077#endif /* !defined(OS_SETREGID_METHODDEF) */
7078
7079#ifndef OS_SETGID_METHODDEF
7080 #define OS_SETGID_METHODDEF
7081#endif /* !defined(OS_SETGID_METHODDEF) */
7082
7083#ifndef OS_SETGROUPS_METHODDEF
7084 #define OS_SETGROUPS_METHODDEF
7085#endif /* !defined(OS_SETGROUPS_METHODDEF) */
7086
7087#ifndef OS_WAIT3_METHODDEF
7088 #define OS_WAIT3_METHODDEF
7089#endif /* !defined(OS_WAIT3_METHODDEF) */
7090
7091#ifndef OS_WAIT4_METHODDEF
7092 #define OS_WAIT4_METHODDEF
7093#endif /* !defined(OS_WAIT4_METHODDEF) */
7094
7095#ifndef OS_WAITID_METHODDEF
7096 #define OS_WAITID_METHODDEF
7097#endif /* !defined(OS_WAITID_METHODDEF) */
7098
7099#ifndef OS_WAITPID_METHODDEF
7100 #define OS_WAITPID_METHODDEF
7101#endif /* !defined(OS_WAITPID_METHODDEF) */
7102
7103#ifndef OS_WAIT_METHODDEF
7104 #define OS_WAIT_METHODDEF
7105#endif /* !defined(OS_WAIT_METHODDEF) */
7106
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007107#ifndef OS_READLINK_METHODDEF
7108 #define OS_READLINK_METHODDEF
7109#endif /* !defined(OS_READLINK_METHODDEF) */
7110
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007111#ifndef OS_SYMLINK_METHODDEF
7112 #define OS_SYMLINK_METHODDEF
7113#endif /* !defined(OS_SYMLINK_METHODDEF) */
7114
7115#ifndef OS_TIMES_METHODDEF
7116 #define OS_TIMES_METHODDEF
7117#endif /* !defined(OS_TIMES_METHODDEF) */
7118
7119#ifndef OS_GETSID_METHODDEF
7120 #define OS_GETSID_METHODDEF
7121#endif /* !defined(OS_GETSID_METHODDEF) */
7122
7123#ifndef OS_SETSID_METHODDEF
7124 #define OS_SETSID_METHODDEF
7125#endif /* !defined(OS_SETSID_METHODDEF) */
7126
7127#ifndef OS_SETPGID_METHODDEF
7128 #define OS_SETPGID_METHODDEF
7129#endif /* !defined(OS_SETPGID_METHODDEF) */
7130
7131#ifndef OS_TCGETPGRP_METHODDEF
7132 #define OS_TCGETPGRP_METHODDEF
7133#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
7134
7135#ifndef OS_TCSETPGRP_METHODDEF
7136 #define OS_TCSETPGRP_METHODDEF
7137#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
7138
7139#ifndef OS_LOCKF_METHODDEF
7140 #define OS_LOCKF_METHODDEF
7141#endif /* !defined(OS_LOCKF_METHODDEF) */
7142
7143#ifndef OS_READV_METHODDEF
7144 #define OS_READV_METHODDEF
7145#endif /* !defined(OS_READV_METHODDEF) */
7146
7147#ifndef OS_PREAD_METHODDEF
7148 #define OS_PREAD_METHODDEF
7149#endif /* !defined(OS_PREAD_METHODDEF) */
7150
Pablo Galindo4defba32018-01-27 16:16:37 +00007151#ifndef OS_PREADV_METHODDEF
7152 #define OS_PREADV_METHODDEF
7153#endif /* !defined(OS_PREADV_METHODDEF) */
7154
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02007155#ifndef OS__FCOPYFILE_METHODDEF
7156 #define OS__FCOPYFILE_METHODDEF
7157#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
7158
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007159#ifndef OS_PIPE_METHODDEF
7160 #define OS_PIPE_METHODDEF
7161#endif /* !defined(OS_PIPE_METHODDEF) */
7162
7163#ifndef OS_PIPE2_METHODDEF
7164 #define OS_PIPE2_METHODDEF
7165#endif /* !defined(OS_PIPE2_METHODDEF) */
7166
7167#ifndef OS_WRITEV_METHODDEF
7168 #define OS_WRITEV_METHODDEF
7169#endif /* !defined(OS_WRITEV_METHODDEF) */
7170
7171#ifndef OS_PWRITE_METHODDEF
7172 #define OS_PWRITE_METHODDEF
7173#endif /* !defined(OS_PWRITE_METHODDEF) */
7174
Pablo Galindo4defba32018-01-27 16:16:37 +00007175#ifndef OS_PWRITEV_METHODDEF
7176 #define OS_PWRITEV_METHODDEF
7177#endif /* !defined(OS_PWRITEV_METHODDEF) */
7178
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007179#ifndef OS_MKFIFO_METHODDEF
7180 #define OS_MKFIFO_METHODDEF
7181#endif /* !defined(OS_MKFIFO_METHODDEF) */
7182
7183#ifndef OS_MKNOD_METHODDEF
7184 #define OS_MKNOD_METHODDEF
7185#endif /* !defined(OS_MKNOD_METHODDEF) */
7186
7187#ifndef OS_MAJOR_METHODDEF
7188 #define OS_MAJOR_METHODDEF
7189#endif /* !defined(OS_MAJOR_METHODDEF) */
7190
7191#ifndef OS_MINOR_METHODDEF
7192 #define OS_MINOR_METHODDEF
7193#endif /* !defined(OS_MINOR_METHODDEF) */
7194
7195#ifndef OS_MAKEDEV_METHODDEF
7196 #define OS_MAKEDEV_METHODDEF
7197#endif /* !defined(OS_MAKEDEV_METHODDEF) */
7198
7199#ifndef OS_FTRUNCATE_METHODDEF
7200 #define OS_FTRUNCATE_METHODDEF
7201#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
7202
7203#ifndef OS_TRUNCATE_METHODDEF
7204 #define OS_TRUNCATE_METHODDEF
7205#endif /* !defined(OS_TRUNCATE_METHODDEF) */
7206
7207#ifndef OS_POSIX_FALLOCATE_METHODDEF
7208 #define OS_POSIX_FALLOCATE_METHODDEF
7209#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
7210
7211#ifndef OS_POSIX_FADVISE_METHODDEF
7212 #define OS_POSIX_FADVISE_METHODDEF
7213#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
7214
7215#ifndef OS_PUTENV_METHODDEF
7216 #define OS_PUTENV_METHODDEF
7217#endif /* !defined(OS_PUTENV_METHODDEF) */
7218
7219#ifndef OS_UNSETENV_METHODDEF
7220 #define OS_UNSETENV_METHODDEF
7221#endif /* !defined(OS_UNSETENV_METHODDEF) */
7222
7223#ifndef OS_WCOREDUMP_METHODDEF
7224 #define OS_WCOREDUMP_METHODDEF
7225#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
7226
7227#ifndef OS_WIFCONTINUED_METHODDEF
7228 #define OS_WIFCONTINUED_METHODDEF
7229#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
7230
7231#ifndef OS_WIFSTOPPED_METHODDEF
7232 #define OS_WIFSTOPPED_METHODDEF
7233#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
7234
7235#ifndef OS_WIFSIGNALED_METHODDEF
7236 #define OS_WIFSIGNALED_METHODDEF
7237#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
7238
7239#ifndef OS_WIFEXITED_METHODDEF
7240 #define OS_WIFEXITED_METHODDEF
7241#endif /* !defined(OS_WIFEXITED_METHODDEF) */
7242
7243#ifndef OS_WEXITSTATUS_METHODDEF
7244 #define OS_WEXITSTATUS_METHODDEF
7245#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
7246
7247#ifndef OS_WTERMSIG_METHODDEF
7248 #define OS_WTERMSIG_METHODDEF
7249#endif /* !defined(OS_WTERMSIG_METHODDEF) */
7250
7251#ifndef OS_WSTOPSIG_METHODDEF
7252 #define OS_WSTOPSIG_METHODDEF
7253#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
7254
7255#ifndef OS_FSTATVFS_METHODDEF
7256 #define OS_FSTATVFS_METHODDEF
7257#endif /* !defined(OS_FSTATVFS_METHODDEF) */
7258
7259#ifndef OS_STATVFS_METHODDEF
7260 #define OS_STATVFS_METHODDEF
7261#endif /* !defined(OS_STATVFS_METHODDEF) */
7262
7263#ifndef OS__GETDISKUSAGE_METHODDEF
7264 #define OS__GETDISKUSAGE_METHODDEF
7265#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
7266
7267#ifndef OS_FPATHCONF_METHODDEF
7268 #define OS_FPATHCONF_METHODDEF
7269#endif /* !defined(OS_FPATHCONF_METHODDEF) */
7270
7271#ifndef OS_PATHCONF_METHODDEF
7272 #define OS_PATHCONF_METHODDEF
7273#endif /* !defined(OS_PATHCONF_METHODDEF) */
7274
7275#ifndef OS_CONFSTR_METHODDEF
7276 #define OS_CONFSTR_METHODDEF
7277#endif /* !defined(OS_CONFSTR_METHODDEF) */
7278
7279#ifndef OS_SYSCONF_METHODDEF
7280 #define OS_SYSCONF_METHODDEF
7281#endif /* !defined(OS_SYSCONF_METHODDEF) */
7282
Steve Dowercc16be82016-09-08 10:35:16 -07007283#ifndef OS_STARTFILE_METHODDEF
7284 #define OS_STARTFILE_METHODDEF
7285#endif /* !defined(OS_STARTFILE_METHODDEF) */
7286
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007287#ifndef OS_GETLOADAVG_METHODDEF
7288 #define OS_GETLOADAVG_METHODDEF
7289#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
7290
7291#ifndef OS_SETRESUID_METHODDEF
7292 #define OS_SETRESUID_METHODDEF
7293#endif /* !defined(OS_SETRESUID_METHODDEF) */
7294
7295#ifndef OS_SETRESGID_METHODDEF
7296 #define OS_SETRESGID_METHODDEF
7297#endif /* !defined(OS_SETRESGID_METHODDEF) */
7298
7299#ifndef OS_GETRESUID_METHODDEF
7300 #define OS_GETRESUID_METHODDEF
7301#endif /* !defined(OS_GETRESUID_METHODDEF) */
7302
7303#ifndef OS_GETRESGID_METHODDEF
7304 #define OS_GETRESGID_METHODDEF
7305#endif /* !defined(OS_GETRESGID_METHODDEF) */
7306
7307#ifndef OS_GETXATTR_METHODDEF
7308 #define OS_GETXATTR_METHODDEF
7309#endif /* !defined(OS_GETXATTR_METHODDEF) */
7310
7311#ifndef OS_SETXATTR_METHODDEF
7312 #define OS_SETXATTR_METHODDEF
7313#endif /* !defined(OS_SETXATTR_METHODDEF) */
7314
7315#ifndef OS_REMOVEXATTR_METHODDEF
7316 #define OS_REMOVEXATTR_METHODDEF
7317#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
7318
7319#ifndef OS_LISTXATTR_METHODDEF
7320 #define OS_LISTXATTR_METHODDEF
7321#endif /* !defined(OS_LISTXATTR_METHODDEF) */
7322
7323#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
7324 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
7325#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
7326
7327#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
7328 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
7329#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07007330
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007331#ifndef OS_GET_BLOCKING_METHODDEF
7332 #define OS_GET_BLOCKING_METHODDEF
7333#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
7334
7335#ifndef OS_SET_BLOCKING_METHODDEF
7336 #define OS_SET_BLOCKING_METHODDEF
7337#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
7338
Victor Stinner9b1f4742016-09-06 16:18:52 -07007339#ifndef OS_GETRANDOM_METHODDEF
7340 #define OS_GETRANDOM_METHODDEF
7341#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03007342/*[clinic end generated code: output=d50ff73e5b5198b9 input=a9049054013a1b77]*/