blob: e310d99cf46825903fce3a5e31f73985fa74f941 [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
Sylvain74453812017-06-10 06:51:48 +02001661 if (!_PyArg_ParseStack(args, nargs, "O&O:execv",
1662 path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001663 goto exit;
1664 }
Steve Dowercc16be82016-09-08 10:35:16 -07001665 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001666
1667exit:
1668 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001669 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001670
1671 return return_value;
1672}
1673
1674#endif /* defined(HAVE_EXECV) */
1675
1676#if defined(HAVE_EXECV)
1677
1678PyDoc_STRVAR(os_execve__doc__,
1679"execve($module, /, path, argv, env)\n"
1680"--\n"
1681"\n"
1682"Execute an executable path with arguments, replacing current process.\n"
1683"\n"
1684" path\n"
1685" Path of executable file.\n"
1686" argv\n"
1687" Tuple or list of strings.\n"
1688" env\n"
1689" Dictionary of strings mapping to strings.");
1690
1691#define OS_EXECVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001692 {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001693
1694static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001695os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001696
1697static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001698os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001699{
1700 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001701 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1702 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001703 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1704 PyObject *argv;
1705 PyObject *env;
1706
Victor Stinner3e1fad62017-01-17 01:29:01 +01001707 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001708 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001709 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001710 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001711 return_value = os_execve_impl(module, &path, argv, env);
1712
1713exit:
1714 /* Cleanup for path */
1715 path_cleanup(&path);
1716
1717 return return_value;
1718}
1719
1720#endif /* defined(HAVE_EXECV) */
1721
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001722#if defined(HAVE_POSIX_SPAWN)
1723
1724PyDoc_STRVAR(os_posix_spawn__doc__,
Serhiy Storchakad700f972018-09-08 14:48:18 +03001725"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001726" setpgroup=None, resetids=False, setsigmask=(),\n"
1727" setsigdef=(), scheduler=None)\n"
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001728"--\n"
1729"\n"
1730"Execute the program specified by path in a new process.\n"
1731"\n"
1732" path\n"
1733" Path of executable file.\n"
1734" argv\n"
1735" Tuple or list of strings.\n"
1736" env\n"
1737" Dictionary of strings mapping to strings.\n"
1738" file_actions\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001739" A sequence of file action tuples.\n"
1740" setpgroup\n"
1741" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1742" resetids\n"
1743" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
1744" setsigmask\n"
1745" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1746" setsigdef\n"
1747" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1748" scheduler\n"
1749" A tuple with the scheduler policy (optional) and parameters.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001750
1751#define OS_POSIX_SPAWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001752 {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001753
1754static PyObject *
1755os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
Pablo Galindo254a4662018-09-07 16:44:24 +01001756 PyObject *env, PyObject *file_actions,
1757 PyObject *setpgroup, int resetids, PyObject *setsigmask,
1758 PyObject *setsigdef, PyObject *scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001759
1760static PyObject *
Pablo Galindo254a4662018-09-07 16:44:24 +01001761os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001762{
1763 PyObject *return_value = NULL;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001764 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL};
1765 static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawn", _keywords, 0};
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001766 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1767 PyObject *argv;
1768 PyObject *env;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001769 PyObject *file_actions = NULL;
Pablo Galindo254a4662018-09-07 16:44:24 +01001770 PyObject *setpgroup = NULL;
1771 int resetids = 0;
1772 PyObject *setsigmask = NULL;
1773 PyObject *setsigdef = NULL;
1774 PyObject *scheduler = NULL;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001775
Pablo Galindo254a4662018-09-07 16:44:24 +01001776 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1777 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) {
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001778 goto exit;
1779 }
Pablo Galindo254a4662018-09-07 16:44:24 +01001780 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001781
1782exit:
1783 /* Cleanup for path */
1784 path_cleanup(&path);
1785
1786 return return_value;
1787}
1788
1789#endif /* defined(HAVE_POSIX_SPAWN) */
1790
Steve Dowercc16be82016-09-08 10:35:16 -07001791#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001792
1793PyDoc_STRVAR(os_spawnv__doc__,
1794"spawnv($module, mode, path, argv, /)\n"
1795"--\n"
1796"\n"
1797"Execute the program specified by path in a new process.\n"
1798"\n"
1799" mode\n"
1800" Mode of process creation.\n"
1801" path\n"
1802" Path of executable file.\n"
1803" argv\n"
1804" Tuple or list of strings.");
1805
1806#define OS_SPAWNV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001807 {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001808
1809static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001810os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001811
1812static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001813os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001814{
1815 PyObject *return_value = NULL;
1816 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001817 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001818 PyObject *argv;
1819
Sylvain74453812017-06-10 06:51:48 +02001820 if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv",
1821 &mode, path_converter, &path, &argv)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001822 goto exit;
1823 }
Steve Dowercc16be82016-09-08 10:35:16 -07001824 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001825
1826exit:
1827 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001828 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001829
1830 return return_value;
1831}
1832
Steve Dowercc16be82016-09-08 10:35:16 -07001833#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001834
Steve Dowercc16be82016-09-08 10:35:16 -07001835#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001836
1837PyDoc_STRVAR(os_spawnve__doc__,
1838"spawnve($module, mode, path, argv, env, /)\n"
1839"--\n"
1840"\n"
1841"Execute the program specified by path in a new process.\n"
1842"\n"
1843" mode\n"
1844" Mode of process creation.\n"
1845" path\n"
1846" Path of executable file.\n"
1847" argv\n"
1848" Tuple or list of strings.\n"
1849" env\n"
1850" Dictionary of strings mapping to strings.");
1851
1852#define OS_SPAWNVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001853 {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001854
1855static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001856os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001857 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001858
1859static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001860os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001861{
1862 PyObject *return_value = NULL;
1863 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001864 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001865 PyObject *argv;
1866 PyObject *env;
1867
Sylvain74453812017-06-10 06:51:48 +02001868 if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve",
1869 &mode, path_converter, &path, &argv, &env)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001870 goto exit;
1871 }
Steve Dowercc16be82016-09-08 10:35:16 -07001872 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001873
1874exit:
1875 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001876 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001877
1878 return return_value;
1879}
1880
Steve Dowercc16be82016-09-08 10:35:16 -07001881#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001882
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001883#if defined(HAVE_FORK)
1884
1885PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001886"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1887" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001888"--\n"
1889"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001890"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001891"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001892" before\n"
1893" A callable to be called in the parent before the fork() syscall.\n"
1894" after_in_child\n"
1895" A callable to be called in the child after fork().\n"
1896" after_in_parent\n"
1897" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001898"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001899"\'before\' callbacks are called in reverse order.\n"
1900"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001901
1902#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001903 {"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 +02001904
1905static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001906os_register_at_fork_impl(PyObject *module, PyObject *before,
1907 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001908
1909static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001910os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001911{
1912 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001913 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1914 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1915 PyObject *before = NULL;
1916 PyObject *after_in_child = NULL;
1917 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001918
1919 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001920 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001921 goto exit;
1922 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001923 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001924
1925exit:
1926 return return_value;
1927}
1928
1929#endif /* defined(HAVE_FORK) */
1930
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001931#if defined(HAVE_FORK1)
1932
1933PyDoc_STRVAR(os_fork1__doc__,
1934"fork1($module, /)\n"
1935"--\n"
1936"\n"
1937"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1938"\n"
1939"Return 0 to child process and PID of child to parent process.");
1940
1941#define OS_FORK1_METHODDEF \
1942 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1943
1944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001945os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001946
1947static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001948os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001949{
1950 return os_fork1_impl(module);
1951}
1952
1953#endif /* defined(HAVE_FORK1) */
1954
1955#if defined(HAVE_FORK)
1956
1957PyDoc_STRVAR(os_fork__doc__,
1958"fork($module, /)\n"
1959"--\n"
1960"\n"
1961"Fork a child process.\n"
1962"\n"
1963"Return 0 to child process and PID of child to parent process.");
1964
1965#define OS_FORK_METHODDEF \
1966 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1967
1968static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001969os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001970
1971static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001972os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001973{
1974 return os_fork_impl(module);
1975}
1976
1977#endif /* defined(HAVE_FORK) */
1978
1979#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
1980
1981PyDoc_STRVAR(os_sched_get_priority_max__doc__,
1982"sched_get_priority_max($module, /, policy)\n"
1983"--\n"
1984"\n"
1985"Get the maximum scheduling priority for policy.");
1986
1987#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001988 {"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 +03001989
1990static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001991os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001992
1993static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001994os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001995{
1996 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001997 static const char * const _keywords[] = {"policy", NULL};
1998 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001999 int policy;
2000
Victor Stinner3e1fad62017-01-17 01:29:01 +01002001 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002002 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002004 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002005 return_value = os_sched_get_priority_max_impl(module, policy);
2006
2007exit:
2008 return return_value;
2009}
2010
2011#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2012
2013#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2014
2015PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2016"sched_get_priority_min($module, /, policy)\n"
2017"--\n"
2018"\n"
2019"Get the minimum scheduling priority for policy.");
2020
2021#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002022 {"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 +03002023
2024static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002025os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002026
2027static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002028os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002029{
2030 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002031 static const char * const _keywords[] = {"policy", NULL};
2032 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002033 int policy;
2034
Victor Stinner3e1fad62017-01-17 01:29:01 +01002035 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002036 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002037 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002038 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002039 return_value = os_sched_get_priority_min_impl(module, policy);
2040
2041exit:
2042 return return_value;
2043}
2044
2045#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2046
2047#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2048
2049PyDoc_STRVAR(os_sched_getscheduler__doc__,
2050"sched_getscheduler($module, pid, /)\n"
2051"--\n"
2052"\n"
2053"Get the scheduling policy for the process identifiedy by pid.\n"
2054"\n"
2055"Passing 0 for pid returns the scheduling policy for the calling process.");
2056
2057#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002058 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002059
2060static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002061os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002062
2063static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002064os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002065{
2066 PyObject *return_value = NULL;
2067 pid_t pid;
2068
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002069 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002070 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002071 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002072 return_value = os_sched_getscheduler_impl(module, pid);
2073
2074exit:
2075 return return_value;
2076}
2077
2078#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2079
William Orr81574b82018-10-01 22:19:56 -07002080#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 +03002081
2082PyDoc_STRVAR(os_sched_param__doc__,
2083"sched_param(sched_priority)\n"
2084"--\n"
2085"\n"
2086"Current has only one field: sched_priority\");\n"
2087"\n"
2088" sched_priority\n"
2089" A scheduling parameter.");
2090
2091static PyObject *
2092os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2093
2094static PyObject *
2095os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2096{
2097 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002098 static const char * const _keywords[] = {"sched_priority", NULL};
2099 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002100 PyObject *sched_priority;
2101
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002102 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002103 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002105 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002106 return_value = os_sched_param_impl(type, sched_priority);
2107
2108exit:
2109 return return_value;
2110}
2111
William Orr81574b82018-10-01 22:19:56 -07002112#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 +03002113
2114#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2115
2116PyDoc_STRVAR(os_sched_setscheduler__doc__,
2117"sched_setscheduler($module, pid, policy, param, /)\n"
2118"--\n"
2119"\n"
2120"Set the scheduling policy for the process identified by pid.\n"
2121"\n"
2122"If pid is 0, the calling process is changed.\n"
2123"param is an instance of sched_param.");
2124
2125#define OS_SCHED_SETSCHEDULER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002126 {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002127
2128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002129os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002130 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002131
2132static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002133os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134{
2135 PyObject *return_value = NULL;
2136 pid_t pid;
2137 int policy;
2138 struct sched_param param;
2139
Sylvain74453812017-06-10 06:51:48 +02002140 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2141 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002142 goto exit;
2143 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002144 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2145
2146exit:
2147 return return_value;
2148}
2149
2150#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2151
2152#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2153
2154PyDoc_STRVAR(os_sched_getparam__doc__,
2155"sched_getparam($module, pid, /)\n"
2156"--\n"
2157"\n"
2158"Returns scheduling parameters for the process identified by pid.\n"
2159"\n"
2160"If pid is 0, returns parameters for the calling process.\n"
2161"Return value is an instance of sched_param.");
2162
2163#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002164 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002165
2166static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002167os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002168
2169static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002170os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002171{
2172 PyObject *return_value = NULL;
2173 pid_t pid;
2174
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002175 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002176 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002177 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002178 return_value = os_sched_getparam_impl(module, pid);
2179
2180exit:
2181 return return_value;
2182}
2183
2184#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2185
2186#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2187
2188PyDoc_STRVAR(os_sched_setparam__doc__,
2189"sched_setparam($module, pid, param, /)\n"
2190"--\n"
2191"\n"
2192"Set scheduling parameters for the process identified by pid.\n"
2193"\n"
2194"If pid is 0, sets parameters for the calling process.\n"
2195"param should be an instance of sched_param.");
2196
2197#define OS_SCHED_SETPARAM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002198 {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002199
2200static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002201os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002202 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002203
2204static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002205os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002206{
2207 PyObject *return_value = NULL;
2208 pid_t pid;
2209 struct sched_param param;
2210
Sylvain74453812017-06-10 06:51:48 +02002211 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2212 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002213 goto exit;
2214 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002215 return_value = os_sched_setparam_impl(module, pid, &param);
2216
2217exit:
2218 return return_value;
2219}
2220
2221#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2222
2223#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2224
2225PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2226"sched_rr_get_interval($module, pid, /)\n"
2227"--\n"
2228"\n"
2229"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2230"\n"
2231"Value returned is a float.");
2232
2233#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002234 {"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 +03002235
2236static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002237os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002238
2239static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002240os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002241{
2242 PyObject *return_value = NULL;
2243 pid_t pid;
2244 double _return_value;
2245
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002246 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002247 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002249 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002250 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002251 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002252 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002253 return_value = PyFloat_FromDouble(_return_value);
2254
2255exit:
2256 return return_value;
2257}
2258
2259#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2260
2261#if defined(HAVE_SCHED_H)
2262
2263PyDoc_STRVAR(os_sched_yield__doc__,
2264"sched_yield($module, /)\n"
2265"--\n"
2266"\n"
2267"Voluntarily relinquish the CPU.");
2268
2269#define OS_SCHED_YIELD_METHODDEF \
2270 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2271
2272static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002273os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002274
2275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002276os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002277{
2278 return os_sched_yield_impl(module);
2279}
2280
2281#endif /* defined(HAVE_SCHED_H) */
2282
2283#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2284
2285PyDoc_STRVAR(os_sched_setaffinity__doc__,
2286"sched_setaffinity($module, pid, mask, /)\n"
2287"--\n"
2288"\n"
2289"Set the CPU affinity of the process identified by pid to mask.\n"
2290"\n"
2291"mask should be an iterable of integers identifying CPUs.");
2292
2293#define OS_SCHED_SETAFFINITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002294 {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002295
2296static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002297os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002298
2299static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002300os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002301{
2302 PyObject *return_value = NULL;
2303 pid_t pid;
2304 PyObject *mask;
2305
Sylvain74453812017-06-10 06:51:48 +02002306 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2307 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002308 goto exit;
2309 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002310 return_value = os_sched_setaffinity_impl(module, pid, mask);
2311
2312exit:
2313 return return_value;
2314}
2315
2316#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2317
2318#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2319
2320PyDoc_STRVAR(os_sched_getaffinity__doc__,
2321"sched_getaffinity($module, pid, /)\n"
2322"--\n"
2323"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002324"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002325"\n"
2326"The affinity is returned as a set of CPU identifiers.");
2327
2328#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002329 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002330
2331static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002332os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002333
2334static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002335os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002336{
2337 PyObject *return_value = NULL;
2338 pid_t pid;
2339
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002340 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002341 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002342 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002343 return_value = os_sched_getaffinity_impl(module, pid);
2344
2345exit:
2346 return return_value;
2347}
2348
2349#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2350
2351#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2352
2353PyDoc_STRVAR(os_openpty__doc__,
2354"openpty($module, /)\n"
2355"--\n"
2356"\n"
2357"Open a pseudo-terminal.\n"
2358"\n"
2359"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2360"for both the master and slave ends.");
2361
2362#define OS_OPENPTY_METHODDEF \
2363 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2364
2365static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002366os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002367
2368static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002369os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002370{
2371 return os_openpty_impl(module);
2372}
2373
2374#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2375
2376#if defined(HAVE_FORKPTY)
2377
2378PyDoc_STRVAR(os_forkpty__doc__,
2379"forkpty($module, /)\n"
2380"--\n"
2381"\n"
2382"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2383"\n"
2384"Returns a tuple of (pid, master_fd).\n"
2385"Like fork(), return pid of 0 to the child process,\n"
2386"and pid of child to the parent process.\n"
2387"To both, return fd of newly opened pseudo-terminal.");
2388
2389#define OS_FORKPTY_METHODDEF \
2390 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2391
2392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002393os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002394
2395static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002396os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002397{
2398 return os_forkpty_impl(module);
2399}
2400
2401#endif /* defined(HAVE_FORKPTY) */
2402
2403#if defined(HAVE_GETEGID)
2404
2405PyDoc_STRVAR(os_getegid__doc__,
2406"getegid($module, /)\n"
2407"--\n"
2408"\n"
2409"Return the current process\'s effective group id.");
2410
2411#define OS_GETEGID_METHODDEF \
2412 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2413
2414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002415os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002416
2417static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002418os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002419{
2420 return os_getegid_impl(module);
2421}
2422
2423#endif /* defined(HAVE_GETEGID) */
2424
2425#if defined(HAVE_GETEUID)
2426
2427PyDoc_STRVAR(os_geteuid__doc__,
2428"geteuid($module, /)\n"
2429"--\n"
2430"\n"
2431"Return the current process\'s effective user id.");
2432
2433#define OS_GETEUID_METHODDEF \
2434 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2435
2436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002437os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002438
2439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002440os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002441{
2442 return os_geteuid_impl(module);
2443}
2444
2445#endif /* defined(HAVE_GETEUID) */
2446
2447#if defined(HAVE_GETGID)
2448
2449PyDoc_STRVAR(os_getgid__doc__,
2450"getgid($module, /)\n"
2451"--\n"
2452"\n"
2453"Return the current process\'s group id.");
2454
2455#define OS_GETGID_METHODDEF \
2456 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2457
2458static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002459os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002460
2461static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002462os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002463{
2464 return os_getgid_impl(module);
2465}
2466
2467#endif /* defined(HAVE_GETGID) */
2468
Berker Peksag39404992016-09-15 20:45:16 +03002469#if defined(HAVE_GETPID)
2470
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002471PyDoc_STRVAR(os_getpid__doc__,
2472"getpid($module, /)\n"
2473"--\n"
2474"\n"
2475"Return the current process id.");
2476
2477#define OS_GETPID_METHODDEF \
2478 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2479
2480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002481os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002482
2483static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002484os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002485{
2486 return os_getpid_impl(module);
2487}
2488
Berker Peksag39404992016-09-15 20:45:16 +03002489#endif /* defined(HAVE_GETPID) */
2490
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491#if defined(HAVE_GETGROUPS)
2492
2493PyDoc_STRVAR(os_getgroups__doc__,
2494"getgroups($module, /)\n"
2495"--\n"
2496"\n"
2497"Return list of supplemental group IDs for the process.");
2498
2499#define OS_GETGROUPS_METHODDEF \
2500 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2501
2502static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002503os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002504
2505static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002506os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002507{
2508 return os_getgroups_impl(module);
2509}
2510
2511#endif /* defined(HAVE_GETGROUPS) */
2512
2513#if defined(HAVE_GETPGID)
2514
2515PyDoc_STRVAR(os_getpgid__doc__,
2516"getpgid($module, /, pid)\n"
2517"--\n"
2518"\n"
2519"Call the system call getpgid(), and return the result.");
2520
2521#define OS_GETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002522 {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002523
2524static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002525os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002526
2527static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002528os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002529{
2530 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002531 static const char * const _keywords[] = {"pid", NULL};
2532 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002533 pid_t pid;
2534
Victor Stinner3e1fad62017-01-17 01:29:01 +01002535 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002536 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002537 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002538 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002539 return_value = os_getpgid_impl(module, pid);
2540
2541exit:
2542 return return_value;
2543}
2544
2545#endif /* defined(HAVE_GETPGID) */
2546
2547#if defined(HAVE_GETPGRP)
2548
2549PyDoc_STRVAR(os_getpgrp__doc__,
2550"getpgrp($module, /)\n"
2551"--\n"
2552"\n"
2553"Return the current process group id.");
2554
2555#define OS_GETPGRP_METHODDEF \
2556 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2557
2558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002559os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002560
2561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002562os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002563{
2564 return os_getpgrp_impl(module);
2565}
2566
2567#endif /* defined(HAVE_GETPGRP) */
2568
2569#if defined(HAVE_SETPGRP)
2570
2571PyDoc_STRVAR(os_setpgrp__doc__,
2572"setpgrp($module, /)\n"
2573"--\n"
2574"\n"
2575"Make the current process the leader of its process group.");
2576
2577#define OS_SETPGRP_METHODDEF \
2578 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2579
2580static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002581os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002582
2583static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002584os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002585{
2586 return os_setpgrp_impl(module);
2587}
2588
2589#endif /* defined(HAVE_SETPGRP) */
2590
2591#if defined(HAVE_GETPPID)
2592
2593PyDoc_STRVAR(os_getppid__doc__,
2594"getppid($module, /)\n"
2595"--\n"
2596"\n"
2597"Return the parent\'s process id.\n"
2598"\n"
2599"If the parent process has already exited, Windows machines will still\n"
2600"return its id; others systems will return the id of the \'init\' process (1).");
2601
2602#define OS_GETPPID_METHODDEF \
2603 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2604
2605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002606os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002607
2608static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002609os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002610{
2611 return os_getppid_impl(module);
2612}
2613
2614#endif /* defined(HAVE_GETPPID) */
2615
2616#if defined(HAVE_GETLOGIN)
2617
2618PyDoc_STRVAR(os_getlogin__doc__,
2619"getlogin($module, /)\n"
2620"--\n"
2621"\n"
2622"Return the actual login name.");
2623
2624#define OS_GETLOGIN_METHODDEF \
2625 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2626
2627static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002628os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002629
2630static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002631os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002632{
2633 return os_getlogin_impl(module);
2634}
2635
2636#endif /* defined(HAVE_GETLOGIN) */
2637
2638#if defined(HAVE_GETUID)
2639
2640PyDoc_STRVAR(os_getuid__doc__,
2641"getuid($module, /)\n"
2642"--\n"
2643"\n"
2644"Return the current process\'s user id.");
2645
2646#define OS_GETUID_METHODDEF \
2647 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2648
2649static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002650os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002651
2652static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002653os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002654{
2655 return os_getuid_impl(module);
2656}
2657
2658#endif /* defined(HAVE_GETUID) */
2659
2660#if defined(HAVE_KILL)
2661
2662PyDoc_STRVAR(os_kill__doc__,
2663"kill($module, pid, signal, /)\n"
2664"--\n"
2665"\n"
2666"Kill a process with a signal.");
2667
2668#define OS_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002669 {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002670
2671static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002672os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002673
2674static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002675os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002676{
2677 PyObject *return_value = NULL;
2678 pid_t pid;
2679 Py_ssize_t signal;
2680
Sylvain74453812017-06-10 06:51:48 +02002681 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2682 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002683 goto exit;
2684 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002685 return_value = os_kill_impl(module, pid, signal);
2686
2687exit:
2688 return return_value;
2689}
2690
2691#endif /* defined(HAVE_KILL) */
2692
2693#if defined(HAVE_KILLPG)
2694
2695PyDoc_STRVAR(os_killpg__doc__,
2696"killpg($module, pgid, signal, /)\n"
2697"--\n"
2698"\n"
2699"Kill a process group with a signal.");
2700
2701#define OS_KILLPG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002702 {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002703
2704static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002705os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002706
2707static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002708os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002709{
2710 PyObject *return_value = NULL;
2711 pid_t pgid;
2712 int signal;
2713
Sylvain74453812017-06-10 06:51:48 +02002714 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2715 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002716 goto exit;
2717 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002718 return_value = os_killpg_impl(module, pgid, signal);
2719
2720exit:
2721 return return_value;
2722}
2723
2724#endif /* defined(HAVE_KILLPG) */
2725
2726#if defined(HAVE_PLOCK)
2727
2728PyDoc_STRVAR(os_plock__doc__,
2729"plock($module, op, /)\n"
2730"--\n"
2731"\n"
2732"Lock program segments into memory.\");");
2733
2734#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002735 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002736
2737static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002738os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002739
2740static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002741os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002742{
2743 PyObject *return_value = NULL;
2744 int op;
2745
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002746 if (PyFloat_Check(arg)) {
2747 PyErr_SetString(PyExc_TypeError,
2748 "integer argument expected, got float" );
2749 goto exit;
2750 }
2751 op = _PyLong_AsInt(arg);
2752 if (op == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002753 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002754 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002755 return_value = os_plock_impl(module, op);
2756
2757exit:
2758 return return_value;
2759}
2760
2761#endif /* defined(HAVE_PLOCK) */
2762
2763#if defined(HAVE_SETUID)
2764
2765PyDoc_STRVAR(os_setuid__doc__,
2766"setuid($module, uid, /)\n"
2767"--\n"
2768"\n"
2769"Set the current process\'s user id.");
2770
2771#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002772 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002773
2774static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002775os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002776
2777static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002778os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002779{
2780 PyObject *return_value = NULL;
2781 uid_t uid;
2782
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002783 if (!_Py_Uid_Converter(arg, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002784 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002785 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002786 return_value = os_setuid_impl(module, uid);
2787
2788exit:
2789 return return_value;
2790}
2791
2792#endif /* defined(HAVE_SETUID) */
2793
2794#if defined(HAVE_SETEUID)
2795
2796PyDoc_STRVAR(os_seteuid__doc__,
2797"seteuid($module, euid, /)\n"
2798"--\n"
2799"\n"
2800"Set the current process\'s effective user id.");
2801
2802#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002803 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002804
2805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002806os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002807
2808static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002809os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002810{
2811 PyObject *return_value = NULL;
2812 uid_t euid;
2813
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002814 if (!_Py_Uid_Converter(arg, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002815 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002816 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002817 return_value = os_seteuid_impl(module, euid);
2818
2819exit:
2820 return return_value;
2821}
2822
2823#endif /* defined(HAVE_SETEUID) */
2824
2825#if defined(HAVE_SETEGID)
2826
2827PyDoc_STRVAR(os_setegid__doc__,
2828"setegid($module, egid, /)\n"
2829"--\n"
2830"\n"
2831"Set the current process\'s effective group id.");
2832
2833#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002834 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002835
2836static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002837os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002838
2839static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002840os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002841{
2842 PyObject *return_value = NULL;
2843 gid_t egid;
2844
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002845 if (!_Py_Gid_Converter(arg, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002846 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002847 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002848 return_value = os_setegid_impl(module, egid);
2849
2850exit:
2851 return return_value;
2852}
2853
2854#endif /* defined(HAVE_SETEGID) */
2855
2856#if defined(HAVE_SETREUID)
2857
2858PyDoc_STRVAR(os_setreuid__doc__,
2859"setreuid($module, ruid, euid, /)\n"
2860"--\n"
2861"\n"
2862"Set the current process\'s real and effective user ids.");
2863
2864#define OS_SETREUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002865 {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002866
2867static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002868os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002869
2870static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002871os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002872{
2873 PyObject *return_value = NULL;
2874 uid_t ruid;
2875 uid_t euid;
2876
Sylvain74453812017-06-10 06:51:48 +02002877 if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid",
2878 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002879 goto exit;
2880 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002881 return_value = os_setreuid_impl(module, ruid, euid);
2882
2883exit:
2884 return return_value;
2885}
2886
2887#endif /* defined(HAVE_SETREUID) */
2888
2889#if defined(HAVE_SETREGID)
2890
2891PyDoc_STRVAR(os_setregid__doc__,
2892"setregid($module, rgid, egid, /)\n"
2893"--\n"
2894"\n"
2895"Set the current process\'s real and effective group ids.");
2896
2897#define OS_SETREGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002898 {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002899
2900static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002901os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002902
2903static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002904os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002905{
2906 PyObject *return_value = NULL;
2907 gid_t rgid;
2908 gid_t egid;
2909
Sylvain74453812017-06-10 06:51:48 +02002910 if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid",
2911 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002912 goto exit;
2913 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002914 return_value = os_setregid_impl(module, rgid, egid);
2915
2916exit:
2917 return return_value;
2918}
2919
2920#endif /* defined(HAVE_SETREGID) */
2921
2922#if defined(HAVE_SETGID)
2923
2924PyDoc_STRVAR(os_setgid__doc__,
2925"setgid($module, gid, /)\n"
2926"--\n"
2927"\n"
2928"Set the current process\'s group id.");
2929
2930#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002931 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002932
2933static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002934os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002935
2936static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002937os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002938{
2939 PyObject *return_value = NULL;
2940 gid_t gid;
2941
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002942 if (!_Py_Gid_Converter(arg, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002943 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002945 return_value = os_setgid_impl(module, gid);
2946
2947exit:
2948 return return_value;
2949}
2950
2951#endif /* defined(HAVE_SETGID) */
2952
2953#if defined(HAVE_SETGROUPS)
2954
2955PyDoc_STRVAR(os_setgroups__doc__,
2956"setgroups($module, groups, /)\n"
2957"--\n"
2958"\n"
2959"Set the groups of the current process to list.");
2960
2961#define OS_SETGROUPS_METHODDEF \
2962 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
2963
2964#endif /* defined(HAVE_SETGROUPS) */
2965
2966#if defined(HAVE_WAIT3)
2967
2968PyDoc_STRVAR(os_wait3__doc__,
2969"wait3($module, /, options)\n"
2970"--\n"
2971"\n"
2972"Wait for completion of a child process.\n"
2973"\n"
2974"Returns a tuple of information about the child process:\n"
2975" (pid, status, rusage)");
2976
2977#define OS_WAIT3_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002978 {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002979
2980static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002981os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002982
2983static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002984os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002985{
2986 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002987 static const char * const _keywords[] = {"options", NULL};
2988 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002989 int options;
2990
Victor Stinner3e1fad62017-01-17 01:29:01 +01002991 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002992 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002993 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002994 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002995 return_value = os_wait3_impl(module, options);
2996
2997exit:
2998 return return_value;
2999}
3000
3001#endif /* defined(HAVE_WAIT3) */
3002
3003#if defined(HAVE_WAIT4)
3004
3005PyDoc_STRVAR(os_wait4__doc__,
3006"wait4($module, /, pid, options)\n"
3007"--\n"
3008"\n"
3009"Wait for completion of a specific child process.\n"
3010"\n"
3011"Returns a tuple of information about the child process:\n"
3012" (pid, status, rusage)");
3013
3014#define OS_WAIT4_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003015 {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003016
3017static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003018os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003019
3020static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003021os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003022{
3023 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003024 static const char * const _keywords[] = {"pid", "options", NULL};
3025 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003026 pid_t pid;
3027 int options;
3028
Victor Stinner3e1fad62017-01-17 01:29:01 +01003029 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003030 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003031 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003032 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003033 return_value = os_wait4_impl(module, pid, options);
3034
3035exit:
3036 return return_value;
3037}
3038
3039#endif /* defined(HAVE_WAIT4) */
3040
3041#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3042
3043PyDoc_STRVAR(os_waitid__doc__,
3044"waitid($module, idtype, id, options, /)\n"
3045"--\n"
3046"\n"
3047"Returns the result of waiting for a process or processes.\n"
3048"\n"
3049" idtype\n"
3050" Must be one of be P_PID, P_PGID or P_ALL.\n"
3051" id\n"
3052" The id to wait on.\n"
3053" options\n"
3054" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3055" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3056"\n"
3057"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3058"no children in a waitable state.");
3059
3060#define OS_WAITID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003061 {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003062
3063static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003064os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003065
3066static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003067os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003068{
3069 PyObject *return_value = NULL;
3070 idtype_t idtype;
3071 id_t id;
3072 int options;
3073
Sylvain74453812017-06-10 06:51:48 +02003074 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3075 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003076 goto exit;
3077 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003078 return_value = os_waitid_impl(module, idtype, id, options);
3079
3080exit:
3081 return return_value;
3082}
3083
3084#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3085
3086#if defined(HAVE_WAITPID)
3087
3088PyDoc_STRVAR(os_waitpid__doc__,
3089"waitpid($module, pid, options, /)\n"
3090"--\n"
3091"\n"
3092"Wait for completion of a given child process.\n"
3093"\n"
3094"Returns a tuple of information regarding the child process:\n"
3095" (pid, status)\n"
3096"\n"
3097"The options argument is ignored on Windows.");
3098
3099#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003100 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003101
3102static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003103os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003104
3105static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003106os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003107{
3108 PyObject *return_value = NULL;
3109 pid_t pid;
3110 int options;
3111
Sylvain74453812017-06-10 06:51:48 +02003112 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3113 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003114 goto exit;
3115 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003116 return_value = os_waitpid_impl(module, pid, options);
3117
3118exit:
3119 return return_value;
3120}
3121
3122#endif /* defined(HAVE_WAITPID) */
3123
3124#if defined(HAVE_CWAIT)
3125
3126PyDoc_STRVAR(os_waitpid__doc__,
3127"waitpid($module, pid, options, /)\n"
3128"--\n"
3129"\n"
3130"Wait for completion of a given process.\n"
3131"\n"
3132"Returns a tuple of information regarding the process:\n"
3133" (pid, status << 8)\n"
3134"\n"
3135"The options argument is ignored on Windows.");
3136
3137#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003138 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003139
3140static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003141os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003142
3143static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003144os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003145{
3146 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003147 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003148 int options;
3149
Sylvain74453812017-06-10 06:51:48 +02003150 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3151 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003152 goto exit;
3153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003154 return_value = os_waitpid_impl(module, pid, options);
3155
3156exit:
3157 return return_value;
3158}
3159
3160#endif /* defined(HAVE_CWAIT) */
3161
3162#if defined(HAVE_WAIT)
3163
3164PyDoc_STRVAR(os_wait__doc__,
3165"wait($module, /)\n"
3166"--\n"
3167"\n"
3168"Wait for completion of a child process.\n"
3169"\n"
3170"Returns a tuple of information about the child process:\n"
3171" (pid, status)");
3172
3173#define OS_WAIT_METHODDEF \
3174 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3175
3176static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003177os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003178
3179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003180os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003181{
3182 return os_wait_impl(module);
3183}
3184
3185#endif /* defined(HAVE_WAIT) */
3186
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003187#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3188
3189PyDoc_STRVAR(os_readlink__doc__,
3190"readlink($module, /, path, *, dir_fd=None)\n"
3191"--\n"
3192"\n"
3193"Return a string representing the path to which the symbolic link points.\n"
3194"\n"
3195"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3196"and path should be relative; path will then be relative to that directory.\n"
3197"\n"
3198"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3199"using it will raise a NotImplementedError.");
3200
3201#define OS_READLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003202 {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003203
3204static PyObject *
3205os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3206
3207static PyObject *
3208os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3209{
3210 PyObject *return_value = NULL;
3211 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3212 static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0};
3213 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3214 int dir_fd = DEFAULT_DIR_FD;
3215
3216 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3217 path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3218 goto exit;
3219 }
3220 return_value = os_readlink_impl(module, &path, dir_fd);
3221
3222exit:
3223 /* Cleanup for path */
3224 path_cleanup(&path);
3225
3226 return return_value;
3227}
3228
3229#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
3230
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003231#if defined(HAVE_SYMLINK)
3232
3233PyDoc_STRVAR(os_symlink__doc__,
3234"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3235"--\n"
3236"\n"
3237"Create a symbolic link pointing to src named dst.\n"
3238"\n"
3239"target_is_directory is required on Windows if the target is to be\n"
3240" interpreted as a directory. (On Windows, symlink requires\n"
3241" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3242" target_is_directory is ignored on non-Windows platforms.\n"
3243"\n"
3244"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3245" and path should be relative; path will then be relative to that directory.\n"
3246"dir_fd may not be implemented on your platform.\n"
3247" If it is unavailable, using it will raise a NotImplementedError.");
3248
3249#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003250 {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003251
3252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003253os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003254 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003255
3256static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003257os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003258{
3259 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003260 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3261 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3263 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3264 int target_is_directory = 0;
3265 int dir_fd = DEFAULT_DIR_FD;
3266
Victor Stinner3e1fad62017-01-17 01:29:01 +01003267 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003268 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003269 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003270 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003271 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3272
3273exit:
3274 /* Cleanup for src */
3275 path_cleanup(&src);
3276 /* Cleanup for dst */
3277 path_cleanup(&dst);
3278
3279 return return_value;
3280}
3281
3282#endif /* defined(HAVE_SYMLINK) */
3283
3284#if defined(HAVE_TIMES)
3285
3286PyDoc_STRVAR(os_times__doc__,
3287"times($module, /)\n"
3288"--\n"
3289"\n"
3290"Return a collection containing process timing information.\n"
3291"\n"
3292"The object returned behaves like a named tuple with these fields:\n"
3293" (utime, stime, cutime, cstime, elapsed_time)\n"
3294"All fields are floating point numbers.");
3295
3296#define OS_TIMES_METHODDEF \
3297 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3298
3299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003300os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003301
3302static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003303os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003304{
3305 return os_times_impl(module);
3306}
3307
3308#endif /* defined(HAVE_TIMES) */
3309
3310#if defined(HAVE_GETSID)
3311
3312PyDoc_STRVAR(os_getsid__doc__,
3313"getsid($module, pid, /)\n"
3314"--\n"
3315"\n"
3316"Call the system call getsid(pid) and return the result.");
3317
3318#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003319 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003320
3321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003322os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003323
3324static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003325os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003326{
3327 PyObject *return_value = NULL;
3328 pid_t pid;
3329
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003330 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003331 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003332 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003333 return_value = os_getsid_impl(module, pid);
3334
3335exit:
3336 return return_value;
3337}
3338
3339#endif /* defined(HAVE_GETSID) */
3340
3341#if defined(HAVE_SETSID)
3342
3343PyDoc_STRVAR(os_setsid__doc__,
3344"setsid($module, /)\n"
3345"--\n"
3346"\n"
3347"Call the system call setsid().");
3348
3349#define OS_SETSID_METHODDEF \
3350 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3351
3352static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003353os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003354
3355static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003356os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003357{
3358 return os_setsid_impl(module);
3359}
3360
3361#endif /* defined(HAVE_SETSID) */
3362
3363#if defined(HAVE_SETPGID)
3364
3365PyDoc_STRVAR(os_setpgid__doc__,
3366"setpgid($module, pid, pgrp, /)\n"
3367"--\n"
3368"\n"
3369"Call the system call setpgid(pid, pgrp).");
3370
3371#define OS_SETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003372 {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003373
3374static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003375os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003376
3377static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003378os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003379{
3380 PyObject *return_value = NULL;
3381 pid_t pid;
3382 pid_t pgrp;
3383
Sylvain74453812017-06-10 06:51:48 +02003384 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3385 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003386 goto exit;
3387 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003388 return_value = os_setpgid_impl(module, pid, pgrp);
3389
3390exit:
3391 return return_value;
3392}
3393
3394#endif /* defined(HAVE_SETPGID) */
3395
3396#if defined(HAVE_TCGETPGRP)
3397
3398PyDoc_STRVAR(os_tcgetpgrp__doc__,
3399"tcgetpgrp($module, fd, /)\n"
3400"--\n"
3401"\n"
3402"Return the process group associated with the terminal specified by fd.");
3403
3404#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003405 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003406
3407static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003408os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003409
3410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003411os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003412{
3413 PyObject *return_value = NULL;
3414 int fd;
3415
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003416 if (PyFloat_Check(arg)) {
3417 PyErr_SetString(PyExc_TypeError,
3418 "integer argument expected, got float" );
3419 goto exit;
3420 }
3421 fd = _PyLong_AsInt(arg);
3422 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003423 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003424 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003425 return_value = os_tcgetpgrp_impl(module, fd);
3426
3427exit:
3428 return return_value;
3429}
3430
3431#endif /* defined(HAVE_TCGETPGRP) */
3432
3433#if defined(HAVE_TCSETPGRP)
3434
3435PyDoc_STRVAR(os_tcsetpgrp__doc__,
3436"tcsetpgrp($module, fd, pgid, /)\n"
3437"--\n"
3438"\n"
3439"Set the process group associated with the terminal specified by fd.");
3440
3441#define OS_TCSETPGRP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003442 {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003443
3444static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003445os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003446
3447static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003448os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003449{
3450 PyObject *return_value = NULL;
3451 int fd;
3452 pid_t pgid;
3453
Sylvain74453812017-06-10 06:51:48 +02003454 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3455 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003456 goto exit;
3457 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003458 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3459
3460exit:
3461 return return_value;
3462}
3463
3464#endif /* defined(HAVE_TCSETPGRP) */
3465
3466PyDoc_STRVAR(os_open__doc__,
3467"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3468"--\n"
3469"\n"
3470"Open a file for low level IO. Returns a file descriptor (integer).\n"
3471"\n"
3472"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3473" and path should be relative; path will then be relative to that directory.\n"
3474"dir_fd may not be implemented on your platform.\n"
3475" If it is unavailable, using it will raise a NotImplementedError.");
3476
3477#define OS_OPEN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003478 {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003479
3480static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003481os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003482
3483static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003484os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003485{
3486 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003487 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3488 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003489 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3490 int flags;
3491 int mode = 511;
3492 int dir_fd = DEFAULT_DIR_FD;
3493 int _return_value;
3494
Victor Stinner3e1fad62017-01-17 01:29:01 +01003495 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003496 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003497 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003498 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003499 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003500 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003501 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003502 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003503 return_value = PyLong_FromLong((long)_return_value);
3504
3505exit:
3506 /* Cleanup for path */
3507 path_cleanup(&path);
3508
3509 return return_value;
3510}
3511
3512PyDoc_STRVAR(os_close__doc__,
3513"close($module, /, fd)\n"
3514"--\n"
3515"\n"
3516"Close a file descriptor.");
3517
3518#define OS_CLOSE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003519 {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003520
3521static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003522os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003523
3524static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003525os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003526{
3527 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003528 static const char * const _keywords[] = {"fd", NULL};
3529 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003530 int fd;
3531
Victor Stinner3e1fad62017-01-17 01:29:01 +01003532 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003533 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003534 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003535 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003536 return_value = os_close_impl(module, fd);
3537
3538exit:
3539 return return_value;
3540}
3541
3542PyDoc_STRVAR(os_closerange__doc__,
3543"closerange($module, fd_low, fd_high, /)\n"
3544"--\n"
3545"\n"
3546"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3547
3548#define OS_CLOSERANGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003549 {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003550
3551static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003552os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003553
3554static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003555os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003556{
3557 PyObject *return_value = NULL;
3558 int fd_low;
3559 int fd_high;
3560
Sylvain74453812017-06-10 06:51:48 +02003561 if (!_PyArg_ParseStack(args, nargs, "ii:closerange",
3562 &fd_low, &fd_high)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003563 goto exit;
3564 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003565 return_value = os_closerange_impl(module, fd_low, fd_high);
3566
3567exit:
3568 return return_value;
3569}
3570
3571PyDoc_STRVAR(os_dup__doc__,
3572"dup($module, fd, /)\n"
3573"--\n"
3574"\n"
3575"Return a duplicate of a file descriptor.");
3576
3577#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003578 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003579
3580static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003581os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003582
3583static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003584os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003585{
3586 PyObject *return_value = NULL;
3587 int fd;
3588 int _return_value;
3589
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003590 if (PyFloat_Check(arg)) {
3591 PyErr_SetString(PyExc_TypeError,
3592 "integer argument expected, got float" );
3593 goto exit;
3594 }
3595 fd = _PyLong_AsInt(arg);
3596 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003597 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003598 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003599 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003600 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003601 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003602 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003603 return_value = PyLong_FromLong((long)_return_value);
3604
3605exit:
3606 return return_value;
3607}
3608
3609PyDoc_STRVAR(os_dup2__doc__,
3610"dup2($module, /, fd, fd2, inheritable=True)\n"
3611"--\n"
3612"\n"
3613"Duplicate file descriptor.");
3614
3615#define OS_DUP2_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003616 {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003617
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003618static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003619os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003620
3621static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003622os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003623{
3624 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003625 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3626 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003627 int fd;
3628 int fd2;
3629 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003630 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003631
Victor Stinner3e1fad62017-01-17 01:29:01 +01003632 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003633 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003634 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003635 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003636 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3637 if ((_return_value == -1) && PyErr_Occurred()) {
3638 goto exit;
3639 }
3640 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003641
3642exit:
3643 return return_value;
3644}
3645
3646#if defined(HAVE_LOCKF)
3647
3648PyDoc_STRVAR(os_lockf__doc__,
3649"lockf($module, fd, command, length, /)\n"
3650"--\n"
3651"\n"
3652"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3653"\n"
3654" fd\n"
3655" An open file descriptor.\n"
3656" command\n"
3657" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3658" length\n"
3659" The number of bytes to lock, starting at the current position.");
3660
3661#define OS_LOCKF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003662 {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003663
3664static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003665os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003666
3667static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003668os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003669{
3670 PyObject *return_value = NULL;
3671 int fd;
3672 int command;
3673 Py_off_t length;
3674
Sylvain74453812017-06-10 06:51:48 +02003675 if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf",
3676 &fd, &command, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003677 goto exit;
3678 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003679 return_value = os_lockf_impl(module, fd, command, length);
3680
3681exit:
3682 return return_value;
3683}
3684
3685#endif /* defined(HAVE_LOCKF) */
3686
3687PyDoc_STRVAR(os_lseek__doc__,
3688"lseek($module, fd, position, how, /)\n"
3689"--\n"
3690"\n"
3691"Set the position of a file descriptor. Return the new position.\n"
3692"\n"
3693"Return the new cursor position in number of bytes\n"
3694"relative to the beginning of the file.");
3695
3696#define OS_LSEEK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003697 {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003698
3699static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003700os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003701
3702static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003703os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003704{
3705 PyObject *return_value = NULL;
3706 int fd;
3707 Py_off_t position;
3708 int how;
3709 Py_off_t _return_value;
3710
Sylvain74453812017-06-10 06:51:48 +02003711 if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek",
3712 &fd, Py_off_t_converter, &position, &how)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003713 goto exit;
3714 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003715 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003716 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003717 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003718 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003719 return_value = PyLong_FromPy_off_t(_return_value);
3720
3721exit:
3722 return return_value;
3723}
3724
3725PyDoc_STRVAR(os_read__doc__,
3726"read($module, fd, length, /)\n"
3727"--\n"
3728"\n"
3729"Read from a file descriptor. Returns a bytes object.");
3730
3731#define OS_READ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003732 {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003733
3734static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003735os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003736
3737static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003738os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003739{
3740 PyObject *return_value = NULL;
3741 int fd;
3742 Py_ssize_t length;
3743
Sylvain74453812017-06-10 06:51:48 +02003744 if (!_PyArg_ParseStack(args, nargs, "in:read",
3745 &fd, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003746 goto exit;
3747 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003748 return_value = os_read_impl(module, fd, length);
3749
3750exit:
3751 return return_value;
3752}
3753
3754#if defined(HAVE_READV)
3755
3756PyDoc_STRVAR(os_readv__doc__,
3757"readv($module, fd, buffers, /)\n"
3758"--\n"
3759"\n"
3760"Read from a file descriptor fd into an iterable of buffers.\n"
3761"\n"
3762"The buffers should be mutable buffers accepting bytes.\n"
3763"readv will transfer data into each buffer until it is full\n"
3764"and then move on to the next buffer in the sequence to hold\n"
3765"the rest of the data.\n"
3766"\n"
3767"readv returns the total number of bytes read,\n"
3768"which may be less than the total capacity of all the buffers.");
3769
3770#define OS_READV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003771 {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003772
3773static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003774os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003775
3776static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003777os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003778{
3779 PyObject *return_value = NULL;
3780 int fd;
3781 PyObject *buffers;
3782 Py_ssize_t _return_value;
3783
Sylvain74453812017-06-10 06:51:48 +02003784 if (!_PyArg_ParseStack(args, nargs, "iO:readv",
3785 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003786 goto exit;
3787 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003788 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003789 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003790 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003791 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003792 return_value = PyLong_FromSsize_t(_return_value);
3793
3794exit:
3795 return return_value;
3796}
3797
3798#endif /* defined(HAVE_READV) */
3799
3800#if defined(HAVE_PREAD)
3801
3802PyDoc_STRVAR(os_pread__doc__,
3803"pread($module, fd, length, offset, /)\n"
3804"--\n"
3805"\n"
3806"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3807"\n"
3808"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3809"the beginning of the file. The file offset remains unchanged.");
3810
3811#define OS_PREAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003812 {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003813
3814static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003815os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003816
3817static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003818os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003819{
3820 PyObject *return_value = NULL;
3821 int fd;
3822 int length;
3823 Py_off_t offset;
3824
Sylvain74453812017-06-10 06:51:48 +02003825 if (!_PyArg_ParseStack(args, nargs, "iiO&:pread",
3826 &fd, &length, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003827 goto exit;
3828 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003829 return_value = os_pread_impl(module, fd, length, offset);
3830
3831exit:
3832 return return_value;
3833}
3834
3835#endif /* defined(HAVE_PREAD) */
3836
Pablo Galindo4defba32018-01-27 16:16:37 +00003837#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3838
3839PyDoc_STRVAR(os_preadv__doc__,
3840"preadv($module, fd, buffers, offset, flags=0, /)\n"
3841"--\n"
3842"\n"
3843"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3844"\n"
3845"Combines the functionality of readv() and pread(). As readv(), it will\n"
3846"transfer data into each buffer until it is full and then move on to the next\n"
3847"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3848"specifies the file offset at which the input operation is to be performed. It\n"
3849"will return the total number of bytes read (which can be less than the total\n"
3850"capacity of all the objects).\n"
3851"\n"
3852"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3853"\n"
3854"- RWF_HIPRI\n"
3855"- RWF_NOWAIT\n"
3856"\n"
3857"Using non-zero flags requires Linux 4.6 or newer.");
3858
3859#define OS_PREADV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003860 {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00003861
3862static Py_ssize_t
3863os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
3864 int flags);
3865
3866static PyObject *
3867os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3868{
3869 PyObject *return_value = NULL;
3870 int fd;
3871 PyObject *buffers;
3872 Py_off_t offset;
3873 int flags = 0;
3874 Py_ssize_t _return_value;
3875
3876 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv",
3877 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
3878 goto exit;
3879 }
3880 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
3881 if ((_return_value == -1) && PyErr_Occurred()) {
3882 goto exit;
3883 }
3884 return_value = PyLong_FromSsize_t(_return_value);
3885
3886exit:
3887 return return_value;
3888}
3889
3890#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
3891
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003892PyDoc_STRVAR(os_write__doc__,
3893"write($module, fd, data, /)\n"
3894"--\n"
3895"\n"
3896"Write a bytes object to a file descriptor.");
3897
3898#define OS_WRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003899 {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003900
3901static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003902os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003903
3904static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003905os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003906{
3907 PyObject *return_value = NULL;
3908 int fd;
3909 Py_buffer data = {NULL, NULL};
3910 Py_ssize_t _return_value;
3911
Sylvain74453812017-06-10 06:51:48 +02003912 if (!_PyArg_ParseStack(args, nargs, "iy*:write",
3913 &fd, &data)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003914 goto exit;
3915 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003916 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003917 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003918 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003919 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003920 return_value = PyLong_FromSsize_t(_return_value);
3921
3922exit:
3923 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003924 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003925 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003926 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003927
3928 return return_value;
3929}
3930
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003931#if defined(__APPLE__)
3932
3933PyDoc_STRVAR(os__fcopyfile__doc__,
3934"_fcopyfile($module, infd, outfd, flags, /)\n"
3935"--\n"
3936"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07003937"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003938
3939#define OS__FCOPYFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003940 {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02003941
3942static PyObject *
3943os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
3944
3945static PyObject *
3946os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3947{
3948 PyObject *return_value = NULL;
3949 int infd;
3950 int outfd;
3951 int flags;
3952
3953 if (!_PyArg_ParseStack(args, nargs, "iii:_fcopyfile",
3954 &infd, &outfd, &flags)) {
3955 goto exit;
3956 }
3957 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
3958
3959exit:
3960 return return_value;
3961}
3962
3963#endif /* defined(__APPLE__) */
3964
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003965PyDoc_STRVAR(os_fstat__doc__,
3966"fstat($module, /, fd)\n"
3967"--\n"
3968"\n"
3969"Perform a stat system call on the given file descriptor.\n"
3970"\n"
3971"Like stat(), but for an open file descriptor.\n"
3972"Equivalent to os.stat(fd).");
3973
3974#define OS_FSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003975 {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003976
3977static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003978os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003979
3980static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003981os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003982{
3983 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003984 static const char * const _keywords[] = {"fd", NULL};
3985 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003986 int fd;
3987
Victor Stinner3e1fad62017-01-17 01:29:01 +01003988 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003989 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003990 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003991 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003992 return_value = os_fstat_impl(module, fd);
3993
3994exit:
3995 return return_value;
3996}
3997
3998PyDoc_STRVAR(os_isatty__doc__,
3999"isatty($module, fd, /)\n"
4000"--\n"
4001"\n"
4002"Return True if the fd is connected to a terminal.\n"
4003"\n"
4004"Return True if the file descriptor is an open file descriptor\n"
4005"connected to the slave end of a terminal.");
4006
4007#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004008 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004009
4010static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004011os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004012
4013static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004014os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004015{
4016 PyObject *return_value = NULL;
4017 int fd;
4018 int _return_value;
4019
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004020 if (PyFloat_Check(arg)) {
4021 PyErr_SetString(PyExc_TypeError,
4022 "integer argument expected, got float" );
4023 goto exit;
4024 }
4025 fd = _PyLong_AsInt(arg);
4026 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004027 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004028 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004029 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004030 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004031 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004032 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004033 return_value = PyBool_FromLong((long)_return_value);
4034
4035exit:
4036 return return_value;
4037}
4038
4039#if defined(HAVE_PIPE)
4040
4041PyDoc_STRVAR(os_pipe__doc__,
4042"pipe($module, /)\n"
4043"--\n"
4044"\n"
4045"Create a pipe.\n"
4046"\n"
4047"Returns a tuple of two file descriptors:\n"
4048" (read_fd, write_fd)");
4049
4050#define OS_PIPE_METHODDEF \
4051 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
4052
4053static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004054os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004055
4056static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004057os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004058{
4059 return os_pipe_impl(module);
4060}
4061
4062#endif /* defined(HAVE_PIPE) */
4063
4064#if defined(HAVE_PIPE2)
4065
4066PyDoc_STRVAR(os_pipe2__doc__,
4067"pipe2($module, flags, /)\n"
4068"--\n"
4069"\n"
4070"Create a pipe with flags set atomically.\n"
4071"\n"
4072"Returns a tuple of two file descriptors:\n"
4073" (read_fd, write_fd)\n"
4074"\n"
4075"flags can be constructed by ORing together one or more of these values:\n"
4076"O_NONBLOCK, O_CLOEXEC.");
4077
4078#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004079 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004080
4081static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004082os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004083
4084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004085os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004086{
4087 PyObject *return_value = NULL;
4088 int flags;
4089
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004090 if (PyFloat_Check(arg)) {
4091 PyErr_SetString(PyExc_TypeError,
4092 "integer argument expected, got float" );
4093 goto exit;
4094 }
4095 flags = _PyLong_AsInt(arg);
4096 if (flags == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004097 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004098 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004099 return_value = os_pipe2_impl(module, flags);
4100
4101exit:
4102 return return_value;
4103}
4104
4105#endif /* defined(HAVE_PIPE2) */
4106
4107#if defined(HAVE_WRITEV)
4108
4109PyDoc_STRVAR(os_writev__doc__,
4110"writev($module, fd, buffers, /)\n"
4111"--\n"
4112"\n"
4113"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4114"\n"
4115"Returns the total number of bytes written.\n"
4116"buffers must be a sequence of bytes-like objects.");
4117
4118#define OS_WRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004119 {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004120
4121static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004122os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004123
4124static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004125os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004126{
4127 PyObject *return_value = NULL;
4128 int fd;
4129 PyObject *buffers;
4130 Py_ssize_t _return_value;
4131
Sylvain74453812017-06-10 06:51:48 +02004132 if (!_PyArg_ParseStack(args, nargs, "iO:writev",
4133 &fd, &buffers)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004134 goto exit;
4135 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004136 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004137 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004138 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004139 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004140 return_value = PyLong_FromSsize_t(_return_value);
4141
4142exit:
4143 return return_value;
4144}
4145
4146#endif /* defined(HAVE_WRITEV) */
4147
4148#if defined(HAVE_PWRITE)
4149
4150PyDoc_STRVAR(os_pwrite__doc__,
4151"pwrite($module, fd, buffer, offset, /)\n"
4152"--\n"
4153"\n"
4154"Write bytes to a file descriptor starting at a particular offset.\n"
4155"\n"
4156"Write buffer to fd, starting at offset bytes from the beginning of\n"
4157"the file. Returns the number of bytes writte. Does not change the\n"
4158"current file offset.");
4159
4160#define OS_PWRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004161 {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004162
4163static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004164os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004165
4166static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004167os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004168{
4169 PyObject *return_value = NULL;
4170 int fd;
4171 Py_buffer buffer = {NULL, NULL};
4172 Py_off_t offset;
4173 Py_ssize_t _return_value;
4174
Sylvain74453812017-06-10 06:51:48 +02004175 if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite",
4176 &fd, &buffer, Py_off_t_converter, &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004177 goto exit;
4178 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004179 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004180 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004181 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004182 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004183 return_value = PyLong_FromSsize_t(_return_value);
4184
4185exit:
4186 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004187 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004188 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004189 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004190
4191 return return_value;
4192}
4193
4194#endif /* defined(HAVE_PWRITE) */
4195
Pablo Galindo4defba32018-01-27 16:16:37 +00004196#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4197
4198PyDoc_STRVAR(os_pwritev__doc__,
4199"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4200"--\n"
4201"\n"
4202"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4203"\n"
4204"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4205"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4206"buffer is written before proceeding to second, and so on. The operating system may\n"
4207"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4208"This function writes the contents of each object to the file descriptor and returns\n"
4209"the total number of bytes written.\n"
4210"\n"
4211"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4212"\n"
4213"- RWF_DSYNC\n"
4214"- RWF_SYNC\n"
4215"\n"
4216"Using non-zero flags requires Linux 4.7 or newer.");
4217
4218#define OS_PWRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004219 {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004220
4221static Py_ssize_t
4222os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4223 int flags);
4224
4225static PyObject *
4226os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4227{
4228 PyObject *return_value = NULL;
4229 int fd;
4230 PyObject *buffers;
4231 Py_off_t offset;
4232 int flags = 0;
4233 Py_ssize_t _return_value;
4234
4235 if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev",
4236 &fd, &buffers, Py_off_t_converter, &offset, &flags)) {
4237 goto exit;
4238 }
4239 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4240 if ((_return_value == -1) && PyErr_Occurred()) {
4241 goto exit;
4242 }
4243 return_value = PyLong_FromSsize_t(_return_value);
4244
4245exit:
4246 return return_value;
4247}
4248
4249#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4250
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004251#if defined(HAVE_MKFIFO)
4252
4253PyDoc_STRVAR(os_mkfifo__doc__,
4254"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4255"--\n"
4256"\n"
4257"Create a \"fifo\" (a POSIX named pipe).\n"
4258"\n"
4259"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4260" and path should be relative; path will then be relative to that directory.\n"
4261"dir_fd may not be implemented on your platform.\n"
4262" If it is unavailable, using it will raise a NotImplementedError.");
4263
4264#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004265 {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004266
4267static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004268os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004269
4270static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004271os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004272{
4273 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004274 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4275 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004276 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4277 int mode = 438;
4278 int dir_fd = DEFAULT_DIR_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 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_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_mkfifo_impl(module, &path, mode, dir_fd);
4285
4286exit:
4287 /* Cleanup for path */
4288 path_cleanup(&path);
4289
4290 return return_value;
4291}
4292
4293#endif /* defined(HAVE_MKFIFO) */
4294
4295#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4296
4297PyDoc_STRVAR(os_mknod__doc__,
4298"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4299"--\n"
4300"\n"
4301"Create a node in the file system.\n"
4302"\n"
4303"Create a node in the file system (file, device special file or named pipe)\n"
4304"at path. mode specifies both the permissions to use and the\n"
4305"type of node to be created, being combined (bitwise OR) with one of\n"
4306"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4307"device defines the newly created device special file (probably using\n"
4308"os.makedev()). Otherwise device is ignored.\n"
4309"\n"
4310"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4311" and path should be relative; path will then be relative to that directory.\n"
4312"dir_fd may not be implemented on your platform.\n"
4313" If it is unavailable, using it will raise a NotImplementedError.");
4314
4315#define OS_MKNOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004316 {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004317
4318static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004319os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004320 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004321
4322static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004323os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004324{
4325 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004326 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4327 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004328 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4329 int mode = 384;
4330 dev_t device = 0;
4331 int dir_fd = DEFAULT_DIR_FD;
4332
Victor Stinner3e1fad62017-01-17 01:29:01 +01004333 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004334 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004335 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004336 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004337 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4338
4339exit:
4340 /* Cleanup for path */
4341 path_cleanup(&path);
4342
4343 return return_value;
4344}
4345
4346#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4347
4348#if defined(HAVE_DEVICE_MACROS)
4349
4350PyDoc_STRVAR(os_major__doc__,
4351"major($module, device, /)\n"
4352"--\n"
4353"\n"
4354"Extracts a device major number from a raw device number.");
4355
4356#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004357 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004358
4359static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004360os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004361
4362static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004363os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364{
4365 PyObject *return_value = NULL;
4366 dev_t device;
4367 unsigned int _return_value;
4368
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004369 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004371 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004372 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004373 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004374 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004375 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004376 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4377
4378exit:
4379 return return_value;
4380}
4381
4382#endif /* defined(HAVE_DEVICE_MACROS) */
4383
4384#if defined(HAVE_DEVICE_MACROS)
4385
4386PyDoc_STRVAR(os_minor__doc__,
4387"minor($module, device, /)\n"
4388"--\n"
4389"\n"
4390"Extracts a device minor number from a raw device number.");
4391
4392#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004393 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004394
4395static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004396os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004397
4398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004399os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004400{
4401 PyObject *return_value = NULL;
4402 dev_t device;
4403 unsigned int _return_value;
4404
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004405 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004406 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004407 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004408 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004409 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004410 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004411 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004412 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4413
4414exit:
4415 return return_value;
4416}
4417
4418#endif /* defined(HAVE_DEVICE_MACROS) */
4419
4420#if defined(HAVE_DEVICE_MACROS)
4421
4422PyDoc_STRVAR(os_makedev__doc__,
4423"makedev($module, major, minor, /)\n"
4424"--\n"
4425"\n"
4426"Composes a raw device number from the major and minor device numbers.");
4427
4428#define OS_MAKEDEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004429 {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004430
4431static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004432os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004433
4434static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004435os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004436{
4437 PyObject *return_value = NULL;
4438 int major;
4439 int minor;
4440 dev_t _return_value;
4441
Sylvain74453812017-06-10 06:51:48 +02004442 if (!_PyArg_ParseStack(args, nargs, "ii:makedev",
4443 &major, &minor)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004444 goto exit;
4445 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004446 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004447 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004448 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004449 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004450 return_value = _PyLong_FromDev(_return_value);
4451
4452exit:
4453 return return_value;
4454}
4455
4456#endif /* defined(HAVE_DEVICE_MACROS) */
4457
Steve Dowerf7377032015-04-12 15:44:54 -04004458#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004459
4460PyDoc_STRVAR(os_ftruncate__doc__,
4461"ftruncate($module, fd, length, /)\n"
4462"--\n"
4463"\n"
4464"Truncate a file, specified by file descriptor, to a specific length.");
4465
4466#define OS_FTRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004467 {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004468
4469static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004470os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004471
4472static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004473os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004474{
4475 PyObject *return_value = NULL;
4476 int fd;
4477 Py_off_t length;
4478
Sylvain74453812017-06-10 06:51:48 +02004479 if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate",
4480 &fd, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004481 goto exit;
4482 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004483 return_value = os_ftruncate_impl(module, fd, length);
4484
4485exit:
4486 return return_value;
4487}
4488
Steve Dowerf7377032015-04-12 15:44:54 -04004489#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004490
Steve Dowerf7377032015-04-12 15:44:54 -04004491#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004492
4493PyDoc_STRVAR(os_truncate__doc__,
4494"truncate($module, /, path, length)\n"
4495"--\n"
4496"\n"
4497"Truncate a file, specified by path, to a specific length.\n"
4498"\n"
4499"On some platforms, path may also be specified as an open file descriptor.\n"
4500" If this functionality is unavailable, using it raises an exception.");
4501
4502#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004503 {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004504
4505static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004506os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004507
4508static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004509os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004510{
4511 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004512 static const char * const _keywords[] = {"path", "length", NULL};
4513 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004514 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4515 Py_off_t length;
4516
Victor Stinner3e1fad62017-01-17 01:29:01 +01004517 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004518 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004519 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004520 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004521 return_value = os_truncate_impl(module, &path, length);
4522
4523exit:
4524 /* Cleanup for path */
4525 path_cleanup(&path);
4526
4527 return return_value;
4528}
4529
Steve Dowerf7377032015-04-12 15:44:54 -04004530#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004531
4532#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4533
4534PyDoc_STRVAR(os_posix_fallocate__doc__,
4535"posix_fallocate($module, fd, offset, length, /)\n"
4536"--\n"
4537"\n"
4538"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4539"\n"
4540"Ensure that the file specified by fd encompasses a range of bytes\n"
4541"starting at offset bytes from the beginning and continuing for length bytes.");
4542
4543#define OS_POSIX_FALLOCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004544 {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004545
4546static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004547os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004548 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004549
4550static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004551os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004552{
4553 PyObject *return_value = NULL;
4554 int fd;
4555 Py_off_t offset;
4556 Py_off_t length;
4557
Sylvain74453812017-06-10 06:51:48 +02004558 if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate",
4559 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004560 goto exit;
4561 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004562 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4563
4564exit:
4565 return return_value;
4566}
4567
4568#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4569
4570#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4571
4572PyDoc_STRVAR(os_posix_fadvise__doc__,
4573"posix_fadvise($module, fd, offset, length, advice, /)\n"
4574"--\n"
4575"\n"
4576"Announce an intention to access data in a specific pattern.\n"
4577"\n"
4578"Announce an intention to access data in a specific pattern, thus allowing\n"
4579"the kernel to make optimizations.\n"
4580"The advice applies to the region of the file specified by fd starting at\n"
4581"offset and continuing for length bytes.\n"
4582"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4583"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4584"POSIX_FADV_DONTNEED.");
4585
4586#define OS_POSIX_FADVISE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004587 {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004588
4589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004590os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004591 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004592
4593static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004594os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004595{
4596 PyObject *return_value = NULL;
4597 int fd;
4598 Py_off_t offset;
4599 Py_off_t length;
4600 int advice;
4601
Sylvain74453812017-06-10 06:51:48 +02004602 if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise",
4603 &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004604 goto exit;
4605 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004606 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4607
4608exit:
4609 return return_value;
4610}
4611
4612#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4613
4614#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4615
4616PyDoc_STRVAR(os_putenv__doc__,
4617"putenv($module, name, value, /)\n"
4618"--\n"
4619"\n"
4620"Change or add an environment variable.");
4621
4622#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004623 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004624
4625static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004626os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004627
4628static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004629os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004630{
4631 PyObject *return_value = NULL;
4632 PyObject *name;
4633 PyObject *value;
4634
Sylvain74453812017-06-10 06:51:48 +02004635 if (!_PyArg_ParseStack(args, nargs, "UU:putenv",
4636 &name, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004637 goto exit;
4638 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004639 return_value = os_putenv_impl(module, name, value);
4640
4641exit:
4642 return return_value;
4643}
4644
4645#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4646
4647#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4648
4649PyDoc_STRVAR(os_putenv__doc__,
4650"putenv($module, name, value, /)\n"
4651"--\n"
4652"\n"
4653"Change or add an environment variable.");
4654
4655#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004656 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004657
4658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004659os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004660
4661static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004662os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004663{
4664 PyObject *return_value = NULL;
4665 PyObject *name = NULL;
4666 PyObject *value = NULL;
4667
Sylvain74453812017-06-10 06:51:48 +02004668 if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv",
4669 PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004670 goto exit;
4671 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004672 return_value = os_putenv_impl(module, name, value);
4673
4674exit:
4675 /* Cleanup for name */
4676 Py_XDECREF(name);
4677 /* Cleanup for value */
4678 Py_XDECREF(value);
4679
4680 return return_value;
4681}
4682
4683#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
4684
4685#if defined(HAVE_UNSETENV)
4686
4687PyDoc_STRVAR(os_unsetenv__doc__,
4688"unsetenv($module, name, /)\n"
4689"--\n"
4690"\n"
4691"Delete an environment variable.");
4692
4693#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004694 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004695
4696static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004697os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004698
4699static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004700os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004701{
4702 PyObject *return_value = NULL;
4703 PyObject *name = NULL;
4704
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004705 if (!PyUnicode_FSConverter(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004707 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708 return_value = os_unsetenv_impl(module, name);
4709
4710exit:
4711 /* Cleanup for name */
4712 Py_XDECREF(name);
4713
4714 return return_value;
4715}
4716
4717#endif /* defined(HAVE_UNSETENV) */
4718
4719PyDoc_STRVAR(os_strerror__doc__,
4720"strerror($module, code, /)\n"
4721"--\n"
4722"\n"
4723"Translate an error code to a message string.");
4724
4725#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004726 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004727
4728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004729os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004730
4731static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004732os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004733{
4734 PyObject *return_value = NULL;
4735 int code;
4736
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004737 if (PyFloat_Check(arg)) {
4738 PyErr_SetString(PyExc_TypeError,
4739 "integer argument expected, got float" );
4740 goto exit;
4741 }
4742 code = _PyLong_AsInt(arg);
4743 if (code == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004744 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004745 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004746 return_value = os_strerror_impl(module, code);
4747
4748exit:
4749 return return_value;
4750}
4751
4752#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
4753
4754PyDoc_STRVAR(os_WCOREDUMP__doc__,
4755"WCOREDUMP($module, status, /)\n"
4756"--\n"
4757"\n"
4758"Return True if the process returning status was dumped to a core file.");
4759
4760#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004761 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004762
4763static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004764os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004765
4766static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004767os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004768{
4769 PyObject *return_value = NULL;
4770 int status;
4771 int _return_value;
4772
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004773 if (PyFloat_Check(arg)) {
4774 PyErr_SetString(PyExc_TypeError,
4775 "integer argument expected, got float" );
4776 goto exit;
4777 }
4778 status = _PyLong_AsInt(arg);
4779 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004780 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004781 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004782 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004783 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004784 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004785 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004786 return_value = PyBool_FromLong((long)_return_value);
4787
4788exit:
4789 return return_value;
4790}
4791
4792#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
4793
4794#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
4795
4796PyDoc_STRVAR(os_WIFCONTINUED__doc__,
4797"WIFCONTINUED($module, /, status)\n"
4798"--\n"
4799"\n"
4800"Return True if a particular process was continued from a job control stop.\n"
4801"\n"
4802"Return True if the process returning status was continued from a\n"
4803"job control stop.");
4804
4805#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004806 {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004807
4808static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004809os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004810
4811static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004812os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004813{
4814 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004815 static const char * const _keywords[] = {"status", NULL};
4816 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004817 int status;
4818 int _return_value;
4819
Victor Stinner3e1fad62017-01-17 01:29:01 +01004820 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004821 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004822 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004823 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004824 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004825 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004826 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004827 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004828 return_value = PyBool_FromLong((long)_return_value);
4829
4830exit:
4831 return return_value;
4832}
4833
4834#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
4835
4836#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
4837
4838PyDoc_STRVAR(os_WIFSTOPPED__doc__,
4839"WIFSTOPPED($module, /, status)\n"
4840"--\n"
4841"\n"
4842"Return True if the process returning status was stopped.");
4843
4844#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004845 {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004846
4847static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004848os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004849
4850static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004851os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004852{
4853 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004854 static const char * const _keywords[] = {"status", NULL};
4855 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004856 int status;
4857 int _return_value;
4858
Victor Stinner3e1fad62017-01-17 01:29:01 +01004859 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004860 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004861 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004862 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004863 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004864 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004865 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004866 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004867 return_value = PyBool_FromLong((long)_return_value);
4868
4869exit:
4870 return return_value;
4871}
4872
4873#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
4874
4875#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
4876
4877PyDoc_STRVAR(os_WIFSIGNALED__doc__,
4878"WIFSIGNALED($module, /, status)\n"
4879"--\n"
4880"\n"
4881"Return True if the process returning status was terminated by a signal.");
4882
4883#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004884 {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004885
4886static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004887os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004888
4889static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004890os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004891{
4892 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004893 static const char * const _keywords[] = {"status", NULL};
4894 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004895 int status;
4896 int _return_value;
4897
Victor Stinner3e1fad62017-01-17 01:29:01 +01004898 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004899 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004900 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004901 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004902 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004903 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004905 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004906 return_value = PyBool_FromLong((long)_return_value);
4907
4908exit:
4909 return return_value;
4910}
4911
4912#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
4913
4914#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
4915
4916PyDoc_STRVAR(os_WIFEXITED__doc__,
4917"WIFEXITED($module, /, status)\n"
4918"--\n"
4919"\n"
4920"Return True if the process returning status exited via the exit() system call.");
4921
4922#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004923 {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004924
4925static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004926os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004927
4928static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004929os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004930{
4931 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004932 static const char * const _keywords[] = {"status", NULL};
4933 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004934 int status;
4935 int _return_value;
4936
Victor Stinner3e1fad62017-01-17 01:29:01 +01004937 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004938 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004939 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004940 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004941 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004942 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004943 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004945 return_value = PyBool_FromLong((long)_return_value);
4946
4947exit:
4948 return return_value;
4949}
4950
4951#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
4952
4953#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
4954
4955PyDoc_STRVAR(os_WEXITSTATUS__doc__,
4956"WEXITSTATUS($module, /, status)\n"
4957"--\n"
4958"\n"
4959"Return the process return code from status.");
4960
4961#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004962 {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004963
4964static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004965os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004966
4967static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004968os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004969{
4970 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004971 static const char * const _keywords[] = {"status", NULL};
4972 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004973 int status;
4974 int _return_value;
4975
Victor Stinner3e1fad62017-01-17 01:29:01 +01004976 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004977 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004978 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004979 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004980 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004981 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004982 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004983 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984 return_value = PyLong_FromLong((long)_return_value);
4985
4986exit:
4987 return return_value;
4988}
4989
4990#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
4991
4992#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
4993
4994PyDoc_STRVAR(os_WTERMSIG__doc__,
4995"WTERMSIG($module, /, status)\n"
4996"--\n"
4997"\n"
4998"Return the signal that terminated the process that provided the status value.");
4999
5000#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005001 {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005002
5003static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005004os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005005
5006static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005007os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005008{
5009 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005010 static const char * const _keywords[] = {"status", NULL};
5011 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005012 int status;
5013 int _return_value;
5014
Victor Stinner3e1fad62017-01-17 01:29:01 +01005015 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005016 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005017 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005018 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005019 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005020 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005021 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005022 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005023 return_value = PyLong_FromLong((long)_return_value);
5024
5025exit:
5026 return return_value;
5027}
5028
5029#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
5030
5031#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
5032
5033PyDoc_STRVAR(os_WSTOPSIG__doc__,
5034"WSTOPSIG($module, /, status)\n"
5035"--\n"
5036"\n"
5037"Return the signal that stopped the process that provided the status value.");
5038
5039#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005040 {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005041
5042static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005043os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005044
5045static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005046os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005047{
5048 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005049 static const char * const _keywords[] = {"status", NULL};
5050 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005051 int status;
5052 int _return_value;
5053
Victor Stinner3e1fad62017-01-17 01:29:01 +01005054 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005055 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005056 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005057 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005058 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005059 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005061 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005062 return_value = PyLong_FromLong((long)_return_value);
5063
5064exit:
5065 return return_value;
5066}
5067
5068#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
5069
5070#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
5071
5072PyDoc_STRVAR(os_fstatvfs__doc__,
5073"fstatvfs($module, fd, /)\n"
5074"--\n"
5075"\n"
5076"Perform an fstatvfs system call on the given fd.\n"
5077"\n"
5078"Equivalent to statvfs(fd).");
5079
5080#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005081 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005082
5083static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005084os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005085
5086static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005087os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005088{
5089 PyObject *return_value = NULL;
5090 int fd;
5091
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005092 if (PyFloat_Check(arg)) {
5093 PyErr_SetString(PyExc_TypeError,
5094 "integer argument expected, got float" );
5095 goto exit;
5096 }
5097 fd = _PyLong_AsInt(arg);
5098 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005099 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005100 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005101 return_value = os_fstatvfs_impl(module, fd);
5102
5103exit:
5104 return return_value;
5105}
5106
5107#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5108
5109#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5110
5111PyDoc_STRVAR(os_statvfs__doc__,
5112"statvfs($module, /, path)\n"
5113"--\n"
5114"\n"
5115"Perform a statvfs system call on the given path.\n"
5116"\n"
5117"path may always be specified as a string.\n"
5118"On some platforms, path may also be specified as an open file descriptor.\n"
5119" If this functionality is unavailable, using it raises an exception.");
5120
5121#define OS_STATVFS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005122 {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005123
5124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005125os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005126
5127static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005128os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005129{
5130 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005131 static const char * const _keywords[] = {"path", NULL};
5132 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005133 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5134
Victor Stinner3e1fad62017-01-17 01:29:01 +01005135 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005136 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005137 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005138 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005139 return_value = os_statvfs_impl(module, &path);
5140
5141exit:
5142 /* Cleanup for path */
5143 path_cleanup(&path);
5144
5145 return return_value;
5146}
5147
5148#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5149
5150#if defined(MS_WINDOWS)
5151
5152PyDoc_STRVAR(os__getdiskusage__doc__,
5153"_getdiskusage($module, /, path)\n"
5154"--\n"
5155"\n"
5156"Return disk usage statistics about the given path as a (total, free) tuple.");
5157
5158#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005159 {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005160
5161static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005162os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005163
5164static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005165os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005166{
5167 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005168 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005169 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5170 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005171
Victor Stinner3e1fad62017-01-17 01:29:01 +01005172 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005173 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005174 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005175 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005176 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005177
5178exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005179 /* Cleanup for path */
5180 path_cleanup(&path);
5181
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005182 return return_value;
5183}
5184
5185#endif /* defined(MS_WINDOWS) */
5186
5187#if defined(HAVE_FPATHCONF)
5188
5189PyDoc_STRVAR(os_fpathconf__doc__,
5190"fpathconf($module, fd, name, /)\n"
5191"--\n"
5192"\n"
5193"Return the configuration limit name for the file descriptor fd.\n"
5194"\n"
5195"If there is no limit, return -1.");
5196
5197#define OS_FPATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005198 {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005199
5200static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005201os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005202
5203static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005204os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005205{
5206 PyObject *return_value = NULL;
5207 int fd;
5208 int name;
5209 long _return_value;
5210
Sylvain74453812017-06-10 06:51:48 +02005211 if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf",
5212 &fd, conv_path_confname, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005213 goto exit;
5214 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005215 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005216 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005217 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005218 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005219 return_value = PyLong_FromLong(_return_value);
5220
5221exit:
5222 return return_value;
5223}
5224
5225#endif /* defined(HAVE_FPATHCONF) */
5226
5227#if defined(HAVE_PATHCONF)
5228
5229PyDoc_STRVAR(os_pathconf__doc__,
5230"pathconf($module, /, path, name)\n"
5231"--\n"
5232"\n"
5233"Return the configuration limit name for the file or directory path.\n"
5234"\n"
5235"If there is no limit, return -1.\n"
5236"On some platforms, path may also be specified as an open file descriptor.\n"
5237" If this functionality is unavailable, using it raises an exception.");
5238
5239#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005240 {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005241
5242static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005243os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005244
5245static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005246os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247{
5248 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005249 static const char * const _keywords[] = {"path", "name", NULL};
5250 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005251 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5252 int name;
5253 long _return_value;
5254
Victor Stinner3e1fad62017-01-17 01:29:01 +01005255 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005256 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005257 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005258 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005259 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005260 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005261 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005262 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005263 return_value = PyLong_FromLong(_return_value);
5264
5265exit:
5266 /* Cleanup for path */
5267 path_cleanup(&path);
5268
5269 return return_value;
5270}
5271
5272#endif /* defined(HAVE_PATHCONF) */
5273
5274#if defined(HAVE_CONFSTR)
5275
5276PyDoc_STRVAR(os_confstr__doc__,
5277"confstr($module, name, /)\n"
5278"--\n"
5279"\n"
5280"Return a string-valued system configuration variable.");
5281
5282#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005283 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005284
5285static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005286os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005287
5288static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005289os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005290{
5291 PyObject *return_value = NULL;
5292 int name;
5293
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005294 if (!conv_confstr_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005295 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005296 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005297 return_value = os_confstr_impl(module, name);
5298
5299exit:
5300 return return_value;
5301}
5302
5303#endif /* defined(HAVE_CONFSTR) */
5304
5305#if defined(HAVE_SYSCONF)
5306
5307PyDoc_STRVAR(os_sysconf__doc__,
5308"sysconf($module, name, /)\n"
5309"--\n"
5310"\n"
5311"Return an integer-valued system configuration variable.");
5312
5313#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005314 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005315
5316static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005317os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005318
5319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005320os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005321{
5322 PyObject *return_value = NULL;
5323 int name;
5324 long _return_value;
5325
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005326 if (!conv_sysconf_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005327 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005328 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005329 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005330 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005331 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005332 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005333 return_value = PyLong_FromLong(_return_value);
5334
5335exit:
5336 return return_value;
5337}
5338
5339#endif /* defined(HAVE_SYSCONF) */
5340
5341PyDoc_STRVAR(os_abort__doc__,
5342"abort($module, /)\n"
5343"--\n"
5344"\n"
5345"Abort the interpreter immediately.\n"
5346"\n"
5347"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5348"on the hosting operating system. This function never returns.");
5349
5350#define OS_ABORT_METHODDEF \
5351 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5352
5353static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005354os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005355
5356static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005357os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005358{
5359 return os_abort_impl(module);
5360}
5361
Steve Dowercc16be82016-09-08 10:35:16 -07005362#if defined(MS_WINDOWS)
5363
5364PyDoc_STRVAR(os_startfile__doc__,
5365"startfile($module, /, filepath, operation=None)\n"
5366"--\n"
5367"\n"
5368"startfile(filepath [, operation])\n"
5369"\n"
5370"Start a file with its associated application.\n"
5371"\n"
5372"When \"operation\" is not specified or \"open\", this acts like\n"
5373"double-clicking the file in Explorer, or giving the file name as an\n"
5374"argument to the DOS \"start\" command: the file is opened with whatever\n"
5375"application (if any) its extension is associated.\n"
5376"When another \"operation\" is given, it specifies what should be done with\n"
5377"the file. A typical operation is \"print\".\n"
5378"\n"
5379"startfile returns as soon as the associated application is launched.\n"
5380"There is no option to wait for the application to close, and no way\n"
5381"to retrieve the application\'s exit status.\n"
5382"\n"
5383"The filepath is relative to the current directory. If you want to use\n"
5384"an absolute path, make sure the first character is not a slash (\"/\");\n"
5385"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5386
5387#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005388 {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005389
5390static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005391os_startfile_impl(PyObject *module, path_t *filepath,
5392 const Py_UNICODE *operation);
Steve Dowercc16be82016-09-08 10:35:16 -07005393
5394static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005395os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005396{
5397 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005398 static const char * const _keywords[] = {"filepath", "operation", NULL};
5399 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005400 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005401 const Py_UNICODE *operation = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07005402
Victor Stinner3e1fad62017-01-17 01:29:01 +01005403 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005404 path_converter, &filepath, &operation)) {
5405 goto exit;
5406 }
5407 return_value = os_startfile_impl(module, &filepath, operation);
5408
5409exit:
5410 /* Cleanup for filepath */
5411 path_cleanup(&filepath);
5412
5413 return return_value;
5414}
5415
5416#endif /* defined(MS_WINDOWS) */
5417
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005418#if defined(HAVE_GETLOADAVG)
5419
5420PyDoc_STRVAR(os_getloadavg__doc__,
5421"getloadavg($module, /)\n"
5422"--\n"
5423"\n"
5424"Return average recent system load information.\n"
5425"\n"
5426"Return the number of processes in the system run queue averaged over\n"
5427"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5428"Raises OSError if the load average was unobtainable.");
5429
5430#define OS_GETLOADAVG_METHODDEF \
5431 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5432
5433static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005434os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005435
5436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005437os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005438{
5439 return os_getloadavg_impl(module);
5440}
5441
5442#endif /* defined(HAVE_GETLOADAVG) */
5443
5444PyDoc_STRVAR(os_device_encoding__doc__,
5445"device_encoding($module, /, fd)\n"
5446"--\n"
5447"\n"
5448"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5449"\n"
5450"The file descriptor must be attached to a terminal.\n"
5451"If the device is not a terminal, return None.");
5452
5453#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005454 {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005455
5456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005457os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005458
5459static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005460os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005461{
5462 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005463 static const char * const _keywords[] = {"fd", NULL};
5464 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005465 int fd;
5466
Victor Stinner3e1fad62017-01-17 01:29:01 +01005467 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005468 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005469 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005471 return_value = os_device_encoding_impl(module, fd);
5472
5473exit:
5474 return return_value;
5475}
5476
5477#if defined(HAVE_SETRESUID)
5478
5479PyDoc_STRVAR(os_setresuid__doc__,
5480"setresuid($module, ruid, euid, suid, /)\n"
5481"--\n"
5482"\n"
5483"Set the current process\'s real, effective, and saved user ids.");
5484
5485#define OS_SETRESUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005486 {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005487
5488static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005489os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005490
5491static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005492os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005493{
5494 PyObject *return_value = NULL;
5495 uid_t ruid;
5496 uid_t euid;
5497 uid_t suid;
5498
Sylvain74453812017-06-10 06:51:48 +02005499 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid",
5500 _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005501 goto exit;
5502 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005503 return_value = os_setresuid_impl(module, ruid, euid, suid);
5504
5505exit:
5506 return return_value;
5507}
5508
5509#endif /* defined(HAVE_SETRESUID) */
5510
5511#if defined(HAVE_SETRESGID)
5512
5513PyDoc_STRVAR(os_setresgid__doc__,
5514"setresgid($module, rgid, egid, sgid, /)\n"
5515"--\n"
5516"\n"
5517"Set the current process\'s real, effective, and saved group ids.");
5518
5519#define OS_SETRESGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005520 {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005521
5522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005523os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005524
5525static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005526os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005527{
5528 PyObject *return_value = NULL;
5529 gid_t rgid;
5530 gid_t egid;
5531 gid_t sgid;
5532
Sylvain74453812017-06-10 06:51:48 +02005533 if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid",
5534 _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005535 goto exit;
5536 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005537 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5538
5539exit:
5540 return return_value;
5541}
5542
5543#endif /* defined(HAVE_SETRESGID) */
5544
5545#if defined(HAVE_GETRESUID)
5546
5547PyDoc_STRVAR(os_getresuid__doc__,
5548"getresuid($module, /)\n"
5549"--\n"
5550"\n"
5551"Return a tuple of the current process\'s real, effective, and saved user ids.");
5552
5553#define OS_GETRESUID_METHODDEF \
5554 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5555
5556static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005557os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005558
5559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005560os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005561{
5562 return os_getresuid_impl(module);
5563}
5564
5565#endif /* defined(HAVE_GETRESUID) */
5566
5567#if defined(HAVE_GETRESGID)
5568
5569PyDoc_STRVAR(os_getresgid__doc__,
5570"getresgid($module, /)\n"
5571"--\n"
5572"\n"
5573"Return a tuple of the current process\'s real, effective, and saved group ids.");
5574
5575#define OS_GETRESGID_METHODDEF \
5576 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5577
5578static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005579os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005580
5581static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005582os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005583{
5584 return os_getresgid_impl(module);
5585}
5586
5587#endif /* defined(HAVE_GETRESGID) */
5588
5589#if defined(USE_XATTRS)
5590
5591PyDoc_STRVAR(os_getxattr__doc__,
5592"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5593"--\n"
5594"\n"
5595"Return the value of extended attribute attribute on path.\n"
5596"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005597"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005598"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5599" link, getxattr will examine the symbolic link itself instead of the file\n"
5600" the link points to.");
5601
5602#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005603 {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005604
5605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005606os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005607 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005608
5609static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005610os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005611{
5612 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005613 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5614 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005615 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5616 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5617 int follow_symlinks = 1;
5618
Victor Stinner3e1fad62017-01-17 01:29:01 +01005619 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005620 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005621 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005622 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005623 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
5624
5625exit:
5626 /* Cleanup for path */
5627 path_cleanup(&path);
5628 /* Cleanup for attribute */
5629 path_cleanup(&attribute);
5630
5631 return return_value;
5632}
5633
5634#endif /* defined(USE_XATTRS) */
5635
5636#if defined(USE_XATTRS)
5637
5638PyDoc_STRVAR(os_setxattr__doc__,
5639"setxattr($module, /, path, attribute, value, flags=0, *,\n"
5640" follow_symlinks=True)\n"
5641"--\n"
5642"\n"
5643"Set extended attribute attribute on path to value.\n"
5644"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005645"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005646"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5647" link, setxattr will modify the symbolic link itself instead of the file\n"
5648" the link points to.");
5649
5650#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005651 {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005652
5653static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005654os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005655 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005656
5657static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005658os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005659{
5660 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005661 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
5662 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005663 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
5664 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
5665 Py_buffer value = {NULL, NULL};
5666 int flags = 0;
5667 int follow_symlinks = 1;
5668
Victor Stinner3e1fad62017-01-17 01:29:01 +01005669 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005670 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005671 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005672 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005673 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
5674
5675exit:
5676 /* Cleanup for path */
5677 path_cleanup(&path);
5678 /* Cleanup for attribute */
5679 path_cleanup(&attribute);
5680 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005681 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005682 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005683 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005684
5685 return return_value;
5686}
5687
5688#endif /* defined(USE_XATTRS) */
5689
5690#if defined(USE_XATTRS)
5691
5692PyDoc_STRVAR(os_removexattr__doc__,
5693"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5694"--\n"
5695"\n"
5696"Remove extended attribute attribute on path.\n"
5697"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005698"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005699"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5700" link, removexattr will modify the symbolic link itself instead of the file\n"
5701" the link points to.");
5702
5703#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005704 {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005705
5706static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005707os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005708 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005709
5710static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005711os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005712{
5713 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005714 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5715 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005716 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
5717 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
5718 int follow_symlinks = 1;
5719
Victor Stinner3e1fad62017-01-17 01:29:01 +01005720 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005721 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005722 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005723 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005724 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
5725
5726exit:
5727 /* Cleanup for path */
5728 path_cleanup(&path);
5729 /* Cleanup for attribute */
5730 path_cleanup(&attribute);
5731
5732 return return_value;
5733}
5734
5735#endif /* defined(USE_XATTRS) */
5736
5737#if defined(USE_XATTRS)
5738
5739PyDoc_STRVAR(os_listxattr__doc__,
5740"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
5741"--\n"
5742"\n"
5743"Return a list of extended attributes on path.\n"
5744"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005745"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005746"if path is None, listxattr will examine the current directory.\n"
5747"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5748" link, listxattr will examine the symbolic link itself instead of the file\n"
5749" the link points to.");
5750
5751#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005752 {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005753
5754static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005755os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005756
5757static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005758os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005759{
5760 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005761 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
5762 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005763 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
5764 int follow_symlinks = 1;
5765
Victor Stinner3e1fad62017-01-17 01:29:01 +01005766 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005767 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005768 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005769 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005770 return_value = os_listxattr_impl(module, &path, follow_symlinks);
5771
5772exit:
5773 /* Cleanup for path */
5774 path_cleanup(&path);
5775
5776 return return_value;
5777}
5778
5779#endif /* defined(USE_XATTRS) */
5780
5781PyDoc_STRVAR(os_urandom__doc__,
5782"urandom($module, size, /)\n"
5783"--\n"
5784"\n"
5785"Return a bytes object containing random bytes suitable for cryptographic use.");
5786
5787#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005788 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005789
5790static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005791os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005792
5793static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005794os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005795{
5796 PyObject *return_value = NULL;
5797 Py_ssize_t size;
5798
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005799 if (PyFloat_Check(arg)) {
5800 PyErr_SetString(PyExc_TypeError,
5801 "integer argument expected, got float" );
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005802 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005803 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005804 {
5805 Py_ssize_t ival = -1;
5806 PyObject *iobj = PyNumber_Index(arg);
5807 if (iobj != NULL) {
5808 ival = PyLong_AsSsize_t(iobj);
5809 Py_DECREF(iobj);
5810 }
5811 if (ival == -1 && PyErr_Occurred()) {
5812 goto exit;
5813 }
5814 size = ival;
5815 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005816 return_value = os_urandom_impl(module, size);
5817
5818exit:
5819 return return_value;
5820}
5821
5822PyDoc_STRVAR(os_cpu_count__doc__,
5823"cpu_count($module, /)\n"
5824"--\n"
5825"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01005826"Return the number of CPUs in the system; return None if indeterminable.\n"
5827"\n"
5828"This number is not equivalent to the number of CPUs the current process can\n"
5829"use. The number of usable CPUs can be obtained with\n"
5830"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005831
5832#define OS_CPU_COUNT_METHODDEF \
5833 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
5834
5835static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005836os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005837
5838static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005839os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005840{
5841 return os_cpu_count_impl(module);
5842}
5843
5844PyDoc_STRVAR(os_get_inheritable__doc__,
5845"get_inheritable($module, fd, /)\n"
5846"--\n"
5847"\n"
5848"Get the close-on-exe flag of the specified file descriptor.");
5849
5850#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005851 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005852
5853static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005854os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005855
5856static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005857os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005858{
5859 PyObject *return_value = NULL;
5860 int fd;
5861 int _return_value;
5862
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005863 if (PyFloat_Check(arg)) {
5864 PyErr_SetString(PyExc_TypeError,
5865 "integer argument expected, got float" );
5866 goto exit;
5867 }
5868 fd = _PyLong_AsInt(arg);
5869 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005870 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005871 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005872 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005873 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005874 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005875 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005876 return_value = PyBool_FromLong((long)_return_value);
5877
5878exit:
5879 return return_value;
5880}
5881
5882PyDoc_STRVAR(os_set_inheritable__doc__,
5883"set_inheritable($module, fd, inheritable, /)\n"
5884"--\n"
5885"\n"
5886"Set the inheritable flag of the specified file descriptor.");
5887
5888#define OS_SET_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005889 {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005890
5891static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005892os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005893
5894static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005895os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005896{
5897 PyObject *return_value = NULL;
5898 int fd;
5899 int inheritable;
5900
Sylvain74453812017-06-10 06:51:48 +02005901 if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable",
5902 &fd, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005903 goto exit;
5904 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005905 return_value = os_set_inheritable_impl(module, fd, inheritable);
5906
5907exit:
5908 return return_value;
5909}
5910
5911#if defined(MS_WINDOWS)
5912
5913PyDoc_STRVAR(os_get_handle_inheritable__doc__,
5914"get_handle_inheritable($module, handle, /)\n"
5915"--\n"
5916"\n"
5917"Get the close-on-exe flag of the specified file descriptor.");
5918
5919#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005920 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005921
5922static int
Victor Stinner581139c2016-09-06 15:54:20 -07005923os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005924
5925static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005926os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005927{
5928 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005929 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005930 int _return_value;
5931
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005932 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005933 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005934 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005935 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005936 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005937 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005938 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005939 return_value = PyBool_FromLong((long)_return_value);
5940
5941exit:
5942 return return_value;
5943}
5944
5945#endif /* defined(MS_WINDOWS) */
5946
5947#if defined(MS_WINDOWS)
5948
5949PyDoc_STRVAR(os_set_handle_inheritable__doc__,
5950"set_handle_inheritable($module, handle, inheritable, /)\n"
5951"--\n"
5952"\n"
5953"Set the inheritable flag of the specified handle.");
5954
5955#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005956 {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005957
5958static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07005959os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04005960 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005961
5962static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005963os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005964{
5965 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07005966 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005967 int inheritable;
5968
Sylvain74453812017-06-10 06:51:48 +02005969 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
5970 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005971 goto exit;
5972 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005973 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
5974
5975exit:
5976 return return_value;
5977}
5978
5979#endif /* defined(MS_WINDOWS) */
5980
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03005981#if !defined(MS_WINDOWS)
5982
5983PyDoc_STRVAR(os_get_blocking__doc__,
5984"get_blocking($module, fd, /)\n"
5985"--\n"
5986"\n"
5987"Get the blocking mode of the file descriptor.\n"
5988"\n"
5989"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
5990
5991#define OS_GET_BLOCKING_METHODDEF \
5992 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
5993
5994static int
5995os_get_blocking_impl(PyObject *module, int fd);
5996
5997static PyObject *
5998os_get_blocking(PyObject *module, PyObject *arg)
5999{
6000 PyObject *return_value = NULL;
6001 int fd;
6002 int _return_value;
6003
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006004 if (PyFloat_Check(arg)) {
6005 PyErr_SetString(PyExc_TypeError,
6006 "integer argument expected, got float" );
6007 goto exit;
6008 }
6009 fd = _PyLong_AsInt(arg);
6010 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006011 goto exit;
6012 }
6013 _return_value = os_get_blocking_impl(module, fd);
6014 if ((_return_value == -1) && PyErr_Occurred()) {
6015 goto exit;
6016 }
6017 return_value = PyBool_FromLong((long)_return_value);
6018
6019exit:
6020 return return_value;
6021}
6022
6023#endif /* !defined(MS_WINDOWS) */
6024
6025#if !defined(MS_WINDOWS)
6026
6027PyDoc_STRVAR(os_set_blocking__doc__,
6028"set_blocking($module, fd, blocking, /)\n"
6029"--\n"
6030"\n"
6031"Set the blocking mode of the specified file descriptor.\n"
6032"\n"
6033"Set the O_NONBLOCK flag if blocking is False,\n"
6034"clear the O_NONBLOCK flag otherwise.");
6035
6036#define OS_SET_BLOCKING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006037 {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006038
6039static PyObject *
6040os_set_blocking_impl(PyObject *module, int fd, int blocking);
6041
6042static PyObject *
6043os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6044{
6045 PyObject *return_value = NULL;
6046 int fd;
6047 int blocking;
6048
6049 if (!_PyArg_ParseStack(args, nargs, "ii:set_blocking",
6050 &fd, &blocking)) {
6051 goto exit;
6052 }
6053 return_value = os_set_blocking_impl(module, fd, blocking);
6054
6055exit:
6056 return return_value;
6057}
6058
6059#endif /* !defined(MS_WINDOWS) */
6060
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006061PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
6062"is_symlink($self, /)\n"
6063"--\n"
6064"\n"
6065"Return True if the entry is a symbolic link; cached per entry.");
6066
6067#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
6068 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
6069
6070static int
6071os_DirEntry_is_symlink_impl(DirEntry *self);
6072
6073static PyObject *
6074os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
6075{
6076 PyObject *return_value = NULL;
6077 int _return_value;
6078
6079 _return_value = os_DirEntry_is_symlink_impl(self);
6080 if ((_return_value == -1) && PyErr_Occurred()) {
6081 goto exit;
6082 }
6083 return_value = PyBool_FromLong((long)_return_value);
6084
6085exit:
6086 return return_value;
6087}
6088
6089PyDoc_STRVAR(os_DirEntry_stat__doc__,
6090"stat($self, /, *, follow_symlinks=True)\n"
6091"--\n"
6092"\n"
6093"Return stat_result object for the entry; cached per entry.");
6094
6095#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006096 {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006097
6098static PyObject *
6099os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
6100
6101static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006102os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006103{
6104 PyObject *return_value = NULL;
6105 static const char * const _keywords[] = {"follow_symlinks", NULL};
6106 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
6107 int follow_symlinks = 1;
6108
Victor Stinner3e1fad62017-01-17 01:29:01 +01006109 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006110 &follow_symlinks)) {
6111 goto exit;
6112 }
6113 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
6114
6115exit:
6116 return return_value;
6117}
6118
6119PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
6120"is_dir($self, /, *, follow_symlinks=True)\n"
6121"--\n"
6122"\n"
6123"Return True if the entry is a directory; cached per entry.");
6124
6125#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006126 {"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 +02006127
6128static int
6129os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
6130
6131static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006132os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006133{
6134 PyObject *return_value = NULL;
6135 static const char * const _keywords[] = {"follow_symlinks", NULL};
6136 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
6137 int follow_symlinks = 1;
6138 int _return_value;
6139
Victor Stinner3e1fad62017-01-17 01:29:01 +01006140 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006141 &follow_symlinks)) {
6142 goto exit;
6143 }
6144 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
6145 if ((_return_value == -1) && PyErr_Occurred()) {
6146 goto exit;
6147 }
6148 return_value = PyBool_FromLong((long)_return_value);
6149
6150exit:
6151 return return_value;
6152}
6153
6154PyDoc_STRVAR(os_DirEntry_is_file__doc__,
6155"is_file($self, /, *, follow_symlinks=True)\n"
6156"--\n"
6157"\n"
6158"Return True if the entry is a file; cached per entry.");
6159
6160#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006161 {"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 +02006162
6163static int
6164os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
6165
6166static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006167os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006168{
6169 PyObject *return_value = NULL;
6170 static const char * const _keywords[] = {"follow_symlinks", NULL};
6171 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
6172 int follow_symlinks = 1;
6173 int _return_value;
6174
Victor Stinner3e1fad62017-01-17 01:29:01 +01006175 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006176 &follow_symlinks)) {
6177 goto exit;
6178 }
6179 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
6180 if ((_return_value == -1) && PyErr_Occurred()) {
6181 goto exit;
6182 }
6183 return_value = PyBool_FromLong((long)_return_value);
6184
6185exit:
6186 return return_value;
6187}
6188
6189PyDoc_STRVAR(os_DirEntry_inode__doc__,
6190"inode($self, /)\n"
6191"--\n"
6192"\n"
6193"Return inode of the entry; cached per entry.");
6194
6195#define OS_DIRENTRY_INODE_METHODDEF \
6196 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6197
6198static PyObject *
6199os_DirEntry_inode_impl(DirEntry *self);
6200
6201static PyObject *
6202os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6203{
6204 return os_DirEntry_inode_impl(self);
6205}
6206
6207PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6208"__fspath__($self, /)\n"
6209"--\n"
6210"\n"
6211"Returns the path for the entry.");
6212
6213#define OS_DIRENTRY___FSPATH___METHODDEF \
6214 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6215
6216static PyObject *
6217os_DirEntry___fspath___impl(DirEntry *self);
6218
6219static PyObject *
6220os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6221{
6222 return os_DirEntry___fspath___impl(self);
6223}
6224
6225PyDoc_STRVAR(os_scandir__doc__,
6226"scandir($module, /, path=None)\n"
6227"--\n"
6228"\n"
6229"Return an iterator of DirEntry objects for given path.\n"
6230"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006231"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006232"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6233"all other circumstances they will be str.\n"
6234"\n"
6235"If path is None, uses the path=\'.\'.");
6236
6237#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006238 {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006239
6240static PyObject *
6241os_scandir_impl(PyObject *module, path_t *path);
6242
6243static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006244os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006245{
6246 PyObject *return_value = NULL;
6247 static const char * const _keywords[] = {"path", NULL};
6248 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006249 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006250
Victor Stinner3e1fad62017-01-17 01:29:01 +01006251 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006252 path_converter, &path)) {
6253 goto exit;
6254 }
6255 return_value = os_scandir_impl(module, &path);
6256
6257exit:
6258 /* Cleanup for path */
6259 path_cleanup(&path);
6260
6261 return return_value;
6262}
6263
Ethan Furman410ef8e2016-06-04 12:06:26 -07006264PyDoc_STRVAR(os_fspath__doc__,
6265"fspath($module, /, path)\n"
6266"--\n"
6267"\n"
6268"Return the file system path representation of the object.\n"
6269"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006270"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6271"object defines __fspath__(), then return the result of that method. All other\n"
6272"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006273
6274#define OS_FSPATH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006275 {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006276
6277static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006278os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006279
6280static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006281os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006282{
6283 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006284 static const char * const _keywords[] = {"path", NULL};
6285 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006286 PyObject *path;
6287
Victor Stinner3e1fad62017-01-17 01:29:01 +01006288 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006289 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006291 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006292 return_value = os_fspath_impl(module, path);
6293
6294exit:
6295 return return_value;
6296}
6297
Victor Stinner9b1f4742016-09-06 16:18:52 -07006298#if defined(HAVE_GETRANDOM_SYSCALL)
6299
6300PyDoc_STRVAR(os_getrandom__doc__,
6301"getrandom($module, /, size, flags=0)\n"
6302"--\n"
6303"\n"
6304"Obtain a series of random bytes.");
6305
6306#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006307 {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006308
6309static PyObject *
6310os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6311
6312static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006313os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006314{
6315 PyObject *return_value = NULL;
6316 static const char * const _keywords[] = {"size", "flags", NULL};
6317 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6318 Py_ssize_t size;
6319 int flags = 0;
6320
Victor Stinner3e1fad62017-01-17 01:29:01 +01006321 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006322 &size, &flags)) {
6323 goto exit;
6324 }
6325 return_value = os_getrandom_impl(module, size, flags);
6326
6327exit:
6328 return return_value;
6329}
6330
6331#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6332
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006333#ifndef OS_TTYNAME_METHODDEF
6334 #define OS_TTYNAME_METHODDEF
6335#endif /* !defined(OS_TTYNAME_METHODDEF) */
6336
6337#ifndef OS_CTERMID_METHODDEF
6338 #define OS_CTERMID_METHODDEF
6339#endif /* !defined(OS_CTERMID_METHODDEF) */
6340
6341#ifndef OS_FCHDIR_METHODDEF
6342 #define OS_FCHDIR_METHODDEF
6343#endif /* !defined(OS_FCHDIR_METHODDEF) */
6344
6345#ifndef OS_FCHMOD_METHODDEF
6346 #define OS_FCHMOD_METHODDEF
6347#endif /* !defined(OS_FCHMOD_METHODDEF) */
6348
6349#ifndef OS_LCHMOD_METHODDEF
6350 #define OS_LCHMOD_METHODDEF
6351#endif /* !defined(OS_LCHMOD_METHODDEF) */
6352
6353#ifndef OS_CHFLAGS_METHODDEF
6354 #define OS_CHFLAGS_METHODDEF
6355#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6356
6357#ifndef OS_LCHFLAGS_METHODDEF
6358 #define OS_LCHFLAGS_METHODDEF
6359#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6360
6361#ifndef OS_CHROOT_METHODDEF
6362 #define OS_CHROOT_METHODDEF
6363#endif /* !defined(OS_CHROOT_METHODDEF) */
6364
6365#ifndef OS_FSYNC_METHODDEF
6366 #define OS_FSYNC_METHODDEF
6367#endif /* !defined(OS_FSYNC_METHODDEF) */
6368
6369#ifndef OS_SYNC_METHODDEF
6370 #define OS_SYNC_METHODDEF
6371#endif /* !defined(OS_SYNC_METHODDEF) */
6372
6373#ifndef OS_FDATASYNC_METHODDEF
6374 #define OS_FDATASYNC_METHODDEF
6375#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6376
6377#ifndef OS_CHOWN_METHODDEF
6378 #define OS_CHOWN_METHODDEF
6379#endif /* !defined(OS_CHOWN_METHODDEF) */
6380
6381#ifndef OS_FCHOWN_METHODDEF
6382 #define OS_FCHOWN_METHODDEF
6383#endif /* !defined(OS_FCHOWN_METHODDEF) */
6384
6385#ifndef OS_LCHOWN_METHODDEF
6386 #define OS_LCHOWN_METHODDEF
6387#endif /* !defined(OS_LCHOWN_METHODDEF) */
6388
6389#ifndef OS_LINK_METHODDEF
6390 #define OS_LINK_METHODDEF
6391#endif /* !defined(OS_LINK_METHODDEF) */
6392
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006393#ifndef OS__GETFULLPATHNAME_METHODDEF
6394 #define OS__GETFULLPATHNAME_METHODDEF
6395#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6396
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006397#ifndef OS__GETFINALPATHNAME_METHODDEF
6398 #define OS__GETFINALPATHNAME_METHODDEF
6399#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6400
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006401#ifndef OS__ISDIR_METHODDEF
6402 #define OS__ISDIR_METHODDEF
6403#endif /* !defined(OS__ISDIR_METHODDEF) */
6404
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006405#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6406 #define OS__GETVOLUMEPATHNAME_METHODDEF
6407#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6408
6409#ifndef OS_NICE_METHODDEF
6410 #define OS_NICE_METHODDEF
6411#endif /* !defined(OS_NICE_METHODDEF) */
6412
6413#ifndef OS_GETPRIORITY_METHODDEF
6414 #define OS_GETPRIORITY_METHODDEF
6415#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6416
6417#ifndef OS_SETPRIORITY_METHODDEF
6418 #define OS_SETPRIORITY_METHODDEF
6419#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6420
6421#ifndef OS_SYSTEM_METHODDEF
6422 #define OS_SYSTEM_METHODDEF
6423#endif /* !defined(OS_SYSTEM_METHODDEF) */
6424
6425#ifndef OS_UNAME_METHODDEF
6426 #define OS_UNAME_METHODDEF
6427#endif /* !defined(OS_UNAME_METHODDEF) */
6428
6429#ifndef OS_EXECV_METHODDEF
6430 #define OS_EXECV_METHODDEF
6431#endif /* !defined(OS_EXECV_METHODDEF) */
6432
6433#ifndef OS_EXECVE_METHODDEF
6434 #define OS_EXECVE_METHODDEF
6435#endif /* !defined(OS_EXECVE_METHODDEF) */
6436
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006437#ifndef OS_POSIX_SPAWN_METHODDEF
6438 #define OS_POSIX_SPAWN_METHODDEF
6439#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6440
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006441#ifndef OS_SPAWNV_METHODDEF
6442 #define OS_SPAWNV_METHODDEF
6443#endif /* !defined(OS_SPAWNV_METHODDEF) */
6444
6445#ifndef OS_SPAWNVE_METHODDEF
6446 #define OS_SPAWNVE_METHODDEF
6447#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6448
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006449#ifndef OS_REGISTER_AT_FORK_METHODDEF
6450 #define OS_REGISTER_AT_FORK_METHODDEF
6451#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6452
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006453#ifndef OS_FORK1_METHODDEF
6454 #define OS_FORK1_METHODDEF
6455#endif /* !defined(OS_FORK1_METHODDEF) */
6456
6457#ifndef OS_FORK_METHODDEF
6458 #define OS_FORK_METHODDEF
6459#endif /* !defined(OS_FORK_METHODDEF) */
6460
6461#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6462 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6463#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6464
6465#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6466 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6467#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6468
6469#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6470 #define OS_SCHED_GETSCHEDULER_METHODDEF
6471#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6472
6473#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6474 #define OS_SCHED_SETSCHEDULER_METHODDEF
6475#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6476
6477#ifndef OS_SCHED_GETPARAM_METHODDEF
6478 #define OS_SCHED_GETPARAM_METHODDEF
6479#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6480
6481#ifndef OS_SCHED_SETPARAM_METHODDEF
6482 #define OS_SCHED_SETPARAM_METHODDEF
6483#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6484
6485#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6486 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6487#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6488
6489#ifndef OS_SCHED_YIELD_METHODDEF
6490 #define OS_SCHED_YIELD_METHODDEF
6491#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6492
6493#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6494 #define OS_SCHED_SETAFFINITY_METHODDEF
6495#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6496
6497#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6498 #define OS_SCHED_GETAFFINITY_METHODDEF
6499#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6500
6501#ifndef OS_OPENPTY_METHODDEF
6502 #define OS_OPENPTY_METHODDEF
6503#endif /* !defined(OS_OPENPTY_METHODDEF) */
6504
6505#ifndef OS_FORKPTY_METHODDEF
6506 #define OS_FORKPTY_METHODDEF
6507#endif /* !defined(OS_FORKPTY_METHODDEF) */
6508
6509#ifndef OS_GETEGID_METHODDEF
6510 #define OS_GETEGID_METHODDEF
6511#endif /* !defined(OS_GETEGID_METHODDEF) */
6512
6513#ifndef OS_GETEUID_METHODDEF
6514 #define OS_GETEUID_METHODDEF
6515#endif /* !defined(OS_GETEUID_METHODDEF) */
6516
6517#ifndef OS_GETGID_METHODDEF
6518 #define OS_GETGID_METHODDEF
6519#endif /* !defined(OS_GETGID_METHODDEF) */
6520
Berker Peksag39404992016-09-15 20:45:16 +03006521#ifndef OS_GETPID_METHODDEF
6522 #define OS_GETPID_METHODDEF
6523#endif /* !defined(OS_GETPID_METHODDEF) */
6524
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006525#ifndef OS_GETGROUPS_METHODDEF
6526 #define OS_GETGROUPS_METHODDEF
6527#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6528
6529#ifndef OS_GETPGID_METHODDEF
6530 #define OS_GETPGID_METHODDEF
6531#endif /* !defined(OS_GETPGID_METHODDEF) */
6532
6533#ifndef OS_GETPGRP_METHODDEF
6534 #define OS_GETPGRP_METHODDEF
6535#endif /* !defined(OS_GETPGRP_METHODDEF) */
6536
6537#ifndef OS_SETPGRP_METHODDEF
6538 #define OS_SETPGRP_METHODDEF
6539#endif /* !defined(OS_SETPGRP_METHODDEF) */
6540
6541#ifndef OS_GETPPID_METHODDEF
6542 #define OS_GETPPID_METHODDEF
6543#endif /* !defined(OS_GETPPID_METHODDEF) */
6544
6545#ifndef OS_GETLOGIN_METHODDEF
6546 #define OS_GETLOGIN_METHODDEF
6547#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6548
6549#ifndef OS_GETUID_METHODDEF
6550 #define OS_GETUID_METHODDEF
6551#endif /* !defined(OS_GETUID_METHODDEF) */
6552
6553#ifndef OS_KILL_METHODDEF
6554 #define OS_KILL_METHODDEF
6555#endif /* !defined(OS_KILL_METHODDEF) */
6556
6557#ifndef OS_KILLPG_METHODDEF
6558 #define OS_KILLPG_METHODDEF
6559#endif /* !defined(OS_KILLPG_METHODDEF) */
6560
6561#ifndef OS_PLOCK_METHODDEF
6562 #define OS_PLOCK_METHODDEF
6563#endif /* !defined(OS_PLOCK_METHODDEF) */
6564
6565#ifndef OS_SETUID_METHODDEF
6566 #define OS_SETUID_METHODDEF
6567#endif /* !defined(OS_SETUID_METHODDEF) */
6568
6569#ifndef OS_SETEUID_METHODDEF
6570 #define OS_SETEUID_METHODDEF
6571#endif /* !defined(OS_SETEUID_METHODDEF) */
6572
6573#ifndef OS_SETEGID_METHODDEF
6574 #define OS_SETEGID_METHODDEF
6575#endif /* !defined(OS_SETEGID_METHODDEF) */
6576
6577#ifndef OS_SETREUID_METHODDEF
6578 #define OS_SETREUID_METHODDEF
6579#endif /* !defined(OS_SETREUID_METHODDEF) */
6580
6581#ifndef OS_SETREGID_METHODDEF
6582 #define OS_SETREGID_METHODDEF
6583#endif /* !defined(OS_SETREGID_METHODDEF) */
6584
6585#ifndef OS_SETGID_METHODDEF
6586 #define OS_SETGID_METHODDEF
6587#endif /* !defined(OS_SETGID_METHODDEF) */
6588
6589#ifndef OS_SETGROUPS_METHODDEF
6590 #define OS_SETGROUPS_METHODDEF
6591#endif /* !defined(OS_SETGROUPS_METHODDEF) */
6592
6593#ifndef OS_WAIT3_METHODDEF
6594 #define OS_WAIT3_METHODDEF
6595#endif /* !defined(OS_WAIT3_METHODDEF) */
6596
6597#ifndef OS_WAIT4_METHODDEF
6598 #define OS_WAIT4_METHODDEF
6599#endif /* !defined(OS_WAIT4_METHODDEF) */
6600
6601#ifndef OS_WAITID_METHODDEF
6602 #define OS_WAITID_METHODDEF
6603#endif /* !defined(OS_WAITID_METHODDEF) */
6604
6605#ifndef OS_WAITPID_METHODDEF
6606 #define OS_WAITPID_METHODDEF
6607#endif /* !defined(OS_WAITPID_METHODDEF) */
6608
6609#ifndef OS_WAIT_METHODDEF
6610 #define OS_WAIT_METHODDEF
6611#endif /* !defined(OS_WAIT_METHODDEF) */
6612
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006613#ifndef OS_READLINK_METHODDEF
6614 #define OS_READLINK_METHODDEF
6615#endif /* !defined(OS_READLINK_METHODDEF) */
6616
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006617#ifndef OS_SYMLINK_METHODDEF
6618 #define OS_SYMLINK_METHODDEF
6619#endif /* !defined(OS_SYMLINK_METHODDEF) */
6620
6621#ifndef OS_TIMES_METHODDEF
6622 #define OS_TIMES_METHODDEF
6623#endif /* !defined(OS_TIMES_METHODDEF) */
6624
6625#ifndef OS_GETSID_METHODDEF
6626 #define OS_GETSID_METHODDEF
6627#endif /* !defined(OS_GETSID_METHODDEF) */
6628
6629#ifndef OS_SETSID_METHODDEF
6630 #define OS_SETSID_METHODDEF
6631#endif /* !defined(OS_SETSID_METHODDEF) */
6632
6633#ifndef OS_SETPGID_METHODDEF
6634 #define OS_SETPGID_METHODDEF
6635#endif /* !defined(OS_SETPGID_METHODDEF) */
6636
6637#ifndef OS_TCGETPGRP_METHODDEF
6638 #define OS_TCGETPGRP_METHODDEF
6639#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
6640
6641#ifndef OS_TCSETPGRP_METHODDEF
6642 #define OS_TCSETPGRP_METHODDEF
6643#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
6644
6645#ifndef OS_LOCKF_METHODDEF
6646 #define OS_LOCKF_METHODDEF
6647#endif /* !defined(OS_LOCKF_METHODDEF) */
6648
6649#ifndef OS_READV_METHODDEF
6650 #define OS_READV_METHODDEF
6651#endif /* !defined(OS_READV_METHODDEF) */
6652
6653#ifndef OS_PREAD_METHODDEF
6654 #define OS_PREAD_METHODDEF
6655#endif /* !defined(OS_PREAD_METHODDEF) */
6656
Pablo Galindo4defba32018-01-27 16:16:37 +00006657#ifndef OS_PREADV_METHODDEF
6658 #define OS_PREADV_METHODDEF
6659#endif /* !defined(OS_PREADV_METHODDEF) */
6660
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02006661#ifndef OS__FCOPYFILE_METHODDEF
6662 #define OS__FCOPYFILE_METHODDEF
6663#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
6664
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006665#ifndef OS_PIPE_METHODDEF
6666 #define OS_PIPE_METHODDEF
6667#endif /* !defined(OS_PIPE_METHODDEF) */
6668
6669#ifndef OS_PIPE2_METHODDEF
6670 #define OS_PIPE2_METHODDEF
6671#endif /* !defined(OS_PIPE2_METHODDEF) */
6672
6673#ifndef OS_WRITEV_METHODDEF
6674 #define OS_WRITEV_METHODDEF
6675#endif /* !defined(OS_WRITEV_METHODDEF) */
6676
6677#ifndef OS_PWRITE_METHODDEF
6678 #define OS_PWRITE_METHODDEF
6679#endif /* !defined(OS_PWRITE_METHODDEF) */
6680
Pablo Galindo4defba32018-01-27 16:16:37 +00006681#ifndef OS_PWRITEV_METHODDEF
6682 #define OS_PWRITEV_METHODDEF
6683#endif /* !defined(OS_PWRITEV_METHODDEF) */
6684
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006685#ifndef OS_MKFIFO_METHODDEF
6686 #define OS_MKFIFO_METHODDEF
6687#endif /* !defined(OS_MKFIFO_METHODDEF) */
6688
6689#ifndef OS_MKNOD_METHODDEF
6690 #define OS_MKNOD_METHODDEF
6691#endif /* !defined(OS_MKNOD_METHODDEF) */
6692
6693#ifndef OS_MAJOR_METHODDEF
6694 #define OS_MAJOR_METHODDEF
6695#endif /* !defined(OS_MAJOR_METHODDEF) */
6696
6697#ifndef OS_MINOR_METHODDEF
6698 #define OS_MINOR_METHODDEF
6699#endif /* !defined(OS_MINOR_METHODDEF) */
6700
6701#ifndef OS_MAKEDEV_METHODDEF
6702 #define OS_MAKEDEV_METHODDEF
6703#endif /* !defined(OS_MAKEDEV_METHODDEF) */
6704
6705#ifndef OS_FTRUNCATE_METHODDEF
6706 #define OS_FTRUNCATE_METHODDEF
6707#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
6708
6709#ifndef OS_TRUNCATE_METHODDEF
6710 #define OS_TRUNCATE_METHODDEF
6711#endif /* !defined(OS_TRUNCATE_METHODDEF) */
6712
6713#ifndef OS_POSIX_FALLOCATE_METHODDEF
6714 #define OS_POSIX_FALLOCATE_METHODDEF
6715#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
6716
6717#ifndef OS_POSIX_FADVISE_METHODDEF
6718 #define OS_POSIX_FADVISE_METHODDEF
6719#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
6720
6721#ifndef OS_PUTENV_METHODDEF
6722 #define OS_PUTENV_METHODDEF
6723#endif /* !defined(OS_PUTENV_METHODDEF) */
6724
6725#ifndef OS_UNSETENV_METHODDEF
6726 #define OS_UNSETENV_METHODDEF
6727#endif /* !defined(OS_UNSETENV_METHODDEF) */
6728
6729#ifndef OS_WCOREDUMP_METHODDEF
6730 #define OS_WCOREDUMP_METHODDEF
6731#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
6732
6733#ifndef OS_WIFCONTINUED_METHODDEF
6734 #define OS_WIFCONTINUED_METHODDEF
6735#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
6736
6737#ifndef OS_WIFSTOPPED_METHODDEF
6738 #define OS_WIFSTOPPED_METHODDEF
6739#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
6740
6741#ifndef OS_WIFSIGNALED_METHODDEF
6742 #define OS_WIFSIGNALED_METHODDEF
6743#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
6744
6745#ifndef OS_WIFEXITED_METHODDEF
6746 #define OS_WIFEXITED_METHODDEF
6747#endif /* !defined(OS_WIFEXITED_METHODDEF) */
6748
6749#ifndef OS_WEXITSTATUS_METHODDEF
6750 #define OS_WEXITSTATUS_METHODDEF
6751#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
6752
6753#ifndef OS_WTERMSIG_METHODDEF
6754 #define OS_WTERMSIG_METHODDEF
6755#endif /* !defined(OS_WTERMSIG_METHODDEF) */
6756
6757#ifndef OS_WSTOPSIG_METHODDEF
6758 #define OS_WSTOPSIG_METHODDEF
6759#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
6760
6761#ifndef OS_FSTATVFS_METHODDEF
6762 #define OS_FSTATVFS_METHODDEF
6763#endif /* !defined(OS_FSTATVFS_METHODDEF) */
6764
6765#ifndef OS_STATVFS_METHODDEF
6766 #define OS_STATVFS_METHODDEF
6767#endif /* !defined(OS_STATVFS_METHODDEF) */
6768
6769#ifndef OS__GETDISKUSAGE_METHODDEF
6770 #define OS__GETDISKUSAGE_METHODDEF
6771#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
6772
6773#ifndef OS_FPATHCONF_METHODDEF
6774 #define OS_FPATHCONF_METHODDEF
6775#endif /* !defined(OS_FPATHCONF_METHODDEF) */
6776
6777#ifndef OS_PATHCONF_METHODDEF
6778 #define OS_PATHCONF_METHODDEF
6779#endif /* !defined(OS_PATHCONF_METHODDEF) */
6780
6781#ifndef OS_CONFSTR_METHODDEF
6782 #define OS_CONFSTR_METHODDEF
6783#endif /* !defined(OS_CONFSTR_METHODDEF) */
6784
6785#ifndef OS_SYSCONF_METHODDEF
6786 #define OS_SYSCONF_METHODDEF
6787#endif /* !defined(OS_SYSCONF_METHODDEF) */
6788
Steve Dowercc16be82016-09-08 10:35:16 -07006789#ifndef OS_STARTFILE_METHODDEF
6790 #define OS_STARTFILE_METHODDEF
6791#endif /* !defined(OS_STARTFILE_METHODDEF) */
6792
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006793#ifndef OS_GETLOADAVG_METHODDEF
6794 #define OS_GETLOADAVG_METHODDEF
6795#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
6796
6797#ifndef OS_SETRESUID_METHODDEF
6798 #define OS_SETRESUID_METHODDEF
6799#endif /* !defined(OS_SETRESUID_METHODDEF) */
6800
6801#ifndef OS_SETRESGID_METHODDEF
6802 #define OS_SETRESGID_METHODDEF
6803#endif /* !defined(OS_SETRESGID_METHODDEF) */
6804
6805#ifndef OS_GETRESUID_METHODDEF
6806 #define OS_GETRESUID_METHODDEF
6807#endif /* !defined(OS_GETRESUID_METHODDEF) */
6808
6809#ifndef OS_GETRESGID_METHODDEF
6810 #define OS_GETRESGID_METHODDEF
6811#endif /* !defined(OS_GETRESGID_METHODDEF) */
6812
6813#ifndef OS_GETXATTR_METHODDEF
6814 #define OS_GETXATTR_METHODDEF
6815#endif /* !defined(OS_GETXATTR_METHODDEF) */
6816
6817#ifndef OS_SETXATTR_METHODDEF
6818 #define OS_SETXATTR_METHODDEF
6819#endif /* !defined(OS_SETXATTR_METHODDEF) */
6820
6821#ifndef OS_REMOVEXATTR_METHODDEF
6822 #define OS_REMOVEXATTR_METHODDEF
6823#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
6824
6825#ifndef OS_LISTXATTR_METHODDEF
6826 #define OS_LISTXATTR_METHODDEF
6827#endif /* !defined(OS_LISTXATTR_METHODDEF) */
6828
6829#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
6830 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
6831#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
6832
6833#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
6834 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
6835#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07006836
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006837#ifndef OS_GET_BLOCKING_METHODDEF
6838 #define OS_GET_BLOCKING_METHODDEF
6839#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
6840
6841#ifndef OS_SET_BLOCKING_METHODDEF
6842 #define OS_SET_BLOCKING_METHODDEF
6843#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
6844
Victor Stinner9b1f4742016-09-06 16:18:52 -07006845#ifndef OS_GETRANDOM_METHODDEF
6846 #define OS_GETRANDOM_METHODDEF
6847#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006848/*[clinic end generated code: output=b02036b2a269b1db input=a9049054013a1b77]*/