blob: 2c1ee97faf711d00dae249c74b9b4ba586de7bb9 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(os_stat__doc__,
6"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
7"--\n"
8"\n"
9"Perform a stat system call on the given path.\n"
10"\n"
11" path\n"
BNMetricsb9427072018-11-02 15:20:19 +000012" Path to be examined; can be string, bytes, a path-like object or\n"
Xiang Zhang4459e002017-01-22 13:04:17 +080013" open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030014" dir_fd\n"
15" If not None, it should be a file descriptor open to a directory,\n"
16" and path should be a relative string; path will then be relative to\n"
17" that directory.\n"
18" follow_symlinks\n"
19" If False, and the last element of the path is a symbolic link,\n"
20" stat will examine the symbolic link itself instead of the file\n"
21" the link points to.\n"
22"\n"
23"dir_fd and follow_symlinks may not be implemented\n"
24" on your platform. If they are unavailable, using them will raise a\n"
25" NotImplementedError.\n"
26"\n"
27"It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
28" an open file descriptor.");
29
30#define OS_STAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020031 {"stat", (PyCFunction)(void(*)(void))os_stat, METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030032
33static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030034os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030035
36static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020037os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030038{
39 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030040 static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
41 static _PyArg_Parser _parser = {"O&|$O&p:stat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030042 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
43 int dir_fd = DEFAULT_DIR_FD;
44 int follow_symlinks = 1;
45
Victor Stinner3e1fad62017-01-17 01:29:01 +010046 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030047 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030048 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030049 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
51
52exit:
53 /* Cleanup for path */
54 path_cleanup(&path);
55
56 return return_value;
57}
58
59PyDoc_STRVAR(os_lstat__doc__,
60"lstat($module, /, path, *, dir_fd=None)\n"
61"--\n"
62"\n"
63"Perform a stat system call on the given path, without following symbolic links.\n"
64"\n"
65"Like stat(), but do not follow symbolic links.\n"
66"Equivalent to stat(path, follow_symlinks=False).");
67
68#define OS_LSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020069 {"lstat", (PyCFunction)(void(*)(void))os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070
71static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030072os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030073
74static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020075os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"path", "dir_fd", NULL};
79 static _PyArg_Parser _parser = {"O&|$O&:lstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030080 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
81 int dir_fd = DEFAULT_DIR_FD;
82
Victor Stinner3e1fad62017-01-17 01:29:01 +010083 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030087 return_value = os_lstat_impl(module, &path, dir_fd);
88
89exit:
90 /* Cleanup for path */
91 path_cleanup(&path);
92
93 return return_value;
94}
95
96PyDoc_STRVAR(os_access__doc__,
97"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
98" follow_symlinks=True)\n"
99"--\n"
100"\n"
101"Use the real uid/gid to test for access to a path.\n"
102"\n"
103" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000104" Path to be tested; can be string, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105" mode\n"
106" Operating-system mode bitfield. Can be F_OK to test existence,\n"
107" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
108" dir_fd\n"
109" If not None, it should be a file descriptor open to a directory,\n"
110" and path should be relative; path will then be relative to that\n"
111" directory.\n"
112" effective_ids\n"
113" If True, access will use the effective uid/gid instead of\n"
114" the real uid/gid.\n"
115" follow_symlinks\n"
116" If False, and the last element of the path is a symbolic link,\n"
117" access will examine the symbolic link itself instead of the file\n"
118" the link points to.\n"
119"\n"
120"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
121" on your platform. If they are unavailable, using them will raise a\n"
122" NotImplementedError.\n"
123"\n"
124"Note that most operations will use the effective uid/gid, therefore this\n"
125" routine can be used in a suid/sgid environment to test if the invoking user\n"
126" has the specified access to the path.");
127
128#define OS_ACCESS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200129 {"access", (PyCFunction)(void(*)(void))os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300130
131static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300132os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400133 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300134
135static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200136os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300137{
138 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300139 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
140 static _PyArg_Parser _parser = {"O&i|$O&pp:access", _keywords, 0};
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700141 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300142 int mode;
143 int dir_fd = DEFAULT_DIR_FD;
144 int effective_ids = 0;
145 int follow_symlinks = 1;
146 int _return_value;
147
Victor Stinner3e1fad62017-01-17 01:29:01 +0100148 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300153 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300155 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156 return_value = PyBool_FromLong((long)_return_value);
157
158exit:
159 /* Cleanup for path */
160 path_cleanup(&path);
161
162 return return_value;
163}
164
165#if defined(HAVE_TTYNAME)
166
167PyDoc_STRVAR(os_ttyname__doc__,
168"ttyname($module, fd, /)\n"
169"--\n"
170"\n"
171"Return the name of the terminal device connected to \'fd\'.\n"
172"\n"
173" fd\n"
174" Integer file descriptor handle.");
175
176#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300177 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300178
Serhiy Storchaka4db62e12018-12-17 16:47:45 +0200179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300180os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300181
182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300183os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300184{
185 PyObject *return_value = NULL;
186 int fd;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300187
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200188 if (PyFloat_Check(arg)) {
189 PyErr_SetString(PyExc_TypeError,
190 "integer argument expected, got float" );
191 goto exit;
192 }
193 fd = _PyLong_AsInt(arg);
194 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300195 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300196 }
Serhiy Storchaka4db62e12018-12-17 16:47:45 +0200197 return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300198
199exit:
200 return return_value;
201}
202
203#endif /* defined(HAVE_TTYNAME) */
204
205#if defined(HAVE_CTERMID)
206
207PyDoc_STRVAR(os_ctermid__doc__,
208"ctermid($module, /)\n"
209"--\n"
210"\n"
211"Return the name of the controlling terminal for this process.");
212
213#define OS_CTERMID_METHODDEF \
214 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
215
216static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300217os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300218
219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300220os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300221{
222 return os_ctermid_impl(module);
223}
224
225#endif /* defined(HAVE_CTERMID) */
226
227PyDoc_STRVAR(os_chdir__doc__,
228"chdir($module, /, path)\n"
229"--\n"
230"\n"
231"Change the current working directory to the specified path.\n"
232"\n"
233"path may always be specified as a string.\n"
234"On some platforms, path may also be specified as an open file descriptor.\n"
235" If this functionality is unavailable, using it raises an exception.");
236
237#define OS_CHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200238 {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300239
240static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300241os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300242
243static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200244os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300245{
246 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300247 static const char * const _keywords[] = {"path", NULL};
248 static _PyArg_Parser _parser = {"O&:chdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300249 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
250
Victor Stinner3e1fad62017-01-17 01:29:01 +0100251 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300252 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300253 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300254 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300255 return_value = os_chdir_impl(module, &path);
256
257exit:
258 /* Cleanup for path */
259 path_cleanup(&path);
260
261 return return_value;
262}
263
264#if defined(HAVE_FCHDIR)
265
266PyDoc_STRVAR(os_fchdir__doc__,
267"fchdir($module, /, fd)\n"
268"--\n"
269"\n"
270"Change to the directory of the given file descriptor.\n"
271"\n"
272"fd must be opened on a directory, not a file.\n"
273"Equivalent to os.chdir(fd).");
274
275#define OS_FCHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200276 {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300277
278static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300279os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300280
281static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200282os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300283{
284 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300285 static const char * const _keywords[] = {"fd", NULL};
286 static _PyArg_Parser _parser = {"O&:fchdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300287 int fd;
288
Victor Stinner3e1fad62017-01-17 01:29:01 +0100289 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300290 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300291 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300292 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300293 return_value = os_fchdir_impl(module, fd);
294
295exit:
296 return return_value;
297}
298
299#endif /* defined(HAVE_FCHDIR) */
300
301PyDoc_STRVAR(os_chmod__doc__,
302"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
303"--\n"
304"\n"
305"Change the access permissions of a file.\n"
306"\n"
307" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000308" Path to be modified. May always be specified as a str, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300309" On some platforms, path may also be specified as an open file descriptor.\n"
310" If this functionality is unavailable, using it raises an exception.\n"
311" mode\n"
312" Operating-system mode bitfield.\n"
313" dir_fd\n"
314" If not None, it should be a file descriptor open to a directory,\n"
315" and path should be relative; path will then be relative to that\n"
316" directory.\n"
317" follow_symlinks\n"
318" If False, and the last element of the path is a symbolic link,\n"
319" chmod will modify the symbolic link itself instead of the file\n"
320" the link points to.\n"
321"\n"
322"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
323" an open file descriptor.\n"
324"dir_fd and follow_symlinks may not be implemented on your platform.\n"
325" If they are unavailable, using them will raise a NotImplementedError.");
326
327#define OS_CHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200328 {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300329
330static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300331os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400332 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300333
334static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200335os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300336{
337 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300338 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
339 static _PyArg_Parser _parser = {"O&i|$O&p:chmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300340 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
341 int mode;
342 int dir_fd = DEFAULT_DIR_FD;
343 int follow_symlinks = 1;
344
Victor Stinner3e1fad62017-01-17 01:29:01 +0100345 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300346 path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300347 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300348 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300349 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
350
351exit:
352 /* Cleanup for path */
353 path_cleanup(&path);
354
355 return return_value;
356}
357
358#if defined(HAVE_FCHMOD)
359
360PyDoc_STRVAR(os_fchmod__doc__,
361"fchmod($module, /, fd, mode)\n"
362"--\n"
363"\n"
364"Change the access permissions of the file given by file descriptor fd.\n"
365"\n"
366"Equivalent to os.chmod(fd, mode).");
367
368#define OS_FCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200369 {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300370
371static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300372os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300373
374static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200375os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300376{
377 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300378 static const char * const _keywords[] = {"fd", "mode", NULL};
379 static _PyArg_Parser _parser = {"ii:fchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300380 int fd;
381 int mode;
382
Victor Stinner3e1fad62017-01-17 01:29:01 +0100383 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300384 &fd, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300385 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300386 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300387 return_value = os_fchmod_impl(module, fd, mode);
388
389exit:
390 return return_value;
391}
392
393#endif /* defined(HAVE_FCHMOD) */
394
395#if defined(HAVE_LCHMOD)
396
397PyDoc_STRVAR(os_lchmod__doc__,
398"lchmod($module, /, path, mode)\n"
399"--\n"
400"\n"
401"Change the access permissions of a file, without following symbolic links.\n"
402"\n"
403"If path is a symlink, this affects the link itself rather than the target.\n"
404"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
405
406#define OS_LCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200407 {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300408
409static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300410os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300411
412static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200413os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300414{
415 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300416 static const char * const _keywords[] = {"path", "mode", NULL};
417 static _PyArg_Parser _parser = {"O&i:lchmod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300418 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
419 int mode;
420
Victor Stinner3e1fad62017-01-17 01:29:01 +0100421 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300422 path_converter, &path, &mode)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300423 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300424 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300425 return_value = os_lchmod_impl(module, &path, mode);
426
427exit:
428 /* Cleanup for path */
429 path_cleanup(&path);
430
431 return return_value;
432}
433
434#endif /* defined(HAVE_LCHMOD) */
435
436#if defined(HAVE_CHFLAGS)
437
438PyDoc_STRVAR(os_chflags__doc__,
439"chflags($module, /, path, flags, follow_symlinks=True)\n"
440"--\n"
441"\n"
442"Set file flags.\n"
443"\n"
444"If follow_symlinks is False, and the last element of the path is a symbolic\n"
445" link, chflags will change flags on the symbolic link itself instead of the\n"
446" file the link points to.\n"
447"follow_symlinks may not be implemented on your platform. If it is\n"
448"unavailable, using it will raise a NotImplementedError.");
449
450#define OS_CHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200451 {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300452
453static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300454os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400455 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300456
457static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200458os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300459{
460 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300461 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
462 static _PyArg_Parser _parser = {"O&k|p:chflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300463 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
464 unsigned long flags;
465 int follow_symlinks = 1;
466
Victor Stinner3e1fad62017-01-17 01:29:01 +0100467 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300468 path_converter, &path, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300469 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300471 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
472
473exit:
474 /* Cleanup for path */
475 path_cleanup(&path);
476
477 return return_value;
478}
479
480#endif /* defined(HAVE_CHFLAGS) */
481
482#if defined(HAVE_LCHFLAGS)
483
484PyDoc_STRVAR(os_lchflags__doc__,
485"lchflags($module, /, path, flags)\n"
486"--\n"
487"\n"
488"Set file flags.\n"
489"\n"
490"This function will not follow symbolic links.\n"
491"Equivalent to chflags(path, flags, follow_symlinks=False).");
492
493#define OS_LCHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200494 {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300495
496static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300497os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300498
499static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200500os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300501{
502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300503 static const char * const _keywords[] = {"path", "flags", NULL};
504 static _PyArg_Parser _parser = {"O&k:lchflags", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300505 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
506 unsigned long flags;
507
Victor Stinner3e1fad62017-01-17 01:29:01 +0100508 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300509 path_converter, &path, &flags)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300510 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300511 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300512 return_value = os_lchflags_impl(module, &path, flags);
513
514exit:
515 /* Cleanup for path */
516 path_cleanup(&path);
517
518 return return_value;
519}
520
521#endif /* defined(HAVE_LCHFLAGS) */
522
523#if defined(HAVE_CHROOT)
524
525PyDoc_STRVAR(os_chroot__doc__,
526"chroot($module, /, path)\n"
527"--\n"
528"\n"
529"Change root directory to path.");
530
531#define OS_CHROOT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200532 {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300533
534static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300535os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300536
537static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200538os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300539{
540 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300541 static const char * const _keywords[] = {"path", NULL};
542 static _PyArg_Parser _parser = {"O&:chroot", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300543 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
544
Victor Stinner3e1fad62017-01-17 01:29:01 +0100545 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300546 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300547 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300548 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300549 return_value = os_chroot_impl(module, &path);
550
551exit:
552 /* Cleanup for path */
553 path_cleanup(&path);
554
555 return return_value;
556}
557
558#endif /* defined(HAVE_CHROOT) */
559
560#if defined(HAVE_FSYNC)
561
562PyDoc_STRVAR(os_fsync__doc__,
563"fsync($module, /, fd)\n"
564"--\n"
565"\n"
566"Force write of fd to disk.");
567
568#define OS_FSYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200569 {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300570
571static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300572os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300573
574static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200575os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300576{
577 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300578 static const char * const _keywords[] = {"fd", NULL};
579 static _PyArg_Parser _parser = {"O&:fsync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300580 int fd;
581
Victor Stinner3e1fad62017-01-17 01:29:01 +0100582 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300583 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300584 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300585 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300586 return_value = os_fsync_impl(module, fd);
587
588exit:
589 return return_value;
590}
591
592#endif /* defined(HAVE_FSYNC) */
593
594#if defined(HAVE_SYNC)
595
596PyDoc_STRVAR(os_sync__doc__,
597"sync($module, /)\n"
598"--\n"
599"\n"
600"Force write of everything to disk.");
601
602#define OS_SYNC_METHODDEF \
603 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
604
605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300606os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300607
608static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300609os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300610{
611 return os_sync_impl(module);
612}
613
614#endif /* defined(HAVE_SYNC) */
615
616#if defined(HAVE_FDATASYNC)
617
618PyDoc_STRVAR(os_fdatasync__doc__,
619"fdatasync($module, /, fd)\n"
620"--\n"
621"\n"
622"Force write of fd to disk without forcing update of metadata.");
623
624#define OS_FDATASYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200625 {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300626
627static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300628os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300629
630static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200631os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300632{
633 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300634 static const char * const _keywords[] = {"fd", NULL};
635 static _PyArg_Parser _parser = {"O&:fdatasync", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300636 int fd;
637
Victor Stinner3e1fad62017-01-17 01:29:01 +0100638 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300639 fildes_converter, &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300640 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300641 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300642 return_value = os_fdatasync_impl(module, fd);
643
644exit:
645 return return_value;
646}
647
648#endif /* defined(HAVE_FDATASYNC) */
649
650#if defined(HAVE_CHOWN)
651
652PyDoc_STRVAR(os_chown__doc__,
653"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
654"--\n"
655"\n"
656"Change the owner and group id of path to the numeric uid and gid.\\\n"
657"\n"
658" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000659" Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300660" dir_fd\n"
661" If not None, it should be a file descriptor open to a directory,\n"
662" and path should be relative; path will then be relative to that\n"
663" directory.\n"
664" follow_symlinks\n"
665" If False, and the last element of the path is a symbolic link,\n"
666" stat will examine the symbolic link itself instead of the file\n"
667" the link points to.\n"
668"\n"
669"path may always be specified as a string.\n"
670"On some platforms, path may also be specified as an open file descriptor.\n"
671" If this functionality is unavailable, using it raises an exception.\n"
672"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
673" and path should be relative; path will then be relative to that directory.\n"
674"If follow_symlinks is False, and the last element of the path is a symbolic\n"
675" link, chown will modify the symbolic link itself instead of the file the\n"
676" link points to.\n"
677"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
678" an open file descriptor.\n"
679"dir_fd and follow_symlinks may not be implemented on your platform.\n"
680" If they are unavailable, using them will raise a NotImplementedError.");
681
682#define OS_CHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200683 {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300684
685static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300686os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400687 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300688
689static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200690os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300691{
692 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300693 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
694 static _PyArg_Parser _parser = {"O&O&O&|$O&p:chown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300695 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
696 uid_t uid;
697 gid_t gid;
698 int dir_fd = DEFAULT_DIR_FD;
699 int follow_symlinks = 1;
700
Victor Stinner3e1fad62017-01-17 01:29:01 +0100701 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300702 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300703 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300704 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
706
707exit:
708 /* Cleanup for path */
709 path_cleanup(&path);
710
711 return return_value;
712}
713
714#endif /* defined(HAVE_CHOWN) */
715
716#if defined(HAVE_FCHOWN)
717
718PyDoc_STRVAR(os_fchown__doc__,
719"fchown($module, /, fd, uid, gid)\n"
720"--\n"
721"\n"
722"Change the owner and group id of the file specified by file descriptor.\n"
723"\n"
724"Equivalent to os.chown(fd, uid, gid).");
725
726#define OS_FCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200727 {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300728
729static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300730os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300731
732static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200733os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300734{
735 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300736 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
737 static _PyArg_Parser _parser = {"iO&O&:fchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300738 int fd;
739 uid_t uid;
740 gid_t gid;
741
Victor Stinner3e1fad62017-01-17 01:29:01 +0100742 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300743 &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300744 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300745 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300746 return_value = os_fchown_impl(module, fd, uid, gid);
747
748exit:
749 return return_value;
750}
751
752#endif /* defined(HAVE_FCHOWN) */
753
754#if defined(HAVE_LCHOWN)
755
756PyDoc_STRVAR(os_lchown__doc__,
757"lchown($module, /, path, uid, gid)\n"
758"--\n"
759"\n"
760"Change the owner and group id of path to the numeric uid and gid.\n"
761"\n"
762"This function will not follow symbolic links.\n"
763"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
764
765#define OS_LCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200766 {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300767
768static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300769os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300770
771static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200772os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300773{
774 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300775 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
776 static _PyArg_Parser _parser = {"O&O&O&:lchown", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300777 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
778 uid_t uid;
779 gid_t gid;
780
Victor Stinner3e1fad62017-01-17 01:29:01 +0100781 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300782 path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300783 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300784 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300785 return_value = os_lchown_impl(module, &path, uid, gid);
786
787exit:
788 /* Cleanup for path */
789 path_cleanup(&path);
790
791 return return_value;
792}
793
794#endif /* defined(HAVE_LCHOWN) */
795
796PyDoc_STRVAR(os_getcwd__doc__,
797"getcwd($module, /)\n"
798"--\n"
799"\n"
800"Return a unicode string representing the current working directory.");
801
802#define OS_GETCWD_METHODDEF \
803 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
804
805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300806os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300807
808static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300809os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300810{
811 return os_getcwd_impl(module);
812}
813
814PyDoc_STRVAR(os_getcwdb__doc__,
815"getcwdb($module, /)\n"
816"--\n"
817"\n"
818"Return a bytes string representing the current working directory.");
819
820#define OS_GETCWDB_METHODDEF \
821 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
822
823static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300824os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300825
826static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300827os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300828{
829 return os_getcwdb_impl(module);
830}
831
832#if defined(HAVE_LINK)
833
834PyDoc_STRVAR(os_link__doc__,
835"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
836" follow_symlinks=True)\n"
837"--\n"
838"\n"
839"Create a hard link to a file.\n"
840"\n"
841"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
842" descriptor open to a directory, and the respective path string (src or dst)\n"
843" should be relative; the path will then be relative to that directory.\n"
844"If follow_symlinks is False, and the last element of src is a symbolic\n"
845" link, link will create a link to the symbolic link itself instead of the\n"
846" file the link points to.\n"
847"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
848" platform. If they are unavailable, using them will raise a\n"
849" NotImplementedError.");
850
851#define OS_LINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200852 {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300853
854static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300855os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400856 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300857
858static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200859os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300860{
861 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300862 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
863 static _PyArg_Parser _parser = {"O&O&|$O&O&p:link", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300864 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
865 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
866 int src_dir_fd = DEFAULT_DIR_FD;
867 int dst_dir_fd = DEFAULT_DIR_FD;
868 int follow_symlinks = 1;
869
Victor Stinner3e1fad62017-01-17 01:29:01 +0100870 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300871 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300872 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300873 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300874 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
875
876exit:
877 /* Cleanup for src */
878 path_cleanup(&src);
879 /* Cleanup for dst */
880 path_cleanup(&dst);
881
882 return return_value;
883}
884
885#endif /* defined(HAVE_LINK) */
886
887PyDoc_STRVAR(os_listdir__doc__,
888"listdir($module, /, path=None)\n"
889"--\n"
890"\n"
891"Return a list containing the names of the files in the directory.\n"
892"\n"
BNMetricsb9427072018-11-02 15:20:19 +0000893"path can be specified as either str, bytes, or a path-like object. If path is bytes,\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300894" the filenames returned will also be bytes; in all other circumstances\n"
895" the filenames returned will be str.\n"
896"If path is None, uses the path=\'.\'.\n"
897"On some platforms, path may also be specified as an open file descriptor;\\\n"
898" the file descriptor must refer to a directory.\n"
899" If this functionality is unavailable, using it raises NotImplementedError.\n"
900"\n"
901"The list is in arbitrary order. It does not include the special\n"
902"entries \'.\' and \'..\' even if they are present in the directory.");
903
904#define OS_LISTDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200905 {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300906
907static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300908os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300909
910static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200911os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300912{
913 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300914 static const char * const _keywords[] = {"path", NULL};
915 static _PyArg_Parser _parser = {"|O&:listdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300916 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
917
Victor Stinner3e1fad62017-01-17 01:29:01 +0100918 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300919 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300920 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300921 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300922 return_value = os_listdir_impl(module, &path);
923
924exit:
925 /* Cleanup for path */
926 path_cleanup(&path);
927
928 return return_value;
929}
930
931#if defined(MS_WINDOWS)
932
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300933PyDoc_STRVAR(os__getfullpathname__doc__,
934"_getfullpathname($module, path, /)\n"
935"--\n"
936"\n");
937
938#define OS__GETFULLPATHNAME_METHODDEF \
939 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
940
941static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300942os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300943
944static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300945os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300946{
947 PyObject *return_value = NULL;
948 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
949
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200950 if (!path_converter(arg, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300951 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300952 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +0300953 return_value = os__getfullpathname_impl(module, &path);
954
955exit:
956 /* Cleanup for path */
957 path_cleanup(&path);
958
959 return return_value;
960}
961
962#endif /* defined(MS_WINDOWS) */
963
964#if defined(MS_WINDOWS)
965
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300966PyDoc_STRVAR(os__getfinalpathname__doc__,
967"_getfinalpathname($module, path, /)\n"
968"--\n"
969"\n"
970"A helper function for samepath on windows.");
971
972#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300973 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300974
975static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -0800976os__getfinalpathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300977
978static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300979os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300980{
981 PyObject *return_value = NULL;
Steve Dower23ad6d02018-02-22 10:39:10 -0800982 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300983
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200984 if (!path_converter(arg, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300985 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300986 }
Steve Dower23ad6d02018-02-22 10:39:10 -0800987 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300988
989exit:
Steve Dower23ad6d02018-02-22 10:39:10 -0800990 /* Cleanup for path */
991 path_cleanup(&path);
992
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300993 return return_value;
994}
995
996#endif /* defined(MS_WINDOWS) */
997
998#if defined(MS_WINDOWS)
999
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001000PyDoc_STRVAR(os__isdir__doc__,
1001"_isdir($module, path, /)\n"
1002"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +02001003"\n"
1004"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001005
1006#define OS__ISDIR_METHODDEF \
1007 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1008
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001009#endif /* defined(MS_WINDOWS) */
1010
1011#if defined(MS_WINDOWS)
1012
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001013PyDoc_STRVAR(os__getvolumepathname__doc__,
1014"_getvolumepathname($module, /, path)\n"
1015"--\n"
1016"\n"
1017"A helper function for ismount on Win32.");
1018
1019#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001020 {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001021
1022static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001023os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001024
1025static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001026os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001027{
1028 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001029 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08001030 static _PyArg_Parser _parser = {"O&:_getvolumepathname", _keywords, 0};
1031 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001032
Victor Stinner3e1fad62017-01-17 01:29:01 +01001033 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08001034 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001035 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001036 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001037 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001038
1039exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001040 /* Cleanup for path */
1041 path_cleanup(&path);
1042
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001043 return return_value;
1044}
1045
1046#endif /* defined(MS_WINDOWS) */
1047
1048PyDoc_STRVAR(os_mkdir__doc__,
1049"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1050"--\n"
1051"\n"
1052"Create a directory.\n"
1053"\n"
1054"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1055" and path should be relative; path will then be relative to that directory.\n"
1056"dir_fd may not be implemented on your platform.\n"
1057" If it is unavailable, using it will raise a NotImplementedError.\n"
1058"\n"
1059"The mode argument is ignored on Windows.");
1060
1061#define OS_MKDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001062 {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001063
1064static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001065os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001066
1067static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001068os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001069{
1070 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001071 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
1072 static _PyArg_Parser _parser = {"O&|i$O&:mkdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001073 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1074 int mode = 511;
1075 int dir_fd = DEFAULT_DIR_FD;
1076
Victor Stinner3e1fad62017-01-17 01:29:01 +01001077 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001078 path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001079 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001080 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001081 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1082
1083exit:
1084 /* Cleanup for path */
1085 path_cleanup(&path);
1086
1087 return return_value;
1088}
1089
1090#if defined(HAVE_NICE)
1091
1092PyDoc_STRVAR(os_nice__doc__,
1093"nice($module, increment, /)\n"
1094"--\n"
1095"\n"
1096"Add increment to the priority of process and return the new priority.");
1097
1098#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001099 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001100
1101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001102os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001103
1104static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001105os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001106{
1107 PyObject *return_value = NULL;
1108 int increment;
1109
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001110 if (PyFloat_Check(arg)) {
1111 PyErr_SetString(PyExc_TypeError,
1112 "integer argument expected, got float" );
1113 goto exit;
1114 }
1115 increment = _PyLong_AsInt(arg);
1116 if (increment == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001117 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001118 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001119 return_value = os_nice_impl(module, increment);
1120
1121exit:
1122 return return_value;
1123}
1124
1125#endif /* defined(HAVE_NICE) */
1126
1127#if defined(HAVE_GETPRIORITY)
1128
1129PyDoc_STRVAR(os_getpriority__doc__,
1130"getpriority($module, /, which, who)\n"
1131"--\n"
1132"\n"
1133"Return program scheduling priority.");
1134
1135#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001136 {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001137
1138static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001139os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001140
1141static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001142os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001143{
1144 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001145 static const char * const _keywords[] = {"which", "who", NULL};
1146 static _PyArg_Parser _parser = {"ii:getpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001147 int which;
1148 int who;
1149
Victor Stinner3e1fad62017-01-17 01:29:01 +01001150 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001151 &which, &who)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001152 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001154 return_value = os_getpriority_impl(module, which, who);
1155
1156exit:
1157 return return_value;
1158}
1159
1160#endif /* defined(HAVE_GETPRIORITY) */
1161
1162#if defined(HAVE_SETPRIORITY)
1163
1164PyDoc_STRVAR(os_setpriority__doc__,
1165"setpriority($module, /, which, who, priority)\n"
1166"--\n"
1167"\n"
1168"Set program scheduling priority.");
1169
1170#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001171 {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001172
1173static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001174os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001175
1176static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001177os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001178{
1179 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001180 static const char * const _keywords[] = {"which", "who", "priority", NULL};
1181 static _PyArg_Parser _parser = {"iii:setpriority", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001182 int which;
1183 int who;
1184 int priority;
1185
Victor Stinner3e1fad62017-01-17 01:29:01 +01001186 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001187 &which, &who, &priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001188 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001189 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001190 return_value = os_setpriority_impl(module, which, who, priority);
1191
1192exit:
1193 return return_value;
1194}
1195
1196#endif /* defined(HAVE_SETPRIORITY) */
1197
1198PyDoc_STRVAR(os_rename__doc__,
1199"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1200"--\n"
1201"\n"
1202"Rename a file or directory.\n"
1203"\n"
1204"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1205" descriptor open to a directory, and the respective path string (src or dst)\n"
1206" should be relative; the path will then be relative to that directory.\n"
1207"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1208" If they are unavailable, using them will raise a NotImplementedError.");
1209
1210#define OS_RENAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001211 {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001212
1213static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001214os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001215 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001216
1217static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001218os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001219{
1220 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001221 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1222 static _PyArg_Parser _parser = {"O&O&|$O&O&:rename", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001223 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1224 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1225 int src_dir_fd = DEFAULT_DIR_FD;
1226 int dst_dir_fd = DEFAULT_DIR_FD;
1227
Victor Stinner3e1fad62017-01-17 01:29:01 +01001228 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001229 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001230 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001231 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001232 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1233
1234exit:
1235 /* Cleanup for src */
1236 path_cleanup(&src);
1237 /* Cleanup for dst */
1238 path_cleanup(&dst);
1239
1240 return return_value;
1241}
1242
1243PyDoc_STRVAR(os_replace__doc__,
1244"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1245"--\n"
1246"\n"
1247"Rename a file or directory, overwriting the destination.\n"
1248"\n"
1249"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1250" descriptor open to a directory, and the respective path string (src or dst)\n"
1251" should be relative; the path will then be relative to that directory.\n"
1252"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1253" If they are unavailable, using them will raise a NotImplementedError.\"");
1254
1255#define OS_REPLACE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001256 {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001257
1258static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001259os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1260 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001261
1262static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001263os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001264{
1265 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001266 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
1267 static _PyArg_Parser _parser = {"O&O&|$O&O&:replace", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001268 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1269 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1270 int src_dir_fd = DEFAULT_DIR_FD;
1271 int dst_dir_fd = DEFAULT_DIR_FD;
1272
Victor Stinner3e1fad62017-01-17 01:29:01 +01001273 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001274 path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001275 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001276 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001277 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1278
1279exit:
1280 /* Cleanup for src */
1281 path_cleanup(&src);
1282 /* Cleanup for dst */
1283 path_cleanup(&dst);
1284
1285 return return_value;
1286}
1287
1288PyDoc_STRVAR(os_rmdir__doc__,
1289"rmdir($module, /, path, *, dir_fd=None)\n"
1290"--\n"
1291"\n"
1292"Remove a directory.\n"
1293"\n"
1294"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1295" and path should be relative; path will then be relative to that directory.\n"
1296"dir_fd may not be implemented on your platform.\n"
1297" If it is unavailable, using it will raise a NotImplementedError.");
1298
1299#define OS_RMDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001300 {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001301
1302static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001303os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001304
1305static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001306os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001307{
1308 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001309 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1310 static _PyArg_Parser _parser = {"O&|$O&:rmdir", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001311 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1312 int dir_fd = DEFAULT_DIR_FD;
1313
Victor Stinner3e1fad62017-01-17 01:29:01 +01001314 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001315 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001316 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001317 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001318 return_value = os_rmdir_impl(module, &path, dir_fd);
1319
1320exit:
1321 /* Cleanup for path */
1322 path_cleanup(&path);
1323
1324 return return_value;
1325}
1326
1327#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1328
1329PyDoc_STRVAR(os_system__doc__,
1330"system($module, /, command)\n"
1331"--\n"
1332"\n"
1333"Execute the command in a subshell.");
1334
1335#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001336 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001337
1338static long
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001339os_system_impl(PyObject *module, const Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001340
1341static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001342os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001343{
1344 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001345 static const char * const _keywords[] = {"command", NULL};
1346 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001347 const Py_UNICODE *command;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348 long _return_value;
1349
Victor Stinner3e1fad62017-01-17 01:29:01 +01001350 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001351 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001352 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001353 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001355 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001356 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001357 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001358 return_value = PyLong_FromLong(_return_value);
1359
1360exit:
1361 return return_value;
1362}
1363
1364#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1365
1366#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1367
1368PyDoc_STRVAR(os_system__doc__,
1369"system($module, /, command)\n"
1370"--\n"
1371"\n"
1372"Execute the command in a subshell.");
1373
1374#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001375 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001376
1377static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001378os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001379
1380static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001381os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001382{
1383 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001384 static const char * const _keywords[] = {"command", NULL};
1385 static _PyArg_Parser _parser = {"O&:system", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001386 PyObject *command = NULL;
1387 long _return_value;
1388
Victor Stinner3e1fad62017-01-17 01:29:01 +01001389 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001390 PyUnicode_FSConverter, &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001391 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001392 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001393 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001394 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001395 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001396 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001397 return_value = PyLong_FromLong(_return_value);
1398
1399exit:
1400 /* Cleanup for command */
1401 Py_XDECREF(command);
1402
1403 return return_value;
1404}
1405
1406#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1407
1408PyDoc_STRVAR(os_umask__doc__,
1409"umask($module, mask, /)\n"
1410"--\n"
1411"\n"
1412"Set the current numeric umask and return the previous umask.");
1413
1414#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001415 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001416
1417static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001418os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001419
1420static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001421os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001422{
1423 PyObject *return_value = NULL;
1424 int mask;
1425
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001426 if (PyFloat_Check(arg)) {
1427 PyErr_SetString(PyExc_TypeError,
1428 "integer argument expected, got float" );
1429 goto exit;
1430 }
1431 mask = _PyLong_AsInt(arg);
1432 if (mask == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001435 return_value = os_umask_impl(module, mask);
1436
1437exit:
1438 return return_value;
1439}
1440
1441PyDoc_STRVAR(os_unlink__doc__,
1442"unlink($module, /, path, *, dir_fd=None)\n"
1443"--\n"
1444"\n"
1445"Remove a file (same as remove()).\n"
1446"\n"
1447"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1448" and path should be relative; path will then be relative to that directory.\n"
1449"dir_fd may not be implemented on your platform.\n"
1450" If it is unavailable, using it will raise a NotImplementedError.");
1451
1452#define OS_UNLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001453 {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001454
1455static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001456os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001457
1458static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001459os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001460{
1461 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001462 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1463 static _PyArg_Parser _parser = {"O&|$O&:unlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001464 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1465 int dir_fd = DEFAULT_DIR_FD;
1466
Victor Stinner3e1fad62017-01-17 01:29:01 +01001467 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001468 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001469 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001470 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001471 return_value = os_unlink_impl(module, &path, dir_fd);
1472
1473exit:
1474 /* Cleanup for path */
1475 path_cleanup(&path);
1476
1477 return return_value;
1478}
1479
1480PyDoc_STRVAR(os_remove__doc__,
1481"remove($module, /, path, *, dir_fd=None)\n"
1482"--\n"
1483"\n"
1484"Remove a file (same as unlink()).\n"
1485"\n"
1486"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1487" and path should be relative; path will then be relative to that directory.\n"
1488"dir_fd may not be implemented on your platform.\n"
1489" If it is unavailable, using it will raise a NotImplementedError.");
1490
1491#define OS_REMOVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001492 {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001493
1494static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001495os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001496
1497static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001498os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001499{
1500 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001501 static const char * const _keywords[] = {"path", "dir_fd", NULL};
1502 static _PyArg_Parser _parser = {"O&|$O&:remove", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001503 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1504 int dir_fd = DEFAULT_DIR_FD;
1505
Victor Stinner3e1fad62017-01-17 01:29:01 +01001506 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001507 path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001508 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001509 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001510 return_value = os_remove_impl(module, &path, dir_fd);
1511
1512exit:
1513 /* Cleanup for path */
1514 path_cleanup(&path);
1515
1516 return return_value;
1517}
1518
1519#if defined(HAVE_UNAME)
1520
1521PyDoc_STRVAR(os_uname__doc__,
1522"uname($module, /)\n"
1523"--\n"
1524"\n"
1525"Return an object identifying the current operating system.\n"
1526"\n"
1527"The object behaves like a named tuple with the following fields:\n"
1528" (sysname, nodename, release, version, machine)");
1529
1530#define OS_UNAME_METHODDEF \
1531 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1532
1533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001534os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001535
1536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001537os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001538{
1539 return os_uname_impl(module);
1540}
1541
1542#endif /* defined(HAVE_UNAME) */
1543
1544PyDoc_STRVAR(os_utime__doc__,
1545"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1546" follow_symlinks=True)\n"
1547"--\n"
1548"\n"
1549"Set the access and modified time of path.\n"
1550"\n"
1551"path may always be specified as a string.\n"
1552"On some platforms, path may also be specified as an open file descriptor.\n"
1553" If this functionality is unavailable, using it raises an exception.\n"
1554"\n"
1555"If times is not None, it must be a tuple (atime, mtime);\n"
1556" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001557"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001558" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
1559" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001560"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001561"Specifying tuples for both times and ns is an error.\n"
1562"\n"
1563"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1564" and path should be relative; path will then be relative to that directory.\n"
1565"If follow_symlinks is False, and the last element of the path is a symbolic\n"
1566" link, utime will modify the symbolic link itself instead of the file the\n"
1567" link points to.\n"
1568"It is an error to use dir_fd or follow_symlinks when specifying path\n"
1569" as an open file descriptor.\n"
1570"dir_fd and follow_symlinks may not be available on your platform.\n"
1571" If they are unavailable, using them will raise a NotImplementedError.");
1572
1573#define OS_UTIME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001574 {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001575
1576static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001577os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
1578 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001579
1580static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001581os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001582{
1583 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001584 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
1585 static _PyArg_Parser _parser = {"O&|O$OO&p:utime", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001586 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
1587 PyObject *times = NULL;
1588 PyObject *ns = NULL;
1589 int dir_fd = DEFAULT_DIR_FD;
1590 int follow_symlinks = 1;
1591
Victor Stinner3e1fad62017-01-17 01:29:01 +01001592 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001593 path_converter, &path, &times, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001594 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001595 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001596 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
1597
1598exit:
1599 /* Cleanup for path */
1600 path_cleanup(&path);
1601
1602 return return_value;
1603}
1604
1605PyDoc_STRVAR(os__exit__doc__,
1606"_exit($module, /, status)\n"
1607"--\n"
1608"\n"
1609"Exit to the system with specified status, without normal exit processing.");
1610
1611#define OS__EXIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001612 {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001613
1614static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001615os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001616
1617static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001618os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001619{
1620 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001621 static const char * const _keywords[] = {"status", NULL};
1622 static _PyArg_Parser _parser = {"i:_exit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001623 int status;
1624
Victor Stinner3e1fad62017-01-17 01:29:01 +01001625 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001626 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001627 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001628 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001629 return_value = os__exit_impl(module, status);
1630
1631exit:
1632 return return_value;
1633}
1634
1635#if defined(HAVE_EXECV)
1636
1637PyDoc_STRVAR(os_execv__doc__,
1638"execv($module, path, argv, /)\n"
1639"--\n"
1640"\n"
1641"Execute an executable path with arguments, replacing current process.\n"
1642"\n"
1643" path\n"
1644" Path of executable file.\n"
1645" argv\n"
1646" Tuple or list of strings.");
1647
1648#define OS_EXECV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001649 {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001650
1651static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001652os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001653
1654static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001655os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001656{
1657 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07001658 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001659 PyObject *argv;
1660
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001661 if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001662 goto exit;
1663 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001664 if (!path_converter(args[0], &path)) {
1665 goto exit;
1666 }
1667 argv = args[1];
Steve Dowercc16be82016-09-08 10:35:16 -07001668 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001669
1670exit:
1671 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001672 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001673
1674 return return_value;
1675}
1676
1677#endif /* defined(HAVE_EXECV) */
1678
1679#if defined(HAVE_EXECV)
1680
1681PyDoc_STRVAR(os_execve__doc__,
1682"execve($module, /, path, argv, env)\n"
1683"--\n"
1684"\n"
1685"Execute an executable path with arguments, replacing current process.\n"
1686"\n"
1687" path\n"
1688" Path of executable file.\n"
1689" argv\n"
1690" Tuple or list of strings.\n"
1691" env\n"
1692" Dictionary of strings mapping to strings.");
1693
1694#define OS_EXECVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001695 {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001696
1697static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001698os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001699
1700static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001701os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001702{
1703 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001704 static const char * const _keywords[] = {"path", "argv", "env", NULL};
1705 static _PyArg_Parser _parser = {"O&OO:execve", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001706 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
1707 PyObject *argv;
1708 PyObject *env;
1709
Victor Stinner3e1fad62017-01-17 01:29:01 +01001710 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001711 path_converter, &path, &argv, &env)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001712 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001713 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001714 return_value = os_execve_impl(module, &path, argv, env);
1715
1716exit:
1717 /* Cleanup for path */
1718 path_cleanup(&path);
1719
1720 return return_value;
1721}
1722
1723#endif /* defined(HAVE_EXECV) */
1724
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001725#if defined(HAVE_POSIX_SPAWN)
1726
1727PyDoc_STRVAR(os_posix_spawn__doc__,
Serhiy Storchakad700f972018-09-08 14:48:18 +03001728"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001729" setpgroup=None, resetids=False, setsigmask=(),\n"
1730" setsigdef=(), scheduler=None)\n"
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001731"--\n"
1732"\n"
1733"Execute the program specified by path in a new process.\n"
1734"\n"
1735" path\n"
1736" Path of executable file.\n"
1737" argv\n"
1738" Tuple or list of strings.\n"
1739" env\n"
1740" Dictionary of strings mapping to strings.\n"
1741" file_actions\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01001742" A sequence of file action tuples.\n"
1743" setpgroup\n"
1744" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1745" resetids\n"
1746" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
1747" setsigmask\n"
1748" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1749" setsigdef\n"
1750" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1751" scheduler\n"
1752" A tuple with the scheduler policy (optional) and parameters.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001753
1754#define OS_POSIX_SPAWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001755 {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001756
1757static PyObject *
1758os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
Pablo Galindo254a4662018-09-07 16:44:24 +01001759 PyObject *env, PyObject *file_actions,
1760 PyObject *setpgroup, int resetids, PyObject *setsigmask,
1761 PyObject *setsigdef, PyObject *scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001762
1763static PyObject *
Pablo Galindo254a4662018-09-07 16:44:24 +01001764os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001765{
1766 PyObject *return_value = NULL;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001767 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL};
1768 static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawn", _keywords, 0};
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001769 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
1770 PyObject *argv;
1771 PyObject *env;
Serhiy Storchakad700f972018-09-08 14:48:18 +03001772 PyObject *file_actions = NULL;
Pablo Galindo254a4662018-09-07 16:44:24 +01001773 PyObject *setpgroup = NULL;
1774 int resetids = 0;
1775 PyObject *setsigmask = NULL;
1776 PyObject *setsigdef = NULL;
1777 PyObject *scheduler = NULL;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001778
Pablo Galindo254a4662018-09-07 16:44:24 +01001779 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1780 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) {
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001781 goto exit;
1782 }
Pablo Galindo254a4662018-09-07 16:44:24 +01001783 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00001784
1785exit:
1786 /* Cleanup for path */
1787 path_cleanup(&path);
1788
1789 return return_value;
1790}
1791
1792#endif /* defined(HAVE_POSIX_SPAWN) */
1793
Steve Dowercc16be82016-09-08 10:35:16 -07001794#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001795
1796PyDoc_STRVAR(os_spawnv__doc__,
1797"spawnv($module, mode, path, argv, /)\n"
1798"--\n"
1799"\n"
1800"Execute the program specified by path in a new process.\n"
1801"\n"
1802" mode\n"
1803" Mode of process creation.\n"
1804" path\n"
1805" Path of executable file.\n"
1806" argv\n"
1807" Tuple or list of strings.");
1808
1809#define OS_SPAWNV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001810 {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001811
1812static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001813os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001814
1815static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001816os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001817{
1818 PyObject *return_value = NULL;
1819 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001820 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001821 PyObject *argv;
1822
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001823 if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001824 goto exit;
1825 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001826 if (PyFloat_Check(args[0])) {
1827 PyErr_SetString(PyExc_TypeError,
1828 "integer argument expected, got float" );
1829 goto exit;
1830 }
1831 mode = _PyLong_AsInt(args[0]);
1832 if (mode == -1 && PyErr_Occurred()) {
1833 goto exit;
1834 }
1835 if (!path_converter(args[1], &path)) {
1836 goto exit;
1837 }
1838 argv = args[2];
Steve Dowercc16be82016-09-08 10:35:16 -07001839 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001840
1841exit:
1842 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001843 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001844
1845 return return_value;
1846}
1847
Steve Dowercc16be82016-09-08 10:35:16 -07001848#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001849
Steve Dowercc16be82016-09-08 10:35:16 -07001850#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001851
1852PyDoc_STRVAR(os_spawnve__doc__,
1853"spawnve($module, mode, path, argv, env, /)\n"
1854"--\n"
1855"\n"
1856"Execute the program specified by path in a new process.\n"
1857"\n"
1858" mode\n"
1859" Mode of process creation.\n"
1860" path\n"
1861" Path of executable file.\n"
1862" argv\n"
1863" Tuple or list of strings.\n"
1864" env\n"
1865" Dictionary of strings mapping to strings.");
1866
1867#define OS_SPAWNVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001868 {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001869
1870static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001871os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001872 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001873
1874static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001875os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001876{
1877 PyObject *return_value = NULL;
1878 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001879 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001880 PyObject *argv;
1881 PyObject *env;
1882
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001883 if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001884 goto exit;
1885 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001886 if (PyFloat_Check(args[0])) {
1887 PyErr_SetString(PyExc_TypeError,
1888 "integer argument expected, got float" );
1889 goto exit;
1890 }
1891 mode = _PyLong_AsInt(args[0]);
1892 if (mode == -1 && PyErr_Occurred()) {
1893 goto exit;
1894 }
1895 if (!path_converter(args[1], &path)) {
1896 goto exit;
1897 }
1898 argv = args[2];
1899 env = args[3];
Steve Dowercc16be82016-09-08 10:35:16 -07001900 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001901
1902exit:
1903 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001904 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001905
1906 return return_value;
1907}
1908
Steve Dowercc16be82016-09-08 10:35:16 -07001909#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001910
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001911#if defined(HAVE_FORK)
1912
1913PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001914"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1915" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001916"--\n"
1917"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001918"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001919"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001920" before\n"
1921" A callable to be called in the parent before the fork() syscall.\n"
1922" after_in_child\n"
1923" A callable to be called in the child after fork().\n"
1924" after_in_parent\n"
1925" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001926"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001927"\'before\' callbacks are called in reverse order.\n"
1928"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001929
1930#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001931 {"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 +02001932
1933static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07001934os_register_at_fork_impl(PyObject *module, PyObject *before,
1935 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001936
1937static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001938os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001939{
1940 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07001941 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
1942 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
1943 PyObject *before = NULL;
1944 PyObject *after_in_child = NULL;
1945 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001946
1947 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001948 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001949 goto exit;
1950 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07001951 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001952
1953exit:
1954 return return_value;
1955}
1956
1957#endif /* defined(HAVE_FORK) */
1958
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001959#if defined(HAVE_FORK1)
1960
1961PyDoc_STRVAR(os_fork1__doc__,
1962"fork1($module, /)\n"
1963"--\n"
1964"\n"
1965"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
1966"\n"
1967"Return 0 to child process and PID of child to parent process.");
1968
1969#define OS_FORK1_METHODDEF \
1970 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
1971
1972static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001973os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001974
1975static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001976os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001977{
1978 return os_fork1_impl(module);
1979}
1980
1981#endif /* defined(HAVE_FORK1) */
1982
1983#if defined(HAVE_FORK)
1984
1985PyDoc_STRVAR(os_fork__doc__,
1986"fork($module, /)\n"
1987"--\n"
1988"\n"
1989"Fork a child process.\n"
1990"\n"
1991"Return 0 to child process and PID of child to parent process.");
1992
1993#define OS_FORK_METHODDEF \
1994 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
1995
1996static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001997os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001998
1999static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002000os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002001{
2002 return os_fork_impl(module);
2003}
2004
2005#endif /* defined(HAVE_FORK) */
2006
2007#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2008
2009PyDoc_STRVAR(os_sched_get_priority_max__doc__,
2010"sched_get_priority_max($module, /, policy)\n"
2011"--\n"
2012"\n"
2013"Get the maximum scheduling priority for policy.");
2014
2015#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002016 {"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 +03002017
2018static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002019os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002020
2021static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002022os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002023{
2024 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002025 static const char * const _keywords[] = {"policy", NULL};
2026 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002027 int policy;
2028
Victor Stinner3e1fad62017-01-17 01:29:01 +01002029 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002030 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002031 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002032 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002033 return_value = os_sched_get_priority_max_impl(module, policy);
2034
2035exit:
2036 return return_value;
2037}
2038
2039#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2040
2041#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2042
2043PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2044"sched_get_priority_min($module, /, policy)\n"
2045"--\n"
2046"\n"
2047"Get the minimum scheduling priority for policy.");
2048
2049#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002050 {"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 +03002051
2052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002053os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002054
2055static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002056os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002057{
2058 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002059 static const char * const _keywords[] = {"policy", NULL};
2060 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002061 int policy;
2062
Victor Stinner3e1fad62017-01-17 01:29:01 +01002063 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002064 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002065 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002066 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002067 return_value = os_sched_get_priority_min_impl(module, policy);
2068
2069exit:
2070 return return_value;
2071}
2072
2073#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2074
2075#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2076
2077PyDoc_STRVAR(os_sched_getscheduler__doc__,
2078"sched_getscheduler($module, pid, /)\n"
2079"--\n"
2080"\n"
2081"Get the scheduling policy for the process identifiedy by pid.\n"
2082"\n"
2083"Passing 0 for pid returns the scheduling policy for the calling process.");
2084
2085#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002086 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002087
2088static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002089os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002090
2091static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002092os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002093{
2094 PyObject *return_value = NULL;
2095 pid_t pid;
2096
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002097 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002098 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002099 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002100 return_value = os_sched_getscheduler_impl(module, pid);
2101
2102exit:
2103 return return_value;
2104}
2105
2106#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2107
William Orr81574b82018-10-01 22:19:56 -07002108#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 +03002109
2110PyDoc_STRVAR(os_sched_param__doc__,
2111"sched_param(sched_priority)\n"
2112"--\n"
2113"\n"
2114"Current has only one field: sched_priority\");\n"
2115"\n"
2116" sched_priority\n"
2117" A scheduling parameter.");
2118
2119static PyObject *
2120os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2121
2122static PyObject *
2123os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2124{
2125 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002126 static const char * const _keywords[] = {"sched_priority", NULL};
2127 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002128 PyObject *sched_priority;
2129
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002130 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002131 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002132 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002133 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134 return_value = os_sched_param_impl(type, sched_priority);
2135
2136exit:
2137 return return_value;
2138}
2139
William Orr81574b82018-10-01 22:19:56 -07002140#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 +03002141
2142#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2143
2144PyDoc_STRVAR(os_sched_setscheduler__doc__,
2145"sched_setscheduler($module, pid, policy, param, /)\n"
2146"--\n"
2147"\n"
2148"Set the scheduling policy for the process identified by pid.\n"
2149"\n"
2150"If pid is 0, the calling process is changed.\n"
2151"param is an instance of sched_param.");
2152
2153#define OS_SCHED_SETSCHEDULER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002154 {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002155
2156static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002157os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002158 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002159
2160static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002161os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002162{
2163 PyObject *return_value = NULL;
2164 pid_t pid;
2165 int policy;
2166 struct sched_param param;
2167
Sylvain74453812017-06-10 06:51:48 +02002168 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2169 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002170 goto exit;
2171 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002172 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2173
2174exit:
2175 return return_value;
2176}
2177
2178#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2179
2180#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2181
2182PyDoc_STRVAR(os_sched_getparam__doc__,
2183"sched_getparam($module, pid, /)\n"
2184"--\n"
2185"\n"
2186"Returns scheduling parameters for the process identified by pid.\n"
2187"\n"
2188"If pid is 0, returns parameters for the calling process.\n"
2189"Return value is an instance of sched_param.");
2190
2191#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002192 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002193
2194static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002195os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002196
2197static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002198os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002199{
2200 PyObject *return_value = NULL;
2201 pid_t pid;
2202
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002203 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002204 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002205 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002206 return_value = os_sched_getparam_impl(module, pid);
2207
2208exit:
2209 return return_value;
2210}
2211
2212#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2213
2214#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2215
2216PyDoc_STRVAR(os_sched_setparam__doc__,
2217"sched_setparam($module, pid, param, /)\n"
2218"--\n"
2219"\n"
2220"Set scheduling parameters for the process identified by pid.\n"
2221"\n"
2222"If pid is 0, sets parameters for the calling process.\n"
2223"param should be an instance of sched_param.");
2224
2225#define OS_SCHED_SETPARAM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002226 {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002227
2228static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002229os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002230 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002231
2232static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002233os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002234{
2235 PyObject *return_value = NULL;
2236 pid_t pid;
2237 struct sched_param param;
2238
Sylvain74453812017-06-10 06:51:48 +02002239 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2240 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002241 goto exit;
2242 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002243 return_value = os_sched_setparam_impl(module, pid, &param);
2244
2245exit:
2246 return return_value;
2247}
2248
2249#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2250
2251#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2252
2253PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2254"sched_rr_get_interval($module, pid, /)\n"
2255"--\n"
2256"\n"
2257"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2258"\n"
2259"Value returned is a float.");
2260
2261#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002262 {"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 +03002263
2264static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002265os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002266
2267static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002268os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002269{
2270 PyObject *return_value = NULL;
2271 pid_t pid;
2272 double _return_value;
2273
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002274 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002275 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002276 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002277 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002278 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002279 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002280 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002281 return_value = PyFloat_FromDouble(_return_value);
2282
2283exit:
2284 return return_value;
2285}
2286
2287#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2288
2289#if defined(HAVE_SCHED_H)
2290
2291PyDoc_STRVAR(os_sched_yield__doc__,
2292"sched_yield($module, /)\n"
2293"--\n"
2294"\n"
2295"Voluntarily relinquish the CPU.");
2296
2297#define OS_SCHED_YIELD_METHODDEF \
2298 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2299
2300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002301os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002302
2303static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002304os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002305{
2306 return os_sched_yield_impl(module);
2307}
2308
2309#endif /* defined(HAVE_SCHED_H) */
2310
2311#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2312
2313PyDoc_STRVAR(os_sched_setaffinity__doc__,
2314"sched_setaffinity($module, pid, mask, /)\n"
2315"--\n"
2316"\n"
2317"Set the CPU affinity of the process identified by pid to mask.\n"
2318"\n"
2319"mask should be an iterable of integers identifying CPUs.");
2320
2321#define OS_SCHED_SETAFFINITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002322 {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002323
2324static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002325os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002326
2327static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002328os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002329{
2330 PyObject *return_value = NULL;
2331 pid_t pid;
2332 PyObject *mask;
2333
Sylvain74453812017-06-10 06:51:48 +02002334 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2335 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002336 goto exit;
2337 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002338 return_value = os_sched_setaffinity_impl(module, pid, mask);
2339
2340exit:
2341 return return_value;
2342}
2343
2344#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2345
2346#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2347
2348PyDoc_STRVAR(os_sched_getaffinity__doc__,
2349"sched_getaffinity($module, pid, /)\n"
2350"--\n"
2351"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002352"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002353"\n"
2354"The affinity is returned as a set of CPU identifiers.");
2355
2356#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002357 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002358
2359static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002360os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002361
2362static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002363os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002364{
2365 PyObject *return_value = NULL;
2366 pid_t pid;
2367
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002368 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002369 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002370 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002371 return_value = os_sched_getaffinity_impl(module, pid);
2372
2373exit:
2374 return return_value;
2375}
2376
2377#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2378
2379#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2380
2381PyDoc_STRVAR(os_openpty__doc__,
2382"openpty($module, /)\n"
2383"--\n"
2384"\n"
2385"Open a pseudo-terminal.\n"
2386"\n"
2387"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2388"for both the master and slave ends.");
2389
2390#define OS_OPENPTY_METHODDEF \
2391 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2392
2393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002394os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002395
2396static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002397os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002398{
2399 return os_openpty_impl(module);
2400}
2401
2402#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2403
2404#if defined(HAVE_FORKPTY)
2405
2406PyDoc_STRVAR(os_forkpty__doc__,
2407"forkpty($module, /)\n"
2408"--\n"
2409"\n"
2410"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2411"\n"
2412"Returns a tuple of (pid, master_fd).\n"
2413"Like fork(), return pid of 0 to the child process,\n"
2414"and pid of child to the parent process.\n"
2415"To both, return fd of newly opened pseudo-terminal.");
2416
2417#define OS_FORKPTY_METHODDEF \
2418 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2419
2420static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002421os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002422
2423static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002424os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002425{
2426 return os_forkpty_impl(module);
2427}
2428
2429#endif /* defined(HAVE_FORKPTY) */
2430
2431#if defined(HAVE_GETEGID)
2432
2433PyDoc_STRVAR(os_getegid__doc__,
2434"getegid($module, /)\n"
2435"--\n"
2436"\n"
2437"Return the current process\'s effective group id.");
2438
2439#define OS_GETEGID_METHODDEF \
2440 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2441
2442static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002443os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002444
2445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002446os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002447{
2448 return os_getegid_impl(module);
2449}
2450
2451#endif /* defined(HAVE_GETEGID) */
2452
2453#if defined(HAVE_GETEUID)
2454
2455PyDoc_STRVAR(os_geteuid__doc__,
2456"geteuid($module, /)\n"
2457"--\n"
2458"\n"
2459"Return the current process\'s effective user id.");
2460
2461#define OS_GETEUID_METHODDEF \
2462 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2463
2464static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002465os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002466
2467static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002468os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002469{
2470 return os_geteuid_impl(module);
2471}
2472
2473#endif /* defined(HAVE_GETEUID) */
2474
2475#if defined(HAVE_GETGID)
2476
2477PyDoc_STRVAR(os_getgid__doc__,
2478"getgid($module, /)\n"
2479"--\n"
2480"\n"
2481"Return the current process\'s group id.");
2482
2483#define OS_GETGID_METHODDEF \
2484 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2485
2486static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002487os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002488
2489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002490os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491{
2492 return os_getgid_impl(module);
2493}
2494
2495#endif /* defined(HAVE_GETGID) */
2496
Berker Peksag39404992016-09-15 20:45:16 +03002497#if defined(HAVE_GETPID)
2498
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002499PyDoc_STRVAR(os_getpid__doc__,
2500"getpid($module, /)\n"
2501"--\n"
2502"\n"
2503"Return the current process id.");
2504
2505#define OS_GETPID_METHODDEF \
2506 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2507
2508static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002509os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002510
2511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002512os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002513{
2514 return os_getpid_impl(module);
2515}
2516
Berker Peksag39404992016-09-15 20:45:16 +03002517#endif /* defined(HAVE_GETPID) */
2518
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002519#if defined(HAVE_GETGROUPS)
2520
2521PyDoc_STRVAR(os_getgroups__doc__,
2522"getgroups($module, /)\n"
2523"--\n"
2524"\n"
2525"Return list of supplemental group IDs for the process.");
2526
2527#define OS_GETGROUPS_METHODDEF \
2528 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2529
2530static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002531os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002532
2533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002534os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002535{
2536 return os_getgroups_impl(module);
2537}
2538
2539#endif /* defined(HAVE_GETGROUPS) */
2540
2541#if defined(HAVE_GETPGID)
2542
2543PyDoc_STRVAR(os_getpgid__doc__,
2544"getpgid($module, /, pid)\n"
2545"--\n"
2546"\n"
2547"Call the system call getpgid(), and return the result.");
2548
2549#define OS_GETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002550 {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002551
2552static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002553os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002554
2555static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002556os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002557{
2558 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002559 static const char * const _keywords[] = {"pid", NULL};
2560 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002561 pid_t pid;
2562
Victor Stinner3e1fad62017-01-17 01:29:01 +01002563 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002564 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002565 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002566 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002567 return_value = os_getpgid_impl(module, pid);
2568
2569exit:
2570 return return_value;
2571}
2572
2573#endif /* defined(HAVE_GETPGID) */
2574
2575#if defined(HAVE_GETPGRP)
2576
2577PyDoc_STRVAR(os_getpgrp__doc__,
2578"getpgrp($module, /)\n"
2579"--\n"
2580"\n"
2581"Return the current process group id.");
2582
2583#define OS_GETPGRP_METHODDEF \
2584 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2585
2586static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002587os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002588
2589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002590os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002591{
2592 return os_getpgrp_impl(module);
2593}
2594
2595#endif /* defined(HAVE_GETPGRP) */
2596
2597#if defined(HAVE_SETPGRP)
2598
2599PyDoc_STRVAR(os_setpgrp__doc__,
2600"setpgrp($module, /)\n"
2601"--\n"
2602"\n"
2603"Make the current process the leader of its process group.");
2604
2605#define OS_SETPGRP_METHODDEF \
2606 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2607
2608static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002609os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002610
2611static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002612os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002613{
2614 return os_setpgrp_impl(module);
2615}
2616
2617#endif /* defined(HAVE_SETPGRP) */
2618
2619#if defined(HAVE_GETPPID)
2620
2621PyDoc_STRVAR(os_getppid__doc__,
2622"getppid($module, /)\n"
2623"--\n"
2624"\n"
2625"Return the parent\'s process id.\n"
2626"\n"
2627"If the parent process has already exited, Windows machines will still\n"
2628"return its id; others systems will return the id of the \'init\' process (1).");
2629
2630#define OS_GETPPID_METHODDEF \
2631 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2632
2633static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002634os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002635
2636static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002637os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002638{
2639 return os_getppid_impl(module);
2640}
2641
2642#endif /* defined(HAVE_GETPPID) */
2643
2644#if defined(HAVE_GETLOGIN)
2645
2646PyDoc_STRVAR(os_getlogin__doc__,
2647"getlogin($module, /)\n"
2648"--\n"
2649"\n"
2650"Return the actual login name.");
2651
2652#define OS_GETLOGIN_METHODDEF \
2653 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2654
2655static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002656os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657
2658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002659os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002660{
2661 return os_getlogin_impl(module);
2662}
2663
2664#endif /* defined(HAVE_GETLOGIN) */
2665
2666#if defined(HAVE_GETUID)
2667
2668PyDoc_STRVAR(os_getuid__doc__,
2669"getuid($module, /)\n"
2670"--\n"
2671"\n"
2672"Return the current process\'s user id.");
2673
2674#define OS_GETUID_METHODDEF \
2675 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2676
2677static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002678os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002679
2680static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002681os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002682{
2683 return os_getuid_impl(module);
2684}
2685
2686#endif /* defined(HAVE_GETUID) */
2687
2688#if defined(HAVE_KILL)
2689
2690PyDoc_STRVAR(os_kill__doc__,
2691"kill($module, pid, signal, /)\n"
2692"--\n"
2693"\n"
2694"Kill a process with a signal.");
2695
2696#define OS_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002697 {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002698
2699static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002700os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002701
2702static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002703os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002704{
2705 PyObject *return_value = NULL;
2706 pid_t pid;
2707 Py_ssize_t signal;
2708
Sylvain74453812017-06-10 06:51:48 +02002709 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2710 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002711 goto exit;
2712 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002713 return_value = os_kill_impl(module, pid, signal);
2714
2715exit:
2716 return return_value;
2717}
2718
2719#endif /* defined(HAVE_KILL) */
2720
2721#if defined(HAVE_KILLPG)
2722
2723PyDoc_STRVAR(os_killpg__doc__,
2724"killpg($module, pgid, signal, /)\n"
2725"--\n"
2726"\n"
2727"Kill a process group with a signal.");
2728
2729#define OS_KILLPG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002730 {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002731
2732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002733os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002734
2735static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002736os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002737{
2738 PyObject *return_value = NULL;
2739 pid_t pgid;
2740 int signal;
2741
Sylvain74453812017-06-10 06:51:48 +02002742 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2743 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002744 goto exit;
2745 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002746 return_value = os_killpg_impl(module, pgid, signal);
2747
2748exit:
2749 return return_value;
2750}
2751
2752#endif /* defined(HAVE_KILLPG) */
2753
2754#if defined(HAVE_PLOCK)
2755
2756PyDoc_STRVAR(os_plock__doc__,
2757"plock($module, op, /)\n"
2758"--\n"
2759"\n"
2760"Lock program segments into memory.\");");
2761
2762#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002763 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002764
2765static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002766os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002767
2768static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002769os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002770{
2771 PyObject *return_value = NULL;
2772 int op;
2773
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002774 if (PyFloat_Check(arg)) {
2775 PyErr_SetString(PyExc_TypeError,
2776 "integer argument expected, got float" );
2777 goto exit;
2778 }
2779 op = _PyLong_AsInt(arg);
2780 if (op == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002781 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002782 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002783 return_value = os_plock_impl(module, op);
2784
2785exit:
2786 return return_value;
2787}
2788
2789#endif /* defined(HAVE_PLOCK) */
2790
2791#if defined(HAVE_SETUID)
2792
2793PyDoc_STRVAR(os_setuid__doc__,
2794"setuid($module, uid, /)\n"
2795"--\n"
2796"\n"
2797"Set the current process\'s user id.");
2798
2799#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002800 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002801
2802static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002803os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002804
2805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002806os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002807{
2808 PyObject *return_value = NULL;
2809 uid_t uid;
2810
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002811 if (!_Py_Uid_Converter(arg, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002812 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002813 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002814 return_value = os_setuid_impl(module, uid);
2815
2816exit:
2817 return return_value;
2818}
2819
2820#endif /* defined(HAVE_SETUID) */
2821
2822#if defined(HAVE_SETEUID)
2823
2824PyDoc_STRVAR(os_seteuid__doc__,
2825"seteuid($module, euid, /)\n"
2826"--\n"
2827"\n"
2828"Set the current process\'s effective user id.");
2829
2830#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002831 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002832
2833static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002834os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002835
2836static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002837os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002838{
2839 PyObject *return_value = NULL;
2840 uid_t euid;
2841
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002842 if (!_Py_Uid_Converter(arg, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002843 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002844 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002845 return_value = os_seteuid_impl(module, euid);
2846
2847exit:
2848 return return_value;
2849}
2850
2851#endif /* defined(HAVE_SETEUID) */
2852
2853#if defined(HAVE_SETEGID)
2854
2855PyDoc_STRVAR(os_setegid__doc__,
2856"setegid($module, egid, /)\n"
2857"--\n"
2858"\n"
2859"Set the current process\'s effective group id.");
2860
2861#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002862 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002863
2864static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002865os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002866
2867static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002868os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002869{
2870 PyObject *return_value = NULL;
2871 gid_t egid;
2872
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002873 if (!_Py_Gid_Converter(arg, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002874 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002875 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002876 return_value = os_setegid_impl(module, egid);
2877
2878exit:
2879 return return_value;
2880}
2881
2882#endif /* defined(HAVE_SETEGID) */
2883
2884#if defined(HAVE_SETREUID)
2885
2886PyDoc_STRVAR(os_setreuid__doc__,
2887"setreuid($module, ruid, euid, /)\n"
2888"--\n"
2889"\n"
2890"Set the current process\'s real and effective user ids.");
2891
2892#define OS_SETREUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002893 {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002894
2895static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002896os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002897
2898static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002899os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002900{
2901 PyObject *return_value = NULL;
2902 uid_t ruid;
2903 uid_t euid;
2904
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002905 if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
2906 goto exit;
2907 }
2908 if (!_Py_Uid_Converter(args[0], &ruid)) {
2909 goto exit;
2910 }
2911 if (!_Py_Uid_Converter(args[1], &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002912 goto exit;
2913 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002914 return_value = os_setreuid_impl(module, ruid, euid);
2915
2916exit:
2917 return return_value;
2918}
2919
2920#endif /* defined(HAVE_SETREUID) */
2921
2922#if defined(HAVE_SETREGID)
2923
2924PyDoc_STRVAR(os_setregid__doc__,
2925"setregid($module, rgid, egid, /)\n"
2926"--\n"
2927"\n"
2928"Set the current process\'s real and effective group ids.");
2929
2930#define OS_SETREGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002931 {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002932
2933static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002934os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002935
2936static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002937os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002938{
2939 PyObject *return_value = NULL;
2940 gid_t rgid;
2941 gid_t egid;
2942
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002943 if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
2944 goto exit;
2945 }
2946 if (!_Py_Gid_Converter(args[0], &rgid)) {
2947 goto exit;
2948 }
2949 if (!_Py_Gid_Converter(args[1], &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002950 goto exit;
2951 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002952 return_value = os_setregid_impl(module, rgid, egid);
2953
2954exit:
2955 return return_value;
2956}
2957
2958#endif /* defined(HAVE_SETREGID) */
2959
2960#if defined(HAVE_SETGID)
2961
2962PyDoc_STRVAR(os_setgid__doc__,
2963"setgid($module, gid, /)\n"
2964"--\n"
2965"\n"
2966"Set the current process\'s group id.");
2967
2968#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002969 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002970
2971static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002972os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002973
2974static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002975os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002976{
2977 PyObject *return_value = NULL;
2978 gid_t gid;
2979
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002980 if (!_Py_Gid_Converter(arg, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002981 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002982 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002983 return_value = os_setgid_impl(module, gid);
2984
2985exit:
2986 return return_value;
2987}
2988
2989#endif /* defined(HAVE_SETGID) */
2990
2991#if defined(HAVE_SETGROUPS)
2992
2993PyDoc_STRVAR(os_setgroups__doc__,
2994"setgroups($module, groups, /)\n"
2995"--\n"
2996"\n"
2997"Set the groups of the current process to list.");
2998
2999#define OS_SETGROUPS_METHODDEF \
3000 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
3001
3002#endif /* defined(HAVE_SETGROUPS) */
3003
3004#if defined(HAVE_WAIT3)
3005
3006PyDoc_STRVAR(os_wait3__doc__,
3007"wait3($module, /, options)\n"
3008"--\n"
3009"\n"
3010"Wait for completion of a child process.\n"
3011"\n"
3012"Returns a tuple of information about the child process:\n"
3013" (pid, status, rusage)");
3014
3015#define OS_WAIT3_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003016 {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003017
3018static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003019os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003020
3021static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003022os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003023{
3024 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003025 static const char * const _keywords[] = {"options", NULL};
3026 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003027 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 &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_wait3_impl(module, options);
3034
3035exit:
3036 return return_value;
3037}
3038
3039#endif /* defined(HAVE_WAIT3) */
3040
3041#if defined(HAVE_WAIT4)
3042
3043PyDoc_STRVAR(os_wait4__doc__,
3044"wait4($module, /, pid, options)\n"
3045"--\n"
3046"\n"
3047"Wait for completion of a specific child process.\n"
3048"\n"
3049"Returns a tuple of information about the child process:\n"
3050" (pid, status, rusage)");
3051
3052#define OS_WAIT4_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003053 {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003054
3055static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003056os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003057
3058static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003059os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003060{
3061 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003062 static const char * const _keywords[] = {"pid", "options", NULL};
3063 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003064 pid_t pid;
3065 int options;
3066
Victor Stinner3e1fad62017-01-17 01:29:01 +01003067 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003068 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003069 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003070 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003071 return_value = os_wait4_impl(module, pid, options);
3072
3073exit:
3074 return return_value;
3075}
3076
3077#endif /* defined(HAVE_WAIT4) */
3078
3079#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3080
3081PyDoc_STRVAR(os_waitid__doc__,
3082"waitid($module, idtype, id, options, /)\n"
3083"--\n"
3084"\n"
3085"Returns the result of waiting for a process or processes.\n"
3086"\n"
3087" idtype\n"
3088" Must be one of be P_PID, P_PGID or P_ALL.\n"
3089" id\n"
3090" The id to wait on.\n"
3091" options\n"
3092" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3093" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3094"\n"
3095"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3096"no children in a waitable state.");
3097
3098#define OS_WAITID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003099 {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003100
3101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003102os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003103
3104static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003105os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003106{
3107 PyObject *return_value = NULL;
3108 idtype_t idtype;
3109 id_t id;
3110 int options;
3111
Sylvain74453812017-06-10 06:51:48 +02003112 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3113 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003114 goto exit;
3115 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003116 return_value = os_waitid_impl(module, idtype, id, options);
3117
3118exit:
3119 return return_value;
3120}
3121
3122#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3123
3124#if defined(HAVE_WAITPID)
3125
3126PyDoc_STRVAR(os_waitpid__doc__,
3127"waitpid($module, pid, options, /)\n"
3128"--\n"
3129"\n"
3130"Wait for completion of a given child process.\n"
3131"\n"
3132"Returns a tuple of information regarding the child process:\n"
3133" (pid, status)\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 *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003141os_waitpid_impl(PyObject *module, pid_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;
3147 pid_t pid;
3148 int options;
3149
Sylvain74453812017-06-10 06:51:48 +02003150 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "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_WAITPID) */
3161
3162#if defined(HAVE_CWAIT)
3163
3164PyDoc_STRVAR(os_waitpid__doc__,
3165"waitpid($module, pid, options, /)\n"
3166"--\n"
3167"\n"
3168"Wait for completion of a given process.\n"
3169"\n"
3170"Returns a tuple of information regarding the process:\n"
3171" (pid, status << 8)\n"
3172"\n"
3173"The options argument is ignored on Windows.");
3174
3175#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003176 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003177
3178static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003179os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003180
3181static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003182os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003183{
3184 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003185 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003186 int options;
3187
Sylvain74453812017-06-10 06:51:48 +02003188 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3189 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003190 goto exit;
3191 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003192 return_value = os_waitpid_impl(module, pid, options);
3193
3194exit:
3195 return return_value;
3196}
3197
3198#endif /* defined(HAVE_CWAIT) */
3199
3200#if defined(HAVE_WAIT)
3201
3202PyDoc_STRVAR(os_wait__doc__,
3203"wait($module, /)\n"
3204"--\n"
3205"\n"
3206"Wait for completion of a child process.\n"
3207"\n"
3208"Returns a tuple of information about the child process:\n"
3209" (pid, status)");
3210
3211#define OS_WAIT_METHODDEF \
3212 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3213
3214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003215os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003216
3217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003218os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003219{
3220 return os_wait_impl(module);
3221}
3222
3223#endif /* defined(HAVE_WAIT) */
3224
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003225#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3226
3227PyDoc_STRVAR(os_readlink__doc__,
3228"readlink($module, /, path, *, dir_fd=None)\n"
3229"--\n"
3230"\n"
3231"Return a string representing the path to which the symbolic link points.\n"
3232"\n"
3233"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3234"and path should be relative; path will then be relative to that directory.\n"
3235"\n"
3236"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3237"using it will raise a NotImplementedError.");
3238
3239#define OS_READLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003240 {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003241
3242static PyObject *
3243os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3244
3245static PyObject *
3246os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3247{
3248 PyObject *return_value = NULL;
3249 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3250 static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0};
3251 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3252 int dir_fd = DEFAULT_DIR_FD;
3253
3254 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3255 path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3256 goto exit;
3257 }
3258 return_value = os_readlink_impl(module, &path, dir_fd);
3259
3260exit:
3261 /* Cleanup for path */
3262 path_cleanup(&path);
3263
3264 return return_value;
3265}
3266
3267#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
3268
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003269#if defined(HAVE_SYMLINK)
3270
3271PyDoc_STRVAR(os_symlink__doc__,
3272"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3273"--\n"
3274"\n"
3275"Create a symbolic link pointing to src named dst.\n"
3276"\n"
3277"target_is_directory is required on Windows if the target is to be\n"
3278" interpreted as a directory. (On Windows, symlink requires\n"
3279" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3280" target_is_directory is ignored on non-Windows platforms.\n"
3281"\n"
3282"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3283" and path should be relative; path will then be relative to that directory.\n"
3284"dir_fd may not be implemented on your platform.\n"
3285" If it is unavailable, using it will raise a NotImplementedError.");
3286
3287#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003288 {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003289
3290static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003291os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003292 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003293
3294static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003295os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003296{
3297 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003298 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3299 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003300 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3301 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3302 int target_is_directory = 0;
3303 int dir_fd = DEFAULT_DIR_FD;
3304
Victor Stinner3e1fad62017-01-17 01:29:01 +01003305 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003306 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003307 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003308 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003309 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3310
3311exit:
3312 /* Cleanup for src */
3313 path_cleanup(&src);
3314 /* Cleanup for dst */
3315 path_cleanup(&dst);
3316
3317 return return_value;
3318}
3319
3320#endif /* defined(HAVE_SYMLINK) */
3321
3322#if defined(HAVE_TIMES)
3323
3324PyDoc_STRVAR(os_times__doc__,
3325"times($module, /)\n"
3326"--\n"
3327"\n"
3328"Return a collection containing process timing information.\n"
3329"\n"
3330"The object returned behaves like a named tuple with these fields:\n"
3331" (utime, stime, cutime, cstime, elapsed_time)\n"
3332"All fields are floating point numbers.");
3333
3334#define OS_TIMES_METHODDEF \
3335 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3336
3337static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003338os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003339
3340static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003341os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003342{
3343 return os_times_impl(module);
3344}
3345
3346#endif /* defined(HAVE_TIMES) */
3347
3348#if defined(HAVE_GETSID)
3349
3350PyDoc_STRVAR(os_getsid__doc__,
3351"getsid($module, pid, /)\n"
3352"--\n"
3353"\n"
3354"Call the system call getsid(pid) and return the result.");
3355
3356#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003357 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003358
3359static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003360os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003361
3362static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003363os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003364{
3365 PyObject *return_value = NULL;
3366 pid_t pid;
3367
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003368 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003369 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003370 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003371 return_value = os_getsid_impl(module, pid);
3372
3373exit:
3374 return return_value;
3375}
3376
3377#endif /* defined(HAVE_GETSID) */
3378
3379#if defined(HAVE_SETSID)
3380
3381PyDoc_STRVAR(os_setsid__doc__,
3382"setsid($module, /)\n"
3383"--\n"
3384"\n"
3385"Call the system call setsid().");
3386
3387#define OS_SETSID_METHODDEF \
3388 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3389
3390static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003391os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003392
3393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003394os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003395{
3396 return os_setsid_impl(module);
3397}
3398
3399#endif /* defined(HAVE_SETSID) */
3400
3401#if defined(HAVE_SETPGID)
3402
3403PyDoc_STRVAR(os_setpgid__doc__,
3404"setpgid($module, pid, pgrp, /)\n"
3405"--\n"
3406"\n"
3407"Call the system call setpgid(pid, pgrp).");
3408
3409#define OS_SETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003410 {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411
3412static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003413os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003414
3415static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003416os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003417{
3418 PyObject *return_value = NULL;
3419 pid_t pid;
3420 pid_t pgrp;
3421
Sylvain74453812017-06-10 06:51:48 +02003422 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3423 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003424 goto exit;
3425 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003426 return_value = os_setpgid_impl(module, pid, pgrp);
3427
3428exit:
3429 return return_value;
3430}
3431
3432#endif /* defined(HAVE_SETPGID) */
3433
3434#if defined(HAVE_TCGETPGRP)
3435
3436PyDoc_STRVAR(os_tcgetpgrp__doc__,
3437"tcgetpgrp($module, fd, /)\n"
3438"--\n"
3439"\n"
3440"Return the process group associated with the terminal specified by fd.");
3441
3442#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003443 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003444
3445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003446os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003447
3448static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003449os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003450{
3451 PyObject *return_value = NULL;
3452 int fd;
3453
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003454 if (PyFloat_Check(arg)) {
3455 PyErr_SetString(PyExc_TypeError,
3456 "integer argument expected, got float" );
3457 goto exit;
3458 }
3459 fd = _PyLong_AsInt(arg);
3460 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003461 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003462 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003463 return_value = os_tcgetpgrp_impl(module, fd);
3464
3465exit:
3466 return return_value;
3467}
3468
3469#endif /* defined(HAVE_TCGETPGRP) */
3470
3471#if defined(HAVE_TCSETPGRP)
3472
3473PyDoc_STRVAR(os_tcsetpgrp__doc__,
3474"tcsetpgrp($module, fd, pgid, /)\n"
3475"--\n"
3476"\n"
3477"Set the process group associated with the terminal specified by fd.");
3478
3479#define OS_TCSETPGRP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003480 {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003481
3482static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003483os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003484
3485static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003486os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003487{
3488 PyObject *return_value = NULL;
3489 int fd;
3490 pid_t pgid;
3491
Sylvain74453812017-06-10 06:51:48 +02003492 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3493 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003494 goto exit;
3495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003496 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3497
3498exit:
3499 return return_value;
3500}
3501
3502#endif /* defined(HAVE_TCSETPGRP) */
3503
3504PyDoc_STRVAR(os_open__doc__,
3505"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3506"--\n"
3507"\n"
3508"Open a file for low level IO. Returns a file descriptor (integer).\n"
3509"\n"
3510"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3511" and path should be relative; path will then be relative to that directory.\n"
3512"dir_fd may not be implemented on your platform.\n"
3513" If it is unavailable, using it will raise a NotImplementedError.");
3514
3515#define OS_OPEN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003516 {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003517
3518static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003519os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003520
3521static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003522os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003523{
3524 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003525 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3526 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003527 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3528 int flags;
3529 int mode = 511;
3530 int dir_fd = DEFAULT_DIR_FD;
3531 int _return_value;
3532
Victor Stinner3e1fad62017-01-17 01:29:01 +01003533 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003534 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003535 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003536 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003537 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003538 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003539 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003540 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003541 return_value = PyLong_FromLong((long)_return_value);
3542
3543exit:
3544 /* Cleanup for path */
3545 path_cleanup(&path);
3546
3547 return return_value;
3548}
3549
3550PyDoc_STRVAR(os_close__doc__,
3551"close($module, /, fd)\n"
3552"--\n"
3553"\n"
3554"Close a file descriptor.");
3555
3556#define OS_CLOSE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003557 {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003558
3559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003560os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003561
3562static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003563os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003564{
3565 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003566 static const char * const _keywords[] = {"fd", NULL};
3567 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003568 int fd;
3569
Victor Stinner3e1fad62017-01-17 01:29:01 +01003570 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003571 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003572 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003573 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003574 return_value = os_close_impl(module, fd);
3575
3576exit:
3577 return return_value;
3578}
3579
3580PyDoc_STRVAR(os_closerange__doc__,
3581"closerange($module, fd_low, fd_high, /)\n"
3582"--\n"
3583"\n"
3584"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3585
3586#define OS_CLOSERANGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003587 {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003588
3589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003590os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003591
3592static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003593os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003594{
3595 PyObject *return_value = NULL;
3596 int fd_low;
3597 int fd_high;
3598
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003599 if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
3600 goto exit;
3601 }
3602 if (PyFloat_Check(args[0])) {
3603 PyErr_SetString(PyExc_TypeError,
3604 "integer argument expected, got float" );
3605 goto exit;
3606 }
3607 fd_low = _PyLong_AsInt(args[0]);
3608 if (fd_low == -1 && PyErr_Occurred()) {
3609 goto exit;
3610 }
3611 if (PyFloat_Check(args[1])) {
3612 PyErr_SetString(PyExc_TypeError,
3613 "integer argument expected, got float" );
3614 goto exit;
3615 }
3616 fd_high = _PyLong_AsInt(args[1]);
3617 if (fd_high == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003618 goto exit;
3619 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003620 return_value = os_closerange_impl(module, fd_low, fd_high);
3621
3622exit:
3623 return return_value;
3624}
3625
3626PyDoc_STRVAR(os_dup__doc__,
3627"dup($module, fd, /)\n"
3628"--\n"
3629"\n"
3630"Return a duplicate of a file descriptor.");
3631
3632#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003633 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003634
3635static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003636os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003637
3638static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003639os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003640{
3641 PyObject *return_value = NULL;
3642 int fd;
3643 int _return_value;
3644
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003645 if (PyFloat_Check(arg)) {
3646 PyErr_SetString(PyExc_TypeError,
3647 "integer argument expected, got float" );
3648 goto exit;
3649 }
3650 fd = _PyLong_AsInt(arg);
3651 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003652 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003653 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003654 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003655 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003656 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003657 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003658 return_value = PyLong_FromLong((long)_return_value);
3659
3660exit:
3661 return return_value;
3662}
3663
3664PyDoc_STRVAR(os_dup2__doc__,
3665"dup2($module, /, fd, fd2, inheritable=True)\n"
3666"--\n"
3667"\n"
3668"Duplicate file descriptor.");
3669
3670#define OS_DUP2_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003671 {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003672
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003673static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003674os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003675
3676static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003677os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003678{
3679 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003680 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3681 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003682 int fd;
3683 int fd2;
3684 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003685 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003686
Victor Stinner3e1fad62017-01-17 01:29:01 +01003687 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003688 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003689 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003690 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003691 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3692 if ((_return_value == -1) && PyErr_Occurred()) {
3693 goto exit;
3694 }
3695 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003696
3697exit:
3698 return return_value;
3699}
3700
3701#if defined(HAVE_LOCKF)
3702
3703PyDoc_STRVAR(os_lockf__doc__,
3704"lockf($module, fd, command, length, /)\n"
3705"--\n"
3706"\n"
3707"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3708"\n"
3709" fd\n"
3710" An open file descriptor.\n"
3711" command\n"
3712" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3713" length\n"
3714" The number of bytes to lock, starting at the current position.");
3715
3716#define OS_LOCKF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003717 {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003718
3719static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003720os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003721
3722static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003723os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003724{
3725 PyObject *return_value = NULL;
3726 int fd;
3727 int command;
3728 Py_off_t length;
3729
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003730 if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
3731 goto exit;
3732 }
3733 if (PyFloat_Check(args[0])) {
3734 PyErr_SetString(PyExc_TypeError,
3735 "integer argument expected, got float" );
3736 goto exit;
3737 }
3738 fd = _PyLong_AsInt(args[0]);
3739 if (fd == -1 && PyErr_Occurred()) {
3740 goto exit;
3741 }
3742 if (PyFloat_Check(args[1])) {
3743 PyErr_SetString(PyExc_TypeError,
3744 "integer argument expected, got float" );
3745 goto exit;
3746 }
3747 command = _PyLong_AsInt(args[1]);
3748 if (command == -1 && PyErr_Occurred()) {
3749 goto exit;
3750 }
3751 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003752 goto exit;
3753 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003754 return_value = os_lockf_impl(module, fd, command, length);
3755
3756exit:
3757 return return_value;
3758}
3759
3760#endif /* defined(HAVE_LOCKF) */
3761
3762PyDoc_STRVAR(os_lseek__doc__,
3763"lseek($module, fd, position, how, /)\n"
3764"--\n"
3765"\n"
3766"Set the position of a file descriptor. Return the new position.\n"
3767"\n"
3768"Return the new cursor position in number of bytes\n"
3769"relative to the beginning of the file.");
3770
3771#define OS_LSEEK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003772 {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003773
3774static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003775os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003776
3777static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003778os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003779{
3780 PyObject *return_value = NULL;
3781 int fd;
3782 Py_off_t position;
3783 int how;
3784 Py_off_t _return_value;
3785
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003786 if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
3787 goto exit;
3788 }
3789 if (PyFloat_Check(args[0])) {
3790 PyErr_SetString(PyExc_TypeError,
3791 "integer argument expected, got float" );
3792 goto exit;
3793 }
3794 fd = _PyLong_AsInt(args[0]);
3795 if (fd == -1 && PyErr_Occurred()) {
3796 goto exit;
3797 }
3798 if (!Py_off_t_converter(args[1], &position)) {
3799 goto exit;
3800 }
3801 if (PyFloat_Check(args[2])) {
3802 PyErr_SetString(PyExc_TypeError,
3803 "integer argument expected, got float" );
3804 goto exit;
3805 }
3806 how = _PyLong_AsInt(args[2]);
3807 if (how == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003808 goto exit;
3809 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003810 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003811 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003812 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003813 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003814 return_value = PyLong_FromPy_off_t(_return_value);
3815
3816exit:
3817 return return_value;
3818}
3819
3820PyDoc_STRVAR(os_read__doc__,
3821"read($module, fd, length, /)\n"
3822"--\n"
3823"\n"
3824"Read from a file descriptor. Returns a bytes object.");
3825
3826#define OS_READ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003827 {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003828
3829static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003830os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003831
3832static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003833os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003834{
3835 PyObject *return_value = NULL;
3836 int fd;
3837 Py_ssize_t length;
3838
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003839 if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003840 goto exit;
3841 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003842 if (PyFloat_Check(args[0])) {
3843 PyErr_SetString(PyExc_TypeError,
3844 "integer argument expected, got float" );
3845 goto exit;
3846 }
3847 fd = _PyLong_AsInt(args[0]);
3848 if (fd == -1 && PyErr_Occurred()) {
3849 goto exit;
3850 }
3851 if (PyFloat_Check(args[1])) {
3852 PyErr_SetString(PyExc_TypeError,
3853 "integer argument expected, got float" );
3854 goto exit;
3855 }
3856 {
3857 Py_ssize_t ival = -1;
3858 PyObject *iobj = PyNumber_Index(args[1]);
3859 if (iobj != NULL) {
3860 ival = PyLong_AsSsize_t(iobj);
3861 Py_DECREF(iobj);
3862 }
3863 if (ival == -1 && PyErr_Occurred()) {
3864 goto exit;
3865 }
3866 length = ival;
3867 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003868 return_value = os_read_impl(module, fd, length);
3869
3870exit:
3871 return return_value;
3872}
3873
3874#if defined(HAVE_READV)
3875
3876PyDoc_STRVAR(os_readv__doc__,
3877"readv($module, fd, buffers, /)\n"
3878"--\n"
3879"\n"
3880"Read from a file descriptor fd into an iterable of buffers.\n"
3881"\n"
3882"The buffers should be mutable buffers accepting bytes.\n"
3883"readv will transfer data into each buffer until it is full\n"
3884"and then move on to the next buffer in the sequence to hold\n"
3885"the rest of the data.\n"
3886"\n"
3887"readv returns the total number of bytes read,\n"
3888"which may be less than the total capacity of all the buffers.");
3889
3890#define OS_READV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003891 {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003892
3893static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003894os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003895
3896static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003897os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003898{
3899 PyObject *return_value = NULL;
3900 int fd;
3901 PyObject *buffers;
3902 Py_ssize_t _return_value;
3903
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003904 if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003905 goto exit;
3906 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003907 if (PyFloat_Check(args[0])) {
3908 PyErr_SetString(PyExc_TypeError,
3909 "integer argument expected, got float" );
3910 goto exit;
3911 }
3912 fd = _PyLong_AsInt(args[0]);
3913 if (fd == -1 && PyErr_Occurred()) {
3914 goto exit;
3915 }
3916 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003917 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003918 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003919 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003920 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003921 return_value = PyLong_FromSsize_t(_return_value);
3922
3923exit:
3924 return return_value;
3925}
3926
3927#endif /* defined(HAVE_READV) */
3928
3929#if defined(HAVE_PREAD)
3930
3931PyDoc_STRVAR(os_pread__doc__,
3932"pread($module, fd, length, offset, /)\n"
3933"--\n"
3934"\n"
3935"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3936"\n"
3937"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3938"the beginning of the file. The file offset remains unchanged.");
3939
3940#define OS_PREAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003941 {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003942
3943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003944os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003945
3946static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003947os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003948{
3949 PyObject *return_value = NULL;
3950 int fd;
3951 int length;
3952 Py_off_t offset;
3953
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003954 if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
3955 goto exit;
3956 }
3957 if (PyFloat_Check(args[0])) {
3958 PyErr_SetString(PyExc_TypeError,
3959 "integer argument expected, got float" );
3960 goto exit;
3961 }
3962 fd = _PyLong_AsInt(args[0]);
3963 if (fd == -1 && PyErr_Occurred()) {
3964 goto exit;
3965 }
3966 if (PyFloat_Check(args[1])) {
3967 PyErr_SetString(PyExc_TypeError,
3968 "integer argument expected, got float" );
3969 goto exit;
3970 }
3971 length = _PyLong_AsInt(args[1]);
3972 if (length == -1 && PyErr_Occurred()) {
3973 goto exit;
3974 }
3975 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003976 goto exit;
3977 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003978 return_value = os_pread_impl(module, fd, length, offset);
3979
3980exit:
3981 return return_value;
3982}
3983
3984#endif /* defined(HAVE_PREAD) */
3985
Pablo Galindo4defba32018-01-27 16:16:37 +00003986#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
3987
3988PyDoc_STRVAR(os_preadv__doc__,
3989"preadv($module, fd, buffers, offset, flags=0, /)\n"
3990"--\n"
3991"\n"
3992"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
3993"\n"
3994"Combines the functionality of readv() and pread(). As readv(), it will\n"
3995"transfer data into each buffer until it is full and then move on to the next\n"
3996"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3997"specifies the file offset at which the input operation is to be performed. It\n"
3998"will return the total number of bytes read (which can be less than the total\n"
3999"capacity of all the objects).\n"
4000"\n"
4001"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4002"\n"
4003"- RWF_HIPRI\n"
4004"- RWF_NOWAIT\n"
4005"\n"
4006"Using non-zero flags requires Linux 4.6 or newer.");
4007
4008#define OS_PREADV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004009 {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004010
4011static Py_ssize_t
4012os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4013 int flags);
4014
4015static PyObject *
4016os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4017{
4018 PyObject *return_value = NULL;
4019 int fd;
4020 PyObject *buffers;
4021 Py_off_t offset;
4022 int flags = 0;
4023 Py_ssize_t _return_value;
4024
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004025 if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00004026 goto exit;
4027 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004028 if (PyFloat_Check(args[0])) {
4029 PyErr_SetString(PyExc_TypeError,
4030 "integer argument expected, got float" );
4031 goto exit;
4032 }
4033 fd = _PyLong_AsInt(args[0]);
4034 if (fd == -1 && PyErr_Occurred()) {
4035 goto exit;
4036 }
4037 buffers = args[1];
4038 if (!Py_off_t_converter(args[2], &offset)) {
4039 goto exit;
4040 }
4041 if (nargs < 4) {
4042 goto skip_optional;
4043 }
4044 if (PyFloat_Check(args[3])) {
4045 PyErr_SetString(PyExc_TypeError,
4046 "integer argument expected, got float" );
4047 goto exit;
4048 }
4049 flags = _PyLong_AsInt(args[3]);
4050 if (flags == -1 && PyErr_Occurred()) {
4051 goto exit;
4052 }
4053skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00004054 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
4055 if ((_return_value == -1) && PyErr_Occurred()) {
4056 goto exit;
4057 }
4058 return_value = PyLong_FromSsize_t(_return_value);
4059
4060exit:
4061 return return_value;
4062}
4063
4064#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
4065
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004066PyDoc_STRVAR(os_write__doc__,
4067"write($module, fd, data, /)\n"
4068"--\n"
4069"\n"
4070"Write a bytes object to a file descriptor.");
4071
4072#define OS_WRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004073 {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074
4075static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004076os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004077
4078static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004079os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004080{
4081 PyObject *return_value = NULL;
4082 int fd;
4083 Py_buffer data = {NULL, NULL};
4084 Py_ssize_t _return_value;
4085
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004086 if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
4087 goto exit;
4088 }
4089 if (PyFloat_Check(args[0])) {
4090 PyErr_SetString(PyExc_TypeError,
4091 "integer argument expected, got float" );
4092 goto exit;
4093 }
4094 fd = _PyLong_AsInt(args[0]);
4095 if (fd == -1 && PyErr_Occurred()) {
4096 goto exit;
4097 }
4098 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
4099 goto exit;
4100 }
4101 if (!PyBuffer_IsContiguous(&data, 'C')) {
4102 _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]);
Victor Stinner259f0e42017-01-17 01:35:17 +01004103 goto exit;
4104 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004105 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004106 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004107 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004108 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004109 return_value = PyLong_FromSsize_t(_return_value);
4110
4111exit:
4112 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004113 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004114 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004115 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004116
4117 return return_value;
4118}
4119
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004120#if defined(__APPLE__)
4121
4122PyDoc_STRVAR(os__fcopyfile__doc__,
4123"_fcopyfile($module, infd, outfd, flags, /)\n"
4124"--\n"
4125"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07004126"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004127
4128#define OS__FCOPYFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004129 {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004130
4131static PyObject *
4132os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
4133
4134static PyObject *
4135os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4136{
4137 PyObject *return_value = NULL;
4138 int infd;
4139 int outfd;
4140 int flags;
4141
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004142 if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
4143 goto exit;
4144 }
4145 if (PyFloat_Check(args[0])) {
4146 PyErr_SetString(PyExc_TypeError,
4147 "integer argument expected, got float" );
4148 goto exit;
4149 }
4150 infd = _PyLong_AsInt(args[0]);
4151 if (infd == -1 && PyErr_Occurred()) {
4152 goto exit;
4153 }
4154 if (PyFloat_Check(args[1])) {
4155 PyErr_SetString(PyExc_TypeError,
4156 "integer argument expected, got float" );
4157 goto exit;
4158 }
4159 outfd = _PyLong_AsInt(args[1]);
4160 if (outfd == -1 && PyErr_Occurred()) {
4161 goto exit;
4162 }
4163 if (PyFloat_Check(args[2])) {
4164 PyErr_SetString(PyExc_TypeError,
4165 "integer argument expected, got float" );
4166 goto exit;
4167 }
4168 flags = _PyLong_AsInt(args[2]);
4169 if (flags == -1 && PyErr_Occurred()) {
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004170 goto exit;
4171 }
4172 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
4173
4174exit:
4175 return return_value;
4176}
4177
4178#endif /* defined(__APPLE__) */
4179
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004180PyDoc_STRVAR(os_fstat__doc__,
4181"fstat($module, /, fd)\n"
4182"--\n"
4183"\n"
4184"Perform a stat system call on the given file descriptor.\n"
4185"\n"
4186"Like stat(), but for an open file descriptor.\n"
4187"Equivalent to os.stat(fd).");
4188
4189#define OS_FSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004190 {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004191
4192static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004193os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004194
4195static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004196os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004197{
4198 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004199 static const char * const _keywords[] = {"fd", NULL};
4200 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004201 int fd;
4202
Victor Stinner3e1fad62017-01-17 01:29:01 +01004203 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004204 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004205 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004206 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004207 return_value = os_fstat_impl(module, fd);
4208
4209exit:
4210 return return_value;
4211}
4212
4213PyDoc_STRVAR(os_isatty__doc__,
4214"isatty($module, fd, /)\n"
4215"--\n"
4216"\n"
4217"Return True if the fd is connected to a terminal.\n"
4218"\n"
4219"Return True if the file descriptor is an open file descriptor\n"
4220"connected to the slave end of a terminal.");
4221
4222#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004223 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004224
4225static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004226os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004227
4228static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004229os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004230{
4231 PyObject *return_value = NULL;
4232 int fd;
4233 int _return_value;
4234
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004235 if (PyFloat_Check(arg)) {
4236 PyErr_SetString(PyExc_TypeError,
4237 "integer argument expected, got float" );
4238 goto exit;
4239 }
4240 fd = _PyLong_AsInt(arg);
4241 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004242 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004243 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004244 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004245 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004246 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004247 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004248 return_value = PyBool_FromLong((long)_return_value);
4249
4250exit:
4251 return return_value;
4252}
4253
4254#if defined(HAVE_PIPE)
4255
4256PyDoc_STRVAR(os_pipe__doc__,
4257"pipe($module, /)\n"
4258"--\n"
4259"\n"
4260"Create a pipe.\n"
4261"\n"
4262"Returns a tuple of two file descriptors:\n"
4263" (read_fd, write_fd)");
4264
4265#define OS_PIPE_METHODDEF \
4266 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
4267
4268static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004269os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004270
4271static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004272os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004273{
4274 return os_pipe_impl(module);
4275}
4276
4277#endif /* defined(HAVE_PIPE) */
4278
4279#if defined(HAVE_PIPE2)
4280
4281PyDoc_STRVAR(os_pipe2__doc__,
4282"pipe2($module, flags, /)\n"
4283"--\n"
4284"\n"
4285"Create a pipe with flags set atomically.\n"
4286"\n"
4287"Returns a tuple of two file descriptors:\n"
4288" (read_fd, write_fd)\n"
4289"\n"
4290"flags can be constructed by ORing together one or more of these values:\n"
4291"O_NONBLOCK, O_CLOEXEC.");
4292
4293#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004294 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004295
4296static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004297os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004298
4299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004300os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004301{
4302 PyObject *return_value = NULL;
4303 int flags;
4304
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004305 if (PyFloat_Check(arg)) {
4306 PyErr_SetString(PyExc_TypeError,
4307 "integer argument expected, got float" );
4308 goto exit;
4309 }
4310 flags = _PyLong_AsInt(arg);
4311 if (flags == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004312 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004313 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004314 return_value = os_pipe2_impl(module, flags);
4315
4316exit:
4317 return return_value;
4318}
4319
4320#endif /* defined(HAVE_PIPE2) */
4321
4322#if defined(HAVE_WRITEV)
4323
4324PyDoc_STRVAR(os_writev__doc__,
4325"writev($module, fd, buffers, /)\n"
4326"--\n"
4327"\n"
4328"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4329"\n"
4330"Returns the total number of bytes written.\n"
4331"buffers must be a sequence of bytes-like objects.");
4332
4333#define OS_WRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004334 {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004335
4336static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004337os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004338
4339static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004340os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004341{
4342 PyObject *return_value = NULL;
4343 int fd;
4344 PyObject *buffers;
4345 Py_ssize_t _return_value;
4346
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004347 if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004348 goto exit;
4349 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004350 if (PyFloat_Check(args[0])) {
4351 PyErr_SetString(PyExc_TypeError,
4352 "integer argument expected, got float" );
4353 goto exit;
4354 }
4355 fd = _PyLong_AsInt(args[0]);
4356 if (fd == -1 && PyErr_Occurred()) {
4357 goto exit;
4358 }
4359 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004360 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004361 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004363 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364 return_value = PyLong_FromSsize_t(_return_value);
4365
4366exit:
4367 return return_value;
4368}
4369
4370#endif /* defined(HAVE_WRITEV) */
4371
4372#if defined(HAVE_PWRITE)
4373
4374PyDoc_STRVAR(os_pwrite__doc__,
4375"pwrite($module, fd, buffer, offset, /)\n"
4376"--\n"
4377"\n"
4378"Write bytes to a file descriptor starting at a particular offset.\n"
4379"\n"
4380"Write buffer to fd, starting at offset bytes from the beginning of\n"
4381"the file. Returns the number of bytes writte. Does not change the\n"
4382"current file offset.");
4383
4384#define OS_PWRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004385 {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004386
4387static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004388os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004389
4390static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004391os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004392{
4393 PyObject *return_value = NULL;
4394 int fd;
4395 Py_buffer buffer = {NULL, NULL};
4396 Py_off_t offset;
4397 Py_ssize_t _return_value;
4398
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004399 if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
4400 goto exit;
4401 }
4402 if (PyFloat_Check(args[0])) {
4403 PyErr_SetString(PyExc_TypeError,
4404 "integer argument expected, got float" );
4405 goto exit;
4406 }
4407 fd = _PyLong_AsInt(args[0]);
4408 if (fd == -1 && PyErr_Occurred()) {
4409 goto exit;
4410 }
4411 if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
4412 goto exit;
4413 }
4414 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
4415 _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]);
4416 goto exit;
4417 }
4418 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004419 goto exit;
4420 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004421 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004422 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004423 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004424 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004425 return_value = PyLong_FromSsize_t(_return_value);
4426
4427exit:
4428 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004429 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004430 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004431 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004432
4433 return return_value;
4434}
4435
4436#endif /* defined(HAVE_PWRITE) */
4437
Pablo Galindo4defba32018-01-27 16:16:37 +00004438#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4439
4440PyDoc_STRVAR(os_pwritev__doc__,
4441"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4442"--\n"
4443"\n"
4444"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4445"\n"
4446"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4447"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4448"buffer is written before proceeding to second, and so on. The operating system may\n"
4449"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4450"This function writes the contents of each object to the file descriptor and returns\n"
4451"the total number of bytes written.\n"
4452"\n"
4453"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4454"\n"
4455"- RWF_DSYNC\n"
4456"- RWF_SYNC\n"
4457"\n"
4458"Using non-zero flags requires Linux 4.7 or newer.");
4459
4460#define OS_PWRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004461 {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004462
4463static Py_ssize_t
4464os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4465 int flags);
4466
4467static PyObject *
4468os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4469{
4470 PyObject *return_value = NULL;
4471 int fd;
4472 PyObject *buffers;
4473 Py_off_t offset;
4474 int flags = 0;
4475 Py_ssize_t _return_value;
4476
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004477 if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00004478 goto exit;
4479 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004480 if (PyFloat_Check(args[0])) {
4481 PyErr_SetString(PyExc_TypeError,
4482 "integer argument expected, got float" );
4483 goto exit;
4484 }
4485 fd = _PyLong_AsInt(args[0]);
4486 if (fd == -1 && PyErr_Occurred()) {
4487 goto exit;
4488 }
4489 buffers = args[1];
4490 if (!Py_off_t_converter(args[2], &offset)) {
4491 goto exit;
4492 }
4493 if (nargs < 4) {
4494 goto skip_optional;
4495 }
4496 if (PyFloat_Check(args[3])) {
4497 PyErr_SetString(PyExc_TypeError,
4498 "integer argument expected, got float" );
4499 goto exit;
4500 }
4501 flags = _PyLong_AsInt(args[3]);
4502 if (flags == -1 && PyErr_Occurred()) {
4503 goto exit;
4504 }
4505skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00004506 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4507 if ((_return_value == -1) && PyErr_Occurred()) {
4508 goto exit;
4509 }
4510 return_value = PyLong_FromSsize_t(_return_value);
4511
4512exit:
4513 return return_value;
4514}
4515
4516#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4517
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004518#if defined(HAVE_MKFIFO)
4519
4520PyDoc_STRVAR(os_mkfifo__doc__,
4521"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4522"--\n"
4523"\n"
4524"Create a \"fifo\" (a POSIX named pipe).\n"
4525"\n"
4526"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4527" and path should be relative; path will then be relative to that directory.\n"
4528"dir_fd may not be implemented on your platform.\n"
4529" If it is unavailable, using it will raise a NotImplementedError.");
4530
4531#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004532 {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004533
4534static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004535os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004536
4537static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004538os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004539{
4540 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004541 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4542 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004543 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4544 int mode = 438;
4545 int dir_fd = DEFAULT_DIR_FD;
4546
Victor Stinner3e1fad62017-01-17 01:29:01 +01004547 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004548 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004549 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004550 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004551 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4552
4553exit:
4554 /* Cleanup for path */
4555 path_cleanup(&path);
4556
4557 return return_value;
4558}
4559
4560#endif /* defined(HAVE_MKFIFO) */
4561
4562#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4563
4564PyDoc_STRVAR(os_mknod__doc__,
4565"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4566"--\n"
4567"\n"
4568"Create a node in the file system.\n"
4569"\n"
4570"Create a node in the file system (file, device special file or named pipe)\n"
4571"at path. mode specifies both the permissions to use and the\n"
4572"type of node to be created, being combined (bitwise OR) with one of\n"
4573"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4574"device defines the newly created device special file (probably using\n"
4575"os.makedev()). Otherwise device is ignored.\n"
4576"\n"
4577"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4578" and path should be relative; path will then be relative to that directory.\n"
4579"dir_fd may not be implemented on your platform.\n"
4580" If it is unavailable, using it will raise a NotImplementedError.");
4581
4582#define OS_MKNOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004583 {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004584
4585static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004586os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004587 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004588
4589static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004590os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004591{
4592 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004593 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4594 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004595 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4596 int mode = 384;
4597 dev_t device = 0;
4598 int dir_fd = DEFAULT_DIR_FD;
4599
Victor Stinner3e1fad62017-01-17 01:29:01 +01004600 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004601 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004602 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004603 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004604 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4605
4606exit:
4607 /* Cleanup for path */
4608 path_cleanup(&path);
4609
4610 return return_value;
4611}
4612
4613#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4614
4615#if defined(HAVE_DEVICE_MACROS)
4616
4617PyDoc_STRVAR(os_major__doc__,
4618"major($module, device, /)\n"
4619"--\n"
4620"\n"
4621"Extracts a device major number from a raw device number.");
4622
4623#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004624 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004625
4626static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004627os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004628
4629static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004630os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004631{
4632 PyObject *return_value = NULL;
4633 dev_t device;
4634 unsigned int _return_value;
4635
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004636 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004637 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004638 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004639 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004640 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004641 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004643 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4644
4645exit:
4646 return return_value;
4647}
4648
4649#endif /* defined(HAVE_DEVICE_MACROS) */
4650
4651#if defined(HAVE_DEVICE_MACROS)
4652
4653PyDoc_STRVAR(os_minor__doc__,
4654"minor($module, device, /)\n"
4655"--\n"
4656"\n"
4657"Extracts a device minor number from a raw device number.");
4658
4659#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004660 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004661
4662static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004663os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004664
4665static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004666os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004667{
4668 PyObject *return_value = NULL;
4669 dev_t device;
4670 unsigned int _return_value;
4671
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004672 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004673 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004674 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004675 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004676 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004677 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004678 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004679 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4680
4681exit:
4682 return return_value;
4683}
4684
4685#endif /* defined(HAVE_DEVICE_MACROS) */
4686
4687#if defined(HAVE_DEVICE_MACROS)
4688
4689PyDoc_STRVAR(os_makedev__doc__,
4690"makedev($module, major, minor, /)\n"
4691"--\n"
4692"\n"
4693"Composes a raw device number from the major and minor device numbers.");
4694
4695#define OS_MAKEDEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004696 {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004697
4698static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004699os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004700
4701static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004702os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004703{
4704 PyObject *return_value = NULL;
4705 int major;
4706 int minor;
4707 dev_t _return_value;
4708
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004709 if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
4710 goto exit;
4711 }
4712 if (PyFloat_Check(args[0])) {
4713 PyErr_SetString(PyExc_TypeError,
4714 "integer argument expected, got float" );
4715 goto exit;
4716 }
4717 major = _PyLong_AsInt(args[0]);
4718 if (major == -1 && PyErr_Occurred()) {
4719 goto exit;
4720 }
4721 if (PyFloat_Check(args[1])) {
4722 PyErr_SetString(PyExc_TypeError,
4723 "integer argument expected, got float" );
4724 goto exit;
4725 }
4726 minor = _PyLong_AsInt(args[1]);
4727 if (minor == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004728 goto exit;
4729 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004730 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004731 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004732 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004733 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004734 return_value = _PyLong_FromDev(_return_value);
4735
4736exit:
4737 return return_value;
4738}
4739
4740#endif /* defined(HAVE_DEVICE_MACROS) */
4741
Steve Dowerf7377032015-04-12 15:44:54 -04004742#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004743
4744PyDoc_STRVAR(os_ftruncate__doc__,
4745"ftruncate($module, fd, length, /)\n"
4746"--\n"
4747"\n"
4748"Truncate a file, specified by file descriptor, to a specific length.");
4749
4750#define OS_FTRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004751 {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004752
4753static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004754os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004755
4756static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004757os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004758{
4759 PyObject *return_value = NULL;
4760 int fd;
4761 Py_off_t length;
4762
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004763 if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
4764 goto exit;
4765 }
4766 if (PyFloat_Check(args[0])) {
4767 PyErr_SetString(PyExc_TypeError,
4768 "integer argument expected, got float" );
4769 goto exit;
4770 }
4771 fd = _PyLong_AsInt(args[0]);
4772 if (fd == -1 && PyErr_Occurred()) {
4773 goto exit;
4774 }
4775 if (!Py_off_t_converter(args[1], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004776 goto exit;
4777 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004778 return_value = os_ftruncate_impl(module, fd, length);
4779
4780exit:
4781 return return_value;
4782}
4783
Steve Dowerf7377032015-04-12 15:44:54 -04004784#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004785
Steve Dowerf7377032015-04-12 15:44:54 -04004786#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004787
4788PyDoc_STRVAR(os_truncate__doc__,
4789"truncate($module, /, path, length)\n"
4790"--\n"
4791"\n"
4792"Truncate a file, specified by path, to a specific length.\n"
4793"\n"
4794"On some platforms, path may also be specified as an open file descriptor.\n"
4795" If this functionality is unavailable, using it raises an exception.");
4796
4797#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004798 {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004799
4800static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004801os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004802
4803static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004804os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004805{
4806 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004807 static const char * const _keywords[] = {"path", "length", NULL};
4808 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004809 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4810 Py_off_t length;
4811
Victor Stinner3e1fad62017-01-17 01:29:01 +01004812 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004813 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004814 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004815 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004816 return_value = os_truncate_impl(module, &path, length);
4817
4818exit:
4819 /* Cleanup for path */
4820 path_cleanup(&path);
4821
4822 return return_value;
4823}
4824
Steve Dowerf7377032015-04-12 15:44:54 -04004825#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004826
4827#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4828
4829PyDoc_STRVAR(os_posix_fallocate__doc__,
4830"posix_fallocate($module, fd, offset, length, /)\n"
4831"--\n"
4832"\n"
4833"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4834"\n"
4835"Ensure that the file specified by fd encompasses a range of bytes\n"
4836"starting at offset bytes from the beginning and continuing for length bytes.");
4837
4838#define OS_POSIX_FALLOCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004839 {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004840
4841static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004842os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004843 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004844
4845static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004846os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004847{
4848 PyObject *return_value = NULL;
4849 int fd;
4850 Py_off_t offset;
4851 Py_off_t length;
4852
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004853 if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
4854 goto exit;
4855 }
4856 if (PyFloat_Check(args[0])) {
4857 PyErr_SetString(PyExc_TypeError,
4858 "integer argument expected, got float" );
4859 goto exit;
4860 }
4861 fd = _PyLong_AsInt(args[0]);
4862 if (fd == -1 && PyErr_Occurred()) {
4863 goto exit;
4864 }
4865 if (!Py_off_t_converter(args[1], &offset)) {
4866 goto exit;
4867 }
4868 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004869 goto exit;
4870 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004871 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4872
4873exit:
4874 return return_value;
4875}
4876
4877#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4878
4879#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4880
4881PyDoc_STRVAR(os_posix_fadvise__doc__,
4882"posix_fadvise($module, fd, offset, length, advice, /)\n"
4883"--\n"
4884"\n"
4885"Announce an intention to access data in a specific pattern.\n"
4886"\n"
4887"Announce an intention to access data in a specific pattern, thus allowing\n"
4888"the kernel to make optimizations.\n"
4889"The advice applies to the region of the file specified by fd starting at\n"
4890"offset and continuing for length bytes.\n"
4891"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4892"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4893"POSIX_FADV_DONTNEED.");
4894
4895#define OS_POSIX_FADVISE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004896 {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004897
4898static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004899os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004900 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004901
4902static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004903os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004904{
4905 PyObject *return_value = NULL;
4906 int fd;
4907 Py_off_t offset;
4908 Py_off_t length;
4909 int advice;
4910
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004911 if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
4912 goto exit;
4913 }
4914 if (PyFloat_Check(args[0])) {
4915 PyErr_SetString(PyExc_TypeError,
4916 "integer argument expected, got float" );
4917 goto exit;
4918 }
4919 fd = _PyLong_AsInt(args[0]);
4920 if (fd == -1 && PyErr_Occurred()) {
4921 goto exit;
4922 }
4923 if (!Py_off_t_converter(args[1], &offset)) {
4924 goto exit;
4925 }
4926 if (!Py_off_t_converter(args[2], &length)) {
4927 goto exit;
4928 }
4929 if (PyFloat_Check(args[3])) {
4930 PyErr_SetString(PyExc_TypeError,
4931 "integer argument expected, got float" );
4932 goto exit;
4933 }
4934 advice = _PyLong_AsInt(args[3]);
4935 if (advice == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004936 goto exit;
4937 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004938 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
4939
4940exit:
4941 return return_value;
4942}
4943
4944#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4945
4946#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
4947
4948PyDoc_STRVAR(os_putenv__doc__,
4949"putenv($module, name, value, /)\n"
4950"--\n"
4951"\n"
4952"Change or add an environment variable.");
4953
4954#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004955 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004956
4957static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004958os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004959
4960static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004961os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004962{
4963 PyObject *return_value = NULL;
4964 PyObject *name;
4965 PyObject *value;
4966
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004967 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004968 goto exit;
4969 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004970 if (!PyUnicode_Check(args[0])) {
4971 _PyArg_BadArgument("putenv", 1, "str", args[0]);
4972 goto exit;
4973 }
4974 if (PyUnicode_READY(args[0]) == -1) {
4975 goto exit;
4976 }
4977 name = args[0];
4978 if (!PyUnicode_Check(args[1])) {
4979 _PyArg_BadArgument("putenv", 2, "str", args[1]);
4980 goto exit;
4981 }
4982 if (PyUnicode_READY(args[1]) == -1) {
4983 goto exit;
4984 }
4985 value = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004986 return_value = os_putenv_impl(module, name, value);
4987
4988exit:
4989 return return_value;
4990}
4991
4992#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
4993
4994#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
4995
4996PyDoc_STRVAR(os_putenv__doc__,
4997"putenv($module, name, value, /)\n"
4998"--\n"
4999"\n"
5000"Change or add an environment variable.");
5001
5002#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005003 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005004
5005static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005006os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005007
5008static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005009os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005010{
5011 PyObject *return_value = NULL;
5012 PyObject *name = NULL;
5013 PyObject *value = NULL;
5014
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005015 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
5016 goto exit;
5017 }
5018 if (!PyUnicode_FSConverter(args[0], &name)) {
5019 goto exit;
5020 }
5021 if (!PyUnicode_FSConverter(args[1], &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005022 goto exit;
5023 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005024 return_value = os_putenv_impl(module, name, value);
5025
5026exit:
5027 /* Cleanup for name */
5028 Py_XDECREF(name);
5029 /* Cleanup for value */
5030 Py_XDECREF(value);
5031
5032 return return_value;
5033}
5034
5035#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
5036
5037#if defined(HAVE_UNSETENV)
5038
5039PyDoc_STRVAR(os_unsetenv__doc__,
5040"unsetenv($module, name, /)\n"
5041"--\n"
5042"\n"
5043"Delete an environment variable.");
5044
5045#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005046 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005047
5048static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005049os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005050
5051static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005052os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005053{
5054 PyObject *return_value = NULL;
5055 PyObject *name = NULL;
5056
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005057 if (!PyUnicode_FSConverter(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005058 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005059 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005060 return_value = os_unsetenv_impl(module, name);
5061
5062exit:
5063 /* Cleanup for name */
5064 Py_XDECREF(name);
5065
5066 return return_value;
5067}
5068
5069#endif /* defined(HAVE_UNSETENV) */
5070
5071PyDoc_STRVAR(os_strerror__doc__,
5072"strerror($module, code, /)\n"
5073"--\n"
5074"\n"
5075"Translate an error code to a message string.");
5076
5077#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005078 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005079
5080static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005081os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005082
5083static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005084os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005085{
5086 PyObject *return_value = NULL;
5087 int code;
5088
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005089 if (PyFloat_Check(arg)) {
5090 PyErr_SetString(PyExc_TypeError,
5091 "integer argument expected, got float" );
5092 goto exit;
5093 }
5094 code = _PyLong_AsInt(arg);
5095 if (code == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005096 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005097 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005098 return_value = os_strerror_impl(module, code);
5099
5100exit:
5101 return return_value;
5102}
5103
5104#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
5105
5106PyDoc_STRVAR(os_WCOREDUMP__doc__,
5107"WCOREDUMP($module, status, /)\n"
5108"--\n"
5109"\n"
5110"Return True if the process returning status was dumped to a core file.");
5111
5112#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005113 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005114
5115static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005116os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005117
5118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005119os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005120{
5121 PyObject *return_value = NULL;
5122 int status;
5123 int _return_value;
5124
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005125 if (PyFloat_Check(arg)) {
5126 PyErr_SetString(PyExc_TypeError,
5127 "integer argument expected, got float" );
5128 goto exit;
5129 }
5130 status = _PyLong_AsInt(arg);
5131 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005132 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005133 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005134 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005135 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005136 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005137 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005138 return_value = PyBool_FromLong((long)_return_value);
5139
5140exit:
5141 return return_value;
5142}
5143
5144#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
5145
5146#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
5147
5148PyDoc_STRVAR(os_WIFCONTINUED__doc__,
5149"WIFCONTINUED($module, /, status)\n"
5150"--\n"
5151"\n"
5152"Return True if a particular process was continued from a job control stop.\n"
5153"\n"
5154"Return True if the process returning status was continued from a\n"
5155"job control stop.");
5156
5157#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005158 {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005159
5160static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005161os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005162
5163static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005164os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005165{
5166 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005167 static const char * const _keywords[] = {"status", NULL};
5168 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005169 int status;
5170 int _return_value;
5171
Victor Stinner3e1fad62017-01-17 01:29:01 +01005172 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005173 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005174 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005175 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005176 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005177 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005178 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005179 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005180 return_value = PyBool_FromLong((long)_return_value);
5181
5182exit:
5183 return return_value;
5184}
5185
5186#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
5187
5188#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
5189
5190PyDoc_STRVAR(os_WIFSTOPPED__doc__,
5191"WIFSTOPPED($module, /, status)\n"
5192"--\n"
5193"\n"
5194"Return True if the process returning status was stopped.");
5195
5196#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005197 {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005198
5199static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005200os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005201
5202static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005203os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005204{
5205 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005206 static const char * const _keywords[] = {"status", NULL};
5207 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005208 int status;
5209 int _return_value;
5210
Victor Stinner3e1fad62017-01-17 01:29:01 +01005211 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005212 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005213 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005214 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005215 _return_value = os_WIFSTOPPED_impl(module, status);
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 = PyBool_FromLong((long)_return_value);
5220
5221exit:
5222 return return_value;
5223}
5224
5225#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
5226
5227#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
5228
5229PyDoc_STRVAR(os_WIFSIGNALED__doc__,
5230"WIFSIGNALED($module, /, status)\n"
5231"--\n"
5232"\n"
5233"Return True if the process returning status was terminated by a signal.");
5234
5235#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005236 {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005237
5238static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005239os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005240
5241static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005242os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005243{
5244 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005245 static const char * const _keywords[] = {"status", NULL};
5246 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247 int status;
5248 int _return_value;
5249
Victor Stinner3e1fad62017-01-17 01:29:01 +01005250 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005251 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005252 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005253 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005254 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005255 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005256 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005257 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005258 return_value = PyBool_FromLong((long)_return_value);
5259
5260exit:
5261 return return_value;
5262}
5263
5264#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
5265
5266#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
5267
5268PyDoc_STRVAR(os_WIFEXITED__doc__,
5269"WIFEXITED($module, /, status)\n"
5270"--\n"
5271"\n"
5272"Return True if the process returning status exited via the exit() system call.");
5273
5274#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005275 {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005276
5277static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005278os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005279
5280static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005281os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005282{
5283 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005284 static const char * const _keywords[] = {"status", NULL};
5285 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005286 int status;
5287 int _return_value;
5288
Victor Stinner3e1fad62017-01-17 01:29:01 +01005289 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005290 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005291 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005292 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005293 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005294 if ((_return_value == -1) && PyErr_Occurred()) {
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 = PyBool_FromLong((long)_return_value);
5298
5299exit:
5300 return return_value;
5301}
5302
5303#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
5304
5305#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
5306
5307PyDoc_STRVAR(os_WEXITSTATUS__doc__,
5308"WEXITSTATUS($module, /, status)\n"
5309"--\n"
5310"\n"
5311"Return the process return code from status.");
5312
5313#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005314 {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005315
5316static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005317os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005318
5319static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005320os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005321{
5322 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005323 static const char * const _keywords[] = {"status", NULL};
5324 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005325 int status;
5326 int _return_value;
5327
Victor Stinner3e1fad62017-01-17 01:29:01 +01005328 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005329 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005331 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005332 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005333 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005334 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005335 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005336 return_value = PyLong_FromLong((long)_return_value);
5337
5338exit:
5339 return return_value;
5340}
5341
5342#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
5343
5344#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
5345
5346PyDoc_STRVAR(os_WTERMSIG__doc__,
5347"WTERMSIG($module, /, status)\n"
5348"--\n"
5349"\n"
5350"Return the signal that terminated the process that provided the status value.");
5351
5352#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005353 {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005354
5355static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005356os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005357
5358static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005359os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005360{
5361 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005362 static const char * const _keywords[] = {"status", NULL};
5363 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005364 int status;
5365 int _return_value;
5366
Victor Stinner3e1fad62017-01-17 01:29:01 +01005367 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005368 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005369 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005370 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005371 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005372 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005373 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005374 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005375 return_value = PyLong_FromLong((long)_return_value);
5376
5377exit:
5378 return return_value;
5379}
5380
5381#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
5382
5383#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
5384
5385PyDoc_STRVAR(os_WSTOPSIG__doc__,
5386"WSTOPSIG($module, /, status)\n"
5387"--\n"
5388"\n"
5389"Return the signal that stopped the process that provided the status value.");
5390
5391#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005392 {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005393
5394static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005395os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005396
5397static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005398os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005399{
5400 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005401 static const char * const _keywords[] = {"status", NULL};
5402 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005403 int status;
5404 int _return_value;
5405
Victor Stinner3e1fad62017-01-17 01:29:01 +01005406 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005407 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005408 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005409 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005410 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005411 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005412 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005413 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005414 return_value = PyLong_FromLong((long)_return_value);
5415
5416exit:
5417 return return_value;
5418}
5419
5420#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
5421
5422#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
5423
5424PyDoc_STRVAR(os_fstatvfs__doc__,
5425"fstatvfs($module, fd, /)\n"
5426"--\n"
5427"\n"
5428"Perform an fstatvfs system call on the given fd.\n"
5429"\n"
5430"Equivalent to statvfs(fd).");
5431
5432#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005433 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005434
5435static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005436os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005437
5438static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005439os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005440{
5441 PyObject *return_value = NULL;
5442 int fd;
5443
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005444 if (PyFloat_Check(arg)) {
5445 PyErr_SetString(PyExc_TypeError,
5446 "integer argument expected, got float" );
5447 goto exit;
5448 }
5449 fd = _PyLong_AsInt(arg);
5450 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005451 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005452 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005453 return_value = os_fstatvfs_impl(module, fd);
5454
5455exit:
5456 return return_value;
5457}
5458
5459#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5460
5461#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5462
5463PyDoc_STRVAR(os_statvfs__doc__,
5464"statvfs($module, /, path)\n"
5465"--\n"
5466"\n"
5467"Perform a statvfs system call on the given path.\n"
5468"\n"
5469"path may always be specified as a string.\n"
5470"On some platforms, path may also be specified as an open file descriptor.\n"
5471" If this functionality is unavailable, using it raises an exception.");
5472
5473#define OS_STATVFS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005474 {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005475
5476static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005477os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005478
5479static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005480os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005481{
5482 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005483 static const char * const _keywords[] = {"path", NULL};
5484 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005485 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5486
Victor Stinner3e1fad62017-01-17 01:29:01 +01005487 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005488 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005489 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005490 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005491 return_value = os_statvfs_impl(module, &path);
5492
5493exit:
5494 /* Cleanup for path */
5495 path_cleanup(&path);
5496
5497 return return_value;
5498}
5499
5500#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5501
5502#if defined(MS_WINDOWS)
5503
5504PyDoc_STRVAR(os__getdiskusage__doc__,
5505"_getdiskusage($module, /, path)\n"
5506"--\n"
5507"\n"
5508"Return disk usage statistics about the given path as a (total, free) tuple.");
5509
5510#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005511 {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005512
5513static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005514os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005515
5516static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005517os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005518{
5519 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005520 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005521 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5522 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005523
Victor Stinner3e1fad62017-01-17 01:29:01 +01005524 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005525 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005526 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005527 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005528 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005529
5530exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005531 /* Cleanup for path */
5532 path_cleanup(&path);
5533
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005534 return return_value;
5535}
5536
5537#endif /* defined(MS_WINDOWS) */
5538
5539#if defined(HAVE_FPATHCONF)
5540
5541PyDoc_STRVAR(os_fpathconf__doc__,
5542"fpathconf($module, fd, name, /)\n"
5543"--\n"
5544"\n"
5545"Return the configuration limit name for the file descriptor fd.\n"
5546"\n"
5547"If there is no limit, return -1.");
5548
5549#define OS_FPATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005550 {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005551
5552static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005553os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005554
5555static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005556os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005557{
5558 PyObject *return_value = NULL;
5559 int fd;
5560 int name;
5561 long _return_value;
5562
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005563 if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
5564 goto exit;
5565 }
5566 if (PyFloat_Check(args[0])) {
5567 PyErr_SetString(PyExc_TypeError,
5568 "integer argument expected, got float" );
5569 goto exit;
5570 }
5571 fd = _PyLong_AsInt(args[0]);
5572 if (fd == -1 && PyErr_Occurred()) {
5573 goto exit;
5574 }
5575 if (!conv_path_confname(args[1], &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005576 goto exit;
5577 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005578 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005579 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005580 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005581 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005582 return_value = PyLong_FromLong(_return_value);
5583
5584exit:
5585 return return_value;
5586}
5587
5588#endif /* defined(HAVE_FPATHCONF) */
5589
5590#if defined(HAVE_PATHCONF)
5591
5592PyDoc_STRVAR(os_pathconf__doc__,
5593"pathconf($module, /, path, name)\n"
5594"--\n"
5595"\n"
5596"Return the configuration limit name for the file or directory path.\n"
5597"\n"
5598"If there is no limit, return -1.\n"
5599"On some platforms, path may also be specified as an open file descriptor.\n"
5600" If this functionality is unavailable, using it raises an exception.");
5601
5602#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005603 {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005604
5605static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005606os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005607
5608static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005609os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005610{
5611 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005612 static const char * const _keywords[] = {"path", "name", NULL};
5613 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005614 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5615 int name;
5616 long _return_value;
5617
Victor Stinner3e1fad62017-01-17 01:29:01 +01005618 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005619 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005620 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005621 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005622 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005623 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005624 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005625 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005626 return_value = PyLong_FromLong(_return_value);
5627
5628exit:
5629 /* Cleanup for path */
5630 path_cleanup(&path);
5631
5632 return return_value;
5633}
5634
5635#endif /* defined(HAVE_PATHCONF) */
5636
5637#if defined(HAVE_CONFSTR)
5638
5639PyDoc_STRVAR(os_confstr__doc__,
5640"confstr($module, name, /)\n"
5641"--\n"
5642"\n"
5643"Return a string-valued system configuration variable.");
5644
5645#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005646 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005647
5648static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005649os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005650
5651static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005652os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005653{
5654 PyObject *return_value = NULL;
5655 int name;
5656
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005657 if (!conv_confstr_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005658 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005659 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005660 return_value = os_confstr_impl(module, name);
5661
5662exit:
5663 return return_value;
5664}
5665
5666#endif /* defined(HAVE_CONFSTR) */
5667
5668#if defined(HAVE_SYSCONF)
5669
5670PyDoc_STRVAR(os_sysconf__doc__,
5671"sysconf($module, name, /)\n"
5672"--\n"
5673"\n"
5674"Return an integer-valued system configuration variable.");
5675
5676#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005677 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005678
5679static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005680os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005681
5682static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005683os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005684{
5685 PyObject *return_value = NULL;
5686 int name;
5687 long _return_value;
5688
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005689 if (!conv_sysconf_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005690 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005691 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005692 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005693 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005694 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005695 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005696 return_value = PyLong_FromLong(_return_value);
5697
5698exit:
5699 return return_value;
5700}
5701
5702#endif /* defined(HAVE_SYSCONF) */
5703
5704PyDoc_STRVAR(os_abort__doc__,
5705"abort($module, /)\n"
5706"--\n"
5707"\n"
5708"Abort the interpreter immediately.\n"
5709"\n"
5710"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5711"on the hosting operating system. This function never returns.");
5712
5713#define OS_ABORT_METHODDEF \
5714 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5715
5716static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005717os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005718
5719static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005720os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005721{
5722 return os_abort_impl(module);
5723}
5724
Steve Dowercc16be82016-09-08 10:35:16 -07005725#if defined(MS_WINDOWS)
5726
5727PyDoc_STRVAR(os_startfile__doc__,
5728"startfile($module, /, filepath, operation=None)\n"
5729"--\n"
5730"\n"
5731"startfile(filepath [, operation])\n"
5732"\n"
5733"Start a file with its associated application.\n"
5734"\n"
5735"When \"operation\" is not specified or \"open\", this acts like\n"
5736"double-clicking the file in Explorer, or giving the file name as an\n"
5737"argument to the DOS \"start\" command: the file is opened with whatever\n"
5738"application (if any) its extension is associated.\n"
5739"When another \"operation\" is given, it specifies what should be done with\n"
5740"the file. A typical operation is \"print\".\n"
5741"\n"
5742"startfile returns as soon as the associated application is launched.\n"
5743"There is no option to wait for the application to close, and no way\n"
5744"to retrieve the application\'s exit status.\n"
5745"\n"
5746"The filepath is relative to the current directory. If you want to use\n"
5747"an absolute path, make sure the first character is not a slash (\"/\");\n"
5748"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5749
5750#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005751 {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005752
5753static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005754os_startfile_impl(PyObject *module, path_t *filepath,
5755 const Py_UNICODE *operation);
Steve Dowercc16be82016-09-08 10:35:16 -07005756
5757static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005758os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005759{
5760 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005761 static const char * const _keywords[] = {"filepath", "operation", NULL};
5762 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005763 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005764 const Py_UNICODE *operation = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07005765
Victor Stinner3e1fad62017-01-17 01:29:01 +01005766 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005767 path_converter, &filepath, &operation)) {
5768 goto exit;
5769 }
5770 return_value = os_startfile_impl(module, &filepath, operation);
5771
5772exit:
5773 /* Cleanup for filepath */
5774 path_cleanup(&filepath);
5775
5776 return return_value;
5777}
5778
5779#endif /* defined(MS_WINDOWS) */
5780
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005781#if defined(HAVE_GETLOADAVG)
5782
5783PyDoc_STRVAR(os_getloadavg__doc__,
5784"getloadavg($module, /)\n"
5785"--\n"
5786"\n"
5787"Return average recent system load information.\n"
5788"\n"
5789"Return the number of processes in the system run queue averaged over\n"
5790"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5791"Raises OSError if the load average was unobtainable.");
5792
5793#define OS_GETLOADAVG_METHODDEF \
5794 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5795
5796static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005797os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005798
5799static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005800os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005801{
5802 return os_getloadavg_impl(module);
5803}
5804
5805#endif /* defined(HAVE_GETLOADAVG) */
5806
5807PyDoc_STRVAR(os_device_encoding__doc__,
5808"device_encoding($module, /, fd)\n"
5809"--\n"
5810"\n"
5811"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5812"\n"
5813"The file descriptor must be attached to a terminal.\n"
5814"If the device is not a terminal, return None.");
5815
5816#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005817 {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005818
5819static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005820os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005821
5822static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005823os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005824{
5825 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005826 static const char * const _keywords[] = {"fd", NULL};
5827 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005828 int fd;
5829
Victor Stinner3e1fad62017-01-17 01:29:01 +01005830 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005831 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005832 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005833 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005834 return_value = os_device_encoding_impl(module, fd);
5835
5836exit:
5837 return return_value;
5838}
5839
5840#if defined(HAVE_SETRESUID)
5841
5842PyDoc_STRVAR(os_setresuid__doc__,
5843"setresuid($module, ruid, euid, suid, /)\n"
5844"--\n"
5845"\n"
5846"Set the current process\'s real, effective, and saved user ids.");
5847
5848#define OS_SETRESUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005849 {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005850
5851static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005852os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005853
5854static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005855os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005856{
5857 PyObject *return_value = NULL;
5858 uid_t ruid;
5859 uid_t euid;
5860 uid_t suid;
5861
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005862 if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
5863 goto exit;
5864 }
5865 if (!_Py_Uid_Converter(args[0], &ruid)) {
5866 goto exit;
5867 }
5868 if (!_Py_Uid_Converter(args[1], &euid)) {
5869 goto exit;
5870 }
5871 if (!_Py_Uid_Converter(args[2], &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005872 goto exit;
5873 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005874 return_value = os_setresuid_impl(module, ruid, euid, suid);
5875
5876exit:
5877 return return_value;
5878}
5879
5880#endif /* defined(HAVE_SETRESUID) */
5881
5882#if defined(HAVE_SETRESGID)
5883
5884PyDoc_STRVAR(os_setresgid__doc__,
5885"setresgid($module, rgid, egid, sgid, /)\n"
5886"--\n"
5887"\n"
5888"Set the current process\'s real, effective, and saved group ids.");
5889
5890#define OS_SETRESGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005891 {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005892
5893static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005894os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005895
5896static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005897os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005898{
5899 PyObject *return_value = NULL;
5900 gid_t rgid;
5901 gid_t egid;
5902 gid_t sgid;
5903
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005904 if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
5905 goto exit;
5906 }
5907 if (!_Py_Gid_Converter(args[0], &rgid)) {
5908 goto exit;
5909 }
5910 if (!_Py_Gid_Converter(args[1], &egid)) {
5911 goto exit;
5912 }
5913 if (!_Py_Gid_Converter(args[2], &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005914 goto exit;
5915 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005916 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5917
5918exit:
5919 return return_value;
5920}
5921
5922#endif /* defined(HAVE_SETRESGID) */
5923
5924#if defined(HAVE_GETRESUID)
5925
5926PyDoc_STRVAR(os_getresuid__doc__,
5927"getresuid($module, /)\n"
5928"--\n"
5929"\n"
5930"Return a tuple of the current process\'s real, effective, and saved user ids.");
5931
5932#define OS_GETRESUID_METHODDEF \
5933 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
5934
5935static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005936os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005937
5938static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005939os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005940{
5941 return os_getresuid_impl(module);
5942}
5943
5944#endif /* defined(HAVE_GETRESUID) */
5945
5946#if defined(HAVE_GETRESGID)
5947
5948PyDoc_STRVAR(os_getresgid__doc__,
5949"getresgid($module, /)\n"
5950"--\n"
5951"\n"
5952"Return a tuple of the current process\'s real, effective, and saved group ids.");
5953
5954#define OS_GETRESGID_METHODDEF \
5955 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
5956
5957static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005958os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005959
5960static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005961os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005962{
5963 return os_getresgid_impl(module);
5964}
5965
5966#endif /* defined(HAVE_GETRESGID) */
5967
5968#if defined(USE_XATTRS)
5969
5970PyDoc_STRVAR(os_getxattr__doc__,
5971"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
5972"--\n"
5973"\n"
5974"Return the value of extended attribute attribute on path.\n"
5975"\n"
BNMetricsb9427072018-11-02 15:20:19 +00005976"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005977"If follow_symlinks is False, and the last element of the path is a symbolic\n"
5978" link, getxattr will examine the symbolic link itself instead of the file\n"
5979" the link points to.");
5980
5981#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005982 {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005983
5984static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005985os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04005986 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005987
5988static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005989os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005990{
5991 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005992 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
5993 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005994 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
5995 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
5996 int follow_symlinks = 1;
5997
Victor Stinner3e1fad62017-01-17 01:29:01 +01005998 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005999 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006000 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006001 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006002 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
6003
6004exit:
6005 /* Cleanup for path */
6006 path_cleanup(&path);
6007 /* Cleanup for attribute */
6008 path_cleanup(&attribute);
6009
6010 return return_value;
6011}
6012
6013#endif /* defined(USE_XATTRS) */
6014
6015#if defined(USE_XATTRS)
6016
6017PyDoc_STRVAR(os_setxattr__doc__,
6018"setxattr($module, /, path, attribute, value, flags=0, *,\n"
6019" follow_symlinks=True)\n"
6020"--\n"
6021"\n"
6022"Set extended attribute attribute on path to value.\n"
6023"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006024"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006025"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6026" link, setxattr will modify the symbolic link itself instead of the file\n"
6027" the link points to.");
6028
6029#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006030 {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006031
6032static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006033os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006034 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006035
6036static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006037os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006038{
6039 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006040 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
6041 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006042 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
6043 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
6044 Py_buffer value = {NULL, NULL};
6045 int flags = 0;
6046 int follow_symlinks = 1;
6047
Victor Stinner3e1fad62017-01-17 01:29:01 +01006048 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006049 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006050 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006051 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006052 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
6053
6054exit:
6055 /* Cleanup for path */
6056 path_cleanup(&path);
6057 /* Cleanup for attribute */
6058 path_cleanup(&attribute);
6059 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006060 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006061 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006062 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006063
6064 return return_value;
6065}
6066
6067#endif /* defined(USE_XATTRS) */
6068
6069#if defined(USE_XATTRS)
6070
6071PyDoc_STRVAR(os_removexattr__doc__,
6072"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
6073"--\n"
6074"\n"
6075"Remove extended attribute attribute on path.\n"
6076"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006077"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006078"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6079" link, removexattr will modify the symbolic link itself instead of the file\n"
6080" the link points to.");
6081
6082#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006083 {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006084
6085static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006086os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006087 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006088
6089static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006090os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006091{
6092 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006093 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
6094 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006095 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
6096 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
6097 int follow_symlinks = 1;
6098
Victor Stinner3e1fad62017-01-17 01:29:01 +01006099 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006100 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006101 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006102 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006103 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
6104
6105exit:
6106 /* Cleanup for path */
6107 path_cleanup(&path);
6108 /* Cleanup for attribute */
6109 path_cleanup(&attribute);
6110
6111 return return_value;
6112}
6113
6114#endif /* defined(USE_XATTRS) */
6115
6116#if defined(USE_XATTRS)
6117
6118PyDoc_STRVAR(os_listxattr__doc__,
6119"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
6120"--\n"
6121"\n"
6122"Return a list of extended attributes on path.\n"
6123"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006124"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006125"if path is None, listxattr will examine the current directory.\n"
6126"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6127" link, listxattr will examine the symbolic link itself instead of the file\n"
6128" the link points to.");
6129
6130#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006131 {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006132
6133static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006134os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006135
6136static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006137os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006138{
6139 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006140 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
6141 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006142 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
6143 int follow_symlinks = 1;
6144
Victor Stinner3e1fad62017-01-17 01:29:01 +01006145 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006146 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006147 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006148 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006149 return_value = os_listxattr_impl(module, &path, follow_symlinks);
6150
6151exit:
6152 /* Cleanup for path */
6153 path_cleanup(&path);
6154
6155 return return_value;
6156}
6157
6158#endif /* defined(USE_XATTRS) */
6159
6160PyDoc_STRVAR(os_urandom__doc__,
6161"urandom($module, size, /)\n"
6162"--\n"
6163"\n"
6164"Return a bytes object containing random bytes suitable for cryptographic use.");
6165
6166#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006167 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006168
6169static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006170os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006171
6172static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006173os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006174{
6175 PyObject *return_value = NULL;
6176 Py_ssize_t size;
6177
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006178 if (PyFloat_Check(arg)) {
6179 PyErr_SetString(PyExc_TypeError,
6180 "integer argument expected, got float" );
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006181 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006182 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006183 {
6184 Py_ssize_t ival = -1;
6185 PyObject *iobj = PyNumber_Index(arg);
6186 if (iobj != NULL) {
6187 ival = PyLong_AsSsize_t(iobj);
6188 Py_DECREF(iobj);
6189 }
6190 if (ival == -1 && PyErr_Occurred()) {
6191 goto exit;
6192 }
6193 size = ival;
6194 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006195 return_value = os_urandom_impl(module, size);
6196
6197exit:
6198 return return_value;
6199}
6200
6201PyDoc_STRVAR(os_cpu_count__doc__,
6202"cpu_count($module, /)\n"
6203"--\n"
6204"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01006205"Return the number of CPUs in the system; return None if indeterminable.\n"
6206"\n"
6207"This number is not equivalent to the number of CPUs the current process can\n"
6208"use. The number of usable CPUs can be obtained with\n"
6209"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006210
6211#define OS_CPU_COUNT_METHODDEF \
6212 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
6213
6214static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006215os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006216
6217static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006218os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006219{
6220 return os_cpu_count_impl(module);
6221}
6222
6223PyDoc_STRVAR(os_get_inheritable__doc__,
6224"get_inheritable($module, fd, /)\n"
6225"--\n"
6226"\n"
6227"Get the close-on-exe flag of the specified file descriptor.");
6228
6229#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006230 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006231
6232static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006233os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006234
6235static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006236os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006237{
6238 PyObject *return_value = NULL;
6239 int fd;
6240 int _return_value;
6241
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006242 if (PyFloat_Check(arg)) {
6243 PyErr_SetString(PyExc_TypeError,
6244 "integer argument expected, got float" );
6245 goto exit;
6246 }
6247 fd = _PyLong_AsInt(arg);
6248 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006249 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006250 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006251 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006252 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006253 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006254 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006255 return_value = PyBool_FromLong((long)_return_value);
6256
6257exit:
6258 return return_value;
6259}
6260
6261PyDoc_STRVAR(os_set_inheritable__doc__,
6262"set_inheritable($module, fd, inheritable, /)\n"
6263"--\n"
6264"\n"
6265"Set the inheritable flag of the specified file descriptor.");
6266
6267#define OS_SET_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006268 {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006269
6270static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006271os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006272
6273static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006274os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006275{
6276 PyObject *return_value = NULL;
6277 int fd;
6278 int inheritable;
6279
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006280 if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
6281 goto exit;
6282 }
6283 if (PyFloat_Check(args[0])) {
6284 PyErr_SetString(PyExc_TypeError,
6285 "integer argument expected, got float" );
6286 goto exit;
6287 }
6288 fd = _PyLong_AsInt(args[0]);
6289 if (fd == -1 && PyErr_Occurred()) {
6290 goto exit;
6291 }
6292 if (PyFloat_Check(args[1])) {
6293 PyErr_SetString(PyExc_TypeError,
6294 "integer argument expected, got float" );
6295 goto exit;
6296 }
6297 inheritable = _PyLong_AsInt(args[1]);
6298 if (inheritable == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006299 goto exit;
6300 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006301 return_value = os_set_inheritable_impl(module, fd, inheritable);
6302
6303exit:
6304 return return_value;
6305}
6306
6307#if defined(MS_WINDOWS)
6308
6309PyDoc_STRVAR(os_get_handle_inheritable__doc__,
6310"get_handle_inheritable($module, handle, /)\n"
6311"--\n"
6312"\n"
6313"Get the close-on-exe flag of the specified file descriptor.");
6314
6315#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006316 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006317
6318static int
Victor Stinner581139c2016-09-06 15:54:20 -07006319os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006320
6321static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006322os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006323{
6324 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07006325 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006326 int _return_value;
6327
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006328 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006329 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006330 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006331 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006332 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006333 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006334 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006335 return_value = PyBool_FromLong((long)_return_value);
6336
6337exit:
6338 return return_value;
6339}
6340
6341#endif /* defined(MS_WINDOWS) */
6342
6343#if defined(MS_WINDOWS)
6344
6345PyDoc_STRVAR(os_set_handle_inheritable__doc__,
6346"set_handle_inheritable($module, handle, inheritable, /)\n"
6347"--\n"
6348"\n"
6349"Set the inheritable flag of the specified handle.");
6350
6351#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006352 {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006353
6354static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07006355os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04006356 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006357
6358static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006359os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006360{
6361 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07006362 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006363 int inheritable;
6364
Sylvain74453812017-06-10 06:51:48 +02006365 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
6366 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006367 goto exit;
6368 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006369 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
6370
6371exit:
6372 return return_value;
6373}
6374
6375#endif /* defined(MS_WINDOWS) */
6376
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006377#if !defined(MS_WINDOWS)
6378
6379PyDoc_STRVAR(os_get_blocking__doc__,
6380"get_blocking($module, fd, /)\n"
6381"--\n"
6382"\n"
6383"Get the blocking mode of the file descriptor.\n"
6384"\n"
6385"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
6386
6387#define OS_GET_BLOCKING_METHODDEF \
6388 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
6389
6390static int
6391os_get_blocking_impl(PyObject *module, int fd);
6392
6393static PyObject *
6394os_get_blocking(PyObject *module, PyObject *arg)
6395{
6396 PyObject *return_value = NULL;
6397 int fd;
6398 int _return_value;
6399
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006400 if (PyFloat_Check(arg)) {
6401 PyErr_SetString(PyExc_TypeError,
6402 "integer argument expected, got float" );
6403 goto exit;
6404 }
6405 fd = _PyLong_AsInt(arg);
6406 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006407 goto exit;
6408 }
6409 _return_value = os_get_blocking_impl(module, fd);
6410 if ((_return_value == -1) && PyErr_Occurred()) {
6411 goto exit;
6412 }
6413 return_value = PyBool_FromLong((long)_return_value);
6414
6415exit:
6416 return return_value;
6417}
6418
6419#endif /* !defined(MS_WINDOWS) */
6420
6421#if !defined(MS_WINDOWS)
6422
6423PyDoc_STRVAR(os_set_blocking__doc__,
6424"set_blocking($module, fd, blocking, /)\n"
6425"--\n"
6426"\n"
6427"Set the blocking mode of the specified file descriptor.\n"
6428"\n"
6429"Set the O_NONBLOCK flag if blocking is False,\n"
6430"clear the O_NONBLOCK flag otherwise.");
6431
6432#define OS_SET_BLOCKING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006433 {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006434
6435static PyObject *
6436os_set_blocking_impl(PyObject *module, int fd, int blocking);
6437
6438static PyObject *
6439os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6440{
6441 PyObject *return_value = NULL;
6442 int fd;
6443 int blocking;
6444
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006445 if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
6446 goto exit;
6447 }
6448 if (PyFloat_Check(args[0])) {
6449 PyErr_SetString(PyExc_TypeError,
6450 "integer argument expected, got float" );
6451 goto exit;
6452 }
6453 fd = _PyLong_AsInt(args[0]);
6454 if (fd == -1 && PyErr_Occurred()) {
6455 goto exit;
6456 }
6457 if (PyFloat_Check(args[1])) {
6458 PyErr_SetString(PyExc_TypeError,
6459 "integer argument expected, got float" );
6460 goto exit;
6461 }
6462 blocking = _PyLong_AsInt(args[1]);
6463 if (blocking == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006464 goto exit;
6465 }
6466 return_value = os_set_blocking_impl(module, fd, blocking);
6467
6468exit:
6469 return return_value;
6470}
6471
6472#endif /* !defined(MS_WINDOWS) */
6473
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006474PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
6475"is_symlink($self, /)\n"
6476"--\n"
6477"\n"
6478"Return True if the entry is a symbolic link; cached per entry.");
6479
6480#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
6481 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
6482
6483static int
6484os_DirEntry_is_symlink_impl(DirEntry *self);
6485
6486static PyObject *
6487os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
6488{
6489 PyObject *return_value = NULL;
6490 int _return_value;
6491
6492 _return_value = os_DirEntry_is_symlink_impl(self);
6493 if ((_return_value == -1) && PyErr_Occurred()) {
6494 goto exit;
6495 }
6496 return_value = PyBool_FromLong((long)_return_value);
6497
6498exit:
6499 return return_value;
6500}
6501
6502PyDoc_STRVAR(os_DirEntry_stat__doc__,
6503"stat($self, /, *, follow_symlinks=True)\n"
6504"--\n"
6505"\n"
6506"Return stat_result object for the entry; cached per entry.");
6507
6508#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006509 {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006510
6511static PyObject *
6512os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
6513
6514static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006515os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006516{
6517 PyObject *return_value = NULL;
6518 static const char * const _keywords[] = {"follow_symlinks", NULL};
6519 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
6520 int follow_symlinks = 1;
6521
Victor Stinner3e1fad62017-01-17 01:29:01 +01006522 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006523 &follow_symlinks)) {
6524 goto exit;
6525 }
6526 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
6527
6528exit:
6529 return return_value;
6530}
6531
6532PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
6533"is_dir($self, /, *, follow_symlinks=True)\n"
6534"--\n"
6535"\n"
6536"Return True if the entry is a directory; cached per entry.");
6537
6538#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006539 {"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 +02006540
6541static int
6542os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
6543
6544static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006545os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006546{
6547 PyObject *return_value = NULL;
6548 static const char * const _keywords[] = {"follow_symlinks", NULL};
6549 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
6550 int follow_symlinks = 1;
6551 int _return_value;
6552
Victor Stinner3e1fad62017-01-17 01:29:01 +01006553 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006554 &follow_symlinks)) {
6555 goto exit;
6556 }
6557 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
6558 if ((_return_value == -1) && PyErr_Occurred()) {
6559 goto exit;
6560 }
6561 return_value = PyBool_FromLong((long)_return_value);
6562
6563exit:
6564 return return_value;
6565}
6566
6567PyDoc_STRVAR(os_DirEntry_is_file__doc__,
6568"is_file($self, /, *, follow_symlinks=True)\n"
6569"--\n"
6570"\n"
6571"Return True if the entry is a file; cached per entry.");
6572
6573#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006574 {"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 +02006575
6576static int
6577os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
6578
6579static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006580os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006581{
6582 PyObject *return_value = NULL;
6583 static const char * const _keywords[] = {"follow_symlinks", NULL};
6584 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
6585 int follow_symlinks = 1;
6586 int _return_value;
6587
Victor Stinner3e1fad62017-01-17 01:29:01 +01006588 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006589 &follow_symlinks)) {
6590 goto exit;
6591 }
6592 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
6593 if ((_return_value == -1) && PyErr_Occurred()) {
6594 goto exit;
6595 }
6596 return_value = PyBool_FromLong((long)_return_value);
6597
6598exit:
6599 return return_value;
6600}
6601
6602PyDoc_STRVAR(os_DirEntry_inode__doc__,
6603"inode($self, /)\n"
6604"--\n"
6605"\n"
6606"Return inode of the entry; cached per entry.");
6607
6608#define OS_DIRENTRY_INODE_METHODDEF \
6609 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6610
6611static PyObject *
6612os_DirEntry_inode_impl(DirEntry *self);
6613
6614static PyObject *
6615os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6616{
6617 return os_DirEntry_inode_impl(self);
6618}
6619
6620PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6621"__fspath__($self, /)\n"
6622"--\n"
6623"\n"
6624"Returns the path for the entry.");
6625
6626#define OS_DIRENTRY___FSPATH___METHODDEF \
6627 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6628
6629static PyObject *
6630os_DirEntry___fspath___impl(DirEntry *self);
6631
6632static PyObject *
6633os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6634{
6635 return os_DirEntry___fspath___impl(self);
6636}
6637
6638PyDoc_STRVAR(os_scandir__doc__,
6639"scandir($module, /, path=None)\n"
6640"--\n"
6641"\n"
6642"Return an iterator of DirEntry objects for given path.\n"
6643"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006644"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006645"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6646"all other circumstances they will be str.\n"
6647"\n"
6648"If path is None, uses the path=\'.\'.");
6649
6650#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006651 {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006652
6653static PyObject *
6654os_scandir_impl(PyObject *module, path_t *path);
6655
6656static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006657os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006658{
6659 PyObject *return_value = NULL;
6660 static const char * const _keywords[] = {"path", NULL};
6661 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006662 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006663
Victor Stinner3e1fad62017-01-17 01:29:01 +01006664 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006665 path_converter, &path)) {
6666 goto exit;
6667 }
6668 return_value = os_scandir_impl(module, &path);
6669
6670exit:
6671 /* Cleanup for path */
6672 path_cleanup(&path);
6673
6674 return return_value;
6675}
6676
Ethan Furman410ef8e2016-06-04 12:06:26 -07006677PyDoc_STRVAR(os_fspath__doc__,
6678"fspath($module, /, path)\n"
6679"--\n"
6680"\n"
6681"Return the file system path representation of the object.\n"
6682"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006683"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6684"object defines __fspath__(), then return the result of that method. All other\n"
6685"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006686
6687#define OS_FSPATH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006688 {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006689
6690static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006691os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006692
6693static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006694os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006695{
6696 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006697 static const char * const _keywords[] = {"path", NULL};
6698 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006699 PyObject *path;
6700
Victor Stinner3e1fad62017-01-17 01:29:01 +01006701 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006702 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006703 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006704 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006705 return_value = os_fspath_impl(module, path);
6706
6707exit:
6708 return return_value;
6709}
6710
Victor Stinner9b1f4742016-09-06 16:18:52 -07006711#if defined(HAVE_GETRANDOM_SYSCALL)
6712
6713PyDoc_STRVAR(os_getrandom__doc__,
6714"getrandom($module, /, size, flags=0)\n"
6715"--\n"
6716"\n"
6717"Obtain a series of random bytes.");
6718
6719#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006720 {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006721
6722static PyObject *
6723os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6724
6725static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006726os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006727{
6728 PyObject *return_value = NULL;
6729 static const char * const _keywords[] = {"size", "flags", NULL};
6730 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6731 Py_ssize_t size;
6732 int flags = 0;
6733
Victor Stinner3e1fad62017-01-17 01:29:01 +01006734 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006735 &size, &flags)) {
6736 goto exit;
6737 }
6738 return_value = os_getrandom_impl(module, size, flags);
6739
6740exit:
6741 return return_value;
6742}
6743
6744#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6745
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006746#ifndef OS_TTYNAME_METHODDEF
6747 #define OS_TTYNAME_METHODDEF
6748#endif /* !defined(OS_TTYNAME_METHODDEF) */
6749
6750#ifndef OS_CTERMID_METHODDEF
6751 #define OS_CTERMID_METHODDEF
6752#endif /* !defined(OS_CTERMID_METHODDEF) */
6753
6754#ifndef OS_FCHDIR_METHODDEF
6755 #define OS_FCHDIR_METHODDEF
6756#endif /* !defined(OS_FCHDIR_METHODDEF) */
6757
6758#ifndef OS_FCHMOD_METHODDEF
6759 #define OS_FCHMOD_METHODDEF
6760#endif /* !defined(OS_FCHMOD_METHODDEF) */
6761
6762#ifndef OS_LCHMOD_METHODDEF
6763 #define OS_LCHMOD_METHODDEF
6764#endif /* !defined(OS_LCHMOD_METHODDEF) */
6765
6766#ifndef OS_CHFLAGS_METHODDEF
6767 #define OS_CHFLAGS_METHODDEF
6768#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6769
6770#ifndef OS_LCHFLAGS_METHODDEF
6771 #define OS_LCHFLAGS_METHODDEF
6772#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6773
6774#ifndef OS_CHROOT_METHODDEF
6775 #define OS_CHROOT_METHODDEF
6776#endif /* !defined(OS_CHROOT_METHODDEF) */
6777
6778#ifndef OS_FSYNC_METHODDEF
6779 #define OS_FSYNC_METHODDEF
6780#endif /* !defined(OS_FSYNC_METHODDEF) */
6781
6782#ifndef OS_SYNC_METHODDEF
6783 #define OS_SYNC_METHODDEF
6784#endif /* !defined(OS_SYNC_METHODDEF) */
6785
6786#ifndef OS_FDATASYNC_METHODDEF
6787 #define OS_FDATASYNC_METHODDEF
6788#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6789
6790#ifndef OS_CHOWN_METHODDEF
6791 #define OS_CHOWN_METHODDEF
6792#endif /* !defined(OS_CHOWN_METHODDEF) */
6793
6794#ifndef OS_FCHOWN_METHODDEF
6795 #define OS_FCHOWN_METHODDEF
6796#endif /* !defined(OS_FCHOWN_METHODDEF) */
6797
6798#ifndef OS_LCHOWN_METHODDEF
6799 #define OS_LCHOWN_METHODDEF
6800#endif /* !defined(OS_LCHOWN_METHODDEF) */
6801
6802#ifndef OS_LINK_METHODDEF
6803 #define OS_LINK_METHODDEF
6804#endif /* !defined(OS_LINK_METHODDEF) */
6805
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006806#ifndef OS__GETFULLPATHNAME_METHODDEF
6807 #define OS__GETFULLPATHNAME_METHODDEF
6808#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6809
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006810#ifndef OS__GETFINALPATHNAME_METHODDEF
6811 #define OS__GETFINALPATHNAME_METHODDEF
6812#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6813
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006814#ifndef OS__ISDIR_METHODDEF
6815 #define OS__ISDIR_METHODDEF
6816#endif /* !defined(OS__ISDIR_METHODDEF) */
6817
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006818#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6819 #define OS__GETVOLUMEPATHNAME_METHODDEF
6820#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6821
6822#ifndef OS_NICE_METHODDEF
6823 #define OS_NICE_METHODDEF
6824#endif /* !defined(OS_NICE_METHODDEF) */
6825
6826#ifndef OS_GETPRIORITY_METHODDEF
6827 #define OS_GETPRIORITY_METHODDEF
6828#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6829
6830#ifndef OS_SETPRIORITY_METHODDEF
6831 #define OS_SETPRIORITY_METHODDEF
6832#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6833
6834#ifndef OS_SYSTEM_METHODDEF
6835 #define OS_SYSTEM_METHODDEF
6836#endif /* !defined(OS_SYSTEM_METHODDEF) */
6837
6838#ifndef OS_UNAME_METHODDEF
6839 #define OS_UNAME_METHODDEF
6840#endif /* !defined(OS_UNAME_METHODDEF) */
6841
6842#ifndef OS_EXECV_METHODDEF
6843 #define OS_EXECV_METHODDEF
6844#endif /* !defined(OS_EXECV_METHODDEF) */
6845
6846#ifndef OS_EXECVE_METHODDEF
6847 #define OS_EXECVE_METHODDEF
6848#endif /* !defined(OS_EXECVE_METHODDEF) */
6849
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006850#ifndef OS_POSIX_SPAWN_METHODDEF
6851 #define OS_POSIX_SPAWN_METHODDEF
6852#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6853
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006854#ifndef OS_SPAWNV_METHODDEF
6855 #define OS_SPAWNV_METHODDEF
6856#endif /* !defined(OS_SPAWNV_METHODDEF) */
6857
6858#ifndef OS_SPAWNVE_METHODDEF
6859 #define OS_SPAWNVE_METHODDEF
6860#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6861
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006862#ifndef OS_REGISTER_AT_FORK_METHODDEF
6863 #define OS_REGISTER_AT_FORK_METHODDEF
6864#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6865
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006866#ifndef OS_FORK1_METHODDEF
6867 #define OS_FORK1_METHODDEF
6868#endif /* !defined(OS_FORK1_METHODDEF) */
6869
6870#ifndef OS_FORK_METHODDEF
6871 #define OS_FORK_METHODDEF
6872#endif /* !defined(OS_FORK_METHODDEF) */
6873
6874#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6875 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6876#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6877
6878#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6879 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6880#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6881
6882#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6883 #define OS_SCHED_GETSCHEDULER_METHODDEF
6884#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6885
6886#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6887 #define OS_SCHED_SETSCHEDULER_METHODDEF
6888#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6889
6890#ifndef OS_SCHED_GETPARAM_METHODDEF
6891 #define OS_SCHED_GETPARAM_METHODDEF
6892#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6893
6894#ifndef OS_SCHED_SETPARAM_METHODDEF
6895 #define OS_SCHED_SETPARAM_METHODDEF
6896#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6897
6898#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6899 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6900#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6901
6902#ifndef OS_SCHED_YIELD_METHODDEF
6903 #define OS_SCHED_YIELD_METHODDEF
6904#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6905
6906#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6907 #define OS_SCHED_SETAFFINITY_METHODDEF
6908#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6909
6910#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6911 #define OS_SCHED_GETAFFINITY_METHODDEF
6912#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6913
6914#ifndef OS_OPENPTY_METHODDEF
6915 #define OS_OPENPTY_METHODDEF
6916#endif /* !defined(OS_OPENPTY_METHODDEF) */
6917
6918#ifndef OS_FORKPTY_METHODDEF
6919 #define OS_FORKPTY_METHODDEF
6920#endif /* !defined(OS_FORKPTY_METHODDEF) */
6921
6922#ifndef OS_GETEGID_METHODDEF
6923 #define OS_GETEGID_METHODDEF
6924#endif /* !defined(OS_GETEGID_METHODDEF) */
6925
6926#ifndef OS_GETEUID_METHODDEF
6927 #define OS_GETEUID_METHODDEF
6928#endif /* !defined(OS_GETEUID_METHODDEF) */
6929
6930#ifndef OS_GETGID_METHODDEF
6931 #define OS_GETGID_METHODDEF
6932#endif /* !defined(OS_GETGID_METHODDEF) */
6933
Berker Peksag39404992016-09-15 20:45:16 +03006934#ifndef OS_GETPID_METHODDEF
6935 #define OS_GETPID_METHODDEF
6936#endif /* !defined(OS_GETPID_METHODDEF) */
6937
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006938#ifndef OS_GETGROUPS_METHODDEF
6939 #define OS_GETGROUPS_METHODDEF
6940#endif /* !defined(OS_GETGROUPS_METHODDEF) */
6941
6942#ifndef OS_GETPGID_METHODDEF
6943 #define OS_GETPGID_METHODDEF
6944#endif /* !defined(OS_GETPGID_METHODDEF) */
6945
6946#ifndef OS_GETPGRP_METHODDEF
6947 #define OS_GETPGRP_METHODDEF
6948#endif /* !defined(OS_GETPGRP_METHODDEF) */
6949
6950#ifndef OS_SETPGRP_METHODDEF
6951 #define OS_SETPGRP_METHODDEF
6952#endif /* !defined(OS_SETPGRP_METHODDEF) */
6953
6954#ifndef OS_GETPPID_METHODDEF
6955 #define OS_GETPPID_METHODDEF
6956#endif /* !defined(OS_GETPPID_METHODDEF) */
6957
6958#ifndef OS_GETLOGIN_METHODDEF
6959 #define OS_GETLOGIN_METHODDEF
6960#endif /* !defined(OS_GETLOGIN_METHODDEF) */
6961
6962#ifndef OS_GETUID_METHODDEF
6963 #define OS_GETUID_METHODDEF
6964#endif /* !defined(OS_GETUID_METHODDEF) */
6965
6966#ifndef OS_KILL_METHODDEF
6967 #define OS_KILL_METHODDEF
6968#endif /* !defined(OS_KILL_METHODDEF) */
6969
6970#ifndef OS_KILLPG_METHODDEF
6971 #define OS_KILLPG_METHODDEF
6972#endif /* !defined(OS_KILLPG_METHODDEF) */
6973
6974#ifndef OS_PLOCK_METHODDEF
6975 #define OS_PLOCK_METHODDEF
6976#endif /* !defined(OS_PLOCK_METHODDEF) */
6977
6978#ifndef OS_SETUID_METHODDEF
6979 #define OS_SETUID_METHODDEF
6980#endif /* !defined(OS_SETUID_METHODDEF) */
6981
6982#ifndef OS_SETEUID_METHODDEF
6983 #define OS_SETEUID_METHODDEF
6984#endif /* !defined(OS_SETEUID_METHODDEF) */
6985
6986#ifndef OS_SETEGID_METHODDEF
6987 #define OS_SETEGID_METHODDEF
6988#endif /* !defined(OS_SETEGID_METHODDEF) */
6989
6990#ifndef OS_SETREUID_METHODDEF
6991 #define OS_SETREUID_METHODDEF
6992#endif /* !defined(OS_SETREUID_METHODDEF) */
6993
6994#ifndef OS_SETREGID_METHODDEF
6995 #define OS_SETREGID_METHODDEF
6996#endif /* !defined(OS_SETREGID_METHODDEF) */
6997
6998#ifndef OS_SETGID_METHODDEF
6999 #define OS_SETGID_METHODDEF
7000#endif /* !defined(OS_SETGID_METHODDEF) */
7001
7002#ifndef OS_SETGROUPS_METHODDEF
7003 #define OS_SETGROUPS_METHODDEF
7004#endif /* !defined(OS_SETGROUPS_METHODDEF) */
7005
7006#ifndef OS_WAIT3_METHODDEF
7007 #define OS_WAIT3_METHODDEF
7008#endif /* !defined(OS_WAIT3_METHODDEF) */
7009
7010#ifndef OS_WAIT4_METHODDEF
7011 #define OS_WAIT4_METHODDEF
7012#endif /* !defined(OS_WAIT4_METHODDEF) */
7013
7014#ifndef OS_WAITID_METHODDEF
7015 #define OS_WAITID_METHODDEF
7016#endif /* !defined(OS_WAITID_METHODDEF) */
7017
7018#ifndef OS_WAITPID_METHODDEF
7019 #define OS_WAITPID_METHODDEF
7020#endif /* !defined(OS_WAITPID_METHODDEF) */
7021
7022#ifndef OS_WAIT_METHODDEF
7023 #define OS_WAIT_METHODDEF
7024#endif /* !defined(OS_WAIT_METHODDEF) */
7025
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007026#ifndef OS_READLINK_METHODDEF
7027 #define OS_READLINK_METHODDEF
7028#endif /* !defined(OS_READLINK_METHODDEF) */
7029
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007030#ifndef OS_SYMLINK_METHODDEF
7031 #define OS_SYMLINK_METHODDEF
7032#endif /* !defined(OS_SYMLINK_METHODDEF) */
7033
7034#ifndef OS_TIMES_METHODDEF
7035 #define OS_TIMES_METHODDEF
7036#endif /* !defined(OS_TIMES_METHODDEF) */
7037
7038#ifndef OS_GETSID_METHODDEF
7039 #define OS_GETSID_METHODDEF
7040#endif /* !defined(OS_GETSID_METHODDEF) */
7041
7042#ifndef OS_SETSID_METHODDEF
7043 #define OS_SETSID_METHODDEF
7044#endif /* !defined(OS_SETSID_METHODDEF) */
7045
7046#ifndef OS_SETPGID_METHODDEF
7047 #define OS_SETPGID_METHODDEF
7048#endif /* !defined(OS_SETPGID_METHODDEF) */
7049
7050#ifndef OS_TCGETPGRP_METHODDEF
7051 #define OS_TCGETPGRP_METHODDEF
7052#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
7053
7054#ifndef OS_TCSETPGRP_METHODDEF
7055 #define OS_TCSETPGRP_METHODDEF
7056#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
7057
7058#ifndef OS_LOCKF_METHODDEF
7059 #define OS_LOCKF_METHODDEF
7060#endif /* !defined(OS_LOCKF_METHODDEF) */
7061
7062#ifndef OS_READV_METHODDEF
7063 #define OS_READV_METHODDEF
7064#endif /* !defined(OS_READV_METHODDEF) */
7065
7066#ifndef OS_PREAD_METHODDEF
7067 #define OS_PREAD_METHODDEF
7068#endif /* !defined(OS_PREAD_METHODDEF) */
7069
Pablo Galindo4defba32018-01-27 16:16:37 +00007070#ifndef OS_PREADV_METHODDEF
7071 #define OS_PREADV_METHODDEF
7072#endif /* !defined(OS_PREADV_METHODDEF) */
7073
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02007074#ifndef OS__FCOPYFILE_METHODDEF
7075 #define OS__FCOPYFILE_METHODDEF
7076#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
7077
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007078#ifndef OS_PIPE_METHODDEF
7079 #define OS_PIPE_METHODDEF
7080#endif /* !defined(OS_PIPE_METHODDEF) */
7081
7082#ifndef OS_PIPE2_METHODDEF
7083 #define OS_PIPE2_METHODDEF
7084#endif /* !defined(OS_PIPE2_METHODDEF) */
7085
7086#ifndef OS_WRITEV_METHODDEF
7087 #define OS_WRITEV_METHODDEF
7088#endif /* !defined(OS_WRITEV_METHODDEF) */
7089
7090#ifndef OS_PWRITE_METHODDEF
7091 #define OS_PWRITE_METHODDEF
7092#endif /* !defined(OS_PWRITE_METHODDEF) */
7093
Pablo Galindo4defba32018-01-27 16:16:37 +00007094#ifndef OS_PWRITEV_METHODDEF
7095 #define OS_PWRITEV_METHODDEF
7096#endif /* !defined(OS_PWRITEV_METHODDEF) */
7097
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007098#ifndef OS_MKFIFO_METHODDEF
7099 #define OS_MKFIFO_METHODDEF
7100#endif /* !defined(OS_MKFIFO_METHODDEF) */
7101
7102#ifndef OS_MKNOD_METHODDEF
7103 #define OS_MKNOD_METHODDEF
7104#endif /* !defined(OS_MKNOD_METHODDEF) */
7105
7106#ifndef OS_MAJOR_METHODDEF
7107 #define OS_MAJOR_METHODDEF
7108#endif /* !defined(OS_MAJOR_METHODDEF) */
7109
7110#ifndef OS_MINOR_METHODDEF
7111 #define OS_MINOR_METHODDEF
7112#endif /* !defined(OS_MINOR_METHODDEF) */
7113
7114#ifndef OS_MAKEDEV_METHODDEF
7115 #define OS_MAKEDEV_METHODDEF
7116#endif /* !defined(OS_MAKEDEV_METHODDEF) */
7117
7118#ifndef OS_FTRUNCATE_METHODDEF
7119 #define OS_FTRUNCATE_METHODDEF
7120#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
7121
7122#ifndef OS_TRUNCATE_METHODDEF
7123 #define OS_TRUNCATE_METHODDEF
7124#endif /* !defined(OS_TRUNCATE_METHODDEF) */
7125
7126#ifndef OS_POSIX_FALLOCATE_METHODDEF
7127 #define OS_POSIX_FALLOCATE_METHODDEF
7128#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
7129
7130#ifndef OS_POSIX_FADVISE_METHODDEF
7131 #define OS_POSIX_FADVISE_METHODDEF
7132#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
7133
7134#ifndef OS_PUTENV_METHODDEF
7135 #define OS_PUTENV_METHODDEF
7136#endif /* !defined(OS_PUTENV_METHODDEF) */
7137
7138#ifndef OS_UNSETENV_METHODDEF
7139 #define OS_UNSETENV_METHODDEF
7140#endif /* !defined(OS_UNSETENV_METHODDEF) */
7141
7142#ifndef OS_WCOREDUMP_METHODDEF
7143 #define OS_WCOREDUMP_METHODDEF
7144#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
7145
7146#ifndef OS_WIFCONTINUED_METHODDEF
7147 #define OS_WIFCONTINUED_METHODDEF
7148#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
7149
7150#ifndef OS_WIFSTOPPED_METHODDEF
7151 #define OS_WIFSTOPPED_METHODDEF
7152#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
7153
7154#ifndef OS_WIFSIGNALED_METHODDEF
7155 #define OS_WIFSIGNALED_METHODDEF
7156#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
7157
7158#ifndef OS_WIFEXITED_METHODDEF
7159 #define OS_WIFEXITED_METHODDEF
7160#endif /* !defined(OS_WIFEXITED_METHODDEF) */
7161
7162#ifndef OS_WEXITSTATUS_METHODDEF
7163 #define OS_WEXITSTATUS_METHODDEF
7164#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
7165
7166#ifndef OS_WTERMSIG_METHODDEF
7167 #define OS_WTERMSIG_METHODDEF
7168#endif /* !defined(OS_WTERMSIG_METHODDEF) */
7169
7170#ifndef OS_WSTOPSIG_METHODDEF
7171 #define OS_WSTOPSIG_METHODDEF
7172#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
7173
7174#ifndef OS_FSTATVFS_METHODDEF
7175 #define OS_FSTATVFS_METHODDEF
7176#endif /* !defined(OS_FSTATVFS_METHODDEF) */
7177
7178#ifndef OS_STATVFS_METHODDEF
7179 #define OS_STATVFS_METHODDEF
7180#endif /* !defined(OS_STATVFS_METHODDEF) */
7181
7182#ifndef OS__GETDISKUSAGE_METHODDEF
7183 #define OS__GETDISKUSAGE_METHODDEF
7184#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
7185
7186#ifndef OS_FPATHCONF_METHODDEF
7187 #define OS_FPATHCONF_METHODDEF
7188#endif /* !defined(OS_FPATHCONF_METHODDEF) */
7189
7190#ifndef OS_PATHCONF_METHODDEF
7191 #define OS_PATHCONF_METHODDEF
7192#endif /* !defined(OS_PATHCONF_METHODDEF) */
7193
7194#ifndef OS_CONFSTR_METHODDEF
7195 #define OS_CONFSTR_METHODDEF
7196#endif /* !defined(OS_CONFSTR_METHODDEF) */
7197
7198#ifndef OS_SYSCONF_METHODDEF
7199 #define OS_SYSCONF_METHODDEF
7200#endif /* !defined(OS_SYSCONF_METHODDEF) */
7201
Steve Dowercc16be82016-09-08 10:35:16 -07007202#ifndef OS_STARTFILE_METHODDEF
7203 #define OS_STARTFILE_METHODDEF
7204#endif /* !defined(OS_STARTFILE_METHODDEF) */
7205
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007206#ifndef OS_GETLOADAVG_METHODDEF
7207 #define OS_GETLOADAVG_METHODDEF
7208#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
7209
7210#ifndef OS_SETRESUID_METHODDEF
7211 #define OS_SETRESUID_METHODDEF
7212#endif /* !defined(OS_SETRESUID_METHODDEF) */
7213
7214#ifndef OS_SETRESGID_METHODDEF
7215 #define OS_SETRESGID_METHODDEF
7216#endif /* !defined(OS_SETRESGID_METHODDEF) */
7217
7218#ifndef OS_GETRESUID_METHODDEF
7219 #define OS_GETRESUID_METHODDEF
7220#endif /* !defined(OS_GETRESUID_METHODDEF) */
7221
7222#ifndef OS_GETRESGID_METHODDEF
7223 #define OS_GETRESGID_METHODDEF
7224#endif /* !defined(OS_GETRESGID_METHODDEF) */
7225
7226#ifndef OS_GETXATTR_METHODDEF
7227 #define OS_GETXATTR_METHODDEF
7228#endif /* !defined(OS_GETXATTR_METHODDEF) */
7229
7230#ifndef OS_SETXATTR_METHODDEF
7231 #define OS_SETXATTR_METHODDEF
7232#endif /* !defined(OS_SETXATTR_METHODDEF) */
7233
7234#ifndef OS_REMOVEXATTR_METHODDEF
7235 #define OS_REMOVEXATTR_METHODDEF
7236#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
7237
7238#ifndef OS_LISTXATTR_METHODDEF
7239 #define OS_LISTXATTR_METHODDEF
7240#endif /* !defined(OS_LISTXATTR_METHODDEF) */
7241
7242#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
7243 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
7244#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
7245
7246#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
7247 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
7248#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07007249
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007250#ifndef OS_GET_BLOCKING_METHODDEF
7251 #define OS_GET_BLOCKING_METHODDEF
7252#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
7253
7254#ifndef OS_SET_BLOCKING_METHODDEF
7255 #define OS_SET_BLOCKING_METHODDEF
7256#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
7257
Victor Stinner9b1f4742016-09-06 16:18:52 -07007258#ifndef OS_GETRANDOM_METHODDEF
7259 #define OS_GETRANDOM_METHODDEF
7260#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02007261/*[clinic end generated code: output=febc1e16c9024e40 input=a9049054013a1b77]*/