blob: ce17709c38ba2c4b05c8278dffc6a2fa1321be12 [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
Joannah Nanjekye92b83222019-01-16 16:29:26 +03001794#if defined(HAVE_POSIX_SPAWNP)
1795
1796PyDoc_STRVAR(os_posix_spawnp__doc__,
1797"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
1798" setpgroup=None, resetids=False, setsigmask=(),\n"
1799" setsigdef=(), scheduler=None)\n"
1800"--\n"
1801"\n"
1802"Execute the program specified by path in a new process.\n"
1803"\n"
1804" path\n"
1805" Path of executable file.\n"
1806" argv\n"
1807" Tuple or list of strings.\n"
1808" env\n"
1809" Dictionary of strings mapping to strings.\n"
1810" file_actions\n"
1811" A sequence of file action tuples.\n"
1812" setpgroup\n"
1813" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
1814" resetids\n"
1815" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
1816" setsigmask\n"
1817" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
1818" setsigdef\n"
1819" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
1820" scheduler\n"
1821" A tuple with the scheduler policy (optional) and parameters.");
1822
1823#define OS_POSIX_SPAWNP_METHODDEF \
1824 {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
1825
1826static PyObject *
1827os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
1828 PyObject *env, PyObject *file_actions,
1829 PyObject *setpgroup, int resetids, PyObject *setsigmask,
1830 PyObject *setsigdef, PyObject *scheduler);
1831
1832static PyObject *
1833os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1834{
1835 PyObject *return_value = NULL;
1836 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsigmask", "setsigdef", "scheduler", NULL};
1837 static _PyArg_Parser _parser = {"O&OO|$OOiOOO:posix_spawnp", _keywords, 0};
1838 path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0);
1839 PyObject *argv;
1840 PyObject *env;
1841 PyObject *file_actions = NULL;
1842 PyObject *setpgroup = NULL;
1843 int resetids = 0;
1844 PyObject *setsigmask = NULL;
1845 PyObject *setsigdef = NULL;
1846 PyObject *scheduler = NULL;
1847
1848 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
1849 path_converter, &path, &argv, &env, &file_actions, &setpgroup, &resetids, &setsigmask, &setsigdef, &scheduler)) {
1850 goto exit;
1851 }
1852 return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsigmask, setsigdef, scheduler);
1853
1854exit:
1855 /* Cleanup for path */
1856 path_cleanup(&path);
1857
1858 return return_value;
1859}
1860
1861#endif /* defined(HAVE_POSIX_SPAWNP) */
1862
Steve Dowercc16be82016-09-08 10:35:16 -07001863#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001864
1865PyDoc_STRVAR(os_spawnv__doc__,
1866"spawnv($module, mode, path, argv, /)\n"
1867"--\n"
1868"\n"
1869"Execute the program specified by path in a new process.\n"
1870"\n"
1871" mode\n"
1872" Mode of process creation.\n"
1873" path\n"
1874" Path of executable file.\n"
1875" argv\n"
1876" Tuple or list of strings.");
1877
1878#define OS_SPAWNV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001879 {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001880
1881static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001882os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001883
1884static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001885os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001886{
1887 PyObject *return_value = NULL;
1888 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001889 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001890 PyObject *argv;
1891
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001892 if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001893 goto exit;
1894 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001895 if (PyFloat_Check(args[0])) {
1896 PyErr_SetString(PyExc_TypeError,
1897 "integer argument expected, got float" );
1898 goto exit;
1899 }
1900 mode = _PyLong_AsInt(args[0]);
1901 if (mode == -1 && PyErr_Occurred()) {
1902 goto exit;
1903 }
1904 if (!path_converter(args[1], &path)) {
1905 goto exit;
1906 }
1907 argv = args[2];
Steve Dowercc16be82016-09-08 10:35:16 -07001908 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001909
1910exit:
1911 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001912 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001913
1914 return return_value;
1915}
1916
Steve Dowercc16be82016-09-08 10:35:16 -07001917#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001918
Steve Dowercc16be82016-09-08 10:35:16 -07001919#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001920
1921PyDoc_STRVAR(os_spawnve__doc__,
1922"spawnve($module, mode, path, argv, env, /)\n"
1923"--\n"
1924"\n"
1925"Execute the program specified by path in a new process.\n"
1926"\n"
1927" mode\n"
1928" Mode of process creation.\n"
1929" path\n"
1930" Path of executable file.\n"
1931" argv\n"
1932" Tuple or list of strings.\n"
1933" env\n"
1934" Dictionary of strings mapping to strings.");
1935
1936#define OS_SPAWNVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001937 {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001938
1939static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07001940os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001941 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001942
1943static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001944os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001945{
1946 PyObject *return_value = NULL;
1947 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07001948 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001949 PyObject *argv;
1950 PyObject *env;
1951
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001952 if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001953 goto exit;
1954 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001955 if (PyFloat_Check(args[0])) {
1956 PyErr_SetString(PyExc_TypeError,
1957 "integer argument expected, got float" );
1958 goto exit;
1959 }
1960 mode = _PyLong_AsInt(args[0]);
1961 if (mode == -1 && PyErr_Occurred()) {
1962 goto exit;
1963 }
1964 if (!path_converter(args[1], &path)) {
1965 goto exit;
1966 }
1967 argv = args[2];
1968 env = args[3];
Steve Dowercc16be82016-09-08 10:35:16 -07001969 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001970
1971exit:
1972 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07001973 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001974
1975 return return_value;
1976}
1977
Steve Dowercc16be82016-09-08 10:35:16 -07001978#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001979
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001980#if defined(HAVE_FORK)
1981
1982PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07001983"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
1984" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001985"--\n"
1986"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001987"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001988"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001989" before\n"
1990" A callable to be called in the parent before the fork() syscall.\n"
1991" after_in_child\n"
1992" A callable to be called in the child after fork().\n"
1993" after_in_parent\n"
1994" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001995"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07001996"\'before\' callbacks are called in reverse order.\n"
1997"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02001998
1999#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002000 {"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 +02002001
2002static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07002003os_register_at_fork_impl(PyObject *module, PyObject *before,
2004 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002005
2006static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002007os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002008{
2009 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07002010 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
2011 static _PyArg_Parser _parser = {"|$OOO:register_at_fork", _keywords, 0};
2012 PyObject *before = NULL;
2013 PyObject *after_in_child = NULL;
2014 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002015
2016 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Gregory P. Smith163468a2017-05-29 10:03:41 -07002017 &before, &after_in_child, &after_in_parent)) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002018 goto exit;
2019 }
Gregory P. Smith163468a2017-05-29 10:03:41 -07002020 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002021
2022exit:
2023 return return_value;
2024}
2025
2026#endif /* defined(HAVE_FORK) */
2027
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002028#if defined(HAVE_FORK1)
2029
2030PyDoc_STRVAR(os_fork1__doc__,
2031"fork1($module, /)\n"
2032"--\n"
2033"\n"
2034"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
2035"\n"
2036"Return 0 to child process and PID of child to parent process.");
2037
2038#define OS_FORK1_METHODDEF \
2039 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
2040
2041static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002042os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002043
2044static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002045os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002046{
2047 return os_fork1_impl(module);
2048}
2049
2050#endif /* defined(HAVE_FORK1) */
2051
2052#if defined(HAVE_FORK)
2053
2054PyDoc_STRVAR(os_fork__doc__,
2055"fork($module, /)\n"
2056"--\n"
2057"\n"
2058"Fork a child process.\n"
2059"\n"
2060"Return 0 to child process and PID of child to parent process.");
2061
2062#define OS_FORK_METHODDEF \
2063 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
2064
2065static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002066os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002067
2068static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002069os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002070{
2071 return os_fork_impl(module);
2072}
2073
2074#endif /* defined(HAVE_FORK) */
2075
2076#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2077
2078PyDoc_STRVAR(os_sched_get_priority_max__doc__,
2079"sched_get_priority_max($module, /, policy)\n"
2080"--\n"
2081"\n"
2082"Get the maximum scheduling priority for policy.");
2083
2084#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002085 {"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 +03002086
2087static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002088os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002089
2090static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002091os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002092{
2093 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002094 static const char * const _keywords[] = {"policy", NULL};
2095 static _PyArg_Parser _parser = {"i:sched_get_priority_max", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002096 int policy;
2097
Victor Stinner3e1fad62017-01-17 01:29:01 +01002098 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002099 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002100 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002101 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002102 return_value = os_sched_get_priority_max_impl(module, policy);
2103
2104exit:
2105 return return_value;
2106}
2107
2108#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2109
2110#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2111
2112PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2113"sched_get_priority_min($module, /, policy)\n"
2114"--\n"
2115"\n"
2116"Get the minimum scheduling priority for policy.");
2117
2118#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002119 {"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 +03002120
2121static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002122os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002123
2124static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002125os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002126{
2127 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002128 static const char * const _keywords[] = {"policy", NULL};
2129 static _PyArg_Parser _parser = {"i:sched_get_priority_min", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002130 int policy;
2131
Victor Stinner3e1fad62017-01-17 01:29:01 +01002132 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002133 &policy)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002134 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002135 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002136 return_value = os_sched_get_priority_min_impl(module, policy);
2137
2138exit:
2139 return return_value;
2140}
2141
2142#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2143
2144#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2145
2146PyDoc_STRVAR(os_sched_getscheduler__doc__,
2147"sched_getscheduler($module, pid, /)\n"
2148"--\n"
2149"\n"
2150"Get the scheduling policy for the process identifiedy by pid.\n"
2151"\n"
2152"Passing 0 for pid returns the scheduling policy for the calling process.");
2153
2154#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002155 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002156
2157static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002158os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002159
2160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002161os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002162{
2163 PyObject *return_value = NULL;
2164 pid_t pid;
2165
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002166 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002167 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002168 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002169 return_value = os_sched_getscheduler_impl(module, pid);
2170
2171exit:
2172 return return_value;
2173}
2174
2175#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2176
William Orr81574b82018-10-01 22:19:56 -07002177#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 +03002178
2179PyDoc_STRVAR(os_sched_param__doc__,
2180"sched_param(sched_priority)\n"
2181"--\n"
2182"\n"
2183"Current has only one field: sched_priority\");\n"
2184"\n"
2185" sched_priority\n"
2186" A scheduling parameter.");
2187
2188static PyObject *
2189os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2190
2191static PyObject *
2192os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2193{
2194 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002195 static const char * const _keywords[] = {"sched_priority", NULL};
2196 static _PyArg_Parser _parser = {"O:sched_param", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002197 PyObject *sched_priority;
2198
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002199 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002200 &sched_priority)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002201 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002202 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002203 return_value = os_sched_param_impl(type, sched_priority);
2204
2205exit:
2206 return return_value;
2207}
2208
William Orr81574b82018-10-01 22:19:56 -07002209#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 +03002210
2211#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2212
2213PyDoc_STRVAR(os_sched_setscheduler__doc__,
2214"sched_setscheduler($module, pid, policy, param, /)\n"
2215"--\n"
2216"\n"
2217"Set the scheduling policy for the process identified by pid.\n"
2218"\n"
2219"If pid is 0, the calling process is changed.\n"
2220"param is an instance of sched_param.");
2221
2222#define OS_SCHED_SETSCHEDULER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002223 {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002224
2225static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002226os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002227 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002228
2229static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002230os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002231{
2232 PyObject *return_value = NULL;
2233 pid_t pid;
2234 int policy;
2235 struct sched_param param;
2236
Sylvain74453812017-06-10 06:51:48 +02002237 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2238 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002239 goto exit;
2240 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002241 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2242
2243exit:
2244 return return_value;
2245}
2246
2247#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2248
2249#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2250
2251PyDoc_STRVAR(os_sched_getparam__doc__,
2252"sched_getparam($module, pid, /)\n"
2253"--\n"
2254"\n"
2255"Returns scheduling parameters for the process identified by pid.\n"
2256"\n"
2257"If pid is 0, returns parameters for the calling process.\n"
2258"Return value is an instance of sched_param.");
2259
2260#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002261 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002262
2263static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002264os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002265
2266static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002267os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002268{
2269 PyObject *return_value = NULL;
2270 pid_t pid;
2271
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002272 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002273 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002274 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002275 return_value = os_sched_getparam_impl(module, pid);
2276
2277exit:
2278 return return_value;
2279}
2280
2281#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2282
2283#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2284
2285PyDoc_STRVAR(os_sched_setparam__doc__,
2286"sched_setparam($module, pid, param, /)\n"
2287"--\n"
2288"\n"
2289"Set scheduling parameters for the process identified by pid.\n"
2290"\n"
2291"If pid is 0, sets parameters for the calling process.\n"
2292"param should be an instance of sched_param.");
2293
2294#define OS_SCHED_SETPARAM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002295 {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002296
2297static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002298os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002299 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002300
2301static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002302os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002303{
2304 PyObject *return_value = NULL;
2305 pid_t pid;
2306 struct sched_param param;
2307
Sylvain74453812017-06-10 06:51:48 +02002308 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2309 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002310 goto exit;
2311 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002312 return_value = os_sched_setparam_impl(module, pid, &param);
2313
2314exit:
2315 return return_value;
2316}
2317
2318#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2319
2320#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2321
2322PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2323"sched_rr_get_interval($module, pid, /)\n"
2324"--\n"
2325"\n"
2326"Return the round-robin quantum for the process identified by pid, in seconds.\n"
2327"\n"
2328"Value returned is a float.");
2329
2330#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002331 {"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 +03002332
2333static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002334os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002335
2336static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002337os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002338{
2339 PyObject *return_value = NULL;
2340 pid_t pid;
2341 double _return_value;
2342
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002343 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002344 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002345 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002346 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002347 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002348 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002349 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002350 return_value = PyFloat_FromDouble(_return_value);
2351
2352exit:
2353 return return_value;
2354}
2355
2356#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
2357
2358#if defined(HAVE_SCHED_H)
2359
2360PyDoc_STRVAR(os_sched_yield__doc__,
2361"sched_yield($module, /)\n"
2362"--\n"
2363"\n"
2364"Voluntarily relinquish the CPU.");
2365
2366#define OS_SCHED_YIELD_METHODDEF \
2367 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
2368
2369static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002370os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002371
2372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002373os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002374{
2375 return os_sched_yield_impl(module);
2376}
2377
2378#endif /* defined(HAVE_SCHED_H) */
2379
2380#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2381
2382PyDoc_STRVAR(os_sched_setaffinity__doc__,
2383"sched_setaffinity($module, pid, mask, /)\n"
2384"--\n"
2385"\n"
2386"Set the CPU affinity of the process identified by pid to mask.\n"
2387"\n"
2388"mask should be an iterable of integers identifying CPUs.");
2389
2390#define OS_SCHED_SETAFFINITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002391 {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002392
2393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002394os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002395
2396static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002397os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002398{
2399 PyObject *return_value = NULL;
2400 pid_t pid;
2401 PyObject *mask;
2402
Sylvain74453812017-06-10 06:51:48 +02002403 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
2404 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002405 goto exit;
2406 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002407 return_value = os_sched_setaffinity_impl(module, pid, mask);
2408
2409exit:
2410 return return_value;
2411}
2412
2413#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2414
2415#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
2416
2417PyDoc_STRVAR(os_sched_getaffinity__doc__,
2418"sched_getaffinity($module, pid, /)\n"
2419"--\n"
2420"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01002421"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002422"\n"
2423"The affinity is returned as a set of CPU identifiers.");
2424
2425#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002426 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002427
2428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002429os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002430
2431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002432os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002433{
2434 PyObject *return_value = NULL;
2435 pid_t pid;
2436
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002437 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002438 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002440 return_value = os_sched_getaffinity_impl(module, pid);
2441
2442exit:
2443 return return_value;
2444}
2445
2446#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
2447
2448#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
2449
2450PyDoc_STRVAR(os_openpty__doc__,
2451"openpty($module, /)\n"
2452"--\n"
2453"\n"
2454"Open a pseudo-terminal.\n"
2455"\n"
2456"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
2457"for both the master and slave ends.");
2458
2459#define OS_OPENPTY_METHODDEF \
2460 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
2461
2462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002463os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002464
2465static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002466os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002467{
2468 return os_openpty_impl(module);
2469}
2470
2471#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
2472
2473#if defined(HAVE_FORKPTY)
2474
2475PyDoc_STRVAR(os_forkpty__doc__,
2476"forkpty($module, /)\n"
2477"--\n"
2478"\n"
2479"Fork a new process with a new pseudo-terminal as controlling tty.\n"
2480"\n"
2481"Returns a tuple of (pid, master_fd).\n"
2482"Like fork(), return pid of 0 to the child process,\n"
2483"and pid of child to the parent process.\n"
2484"To both, return fd of newly opened pseudo-terminal.");
2485
2486#define OS_FORKPTY_METHODDEF \
2487 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
2488
2489static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002490os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002491
2492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002493os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002494{
2495 return os_forkpty_impl(module);
2496}
2497
2498#endif /* defined(HAVE_FORKPTY) */
2499
2500#if defined(HAVE_GETEGID)
2501
2502PyDoc_STRVAR(os_getegid__doc__,
2503"getegid($module, /)\n"
2504"--\n"
2505"\n"
2506"Return the current process\'s effective group id.");
2507
2508#define OS_GETEGID_METHODDEF \
2509 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
2510
2511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002512os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002513
2514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002515os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002516{
2517 return os_getegid_impl(module);
2518}
2519
2520#endif /* defined(HAVE_GETEGID) */
2521
2522#if defined(HAVE_GETEUID)
2523
2524PyDoc_STRVAR(os_geteuid__doc__,
2525"geteuid($module, /)\n"
2526"--\n"
2527"\n"
2528"Return the current process\'s effective user id.");
2529
2530#define OS_GETEUID_METHODDEF \
2531 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
2532
2533static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002534os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002535
2536static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002537os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002538{
2539 return os_geteuid_impl(module);
2540}
2541
2542#endif /* defined(HAVE_GETEUID) */
2543
2544#if defined(HAVE_GETGID)
2545
2546PyDoc_STRVAR(os_getgid__doc__,
2547"getgid($module, /)\n"
2548"--\n"
2549"\n"
2550"Return the current process\'s group id.");
2551
2552#define OS_GETGID_METHODDEF \
2553 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
2554
2555static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002556os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002557
2558static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002559os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002560{
2561 return os_getgid_impl(module);
2562}
2563
2564#endif /* defined(HAVE_GETGID) */
2565
Berker Peksag39404992016-09-15 20:45:16 +03002566#if defined(HAVE_GETPID)
2567
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002568PyDoc_STRVAR(os_getpid__doc__,
2569"getpid($module, /)\n"
2570"--\n"
2571"\n"
2572"Return the current process id.");
2573
2574#define OS_GETPID_METHODDEF \
2575 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
2576
2577static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002578os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002579
2580static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002581os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002582{
2583 return os_getpid_impl(module);
2584}
2585
Berker Peksag39404992016-09-15 20:45:16 +03002586#endif /* defined(HAVE_GETPID) */
2587
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002588#if defined(HAVE_GETGROUPS)
2589
2590PyDoc_STRVAR(os_getgroups__doc__,
2591"getgroups($module, /)\n"
2592"--\n"
2593"\n"
2594"Return list of supplemental group IDs for the process.");
2595
2596#define OS_GETGROUPS_METHODDEF \
2597 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
2598
2599static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002600os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002601
2602static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002603os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002604{
2605 return os_getgroups_impl(module);
2606}
2607
2608#endif /* defined(HAVE_GETGROUPS) */
2609
2610#if defined(HAVE_GETPGID)
2611
2612PyDoc_STRVAR(os_getpgid__doc__,
2613"getpgid($module, /, pid)\n"
2614"--\n"
2615"\n"
2616"Call the system call getpgid(), and return the result.");
2617
2618#define OS_GETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002619 {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002620
2621static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002622os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002623
2624static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002625os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002626{
2627 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002628 static const char * const _keywords[] = {"pid", NULL};
2629 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002630 pid_t pid;
2631
Victor Stinner3e1fad62017-01-17 01:29:01 +01002632 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002633 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002634 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002635 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002636 return_value = os_getpgid_impl(module, pid);
2637
2638exit:
2639 return return_value;
2640}
2641
2642#endif /* defined(HAVE_GETPGID) */
2643
2644#if defined(HAVE_GETPGRP)
2645
2646PyDoc_STRVAR(os_getpgrp__doc__,
2647"getpgrp($module, /)\n"
2648"--\n"
2649"\n"
2650"Return the current process group id.");
2651
2652#define OS_GETPGRP_METHODDEF \
2653 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
2654
2655static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002656os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002657
2658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002659os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002660{
2661 return os_getpgrp_impl(module);
2662}
2663
2664#endif /* defined(HAVE_GETPGRP) */
2665
2666#if defined(HAVE_SETPGRP)
2667
2668PyDoc_STRVAR(os_setpgrp__doc__,
2669"setpgrp($module, /)\n"
2670"--\n"
2671"\n"
2672"Make the current process the leader of its process group.");
2673
2674#define OS_SETPGRP_METHODDEF \
2675 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
2676
2677static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002678os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002679
2680static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002681os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002682{
2683 return os_setpgrp_impl(module);
2684}
2685
2686#endif /* defined(HAVE_SETPGRP) */
2687
2688#if defined(HAVE_GETPPID)
2689
2690PyDoc_STRVAR(os_getppid__doc__,
2691"getppid($module, /)\n"
2692"--\n"
2693"\n"
2694"Return the parent\'s process id.\n"
2695"\n"
2696"If the parent process has already exited, Windows machines will still\n"
2697"return its id; others systems will return the id of the \'init\' process (1).");
2698
2699#define OS_GETPPID_METHODDEF \
2700 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
2701
2702static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002703os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002704
2705static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002706os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002707{
2708 return os_getppid_impl(module);
2709}
2710
2711#endif /* defined(HAVE_GETPPID) */
2712
2713#if defined(HAVE_GETLOGIN)
2714
2715PyDoc_STRVAR(os_getlogin__doc__,
2716"getlogin($module, /)\n"
2717"--\n"
2718"\n"
2719"Return the actual login name.");
2720
2721#define OS_GETLOGIN_METHODDEF \
2722 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
2723
2724static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002725os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002726
2727static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002728os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002729{
2730 return os_getlogin_impl(module);
2731}
2732
2733#endif /* defined(HAVE_GETLOGIN) */
2734
2735#if defined(HAVE_GETUID)
2736
2737PyDoc_STRVAR(os_getuid__doc__,
2738"getuid($module, /)\n"
2739"--\n"
2740"\n"
2741"Return the current process\'s user id.");
2742
2743#define OS_GETUID_METHODDEF \
2744 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
2745
2746static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002747os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002748
2749static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002750os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002751{
2752 return os_getuid_impl(module);
2753}
2754
2755#endif /* defined(HAVE_GETUID) */
2756
2757#if defined(HAVE_KILL)
2758
2759PyDoc_STRVAR(os_kill__doc__,
2760"kill($module, pid, signal, /)\n"
2761"--\n"
2762"\n"
2763"Kill a process with a signal.");
2764
2765#define OS_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002766 {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002767
2768static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002769os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002770
2771static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002772os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002773{
2774 PyObject *return_value = NULL;
2775 pid_t pid;
2776 Py_ssize_t signal;
2777
Sylvain74453812017-06-10 06:51:48 +02002778 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
2779 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002780 goto exit;
2781 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002782 return_value = os_kill_impl(module, pid, signal);
2783
2784exit:
2785 return return_value;
2786}
2787
2788#endif /* defined(HAVE_KILL) */
2789
2790#if defined(HAVE_KILLPG)
2791
2792PyDoc_STRVAR(os_killpg__doc__,
2793"killpg($module, pgid, signal, /)\n"
2794"--\n"
2795"\n"
2796"Kill a process group with a signal.");
2797
2798#define OS_KILLPG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002799 {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002800
2801static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002802os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002803
2804static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002805os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002806{
2807 PyObject *return_value = NULL;
2808 pid_t pgid;
2809 int signal;
2810
Sylvain74453812017-06-10 06:51:48 +02002811 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
2812 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002813 goto exit;
2814 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002815 return_value = os_killpg_impl(module, pgid, signal);
2816
2817exit:
2818 return return_value;
2819}
2820
2821#endif /* defined(HAVE_KILLPG) */
2822
2823#if defined(HAVE_PLOCK)
2824
2825PyDoc_STRVAR(os_plock__doc__,
2826"plock($module, op, /)\n"
2827"--\n"
2828"\n"
2829"Lock program segments into memory.\");");
2830
2831#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002832 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002833
2834static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002835os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002836
2837static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002838os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002839{
2840 PyObject *return_value = NULL;
2841 int op;
2842
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002843 if (PyFloat_Check(arg)) {
2844 PyErr_SetString(PyExc_TypeError,
2845 "integer argument expected, got float" );
2846 goto exit;
2847 }
2848 op = _PyLong_AsInt(arg);
2849 if (op == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002850 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002851 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002852 return_value = os_plock_impl(module, op);
2853
2854exit:
2855 return return_value;
2856}
2857
2858#endif /* defined(HAVE_PLOCK) */
2859
2860#if defined(HAVE_SETUID)
2861
2862PyDoc_STRVAR(os_setuid__doc__,
2863"setuid($module, uid, /)\n"
2864"--\n"
2865"\n"
2866"Set the current process\'s user id.");
2867
2868#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002869 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002870
2871static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002872os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002873
2874static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002875os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002876{
2877 PyObject *return_value = NULL;
2878 uid_t uid;
2879
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002880 if (!_Py_Uid_Converter(arg, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002881 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002882 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002883 return_value = os_setuid_impl(module, uid);
2884
2885exit:
2886 return return_value;
2887}
2888
2889#endif /* defined(HAVE_SETUID) */
2890
2891#if defined(HAVE_SETEUID)
2892
2893PyDoc_STRVAR(os_seteuid__doc__,
2894"seteuid($module, euid, /)\n"
2895"--\n"
2896"\n"
2897"Set the current process\'s effective user id.");
2898
2899#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002900 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002901
2902static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002903os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002904
2905static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002906os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002907{
2908 PyObject *return_value = NULL;
2909 uid_t euid;
2910
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002911 if (!_Py_Uid_Converter(arg, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002912 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002913 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002914 return_value = os_seteuid_impl(module, euid);
2915
2916exit:
2917 return return_value;
2918}
2919
2920#endif /* defined(HAVE_SETEUID) */
2921
2922#if defined(HAVE_SETEGID)
2923
2924PyDoc_STRVAR(os_setegid__doc__,
2925"setegid($module, egid, /)\n"
2926"--\n"
2927"\n"
2928"Set the current process\'s effective group id.");
2929
2930#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002931 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002932
2933static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002934os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002935
2936static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002937os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002938{
2939 PyObject *return_value = NULL;
2940 gid_t egid;
2941
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002942 if (!_Py_Gid_Converter(arg, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002943 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002945 return_value = os_setegid_impl(module, egid);
2946
2947exit:
2948 return return_value;
2949}
2950
2951#endif /* defined(HAVE_SETEGID) */
2952
2953#if defined(HAVE_SETREUID)
2954
2955PyDoc_STRVAR(os_setreuid__doc__,
2956"setreuid($module, ruid, euid, /)\n"
2957"--\n"
2958"\n"
2959"Set the current process\'s real and effective user ids.");
2960
2961#define OS_SETREUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002962 {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002963
2964static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002965os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002966
2967static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002968os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002969{
2970 PyObject *return_value = NULL;
2971 uid_t ruid;
2972 uid_t euid;
2973
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002974 if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
2975 goto exit;
2976 }
2977 if (!_Py_Uid_Converter(args[0], &ruid)) {
2978 goto exit;
2979 }
2980 if (!_Py_Uid_Converter(args[1], &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002981 goto exit;
2982 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002983 return_value = os_setreuid_impl(module, ruid, euid);
2984
2985exit:
2986 return return_value;
2987}
2988
2989#endif /* defined(HAVE_SETREUID) */
2990
2991#if defined(HAVE_SETREGID)
2992
2993PyDoc_STRVAR(os_setregid__doc__,
2994"setregid($module, rgid, egid, /)\n"
2995"--\n"
2996"\n"
2997"Set the current process\'s real and effective group ids.");
2998
2999#define OS_SETREGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003000 {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003001
3002static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003003os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003004
3005static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003006os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003007{
3008 PyObject *return_value = NULL;
3009 gid_t rgid;
3010 gid_t egid;
3011
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003012 if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
3013 goto exit;
3014 }
3015 if (!_Py_Gid_Converter(args[0], &rgid)) {
3016 goto exit;
3017 }
3018 if (!_Py_Gid_Converter(args[1], &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003019 goto exit;
3020 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003021 return_value = os_setregid_impl(module, rgid, egid);
3022
3023exit:
3024 return return_value;
3025}
3026
3027#endif /* defined(HAVE_SETREGID) */
3028
3029#if defined(HAVE_SETGID)
3030
3031PyDoc_STRVAR(os_setgid__doc__,
3032"setgid($module, gid, /)\n"
3033"--\n"
3034"\n"
3035"Set the current process\'s group id.");
3036
3037#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003038 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003039
3040static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003041os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003042
3043static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003044os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003045{
3046 PyObject *return_value = NULL;
3047 gid_t gid;
3048
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003049 if (!_Py_Gid_Converter(arg, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003050 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003051 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003052 return_value = os_setgid_impl(module, gid);
3053
3054exit:
3055 return return_value;
3056}
3057
3058#endif /* defined(HAVE_SETGID) */
3059
3060#if defined(HAVE_SETGROUPS)
3061
3062PyDoc_STRVAR(os_setgroups__doc__,
3063"setgroups($module, groups, /)\n"
3064"--\n"
3065"\n"
3066"Set the groups of the current process to list.");
3067
3068#define OS_SETGROUPS_METHODDEF \
3069 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
3070
3071#endif /* defined(HAVE_SETGROUPS) */
3072
3073#if defined(HAVE_WAIT3)
3074
3075PyDoc_STRVAR(os_wait3__doc__,
3076"wait3($module, /, options)\n"
3077"--\n"
3078"\n"
3079"Wait for completion of a child process.\n"
3080"\n"
3081"Returns a tuple of information about the child process:\n"
3082" (pid, status, rusage)");
3083
3084#define OS_WAIT3_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003085 {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003086
3087static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003088os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003089
3090static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003091os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003092{
3093 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003094 static const char * const _keywords[] = {"options", NULL};
3095 static _PyArg_Parser _parser = {"i:wait3", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003096 int options;
3097
Victor Stinner3e1fad62017-01-17 01:29:01 +01003098 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003099 &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003100 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003101 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003102 return_value = os_wait3_impl(module, options);
3103
3104exit:
3105 return return_value;
3106}
3107
3108#endif /* defined(HAVE_WAIT3) */
3109
3110#if defined(HAVE_WAIT4)
3111
3112PyDoc_STRVAR(os_wait4__doc__,
3113"wait4($module, /, pid, options)\n"
3114"--\n"
3115"\n"
3116"Wait for completion of a specific child process.\n"
3117"\n"
3118"Returns a tuple of information about the child process:\n"
3119" (pid, status, rusage)");
3120
3121#define OS_WAIT4_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003122 {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003123
3124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003125os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003126
3127static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003128os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003129{
3130 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003131 static const char * const _keywords[] = {"pid", "options", NULL};
3132 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003133 pid_t pid;
3134 int options;
3135
Victor Stinner3e1fad62017-01-17 01:29:01 +01003136 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003137 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003138 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003139 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003140 return_value = os_wait4_impl(module, pid, options);
3141
3142exit:
3143 return return_value;
3144}
3145
3146#endif /* defined(HAVE_WAIT4) */
3147
3148#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3149
3150PyDoc_STRVAR(os_waitid__doc__,
3151"waitid($module, idtype, id, options, /)\n"
3152"--\n"
3153"\n"
3154"Returns the result of waiting for a process or processes.\n"
3155"\n"
3156" idtype\n"
3157" Must be one of be P_PID, P_PGID or P_ALL.\n"
3158" id\n"
3159" The id to wait on.\n"
3160" options\n"
3161" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3162" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3163"\n"
3164"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3165"no children in a waitable state.");
3166
3167#define OS_WAITID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003168 {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003169
3170static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003171os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003172
3173static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003174os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003175{
3176 PyObject *return_value = NULL;
3177 idtype_t idtype;
3178 id_t id;
3179 int options;
3180
Sylvain74453812017-06-10 06:51:48 +02003181 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3182 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003183 goto exit;
3184 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003185 return_value = os_waitid_impl(module, idtype, id, options);
3186
3187exit:
3188 return return_value;
3189}
3190
3191#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3192
3193#if defined(HAVE_WAITPID)
3194
3195PyDoc_STRVAR(os_waitpid__doc__,
3196"waitpid($module, pid, options, /)\n"
3197"--\n"
3198"\n"
3199"Wait for completion of a given child process.\n"
3200"\n"
3201"Returns a tuple of information regarding the child process:\n"
3202" (pid, status)\n"
3203"\n"
3204"The options argument is ignored on Windows.");
3205
3206#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003207 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003208
3209static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003210os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003211
3212static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003213os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003214{
3215 PyObject *return_value = NULL;
3216 pid_t pid;
3217 int options;
3218
Sylvain74453812017-06-10 06:51:48 +02003219 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3220 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003221 goto exit;
3222 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003223 return_value = os_waitpid_impl(module, pid, options);
3224
3225exit:
3226 return return_value;
3227}
3228
3229#endif /* defined(HAVE_WAITPID) */
3230
3231#if defined(HAVE_CWAIT)
3232
3233PyDoc_STRVAR(os_waitpid__doc__,
3234"waitpid($module, pid, options, /)\n"
3235"--\n"
3236"\n"
3237"Wait for completion of a given process.\n"
3238"\n"
3239"Returns a tuple of information regarding the process:\n"
3240" (pid, status << 8)\n"
3241"\n"
3242"The options argument is ignored on Windows.");
3243
3244#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003245 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003246
3247static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003248os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003249
3250static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003251os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003252{
3253 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003254 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003255 int options;
3256
Sylvain74453812017-06-10 06:51:48 +02003257 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3258 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003259 goto exit;
3260 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003261 return_value = os_waitpid_impl(module, pid, options);
3262
3263exit:
3264 return return_value;
3265}
3266
3267#endif /* defined(HAVE_CWAIT) */
3268
3269#if defined(HAVE_WAIT)
3270
3271PyDoc_STRVAR(os_wait__doc__,
3272"wait($module, /)\n"
3273"--\n"
3274"\n"
3275"Wait for completion of a child process.\n"
3276"\n"
3277"Returns a tuple of information about the child process:\n"
3278" (pid, status)");
3279
3280#define OS_WAIT_METHODDEF \
3281 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3282
3283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003284os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003285
3286static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003287os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003288{
3289 return os_wait_impl(module);
3290}
3291
3292#endif /* defined(HAVE_WAIT) */
3293
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003294#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3295
3296PyDoc_STRVAR(os_readlink__doc__,
3297"readlink($module, /, path, *, dir_fd=None)\n"
3298"--\n"
3299"\n"
3300"Return a string representing the path to which the symbolic link points.\n"
3301"\n"
3302"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3303"and path should be relative; path will then be relative to that directory.\n"
3304"\n"
3305"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3306"using it will raise a NotImplementedError.");
3307
3308#define OS_READLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003309 {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003310
3311static PyObject *
3312os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3313
3314static PyObject *
3315os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3316{
3317 PyObject *return_value = NULL;
3318 static const char * const _keywords[] = {"path", "dir_fd", NULL};
3319 static _PyArg_Parser _parser = {"O&|$O&:readlink", _keywords, 0};
3320 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
3321 int dir_fd = DEFAULT_DIR_FD;
3322
3323 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
3324 path_converter, &path, READLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
3325 goto exit;
3326 }
3327 return_value = os_readlink_impl(module, &path, dir_fd);
3328
3329exit:
3330 /* Cleanup for path */
3331 path_cleanup(&path);
3332
3333 return return_value;
3334}
3335
3336#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
3337
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003338#if defined(HAVE_SYMLINK)
3339
3340PyDoc_STRVAR(os_symlink__doc__,
3341"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
3342"--\n"
3343"\n"
3344"Create a symbolic link pointing to src named dst.\n"
3345"\n"
3346"target_is_directory is required on Windows if the target is to be\n"
3347" interpreted as a directory. (On Windows, symlink requires\n"
3348" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
3349" target_is_directory is ignored on non-Windows platforms.\n"
3350"\n"
3351"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3352" and path should be relative; path will then be relative to that directory.\n"
3353"dir_fd may not be implemented on your platform.\n"
3354" If it is unavailable, using it will raise a NotImplementedError.");
3355
3356#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003357 {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003358
3359static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003360os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04003361 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003362
3363static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003364os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003365{
3366 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003367 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
3368 static _PyArg_Parser _parser = {"O&O&|p$O&:symlink", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003369 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
3370 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
3371 int target_is_directory = 0;
3372 int dir_fd = DEFAULT_DIR_FD;
3373
Victor Stinner3e1fad62017-01-17 01:29:01 +01003374 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003375 path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003376 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003377 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
3379
3380exit:
3381 /* Cleanup for src */
3382 path_cleanup(&src);
3383 /* Cleanup for dst */
3384 path_cleanup(&dst);
3385
3386 return return_value;
3387}
3388
3389#endif /* defined(HAVE_SYMLINK) */
3390
3391#if defined(HAVE_TIMES)
3392
3393PyDoc_STRVAR(os_times__doc__,
3394"times($module, /)\n"
3395"--\n"
3396"\n"
3397"Return a collection containing process timing information.\n"
3398"\n"
3399"The object returned behaves like a named tuple with these fields:\n"
3400" (utime, stime, cutime, cstime, elapsed_time)\n"
3401"All fields are floating point numbers.");
3402
3403#define OS_TIMES_METHODDEF \
3404 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
3405
3406static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003407os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003408
3409static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003410os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003411{
3412 return os_times_impl(module);
3413}
3414
3415#endif /* defined(HAVE_TIMES) */
3416
3417#if defined(HAVE_GETSID)
3418
3419PyDoc_STRVAR(os_getsid__doc__,
3420"getsid($module, pid, /)\n"
3421"--\n"
3422"\n"
3423"Call the system call getsid(pid) and return the result.");
3424
3425#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003426 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003427
3428static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003429os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003430
3431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003432os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003433{
3434 PyObject *return_value = NULL;
3435 pid_t pid;
3436
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003437 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003438 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003440 return_value = os_getsid_impl(module, pid);
3441
3442exit:
3443 return return_value;
3444}
3445
3446#endif /* defined(HAVE_GETSID) */
3447
3448#if defined(HAVE_SETSID)
3449
3450PyDoc_STRVAR(os_setsid__doc__,
3451"setsid($module, /)\n"
3452"--\n"
3453"\n"
3454"Call the system call setsid().");
3455
3456#define OS_SETSID_METHODDEF \
3457 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
3458
3459static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003460os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003461
3462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003463os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003464{
3465 return os_setsid_impl(module);
3466}
3467
3468#endif /* defined(HAVE_SETSID) */
3469
3470#if defined(HAVE_SETPGID)
3471
3472PyDoc_STRVAR(os_setpgid__doc__,
3473"setpgid($module, pid, pgrp, /)\n"
3474"--\n"
3475"\n"
3476"Call the system call setpgid(pid, pgrp).");
3477
3478#define OS_SETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003479 {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003480
3481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003482os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003483
3484static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003485os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003486{
3487 PyObject *return_value = NULL;
3488 pid_t pid;
3489 pid_t pgrp;
3490
Sylvain74453812017-06-10 06:51:48 +02003491 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
3492 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003493 goto exit;
3494 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003495 return_value = os_setpgid_impl(module, pid, pgrp);
3496
3497exit:
3498 return return_value;
3499}
3500
3501#endif /* defined(HAVE_SETPGID) */
3502
3503#if defined(HAVE_TCGETPGRP)
3504
3505PyDoc_STRVAR(os_tcgetpgrp__doc__,
3506"tcgetpgrp($module, fd, /)\n"
3507"--\n"
3508"\n"
3509"Return the process group associated with the terminal specified by fd.");
3510
3511#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003512 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003513
3514static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003515os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003516
3517static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003518os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003519{
3520 PyObject *return_value = NULL;
3521 int fd;
3522
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003523 if (PyFloat_Check(arg)) {
3524 PyErr_SetString(PyExc_TypeError,
3525 "integer argument expected, got float" );
3526 goto exit;
3527 }
3528 fd = _PyLong_AsInt(arg);
3529 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003530 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003531 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003532 return_value = os_tcgetpgrp_impl(module, fd);
3533
3534exit:
3535 return return_value;
3536}
3537
3538#endif /* defined(HAVE_TCGETPGRP) */
3539
3540#if defined(HAVE_TCSETPGRP)
3541
3542PyDoc_STRVAR(os_tcsetpgrp__doc__,
3543"tcsetpgrp($module, fd, pgid, /)\n"
3544"--\n"
3545"\n"
3546"Set the process group associated with the terminal specified by fd.");
3547
3548#define OS_TCSETPGRP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003549 {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003550
3551static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003552os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003553
3554static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003555os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003556{
3557 PyObject *return_value = NULL;
3558 int fd;
3559 pid_t pgid;
3560
Sylvain74453812017-06-10 06:51:48 +02003561 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
3562 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003563 goto exit;
3564 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003565 return_value = os_tcsetpgrp_impl(module, fd, pgid);
3566
3567exit:
3568 return return_value;
3569}
3570
3571#endif /* defined(HAVE_TCSETPGRP) */
3572
3573PyDoc_STRVAR(os_open__doc__,
3574"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
3575"--\n"
3576"\n"
3577"Open a file for low level IO. Returns a file descriptor (integer).\n"
3578"\n"
3579"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3580" and path should be relative; path will then be relative to that directory.\n"
3581"dir_fd may not be implemented on your platform.\n"
3582" If it is unavailable, using it will raise a NotImplementedError.");
3583
3584#define OS_OPEN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003585 {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003586
3587static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003588os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003589
3590static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003591os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003592{
3593 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003594 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
3595 static _PyArg_Parser _parser = {"O&i|i$O&:open", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003596 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
3597 int flags;
3598 int mode = 511;
3599 int dir_fd = DEFAULT_DIR_FD;
3600 int _return_value;
3601
Victor Stinner3e1fad62017-01-17 01:29:01 +01003602 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003603 path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003604 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003605 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003606 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003607 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003608 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003609 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003610 return_value = PyLong_FromLong((long)_return_value);
3611
3612exit:
3613 /* Cleanup for path */
3614 path_cleanup(&path);
3615
3616 return return_value;
3617}
3618
3619PyDoc_STRVAR(os_close__doc__,
3620"close($module, /, fd)\n"
3621"--\n"
3622"\n"
3623"Close a file descriptor.");
3624
3625#define OS_CLOSE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003626 {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003627
3628static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003629os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003630
3631static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003632os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003633{
3634 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003635 static const char * const _keywords[] = {"fd", NULL};
3636 static _PyArg_Parser _parser = {"i:close", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003637 int fd;
3638
Victor Stinner3e1fad62017-01-17 01:29:01 +01003639 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003640 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003641 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003643 return_value = os_close_impl(module, fd);
3644
3645exit:
3646 return return_value;
3647}
3648
3649PyDoc_STRVAR(os_closerange__doc__,
3650"closerange($module, fd_low, fd_high, /)\n"
3651"--\n"
3652"\n"
3653"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
3654
3655#define OS_CLOSERANGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003656 {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003657
3658static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003659os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003660
3661static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003662os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003663{
3664 PyObject *return_value = NULL;
3665 int fd_low;
3666 int fd_high;
3667
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003668 if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
3669 goto exit;
3670 }
3671 if (PyFloat_Check(args[0])) {
3672 PyErr_SetString(PyExc_TypeError,
3673 "integer argument expected, got float" );
3674 goto exit;
3675 }
3676 fd_low = _PyLong_AsInt(args[0]);
3677 if (fd_low == -1 && PyErr_Occurred()) {
3678 goto exit;
3679 }
3680 if (PyFloat_Check(args[1])) {
3681 PyErr_SetString(PyExc_TypeError,
3682 "integer argument expected, got float" );
3683 goto exit;
3684 }
3685 fd_high = _PyLong_AsInt(args[1]);
3686 if (fd_high == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003687 goto exit;
3688 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003689 return_value = os_closerange_impl(module, fd_low, fd_high);
3690
3691exit:
3692 return return_value;
3693}
3694
3695PyDoc_STRVAR(os_dup__doc__,
3696"dup($module, fd, /)\n"
3697"--\n"
3698"\n"
3699"Return a duplicate of a file descriptor.");
3700
3701#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003702 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003703
3704static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003705os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003706
3707static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003708os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003709{
3710 PyObject *return_value = NULL;
3711 int fd;
3712 int _return_value;
3713
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003714 if (PyFloat_Check(arg)) {
3715 PyErr_SetString(PyExc_TypeError,
3716 "integer argument expected, got float" );
3717 goto exit;
3718 }
3719 fd = _PyLong_AsInt(arg);
3720 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003721 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003722 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003723 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003724 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003725 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003726 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003727 return_value = PyLong_FromLong((long)_return_value);
3728
3729exit:
3730 return return_value;
3731}
3732
3733PyDoc_STRVAR(os_dup2__doc__,
3734"dup2($module, /, fd, fd2, inheritable=True)\n"
3735"--\n"
3736"\n"
3737"Duplicate file descriptor.");
3738
3739#define OS_DUP2_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003740 {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003741
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003742static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003743os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003744
3745static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003746os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003747{
3748 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003749 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
3750 static _PyArg_Parser _parser = {"ii|p:dup2", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003751 int fd;
3752 int fd2;
3753 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003754 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003755
Victor Stinner3e1fad62017-01-17 01:29:01 +01003756 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003757 &fd, &fd2, &inheritable)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003758 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003759 }
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08003760 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
3761 if ((_return_value == -1) && PyErr_Occurred()) {
3762 goto exit;
3763 }
3764 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003765
3766exit:
3767 return return_value;
3768}
3769
3770#if defined(HAVE_LOCKF)
3771
3772PyDoc_STRVAR(os_lockf__doc__,
3773"lockf($module, fd, command, length, /)\n"
3774"--\n"
3775"\n"
3776"Apply, test or remove a POSIX lock on an open file descriptor.\n"
3777"\n"
3778" fd\n"
3779" An open file descriptor.\n"
3780" command\n"
3781" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
3782" length\n"
3783" The number of bytes to lock, starting at the current position.");
3784
3785#define OS_LOCKF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003786 {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003787
3788static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003789os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003790
3791static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003792os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003793{
3794 PyObject *return_value = NULL;
3795 int fd;
3796 int command;
3797 Py_off_t length;
3798
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003799 if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
3800 goto exit;
3801 }
3802 if (PyFloat_Check(args[0])) {
3803 PyErr_SetString(PyExc_TypeError,
3804 "integer argument expected, got float" );
3805 goto exit;
3806 }
3807 fd = _PyLong_AsInt(args[0]);
3808 if (fd == -1 && PyErr_Occurred()) {
3809 goto exit;
3810 }
3811 if (PyFloat_Check(args[1])) {
3812 PyErr_SetString(PyExc_TypeError,
3813 "integer argument expected, got float" );
3814 goto exit;
3815 }
3816 command = _PyLong_AsInt(args[1]);
3817 if (command == -1 && PyErr_Occurred()) {
3818 goto exit;
3819 }
3820 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003821 goto exit;
3822 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003823 return_value = os_lockf_impl(module, fd, command, length);
3824
3825exit:
3826 return return_value;
3827}
3828
3829#endif /* defined(HAVE_LOCKF) */
3830
3831PyDoc_STRVAR(os_lseek__doc__,
3832"lseek($module, fd, position, how, /)\n"
3833"--\n"
3834"\n"
3835"Set the position of a file descriptor. Return the new position.\n"
3836"\n"
3837"Return the new cursor position in number of bytes\n"
3838"relative to the beginning of the file.");
3839
3840#define OS_LSEEK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003841 {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003842
3843static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003844os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003845
3846static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003847os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003848{
3849 PyObject *return_value = NULL;
3850 int fd;
3851 Py_off_t position;
3852 int how;
3853 Py_off_t _return_value;
3854
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003855 if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
3856 goto exit;
3857 }
3858 if (PyFloat_Check(args[0])) {
3859 PyErr_SetString(PyExc_TypeError,
3860 "integer argument expected, got float" );
3861 goto exit;
3862 }
3863 fd = _PyLong_AsInt(args[0]);
3864 if (fd == -1 && PyErr_Occurred()) {
3865 goto exit;
3866 }
3867 if (!Py_off_t_converter(args[1], &position)) {
3868 goto exit;
3869 }
3870 if (PyFloat_Check(args[2])) {
3871 PyErr_SetString(PyExc_TypeError,
3872 "integer argument expected, got float" );
3873 goto exit;
3874 }
3875 how = _PyLong_AsInt(args[2]);
3876 if (how == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003877 goto exit;
3878 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003879 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003880 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003881 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003882 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003883 return_value = PyLong_FromPy_off_t(_return_value);
3884
3885exit:
3886 return return_value;
3887}
3888
3889PyDoc_STRVAR(os_read__doc__,
3890"read($module, fd, length, /)\n"
3891"--\n"
3892"\n"
3893"Read from a file descriptor. Returns a bytes object.");
3894
3895#define OS_READ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003896 {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003897
3898static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003899os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003900
3901static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003902os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003903{
3904 PyObject *return_value = NULL;
3905 int fd;
3906 Py_ssize_t length;
3907
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003908 if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003909 goto exit;
3910 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003911 if (PyFloat_Check(args[0])) {
3912 PyErr_SetString(PyExc_TypeError,
3913 "integer argument expected, got float" );
3914 goto exit;
3915 }
3916 fd = _PyLong_AsInt(args[0]);
3917 if (fd == -1 && PyErr_Occurred()) {
3918 goto exit;
3919 }
3920 if (PyFloat_Check(args[1])) {
3921 PyErr_SetString(PyExc_TypeError,
3922 "integer argument expected, got float" );
3923 goto exit;
3924 }
3925 {
3926 Py_ssize_t ival = -1;
3927 PyObject *iobj = PyNumber_Index(args[1]);
3928 if (iobj != NULL) {
3929 ival = PyLong_AsSsize_t(iobj);
3930 Py_DECREF(iobj);
3931 }
3932 if (ival == -1 && PyErr_Occurred()) {
3933 goto exit;
3934 }
3935 length = ival;
3936 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003937 return_value = os_read_impl(module, fd, length);
3938
3939exit:
3940 return return_value;
3941}
3942
3943#if defined(HAVE_READV)
3944
3945PyDoc_STRVAR(os_readv__doc__,
3946"readv($module, fd, buffers, /)\n"
3947"--\n"
3948"\n"
3949"Read from a file descriptor fd into an iterable of buffers.\n"
3950"\n"
3951"The buffers should be mutable buffers accepting bytes.\n"
3952"readv will transfer data into each buffer until it is full\n"
3953"and then move on to the next buffer in the sequence to hold\n"
3954"the rest of the data.\n"
3955"\n"
3956"readv returns the total number of bytes read,\n"
3957"which may be less than the total capacity of all the buffers.");
3958
3959#define OS_READV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003960 {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003961
3962static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003963os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003964
3965static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003966os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003967{
3968 PyObject *return_value = NULL;
3969 int fd;
3970 PyObject *buffers;
3971 Py_ssize_t _return_value;
3972
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003973 if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003974 goto exit;
3975 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003976 if (PyFloat_Check(args[0])) {
3977 PyErr_SetString(PyExc_TypeError,
3978 "integer argument expected, got float" );
3979 goto exit;
3980 }
3981 fd = _PyLong_AsInt(args[0]);
3982 if (fd == -1 && PyErr_Occurred()) {
3983 goto exit;
3984 }
3985 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003986 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003987 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003988 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003989 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003990 return_value = PyLong_FromSsize_t(_return_value);
3991
3992exit:
3993 return return_value;
3994}
3995
3996#endif /* defined(HAVE_READV) */
3997
3998#if defined(HAVE_PREAD)
3999
4000PyDoc_STRVAR(os_pread__doc__,
4001"pread($module, fd, length, offset, /)\n"
4002"--\n"
4003"\n"
4004"Read a number of bytes from a file descriptor starting at a particular offset.\n"
4005"\n"
4006"Read length bytes from file descriptor fd, starting at offset bytes from\n"
4007"the beginning of the file. The file offset remains unchanged.");
4008
4009#define OS_PREAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004010 {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004011
4012static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004013os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004014
4015static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004016os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004017{
4018 PyObject *return_value = NULL;
4019 int fd;
4020 int length;
4021 Py_off_t offset;
4022
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004023 if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
4024 goto exit;
4025 }
4026 if (PyFloat_Check(args[0])) {
4027 PyErr_SetString(PyExc_TypeError,
4028 "integer argument expected, got float" );
4029 goto exit;
4030 }
4031 fd = _PyLong_AsInt(args[0]);
4032 if (fd == -1 && PyErr_Occurred()) {
4033 goto exit;
4034 }
4035 if (PyFloat_Check(args[1])) {
4036 PyErr_SetString(PyExc_TypeError,
4037 "integer argument expected, got float" );
4038 goto exit;
4039 }
4040 length = _PyLong_AsInt(args[1]);
4041 if (length == -1 && PyErr_Occurred()) {
4042 goto exit;
4043 }
4044 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004045 goto exit;
4046 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004047 return_value = os_pread_impl(module, fd, length, offset);
4048
4049exit:
4050 return return_value;
4051}
4052
4053#endif /* defined(HAVE_PREAD) */
4054
Pablo Galindo4defba32018-01-27 16:16:37 +00004055#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
4056
4057PyDoc_STRVAR(os_preadv__doc__,
4058"preadv($module, fd, buffers, offset, flags=0, /)\n"
4059"--\n"
4060"\n"
4061"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
4062"\n"
4063"Combines the functionality of readv() and pread(). As readv(), it will\n"
4064"transfer data into each buffer until it is full and then move on to the next\n"
4065"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
4066"specifies the file offset at which the input operation is to be performed. It\n"
4067"will return the total number of bytes read (which can be less than the total\n"
4068"capacity of all the objects).\n"
4069"\n"
4070"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4071"\n"
4072"- RWF_HIPRI\n"
4073"- RWF_NOWAIT\n"
4074"\n"
4075"Using non-zero flags requires Linux 4.6 or newer.");
4076
4077#define OS_PREADV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004078 {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004079
4080static Py_ssize_t
4081os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4082 int flags);
4083
4084static PyObject *
4085os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4086{
4087 PyObject *return_value = NULL;
4088 int fd;
4089 PyObject *buffers;
4090 Py_off_t offset;
4091 int flags = 0;
4092 Py_ssize_t _return_value;
4093
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004094 if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00004095 goto exit;
4096 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004097 if (PyFloat_Check(args[0])) {
4098 PyErr_SetString(PyExc_TypeError,
4099 "integer argument expected, got float" );
4100 goto exit;
4101 }
4102 fd = _PyLong_AsInt(args[0]);
4103 if (fd == -1 && PyErr_Occurred()) {
4104 goto exit;
4105 }
4106 buffers = args[1];
4107 if (!Py_off_t_converter(args[2], &offset)) {
4108 goto exit;
4109 }
4110 if (nargs < 4) {
4111 goto skip_optional;
4112 }
4113 if (PyFloat_Check(args[3])) {
4114 PyErr_SetString(PyExc_TypeError,
4115 "integer argument expected, got float" );
4116 goto exit;
4117 }
4118 flags = _PyLong_AsInt(args[3]);
4119 if (flags == -1 && PyErr_Occurred()) {
4120 goto exit;
4121 }
4122skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00004123 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
4124 if ((_return_value == -1) && PyErr_Occurred()) {
4125 goto exit;
4126 }
4127 return_value = PyLong_FromSsize_t(_return_value);
4128
4129exit:
4130 return return_value;
4131}
4132
4133#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
4134
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004135PyDoc_STRVAR(os_write__doc__,
4136"write($module, fd, data, /)\n"
4137"--\n"
4138"\n"
4139"Write a bytes object to a file descriptor.");
4140
4141#define OS_WRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004142 {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004143
4144static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004145os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004146
4147static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004148os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004149{
4150 PyObject *return_value = NULL;
4151 int fd;
4152 Py_buffer data = {NULL, NULL};
4153 Py_ssize_t _return_value;
4154
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004155 if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
4156 goto exit;
4157 }
4158 if (PyFloat_Check(args[0])) {
4159 PyErr_SetString(PyExc_TypeError,
4160 "integer argument expected, got float" );
4161 goto exit;
4162 }
4163 fd = _PyLong_AsInt(args[0]);
4164 if (fd == -1 && PyErr_Occurred()) {
4165 goto exit;
4166 }
4167 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
4168 goto exit;
4169 }
4170 if (!PyBuffer_IsContiguous(&data, 'C')) {
4171 _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]);
Victor Stinner259f0e42017-01-17 01:35:17 +01004172 goto exit;
4173 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004174 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004175 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004176 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004177 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004178 return_value = PyLong_FromSsize_t(_return_value);
4179
4180exit:
4181 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004182 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004183 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004184 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004185
4186 return return_value;
4187}
4188
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004189#if defined(__APPLE__)
4190
4191PyDoc_STRVAR(os__fcopyfile__doc__,
4192"_fcopyfile($module, infd, outfd, flags, /)\n"
4193"--\n"
4194"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07004195"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004196
4197#define OS__FCOPYFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004198 {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004199
4200static PyObject *
4201os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
4202
4203static PyObject *
4204os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4205{
4206 PyObject *return_value = NULL;
4207 int infd;
4208 int outfd;
4209 int flags;
4210
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004211 if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
4212 goto exit;
4213 }
4214 if (PyFloat_Check(args[0])) {
4215 PyErr_SetString(PyExc_TypeError,
4216 "integer argument expected, got float" );
4217 goto exit;
4218 }
4219 infd = _PyLong_AsInt(args[0]);
4220 if (infd == -1 && PyErr_Occurred()) {
4221 goto exit;
4222 }
4223 if (PyFloat_Check(args[1])) {
4224 PyErr_SetString(PyExc_TypeError,
4225 "integer argument expected, got float" );
4226 goto exit;
4227 }
4228 outfd = _PyLong_AsInt(args[1]);
4229 if (outfd == -1 && PyErr_Occurred()) {
4230 goto exit;
4231 }
4232 if (PyFloat_Check(args[2])) {
4233 PyErr_SetString(PyExc_TypeError,
4234 "integer argument expected, got float" );
4235 goto exit;
4236 }
4237 flags = _PyLong_AsInt(args[2]);
4238 if (flags == -1 && PyErr_Occurred()) {
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004239 goto exit;
4240 }
4241 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
4242
4243exit:
4244 return return_value;
4245}
4246
4247#endif /* defined(__APPLE__) */
4248
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004249PyDoc_STRVAR(os_fstat__doc__,
4250"fstat($module, /, fd)\n"
4251"--\n"
4252"\n"
4253"Perform a stat system call on the given file descriptor.\n"
4254"\n"
4255"Like stat(), but for an open file descriptor.\n"
4256"Equivalent to os.stat(fd).");
4257
4258#define OS_FSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004259 {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004260
4261static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004262os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004263
4264static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004265os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004266{
4267 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004268 static const char * const _keywords[] = {"fd", NULL};
4269 static _PyArg_Parser _parser = {"i:fstat", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004270 int fd;
4271
Victor Stinner3e1fad62017-01-17 01:29:01 +01004272 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004273 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004274 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004275 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004276 return_value = os_fstat_impl(module, fd);
4277
4278exit:
4279 return return_value;
4280}
4281
4282PyDoc_STRVAR(os_isatty__doc__,
4283"isatty($module, fd, /)\n"
4284"--\n"
4285"\n"
4286"Return True if the fd is connected to a terminal.\n"
4287"\n"
4288"Return True if the file descriptor is an open file descriptor\n"
4289"connected to the slave end of a terminal.");
4290
4291#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004292 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004293
4294static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004295os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004296
4297static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004298os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004299{
4300 PyObject *return_value = NULL;
4301 int fd;
4302 int _return_value;
4303
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004304 if (PyFloat_Check(arg)) {
4305 PyErr_SetString(PyExc_TypeError,
4306 "integer argument expected, got float" );
4307 goto exit;
4308 }
4309 fd = _PyLong_AsInt(arg);
4310 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004311 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004312 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004313 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004314 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004315 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004316 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004317 return_value = PyBool_FromLong((long)_return_value);
4318
4319exit:
4320 return return_value;
4321}
4322
4323#if defined(HAVE_PIPE)
4324
4325PyDoc_STRVAR(os_pipe__doc__,
4326"pipe($module, /)\n"
4327"--\n"
4328"\n"
4329"Create a pipe.\n"
4330"\n"
4331"Returns a tuple of two file descriptors:\n"
4332" (read_fd, write_fd)");
4333
4334#define OS_PIPE_METHODDEF \
4335 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
4336
4337static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004338os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004339
4340static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004341os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004342{
4343 return os_pipe_impl(module);
4344}
4345
4346#endif /* defined(HAVE_PIPE) */
4347
4348#if defined(HAVE_PIPE2)
4349
4350PyDoc_STRVAR(os_pipe2__doc__,
4351"pipe2($module, flags, /)\n"
4352"--\n"
4353"\n"
4354"Create a pipe with flags set atomically.\n"
4355"\n"
4356"Returns a tuple of two file descriptors:\n"
4357" (read_fd, write_fd)\n"
4358"\n"
4359"flags can be constructed by ORing together one or more of these values:\n"
4360"O_NONBLOCK, O_CLOEXEC.");
4361
4362#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004363 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004364
4365static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004366os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004367
4368static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004369os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004370{
4371 PyObject *return_value = NULL;
4372 int flags;
4373
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004374 if (PyFloat_Check(arg)) {
4375 PyErr_SetString(PyExc_TypeError,
4376 "integer argument expected, got float" );
4377 goto exit;
4378 }
4379 flags = _PyLong_AsInt(arg);
4380 if (flags == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004381 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004382 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004383 return_value = os_pipe2_impl(module, flags);
4384
4385exit:
4386 return return_value;
4387}
4388
4389#endif /* defined(HAVE_PIPE2) */
4390
4391#if defined(HAVE_WRITEV)
4392
4393PyDoc_STRVAR(os_writev__doc__,
4394"writev($module, fd, buffers, /)\n"
4395"--\n"
4396"\n"
4397"Iterate over buffers, and write the contents of each to a file descriptor.\n"
4398"\n"
4399"Returns the total number of bytes written.\n"
4400"buffers must be a sequence of bytes-like objects.");
4401
4402#define OS_WRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004403 {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004404
4405static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004406os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004407
4408static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004409os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004410{
4411 PyObject *return_value = NULL;
4412 int fd;
4413 PyObject *buffers;
4414 Py_ssize_t _return_value;
4415
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004416 if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004417 goto exit;
4418 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004419 if (PyFloat_Check(args[0])) {
4420 PyErr_SetString(PyExc_TypeError,
4421 "integer argument expected, got float" );
4422 goto exit;
4423 }
4424 fd = _PyLong_AsInt(args[0]);
4425 if (fd == -1 && PyErr_Occurred()) {
4426 goto exit;
4427 }
4428 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004429 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004430 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004431 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004432 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004433 return_value = PyLong_FromSsize_t(_return_value);
4434
4435exit:
4436 return return_value;
4437}
4438
4439#endif /* defined(HAVE_WRITEV) */
4440
4441#if defined(HAVE_PWRITE)
4442
4443PyDoc_STRVAR(os_pwrite__doc__,
4444"pwrite($module, fd, buffer, offset, /)\n"
4445"--\n"
4446"\n"
4447"Write bytes to a file descriptor starting at a particular offset.\n"
4448"\n"
4449"Write buffer to fd, starting at offset bytes from the beginning of\n"
4450"the file. Returns the number of bytes writte. Does not change the\n"
4451"current file offset.");
4452
4453#define OS_PWRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004454 {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004455
4456static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004457os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004458
4459static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004460os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004461{
4462 PyObject *return_value = NULL;
4463 int fd;
4464 Py_buffer buffer = {NULL, NULL};
4465 Py_off_t offset;
4466 Py_ssize_t _return_value;
4467
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004468 if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
4469 goto exit;
4470 }
4471 if (PyFloat_Check(args[0])) {
4472 PyErr_SetString(PyExc_TypeError,
4473 "integer argument expected, got float" );
4474 goto exit;
4475 }
4476 fd = _PyLong_AsInt(args[0]);
4477 if (fd == -1 && PyErr_Occurred()) {
4478 goto exit;
4479 }
4480 if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
4481 goto exit;
4482 }
4483 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
4484 _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]);
4485 goto exit;
4486 }
4487 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004488 goto exit;
4489 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004490 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004491 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004492 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004493 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004494 return_value = PyLong_FromSsize_t(_return_value);
4495
4496exit:
4497 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004498 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004499 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004500 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004501
4502 return return_value;
4503}
4504
4505#endif /* defined(HAVE_PWRITE) */
4506
Pablo Galindo4defba32018-01-27 16:16:37 +00004507#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
4508
4509PyDoc_STRVAR(os_pwritev__doc__,
4510"pwritev($module, fd, buffers, offset, flags=0, /)\n"
4511"--\n"
4512"\n"
4513"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
4514"\n"
4515"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4516"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4517"buffer is written before proceeding to second, and so on. The operating system may\n"
4518"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4519"This function writes the contents of each object to the file descriptor and returns\n"
4520"the total number of bytes written.\n"
4521"\n"
4522"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4523"\n"
4524"- RWF_DSYNC\n"
4525"- RWF_SYNC\n"
4526"\n"
4527"Using non-zero flags requires Linux 4.7 or newer.");
4528
4529#define OS_PWRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004530 {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004531
4532static Py_ssize_t
4533os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4534 int flags);
4535
4536static PyObject *
4537os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4538{
4539 PyObject *return_value = NULL;
4540 int fd;
4541 PyObject *buffers;
4542 Py_off_t offset;
4543 int flags = 0;
4544 Py_ssize_t _return_value;
4545
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004546 if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00004547 goto exit;
4548 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004549 if (PyFloat_Check(args[0])) {
4550 PyErr_SetString(PyExc_TypeError,
4551 "integer argument expected, got float" );
4552 goto exit;
4553 }
4554 fd = _PyLong_AsInt(args[0]);
4555 if (fd == -1 && PyErr_Occurred()) {
4556 goto exit;
4557 }
4558 buffers = args[1];
4559 if (!Py_off_t_converter(args[2], &offset)) {
4560 goto exit;
4561 }
4562 if (nargs < 4) {
4563 goto skip_optional;
4564 }
4565 if (PyFloat_Check(args[3])) {
4566 PyErr_SetString(PyExc_TypeError,
4567 "integer argument expected, got float" );
4568 goto exit;
4569 }
4570 flags = _PyLong_AsInt(args[3]);
4571 if (flags == -1 && PyErr_Occurred()) {
4572 goto exit;
4573 }
4574skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00004575 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
4576 if ((_return_value == -1) && PyErr_Occurred()) {
4577 goto exit;
4578 }
4579 return_value = PyLong_FromSsize_t(_return_value);
4580
4581exit:
4582 return return_value;
4583}
4584
4585#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
4586
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004587#if defined(HAVE_MKFIFO)
4588
4589PyDoc_STRVAR(os_mkfifo__doc__,
4590"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
4591"--\n"
4592"\n"
4593"Create a \"fifo\" (a POSIX named pipe).\n"
4594"\n"
4595"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4596" and path should be relative; path will then be relative to that directory.\n"
4597"dir_fd may not be implemented on your platform.\n"
4598" If it is unavailable, using it will raise a NotImplementedError.");
4599
4600#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004601 {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004602
4603static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004604os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004605
4606static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004607os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004608{
4609 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004610 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
4611 static _PyArg_Parser _parser = {"O&|i$O&:mkfifo", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004612 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
4613 int mode = 438;
4614 int dir_fd = DEFAULT_DIR_FD;
4615
Victor Stinner3e1fad62017-01-17 01:29:01 +01004616 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004617 path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004618 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004619 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004620 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
4621
4622exit:
4623 /* Cleanup for path */
4624 path_cleanup(&path);
4625
4626 return return_value;
4627}
4628
4629#endif /* defined(HAVE_MKFIFO) */
4630
4631#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
4632
4633PyDoc_STRVAR(os_mknod__doc__,
4634"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
4635"--\n"
4636"\n"
4637"Create a node in the file system.\n"
4638"\n"
4639"Create a node in the file system (file, device special file or named pipe)\n"
4640"at path. mode specifies both the permissions to use and the\n"
4641"type of node to be created, being combined (bitwise OR) with one of\n"
4642"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
4643"device defines the newly created device special file (probably using\n"
4644"os.makedev()). Otherwise device is ignored.\n"
4645"\n"
4646"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4647" and path should be relative; path will then be relative to that directory.\n"
4648"dir_fd may not be implemented on your platform.\n"
4649" If it is unavailable, using it will raise a NotImplementedError.");
4650
4651#define OS_MKNOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004652 {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004653
4654static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004655os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04004656 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004657
4658static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004659os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004660{
4661 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004662 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
4663 static _PyArg_Parser _parser = {"O&|iO&$O&:mknod", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004664 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
4665 int mode = 384;
4666 dev_t device = 0;
4667 int dir_fd = DEFAULT_DIR_FD;
4668
Victor Stinner3e1fad62017-01-17 01:29:01 +01004669 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004670 path_converter, &path, &mode, _Py_Dev_Converter, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004671 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004672 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004673 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
4674
4675exit:
4676 /* Cleanup for path */
4677 path_cleanup(&path);
4678
4679 return return_value;
4680}
4681
4682#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
4683
4684#if defined(HAVE_DEVICE_MACROS)
4685
4686PyDoc_STRVAR(os_major__doc__,
4687"major($module, device, /)\n"
4688"--\n"
4689"\n"
4690"Extracts a device major number from a raw device number.");
4691
4692#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004693 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004694
4695static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004696os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004697
4698static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004699os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004700{
4701 PyObject *return_value = NULL;
4702 dev_t device;
4703 unsigned int _return_value;
4704
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004705 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004706 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004707 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004708 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004709 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004710 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004711 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004712 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4713
4714exit:
4715 return return_value;
4716}
4717
4718#endif /* defined(HAVE_DEVICE_MACROS) */
4719
4720#if defined(HAVE_DEVICE_MACROS)
4721
4722PyDoc_STRVAR(os_minor__doc__,
4723"minor($module, device, /)\n"
4724"--\n"
4725"\n"
4726"Extracts a device minor number from a raw device number.");
4727
4728#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004729 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004730
4731static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004732os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004733
4734static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004735os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004736{
4737 PyObject *return_value = NULL;
4738 dev_t device;
4739 unsigned int _return_value;
4740
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004741 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004742 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004743 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004744 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004745 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004746 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004747 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004748 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
4749
4750exit:
4751 return return_value;
4752}
4753
4754#endif /* defined(HAVE_DEVICE_MACROS) */
4755
4756#if defined(HAVE_DEVICE_MACROS)
4757
4758PyDoc_STRVAR(os_makedev__doc__,
4759"makedev($module, major, minor, /)\n"
4760"--\n"
4761"\n"
4762"Composes a raw device number from the major and minor device numbers.");
4763
4764#define OS_MAKEDEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004765 {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004766
4767static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004768os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004769
4770static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004771os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004772{
4773 PyObject *return_value = NULL;
4774 int major;
4775 int minor;
4776 dev_t _return_value;
4777
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004778 if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
4779 goto exit;
4780 }
4781 if (PyFloat_Check(args[0])) {
4782 PyErr_SetString(PyExc_TypeError,
4783 "integer argument expected, got float" );
4784 goto exit;
4785 }
4786 major = _PyLong_AsInt(args[0]);
4787 if (major == -1 && PyErr_Occurred()) {
4788 goto exit;
4789 }
4790 if (PyFloat_Check(args[1])) {
4791 PyErr_SetString(PyExc_TypeError,
4792 "integer argument expected, got float" );
4793 goto exit;
4794 }
4795 minor = _PyLong_AsInt(args[1]);
4796 if (minor == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004797 goto exit;
4798 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004799 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004800 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004801 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004802 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004803 return_value = _PyLong_FromDev(_return_value);
4804
4805exit:
4806 return return_value;
4807}
4808
4809#endif /* defined(HAVE_DEVICE_MACROS) */
4810
Steve Dowerf7377032015-04-12 15:44:54 -04004811#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004812
4813PyDoc_STRVAR(os_ftruncate__doc__,
4814"ftruncate($module, fd, length, /)\n"
4815"--\n"
4816"\n"
4817"Truncate a file, specified by file descriptor, to a specific length.");
4818
4819#define OS_FTRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004820 {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004821
4822static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004823os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004824
4825static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004826os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004827{
4828 PyObject *return_value = NULL;
4829 int fd;
4830 Py_off_t length;
4831
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004832 if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
4833 goto exit;
4834 }
4835 if (PyFloat_Check(args[0])) {
4836 PyErr_SetString(PyExc_TypeError,
4837 "integer argument expected, got float" );
4838 goto exit;
4839 }
4840 fd = _PyLong_AsInt(args[0]);
4841 if (fd == -1 && PyErr_Occurred()) {
4842 goto exit;
4843 }
4844 if (!Py_off_t_converter(args[1], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004845 goto exit;
4846 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004847 return_value = os_ftruncate_impl(module, fd, length);
4848
4849exit:
4850 return return_value;
4851}
4852
Steve Dowerf7377032015-04-12 15:44:54 -04004853#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004854
Steve Dowerf7377032015-04-12 15:44:54 -04004855#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004856
4857PyDoc_STRVAR(os_truncate__doc__,
4858"truncate($module, /, path, length)\n"
4859"--\n"
4860"\n"
4861"Truncate a file, specified by path, to a specific length.\n"
4862"\n"
4863"On some platforms, path may also be specified as an open file descriptor.\n"
4864" If this functionality is unavailable, using it raises an exception.");
4865
4866#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004867 {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004868
4869static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004870os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004871
4872static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004873os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004874{
4875 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004876 static const char * const _keywords[] = {"path", "length", NULL};
4877 static _PyArg_Parser _parser = {"O&O&:truncate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004878 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
4879 Py_off_t length;
4880
Victor Stinner3e1fad62017-01-17 01:29:01 +01004881 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004882 path_converter, &path, Py_off_t_converter, &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004883 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004884 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004885 return_value = os_truncate_impl(module, &path, length);
4886
4887exit:
4888 /* Cleanup for path */
4889 path_cleanup(&path);
4890
4891 return return_value;
4892}
4893
Steve Dowerf7377032015-04-12 15:44:54 -04004894#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004895
4896#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
4897
4898PyDoc_STRVAR(os_posix_fallocate__doc__,
4899"posix_fallocate($module, fd, offset, length, /)\n"
4900"--\n"
4901"\n"
4902"Ensure a file has allocated at least a particular number of bytes on disk.\n"
4903"\n"
4904"Ensure that the file specified by fd encompasses a range of bytes\n"
4905"starting at offset bytes from the beginning and continuing for length bytes.");
4906
4907#define OS_POSIX_FALLOCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004908 {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004909
4910static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004911os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004912 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004913
4914static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004915os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004916{
4917 PyObject *return_value = NULL;
4918 int fd;
4919 Py_off_t offset;
4920 Py_off_t length;
4921
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004922 if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
4923 goto exit;
4924 }
4925 if (PyFloat_Check(args[0])) {
4926 PyErr_SetString(PyExc_TypeError,
4927 "integer argument expected, got float" );
4928 goto exit;
4929 }
4930 fd = _PyLong_AsInt(args[0]);
4931 if (fd == -1 && PyErr_Occurred()) {
4932 goto exit;
4933 }
4934 if (!Py_off_t_converter(args[1], &offset)) {
4935 goto exit;
4936 }
4937 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004938 goto exit;
4939 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004940 return_value = os_posix_fallocate_impl(module, fd, offset, length);
4941
4942exit:
4943 return return_value;
4944}
4945
4946#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
4947
4948#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
4949
4950PyDoc_STRVAR(os_posix_fadvise__doc__,
4951"posix_fadvise($module, fd, offset, length, advice, /)\n"
4952"--\n"
4953"\n"
4954"Announce an intention to access data in a specific pattern.\n"
4955"\n"
4956"Announce an intention to access data in a specific pattern, thus allowing\n"
4957"the kernel to make optimizations.\n"
4958"The advice applies to the region of the file specified by fd starting at\n"
4959"offset and continuing for length bytes.\n"
4960"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
4961"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
4962"POSIX_FADV_DONTNEED.");
4963
4964#define OS_POSIX_FADVISE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004965 {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004966
4967static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004968os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04004969 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004970
4971static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004972os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004973{
4974 PyObject *return_value = NULL;
4975 int fd;
4976 Py_off_t offset;
4977 Py_off_t length;
4978 int advice;
4979
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004980 if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
4981 goto exit;
4982 }
4983 if (PyFloat_Check(args[0])) {
4984 PyErr_SetString(PyExc_TypeError,
4985 "integer argument expected, got float" );
4986 goto exit;
4987 }
4988 fd = _PyLong_AsInt(args[0]);
4989 if (fd == -1 && PyErr_Occurred()) {
4990 goto exit;
4991 }
4992 if (!Py_off_t_converter(args[1], &offset)) {
4993 goto exit;
4994 }
4995 if (!Py_off_t_converter(args[2], &length)) {
4996 goto exit;
4997 }
4998 if (PyFloat_Check(args[3])) {
4999 PyErr_SetString(PyExc_TypeError,
5000 "integer argument expected, got float" );
5001 goto exit;
5002 }
5003 advice = _PyLong_AsInt(args[3]);
5004 if (advice == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005005 goto exit;
5006 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005007 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
5008
5009exit:
5010 return return_value;
5011}
5012
5013#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
5014
5015#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
5016
5017PyDoc_STRVAR(os_putenv__doc__,
5018"putenv($module, name, value, /)\n"
5019"--\n"
5020"\n"
5021"Change or add an environment variable.");
5022
5023#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005024 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005025
5026static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005027os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005028
5029static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005030os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005031{
5032 PyObject *return_value = NULL;
5033 PyObject *name;
5034 PyObject *value;
5035
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005036 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005037 goto exit;
5038 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005039 if (!PyUnicode_Check(args[0])) {
5040 _PyArg_BadArgument("putenv", 1, "str", args[0]);
5041 goto exit;
5042 }
5043 if (PyUnicode_READY(args[0]) == -1) {
5044 goto exit;
5045 }
5046 name = args[0];
5047 if (!PyUnicode_Check(args[1])) {
5048 _PyArg_BadArgument("putenv", 2, "str", args[1]);
5049 goto exit;
5050 }
5051 if (PyUnicode_READY(args[1]) == -1) {
5052 goto exit;
5053 }
5054 value = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005055 return_value = os_putenv_impl(module, name, value);
5056
5057exit:
5058 return return_value;
5059}
5060
5061#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
5062
5063#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
5064
5065PyDoc_STRVAR(os_putenv__doc__,
5066"putenv($module, name, value, /)\n"
5067"--\n"
5068"\n"
5069"Change or add an environment variable.");
5070
5071#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005072 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005073
5074static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005075os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005076
5077static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005078os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005079{
5080 PyObject *return_value = NULL;
5081 PyObject *name = NULL;
5082 PyObject *value = NULL;
5083
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005084 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
5085 goto exit;
5086 }
5087 if (!PyUnicode_FSConverter(args[0], &name)) {
5088 goto exit;
5089 }
5090 if (!PyUnicode_FSConverter(args[1], &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005091 goto exit;
5092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005093 return_value = os_putenv_impl(module, name, value);
5094
5095exit:
5096 /* Cleanup for name */
5097 Py_XDECREF(name);
5098 /* Cleanup for value */
5099 Py_XDECREF(value);
5100
5101 return return_value;
5102}
5103
5104#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
5105
5106#if defined(HAVE_UNSETENV)
5107
5108PyDoc_STRVAR(os_unsetenv__doc__,
5109"unsetenv($module, name, /)\n"
5110"--\n"
5111"\n"
5112"Delete an environment variable.");
5113
5114#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005115 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005116
5117static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005118os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005119
5120static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005121os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005122{
5123 PyObject *return_value = NULL;
5124 PyObject *name = NULL;
5125
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005126 if (!PyUnicode_FSConverter(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005127 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005128 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005129 return_value = os_unsetenv_impl(module, name);
5130
5131exit:
5132 /* Cleanup for name */
5133 Py_XDECREF(name);
5134
5135 return return_value;
5136}
5137
5138#endif /* defined(HAVE_UNSETENV) */
5139
5140PyDoc_STRVAR(os_strerror__doc__,
5141"strerror($module, code, /)\n"
5142"--\n"
5143"\n"
5144"Translate an error code to a message string.");
5145
5146#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005147 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005148
5149static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005150os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005151
5152static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005153os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005154{
5155 PyObject *return_value = NULL;
5156 int code;
5157
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005158 if (PyFloat_Check(arg)) {
5159 PyErr_SetString(PyExc_TypeError,
5160 "integer argument expected, got float" );
5161 goto exit;
5162 }
5163 code = _PyLong_AsInt(arg);
5164 if (code == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005165 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005166 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005167 return_value = os_strerror_impl(module, code);
5168
5169exit:
5170 return return_value;
5171}
5172
5173#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
5174
5175PyDoc_STRVAR(os_WCOREDUMP__doc__,
5176"WCOREDUMP($module, status, /)\n"
5177"--\n"
5178"\n"
5179"Return True if the process returning status was dumped to a core file.");
5180
5181#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005182 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005183
5184static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005185os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005186
5187static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005188os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005189{
5190 PyObject *return_value = NULL;
5191 int status;
5192 int _return_value;
5193
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005194 if (PyFloat_Check(arg)) {
5195 PyErr_SetString(PyExc_TypeError,
5196 "integer argument expected, got float" );
5197 goto exit;
5198 }
5199 status = _PyLong_AsInt(arg);
5200 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005201 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005202 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005203 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005204 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005205 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005206 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005207 return_value = PyBool_FromLong((long)_return_value);
5208
5209exit:
5210 return return_value;
5211}
5212
5213#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
5214
5215#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
5216
5217PyDoc_STRVAR(os_WIFCONTINUED__doc__,
5218"WIFCONTINUED($module, /, status)\n"
5219"--\n"
5220"\n"
5221"Return True if a particular process was continued from a job control stop.\n"
5222"\n"
5223"Return True if the process returning status was continued from a\n"
5224"job control stop.");
5225
5226#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005227 {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005228
5229static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005230os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005231
5232static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005233os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005234{
5235 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005236 static const char * const _keywords[] = {"status", NULL};
5237 static _PyArg_Parser _parser = {"i:WIFCONTINUED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005238 int status;
5239 int _return_value;
5240
Victor Stinner3e1fad62017-01-17 01:29:01 +01005241 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005242 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005243 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005244 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005245 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005246 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005247 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005248 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005249 return_value = PyBool_FromLong((long)_return_value);
5250
5251exit:
5252 return return_value;
5253}
5254
5255#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
5256
5257#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
5258
5259PyDoc_STRVAR(os_WIFSTOPPED__doc__,
5260"WIFSTOPPED($module, /, status)\n"
5261"--\n"
5262"\n"
5263"Return True if the process returning status was stopped.");
5264
5265#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005266 {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005267
5268static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005269os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005270
5271static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005272os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005273{
5274 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005275 static const char * const _keywords[] = {"status", NULL};
5276 static _PyArg_Parser _parser = {"i:WIFSTOPPED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005277 int status;
5278 int _return_value;
5279
Victor Stinner3e1fad62017-01-17 01:29:01 +01005280 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005281 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005282 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005283 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005284 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005285 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005286 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005287 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005288 return_value = PyBool_FromLong((long)_return_value);
5289
5290exit:
5291 return return_value;
5292}
5293
5294#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
5295
5296#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
5297
5298PyDoc_STRVAR(os_WIFSIGNALED__doc__,
5299"WIFSIGNALED($module, /, status)\n"
5300"--\n"
5301"\n"
5302"Return True if the process returning status was terminated by a signal.");
5303
5304#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005305 {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005306
5307static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005308os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005309
5310static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005311os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005312{
5313 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005314 static const char * const _keywords[] = {"status", NULL};
5315 static _PyArg_Parser _parser = {"i:WIFSIGNALED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005316 int status;
5317 int _return_value;
5318
Victor Stinner3e1fad62017-01-17 01:29:01 +01005319 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005320 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005321 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005322 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005323 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005324 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005325 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005326 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005327 return_value = PyBool_FromLong((long)_return_value);
5328
5329exit:
5330 return return_value;
5331}
5332
5333#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
5334
5335#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
5336
5337PyDoc_STRVAR(os_WIFEXITED__doc__,
5338"WIFEXITED($module, /, status)\n"
5339"--\n"
5340"\n"
5341"Return True if the process returning status exited via the exit() system call.");
5342
5343#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005344 {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005345
5346static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005347os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005348
5349static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005350os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005351{
5352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005353 static const char * const _keywords[] = {"status", NULL};
5354 static _PyArg_Parser _parser = {"i:WIFEXITED", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005355 int status;
5356 int _return_value;
5357
Victor Stinner3e1fad62017-01-17 01:29:01 +01005358 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005359 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005361 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005362 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005363 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005366 return_value = PyBool_FromLong((long)_return_value);
5367
5368exit:
5369 return return_value;
5370}
5371
5372#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
5373
5374#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
5375
5376PyDoc_STRVAR(os_WEXITSTATUS__doc__,
5377"WEXITSTATUS($module, /, status)\n"
5378"--\n"
5379"\n"
5380"Return the process return code from status.");
5381
5382#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005383 {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005384
5385static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005386os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005387
5388static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005389os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005390{
5391 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005392 static const char * const _keywords[] = {"status", NULL};
5393 static _PyArg_Parser _parser = {"i:WEXITSTATUS", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005394 int status;
5395 int _return_value;
5396
Victor Stinner3e1fad62017-01-17 01:29:01 +01005397 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005398 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005399 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005400 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005401 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005402 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005405 return_value = PyLong_FromLong((long)_return_value);
5406
5407exit:
5408 return return_value;
5409}
5410
5411#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
5412
5413#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
5414
5415PyDoc_STRVAR(os_WTERMSIG__doc__,
5416"WTERMSIG($module, /, status)\n"
5417"--\n"
5418"\n"
5419"Return the signal that terminated the process that provided the status value.");
5420
5421#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005422 {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005423
5424static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005425os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005426
5427static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005428os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005429{
5430 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005431 static const char * const _keywords[] = {"status", NULL};
5432 static _PyArg_Parser _parser = {"i:WTERMSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005433 int status;
5434 int _return_value;
5435
Victor Stinner3e1fad62017-01-17 01:29:01 +01005436 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005437 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005438 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005440 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005441 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005442 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005443 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005444 return_value = PyLong_FromLong((long)_return_value);
5445
5446exit:
5447 return return_value;
5448}
5449
5450#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
5451
5452#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
5453
5454PyDoc_STRVAR(os_WSTOPSIG__doc__,
5455"WSTOPSIG($module, /, status)\n"
5456"--\n"
5457"\n"
5458"Return the signal that stopped the process that provided the status value.");
5459
5460#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005461 {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005462
5463static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005464os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005465
5466static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005467os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005468{
5469 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005470 static const char * const _keywords[] = {"status", NULL};
5471 static _PyArg_Parser _parser = {"i:WSTOPSIG", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005472 int status;
5473 int _return_value;
5474
Victor Stinner3e1fad62017-01-17 01:29:01 +01005475 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005476 &status)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005477 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005478 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005479 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005480 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005481 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005482 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005483 return_value = PyLong_FromLong((long)_return_value);
5484
5485exit:
5486 return return_value;
5487}
5488
5489#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
5490
5491#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
5492
5493PyDoc_STRVAR(os_fstatvfs__doc__,
5494"fstatvfs($module, fd, /)\n"
5495"--\n"
5496"\n"
5497"Perform an fstatvfs system call on the given fd.\n"
5498"\n"
5499"Equivalent to statvfs(fd).");
5500
5501#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005502 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005503
5504static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005505os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005506
5507static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005508os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005509{
5510 PyObject *return_value = NULL;
5511 int fd;
5512
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005513 if (PyFloat_Check(arg)) {
5514 PyErr_SetString(PyExc_TypeError,
5515 "integer argument expected, got float" );
5516 goto exit;
5517 }
5518 fd = _PyLong_AsInt(arg);
5519 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005520 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005521 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005522 return_value = os_fstatvfs_impl(module, fd);
5523
5524exit:
5525 return return_value;
5526}
5527
5528#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5529
5530#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
5531
5532PyDoc_STRVAR(os_statvfs__doc__,
5533"statvfs($module, /, path)\n"
5534"--\n"
5535"\n"
5536"Perform a statvfs system call on the given path.\n"
5537"\n"
5538"path may always be specified as a string.\n"
5539"On some platforms, path may also be specified as an open file descriptor.\n"
5540" If this functionality is unavailable, using it raises an exception.");
5541
5542#define OS_STATVFS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005543 {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005544
5545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005546os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005547
5548static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005549os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005550{
5551 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005552 static const char * const _keywords[] = {"path", NULL};
5553 static _PyArg_Parser _parser = {"O&:statvfs", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005554 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
5555
Victor Stinner3e1fad62017-01-17 01:29:01 +01005556 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005557 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005558 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005559 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005560 return_value = os_statvfs_impl(module, &path);
5561
5562exit:
5563 /* Cleanup for path */
5564 path_cleanup(&path);
5565
5566 return return_value;
5567}
5568
5569#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
5570
5571#if defined(MS_WINDOWS)
5572
5573PyDoc_STRVAR(os__getdiskusage__doc__,
5574"_getdiskusage($module, /, path)\n"
5575"--\n"
5576"\n"
5577"Return disk usage statistics about the given path as a (total, free) tuple.");
5578
5579#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005580 {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005581
5582static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08005583os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005584
5585static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005586os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005587{
5588 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005589 static const char * const _keywords[] = {"path", NULL};
Steve Dower23ad6d02018-02-22 10:39:10 -08005590 static _PyArg_Parser _parser = {"O&:_getdiskusage", _keywords, 0};
5591 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005592
Victor Stinner3e1fad62017-01-17 01:29:01 +01005593 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dower23ad6d02018-02-22 10:39:10 -08005594 path_converter, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005595 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005596 }
Steve Dower23ad6d02018-02-22 10:39:10 -08005597 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005598
5599exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08005600 /* Cleanup for path */
5601 path_cleanup(&path);
5602
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005603 return return_value;
5604}
5605
5606#endif /* defined(MS_WINDOWS) */
5607
5608#if defined(HAVE_FPATHCONF)
5609
5610PyDoc_STRVAR(os_fpathconf__doc__,
5611"fpathconf($module, fd, name, /)\n"
5612"--\n"
5613"\n"
5614"Return the configuration limit name for the file descriptor fd.\n"
5615"\n"
5616"If there is no limit, return -1.");
5617
5618#define OS_FPATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005619 {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005620
5621static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005622os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005623
5624static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005625os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005626{
5627 PyObject *return_value = NULL;
5628 int fd;
5629 int name;
5630 long _return_value;
5631
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005632 if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
5633 goto exit;
5634 }
5635 if (PyFloat_Check(args[0])) {
5636 PyErr_SetString(PyExc_TypeError,
5637 "integer argument expected, got float" );
5638 goto exit;
5639 }
5640 fd = _PyLong_AsInt(args[0]);
5641 if (fd == -1 && PyErr_Occurred()) {
5642 goto exit;
5643 }
5644 if (!conv_path_confname(args[1], &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005645 goto exit;
5646 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005647 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005648 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005649 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005650 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005651 return_value = PyLong_FromLong(_return_value);
5652
5653exit:
5654 return return_value;
5655}
5656
5657#endif /* defined(HAVE_FPATHCONF) */
5658
5659#if defined(HAVE_PATHCONF)
5660
5661PyDoc_STRVAR(os_pathconf__doc__,
5662"pathconf($module, /, path, name)\n"
5663"--\n"
5664"\n"
5665"Return the configuration limit name for the file or directory path.\n"
5666"\n"
5667"If there is no limit, return -1.\n"
5668"On some platforms, path may also be specified as an open file descriptor.\n"
5669" If this functionality is unavailable, using it raises an exception.");
5670
5671#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005672 {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005673
5674static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005675os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005676
5677static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005678os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005679{
5680 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005681 static const char * const _keywords[] = {"path", "name", NULL};
5682 static _PyArg_Parser _parser = {"O&O&:pathconf", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005683 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
5684 int name;
5685 long _return_value;
5686
Victor Stinner3e1fad62017-01-17 01:29:01 +01005687 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005688 path_converter, &path, conv_path_confname, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005689 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005690 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005691 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005692 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005693 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005694 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005695 return_value = PyLong_FromLong(_return_value);
5696
5697exit:
5698 /* Cleanup for path */
5699 path_cleanup(&path);
5700
5701 return return_value;
5702}
5703
5704#endif /* defined(HAVE_PATHCONF) */
5705
5706#if defined(HAVE_CONFSTR)
5707
5708PyDoc_STRVAR(os_confstr__doc__,
5709"confstr($module, name, /)\n"
5710"--\n"
5711"\n"
5712"Return a string-valued system configuration variable.");
5713
5714#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005715 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005716
5717static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005718os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005719
5720static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005721os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005722{
5723 PyObject *return_value = NULL;
5724 int name;
5725
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005726 if (!conv_confstr_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005727 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005728 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005729 return_value = os_confstr_impl(module, name);
5730
5731exit:
5732 return return_value;
5733}
5734
5735#endif /* defined(HAVE_CONFSTR) */
5736
5737#if defined(HAVE_SYSCONF)
5738
5739PyDoc_STRVAR(os_sysconf__doc__,
5740"sysconf($module, name, /)\n"
5741"--\n"
5742"\n"
5743"Return an integer-valued system configuration variable.");
5744
5745#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005746 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005747
5748static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005749os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005750
5751static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005752os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005753{
5754 PyObject *return_value = NULL;
5755 int name;
5756 long _return_value;
5757
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005758 if (!conv_sysconf_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005759 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005760 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005761 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005762 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005763 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005764 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005765 return_value = PyLong_FromLong(_return_value);
5766
5767exit:
5768 return return_value;
5769}
5770
5771#endif /* defined(HAVE_SYSCONF) */
5772
5773PyDoc_STRVAR(os_abort__doc__,
5774"abort($module, /)\n"
5775"--\n"
5776"\n"
5777"Abort the interpreter immediately.\n"
5778"\n"
5779"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
5780"on the hosting operating system. This function never returns.");
5781
5782#define OS_ABORT_METHODDEF \
5783 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
5784
5785static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005786os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005787
5788static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005789os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005790{
5791 return os_abort_impl(module);
5792}
5793
Steve Dowercc16be82016-09-08 10:35:16 -07005794#if defined(MS_WINDOWS)
5795
5796PyDoc_STRVAR(os_startfile__doc__,
5797"startfile($module, /, filepath, operation=None)\n"
5798"--\n"
5799"\n"
5800"startfile(filepath [, operation])\n"
5801"\n"
5802"Start a file with its associated application.\n"
5803"\n"
5804"When \"operation\" is not specified or \"open\", this acts like\n"
5805"double-clicking the file in Explorer, or giving the file name as an\n"
5806"argument to the DOS \"start\" command: the file is opened with whatever\n"
5807"application (if any) its extension is associated.\n"
5808"When another \"operation\" is given, it specifies what should be done with\n"
5809"the file. A typical operation is \"print\".\n"
5810"\n"
5811"startfile returns as soon as the associated application is launched.\n"
5812"There is no option to wait for the application to close, and no way\n"
5813"to retrieve the application\'s exit status.\n"
5814"\n"
5815"The filepath is relative to the current directory. If you want to use\n"
5816"an absolute path, make sure the first character is not a slash (\"/\");\n"
5817"the underlying Win32 ShellExecute function doesn\'t work if it is.");
5818
5819#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005820 {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07005821
5822static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005823os_startfile_impl(PyObject *module, path_t *filepath,
5824 const Py_UNICODE *operation);
Steve Dowercc16be82016-09-08 10:35:16 -07005825
5826static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005827os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07005828{
5829 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07005830 static const char * const _keywords[] = {"filepath", "operation", NULL};
5831 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07005832 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02005833 const Py_UNICODE *operation = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07005834
Victor Stinner3e1fad62017-01-17 01:29:01 +01005835 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07005836 path_converter, &filepath, &operation)) {
5837 goto exit;
5838 }
5839 return_value = os_startfile_impl(module, &filepath, operation);
5840
5841exit:
5842 /* Cleanup for filepath */
5843 path_cleanup(&filepath);
5844
5845 return return_value;
5846}
5847
5848#endif /* defined(MS_WINDOWS) */
5849
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005850#if defined(HAVE_GETLOADAVG)
5851
5852PyDoc_STRVAR(os_getloadavg__doc__,
5853"getloadavg($module, /)\n"
5854"--\n"
5855"\n"
5856"Return average recent system load information.\n"
5857"\n"
5858"Return the number of processes in the system run queue averaged over\n"
5859"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
5860"Raises OSError if the load average was unobtainable.");
5861
5862#define OS_GETLOADAVG_METHODDEF \
5863 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
5864
5865static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005866os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005867
5868static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005869os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005870{
5871 return os_getloadavg_impl(module);
5872}
5873
5874#endif /* defined(HAVE_GETLOADAVG) */
5875
5876PyDoc_STRVAR(os_device_encoding__doc__,
5877"device_encoding($module, /, fd)\n"
5878"--\n"
5879"\n"
5880"Return a string describing the encoding of a terminal\'s file descriptor.\n"
5881"\n"
5882"The file descriptor must be attached to a terminal.\n"
5883"If the device is not a terminal, return None.");
5884
5885#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005886 {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005887
5888static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005889os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005890
5891static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005892os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005893{
5894 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005895 static const char * const _keywords[] = {"fd", NULL};
5896 static _PyArg_Parser _parser = {"i:device_encoding", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005897 int fd;
5898
Victor Stinner3e1fad62017-01-17 01:29:01 +01005899 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005900 &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005901 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005902 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005903 return_value = os_device_encoding_impl(module, fd);
5904
5905exit:
5906 return return_value;
5907}
5908
5909#if defined(HAVE_SETRESUID)
5910
5911PyDoc_STRVAR(os_setresuid__doc__,
5912"setresuid($module, ruid, euid, suid, /)\n"
5913"--\n"
5914"\n"
5915"Set the current process\'s real, effective, and saved user ids.");
5916
5917#define OS_SETRESUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005918 {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005919
5920static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005921os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005922
5923static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005924os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005925{
5926 PyObject *return_value = NULL;
5927 uid_t ruid;
5928 uid_t euid;
5929 uid_t suid;
5930
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005931 if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
5932 goto exit;
5933 }
5934 if (!_Py_Uid_Converter(args[0], &ruid)) {
5935 goto exit;
5936 }
5937 if (!_Py_Uid_Converter(args[1], &euid)) {
5938 goto exit;
5939 }
5940 if (!_Py_Uid_Converter(args[2], &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005941 goto exit;
5942 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005943 return_value = os_setresuid_impl(module, ruid, euid, suid);
5944
5945exit:
5946 return return_value;
5947}
5948
5949#endif /* defined(HAVE_SETRESUID) */
5950
5951#if defined(HAVE_SETRESGID)
5952
5953PyDoc_STRVAR(os_setresgid__doc__,
5954"setresgid($module, rgid, egid, sgid, /)\n"
5955"--\n"
5956"\n"
5957"Set the current process\'s real, effective, and saved group ids.");
5958
5959#define OS_SETRESGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005960 {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005961
5962static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005963os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005964
5965static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005966os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005967{
5968 PyObject *return_value = NULL;
5969 gid_t rgid;
5970 gid_t egid;
5971 gid_t sgid;
5972
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005973 if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
5974 goto exit;
5975 }
5976 if (!_Py_Gid_Converter(args[0], &rgid)) {
5977 goto exit;
5978 }
5979 if (!_Py_Gid_Converter(args[1], &egid)) {
5980 goto exit;
5981 }
5982 if (!_Py_Gid_Converter(args[2], &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005983 goto exit;
5984 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005985 return_value = os_setresgid_impl(module, rgid, egid, sgid);
5986
5987exit:
5988 return return_value;
5989}
5990
5991#endif /* defined(HAVE_SETRESGID) */
5992
5993#if defined(HAVE_GETRESUID)
5994
5995PyDoc_STRVAR(os_getresuid__doc__,
5996"getresuid($module, /)\n"
5997"--\n"
5998"\n"
5999"Return a tuple of the current process\'s real, effective, and saved user ids.");
6000
6001#define OS_GETRESUID_METHODDEF \
6002 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
6003
6004static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006005os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006006
6007static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006008os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006009{
6010 return os_getresuid_impl(module);
6011}
6012
6013#endif /* defined(HAVE_GETRESUID) */
6014
6015#if defined(HAVE_GETRESGID)
6016
6017PyDoc_STRVAR(os_getresgid__doc__,
6018"getresgid($module, /)\n"
6019"--\n"
6020"\n"
6021"Return a tuple of the current process\'s real, effective, and saved group ids.");
6022
6023#define OS_GETRESGID_METHODDEF \
6024 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
6025
6026static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006027os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006028
6029static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006030os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006031{
6032 return os_getresgid_impl(module);
6033}
6034
6035#endif /* defined(HAVE_GETRESGID) */
6036
6037#if defined(USE_XATTRS)
6038
6039PyDoc_STRVAR(os_getxattr__doc__,
6040"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
6041"--\n"
6042"\n"
6043"Return the value of extended attribute attribute on path.\n"
6044"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006045"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006046"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6047" link, getxattr will examine the symbolic link itself instead of the file\n"
6048" the link points to.");
6049
6050#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006051 {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006052
6053static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006054os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006055 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006056
6057static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006058os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006059{
6060 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006061 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
6062 static _PyArg_Parser _parser = {"O&O&|$p:getxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006063 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
6064 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
6065 int follow_symlinks = 1;
6066
Victor Stinner3e1fad62017-01-17 01:29:01 +01006067 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006068 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006069 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006070 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006071 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
6072
6073exit:
6074 /* Cleanup for path */
6075 path_cleanup(&path);
6076 /* Cleanup for attribute */
6077 path_cleanup(&attribute);
6078
6079 return return_value;
6080}
6081
6082#endif /* defined(USE_XATTRS) */
6083
6084#if defined(USE_XATTRS)
6085
6086PyDoc_STRVAR(os_setxattr__doc__,
6087"setxattr($module, /, path, attribute, value, flags=0, *,\n"
6088" follow_symlinks=True)\n"
6089"--\n"
6090"\n"
6091"Set extended attribute attribute on path to value.\n"
6092"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006093"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006094"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6095" link, setxattr will modify the symbolic link itself instead of the file\n"
6096" the link points to.");
6097
6098#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006099 {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006100
6101static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006102os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006103 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006104
6105static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006106os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006107{
6108 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006109 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
6110 static _PyArg_Parser _parser = {"O&O&y*|i$p:setxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006111 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
6112 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
6113 Py_buffer value = {NULL, NULL};
6114 int flags = 0;
6115 int follow_symlinks = 1;
6116
Victor Stinner3e1fad62017-01-17 01:29:01 +01006117 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006118 path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006119 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006120 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006121 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
6122
6123exit:
6124 /* Cleanup for path */
6125 path_cleanup(&path);
6126 /* Cleanup for attribute */
6127 path_cleanup(&attribute);
6128 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006129 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006130 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006131 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006132
6133 return return_value;
6134}
6135
6136#endif /* defined(USE_XATTRS) */
6137
6138#if defined(USE_XATTRS)
6139
6140PyDoc_STRVAR(os_removexattr__doc__,
6141"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
6142"--\n"
6143"\n"
6144"Remove extended attribute attribute on path.\n"
6145"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006146"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006147"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6148" link, removexattr will modify the symbolic link itself instead of the file\n"
6149" the link points to.");
6150
6151#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006152 {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006153
6154static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006155os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04006156 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006157
6158static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006159os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006160{
6161 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006162 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
6163 static _PyArg_Parser _parser = {"O&O&|$p:removexattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006164 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
6165 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
6166 int follow_symlinks = 1;
6167
Victor Stinner3e1fad62017-01-17 01:29:01 +01006168 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006169 path_converter, &path, path_converter, &attribute, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006170 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006171 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006172 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
6173
6174exit:
6175 /* Cleanup for path */
6176 path_cleanup(&path);
6177 /* Cleanup for attribute */
6178 path_cleanup(&attribute);
6179
6180 return return_value;
6181}
6182
6183#endif /* defined(USE_XATTRS) */
6184
6185#if defined(USE_XATTRS)
6186
6187PyDoc_STRVAR(os_listxattr__doc__,
6188"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
6189"--\n"
6190"\n"
6191"Return a list of extended attributes on path.\n"
6192"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006193"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006194"if path is None, listxattr will examine the current directory.\n"
6195"If follow_symlinks is False, and the last element of the path is a symbolic\n"
6196" link, listxattr will examine the symbolic link itself instead of the file\n"
6197" the link points to.");
6198
6199#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006200 {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006201
6202static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006203os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006204
6205static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006206os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006207{
6208 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006209 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
6210 static _PyArg_Parser _parser = {"|O&$p:listxattr", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006211 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
6212 int follow_symlinks = 1;
6213
Victor Stinner3e1fad62017-01-17 01:29:01 +01006214 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006215 path_converter, &path, &follow_symlinks)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006216 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006217 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006218 return_value = os_listxattr_impl(module, &path, follow_symlinks);
6219
6220exit:
6221 /* Cleanup for path */
6222 path_cleanup(&path);
6223
6224 return return_value;
6225}
6226
6227#endif /* defined(USE_XATTRS) */
6228
6229PyDoc_STRVAR(os_urandom__doc__,
6230"urandom($module, size, /)\n"
6231"--\n"
6232"\n"
6233"Return a bytes object containing random bytes suitable for cryptographic use.");
6234
6235#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006236 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006237
6238static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006239os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006240
6241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006242os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006243{
6244 PyObject *return_value = NULL;
6245 Py_ssize_t size;
6246
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006247 if (PyFloat_Check(arg)) {
6248 PyErr_SetString(PyExc_TypeError,
6249 "integer argument expected, got float" );
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006250 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006251 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006252 {
6253 Py_ssize_t ival = -1;
6254 PyObject *iobj = PyNumber_Index(arg);
6255 if (iobj != NULL) {
6256 ival = PyLong_AsSsize_t(iobj);
6257 Py_DECREF(iobj);
6258 }
6259 if (ival == -1 && PyErr_Occurred()) {
6260 goto exit;
6261 }
6262 size = ival;
6263 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006264 return_value = os_urandom_impl(module, size);
6265
6266exit:
6267 return return_value;
6268}
6269
6270PyDoc_STRVAR(os_cpu_count__doc__,
6271"cpu_count($module, /)\n"
6272"--\n"
6273"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01006274"Return the number of CPUs in the system; return None if indeterminable.\n"
6275"\n"
6276"This number is not equivalent to the number of CPUs the current process can\n"
6277"use. The number of usable CPUs can be obtained with\n"
6278"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006279
6280#define OS_CPU_COUNT_METHODDEF \
6281 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
6282
6283static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006284os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006285
6286static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006287os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006288{
6289 return os_cpu_count_impl(module);
6290}
6291
6292PyDoc_STRVAR(os_get_inheritable__doc__,
6293"get_inheritable($module, fd, /)\n"
6294"--\n"
6295"\n"
6296"Get the close-on-exe flag of the specified file descriptor.");
6297
6298#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006299 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006300
6301static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006302os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006303
6304static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006305os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006306{
6307 PyObject *return_value = NULL;
6308 int fd;
6309 int _return_value;
6310
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006311 if (PyFloat_Check(arg)) {
6312 PyErr_SetString(PyExc_TypeError,
6313 "integer argument expected, got float" );
6314 goto exit;
6315 }
6316 fd = _PyLong_AsInt(arg);
6317 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006318 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006319 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006320 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006321 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006322 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006323 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006324 return_value = PyBool_FromLong((long)_return_value);
6325
6326exit:
6327 return return_value;
6328}
6329
6330PyDoc_STRVAR(os_set_inheritable__doc__,
6331"set_inheritable($module, fd, inheritable, /)\n"
6332"--\n"
6333"\n"
6334"Set the inheritable flag of the specified file descriptor.");
6335
6336#define OS_SET_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006337 {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006338
6339static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006340os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006341
6342static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006343os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006344{
6345 PyObject *return_value = NULL;
6346 int fd;
6347 int inheritable;
6348
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006349 if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
6350 goto exit;
6351 }
6352 if (PyFloat_Check(args[0])) {
6353 PyErr_SetString(PyExc_TypeError,
6354 "integer argument expected, got float" );
6355 goto exit;
6356 }
6357 fd = _PyLong_AsInt(args[0]);
6358 if (fd == -1 && PyErr_Occurred()) {
6359 goto exit;
6360 }
6361 if (PyFloat_Check(args[1])) {
6362 PyErr_SetString(PyExc_TypeError,
6363 "integer argument expected, got float" );
6364 goto exit;
6365 }
6366 inheritable = _PyLong_AsInt(args[1]);
6367 if (inheritable == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006368 goto exit;
6369 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006370 return_value = os_set_inheritable_impl(module, fd, inheritable);
6371
6372exit:
6373 return return_value;
6374}
6375
6376#if defined(MS_WINDOWS)
6377
6378PyDoc_STRVAR(os_get_handle_inheritable__doc__,
6379"get_handle_inheritable($module, handle, /)\n"
6380"--\n"
6381"\n"
6382"Get the close-on-exe flag of the specified file descriptor.");
6383
6384#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006385 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006386
6387static int
Victor Stinner581139c2016-09-06 15:54:20 -07006388os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006389
6390static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006391os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006392{
6393 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07006394 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006395 int _return_value;
6396
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006397 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006400 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006401 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006402 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006403 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006404 return_value = PyBool_FromLong((long)_return_value);
6405
6406exit:
6407 return return_value;
6408}
6409
6410#endif /* defined(MS_WINDOWS) */
6411
6412#if defined(MS_WINDOWS)
6413
6414PyDoc_STRVAR(os_set_handle_inheritable__doc__,
6415"set_handle_inheritable($module, handle, inheritable, /)\n"
6416"--\n"
6417"\n"
6418"Set the inheritable flag of the specified handle.");
6419
6420#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006421 {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006422
6423static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07006424os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04006425 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006426
6427static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006428os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006429{
6430 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07006431 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006432 int inheritable;
6433
Sylvain74453812017-06-10 06:51:48 +02006434 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
6435 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006436 goto exit;
6437 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006438 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
6439
6440exit:
6441 return return_value;
6442}
6443
6444#endif /* defined(MS_WINDOWS) */
6445
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006446#if !defined(MS_WINDOWS)
6447
6448PyDoc_STRVAR(os_get_blocking__doc__,
6449"get_blocking($module, fd, /)\n"
6450"--\n"
6451"\n"
6452"Get the blocking mode of the file descriptor.\n"
6453"\n"
6454"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
6455
6456#define OS_GET_BLOCKING_METHODDEF \
6457 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
6458
6459static int
6460os_get_blocking_impl(PyObject *module, int fd);
6461
6462static PyObject *
6463os_get_blocking(PyObject *module, PyObject *arg)
6464{
6465 PyObject *return_value = NULL;
6466 int fd;
6467 int _return_value;
6468
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006469 if (PyFloat_Check(arg)) {
6470 PyErr_SetString(PyExc_TypeError,
6471 "integer argument expected, got float" );
6472 goto exit;
6473 }
6474 fd = _PyLong_AsInt(arg);
6475 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006476 goto exit;
6477 }
6478 _return_value = os_get_blocking_impl(module, fd);
6479 if ((_return_value == -1) && PyErr_Occurred()) {
6480 goto exit;
6481 }
6482 return_value = PyBool_FromLong((long)_return_value);
6483
6484exit:
6485 return return_value;
6486}
6487
6488#endif /* !defined(MS_WINDOWS) */
6489
6490#if !defined(MS_WINDOWS)
6491
6492PyDoc_STRVAR(os_set_blocking__doc__,
6493"set_blocking($module, fd, blocking, /)\n"
6494"--\n"
6495"\n"
6496"Set the blocking mode of the specified file descriptor.\n"
6497"\n"
6498"Set the O_NONBLOCK flag if blocking is False,\n"
6499"clear the O_NONBLOCK flag otherwise.");
6500
6501#define OS_SET_BLOCKING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006502 {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006503
6504static PyObject *
6505os_set_blocking_impl(PyObject *module, int fd, int blocking);
6506
6507static PyObject *
6508os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6509{
6510 PyObject *return_value = NULL;
6511 int fd;
6512 int blocking;
6513
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006514 if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
6515 goto exit;
6516 }
6517 if (PyFloat_Check(args[0])) {
6518 PyErr_SetString(PyExc_TypeError,
6519 "integer argument expected, got float" );
6520 goto exit;
6521 }
6522 fd = _PyLong_AsInt(args[0]);
6523 if (fd == -1 && PyErr_Occurred()) {
6524 goto exit;
6525 }
6526 if (PyFloat_Check(args[1])) {
6527 PyErr_SetString(PyExc_TypeError,
6528 "integer argument expected, got float" );
6529 goto exit;
6530 }
6531 blocking = _PyLong_AsInt(args[1]);
6532 if (blocking == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03006533 goto exit;
6534 }
6535 return_value = os_set_blocking_impl(module, fd, blocking);
6536
6537exit:
6538 return return_value;
6539}
6540
6541#endif /* !defined(MS_WINDOWS) */
6542
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006543PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
6544"is_symlink($self, /)\n"
6545"--\n"
6546"\n"
6547"Return True if the entry is a symbolic link; cached per entry.");
6548
6549#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
6550 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
6551
6552static int
6553os_DirEntry_is_symlink_impl(DirEntry *self);
6554
6555static PyObject *
6556os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
6557{
6558 PyObject *return_value = NULL;
6559 int _return_value;
6560
6561 _return_value = os_DirEntry_is_symlink_impl(self);
6562 if ((_return_value == -1) && PyErr_Occurred()) {
6563 goto exit;
6564 }
6565 return_value = PyBool_FromLong((long)_return_value);
6566
6567exit:
6568 return return_value;
6569}
6570
6571PyDoc_STRVAR(os_DirEntry_stat__doc__,
6572"stat($self, /, *, follow_symlinks=True)\n"
6573"--\n"
6574"\n"
6575"Return stat_result object for the entry; cached per entry.");
6576
6577#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006578 {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006579
6580static PyObject *
6581os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
6582
6583static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006584os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006585{
6586 PyObject *return_value = NULL;
6587 static const char * const _keywords[] = {"follow_symlinks", NULL};
6588 static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0};
6589 int follow_symlinks = 1;
6590
Victor Stinner3e1fad62017-01-17 01:29:01 +01006591 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006592 &follow_symlinks)) {
6593 goto exit;
6594 }
6595 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
6596
6597exit:
6598 return return_value;
6599}
6600
6601PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
6602"is_dir($self, /, *, follow_symlinks=True)\n"
6603"--\n"
6604"\n"
6605"Return True if the entry is a directory; cached per entry.");
6606
6607#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006608 {"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 +02006609
6610static int
6611os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
6612
6613static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006614os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006615{
6616 PyObject *return_value = NULL;
6617 static const char * const _keywords[] = {"follow_symlinks", NULL};
6618 static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0};
6619 int follow_symlinks = 1;
6620 int _return_value;
6621
Victor Stinner3e1fad62017-01-17 01:29:01 +01006622 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006623 &follow_symlinks)) {
6624 goto exit;
6625 }
6626 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
6627 if ((_return_value == -1) && PyErr_Occurred()) {
6628 goto exit;
6629 }
6630 return_value = PyBool_FromLong((long)_return_value);
6631
6632exit:
6633 return return_value;
6634}
6635
6636PyDoc_STRVAR(os_DirEntry_is_file__doc__,
6637"is_file($self, /, *, follow_symlinks=True)\n"
6638"--\n"
6639"\n"
6640"Return True if the entry is a file; cached per entry.");
6641
6642#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006643 {"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 +02006644
6645static int
6646os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
6647
6648static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006649os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006650{
6651 PyObject *return_value = NULL;
6652 static const char * const _keywords[] = {"follow_symlinks", NULL};
6653 static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0};
6654 int follow_symlinks = 1;
6655 int _return_value;
6656
Victor Stinner3e1fad62017-01-17 01:29:01 +01006657 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006658 &follow_symlinks)) {
6659 goto exit;
6660 }
6661 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
6662 if ((_return_value == -1) && PyErr_Occurred()) {
6663 goto exit;
6664 }
6665 return_value = PyBool_FromLong((long)_return_value);
6666
6667exit:
6668 return return_value;
6669}
6670
6671PyDoc_STRVAR(os_DirEntry_inode__doc__,
6672"inode($self, /)\n"
6673"--\n"
6674"\n"
6675"Return inode of the entry; cached per entry.");
6676
6677#define OS_DIRENTRY_INODE_METHODDEF \
6678 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
6679
6680static PyObject *
6681os_DirEntry_inode_impl(DirEntry *self);
6682
6683static PyObject *
6684os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
6685{
6686 return os_DirEntry_inode_impl(self);
6687}
6688
6689PyDoc_STRVAR(os_DirEntry___fspath____doc__,
6690"__fspath__($self, /)\n"
6691"--\n"
6692"\n"
6693"Returns the path for the entry.");
6694
6695#define OS_DIRENTRY___FSPATH___METHODDEF \
6696 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
6697
6698static PyObject *
6699os_DirEntry___fspath___impl(DirEntry *self);
6700
6701static PyObject *
6702os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
6703{
6704 return os_DirEntry___fspath___impl(self);
6705}
6706
6707PyDoc_STRVAR(os_scandir__doc__,
6708"scandir($module, /, path=None)\n"
6709"--\n"
6710"\n"
6711"Return an iterator of DirEntry objects for given path.\n"
6712"\n"
BNMetricsb9427072018-11-02 15:20:19 +00006713"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006714"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
6715"all other circumstances they will be str.\n"
6716"\n"
6717"If path is None, uses the path=\'.\'.");
6718
6719#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006720 {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006721
6722static PyObject *
6723os_scandir_impl(PyObject *module, path_t *path);
6724
6725static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006726os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006727{
6728 PyObject *return_value = NULL;
6729 static const char * const _keywords[] = {"path", NULL};
6730 static _PyArg_Parser _parser = {"|O&:scandir", _keywords, 0};
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03006731 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006732
Victor Stinner3e1fad62017-01-17 01:29:01 +01006733 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02006734 path_converter, &path)) {
6735 goto exit;
6736 }
6737 return_value = os_scandir_impl(module, &path);
6738
6739exit:
6740 /* Cleanup for path */
6741 path_cleanup(&path);
6742
6743 return return_value;
6744}
6745
Ethan Furman410ef8e2016-06-04 12:06:26 -07006746PyDoc_STRVAR(os_fspath__doc__,
6747"fspath($module, /, path)\n"
6748"--\n"
6749"\n"
6750"Return the file system path representation of the object.\n"
6751"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07006752"If the object is str or bytes, then allow it to pass through as-is. If the\n"
6753"object defines __fspath__(), then return the result of that method. All other\n"
6754"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07006755
6756#define OS_FSPATH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006757 {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07006758
6759static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03006760os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07006761
6762static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006763os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07006764{
6765 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006766 static const char * const _keywords[] = {"path", NULL};
6767 static _PyArg_Parser _parser = {"O:fspath", _keywords, 0};
Ethan Furman410ef8e2016-06-04 12:06:26 -07006768 PyObject *path;
6769
Victor Stinner3e1fad62017-01-17 01:29:01 +01006770 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006771 &path)) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07006772 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006773 }
Ethan Furman410ef8e2016-06-04 12:06:26 -07006774 return_value = os_fspath_impl(module, path);
6775
6776exit:
6777 return return_value;
6778}
6779
Victor Stinner9b1f4742016-09-06 16:18:52 -07006780#if defined(HAVE_GETRANDOM_SYSCALL)
6781
6782PyDoc_STRVAR(os_getrandom__doc__,
6783"getrandom($module, /, size, flags=0)\n"
6784"--\n"
6785"\n"
6786"Obtain a series of random bytes.");
6787
6788#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006789 {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07006790
6791static PyObject *
6792os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
6793
6794static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006795os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07006796{
6797 PyObject *return_value = NULL;
6798 static const char * const _keywords[] = {"size", "flags", NULL};
6799 static _PyArg_Parser _parser = {"n|i:getrandom", _keywords, 0};
6800 Py_ssize_t size;
6801 int flags = 0;
6802
Victor Stinner3e1fad62017-01-17 01:29:01 +01006803 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Victor Stinner9b1f4742016-09-06 16:18:52 -07006804 &size, &flags)) {
6805 goto exit;
6806 }
6807 return_value = os_getrandom_impl(module, size, flags);
6808
6809exit:
6810 return return_value;
6811}
6812
6813#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
6814
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006815#ifndef OS_TTYNAME_METHODDEF
6816 #define OS_TTYNAME_METHODDEF
6817#endif /* !defined(OS_TTYNAME_METHODDEF) */
6818
6819#ifndef OS_CTERMID_METHODDEF
6820 #define OS_CTERMID_METHODDEF
6821#endif /* !defined(OS_CTERMID_METHODDEF) */
6822
6823#ifndef OS_FCHDIR_METHODDEF
6824 #define OS_FCHDIR_METHODDEF
6825#endif /* !defined(OS_FCHDIR_METHODDEF) */
6826
6827#ifndef OS_FCHMOD_METHODDEF
6828 #define OS_FCHMOD_METHODDEF
6829#endif /* !defined(OS_FCHMOD_METHODDEF) */
6830
6831#ifndef OS_LCHMOD_METHODDEF
6832 #define OS_LCHMOD_METHODDEF
6833#endif /* !defined(OS_LCHMOD_METHODDEF) */
6834
6835#ifndef OS_CHFLAGS_METHODDEF
6836 #define OS_CHFLAGS_METHODDEF
6837#endif /* !defined(OS_CHFLAGS_METHODDEF) */
6838
6839#ifndef OS_LCHFLAGS_METHODDEF
6840 #define OS_LCHFLAGS_METHODDEF
6841#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
6842
6843#ifndef OS_CHROOT_METHODDEF
6844 #define OS_CHROOT_METHODDEF
6845#endif /* !defined(OS_CHROOT_METHODDEF) */
6846
6847#ifndef OS_FSYNC_METHODDEF
6848 #define OS_FSYNC_METHODDEF
6849#endif /* !defined(OS_FSYNC_METHODDEF) */
6850
6851#ifndef OS_SYNC_METHODDEF
6852 #define OS_SYNC_METHODDEF
6853#endif /* !defined(OS_SYNC_METHODDEF) */
6854
6855#ifndef OS_FDATASYNC_METHODDEF
6856 #define OS_FDATASYNC_METHODDEF
6857#endif /* !defined(OS_FDATASYNC_METHODDEF) */
6858
6859#ifndef OS_CHOWN_METHODDEF
6860 #define OS_CHOWN_METHODDEF
6861#endif /* !defined(OS_CHOWN_METHODDEF) */
6862
6863#ifndef OS_FCHOWN_METHODDEF
6864 #define OS_FCHOWN_METHODDEF
6865#endif /* !defined(OS_FCHOWN_METHODDEF) */
6866
6867#ifndef OS_LCHOWN_METHODDEF
6868 #define OS_LCHOWN_METHODDEF
6869#endif /* !defined(OS_LCHOWN_METHODDEF) */
6870
6871#ifndef OS_LINK_METHODDEF
6872 #define OS_LINK_METHODDEF
6873#endif /* !defined(OS_LINK_METHODDEF) */
6874
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006875#ifndef OS__GETFULLPATHNAME_METHODDEF
6876 #define OS__GETFULLPATHNAME_METHODDEF
6877#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
6878
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006879#ifndef OS__GETFINALPATHNAME_METHODDEF
6880 #define OS__GETFINALPATHNAME_METHODDEF
6881#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
6882
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03006883#ifndef OS__ISDIR_METHODDEF
6884 #define OS__ISDIR_METHODDEF
6885#endif /* !defined(OS__ISDIR_METHODDEF) */
6886
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006887#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
6888 #define OS__GETVOLUMEPATHNAME_METHODDEF
6889#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
6890
6891#ifndef OS_NICE_METHODDEF
6892 #define OS_NICE_METHODDEF
6893#endif /* !defined(OS_NICE_METHODDEF) */
6894
6895#ifndef OS_GETPRIORITY_METHODDEF
6896 #define OS_GETPRIORITY_METHODDEF
6897#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
6898
6899#ifndef OS_SETPRIORITY_METHODDEF
6900 #define OS_SETPRIORITY_METHODDEF
6901#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
6902
6903#ifndef OS_SYSTEM_METHODDEF
6904 #define OS_SYSTEM_METHODDEF
6905#endif /* !defined(OS_SYSTEM_METHODDEF) */
6906
6907#ifndef OS_UNAME_METHODDEF
6908 #define OS_UNAME_METHODDEF
6909#endif /* !defined(OS_UNAME_METHODDEF) */
6910
6911#ifndef OS_EXECV_METHODDEF
6912 #define OS_EXECV_METHODDEF
6913#endif /* !defined(OS_EXECV_METHODDEF) */
6914
6915#ifndef OS_EXECVE_METHODDEF
6916 #define OS_EXECVE_METHODDEF
6917#endif /* !defined(OS_EXECVE_METHODDEF) */
6918
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00006919#ifndef OS_POSIX_SPAWN_METHODDEF
6920 #define OS_POSIX_SPAWN_METHODDEF
6921#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
6922
Joannah Nanjekye92b83222019-01-16 16:29:26 +03006923#ifndef OS_POSIX_SPAWNP_METHODDEF
6924 #define OS_POSIX_SPAWNP_METHODDEF
6925#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
6926
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006927#ifndef OS_SPAWNV_METHODDEF
6928 #define OS_SPAWNV_METHODDEF
6929#endif /* !defined(OS_SPAWNV_METHODDEF) */
6930
6931#ifndef OS_SPAWNVE_METHODDEF
6932 #define OS_SPAWNVE_METHODDEF
6933#endif /* !defined(OS_SPAWNVE_METHODDEF) */
6934
Antoine Pitrou346cbd32017-05-27 17:50:54 +02006935#ifndef OS_REGISTER_AT_FORK_METHODDEF
6936 #define OS_REGISTER_AT_FORK_METHODDEF
6937#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
6938
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006939#ifndef OS_FORK1_METHODDEF
6940 #define OS_FORK1_METHODDEF
6941#endif /* !defined(OS_FORK1_METHODDEF) */
6942
6943#ifndef OS_FORK_METHODDEF
6944 #define OS_FORK_METHODDEF
6945#endif /* !defined(OS_FORK_METHODDEF) */
6946
6947#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6948 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
6949#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
6950
6951#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6952 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
6953#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
6954
6955#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
6956 #define OS_SCHED_GETSCHEDULER_METHODDEF
6957#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
6958
6959#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
6960 #define OS_SCHED_SETSCHEDULER_METHODDEF
6961#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
6962
6963#ifndef OS_SCHED_GETPARAM_METHODDEF
6964 #define OS_SCHED_GETPARAM_METHODDEF
6965#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
6966
6967#ifndef OS_SCHED_SETPARAM_METHODDEF
6968 #define OS_SCHED_SETPARAM_METHODDEF
6969#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
6970
6971#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
6972 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
6973#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
6974
6975#ifndef OS_SCHED_YIELD_METHODDEF
6976 #define OS_SCHED_YIELD_METHODDEF
6977#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
6978
6979#ifndef OS_SCHED_SETAFFINITY_METHODDEF
6980 #define OS_SCHED_SETAFFINITY_METHODDEF
6981#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
6982
6983#ifndef OS_SCHED_GETAFFINITY_METHODDEF
6984 #define OS_SCHED_GETAFFINITY_METHODDEF
6985#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
6986
6987#ifndef OS_OPENPTY_METHODDEF
6988 #define OS_OPENPTY_METHODDEF
6989#endif /* !defined(OS_OPENPTY_METHODDEF) */
6990
6991#ifndef OS_FORKPTY_METHODDEF
6992 #define OS_FORKPTY_METHODDEF
6993#endif /* !defined(OS_FORKPTY_METHODDEF) */
6994
6995#ifndef OS_GETEGID_METHODDEF
6996 #define OS_GETEGID_METHODDEF
6997#endif /* !defined(OS_GETEGID_METHODDEF) */
6998
6999#ifndef OS_GETEUID_METHODDEF
7000 #define OS_GETEUID_METHODDEF
7001#endif /* !defined(OS_GETEUID_METHODDEF) */
7002
7003#ifndef OS_GETGID_METHODDEF
7004 #define OS_GETGID_METHODDEF
7005#endif /* !defined(OS_GETGID_METHODDEF) */
7006
Berker Peksag39404992016-09-15 20:45:16 +03007007#ifndef OS_GETPID_METHODDEF
7008 #define OS_GETPID_METHODDEF
7009#endif /* !defined(OS_GETPID_METHODDEF) */
7010
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007011#ifndef OS_GETGROUPS_METHODDEF
7012 #define OS_GETGROUPS_METHODDEF
7013#endif /* !defined(OS_GETGROUPS_METHODDEF) */
7014
7015#ifndef OS_GETPGID_METHODDEF
7016 #define OS_GETPGID_METHODDEF
7017#endif /* !defined(OS_GETPGID_METHODDEF) */
7018
7019#ifndef OS_GETPGRP_METHODDEF
7020 #define OS_GETPGRP_METHODDEF
7021#endif /* !defined(OS_GETPGRP_METHODDEF) */
7022
7023#ifndef OS_SETPGRP_METHODDEF
7024 #define OS_SETPGRP_METHODDEF
7025#endif /* !defined(OS_SETPGRP_METHODDEF) */
7026
7027#ifndef OS_GETPPID_METHODDEF
7028 #define OS_GETPPID_METHODDEF
7029#endif /* !defined(OS_GETPPID_METHODDEF) */
7030
7031#ifndef OS_GETLOGIN_METHODDEF
7032 #define OS_GETLOGIN_METHODDEF
7033#endif /* !defined(OS_GETLOGIN_METHODDEF) */
7034
7035#ifndef OS_GETUID_METHODDEF
7036 #define OS_GETUID_METHODDEF
7037#endif /* !defined(OS_GETUID_METHODDEF) */
7038
7039#ifndef OS_KILL_METHODDEF
7040 #define OS_KILL_METHODDEF
7041#endif /* !defined(OS_KILL_METHODDEF) */
7042
7043#ifndef OS_KILLPG_METHODDEF
7044 #define OS_KILLPG_METHODDEF
7045#endif /* !defined(OS_KILLPG_METHODDEF) */
7046
7047#ifndef OS_PLOCK_METHODDEF
7048 #define OS_PLOCK_METHODDEF
7049#endif /* !defined(OS_PLOCK_METHODDEF) */
7050
7051#ifndef OS_SETUID_METHODDEF
7052 #define OS_SETUID_METHODDEF
7053#endif /* !defined(OS_SETUID_METHODDEF) */
7054
7055#ifndef OS_SETEUID_METHODDEF
7056 #define OS_SETEUID_METHODDEF
7057#endif /* !defined(OS_SETEUID_METHODDEF) */
7058
7059#ifndef OS_SETEGID_METHODDEF
7060 #define OS_SETEGID_METHODDEF
7061#endif /* !defined(OS_SETEGID_METHODDEF) */
7062
7063#ifndef OS_SETREUID_METHODDEF
7064 #define OS_SETREUID_METHODDEF
7065#endif /* !defined(OS_SETREUID_METHODDEF) */
7066
7067#ifndef OS_SETREGID_METHODDEF
7068 #define OS_SETREGID_METHODDEF
7069#endif /* !defined(OS_SETREGID_METHODDEF) */
7070
7071#ifndef OS_SETGID_METHODDEF
7072 #define OS_SETGID_METHODDEF
7073#endif /* !defined(OS_SETGID_METHODDEF) */
7074
7075#ifndef OS_SETGROUPS_METHODDEF
7076 #define OS_SETGROUPS_METHODDEF
7077#endif /* !defined(OS_SETGROUPS_METHODDEF) */
7078
7079#ifndef OS_WAIT3_METHODDEF
7080 #define OS_WAIT3_METHODDEF
7081#endif /* !defined(OS_WAIT3_METHODDEF) */
7082
7083#ifndef OS_WAIT4_METHODDEF
7084 #define OS_WAIT4_METHODDEF
7085#endif /* !defined(OS_WAIT4_METHODDEF) */
7086
7087#ifndef OS_WAITID_METHODDEF
7088 #define OS_WAITID_METHODDEF
7089#endif /* !defined(OS_WAITID_METHODDEF) */
7090
7091#ifndef OS_WAITPID_METHODDEF
7092 #define OS_WAITPID_METHODDEF
7093#endif /* !defined(OS_WAITPID_METHODDEF) */
7094
7095#ifndef OS_WAIT_METHODDEF
7096 #define OS_WAIT_METHODDEF
7097#endif /* !defined(OS_WAIT_METHODDEF) */
7098
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007099#ifndef OS_READLINK_METHODDEF
7100 #define OS_READLINK_METHODDEF
7101#endif /* !defined(OS_READLINK_METHODDEF) */
7102
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007103#ifndef OS_SYMLINK_METHODDEF
7104 #define OS_SYMLINK_METHODDEF
7105#endif /* !defined(OS_SYMLINK_METHODDEF) */
7106
7107#ifndef OS_TIMES_METHODDEF
7108 #define OS_TIMES_METHODDEF
7109#endif /* !defined(OS_TIMES_METHODDEF) */
7110
7111#ifndef OS_GETSID_METHODDEF
7112 #define OS_GETSID_METHODDEF
7113#endif /* !defined(OS_GETSID_METHODDEF) */
7114
7115#ifndef OS_SETSID_METHODDEF
7116 #define OS_SETSID_METHODDEF
7117#endif /* !defined(OS_SETSID_METHODDEF) */
7118
7119#ifndef OS_SETPGID_METHODDEF
7120 #define OS_SETPGID_METHODDEF
7121#endif /* !defined(OS_SETPGID_METHODDEF) */
7122
7123#ifndef OS_TCGETPGRP_METHODDEF
7124 #define OS_TCGETPGRP_METHODDEF
7125#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
7126
7127#ifndef OS_TCSETPGRP_METHODDEF
7128 #define OS_TCSETPGRP_METHODDEF
7129#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
7130
7131#ifndef OS_LOCKF_METHODDEF
7132 #define OS_LOCKF_METHODDEF
7133#endif /* !defined(OS_LOCKF_METHODDEF) */
7134
7135#ifndef OS_READV_METHODDEF
7136 #define OS_READV_METHODDEF
7137#endif /* !defined(OS_READV_METHODDEF) */
7138
7139#ifndef OS_PREAD_METHODDEF
7140 #define OS_PREAD_METHODDEF
7141#endif /* !defined(OS_PREAD_METHODDEF) */
7142
Pablo Galindo4defba32018-01-27 16:16:37 +00007143#ifndef OS_PREADV_METHODDEF
7144 #define OS_PREADV_METHODDEF
7145#endif /* !defined(OS_PREADV_METHODDEF) */
7146
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02007147#ifndef OS__FCOPYFILE_METHODDEF
7148 #define OS__FCOPYFILE_METHODDEF
7149#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
7150
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007151#ifndef OS_PIPE_METHODDEF
7152 #define OS_PIPE_METHODDEF
7153#endif /* !defined(OS_PIPE_METHODDEF) */
7154
7155#ifndef OS_PIPE2_METHODDEF
7156 #define OS_PIPE2_METHODDEF
7157#endif /* !defined(OS_PIPE2_METHODDEF) */
7158
7159#ifndef OS_WRITEV_METHODDEF
7160 #define OS_WRITEV_METHODDEF
7161#endif /* !defined(OS_WRITEV_METHODDEF) */
7162
7163#ifndef OS_PWRITE_METHODDEF
7164 #define OS_PWRITE_METHODDEF
7165#endif /* !defined(OS_PWRITE_METHODDEF) */
7166
Pablo Galindo4defba32018-01-27 16:16:37 +00007167#ifndef OS_PWRITEV_METHODDEF
7168 #define OS_PWRITEV_METHODDEF
7169#endif /* !defined(OS_PWRITEV_METHODDEF) */
7170
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007171#ifndef OS_MKFIFO_METHODDEF
7172 #define OS_MKFIFO_METHODDEF
7173#endif /* !defined(OS_MKFIFO_METHODDEF) */
7174
7175#ifndef OS_MKNOD_METHODDEF
7176 #define OS_MKNOD_METHODDEF
7177#endif /* !defined(OS_MKNOD_METHODDEF) */
7178
7179#ifndef OS_MAJOR_METHODDEF
7180 #define OS_MAJOR_METHODDEF
7181#endif /* !defined(OS_MAJOR_METHODDEF) */
7182
7183#ifndef OS_MINOR_METHODDEF
7184 #define OS_MINOR_METHODDEF
7185#endif /* !defined(OS_MINOR_METHODDEF) */
7186
7187#ifndef OS_MAKEDEV_METHODDEF
7188 #define OS_MAKEDEV_METHODDEF
7189#endif /* !defined(OS_MAKEDEV_METHODDEF) */
7190
7191#ifndef OS_FTRUNCATE_METHODDEF
7192 #define OS_FTRUNCATE_METHODDEF
7193#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
7194
7195#ifndef OS_TRUNCATE_METHODDEF
7196 #define OS_TRUNCATE_METHODDEF
7197#endif /* !defined(OS_TRUNCATE_METHODDEF) */
7198
7199#ifndef OS_POSIX_FALLOCATE_METHODDEF
7200 #define OS_POSIX_FALLOCATE_METHODDEF
7201#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
7202
7203#ifndef OS_POSIX_FADVISE_METHODDEF
7204 #define OS_POSIX_FADVISE_METHODDEF
7205#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
7206
7207#ifndef OS_PUTENV_METHODDEF
7208 #define OS_PUTENV_METHODDEF
7209#endif /* !defined(OS_PUTENV_METHODDEF) */
7210
7211#ifndef OS_UNSETENV_METHODDEF
7212 #define OS_UNSETENV_METHODDEF
7213#endif /* !defined(OS_UNSETENV_METHODDEF) */
7214
7215#ifndef OS_WCOREDUMP_METHODDEF
7216 #define OS_WCOREDUMP_METHODDEF
7217#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
7218
7219#ifndef OS_WIFCONTINUED_METHODDEF
7220 #define OS_WIFCONTINUED_METHODDEF
7221#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
7222
7223#ifndef OS_WIFSTOPPED_METHODDEF
7224 #define OS_WIFSTOPPED_METHODDEF
7225#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
7226
7227#ifndef OS_WIFSIGNALED_METHODDEF
7228 #define OS_WIFSIGNALED_METHODDEF
7229#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
7230
7231#ifndef OS_WIFEXITED_METHODDEF
7232 #define OS_WIFEXITED_METHODDEF
7233#endif /* !defined(OS_WIFEXITED_METHODDEF) */
7234
7235#ifndef OS_WEXITSTATUS_METHODDEF
7236 #define OS_WEXITSTATUS_METHODDEF
7237#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
7238
7239#ifndef OS_WTERMSIG_METHODDEF
7240 #define OS_WTERMSIG_METHODDEF
7241#endif /* !defined(OS_WTERMSIG_METHODDEF) */
7242
7243#ifndef OS_WSTOPSIG_METHODDEF
7244 #define OS_WSTOPSIG_METHODDEF
7245#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
7246
7247#ifndef OS_FSTATVFS_METHODDEF
7248 #define OS_FSTATVFS_METHODDEF
7249#endif /* !defined(OS_FSTATVFS_METHODDEF) */
7250
7251#ifndef OS_STATVFS_METHODDEF
7252 #define OS_STATVFS_METHODDEF
7253#endif /* !defined(OS_STATVFS_METHODDEF) */
7254
7255#ifndef OS__GETDISKUSAGE_METHODDEF
7256 #define OS__GETDISKUSAGE_METHODDEF
7257#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
7258
7259#ifndef OS_FPATHCONF_METHODDEF
7260 #define OS_FPATHCONF_METHODDEF
7261#endif /* !defined(OS_FPATHCONF_METHODDEF) */
7262
7263#ifndef OS_PATHCONF_METHODDEF
7264 #define OS_PATHCONF_METHODDEF
7265#endif /* !defined(OS_PATHCONF_METHODDEF) */
7266
7267#ifndef OS_CONFSTR_METHODDEF
7268 #define OS_CONFSTR_METHODDEF
7269#endif /* !defined(OS_CONFSTR_METHODDEF) */
7270
7271#ifndef OS_SYSCONF_METHODDEF
7272 #define OS_SYSCONF_METHODDEF
7273#endif /* !defined(OS_SYSCONF_METHODDEF) */
7274
Steve Dowercc16be82016-09-08 10:35:16 -07007275#ifndef OS_STARTFILE_METHODDEF
7276 #define OS_STARTFILE_METHODDEF
7277#endif /* !defined(OS_STARTFILE_METHODDEF) */
7278
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007279#ifndef OS_GETLOADAVG_METHODDEF
7280 #define OS_GETLOADAVG_METHODDEF
7281#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
7282
7283#ifndef OS_SETRESUID_METHODDEF
7284 #define OS_SETRESUID_METHODDEF
7285#endif /* !defined(OS_SETRESUID_METHODDEF) */
7286
7287#ifndef OS_SETRESGID_METHODDEF
7288 #define OS_SETRESGID_METHODDEF
7289#endif /* !defined(OS_SETRESGID_METHODDEF) */
7290
7291#ifndef OS_GETRESUID_METHODDEF
7292 #define OS_GETRESUID_METHODDEF
7293#endif /* !defined(OS_GETRESUID_METHODDEF) */
7294
7295#ifndef OS_GETRESGID_METHODDEF
7296 #define OS_GETRESGID_METHODDEF
7297#endif /* !defined(OS_GETRESGID_METHODDEF) */
7298
7299#ifndef OS_GETXATTR_METHODDEF
7300 #define OS_GETXATTR_METHODDEF
7301#endif /* !defined(OS_GETXATTR_METHODDEF) */
7302
7303#ifndef OS_SETXATTR_METHODDEF
7304 #define OS_SETXATTR_METHODDEF
7305#endif /* !defined(OS_SETXATTR_METHODDEF) */
7306
7307#ifndef OS_REMOVEXATTR_METHODDEF
7308 #define OS_REMOVEXATTR_METHODDEF
7309#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
7310
7311#ifndef OS_LISTXATTR_METHODDEF
7312 #define OS_LISTXATTR_METHODDEF
7313#endif /* !defined(OS_LISTXATTR_METHODDEF) */
7314
7315#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
7316 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
7317#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
7318
7319#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
7320 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
7321#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07007322
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007323#ifndef OS_GET_BLOCKING_METHODDEF
7324 #define OS_GET_BLOCKING_METHODDEF
7325#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
7326
7327#ifndef OS_SET_BLOCKING_METHODDEF
7328 #define OS_SET_BLOCKING_METHODDEF
7329#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
7330
Victor Stinner9b1f4742016-09-06 16:18:52 -07007331#ifndef OS_GETRANDOM_METHODDEF
7332 #define OS_GETRANDOM_METHODDEF
7333#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Joannah Nanjekye92b83222019-01-16 16:29:26 +03007334/*[clinic end generated code: output=dabd0fa27bf87044 input=a9049054013a1b77]*/