blob: 43f8ba6b4e6161d4f99c4956eb011bb0b11b1e4f [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};
Serhiy Storchaka31913912019-03-14 10:32:22 +020041 static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0};
42 PyObject *argsbuf[3];
43 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030044 path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
45 int dir_fd = DEFAULT_DIR_FD;
46 int follow_symlinks = 1;
47
Serhiy Storchaka31913912019-03-14 10:32:22 +020048 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
49 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030050 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030051 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020052 if (!path_converter(args[0], &path)) {
53 goto exit;
54 }
55 if (!noptargs) {
56 goto skip_optional_kwonly;
57 }
58 if (args[1]) {
59 if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
60 goto exit;
61 }
62 if (!--noptargs) {
63 goto skip_optional_kwonly;
64 }
65 }
66 follow_symlinks = PyObject_IsTrue(args[2]);
67 if (follow_symlinks < 0) {
68 goto exit;
69 }
70skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030071 return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
72
73exit:
74 /* Cleanup for path */
75 path_cleanup(&path);
76
77 return return_value;
78}
79
80PyDoc_STRVAR(os_lstat__doc__,
81"lstat($module, /, path, *, dir_fd=None)\n"
82"--\n"
83"\n"
84"Perform a stat system call on the given path, without following symbolic links.\n"
85"\n"
86"Like stat(), but do not follow symbolic links.\n"
87"Equivalent to stat(path, follow_symlinks=False).");
88
89#define OS_LSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020090 {"lstat", (PyCFunction)(void(*)(void))os_lstat, METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030091
92static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030093os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030094
95static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020096os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030097{
98 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030099 static const char * const _keywords[] = {"path", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200100 static _PyArg_Parser _parser = {NULL, _keywords, "lstat", 0};
101 PyObject *argsbuf[2];
102 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300103 path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
104 int dir_fd = DEFAULT_DIR_FD;
105
Serhiy Storchaka31913912019-03-14 10:32:22 +0200106 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
107 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300109 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200110 if (!path_converter(args[0], &path)) {
111 goto exit;
112 }
113 if (!noptargs) {
114 goto skip_optional_kwonly;
115 }
116 if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
117 goto exit;
118 }
119skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300120 return_value = os_lstat_impl(module, &path, dir_fd);
121
122exit:
123 /* Cleanup for path */
124 path_cleanup(&path);
125
126 return return_value;
127}
128
129PyDoc_STRVAR(os_access__doc__,
130"access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
131" follow_symlinks=True)\n"
132"--\n"
133"\n"
134"Use the real uid/gid to test for access to a path.\n"
135"\n"
136" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000137" Path to be tested; can be string, bytes, or a path-like object.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300138" mode\n"
139" Operating-system mode bitfield. Can be F_OK to test existence,\n"
140" or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
141" dir_fd\n"
142" If not None, it should be a file descriptor open to a directory,\n"
143" and path should be relative; path will then be relative to that\n"
144" directory.\n"
145" effective_ids\n"
146" If True, access will use the effective uid/gid instead of\n"
147" the real uid/gid.\n"
148" follow_symlinks\n"
149" If False, and the last element of the path is a symbolic link,\n"
150" access will examine the symbolic link itself instead of the file\n"
151" the link points to.\n"
152"\n"
153"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
154" on your platform. If they are unavailable, using them will raise a\n"
155" NotImplementedError.\n"
156"\n"
157"Note that most operations will use the effective uid/gid, therefore this\n"
158" routine can be used in a suid/sgid environment to test if the invoking user\n"
159" has the specified access to the path.");
160
161#define OS_ACCESS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200162 {"access", (PyCFunction)(void(*)(void))os_access, METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300163
164static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300165os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400166 int effective_ids, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300167
168static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200169os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300170{
171 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300172 static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200173 static _PyArg_Parser _parser = {NULL, _keywords, "access", 0};
174 PyObject *argsbuf[5];
175 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Benjamin Peterson768f3b42016-09-05 15:29:33 -0700176 path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300177 int mode;
178 int dir_fd = DEFAULT_DIR_FD;
179 int effective_ids = 0;
180 int follow_symlinks = 1;
181 int _return_value;
182
Serhiy Storchaka31913912019-03-14 10:32:22 +0200183 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
184 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300185 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300186 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200187 if (!path_converter(args[0], &path)) {
188 goto exit;
189 }
190 if (PyFloat_Check(args[1])) {
191 PyErr_SetString(PyExc_TypeError,
192 "integer argument expected, got float" );
193 goto exit;
194 }
195 mode = _PyLong_AsInt(args[1]);
196 if (mode == -1 && PyErr_Occurred()) {
197 goto exit;
198 }
199 if (!noptargs) {
200 goto skip_optional_kwonly;
201 }
202 if (args[2]) {
203 if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
204 goto exit;
205 }
206 if (!--noptargs) {
207 goto skip_optional_kwonly;
208 }
209 }
210 if (args[3]) {
211 effective_ids = PyObject_IsTrue(args[3]);
212 if (effective_ids < 0) {
213 goto exit;
214 }
215 if (!--noptargs) {
216 goto skip_optional_kwonly;
217 }
218 }
219 follow_symlinks = PyObject_IsTrue(args[4]);
220 if (follow_symlinks < 0) {
221 goto exit;
222 }
223skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300224 _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300225 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300226 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300227 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300228 return_value = PyBool_FromLong((long)_return_value);
229
230exit:
231 /* Cleanup for path */
232 path_cleanup(&path);
233
234 return return_value;
235}
236
237#if defined(HAVE_TTYNAME)
238
239PyDoc_STRVAR(os_ttyname__doc__,
240"ttyname($module, fd, /)\n"
241"--\n"
242"\n"
243"Return the name of the terminal device connected to \'fd\'.\n"
244"\n"
245" fd\n"
246" Integer file descriptor handle.");
247
248#define OS_TTYNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300249 {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300250
Serhiy Storchaka4db62e12018-12-17 16:47:45 +0200251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300252os_ttyname_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300253
254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300255os_ttyname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300256{
257 PyObject *return_value = NULL;
258 int fd;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300259
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200260 if (PyFloat_Check(arg)) {
261 PyErr_SetString(PyExc_TypeError,
262 "integer argument expected, got float" );
263 goto exit;
264 }
265 fd = _PyLong_AsInt(arg);
266 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300267 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300268 }
Serhiy Storchaka4db62e12018-12-17 16:47:45 +0200269 return_value = os_ttyname_impl(module, fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300270
271exit:
272 return return_value;
273}
274
275#endif /* defined(HAVE_TTYNAME) */
276
277#if defined(HAVE_CTERMID)
278
279PyDoc_STRVAR(os_ctermid__doc__,
280"ctermid($module, /)\n"
281"--\n"
282"\n"
283"Return the name of the controlling terminal for this process.");
284
285#define OS_CTERMID_METHODDEF \
286 {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
287
288static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300289os_ctermid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300290
291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300292os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300293{
294 return os_ctermid_impl(module);
295}
296
297#endif /* defined(HAVE_CTERMID) */
298
299PyDoc_STRVAR(os_chdir__doc__,
300"chdir($module, /, path)\n"
301"--\n"
302"\n"
303"Change the current working directory to the specified path.\n"
304"\n"
305"path may always be specified as a string.\n"
306"On some platforms, path may also be specified as an open file descriptor.\n"
307" If this functionality is unavailable, using it raises an exception.");
308
309#define OS_CHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200310 {"chdir", (PyCFunction)(void(*)(void))os_chdir, METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300311
312static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300313os_chdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300314
315static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200316os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300317{
318 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300319 static const char * const _keywords[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200320 static _PyArg_Parser _parser = {NULL, _keywords, "chdir", 0};
321 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300322 path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
323
Serhiy Storchaka31913912019-03-14 10:32:22 +0200324 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
325 if (!args) {
326 goto exit;
327 }
328 if (!path_converter(args[0], &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300329 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300330 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300331 return_value = os_chdir_impl(module, &path);
332
333exit:
334 /* Cleanup for path */
335 path_cleanup(&path);
336
337 return return_value;
338}
339
340#if defined(HAVE_FCHDIR)
341
342PyDoc_STRVAR(os_fchdir__doc__,
343"fchdir($module, /, fd)\n"
344"--\n"
345"\n"
346"Change to the directory of the given file descriptor.\n"
347"\n"
348"fd must be opened on a directory, not a file.\n"
349"Equivalent to os.chdir(fd).");
350
351#define OS_FCHDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200352 {"fchdir", (PyCFunction)(void(*)(void))os_fchdir, METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300353
354static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300355os_fchdir_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300356
357static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200358os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300359{
360 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300361 static const char * const _keywords[] = {"fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200362 static _PyArg_Parser _parser = {NULL, _keywords, "fchdir", 0};
363 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300364 int fd;
365
Serhiy Storchaka31913912019-03-14 10:32:22 +0200366 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
367 if (!args) {
368 goto exit;
369 }
370 if (!fildes_converter(args[0], &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300371 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300372 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300373 return_value = os_fchdir_impl(module, fd);
374
375exit:
376 return return_value;
377}
378
379#endif /* defined(HAVE_FCHDIR) */
380
381PyDoc_STRVAR(os_chmod__doc__,
382"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
383"--\n"
384"\n"
385"Change the access permissions of a file.\n"
386"\n"
387" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000388" 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 +0300389" On some platforms, path may also be specified as an open file descriptor.\n"
390" If this functionality is unavailable, using it raises an exception.\n"
391" mode\n"
392" Operating-system mode bitfield.\n"
393" dir_fd\n"
394" If not None, it should be a file descriptor open to a directory,\n"
395" and path should be relative; path will then be relative to that\n"
396" directory.\n"
397" follow_symlinks\n"
398" If False, and the last element of the path is a symbolic link,\n"
399" chmod will modify the symbolic link itself instead of the file\n"
400" the link points to.\n"
401"\n"
402"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
403" an open file descriptor.\n"
404"dir_fd and follow_symlinks may not be implemented on your platform.\n"
405" If they are unavailable, using them will raise a NotImplementedError.");
406
407#define OS_CHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200408 {"chmod", (PyCFunction)(void(*)(void))os_chmod, METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300409
410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300411os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -0400412 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300413
414static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200415os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300416{
417 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300418 static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200419 static _PyArg_Parser _parser = {NULL, _keywords, "chmod", 0};
420 PyObject *argsbuf[4];
421 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422 path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
423 int mode;
424 int dir_fd = DEFAULT_DIR_FD;
425 int follow_symlinks = 1;
426
Serhiy Storchaka31913912019-03-14 10:32:22 +0200427 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
428 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300429 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300430 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200431 if (!path_converter(args[0], &path)) {
432 goto exit;
433 }
434 if (PyFloat_Check(args[1])) {
435 PyErr_SetString(PyExc_TypeError,
436 "integer argument expected, got float" );
437 goto exit;
438 }
439 mode = _PyLong_AsInt(args[1]);
440 if (mode == -1 && PyErr_Occurred()) {
441 goto exit;
442 }
443 if (!noptargs) {
444 goto skip_optional_kwonly;
445 }
446 if (args[2]) {
447 if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
448 goto exit;
449 }
450 if (!--noptargs) {
451 goto skip_optional_kwonly;
452 }
453 }
454 follow_symlinks = PyObject_IsTrue(args[3]);
455 if (follow_symlinks < 0) {
456 goto exit;
457 }
458skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300459 return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
460
461exit:
462 /* Cleanup for path */
463 path_cleanup(&path);
464
465 return return_value;
466}
467
468#if defined(HAVE_FCHMOD)
469
470PyDoc_STRVAR(os_fchmod__doc__,
471"fchmod($module, /, fd, mode)\n"
472"--\n"
473"\n"
474"Change the access permissions of the file given by file descriptor fd.\n"
475"\n"
476"Equivalent to os.chmod(fd, mode).");
477
478#define OS_FCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200479 {"fchmod", (PyCFunction)(void(*)(void))os_fchmod, METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300480
481static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300482os_fchmod_impl(PyObject *module, int fd, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300483
484static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200485os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300486{
487 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300488 static const char * const _keywords[] = {"fd", "mode", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200489 static _PyArg_Parser _parser = {NULL, _keywords, "fchmod", 0};
490 PyObject *argsbuf[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300491 int fd;
492 int mode;
493
Serhiy Storchaka31913912019-03-14 10:32:22 +0200494 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
495 if (!args) {
496 goto exit;
497 }
498 if (PyFloat_Check(args[0])) {
499 PyErr_SetString(PyExc_TypeError,
500 "integer argument expected, got float" );
501 goto exit;
502 }
503 fd = _PyLong_AsInt(args[0]);
504 if (fd == -1 && PyErr_Occurred()) {
505 goto exit;
506 }
507 if (PyFloat_Check(args[1])) {
508 PyErr_SetString(PyExc_TypeError,
509 "integer argument expected, got float" );
510 goto exit;
511 }
512 mode = _PyLong_AsInt(args[1]);
513 if (mode == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300514 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300515 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300516 return_value = os_fchmod_impl(module, fd, mode);
517
518exit:
519 return return_value;
520}
521
522#endif /* defined(HAVE_FCHMOD) */
523
524#if defined(HAVE_LCHMOD)
525
526PyDoc_STRVAR(os_lchmod__doc__,
527"lchmod($module, /, path, mode)\n"
528"--\n"
529"\n"
530"Change the access permissions of a file, without following symbolic links.\n"
531"\n"
532"If path is a symlink, this affects the link itself rather than the target.\n"
533"Equivalent to chmod(path, mode, follow_symlinks=False).\"");
534
535#define OS_LCHMOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200536 {"lchmod", (PyCFunction)(void(*)(void))os_lchmod, METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537
538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300539os_lchmod_impl(PyObject *module, path_t *path, int mode);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300540
541static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200542os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300543{
544 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300545 static const char * const _keywords[] = {"path", "mode", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200546 static _PyArg_Parser _parser = {NULL, _keywords, "lchmod", 0};
547 PyObject *argsbuf[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
549 int mode;
550
Serhiy Storchaka31913912019-03-14 10:32:22 +0200551 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
552 if (!args) {
553 goto exit;
554 }
555 if (!path_converter(args[0], &path)) {
556 goto exit;
557 }
558 if (PyFloat_Check(args[1])) {
559 PyErr_SetString(PyExc_TypeError,
560 "integer argument expected, got float" );
561 goto exit;
562 }
563 mode = _PyLong_AsInt(args[1]);
564 if (mode == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300565 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300566 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300567 return_value = os_lchmod_impl(module, &path, mode);
568
569exit:
570 /* Cleanup for path */
571 path_cleanup(&path);
572
573 return return_value;
574}
575
576#endif /* defined(HAVE_LCHMOD) */
577
578#if defined(HAVE_CHFLAGS)
579
580PyDoc_STRVAR(os_chflags__doc__,
581"chflags($module, /, path, flags, follow_symlinks=True)\n"
582"--\n"
583"\n"
584"Set file flags.\n"
585"\n"
586"If follow_symlinks is False, and the last element of the path is a symbolic\n"
587" link, chflags will change flags on the symbolic link itself instead of the\n"
588" file the link points to.\n"
589"follow_symlinks may not be implemented on your platform. If it is\n"
590"unavailable, using it will raise a NotImplementedError.");
591
592#define OS_CHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200593 {"chflags", (PyCFunction)(void(*)(void))os_chflags, METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300594
595static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300596os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
Larry Hastings89964c42015-04-14 18:07:59 -0400597 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300598
599static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200600os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300601{
602 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300603 static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200604 static _PyArg_Parser _parser = {NULL, _keywords, "chflags", 0};
605 PyObject *argsbuf[3];
606 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300607 path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
608 unsigned long flags;
609 int follow_symlinks = 1;
610
Serhiy Storchaka31913912019-03-14 10:32:22 +0200611 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
612 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300613 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300614 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200615 if (!path_converter(args[0], &path)) {
616 goto exit;
617 }
618 if (!PyLong_Check(args[1])) {
619 _PyArg_BadArgument("chflags", 2, "int", args[1]);
620 goto exit;
621 }
622 flags = PyLong_AsUnsignedLongMask(args[1]);
623 if (!noptargs) {
624 goto skip_optional_pos;
625 }
626 follow_symlinks = PyObject_IsTrue(args[2]);
627 if (follow_symlinks < 0) {
628 goto exit;
629 }
630skip_optional_pos:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631 return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
632
633exit:
634 /* Cleanup for path */
635 path_cleanup(&path);
636
637 return return_value;
638}
639
640#endif /* defined(HAVE_CHFLAGS) */
641
642#if defined(HAVE_LCHFLAGS)
643
644PyDoc_STRVAR(os_lchflags__doc__,
645"lchflags($module, /, path, flags)\n"
646"--\n"
647"\n"
648"Set file flags.\n"
649"\n"
650"This function will not follow symbolic links.\n"
651"Equivalent to chflags(path, flags, follow_symlinks=False).");
652
653#define OS_LCHFLAGS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200654 {"lchflags", (PyCFunction)(void(*)(void))os_lchflags, METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300655
656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300657os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300658
659static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200660os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300661{
662 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300663 static const char * const _keywords[] = {"path", "flags", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200664 static _PyArg_Parser _parser = {NULL, _keywords, "lchflags", 0};
665 PyObject *argsbuf[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300666 path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
667 unsigned long flags;
668
Serhiy Storchaka31913912019-03-14 10:32:22 +0200669 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
670 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300671 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300672 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200673 if (!path_converter(args[0], &path)) {
674 goto exit;
675 }
676 if (!PyLong_Check(args[1])) {
677 _PyArg_BadArgument("lchflags", 2, "int", args[1]);
678 goto exit;
679 }
680 flags = PyLong_AsUnsignedLongMask(args[1]);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300681 return_value = os_lchflags_impl(module, &path, flags);
682
683exit:
684 /* Cleanup for path */
685 path_cleanup(&path);
686
687 return return_value;
688}
689
690#endif /* defined(HAVE_LCHFLAGS) */
691
692#if defined(HAVE_CHROOT)
693
694PyDoc_STRVAR(os_chroot__doc__,
695"chroot($module, /, path)\n"
696"--\n"
697"\n"
698"Change root directory to path.");
699
700#define OS_CHROOT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200701 {"chroot", (PyCFunction)(void(*)(void))os_chroot, METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300702
703static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300704os_chroot_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705
706static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200707os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300708{
709 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300710 static const char * const _keywords[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200711 static _PyArg_Parser _parser = {NULL, _keywords, "chroot", 0};
712 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300713 path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
714
Serhiy Storchaka31913912019-03-14 10:32:22 +0200715 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
716 if (!args) {
717 goto exit;
718 }
719 if (!path_converter(args[0], &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300720 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300721 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300722 return_value = os_chroot_impl(module, &path);
723
724exit:
725 /* Cleanup for path */
726 path_cleanup(&path);
727
728 return return_value;
729}
730
731#endif /* defined(HAVE_CHROOT) */
732
733#if defined(HAVE_FSYNC)
734
735PyDoc_STRVAR(os_fsync__doc__,
736"fsync($module, /, fd)\n"
737"--\n"
738"\n"
739"Force write of fd to disk.");
740
741#define OS_FSYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200742 {"fsync", (PyCFunction)(void(*)(void))os_fsync, METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300743
744static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300745os_fsync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300746
747static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200748os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300749{
750 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300751 static const char * const _keywords[] = {"fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200752 static _PyArg_Parser _parser = {NULL, _keywords, "fsync", 0};
753 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300754 int fd;
755
Serhiy Storchaka31913912019-03-14 10:32:22 +0200756 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
757 if (!args) {
758 goto exit;
759 }
760 if (!fildes_converter(args[0], &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300761 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300762 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300763 return_value = os_fsync_impl(module, fd);
764
765exit:
766 return return_value;
767}
768
769#endif /* defined(HAVE_FSYNC) */
770
771#if defined(HAVE_SYNC)
772
773PyDoc_STRVAR(os_sync__doc__,
774"sync($module, /)\n"
775"--\n"
776"\n"
777"Force write of everything to disk.");
778
779#define OS_SYNC_METHODDEF \
780 {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
781
782static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300783os_sync_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300784
785static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300786os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300787{
788 return os_sync_impl(module);
789}
790
791#endif /* defined(HAVE_SYNC) */
792
793#if defined(HAVE_FDATASYNC)
794
795PyDoc_STRVAR(os_fdatasync__doc__,
796"fdatasync($module, /, fd)\n"
797"--\n"
798"\n"
799"Force write of fd to disk without forcing update of metadata.");
800
801#define OS_FDATASYNC_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200802 {"fdatasync", (PyCFunction)(void(*)(void))os_fdatasync, METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300803
804static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300805os_fdatasync_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300806
807static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200808os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300809{
810 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300811 static const char * const _keywords[] = {"fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200812 static _PyArg_Parser _parser = {NULL, _keywords, "fdatasync", 0};
813 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300814 int fd;
815
Serhiy Storchaka31913912019-03-14 10:32:22 +0200816 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
817 if (!args) {
818 goto exit;
819 }
820 if (!fildes_converter(args[0], &fd)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300821 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300822 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300823 return_value = os_fdatasync_impl(module, fd);
824
825exit:
826 return return_value;
827}
828
829#endif /* defined(HAVE_FDATASYNC) */
830
831#if defined(HAVE_CHOWN)
832
833PyDoc_STRVAR(os_chown__doc__,
834"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
835"--\n"
836"\n"
837"Change the owner and group id of path to the numeric uid and gid.\\\n"
838"\n"
839" path\n"
BNMetricsb9427072018-11-02 15:20:19 +0000840" 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 +0300841" dir_fd\n"
842" If not None, it should be a file descriptor open to a directory,\n"
843" and path should be relative; path will then be relative to that\n"
844" directory.\n"
845" follow_symlinks\n"
846" If False, and the last element of the path is a symbolic link,\n"
847" stat will examine the symbolic link itself instead of the file\n"
848" the link points to.\n"
849"\n"
850"path may always be specified as a string.\n"
851"On some platforms, path may also be specified as an open file descriptor.\n"
852" If this functionality is unavailable, using it raises an exception.\n"
853"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
854" and path should be relative; path will then be relative to that directory.\n"
855"If follow_symlinks is False, and the last element of the path is a symbolic\n"
856" link, chown will modify the symbolic link itself instead of the file the\n"
857" link points to.\n"
858"It is an error to use dir_fd or follow_symlinks when specifying path as\n"
859" an open file descriptor.\n"
860"dir_fd and follow_symlinks may not be implemented on your platform.\n"
861" If they are unavailable, using them will raise a NotImplementedError.");
862
863#define OS_CHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200864 {"chown", (PyCFunction)(void(*)(void))os_chown, METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300865
866static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300867os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
Larry Hastings89964c42015-04-14 18:07:59 -0400868 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300869
870static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200871os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300872{
873 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300874 static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200875 static _PyArg_Parser _parser = {NULL, _keywords, "chown", 0};
876 PyObject *argsbuf[5];
877 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300878 path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
879 uid_t uid;
880 gid_t gid;
881 int dir_fd = DEFAULT_DIR_FD;
882 int follow_symlinks = 1;
883
Serhiy Storchaka31913912019-03-14 10:32:22 +0200884 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
885 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300886 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300887 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200888 if (!path_converter(args[0], &path)) {
889 goto exit;
890 }
891 if (!_Py_Uid_Converter(args[1], &uid)) {
892 goto exit;
893 }
894 if (!_Py_Gid_Converter(args[2], &gid)) {
895 goto exit;
896 }
897 if (!noptargs) {
898 goto skip_optional_kwonly;
899 }
900 if (args[3]) {
901 if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
902 goto exit;
903 }
904 if (!--noptargs) {
905 goto skip_optional_kwonly;
906 }
907 }
908 follow_symlinks = PyObject_IsTrue(args[4]);
909 if (follow_symlinks < 0) {
910 goto exit;
911 }
912skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300913 return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
914
915exit:
916 /* Cleanup for path */
917 path_cleanup(&path);
918
919 return return_value;
920}
921
922#endif /* defined(HAVE_CHOWN) */
923
924#if defined(HAVE_FCHOWN)
925
926PyDoc_STRVAR(os_fchown__doc__,
927"fchown($module, /, fd, uid, gid)\n"
928"--\n"
929"\n"
930"Change the owner and group id of the file specified by file descriptor.\n"
931"\n"
932"Equivalent to os.chown(fd, uid, gid).");
933
934#define OS_FCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200935 {"fchown", (PyCFunction)(void(*)(void))os_fchown, METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300936
937static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300938os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300939
940static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200941os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300942{
943 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300944 static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200945 static _PyArg_Parser _parser = {NULL, _keywords, "fchown", 0};
946 PyObject *argsbuf[3];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300947 int fd;
948 uid_t uid;
949 gid_t gid;
950
Serhiy Storchaka31913912019-03-14 10:32:22 +0200951 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
952 if (!args) {
953 goto exit;
954 }
955 if (PyFloat_Check(args[0])) {
956 PyErr_SetString(PyExc_TypeError,
957 "integer argument expected, got float" );
958 goto exit;
959 }
960 fd = _PyLong_AsInt(args[0]);
961 if (fd == -1 && PyErr_Occurred()) {
962 goto exit;
963 }
964 if (!_Py_Uid_Converter(args[1], &uid)) {
965 goto exit;
966 }
967 if (!_Py_Gid_Converter(args[2], &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300968 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300969 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300970 return_value = os_fchown_impl(module, fd, uid, gid);
971
972exit:
973 return return_value;
974}
975
976#endif /* defined(HAVE_FCHOWN) */
977
978#if defined(HAVE_LCHOWN)
979
980PyDoc_STRVAR(os_lchown__doc__,
981"lchown($module, /, path, uid, gid)\n"
982"--\n"
983"\n"
984"Change the owner and group id of path to the numeric uid and gid.\n"
985"\n"
986"This function will not follow symbolic links.\n"
987"Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
988
989#define OS_LCHOWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200990 {"lchown", (PyCFunction)(void(*)(void))os_lchown, METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300991
992static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300993os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300994
995static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200996os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300997{
998 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300999 static const char * const _keywords[] = {"path", "uid", "gid", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001000 static _PyArg_Parser _parser = {NULL, _keywords, "lchown", 0};
1001 PyObject *argsbuf[3];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001002 path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
1003 uid_t uid;
1004 gid_t gid;
1005
Serhiy Storchaka31913912019-03-14 10:32:22 +02001006 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
1007 if (!args) {
1008 goto exit;
1009 }
1010 if (!path_converter(args[0], &path)) {
1011 goto exit;
1012 }
1013 if (!_Py_Uid_Converter(args[1], &uid)) {
1014 goto exit;
1015 }
1016 if (!_Py_Gid_Converter(args[2], &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001017 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001018 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001019 return_value = os_lchown_impl(module, &path, uid, gid);
1020
1021exit:
1022 /* Cleanup for path */
1023 path_cleanup(&path);
1024
1025 return return_value;
1026}
1027
1028#endif /* defined(HAVE_LCHOWN) */
1029
1030PyDoc_STRVAR(os_getcwd__doc__,
1031"getcwd($module, /)\n"
1032"--\n"
1033"\n"
1034"Return a unicode string representing the current working directory.");
1035
1036#define OS_GETCWD_METHODDEF \
1037 {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1038
1039static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001040os_getcwd_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001041
1042static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001043os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001044{
1045 return os_getcwd_impl(module);
1046}
1047
1048PyDoc_STRVAR(os_getcwdb__doc__,
1049"getcwdb($module, /)\n"
1050"--\n"
1051"\n"
1052"Return a bytes string representing the current working directory.");
1053
1054#define OS_GETCWDB_METHODDEF \
1055 {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1056
1057static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001058os_getcwdb_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001059
1060static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001061os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001062{
1063 return os_getcwdb_impl(module);
1064}
1065
1066#if defined(HAVE_LINK)
1067
1068PyDoc_STRVAR(os_link__doc__,
1069"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1070" follow_symlinks=True)\n"
1071"--\n"
1072"\n"
1073"Create a hard link to a file.\n"
1074"\n"
1075"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1076" descriptor open to a directory, and the respective path string (src or dst)\n"
1077" should be relative; the path will then be relative to that directory.\n"
1078"If follow_symlinks is False, and the last element of src is a symbolic\n"
1079" link, link will create a link to the symbolic link itself instead of the\n"
1080" file the link points to.\n"
1081"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
1082" platform. If they are unavailable, using them will raise a\n"
1083" NotImplementedError.");
1084
1085#define OS_LINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001086 {"link", (PyCFunction)(void(*)(void))os_link, METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001087
1088static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001089os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001090 int dst_dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001091
1092static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001093os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001094{
1095 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001096 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001097 static _PyArg_Parser _parser = {NULL, _keywords, "link", 0};
1098 PyObject *argsbuf[5];
1099 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001100 path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
1101 path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
1102 int src_dir_fd = DEFAULT_DIR_FD;
1103 int dst_dir_fd = DEFAULT_DIR_FD;
1104 int follow_symlinks = 1;
1105
Serhiy Storchaka31913912019-03-14 10:32:22 +02001106 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1107 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001109 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001110 if (!path_converter(args[0], &src)) {
1111 goto exit;
1112 }
1113 if (!path_converter(args[1], &dst)) {
1114 goto exit;
1115 }
1116 if (!noptargs) {
1117 goto skip_optional_kwonly;
1118 }
1119 if (args[2]) {
1120 if (!dir_fd_converter(args[2], &src_dir_fd)) {
1121 goto exit;
1122 }
1123 if (!--noptargs) {
1124 goto skip_optional_kwonly;
1125 }
1126 }
1127 if (args[3]) {
1128 if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1129 goto exit;
1130 }
1131 if (!--noptargs) {
1132 goto skip_optional_kwonly;
1133 }
1134 }
1135 follow_symlinks = PyObject_IsTrue(args[4]);
1136 if (follow_symlinks < 0) {
1137 goto exit;
1138 }
1139skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001140 return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1141
1142exit:
1143 /* Cleanup for src */
1144 path_cleanup(&src);
1145 /* Cleanup for dst */
1146 path_cleanup(&dst);
1147
1148 return return_value;
1149}
1150
1151#endif /* defined(HAVE_LINK) */
1152
1153PyDoc_STRVAR(os_listdir__doc__,
1154"listdir($module, /, path=None)\n"
1155"--\n"
1156"\n"
1157"Return a list containing the names of the files in the directory.\n"
1158"\n"
BNMetricsb9427072018-11-02 15:20:19 +00001159"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 +03001160" the filenames returned will also be bytes; in all other circumstances\n"
1161" the filenames returned will be str.\n"
1162"If path is None, uses the path=\'.\'.\n"
1163"On some platforms, path may also be specified as an open file descriptor;\\\n"
1164" the file descriptor must refer to a directory.\n"
1165" If this functionality is unavailable, using it raises NotImplementedError.\n"
1166"\n"
1167"The list is in arbitrary order. It does not include the special\n"
1168"entries \'.\' and \'..\' even if they are present in the directory.");
1169
1170#define OS_LISTDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001171 {"listdir", (PyCFunction)(void(*)(void))os_listdir, METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001172
1173static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001174os_listdir_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001175
1176static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001177os_listdir(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[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001181 static _PyArg_Parser _parser = {NULL, _keywords, "listdir", 0};
1182 PyObject *argsbuf[1];
1183 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001184 path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
1185
Serhiy Storchaka31913912019-03-14 10:32:22 +02001186 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1187 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001188 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001189 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001190 if (!noptargs) {
1191 goto skip_optional_pos;
1192 }
1193 if (!path_converter(args[0], &path)) {
1194 goto exit;
1195 }
1196skip_optional_pos:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001197 return_value = os_listdir_impl(module, &path);
1198
1199exit:
1200 /* Cleanup for path */
1201 path_cleanup(&path);
1202
1203 return return_value;
1204}
1205
1206#if defined(MS_WINDOWS)
1207
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001208PyDoc_STRVAR(os__getfullpathname__doc__,
1209"_getfullpathname($module, path, /)\n"
1210"--\n"
1211"\n");
1212
1213#define OS__GETFULLPATHNAME_METHODDEF \
1214 {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
1215
1216static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001217os__getfullpathname_impl(PyObject *module, path_t *path);
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001218
1219static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001220os__getfullpathname(PyObject *module, PyObject *arg)
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001221{
1222 PyObject *return_value = NULL;
1223 path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
1224
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001225 if (!path_converter(arg, &path)) {
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001226 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001227 }
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001228 return_value = os__getfullpathname_impl(module, &path);
1229
1230exit:
1231 /* Cleanup for path */
1232 path_cleanup(&path);
1233
1234 return return_value;
1235}
1236
1237#endif /* defined(MS_WINDOWS) */
1238
1239#if defined(MS_WINDOWS)
1240
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001241PyDoc_STRVAR(os__getfinalpathname__doc__,
1242"_getfinalpathname($module, path, /)\n"
1243"--\n"
1244"\n"
1245"A helper function for samepath on windows.");
1246
1247#define OS__GETFINALPATHNAME_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001248 {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001249
1250static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001251os__getfinalpathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001252
1253static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001254os__getfinalpathname(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001255{
1256 PyObject *return_value = NULL;
Steve Dower23ad6d02018-02-22 10:39:10 -08001257 path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001258
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001259 if (!path_converter(arg, &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001260 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001261 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001262 return_value = os__getfinalpathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001263
1264exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001265 /* Cleanup for path */
1266 path_cleanup(&path);
1267
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001268 return return_value;
1269}
1270
1271#endif /* defined(MS_WINDOWS) */
1272
1273#if defined(MS_WINDOWS)
1274
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001275PyDoc_STRVAR(os__isdir__doc__,
1276"_isdir($module, path, /)\n"
1277"--\n"
Serhiy Storchaka579f0382016-11-08 20:21:22 +02001278"\n"
1279"Return true if the pathname refers to an existing directory.");
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001280
1281#define OS__ISDIR_METHODDEF \
1282 {"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
1283
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03001284#endif /* defined(MS_WINDOWS) */
1285
1286#if defined(MS_WINDOWS)
1287
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001288PyDoc_STRVAR(os__getvolumepathname__doc__,
1289"_getvolumepathname($module, /, path)\n"
1290"--\n"
1291"\n"
1292"A helper function for ismount on Win32.");
1293
1294#define OS__GETVOLUMEPATHNAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001295 {"_getvolumepathname", (PyCFunction)(void(*)(void))os__getvolumepathname, METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001296
1297static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08001298os__getvolumepathname_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001299
1300static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001301os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001302{
1303 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001304 static const char * const _keywords[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001305 static _PyArg_Parser _parser = {NULL, _keywords, "_getvolumepathname", 0};
1306 PyObject *argsbuf[1];
Steve Dower23ad6d02018-02-22 10:39:10 -08001307 path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001308
Serhiy Storchaka31913912019-03-14 10:32:22 +02001309 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1310 if (!args) {
1311 goto exit;
1312 }
1313 if (!path_converter(args[0], &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001314 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001315 }
Steve Dower23ad6d02018-02-22 10:39:10 -08001316 return_value = os__getvolumepathname_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001317
1318exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08001319 /* Cleanup for path */
1320 path_cleanup(&path);
1321
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001322 return return_value;
1323}
1324
1325#endif /* defined(MS_WINDOWS) */
1326
1327PyDoc_STRVAR(os_mkdir__doc__,
1328"mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
1329"--\n"
1330"\n"
1331"Create a directory.\n"
1332"\n"
1333"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1334" and path should be relative; path will then be relative to that directory.\n"
1335"dir_fd may not be implemented on your platform.\n"
1336" If it is unavailable, using it will raise a NotImplementedError.\n"
1337"\n"
1338"The mode argument is ignored on Windows.");
1339
1340#define OS_MKDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001341 {"mkdir", (PyCFunction)(void(*)(void))os_mkdir, METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001342
1343static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001344os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001345
1346static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001347os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001348{
1349 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001350 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001351 static _PyArg_Parser _parser = {NULL, _keywords, "mkdir", 0};
1352 PyObject *argsbuf[3];
1353 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001354 path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
1355 int mode = 511;
1356 int dir_fd = DEFAULT_DIR_FD;
1357
Serhiy Storchaka31913912019-03-14 10:32:22 +02001358 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
1359 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001360 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001361 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001362 if (!path_converter(args[0], &path)) {
1363 goto exit;
1364 }
1365 if (!noptargs) {
1366 goto skip_optional_pos;
1367 }
1368 if (args[1]) {
1369 if (PyFloat_Check(args[1])) {
1370 PyErr_SetString(PyExc_TypeError,
1371 "integer argument expected, got float" );
1372 goto exit;
1373 }
1374 mode = _PyLong_AsInt(args[1]);
1375 if (mode == -1 && PyErr_Occurred()) {
1376 goto exit;
1377 }
1378 if (!--noptargs) {
1379 goto skip_optional_pos;
1380 }
1381 }
1382skip_optional_pos:
1383 if (!noptargs) {
1384 goto skip_optional_kwonly;
1385 }
1386 if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
1387 goto exit;
1388 }
1389skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001390 return_value = os_mkdir_impl(module, &path, mode, dir_fd);
1391
1392exit:
1393 /* Cleanup for path */
1394 path_cleanup(&path);
1395
1396 return return_value;
1397}
1398
1399#if defined(HAVE_NICE)
1400
1401PyDoc_STRVAR(os_nice__doc__,
1402"nice($module, increment, /)\n"
1403"--\n"
1404"\n"
1405"Add increment to the priority of process and return the new priority.");
1406
1407#define OS_NICE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001408 {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001409
1410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001411os_nice_impl(PyObject *module, int increment);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001412
1413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001414os_nice(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001415{
1416 PyObject *return_value = NULL;
1417 int increment;
1418
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001419 if (PyFloat_Check(arg)) {
1420 PyErr_SetString(PyExc_TypeError,
1421 "integer argument expected, got float" );
1422 goto exit;
1423 }
1424 increment = _PyLong_AsInt(arg);
1425 if (increment == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001426 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001427 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001428 return_value = os_nice_impl(module, increment);
1429
1430exit:
1431 return return_value;
1432}
1433
1434#endif /* defined(HAVE_NICE) */
1435
1436#if defined(HAVE_GETPRIORITY)
1437
1438PyDoc_STRVAR(os_getpriority__doc__,
1439"getpriority($module, /, which, who)\n"
1440"--\n"
1441"\n"
1442"Return program scheduling priority.");
1443
1444#define OS_GETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001445 {"getpriority", (PyCFunction)(void(*)(void))os_getpriority, METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001446
1447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001448os_getpriority_impl(PyObject *module, int which, int who);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001449
1450static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001451os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001452{
1453 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001454 static const char * const _keywords[] = {"which", "who", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001455 static _PyArg_Parser _parser = {NULL, _keywords, "getpriority", 0};
1456 PyObject *argsbuf[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001457 int which;
1458 int who;
1459
Serhiy Storchaka31913912019-03-14 10:32:22 +02001460 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1461 if (!args) {
1462 goto exit;
1463 }
1464 if (PyFloat_Check(args[0])) {
1465 PyErr_SetString(PyExc_TypeError,
1466 "integer argument expected, got float" );
1467 goto exit;
1468 }
1469 which = _PyLong_AsInt(args[0]);
1470 if (which == -1 && PyErr_Occurred()) {
1471 goto exit;
1472 }
1473 if (PyFloat_Check(args[1])) {
1474 PyErr_SetString(PyExc_TypeError,
1475 "integer argument expected, got float" );
1476 goto exit;
1477 }
1478 who = _PyLong_AsInt(args[1]);
1479 if (who == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001480 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001481 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001482 return_value = os_getpriority_impl(module, which, who);
1483
1484exit:
1485 return return_value;
1486}
1487
1488#endif /* defined(HAVE_GETPRIORITY) */
1489
1490#if defined(HAVE_SETPRIORITY)
1491
1492PyDoc_STRVAR(os_setpriority__doc__,
1493"setpriority($module, /, which, who, priority)\n"
1494"--\n"
1495"\n"
1496"Set program scheduling priority.");
1497
1498#define OS_SETPRIORITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001499 {"setpriority", (PyCFunction)(void(*)(void))os_setpriority, METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001500
1501static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001502os_setpriority_impl(PyObject *module, int which, int who, int priority);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001503
1504static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001505os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001506{
1507 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001508 static const char * const _keywords[] = {"which", "who", "priority", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001509 static _PyArg_Parser _parser = {NULL, _keywords, "setpriority", 0};
1510 PyObject *argsbuf[3];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001511 int which;
1512 int who;
1513 int priority;
1514
Serhiy Storchaka31913912019-03-14 10:32:22 +02001515 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
1516 if (!args) {
1517 goto exit;
1518 }
1519 if (PyFloat_Check(args[0])) {
1520 PyErr_SetString(PyExc_TypeError,
1521 "integer argument expected, got float" );
1522 goto exit;
1523 }
1524 which = _PyLong_AsInt(args[0]);
1525 if (which == -1 && PyErr_Occurred()) {
1526 goto exit;
1527 }
1528 if (PyFloat_Check(args[1])) {
1529 PyErr_SetString(PyExc_TypeError,
1530 "integer argument expected, got float" );
1531 goto exit;
1532 }
1533 who = _PyLong_AsInt(args[1]);
1534 if (who == -1 && PyErr_Occurred()) {
1535 goto exit;
1536 }
1537 if (PyFloat_Check(args[2])) {
1538 PyErr_SetString(PyExc_TypeError,
1539 "integer argument expected, got float" );
1540 goto exit;
1541 }
1542 priority = _PyLong_AsInt(args[2]);
1543 if (priority == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001544 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001545 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001546 return_value = os_setpriority_impl(module, which, who, priority);
1547
1548exit:
1549 return return_value;
1550}
1551
1552#endif /* defined(HAVE_SETPRIORITY) */
1553
1554PyDoc_STRVAR(os_rename__doc__,
1555"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1556"--\n"
1557"\n"
1558"Rename a file or directory.\n"
1559"\n"
1560"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1561" descriptor open to a directory, and the respective path string (src or dst)\n"
1562" should be relative; the path will then be relative to that directory.\n"
1563"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
1564" If they are unavailable, using them will raise a NotImplementedError.");
1565
1566#define OS_RENAME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001567 {"rename", (PyCFunction)(void(*)(void))os_rename, METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001568
1569static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001570os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
Larry Hastings89964c42015-04-14 18:07:59 -04001571 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001572
1573static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001574os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001575{
1576 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001577 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001578 static _PyArg_Parser _parser = {NULL, _keywords, "rename", 0};
1579 PyObject *argsbuf[4];
1580 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001581 path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
1582 path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
1583 int src_dir_fd = DEFAULT_DIR_FD;
1584 int dst_dir_fd = DEFAULT_DIR_FD;
1585
Serhiy Storchaka31913912019-03-14 10:32:22 +02001586 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1587 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001588 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001589 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001590 if (!path_converter(args[0], &src)) {
1591 goto exit;
1592 }
1593 if (!path_converter(args[1], &dst)) {
1594 goto exit;
1595 }
1596 if (!noptargs) {
1597 goto skip_optional_kwonly;
1598 }
1599 if (args[2]) {
1600 if (!dir_fd_converter(args[2], &src_dir_fd)) {
1601 goto exit;
1602 }
1603 if (!--noptargs) {
1604 goto skip_optional_kwonly;
1605 }
1606 }
1607 if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1608 goto exit;
1609 }
1610skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001611 return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1612
1613exit:
1614 /* Cleanup for src */
1615 path_cleanup(&src);
1616 /* Cleanup for dst */
1617 path_cleanup(&dst);
1618
1619 return return_value;
1620}
1621
1622PyDoc_STRVAR(os_replace__doc__,
1623"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
1624"--\n"
1625"\n"
1626"Rename a file or directory, overwriting the destination.\n"
1627"\n"
1628"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1629" descriptor open to a directory, and the respective path string (src or dst)\n"
1630" should be relative; the path will then be relative to that directory.\n"
1631"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
Anthony Sottile73d60022019-02-12 23:15:54 -05001632" If they are unavailable, using them will raise a NotImplementedError.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001633
1634#define OS_REPLACE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001635 {"replace", (PyCFunction)(void(*)(void))os_replace, METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001636
1637static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001638os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1639 int dst_dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001640
1641static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001642os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001643{
1644 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001645 static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001646 static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0};
1647 PyObject *argsbuf[4];
1648 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001649 path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
1650 path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
1651 int src_dir_fd = DEFAULT_DIR_FD;
1652 int dst_dir_fd = DEFAULT_DIR_FD;
1653
Serhiy Storchaka31913912019-03-14 10:32:22 +02001654 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1655 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001656 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001657 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001658 if (!path_converter(args[0], &src)) {
1659 goto exit;
1660 }
1661 if (!path_converter(args[1], &dst)) {
1662 goto exit;
1663 }
1664 if (!noptargs) {
1665 goto skip_optional_kwonly;
1666 }
1667 if (args[2]) {
1668 if (!dir_fd_converter(args[2], &src_dir_fd)) {
1669 goto exit;
1670 }
1671 if (!--noptargs) {
1672 goto skip_optional_kwonly;
1673 }
1674 }
1675 if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1676 goto exit;
1677 }
1678skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001679 return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
1680
1681exit:
1682 /* Cleanup for src */
1683 path_cleanup(&src);
1684 /* Cleanup for dst */
1685 path_cleanup(&dst);
1686
1687 return return_value;
1688}
1689
1690PyDoc_STRVAR(os_rmdir__doc__,
1691"rmdir($module, /, path, *, dir_fd=None)\n"
1692"--\n"
1693"\n"
1694"Remove a directory.\n"
1695"\n"
1696"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1697" and path should be relative; path will then be relative to that directory.\n"
1698"dir_fd may not be implemented on your platform.\n"
1699" If it is unavailable, using it will raise a NotImplementedError.");
1700
1701#define OS_RMDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001702 {"rmdir", (PyCFunction)(void(*)(void))os_rmdir, METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001703
1704static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001705os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001706
1707static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001708os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001709{
1710 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001711 static const char * const _keywords[] = {"path", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001712 static _PyArg_Parser _parser = {NULL, _keywords, "rmdir", 0};
1713 PyObject *argsbuf[2];
1714 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001715 path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
1716 int dir_fd = DEFAULT_DIR_FD;
1717
Serhiy Storchaka31913912019-03-14 10:32:22 +02001718 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1719 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001720 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001721 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001722 if (!path_converter(args[0], &path)) {
1723 goto exit;
1724 }
1725 if (!noptargs) {
1726 goto skip_optional_kwonly;
1727 }
1728 if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
1729 goto exit;
1730 }
1731skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001732 return_value = os_rmdir_impl(module, &path, dir_fd);
1733
1734exit:
1735 /* Cleanup for path */
1736 path_cleanup(&path);
1737
1738 return return_value;
1739}
1740
1741#if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
1742
1743PyDoc_STRVAR(os_system__doc__,
1744"system($module, /, command)\n"
1745"--\n"
1746"\n"
1747"Execute the command in a subshell.");
1748
1749#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001750 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001751
1752static long
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001753os_system_impl(PyObject *module, const Py_UNICODE *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001754
1755static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001756os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001757{
1758 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001759 static const char * const _keywords[] = {"command", NULL};
1760 static _PyArg_Parser _parser = {"u:system", _keywords, 0};
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001761 const Py_UNICODE *command;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001762 long _return_value;
1763
Victor Stinner3e1fad62017-01-17 01:29:01 +01001764 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001765 &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001766 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001767 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001768 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001769 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001770 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001771 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001772 return_value = PyLong_FromLong(_return_value);
1773
1774exit:
1775 return return_value;
1776}
1777
1778#endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
1779
1780#if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
1781
1782PyDoc_STRVAR(os_system__doc__,
1783"system($module, /, command)\n"
1784"--\n"
1785"\n"
1786"Execute the command in a subshell.");
1787
1788#define OS_SYSTEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001789 {"system", (PyCFunction)(void(*)(void))os_system, METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001790
1791static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001792os_system_impl(PyObject *module, PyObject *command);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001793
1794static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001795os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001796{
1797 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001798 static const char * const _keywords[] = {"command", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001799 static _PyArg_Parser _parser = {NULL, _keywords, "system", 0};
1800 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001801 PyObject *command = NULL;
1802 long _return_value;
1803
Serhiy Storchaka31913912019-03-14 10:32:22 +02001804 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1805 if (!args) {
1806 goto exit;
1807 }
1808 if (!PyUnicode_FSConverter(args[0], &command)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001809 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001810 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001811 _return_value = os_system_impl(module, command);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001812 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001813 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001814 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001815 return_value = PyLong_FromLong(_return_value);
1816
1817exit:
1818 /* Cleanup for command */
1819 Py_XDECREF(command);
1820
1821 return return_value;
1822}
1823
1824#endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
1825
1826PyDoc_STRVAR(os_umask__doc__,
1827"umask($module, mask, /)\n"
1828"--\n"
1829"\n"
1830"Set the current numeric umask and return the previous umask.");
1831
1832#define OS_UMASK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03001833 {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001834
1835static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001836os_umask_impl(PyObject *module, int mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001837
1838static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001839os_umask(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001840{
1841 PyObject *return_value = NULL;
1842 int mask;
1843
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001844 if (PyFloat_Check(arg)) {
1845 PyErr_SetString(PyExc_TypeError,
1846 "integer argument expected, got float" );
1847 goto exit;
1848 }
1849 mask = _PyLong_AsInt(arg);
1850 if (mask == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001851 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001852 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001853 return_value = os_umask_impl(module, mask);
1854
1855exit:
1856 return return_value;
1857}
1858
1859PyDoc_STRVAR(os_unlink__doc__,
1860"unlink($module, /, path, *, dir_fd=None)\n"
1861"--\n"
1862"\n"
1863"Remove a file (same as remove()).\n"
1864"\n"
1865"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1866" and path should be relative; path will then be relative to that directory.\n"
1867"dir_fd may not be implemented on your platform.\n"
1868" If it is unavailable, using it will raise a NotImplementedError.");
1869
1870#define OS_UNLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001871 {"unlink", (PyCFunction)(void(*)(void))os_unlink, METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001872
1873static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001874os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001875
1876static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001877os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001878{
1879 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001880 static const char * const _keywords[] = {"path", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001881 static _PyArg_Parser _parser = {NULL, _keywords, "unlink", 0};
1882 PyObject *argsbuf[2];
1883 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001884 path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
1885 int dir_fd = DEFAULT_DIR_FD;
1886
Serhiy Storchaka31913912019-03-14 10:32:22 +02001887 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1888 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001889 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001890 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001891 if (!path_converter(args[0], &path)) {
1892 goto exit;
1893 }
1894 if (!noptargs) {
1895 goto skip_optional_kwonly;
1896 }
1897 if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
1898 goto exit;
1899 }
1900skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001901 return_value = os_unlink_impl(module, &path, dir_fd);
1902
1903exit:
1904 /* Cleanup for path */
1905 path_cleanup(&path);
1906
1907 return return_value;
1908}
1909
1910PyDoc_STRVAR(os_remove__doc__,
1911"remove($module, /, path, *, dir_fd=None)\n"
1912"--\n"
1913"\n"
1914"Remove a file (same as unlink()).\n"
1915"\n"
1916"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1917" and path should be relative; path will then be relative to that directory.\n"
1918"dir_fd may not be implemented on your platform.\n"
1919" If it is unavailable, using it will raise a NotImplementedError.");
1920
1921#define OS_REMOVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001922 {"remove", (PyCFunction)(void(*)(void))os_remove, METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001923
1924static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001925os_remove_impl(PyObject *module, path_t *path, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001926
1927static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001928os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001929{
1930 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001931 static const char * const _keywords[] = {"path", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001932 static _PyArg_Parser _parser = {NULL, _keywords, "remove", 0};
1933 PyObject *argsbuf[2];
1934 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001935 path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
1936 int dir_fd = DEFAULT_DIR_FD;
1937
Serhiy Storchaka31913912019-03-14 10:32:22 +02001938 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1939 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001940 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001941 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001942 if (!path_converter(args[0], &path)) {
1943 goto exit;
1944 }
1945 if (!noptargs) {
1946 goto skip_optional_kwonly;
1947 }
1948 if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
1949 goto exit;
1950 }
1951skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001952 return_value = os_remove_impl(module, &path, dir_fd);
1953
1954exit:
1955 /* Cleanup for path */
1956 path_cleanup(&path);
1957
1958 return return_value;
1959}
1960
1961#if defined(HAVE_UNAME)
1962
1963PyDoc_STRVAR(os_uname__doc__,
1964"uname($module, /)\n"
1965"--\n"
1966"\n"
1967"Return an object identifying the current operating system.\n"
1968"\n"
1969"The object behaves like a named tuple with the following fields:\n"
1970" (sysname, nodename, release, version, machine)");
1971
1972#define OS_UNAME_METHODDEF \
1973 {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
1974
1975static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001976os_uname_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001977
1978static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001979os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001980{
1981 return os_uname_impl(module);
1982}
1983
1984#endif /* defined(HAVE_UNAME) */
1985
1986PyDoc_STRVAR(os_utime__doc__,
1987"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n"
1988" follow_symlinks=True)\n"
1989"--\n"
1990"\n"
1991"Set the access and modified time of path.\n"
1992"\n"
1993"path may always be specified as a string.\n"
1994"On some platforms, path may also be specified as an open file descriptor.\n"
1995" If this functionality is unavailable, using it raises an exception.\n"
1996"\n"
1997"If times is not None, it must be a tuple (atime, mtime);\n"
1998" atime and mtime should be expressed as float seconds since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00001999"If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002000" atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
2001" since the epoch.\n"
Martin Panter0ff89092015-09-09 01:56:53 +00002002"If times is None and ns is unspecified, utime uses the current time.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002003"Specifying tuples for both times and ns is an error.\n"
2004"\n"
2005"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2006" and path should be relative; path will then be relative to that directory.\n"
2007"If follow_symlinks is False, and the last element of the path is a symbolic\n"
2008" link, utime will modify the symbolic link itself instead of the file the\n"
2009" link points to.\n"
2010"It is an error to use dir_fd or follow_symlinks when specifying path\n"
2011" as an open file descriptor.\n"
2012"dir_fd and follow_symlinks may not be available on your platform.\n"
2013" If they are unavailable, using them will raise a NotImplementedError.");
2014
2015#define OS_UTIME_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002016 {"utime", (PyCFunction)(void(*)(void))os_utime, METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002017
2018static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002019os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
2020 int dir_fd, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002021
2022static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002023os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002024{
2025 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002026 static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002027 static _PyArg_Parser _parser = {NULL, _keywords, "utime", 0};
2028 PyObject *argsbuf[5];
2029 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002030 path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
2031 PyObject *times = NULL;
2032 PyObject *ns = NULL;
2033 int dir_fd = DEFAULT_DIR_FD;
2034 int follow_symlinks = 1;
2035
Serhiy Storchaka31913912019-03-14 10:32:22 +02002036 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
2037 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002038 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002039 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02002040 if (!path_converter(args[0], &path)) {
2041 goto exit;
2042 }
2043 if (!noptargs) {
2044 goto skip_optional_pos;
2045 }
2046 if (args[1]) {
2047 times = args[1];
2048 if (!--noptargs) {
2049 goto skip_optional_pos;
2050 }
2051 }
2052skip_optional_pos:
2053 if (!noptargs) {
2054 goto skip_optional_kwonly;
2055 }
2056 if (args[2]) {
2057 ns = args[2];
2058 if (!--noptargs) {
2059 goto skip_optional_kwonly;
2060 }
2061 }
2062 if (args[3]) {
2063 if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
2064 goto exit;
2065 }
2066 if (!--noptargs) {
2067 goto skip_optional_kwonly;
2068 }
2069 }
2070 follow_symlinks = PyObject_IsTrue(args[4]);
2071 if (follow_symlinks < 0) {
2072 goto exit;
2073 }
2074skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002075 return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
2076
2077exit:
2078 /* Cleanup for path */
2079 path_cleanup(&path);
2080
2081 return return_value;
2082}
2083
2084PyDoc_STRVAR(os__exit__doc__,
2085"_exit($module, /, status)\n"
2086"--\n"
2087"\n"
2088"Exit to the system with specified status, without normal exit processing.");
2089
2090#define OS__EXIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002091 {"_exit", (PyCFunction)(void(*)(void))os__exit, METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002092
2093static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002094os__exit_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002095
2096static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002097os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002098{
2099 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002100 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002101 static _PyArg_Parser _parser = {NULL, _keywords, "_exit", 0};
2102 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002103 int status;
2104
Serhiy Storchaka31913912019-03-14 10:32:22 +02002105 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2106 if (!args) {
2107 goto exit;
2108 }
2109 if (PyFloat_Check(args[0])) {
2110 PyErr_SetString(PyExc_TypeError,
2111 "integer argument expected, got float" );
2112 goto exit;
2113 }
2114 status = _PyLong_AsInt(args[0]);
2115 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002116 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002118 return_value = os__exit_impl(module, status);
2119
2120exit:
2121 return return_value;
2122}
2123
2124#if defined(HAVE_EXECV)
2125
2126PyDoc_STRVAR(os_execv__doc__,
2127"execv($module, path, argv, /)\n"
2128"--\n"
2129"\n"
2130"Execute an executable path with arguments, replacing current process.\n"
2131"\n"
2132" path\n"
2133" Path of executable file.\n"
2134" argv\n"
2135" Tuple or list of strings.");
2136
2137#define OS_EXECV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002138 {"execv", (PyCFunction)(void(*)(void))os_execv, METH_FASTCALL, os_execv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002139
2140static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07002141os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002142
2143static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002144os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002145{
2146 PyObject *return_value = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07002147 path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002148 PyObject *argv;
2149
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002150 if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002151 goto exit;
2152 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002153 if (!path_converter(args[0], &path)) {
2154 goto exit;
2155 }
2156 argv = args[1];
Steve Dowercc16be82016-09-08 10:35:16 -07002157 return_value = os_execv_impl(module, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002158
2159exit:
2160 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07002161 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002162
2163 return return_value;
2164}
2165
2166#endif /* defined(HAVE_EXECV) */
2167
2168#if defined(HAVE_EXECV)
2169
2170PyDoc_STRVAR(os_execve__doc__,
2171"execve($module, /, path, argv, env)\n"
2172"--\n"
2173"\n"
2174"Execute an executable path with arguments, replacing current process.\n"
2175"\n"
2176" path\n"
2177" Path of executable file.\n"
2178" argv\n"
2179" Tuple or list of strings.\n"
2180" env\n"
2181" Dictionary of strings mapping to strings.");
2182
2183#define OS_EXECVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002184 {"execve", (PyCFunction)(void(*)(void))os_execve, METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002185
2186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002187os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002188
2189static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002190os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002191{
2192 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002193 static const char * const _keywords[] = {"path", "argv", "env", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002194 static _PyArg_Parser _parser = {NULL, _keywords, "execve", 0};
2195 PyObject *argsbuf[3];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002196 path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
2197 PyObject *argv;
2198 PyObject *env;
2199
Serhiy Storchaka31913912019-03-14 10:32:22 +02002200 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
2201 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002202 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002203 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02002204 if (!path_converter(args[0], &path)) {
2205 goto exit;
2206 }
2207 argv = args[1];
2208 env = args[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002209 return_value = os_execve_impl(module, &path, argv, env);
2210
2211exit:
2212 /* Cleanup for path */
2213 path_cleanup(&path);
2214
2215 return return_value;
2216}
2217
2218#endif /* defined(HAVE_EXECV) */
2219
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002220#if defined(HAVE_POSIX_SPAWN)
2221
2222PyDoc_STRVAR(os_posix_spawn__doc__,
Serhiy Storchakad700f972018-09-08 14:48:18 +03002223"posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002224" setpgroup=None, resetids=False, setsid=False,\n"
2225" setsigmask=(), setsigdef=(), scheduler=None)\n"
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002226"--\n"
2227"\n"
2228"Execute the program specified by path in a new process.\n"
2229"\n"
2230" path\n"
2231" Path of executable file.\n"
2232" argv\n"
2233" Tuple or list of strings.\n"
2234" env\n"
2235" Dictionary of strings mapping to strings.\n"
2236" file_actions\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01002237" A sequence of file action tuples.\n"
2238" setpgroup\n"
2239" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
2240" resetids\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002241" If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
2242" setsid\n"
2243" If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
Pablo Galindo254a4662018-09-07 16:44:24 +01002244" setsigmask\n"
2245" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
2246" setsigdef\n"
2247" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
2248" scheduler\n"
2249" A tuple with the scheduler policy (optional) and parameters.");
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002250
2251#define OS_POSIX_SPAWN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002252 {"posix_spawn", (PyCFunction)(void(*)(void))os_posix_spawn, METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002253
2254static PyObject *
2255os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
Pablo Galindo254a4662018-09-07 16:44:24 +01002256 PyObject *env, PyObject *file_actions,
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002257 PyObject *setpgroup, int resetids, int setsid,
2258 PyObject *setsigmask, PyObject *setsigdef,
2259 PyObject *scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002260
2261static PyObject *
Pablo Galindo254a4662018-09-07 16:44:24 +01002262os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002263{
2264 PyObject *return_value = NULL;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002265 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002266 static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawn", 0};
2267 PyObject *argsbuf[10];
2268 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002269 path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
2270 PyObject *argv;
2271 PyObject *env;
Serhiy Storchakad700f972018-09-08 14:48:18 +03002272 PyObject *file_actions = NULL;
Pablo Galindo254a4662018-09-07 16:44:24 +01002273 PyObject *setpgroup = NULL;
2274 int resetids = 0;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002275 int setsid = 0;
Pablo Galindo254a4662018-09-07 16:44:24 +01002276 PyObject *setsigmask = NULL;
2277 PyObject *setsigdef = NULL;
2278 PyObject *scheduler = NULL;
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002279
Serhiy Storchaka31913912019-03-14 10:32:22 +02002280 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
2281 if (!args) {
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002282 goto exit;
2283 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02002284 if (!path_converter(args[0], &path)) {
2285 goto exit;
2286 }
2287 argv = args[1];
2288 env = args[2];
2289 if (!noptargs) {
2290 goto skip_optional_kwonly;
2291 }
2292 if (args[3]) {
2293 file_actions = args[3];
2294 if (!--noptargs) {
2295 goto skip_optional_kwonly;
2296 }
2297 }
2298 if (args[4]) {
2299 setpgroup = args[4];
2300 if (!--noptargs) {
2301 goto skip_optional_kwonly;
2302 }
2303 }
2304 if (args[5]) {
2305 if (PyFloat_Check(args[5])) {
2306 PyErr_SetString(PyExc_TypeError,
2307 "integer argument expected, got float" );
2308 goto exit;
2309 }
2310 resetids = _PyLong_AsInt(args[5]);
2311 if (resetids == -1 && PyErr_Occurred()) {
2312 goto exit;
2313 }
2314 if (!--noptargs) {
2315 goto skip_optional_kwonly;
2316 }
2317 }
2318 if (args[6]) {
2319 if (PyFloat_Check(args[6])) {
2320 PyErr_SetString(PyExc_TypeError,
2321 "integer argument expected, got float" );
2322 goto exit;
2323 }
2324 setsid = _PyLong_AsInt(args[6]);
2325 if (setsid == -1 && PyErr_Occurred()) {
2326 goto exit;
2327 }
2328 if (!--noptargs) {
2329 goto skip_optional_kwonly;
2330 }
2331 }
2332 if (args[7]) {
2333 setsigmask = args[7];
2334 if (!--noptargs) {
2335 goto skip_optional_kwonly;
2336 }
2337 }
2338 if (args[8]) {
2339 setsigdef = args[8];
2340 if (!--noptargs) {
2341 goto skip_optional_kwonly;
2342 }
2343 }
2344 scheduler = args[9];
2345skip_optional_kwonly:
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002346 return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00002347
2348exit:
2349 /* Cleanup for path */
2350 path_cleanup(&path);
2351
2352 return return_value;
2353}
2354
2355#endif /* defined(HAVE_POSIX_SPAWN) */
2356
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002357#if defined(HAVE_POSIX_SPAWNP)
2358
2359PyDoc_STRVAR(os_posix_spawnp__doc__,
2360"posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002361" setpgroup=None, resetids=False, setsid=False,\n"
2362" setsigmask=(), setsigdef=(), scheduler=None)\n"
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002363"--\n"
2364"\n"
2365"Execute the program specified by path in a new process.\n"
2366"\n"
2367" path\n"
2368" Path of executable file.\n"
2369" argv\n"
2370" Tuple or list of strings.\n"
2371" env\n"
2372" Dictionary of strings mapping to strings.\n"
2373" file_actions\n"
2374" A sequence of file action tuples.\n"
2375" setpgroup\n"
2376" The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
2377" resetids\n"
2378" If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002379" setsid\n"
2380" If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002381" setsigmask\n"
2382" The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
2383" setsigdef\n"
2384" The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
2385" scheduler\n"
2386" A tuple with the scheduler policy (optional) and parameters.");
2387
2388#define OS_POSIX_SPAWNP_METHODDEF \
2389 {"posix_spawnp", (PyCFunction)(void(*)(void))os_posix_spawnp, METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
2390
2391static PyObject *
2392os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
2393 PyObject *env, PyObject *file_actions,
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002394 PyObject *setpgroup, int resetids, int setsid,
2395 PyObject *setsigmask, PyObject *setsigdef,
2396 PyObject *scheduler);
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002397
2398static PyObject *
2399os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2400{
2401 PyObject *return_value = NULL;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002402 static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002403 static _PyArg_Parser _parser = {NULL, _keywords, "posix_spawnp", 0};
2404 PyObject *argsbuf[10];
2405 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002406 path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0);
2407 PyObject *argv;
2408 PyObject *env;
2409 PyObject *file_actions = NULL;
2410 PyObject *setpgroup = NULL;
2411 int resetids = 0;
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002412 int setsid = 0;
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002413 PyObject *setsigmask = NULL;
2414 PyObject *setsigdef = NULL;
2415 PyObject *scheduler = NULL;
2416
Serhiy Storchaka31913912019-03-14 10:32:22 +02002417 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
2418 if (!args) {
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002419 goto exit;
2420 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02002421 if (!path_converter(args[0], &path)) {
2422 goto exit;
2423 }
2424 argv = args[1];
2425 env = args[2];
2426 if (!noptargs) {
2427 goto skip_optional_kwonly;
2428 }
2429 if (args[3]) {
2430 file_actions = args[3];
2431 if (!--noptargs) {
2432 goto skip_optional_kwonly;
2433 }
2434 }
2435 if (args[4]) {
2436 setpgroup = args[4];
2437 if (!--noptargs) {
2438 goto skip_optional_kwonly;
2439 }
2440 }
2441 if (args[5]) {
2442 if (PyFloat_Check(args[5])) {
2443 PyErr_SetString(PyExc_TypeError,
2444 "integer argument expected, got float" );
2445 goto exit;
2446 }
2447 resetids = _PyLong_AsInt(args[5]);
2448 if (resetids == -1 && PyErr_Occurred()) {
2449 goto exit;
2450 }
2451 if (!--noptargs) {
2452 goto skip_optional_kwonly;
2453 }
2454 }
2455 if (args[6]) {
2456 if (PyFloat_Check(args[6])) {
2457 PyErr_SetString(PyExc_TypeError,
2458 "integer argument expected, got float" );
2459 goto exit;
2460 }
2461 setsid = _PyLong_AsInt(args[6]);
2462 if (setsid == -1 && PyErr_Occurred()) {
2463 goto exit;
2464 }
2465 if (!--noptargs) {
2466 goto skip_optional_kwonly;
2467 }
2468 }
2469 if (args[7]) {
2470 setsigmask = args[7];
2471 if (!--noptargs) {
2472 goto skip_optional_kwonly;
2473 }
2474 }
2475 if (args[8]) {
2476 setsigdef = args[8];
2477 if (!--noptargs) {
2478 goto skip_optional_kwonly;
2479 }
2480 }
2481 scheduler = args[9];
2482skip_optional_kwonly:
Joannah Nanjekye80c5dfe2019-02-01 13:05:22 +03002483 return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
Joannah Nanjekye92b83222019-01-16 16:29:26 +03002484
2485exit:
2486 /* Cleanup for path */
2487 path_cleanup(&path);
2488
2489 return return_value;
2490}
2491
2492#endif /* defined(HAVE_POSIX_SPAWNP) */
2493
Steve Dowercc16be82016-09-08 10:35:16 -07002494#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002495
2496PyDoc_STRVAR(os_spawnv__doc__,
2497"spawnv($module, mode, path, argv, /)\n"
2498"--\n"
2499"\n"
2500"Execute the program specified by path in a new process.\n"
2501"\n"
2502" mode\n"
2503" Mode of process creation.\n"
2504" path\n"
2505" Path of executable file.\n"
2506" argv\n"
2507" Tuple or list of strings.");
2508
2509#define OS_SPAWNV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002510 {"spawnv", (PyCFunction)(void(*)(void))os_spawnv, METH_FASTCALL, os_spawnv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002511
2512static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07002513os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002514
2515static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002516os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002517{
2518 PyObject *return_value = NULL;
2519 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07002520 path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002521 PyObject *argv;
2522
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002523 if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002524 goto exit;
2525 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002526 if (PyFloat_Check(args[0])) {
2527 PyErr_SetString(PyExc_TypeError,
2528 "integer argument expected, got float" );
2529 goto exit;
2530 }
2531 mode = _PyLong_AsInt(args[0]);
2532 if (mode == -1 && PyErr_Occurred()) {
2533 goto exit;
2534 }
2535 if (!path_converter(args[1], &path)) {
2536 goto exit;
2537 }
2538 argv = args[2];
Steve Dowercc16be82016-09-08 10:35:16 -07002539 return_value = os_spawnv_impl(module, mode, &path, argv);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002540
2541exit:
2542 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07002543 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002544
2545 return return_value;
2546}
2547
Steve Dowercc16be82016-09-08 10:35:16 -07002548#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002549
Steve Dowercc16be82016-09-08 10:35:16 -07002550#if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002551
2552PyDoc_STRVAR(os_spawnve__doc__,
2553"spawnve($module, mode, path, argv, env, /)\n"
2554"--\n"
2555"\n"
2556"Execute the program specified by path in a new process.\n"
2557"\n"
2558" mode\n"
2559" Mode of process creation.\n"
2560" path\n"
2561" Path of executable file.\n"
2562" argv\n"
2563" Tuple or list of strings.\n"
2564" env\n"
2565" Dictionary of strings mapping to strings.");
2566
2567#define OS_SPAWNVE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002568 {"spawnve", (PyCFunction)(void(*)(void))os_spawnve, METH_FASTCALL, os_spawnve__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002569
2570static PyObject *
Steve Dowercc16be82016-09-08 10:35:16 -07002571os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002572 PyObject *env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002573
2574static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002575os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002576{
2577 PyObject *return_value = NULL;
2578 int mode;
Steve Dowercc16be82016-09-08 10:35:16 -07002579 path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002580 PyObject *argv;
2581 PyObject *env;
2582
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002583 if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002584 goto exit;
2585 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002586 if (PyFloat_Check(args[0])) {
2587 PyErr_SetString(PyExc_TypeError,
2588 "integer argument expected, got float" );
2589 goto exit;
2590 }
2591 mode = _PyLong_AsInt(args[0]);
2592 if (mode == -1 && PyErr_Occurred()) {
2593 goto exit;
2594 }
2595 if (!path_converter(args[1], &path)) {
2596 goto exit;
2597 }
2598 argv = args[2];
2599 env = args[3];
Steve Dowercc16be82016-09-08 10:35:16 -07002600 return_value = os_spawnve_impl(module, mode, &path, argv, env);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002601
2602exit:
2603 /* Cleanup for path */
Steve Dowercc16be82016-09-08 10:35:16 -07002604 path_cleanup(&path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002605
2606 return return_value;
2607}
2608
Steve Dowercc16be82016-09-08 10:35:16 -07002609#endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002610
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002611#if defined(HAVE_FORK)
2612
2613PyDoc_STRVAR(os_register_at_fork__doc__,
Gregory P. Smith163468a2017-05-29 10:03:41 -07002614"register_at_fork($module, /, *, before=None, after_in_child=None,\n"
2615" after_in_parent=None)\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002616"--\n"
2617"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07002618"Register callables to be called when forking a new process.\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002619"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07002620" before\n"
2621" A callable to be called in the parent before the fork() syscall.\n"
2622" after_in_child\n"
2623" A callable to be called in the child after fork().\n"
2624" after_in_parent\n"
2625" A callable to be called in the parent after fork().\n"
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002626"\n"
Gregory P. Smith163468a2017-05-29 10:03:41 -07002627"\'before\' callbacks are called in reverse order.\n"
2628"\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002629
2630#define OS_REGISTER_AT_FORK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002631 {"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 +02002632
2633static PyObject *
Gregory P. Smith163468a2017-05-29 10:03:41 -07002634os_register_at_fork_impl(PyObject *module, PyObject *before,
2635 PyObject *after_in_child, PyObject *after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002636
2637static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002638os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002639{
2640 PyObject *return_value = NULL;
Gregory P. Smith163468a2017-05-29 10:03:41 -07002641 static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002642 static _PyArg_Parser _parser = {NULL, _keywords, "register_at_fork", 0};
2643 PyObject *argsbuf[3];
2644 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Gregory P. Smith163468a2017-05-29 10:03:41 -07002645 PyObject *before = NULL;
2646 PyObject *after_in_child = NULL;
2647 PyObject *after_in_parent = NULL;
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002648
Serhiy Storchaka31913912019-03-14 10:32:22 +02002649 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
2650 if (!args) {
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002651 goto exit;
2652 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02002653 if (!noptargs) {
2654 goto skip_optional_kwonly;
2655 }
2656 if (args[0]) {
2657 before = args[0];
2658 if (!--noptargs) {
2659 goto skip_optional_kwonly;
2660 }
2661 }
2662 if (args[1]) {
2663 after_in_child = args[1];
2664 if (!--noptargs) {
2665 goto skip_optional_kwonly;
2666 }
2667 }
2668 after_in_parent = args[2];
2669skip_optional_kwonly:
Gregory P. Smith163468a2017-05-29 10:03:41 -07002670 return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
Antoine Pitrou346cbd32017-05-27 17:50:54 +02002671
2672exit:
2673 return return_value;
2674}
2675
2676#endif /* defined(HAVE_FORK) */
2677
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002678#if defined(HAVE_FORK1)
2679
2680PyDoc_STRVAR(os_fork1__doc__,
2681"fork1($module, /)\n"
2682"--\n"
2683"\n"
2684"Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
2685"\n"
2686"Return 0 to child process and PID of child to parent process.");
2687
2688#define OS_FORK1_METHODDEF \
2689 {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
2690
2691static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002692os_fork1_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002693
2694static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002695os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002696{
2697 return os_fork1_impl(module);
2698}
2699
2700#endif /* defined(HAVE_FORK1) */
2701
2702#if defined(HAVE_FORK)
2703
2704PyDoc_STRVAR(os_fork__doc__,
2705"fork($module, /)\n"
2706"--\n"
2707"\n"
2708"Fork a child process.\n"
2709"\n"
2710"Return 0 to child process and PID of child to parent process.");
2711
2712#define OS_FORK_METHODDEF \
2713 {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
2714
2715static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002716os_fork_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002717
2718static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002719os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002720{
2721 return os_fork_impl(module);
2722}
2723
2724#endif /* defined(HAVE_FORK) */
2725
2726#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2727
2728PyDoc_STRVAR(os_sched_get_priority_max__doc__,
2729"sched_get_priority_max($module, /, policy)\n"
2730"--\n"
2731"\n"
2732"Get the maximum scheduling priority for policy.");
2733
2734#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002735 {"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 +03002736
2737static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002738os_sched_get_priority_max_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002739
2740static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002741os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002742{
2743 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002744 static const char * const _keywords[] = {"policy", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002745 static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_max", 0};
2746 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002747 int policy;
2748
Serhiy Storchaka31913912019-03-14 10:32:22 +02002749 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2750 if (!args) {
2751 goto exit;
2752 }
2753 if (PyFloat_Check(args[0])) {
2754 PyErr_SetString(PyExc_TypeError,
2755 "integer argument expected, got float" );
2756 goto exit;
2757 }
2758 policy = _PyLong_AsInt(args[0]);
2759 if (policy == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002760 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002761 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002762 return_value = os_sched_get_priority_max_impl(module, policy);
2763
2764exit:
2765 return return_value;
2766}
2767
2768#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2769
2770#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
2771
2772PyDoc_STRVAR(os_sched_get_priority_min__doc__,
2773"sched_get_priority_min($module, /, policy)\n"
2774"--\n"
2775"\n"
2776"Get the minimum scheduling priority for policy.");
2777
2778#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002779 {"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 +03002780
2781static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002782os_sched_get_priority_min_impl(PyObject *module, int policy);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002783
2784static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002785os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002786{
2787 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002788 static const char * const _keywords[] = {"policy", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002789 static _PyArg_Parser _parser = {NULL, _keywords, "sched_get_priority_min", 0};
2790 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002791 int policy;
2792
Serhiy Storchaka31913912019-03-14 10:32:22 +02002793 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2794 if (!args) {
2795 goto exit;
2796 }
2797 if (PyFloat_Check(args[0])) {
2798 PyErr_SetString(PyExc_TypeError,
2799 "integer argument expected, got float" );
2800 goto exit;
2801 }
2802 policy = _PyLong_AsInt(args[0]);
2803 if (policy == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002804 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002805 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002806 return_value = os_sched_get_priority_min_impl(module, policy);
2807
2808exit:
2809 return return_value;
2810}
2811
2812#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
2813
2814#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2815
2816PyDoc_STRVAR(os_sched_getscheduler__doc__,
2817"sched_getscheduler($module, pid, /)\n"
2818"--\n"
2819"\n"
2820"Get the scheduling policy for the process identifiedy by pid.\n"
2821"\n"
2822"Passing 0 for pid returns the scheduling policy for the calling process.");
2823
2824#define OS_SCHED_GETSCHEDULER_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002825 {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002826
2827static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002828os_sched_getscheduler_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002829
2830static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002831os_sched_getscheduler(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002832{
2833 PyObject *return_value = NULL;
2834 pid_t pid;
2835
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002836 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002837 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002838 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002839 return_value = os_sched_getscheduler_impl(module, pid);
2840
2841exit:
2842 return return_value;
2843}
2844
2845#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2846
William Orr81574b82018-10-01 22:19:56 -07002847#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 +03002848
2849PyDoc_STRVAR(os_sched_param__doc__,
2850"sched_param(sched_priority)\n"
2851"--\n"
2852"\n"
2853"Current has only one field: sched_priority\");\n"
2854"\n"
2855" sched_priority\n"
2856" A scheduling parameter.");
2857
2858static PyObject *
2859os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
2860
2861static PyObject *
2862os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2863{
2864 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03002865 static const char * const _keywords[] = {"sched_priority", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02002866 static _PyArg_Parser _parser = {NULL, _keywords, "sched_param", 0};
2867 PyObject *argsbuf[1];
2868 PyObject * const *fastargs;
2869 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002870 PyObject *sched_priority;
2871
Serhiy Storchaka31913912019-03-14 10:32:22 +02002872 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
2873 if (!fastargs) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002874 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002875 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02002876 sched_priority = fastargs[0];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002877 return_value = os_sched_param_impl(type, sched_priority);
2878
2879exit:
2880 return return_value;
2881}
2882
William Orr81574b82018-10-01 22:19:56 -07002883#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 +03002884
2885#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
2886
2887PyDoc_STRVAR(os_sched_setscheduler__doc__,
2888"sched_setscheduler($module, pid, policy, param, /)\n"
2889"--\n"
2890"\n"
2891"Set the scheduling policy for the process identified by pid.\n"
2892"\n"
2893"If pid is 0, the calling process is changed.\n"
2894"param is an instance of sched_param.");
2895
2896#define OS_SCHED_SETSCHEDULER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002897 {"sched_setscheduler", (PyCFunction)(void(*)(void))os_sched_setscheduler, METH_FASTCALL, os_sched_setscheduler__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002898
2899static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002900os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
Larry Hastings89964c42015-04-14 18:07:59 -04002901 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002902
2903static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002904os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002905{
2906 PyObject *return_value = NULL;
2907 pid_t pid;
2908 int policy;
2909 struct sched_param param;
2910
Sylvain74453812017-06-10 06:51:48 +02002911 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO&:sched_setscheduler",
2912 &pid, &policy, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002913 goto exit;
2914 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002915 return_value = os_sched_setscheduler_impl(module, pid, policy, &param);
2916
2917exit:
2918 return return_value;
2919}
2920
2921#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
2922
2923#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2924
2925PyDoc_STRVAR(os_sched_getparam__doc__,
2926"sched_getparam($module, pid, /)\n"
2927"--\n"
2928"\n"
2929"Returns scheduling parameters for the process identified by pid.\n"
2930"\n"
2931"If pid is 0, returns parameters for the calling process.\n"
2932"Return value is an instance of sched_param.");
2933
2934#define OS_SCHED_GETPARAM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03002935 {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002936
2937static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002938os_sched_getparam_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002939
2940static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002941os_sched_getparam(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002942{
2943 PyObject *return_value = NULL;
2944 pid_t pid;
2945
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002946 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002947 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002948 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002949 return_value = os_sched_getparam_impl(module, pid);
2950
2951exit:
2952 return return_value;
2953}
2954
2955#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2956
2957#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
2958
2959PyDoc_STRVAR(os_sched_setparam__doc__,
2960"sched_setparam($module, pid, param, /)\n"
2961"--\n"
2962"\n"
2963"Set scheduling parameters for the process identified by pid.\n"
2964"\n"
2965"If pid is 0, sets parameters for the calling process.\n"
2966"param should be an instance of sched_param.");
2967
2968#define OS_SCHED_SETPARAM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002969 {"sched_setparam", (PyCFunction)(void(*)(void))os_sched_setparam, METH_FASTCALL, os_sched_setparam__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002970
2971static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002972os_sched_setparam_impl(PyObject *module, pid_t pid,
Larry Hastings89964c42015-04-14 18:07:59 -04002973 struct sched_param *param);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002974
2975static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002976os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002977{
2978 PyObject *return_value = NULL;
2979 pid_t pid;
2980 struct sched_param param;
2981
Sylvain74453812017-06-10 06:51:48 +02002982 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O&:sched_setparam",
2983 &pid, convert_sched_param, &param)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002984 goto exit;
2985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03002986 return_value = os_sched_setparam_impl(module, pid, &param);
2987
2988exit:
2989 return return_value;
2990}
2991
2992#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
2993
2994#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
2995
2996PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
2997"sched_rr_get_interval($module, pid, /)\n"
2998"--\n"
2999"\n"
3000"Return the round-robin quantum for the process identified by pid, in seconds.\n"
3001"\n"
3002"Value returned is a float.");
3003
3004#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003005 {"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 +03003006
3007static double
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003008os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003009
3010static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003011os_sched_rr_get_interval(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003012{
3013 PyObject *return_value = NULL;
3014 pid_t pid;
3015 double _return_value;
3016
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003017 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003018 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003019 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003020 _return_value = os_sched_rr_get_interval_impl(module, pid);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003021 if ((_return_value == -1.0) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003022 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003023 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003024 return_value = PyFloat_FromDouble(_return_value);
3025
3026exit:
3027 return return_value;
3028}
3029
3030#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
3031
3032#if defined(HAVE_SCHED_H)
3033
3034PyDoc_STRVAR(os_sched_yield__doc__,
3035"sched_yield($module, /)\n"
3036"--\n"
3037"\n"
3038"Voluntarily relinquish the CPU.");
3039
3040#define OS_SCHED_YIELD_METHODDEF \
3041 {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
3042
3043static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003044os_sched_yield_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003045
3046static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003047os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003048{
3049 return os_sched_yield_impl(module);
3050}
3051
3052#endif /* defined(HAVE_SCHED_H) */
3053
3054#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
3055
3056PyDoc_STRVAR(os_sched_setaffinity__doc__,
3057"sched_setaffinity($module, pid, mask, /)\n"
3058"--\n"
3059"\n"
3060"Set the CPU affinity of the process identified by pid to mask.\n"
3061"\n"
3062"mask should be an iterable of integers identifying CPUs.");
3063
3064#define OS_SCHED_SETAFFINITY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003065 {"sched_setaffinity", (PyCFunction)(void(*)(void))os_sched_setaffinity, METH_FASTCALL, os_sched_setaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003066
3067static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003068os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003069
3070static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003071os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003072{
3073 PyObject *return_value = NULL;
3074 pid_t pid;
3075 PyObject *mask;
3076
Sylvain74453812017-06-10 06:51:48 +02003077 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
3078 &pid, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003079 goto exit;
3080 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003081 return_value = os_sched_setaffinity_impl(module, pid, mask);
3082
3083exit:
3084 return return_value;
3085}
3086
3087#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
3088
3089#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
3090
3091PyDoc_STRVAR(os_sched_getaffinity__doc__,
3092"sched_getaffinity($module, pid, /)\n"
3093"--\n"
3094"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01003095"Return the affinity of the process identified by pid (or the current process if zero).\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003096"\n"
3097"The affinity is returned as a set of CPU identifiers.");
3098
3099#define OS_SCHED_GETAFFINITY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003100 {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003101
3102static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003103os_sched_getaffinity_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003104
3105static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003106os_sched_getaffinity(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003107{
3108 PyObject *return_value = NULL;
3109 pid_t pid;
3110
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003111 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003112 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003113 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003114 return_value = os_sched_getaffinity_impl(module, pid);
3115
3116exit:
3117 return return_value;
3118}
3119
3120#endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
3121
3122#if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
3123
3124PyDoc_STRVAR(os_openpty__doc__,
3125"openpty($module, /)\n"
3126"--\n"
3127"\n"
3128"Open a pseudo-terminal.\n"
3129"\n"
3130"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
3131"for both the master and slave ends.");
3132
3133#define OS_OPENPTY_METHODDEF \
3134 {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
3135
3136static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003137os_openpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003138
3139static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003140os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003141{
3142 return os_openpty_impl(module);
3143}
3144
3145#endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
3146
3147#if defined(HAVE_FORKPTY)
3148
3149PyDoc_STRVAR(os_forkpty__doc__,
3150"forkpty($module, /)\n"
3151"--\n"
3152"\n"
3153"Fork a new process with a new pseudo-terminal as controlling tty.\n"
3154"\n"
3155"Returns a tuple of (pid, master_fd).\n"
3156"Like fork(), return pid of 0 to the child process,\n"
3157"and pid of child to the parent process.\n"
3158"To both, return fd of newly opened pseudo-terminal.");
3159
3160#define OS_FORKPTY_METHODDEF \
3161 {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
3162
3163static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003164os_forkpty_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003165
3166static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003167os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003168{
3169 return os_forkpty_impl(module);
3170}
3171
3172#endif /* defined(HAVE_FORKPTY) */
3173
3174#if defined(HAVE_GETEGID)
3175
3176PyDoc_STRVAR(os_getegid__doc__,
3177"getegid($module, /)\n"
3178"--\n"
3179"\n"
3180"Return the current process\'s effective group id.");
3181
3182#define OS_GETEGID_METHODDEF \
3183 {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
3184
3185static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003186os_getegid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003187
3188static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003189os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003190{
3191 return os_getegid_impl(module);
3192}
3193
3194#endif /* defined(HAVE_GETEGID) */
3195
3196#if defined(HAVE_GETEUID)
3197
3198PyDoc_STRVAR(os_geteuid__doc__,
3199"geteuid($module, /)\n"
3200"--\n"
3201"\n"
3202"Return the current process\'s effective user id.");
3203
3204#define OS_GETEUID_METHODDEF \
3205 {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
3206
3207static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003208os_geteuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003209
3210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003211os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003212{
3213 return os_geteuid_impl(module);
3214}
3215
3216#endif /* defined(HAVE_GETEUID) */
3217
3218#if defined(HAVE_GETGID)
3219
3220PyDoc_STRVAR(os_getgid__doc__,
3221"getgid($module, /)\n"
3222"--\n"
3223"\n"
3224"Return the current process\'s group id.");
3225
3226#define OS_GETGID_METHODDEF \
3227 {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
3228
3229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003230os_getgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003231
3232static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003233os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003234{
3235 return os_getgid_impl(module);
3236}
3237
3238#endif /* defined(HAVE_GETGID) */
3239
Berker Peksag39404992016-09-15 20:45:16 +03003240#if defined(HAVE_GETPID)
3241
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003242PyDoc_STRVAR(os_getpid__doc__,
3243"getpid($module, /)\n"
3244"--\n"
3245"\n"
3246"Return the current process id.");
3247
3248#define OS_GETPID_METHODDEF \
3249 {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
3250
3251static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003252os_getpid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003253
3254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003255os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003256{
3257 return os_getpid_impl(module);
3258}
3259
Berker Peksag39404992016-09-15 20:45:16 +03003260#endif /* defined(HAVE_GETPID) */
3261
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003262#if defined(HAVE_GETGROUPS)
3263
3264PyDoc_STRVAR(os_getgroups__doc__,
3265"getgroups($module, /)\n"
3266"--\n"
3267"\n"
3268"Return list of supplemental group IDs for the process.");
3269
3270#define OS_GETGROUPS_METHODDEF \
3271 {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
3272
3273static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003274os_getgroups_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003275
3276static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003277os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003278{
3279 return os_getgroups_impl(module);
3280}
3281
3282#endif /* defined(HAVE_GETGROUPS) */
3283
3284#if defined(HAVE_GETPGID)
3285
3286PyDoc_STRVAR(os_getpgid__doc__,
3287"getpgid($module, /, pid)\n"
3288"--\n"
3289"\n"
3290"Call the system call getpgid(), and return the result.");
3291
3292#define OS_GETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003293 {"getpgid", (PyCFunction)(void(*)(void))os_getpgid, METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003294
3295static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003296os_getpgid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003297
3298static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003299os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003300{
3301 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003302 static const char * const _keywords[] = {"pid", NULL};
3303 static _PyArg_Parser _parser = {"" _Py_PARSE_PID ":getpgid", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003304 pid_t pid;
3305
Victor Stinner3e1fad62017-01-17 01:29:01 +01003306 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003307 &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003308 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003309 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003310 return_value = os_getpgid_impl(module, pid);
3311
3312exit:
3313 return return_value;
3314}
3315
3316#endif /* defined(HAVE_GETPGID) */
3317
3318#if defined(HAVE_GETPGRP)
3319
3320PyDoc_STRVAR(os_getpgrp__doc__,
3321"getpgrp($module, /)\n"
3322"--\n"
3323"\n"
3324"Return the current process group id.");
3325
3326#define OS_GETPGRP_METHODDEF \
3327 {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
3328
3329static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003330os_getpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003331
3332static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003333os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003334{
3335 return os_getpgrp_impl(module);
3336}
3337
3338#endif /* defined(HAVE_GETPGRP) */
3339
3340#if defined(HAVE_SETPGRP)
3341
3342PyDoc_STRVAR(os_setpgrp__doc__,
3343"setpgrp($module, /)\n"
3344"--\n"
3345"\n"
3346"Make the current process the leader of its process group.");
3347
3348#define OS_SETPGRP_METHODDEF \
3349 {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
3350
3351static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003352os_setpgrp_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003353
3354static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003355os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003356{
3357 return os_setpgrp_impl(module);
3358}
3359
3360#endif /* defined(HAVE_SETPGRP) */
3361
3362#if defined(HAVE_GETPPID)
3363
3364PyDoc_STRVAR(os_getppid__doc__,
3365"getppid($module, /)\n"
3366"--\n"
3367"\n"
3368"Return the parent\'s process id.\n"
3369"\n"
3370"If the parent process has already exited, Windows machines will still\n"
3371"return its id; others systems will return the id of the \'init\' process (1).");
3372
3373#define OS_GETPPID_METHODDEF \
3374 {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
3375
3376static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003377os_getppid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003378
3379static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003380os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003381{
3382 return os_getppid_impl(module);
3383}
3384
3385#endif /* defined(HAVE_GETPPID) */
3386
3387#if defined(HAVE_GETLOGIN)
3388
3389PyDoc_STRVAR(os_getlogin__doc__,
3390"getlogin($module, /)\n"
3391"--\n"
3392"\n"
3393"Return the actual login name.");
3394
3395#define OS_GETLOGIN_METHODDEF \
3396 {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
3397
3398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003399os_getlogin_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003400
3401static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003402os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003403{
3404 return os_getlogin_impl(module);
3405}
3406
3407#endif /* defined(HAVE_GETLOGIN) */
3408
3409#if defined(HAVE_GETUID)
3410
3411PyDoc_STRVAR(os_getuid__doc__,
3412"getuid($module, /)\n"
3413"--\n"
3414"\n"
3415"Return the current process\'s user id.");
3416
3417#define OS_GETUID_METHODDEF \
3418 {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
3419
3420static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003421os_getuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003422
3423static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003424os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003425{
3426 return os_getuid_impl(module);
3427}
3428
3429#endif /* defined(HAVE_GETUID) */
3430
3431#if defined(HAVE_KILL)
3432
3433PyDoc_STRVAR(os_kill__doc__,
3434"kill($module, pid, signal, /)\n"
3435"--\n"
3436"\n"
3437"Kill a process with a signal.");
3438
3439#define OS_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003440 {"kill", (PyCFunction)(void(*)(void))os_kill, METH_FASTCALL, os_kill__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003441
3442static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003443os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003444
3445static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003446os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003447{
3448 PyObject *return_value = NULL;
3449 pid_t pid;
3450 Py_ssize_t signal;
3451
Sylvain74453812017-06-10 06:51:48 +02003452 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
3453 &pid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003454 goto exit;
3455 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003456 return_value = os_kill_impl(module, pid, signal);
3457
3458exit:
3459 return return_value;
3460}
3461
3462#endif /* defined(HAVE_KILL) */
3463
3464#if defined(HAVE_KILLPG)
3465
3466PyDoc_STRVAR(os_killpg__doc__,
3467"killpg($module, pgid, signal, /)\n"
3468"--\n"
3469"\n"
3470"Kill a process group with a signal.");
3471
3472#define OS_KILLPG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003473 {"killpg", (PyCFunction)(void(*)(void))os_killpg, METH_FASTCALL, os_killpg__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003474
3475static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003476os_killpg_impl(PyObject *module, pid_t pgid, int signal);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003477
3478static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003479os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003480{
3481 PyObject *return_value = NULL;
3482 pid_t pgid;
3483 int signal;
3484
Sylvain74453812017-06-10 06:51:48 +02003485 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
3486 &pgid, &signal)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003487 goto exit;
3488 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003489 return_value = os_killpg_impl(module, pgid, signal);
3490
3491exit:
3492 return return_value;
3493}
3494
3495#endif /* defined(HAVE_KILLPG) */
3496
3497#if defined(HAVE_PLOCK)
3498
3499PyDoc_STRVAR(os_plock__doc__,
3500"plock($module, op, /)\n"
3501"--\n"
3502"\n"
3503"Lock program segments into memory.\");");
3504
3505#define OS_PLOCK_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003506 {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003507
3508static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003509os_plock_impl(PyObject *module, int op);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003510
3511static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003512os_plock(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003513{
3514 PyObject *return_value = NULL;
3515 int op;
3516
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003517 if (PyFloat_Check(arg)) {
3518 PyErr_SetString(PyExc_TypeError,
3519 "integer argument expected, got float" );
3520 goto exit;
3521 }
3522 op = _PyLong_AsInt(arg);
3523 if (op == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003524 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003525 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003526 return_value = os_plock_impl(module, op);
3527
3528exit:
3529 return return_value;
3530}
3531
3532#endif /* defined(HAVE_PLOCK) */
3533
3534#if defined(HAVE_SETUID)
3535
3536PyDoc_STRVAR(os_setuid__doc__,
3537"setuid($module, uid, /)\n"
3538"--\n"
3539"\n"
3540"Set the current process\'s user id.");
3541
3542#define OS_SETUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003543 {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003544
3545static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003546os_setuid_impl(PyObject *module, uid_t uid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003547
3548static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003549os_setuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003550{
3551 PyObject *return_value = NULL;
3552 uid_t uid;
3553
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003554 if (!_Py_Uid_Converter(arg, &uid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003555 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003556 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003557 return_value = os_setuid_impl(module, uid);
3558
3559exit:
3560 return return_value;
3561}
3562
3563#endif /* defined(HAVE_SETUID) */
3564
3565#if defined(HAVE_SETEUID)
3566
3567PyDoc_STRVAR(os_seteuid__doc__,
3568"seteuid($module, euid, /)\n"
3569"--\n"
3570"\n"
3571"Set the current process\'s effective user id.");
3572
3573#define OS_SETEUID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003574 {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003575
3576static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003577os_seteuid_impl(PyObject *module, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003578
3579static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003580os_seteuid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003581{
3582 PyObject *return_value = NULL;
3583 uid_t euid;
3584
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003585 if (!_Py_Uid_Converter(arg, &euid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003586 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003587 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003588 return_value = os_seteuid_impl(module, euid);
3589
3590exit:
3591 return return_value;
3592}
3593
3594#endif /* defined(HAVE_SETEUID) */
3595
3596#if defined(HAVE_SETEGID)
3597
3598PyDoc_STRVAR(os_setegid__doc__,
3599"setegid($module, egid, /)\n"
3600"--\n"
3601"\n"
3602"Set the current process\'s effective group id.");
3603
3604#define OS_SETEGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003605 {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003606
3607static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003608os_setegid_impl(PyObject *module, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003609
3610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003611os_setegid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003612{
3613 PyObject *return_value = NULL;
3614 gid_t egid;
3615
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003616 if (!_Py_Gid_Converter(arg, &egid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003617 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003618 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003619 return_value = os_setegid_impl(module, egid);
3620
3621exit:
3622 return return_value;
3623}
3624
3625#endif /* defined(HAVE_SETEGID) */
3626
3627#if defined(HAVE_SETREUID)
3628
3629PyDoc_STRVAR(os_setreuid__doc__,
3630"setreuid($module, ruid, euid, /)\n"
3631"--\n"
3632"\n"
3633"Set the current process\'s real and effective user ids.");
3634
3635#define OS_SETREUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003636 {"setreuid", (PyCFunction)(void(*)(void))os_setreuid, METH_FASTCALL, os_setreuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003637
3638static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003639os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003640
3641static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003642os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003643{
3644 PyObject *return_value = NULL;
3645 uid_t ruid;
3646 uid_t euid;
3647
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003648 if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
3649 goto exit;
3650 }
3651 if (!_Py_Uid_Converter(args[0], &ruid)) {
3652 goto exit;
3653 }
3654 if (!_Py_Uid_Converter(args[1], &euid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003655 goto exit;
3656 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003657 return_value = os_setreuid_impl(module, ruid, euid);
3658
3659exit:
3660 return return_value;
3661}
3662
3663#endif /* defined(HAVE_SETREUID) */
3664
3665#if defined(HAVE_SETREGID)
3666
3667PyDoc_STRVAR(os_setregid__doc__,
3668"setregid($module, rgid, egid, /)\n"
3669"--\n"
3670"\n"
3671"Set the current process\'s real and effective group ids.");
3672
3673#define OS_SETREGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003674 {"setregid", (PyCFunction)(void(*)(void))os_setregid, METH_FASTCALL, os_setregid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003675
3676static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003677os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003678
3679static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003680os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003681{
3682 PyObject *return_value = NULL;
3683 gid_t rgid;
3684 gid_t egid;
3685
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02003686 if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
3687 goto exit;
3688 }
3689 if (!_Py_Gid_Converter(args[0], &rgid)) {
3690 goto exit;
3691 }
3692 if (!_Py_Gid_Converter(args[1], &egid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003693 goto exit;
3694 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003695 return_value = os_setregid_impl(module, rgid, egid);
3696
3697exit:
3698 return return_value;
3699}
3700
3701#endif /* defined(HAVE_SETREGID) */
3702
3703#if defined(HAVE_SETGID)
3704
3705PyDoc_STRVAR(os_setgid__doc__,
3706"setgid($module, gid, /)\n"
3707"--\n"
3708"\n"
3709"Set the current process\'s group id.");
3710
3711#define OS_SETGID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03003712 {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003713
3714static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003715os_setgid_impl(PyObject *module, gid_t gid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003716
3717static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003718os_setgid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003719{
3720 PyObject *return_value = NULL;
3721 gid_t gid;
3722
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02003723 if (!_Py_Gid_Converter(arg, &gid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003724 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003725 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003726 return_value = os_setgid_impl(module, gid);
3727
3728exit:
3729 return return_value;
3730}
3731
3732#endif /* defined(HAVE_SETGID) */
3733
3734#if defined(HAVE_SETGROUPS)
3735
3736PyDoc_STRVAR(os_setgroups__doc__,
3737"setgroups($module, groups, /)\n"
3738"--\n"
3739"\n"
3740"Set the groups of the current process to list.");
3741
3742#define OS_SETGROUPS_METHODDEF \
3743 {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
3744
3745#endif /* defined(HAVE_SETGROUPS) */
3746
3747#if defined(HAVE_WAIT3)
3748
3749PyDoc_STRVAR(os_wait3__doc__,
3750"wait3($module, /, options)\n"
3751"--\n"
3752"\n"
3753"Wait for completion of a child process.\n"
3754"\n"
3755"Returns a tuple of information about the child process:\n"
3756" (pid, status, rusage)");
3757
3758#define OS_WAIT3_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003759 {"wait3", (PyCFunction)(void(*)(void))os_wait3, METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003760
3761static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003762os_wait3_impl(PyObject *module, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003763
3764static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003765os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003766{
3767 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003768 static const char * const _keywords[] = {"options", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02003769 static _PyArg_Parser _parser = {NULL, _keywords, "wait3", 0};
3770 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003771 int options;
3772
Serhiy Storchaka31913912019-03-14 10:32:22 +02003773 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
3774 if (!args) {
3775 goto exit;
3776 }
3777 if (PyFloat_Check(args[0])) {
3778 PyErr_SetString(PyExc_TypeError,
3779 "integer argument expected, got float" );
3780 goto exit;
3781 }
3782 options = _PyLong_AsInt(args[0]);
3783 if (options == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003784 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003785 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003786 return_value = os_wait3_impl(module, options);
3787
3788exit:
3789 return return_value;
3790}
3791
3792#endif /* defined(HAVE_WAIT3) */
3793
3794#if defined(HAVE_WAIT4)
3795
3796PyDoc_STRVAR(os_wait4__doc__,
3797"wait4($module, /, pid, options)\n"
3798"--\n"
3799"\n"
3800"Wait for completion of a specific child process.\n"
3801"\n"
3802"Returns a tuple of information about the child process:\n"
3803" (pid, status, rusage)");
3804
3805#define OS_WAIT4_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003806 {"wait4", (PyCFunction)(void(*)(void))os_wait4, METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003807
3808static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003809os_wait4_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003810
3811static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003812os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003813{
3814 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03003815 static const char * const _keywords[] = {"pid", "options", NULL};
3816 static _PyArg_Parser _parser = {"" _Py_PARSE_PID "i:wait4", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003817 pid_t pid;
3818 int options;
3819
Victor Stinner3e1fad62017-01-17 01:29:01 +01003820 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003821 &pid, &options)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003822 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03003823 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003824 return_value = os_wait4_impl(module, pid, options);
3825
3826exit:
3827 return return_value;
3828}
3829
3830#endif /* defined(HAVE_WAIT4) */
3831
3832#if (defined(HAVE_WAITID) && !defined(__APPLE__))
3833
3834PyDoc_STRVAR(os_waitid__doc__,
3835"waitid($module, idtype, id, options, /)\n"
3836"--\n"
3837"\n"
3838"Returns the result of waiting for a process or processes.\n"
3839"\n"
3840" idtype\n"
3841" Must be one of be P_PID, P_PGID or P_ALL.\n"
3842" id\n"
3843" The id to wait on.\n"
3844" options\n"
3845" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
3846" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
3847"\n"
3848"Returns either waitid_result or None if WNOHANG is specified and there are\n"
3849"no children in a waitable state.");
3850
3851#define OS_WAITID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003852 {"waitid", (PyCFunction)(void(*)(void))os_waitid, METH_FASTCALL, os_waitid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003853
3854static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003855os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003856
3857static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003858os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003859{
3860 PyObject *return_value = NULL;
3861 idtype_t idtype;
3862 id_t id;
3863 int options;
3864
Sylvain74453812017-06-10 06:51:48 +02003865 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
3866 &idtype, &id, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003867 goto exit;
3868 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003869 return_value = os_waitid_impl(module, idtype, id, options);
3870
3871exit:
3872 return return_value;
3873}
3874
3875#endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
3876
3877#if defined(HAVE_WAITPID)
3878
3879PyDoc_STRVAR(os_waitpid__doc__,
3880"waitpid($module, pid, options, /)\n"
3881"--\n"
3882"\n"
3883"Wait for completion of a given child process.\n"
3884"\n"
3885"Returns a tuple of information regarding the child process:\n"
3886" (pid, status)\n"
3887"\n"
3888"The options argument is ignored on Windows.");
3889
3890#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003891 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003892
3893static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003894os_waitpid_impl(PyObject *module, pid_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003895
3896static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003897os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003898{
3899 PyObject *return_value = NULL;
3900 pid_t pid;
3901 int options;
3902
Sylvain74453812017-06-10 06:51:48 +02003903 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
3904 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003905 goto exit;
3906 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003907 return_value = os_waitpid_impl(module, pid, options);
3908
3909exit:
3910 return return_value;
3911}
3912
3913#endif /* defined(HAVE_WAITPID) */
3914
3915#if defined(HAVE_CWAIT)
3916
3917PyDoc_STRVAR(os_waitpid__doc__,
3918"waitpid($module, pid, options, /)\n"
3919"--\n"
3920"\n"
3921"Wait for completion of a given process.\n"
3922"\n"
3923"Returns a tuple of information regarding the process:\n"
3924" (pid, status << 8)\n"
3925"\n"
3926"The options argument is ignored on Windows.");
3927
3928#define OS_WAITPID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003929 {"waitpid", (PyCFunction)(void(*)(void))os_waitpid, METH_FASTCALL, os_waitpid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003930
3931static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07003932os_waitpid_impl(PyObject *module, intptr_t pid, int options);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003933
3934static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02003935os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003936{
3937 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07003938 intptr_t pid;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003939 int options;
3940
Sylvain74453812017-06-10 06:51:48 +02003941 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
3942 &pid, &options)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01003943 goto exit;
3944 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003945 return_value = os_waitpid_impl(module, pid, options);
3946
3947exit:
3948 return return_value;
3949}
3950
3951#endif /* defined(HAVE_CWAIT) */
3952
3953#if defined(HAVE_WAIT)
3954
3955PyDoc_STRVAR(os_wait__doc__,
3956"wait($module, /)\n"
3957"--\n"
3958"\n"
3959"Wait for completion of a child process.\n"
3960"\n"
3961"Returns a tuple of information about the child process:\n"
3962" (pid, status)");
3963
3964#define OS_WAIT_METHODDEF \
3965 {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
3966
3967static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003968os_wait_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003969
3970static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03003971os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03003972{
3973 return os_wait_impl(module);
3974}
3975
3976#endif /* defined(HAVE_WAIT) */
3977
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003978#if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
3979
3980PyDoc_STRVAR(os_readlink__doc__,
3981"readlink($module, /, path, *, dir_fd=None)\n"
3982"--\n"
3983"\n"
3984"Return a string representing the path to which the symbolic link points.\n"
3985"\n"
3986"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3987"and path should be relative; path will then be relative to that directory.\n"
3988"\n"
3989"dir_fd may not be implemented on your platform. If it is unavailable,\n"
3990"using it will raise a NotImplementedError.");
3991
3992#define OS_READLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02003993 {"readlink", (PyCFunction)(void(*)(void))os_readlink, METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03003994
3995static PyObject *
3996os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
3997
3998static PyObject *
3999os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4000{
4001 PyObject *return_value = NULL;
4002 static const char * const _keywords[] = {"path", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02004003 static _PyArg_Parser _parser = {NULL, _keywords, "readlink", 0};
4004 PyObject *argsbuf[2];
4005 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03004006 path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
4007 int dir_fd = DEFAULT_DIR_FD;
4008
Serhiy Storchaka31913912019-03-14 10:32:22 +02004009 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
4010 if (!args) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03004011 goto exit;
4012 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02004013 if (!path_converter(args[0], &path)) {
4014 goto exit;
4015 }
4016 if (!noptargs) {
4017 goto skip_optional_kwonly;
4018 }
4019 if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
4020 goto exit;
4021 }
4022skip_optional_kwonly:
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03004023 return_value = os_readlink_impl(module, &path, dir_fd);
4024
4025exit:
4026 /* Cleanup for path */
4027 path_cleanup(&path);
4028
4029 return return_value;
4030}
4031
4032#endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
4033
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004034#if defined(HAVE_SYMLINK)
4035
4036PyDoc_STRVAR(os_symlink__doc__,
4037"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
4038"--\n"
4039"\n"
4040"Create a symbolic link pointing to src named dst.\n"
4041"\n"
4042"target_is_directory is required on Windows if the target is to be\n"
4043" interpreted as a directory. (On Windows, symlink requires\n"
4044" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
4045" target_is_directory is ignored on non-Windows platforms.\n"
4046"\n"
4047"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4048" and path should be relative; path will then be relative to that directory.\n"
4049"dir_fd may not be implemented on your platform.\n"
4050" If it is unavailable, using it will raise a NotImplementedError.");
4051
4052#define OS_SYMLINK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004053 {"symlink", (PyCFunction)(void(*)(void))os_symlink, METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004054
4055static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004056os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
Larry Hastings89964c42015-04-14 18:07:59 -04004057 int target_is_directory, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004058
4059static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004060os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004061{
4062 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004063 static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02004064 static _PyArg_Parser _parser = {NULL, _keywords, "symlink", 0};
4065 PyObject *argsbuf[4];
4066 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004067 path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
4068 path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
4069 int target_is_directory = 0;
4070 int dir_fd = DEFAULT_DIR_FD;
4071
Serhiy Storchaka31913912019-03-14 10:32:22 +02004072 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
4073 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004074 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004075 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02004076 if (!path_converter(args[0], &src)) {
4077 goto exit;
4078 }
4079 if (!path_converter(args[1], &dst)) {
4080 goto exit;
4081 }
4082 if (!noptargs) {
4083 goto skip_optional_pos;
4084 }
4085 if (args[2]) {
4086 target_is_directory = PyObject_IsTrue(args[2]);
4087 if (target_is_directory < 0) {
4088 goto exit;
4089 }
4090 if (!--noptargs) {
4091 goto skip_optional_pos;
4092 }
4093 }
4094skip_optional_pos:
4095 if (!noptargs) {
4096 goto skip_optional_kwonly;
4097 }
4098 if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
4099 goto exit;
4100 }
4101skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004102 return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
4103
4104exit:
4105 /* Cleanup for src */
4106 path_cleanup(&src);
4107 /* Cleanup for dst */
4108 path_cleanup(&dst);
4109
4110 return return_value;
4111}
4112
4113#endif /* defined(HAVE_SYMLINK) */
4114
4115#if defined(HAVE_TIMES)
4116
4117PyDoc_STRVAR(os_times__doc__,
4118"times($module, /)\n"
4119"--\n"
4120"\n"
4121"Return a collection containing process timing information.\n"
4122"\n"
4123"The object returned behaves like a named tuple with these fields:\n"
4124" (utime, stime, cutime, cstime, elapsed_time)\n"
4125"All fields are floating point numbers.");
4126
4127#define OS_TIMES_METHODDEF \
4128 {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
4129
4130static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004131os_times_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004132
4133static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004134os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004135{
4136 return os_times_impl(module);
4137}
4138
4139#endif /* defined(HAVE_TIMES) */
4140
4141#if defined(HAVE_GETSID)
4142
4143PyDoc_STRVAR(os_getsid__doc__,
4144"getsid($module, pid, /)\n"
4145"--\n"
4146"\n"
4147"Call the system call getsid(pid) and return the result.");
4148
4149#define OS_GETSID_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004150 {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004151
4152static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004153os_getsid_impl(PyObject *module, pid_t pid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004154
4155static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004156os_getsid(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004157{
4158 PyObject *return_value = NULL;
4159 pid_t pid;
4160
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004161 if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004162 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004163 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004164 return_value = os_getsid_impl(module, pid);
4165
4166exit:
4167 return return_value;
4168}
4169
4170#endif /* defined(HAVE_GETSID) */
4171
4172#if defined(HAVE_SETSID)
4173
4174PyDoc_STRVAR(os_setsid__doc__,
4175"setsid($module, /)\n"
4176"--\n"
4177"\n"
4178"Call the system call setsid().");
4179
4180#define OS_SETSID_METHODDEF \
4181 {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
4182
4183static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004184os_setsid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004185
4186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004187os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004188{
4189 return os_setsid_impl(module);
4190}
4191
4192#endif /* defined(HAVE_SETSID) */
4193
4194#if defined(HAVE_SETPGID)
4195
4196PyDoc_STRVAR(os_setpgid__doc__,
4197"setpgid($module, pid, pgrp, /)\n"
4198"--\n"
4199"\n"
4200"Call the system call setpgid(pid, pgrp).");
4201
4202#define OS_SETPGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004203 {"setpgid", (PyCFunction)(void(*)(void))os_setpgid, METH_FASTCALL, os_setpgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004204
4205static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004206os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004207
4208static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004209os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004210{
4211 PyObject *return_value = NULL;
4212 pid_t pid;
4213 pid_t pgrp;
4214
Sylvain74453812017-06-10 06:51:48 +02004215 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
4216 &pid, &pgrp)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004217 goto exit;
4218 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004219 return_value = os_setpgid_impl(module, pid, pgrp);
4220
4221exit:
4222 return return_value;
4223}
4224
4225#endif /* defined(HAVE_SETPGID) */
4226
4227#if defined(HAVE_TCGETPGRP)
4228
4229PyDoc_STRVAR(os_tcgetpgrp__doc__,
4230"tcgetpgrp($module, fd, /)\n"
4231"--\n"
4232"\n"
4233"Return the process group associated with the terminal specified by fd.");
4234
4235#define OS_TCGETPGRP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004236 {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004237
4238static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004239os_tcgetpgrp_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004240
4241static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004242os_tcgetpgrp(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004243{
4244 PyObject *return_value = NULL;
4245 int fd;
4246
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004247 if (PyFloat_Check(arg)) {
4248 PyErr_SetString(PyExc_TypeError,
4249 "integer argument expected, got float" );
4250 goto exit;
4251 }
4252 fd = _PyLong_AsInt(arg);
4253 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004254 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004255 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004256 return_value = os_tcgetpgrp_impl(module, fd);
4257
4258exit:
4259 return return_value;
4260}
4261
4262#endif /* defined(HAVE_TCGETPGRP) */
4263
4264#if defined(HAVE_TCSETPGRP)
4265
4266PyDoc_STRVAR(os_tcsetpgrp__doc__,
4267"tcsetpgrp($module, fd, pgid, /)\n"
4268"--\n"
4269"\n"
4270"Set the process group associated with the terminal specified by fd.");
4271
4272#define OS_TCSETPGRP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004273 {"tcsetpgrp", (PyCFunction)(void(*)(void))os_tcsetpgrp, METH_FASTCALL, os_tcsetpgrp__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004274
4275static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004276os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004277
4278static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004279os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004280{
4281 PyObject *return_value = NULL;
4282 int fd;
4283 pid_t pgid;
4284
Sylvain74453812017-06-10 06:51:48 +02004285 if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
4286 &fd, &pgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004287 goto exit;
4288 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004289 return_value = os_tcsetpgrp_impl(module, fd, pgid);
4290
4291exit:
4292 return return_value;
4293}
4294
4295#endif /* defined(HAVE_TCSETPGRP) */
4296
4297PyDoc_STRVAR(os_open__doc__,
4298"open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
4299"--\n"
4300"\n"
4301"Open a file for low level IO. Returns a file descriptor (integer).\n"
4302"\n"
4303"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
4304" and path should be relative; path will then be relative to that directory.\n"
4305"dir_fd may not be implemented on your platform.\n"
4306" If it is unavailable, using it will raise a NotImplementedError.");
4307
4308#define OS_OPEN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004309 {"open", (PyCFunction)(void(*)(void))os_open, METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004310
4311static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004312os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004313
4314static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004315os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004316{
4317 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004318 static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02004319 static _PyArg_Parser _parser = {NULL, _keywords, "open", 0};
4320 PyObject *argsbuf[4];
4321 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004322 path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
4323 int flags;
4324 int mode = 511;
4325 int dir_fd = DEFAULT_DIR_FD;
4326 int _return_value;
4327
Serhiy Storchaka31913912019-03-14 10:32:22 +02004328 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
4329 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004330 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004331 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02004332 if (!path_converter(args[0], &path)) {
4333 goto exit;
4334 }
4335 if (PyFloat_Check(args[1])) {
4336 PyErr_SetString(PyExc_TypeError,
4337 "integer argument expected, got float" );
4338 goto exit;
4339 }
4340 flags = _PyLong_AsInt(args[1]);
4341 if (flags == -1 && PyErr_Occurred()) {
4342 goto exit;
4343 }
4344 if (!noptargs) {
4345 goto skip_optional_pos;
4346 }
4347 if (args[2]) {
4348 if (PyFloat_Check(args[2])) {
4349 PyErr_SetString(PyExc_TypeError,
4350 "integer argument expected, got float" );
4351 goto exit;
4352 }
4353 mode = _PyLong_AsInt(args[2]);
4354 if (mode == -1 && PyErr_Occurred()) {
4355 goto exit;
4356 }
4357 if (!--noptargs) {
4358 goto skip_optional_pos;
4359 }
4360 }
4361skip_optional_pos:
4362 if (!noptargs) {
4363 goto skip_optional_kwonly;
4364 }
4365 if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
4366 goto exit;
4367 }
4368skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004369 _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004370 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004371 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004372 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004373 return_value = PyLong_FromLong((long)_return_value);
4374
4375exit:
4376 /* Cleanup for path */
4377 path_cleanup(&path);
4378
4379 return return_value;
4380}
4381
4382PyDoc_STRVAR(os_close__doc__,
4383"close($module, /, fd)\n"
4384"--\n"
4385"\n"
4386"Close a file descriptor.");
4387
4388#define OS_CLOSE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004389 {"close", (PyCFunction)(void(*)(void))os_close, METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004390
4391static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004392os_close_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004393
4394static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004395os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004396{
4397 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004398 static const char * const _keywords[] = {"fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02004399 static _PyArg_Parser _parser = {NULL, _keywords, "close", 0};
4400 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004401 int fd;
4402
Serhiy Storchaka31913912019-03-14 10:32:22 +02004403 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
4404 if (!args) {
4405 goto exit;
4406 }
4407 if (PyFloat_Check(args[0])) {
4408 PyErr_SetString(PyExc_TypeError,
4409 "integer argument expected, got float" );
4410 goto exit;
4411 }
4412 fd = _PyLong_AsInt(args[0]);
4413 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004414 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004415 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004416 return_value = os_close_impl(module, fd);
4417
4418exit:
4419 return return_value;
4420}
4421
4422PyDoc_STRVAR(os_closerange__doc__,
4423"closerange($module, fd_low, fd_high, /)\n"
4424"--\n"
4425"\n"
4426"Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
4427
4428#define OS_CLOSERANGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004429 {"closerange", (PyCFunction)(void(*)(void))os_closerange, METH_FASTCALL, os_closerange__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004430
4431static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004432os_closerange_impl(PyObject *module, int fd_low, int fd_high);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004433
4434static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004435os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004436{
4437 PyObject *return_value = NULL;
4438 int fd_low;
4439 int fd_high;
4440
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004441 if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
4442 goto exit;
4443 }
4444 if (PyFloat_Check(args[0])) {
4445 PyErr_SetString(PyExc_TypeError,
4446 "integer argument expected, got float" );
4447 goto exit;
4448 }
4449 fd_low = _PyLong_AsInt(args[0]);
4450 if (fd_low == -1 && PyErr_Occurred()) {
4451 goto exit;
4452 }
4453 if (PyFloat_Check(args[1])) {
4454 PyErr_SetString(PyExc_TypeError,
4455 "integer argument expected, got float" );
4456 goto exit;
4457 }
4458 fd_high = _PyLong_AsInt(args[1]);
4459 if (fd_high == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004460 goto exit;
4461 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004462 return_value = os_closerange_impl(module, fd_low, fd_high);
4463
4464exit:
4465 return return_value;
4466}
4467
4468PyDoc_STRVAR(os_dup__doc__,
4469"dup($module, fd, /)\n"
4470"--\n"
4471"\n"
4472"Return a duplicate of a file descriptor.");
4473
4474#define OS_DUP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03004475 {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004476
4477static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004478os_dup_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004479
4480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004481os_dup(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004482{
4483 PyObject *return_value = NULL;
4484 int fd;
4485 int _return_value;
4486
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02004487 if (PyFloat_Check(arg)) {
4488 PyErr_SetString(PyExc_TypeError,
4489 "integer argument expected, got float" );
4490 goto exit;
4491 }
4492 fd = _PyLong_AsInt(arg);
4493 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004494 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004495 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004496 _return_value = os_dup_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004497 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004498 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004499 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004500 return_value = PyLong_FromLong((long)_return_value);
4501
4502exit:
4503 return return_value;
4504}
4505
4506PyDoc_STRVAR(os_dup2__doc__,
4507"dup2($module, /, fd, fd2, inheritable=True)\n"
4508"--\n"
4509"\n"
4510"Duplicate file descriptor.");
4511
4512#define OS_DUP2_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004513 {"dup2", (PyCFunction)(void(*)(void))os_dup2, METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004514
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08004515static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004516os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004517
4518static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004519os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004520{
4521 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03004522 static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02004523 static _PyArg_Parser _parser = {NULL, _keywords, "dup2", 0};
4524 PyObject *argsbuf[3];
4525 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004526 int fd;
4527 int fd2;
4528 int inheritable = 1;
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08004529 int _return_value;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004530
Serhiy Storchaka31913912019-03-14 10:32:22 +02004531 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
4532 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004533 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004534 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02004535 if (PyFloat_Check(args[0])) {
4536 PyErr_SetString(PyExc_TypeError,
4537 "integer argument expected, got float" );
4538 goto exit;
4539 }
4540 fd = _PyLong_AsInt(args[0]);
4541 if (fd == -1 && PyErr_Occurred()) {
4542 goto exit;
4543 }
4544 if (PyFloat_Check(args[1])) {
4545 PyErr_SetString(PyExc_TypeError,
4546 "integer argument expected, got float" );
4547 goto exit;
4548 }
4549 fd2 = _PyLong_AsInt(args[1]);
4550 if (fd2 == -1 && PyErr_Occurred()) {
4551 goto exit;
4552 }
4553 if (!noptargs) {
4554 goto skip_optional_pos;
4555 }
4556 inheritable = PyObject_IsTrue(args[2]);
4557 if (inheritable < 0) {
4558 goto exit;
4559 }
4560skip_optional_pos:
Benjamin Petersonbbdb17d2017-12-29 13:13:06 -08004561 _return_value = os_dup2_impl(module, fd, fd2, inheritable);
4562 if ((_return_value == -1) && PyErr_Occurred()) {
4563 goto exit;
4564 }
4565 return_value = PyLong_FromLong((long)_return_value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004566
4567exit:
4568 return return_value;
4569}
4570
4571#if defined(HAVE_LOCKF)
4572
4573PyDoc_STRVAR(os_lockf__doc__,
4574"lockf($module, fd, command, length, /)\n"
4575"--\n"
4576"\n"
4577"Apply, test or remove a POSIX lock on an open file descriptor.\n"
4578"\n"
4579" fd\n"
4580" An open file descriptor.\n"
4581" command\n"
4582" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
4583" length\n"
4584" The number of bytes to lock, starting at the current position.");
4585
4586#define OS_LOCKF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004587 {"lockf", (PyCFunction)(void(*)(void))os_lockf, METH_FASTCALL, os_lockf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004588
4589static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004590os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004591
4592static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004593os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004594{
4595 PyObject *return_value = NULL;
4596 int fd;
4597 int command;
4598 Py_off_t length;
4599
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004600 if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
4601 goto exit;
4602 }
4603 if (PyFloat_Check(args[0])) {
4604 PyErr_SetString(PyExc_TypeError,
4605 "integer argument expected, got float" );
4606 goto exit;
4607 }
4608 fd = _PyLong_AsInt(args[0]);
4609 if (fd == -1 && PyErr_Occurred()) {
4610 goto exit;
4611 }
4612 if (PyFloat_Check(args[1])) {
4613 PyErr_SetString(PyExc_TypeError,
4614 "integer argument expected, got float" );
4615 goto exit;
4616 }
4617 command = _PyLong_AsInt(args[1]);
4618 if (command == -1 && PyErr_Occurred()) {
4619 goto exit;
4620 }
4621 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004622 goto exit;
4623 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004624 return_value = os_lockf_impl(module, fd, command, length);
4625
4626exit:
4627 return return_value;
4628}
4629
4630#endif /* defined(HAVE_LOCKF) */
4631
4632PyDoc_STRVAR(os_lseek__doc__,
4633"lseek($module, fd, position, how, /)\n"
4634"--\n"
4635"\n"
4636"Set the position of a file descriptor. Return the new position.\n"
4637"\n"
4638"Return the new cursor position in number of bytes\n"
4639"relative to the beginning of the file.");
4640
4641#define OS_LSEEK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004642 {"lseek", (PyCFunction)(void(*)(void))os_lseek, METH_FASTCALL, os_lseek__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004643
4644static Py_off_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004645os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004646
4647static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004648os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004649{
4650 PyObject *return_value = NULL;
4651 int fd;
4652 Py_off_t position;
4653 int how;
4654 Py_off_t _return_value;
4655
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004656 if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
4657 goto exit;
4658 }
4659 if (PyFloat_Check(args[0])) {
4660 PyErr_SetString(PyExc_TypeError,
4661 "integer argument expected, got float" );
4662 goto exit;
4663 }
4664 fd = _PyLong_AsInt(args[0]);
4665 if (fd == -1 && PyErr_Occurred()) {
4666 goto exit;
4667 }
4668 if (!Py_off_t_converter(args[1], &position)) {
4669 goto exit;
4670 }
4671 if (PyFloat_Check(args[2])) {
4672 PyErr_SetString(PyExc_TypeError,
4673 "integer argument expected, got float" );
4674 goto exit;
4675 }
4676 how = _PyLong_AsInt(args[2]);
4677 if (how == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004678 goto exit;
4679 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004680 _return_value = os_lseek_impl(module, fd, position, how);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004681 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004682 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004683 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004684 return_value = PyLong_FromPy_off_t(_return_value);
4685
4686exit:
4687 return return_value;
4688}
4689
4690PyDoc_STRVAR(os_read__doc__,
4691"read($module, fd, length, /)\n"
4692"--\n"
4693"\n"
4694"Read from a file descriptor. Returns a bytes object.");
4695
4696#define OS_READ_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004697 {"read", (PyCFunction)(void(*)(void))os_read, METH_FASTCALL, os_read__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004698
4699static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004700os_read_impl(PyObject *module, int fd, Py_ssize_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004701
4702static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004703os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004704{
4705 PyObject *return_value = NULL;
4706 int fd;
4707 Py_ssize_t length;
4708
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004709 if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004710 goto exit;
4711 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004712 if (PyFloat_Check(args[0])) {
4713 PyErr_SetString(PyExc_TypeError,
4714 "integer argument expected, got float" );
4715 goto exit;
4716 }
4717 fd = _PyLong_AsInt(args[0]);
4718 if (fd == -1 && PyErr_Occurred()) {
4719 goto exit;
4720 }
4721 if (PyFloat_Check(args[1])) {
4722 PyErr_SetString(PyExc_TypeError,
4723 "integer argument expected, got float" );
4724 goto exit;
4725 }
4726 {
4727 Py_ssize_t ival = -1;
4728 PyObject *iobj = PyNumber_Index(args[1]);
4729 if (iobj != NULL) {
4730 ival = PyLong_AsSsize_t(iobj);
4731 Py_DECREF(iobj);
4732 }
4733 if (ival == -1 && PyErr_Occurred()) {
4734 goto exit;
4735 }
4736 length = ival;
4737 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004738 return_value = os_read_impl(module, fd, length);
4739
4740exit:
4741 return return_value;
4742}
4743
4744#if defined(HAVE_READV)
4745
4746PyDoc_STRVAR(os_readv__doc__,
4747"readv($module, fd, buffers, /)\n"
4748"--\n"
4749"\n"
4750"Read from a file descriptor fd into an iterable of buffers.\n"
4751"\n"
4752"The buffers should be mutable buffers accepting bytes.\n"
4753"readv will transfer data into each buffer until it is full\n"
4754"and then move on to the next buffer in the sequence to hold\n"
4755"the rest of the data.\n"
4756"\n"
4757"readv returns the total number of bytes read,\n"
4758"which may be less than the total capacity of all the buffers.");
4759
4760#define OS_READV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004761 {"readv", (PyCFunction)(void(*)(void))os_readv, METH_FASTCALL, os_readv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004762
4763static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004764os_readv_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004765
4766static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004767os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004768{
4769 PyObject *return_value = NULL;
4770 int fd;
4771 PyObject *buffers;
4772 Py_ssize_t _return_value;
4773
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004774 if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004775 goto exit;
4776 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004777 if (PyFloat_Check(args[0])) {
4778 PyErr_SetString(PyExc_TypeError,
4779 "integer argument expected, got float" );
4780 goto exit;
4781 }
4782 fd = _PyLong_AsInt(args[0]);
4783 if (fd == -1 && PyErr_Occurred()) {
4784 goto exit;
4785 }
4786 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004787 _return_value = os_readv_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004788 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004789 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004790 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004791 return_value = PyLong_FromSsize_t(_return_value);
4792
4793exit:
4794 return return_value;
4795}
4796
4797#endif /* defined(HAVE_READV) */
4798
4799#if defined(HAVE_PREAD)
4800
4801PyDoc_STRVAR(os_pread__doc__,
4802"pread($module, fd, length, offset, /)\n"
4803"--\n"
4804"\n"
4805"Read a number of bytes from a file descriptor starting at a particular offset.\n"
4806"\n"
4807"Read length bytes from file descriptor fd, starting at offset bytes from\n"
4808"the beginning of the file. The file offset remains unchanged.");
4809
4810#define OS_PREAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004811 {"pread", (PyCFunction)(void(*)(void))os_pread, METH_FASTCALL, os_pread__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004812
4813static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004814os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004815
4816static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004817os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004818{
4819 PyObject *return_value = NULL;
4820 int fd;
4821 int length;
4822 Py_off_t offset;
4823
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004824 if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
4825 goto exit;
4826 }
4827 if (PyFloat_Check(args[0])) {
4828 PyErr_SetString(PyExc_TypeError,
4829 "integer argument expected, got float" );
4830 goto exit;
4831 }
4832 fd = _PyLong_AsInt(args[0]);
4833 if (fd == -1 && PyErr_Occurred()) {
4834 goto exit;
4835 }
4836 if (PyFloat_Check(args[1])) {
4837 PyErr_SetString(PyExc_TypeError,
4838 "integer argument expected, got float" );
4839 goto exit;
4840 }
4841 length = _PyLong_AsInt(args[1]);
4842 if (length == -1 && PyErr_Occurred()) {
4843 goto exit;
4844 }
4845 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01004846 goto exit;
4847 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004848 return_value = os_pread_impl(module, fd, length, offset);
4849
4850exit:
4851 return return_value;
4852}
4853
4854#endif /* defined(HAVE_PREAD) */
4855
Pablo Galindo4defba32018-01-27 16:16:37 +00004856#if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
4857
4858PyDoc_STRVAR(os_preadv__doc__,
4859"preadv($module, fd, buffers, offset, flags=0, /)\n"
4860"--\n"
4861"\n"
4862"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
4863"\n"
4864"Combines the functionality of readv() and pread(). As readv(), it will\n"
4865"transfer data into each buffer until it is full and then move on to the next\n"
4866"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
4867"specifies the file offset at which the input operation is to be performed. It\n"
4868"will return the total number of bytes read (which can be less than the total\n"
4869"capacity of all the objects).\n"
4870"\n"
4871"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4872"\n"
4873"- RWF_HIPRI\n"
4874"- RWF_NOWAIT\n"
4875"\n"
4876"Using non-zero flags requires Linux 4.6 or newer.");
4877
4878#define OS_PREADV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004879 {"preadv", (PyCFunction)(void(*)(void))os_preadv, METH_FASTCALL, os_preadv__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00004880
4881static Py_ssize_t
4882os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
4883 int flags);
4884
4885static PyObject *
4886os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4887{
4888 PyObject *return_value = NULL;
4889 int fd;
4890 PyObject *buffers;
4891 Py_off_t offset;
4892 int flags = 0;
4893 Py_ssize_t _return_value;
4894
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004895 if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00004896 goto exit;
4897 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004898 if (PyFloat_Check(args[0])) {
4899 PyErr_SetString(PyExc_TypeError,
4900 "integer argument expected, got float" );
4901 goto exit;
4902 }
4903 fd = _PyLong_AsInt(args[0]);
4904 if (fd == -1 && PyErr_Occurred()) {
4905 goto exit;
4906 }
4907 buffers = args[1];
4908 if (!Py_off_t_converter(args[2], &offset)) {
4909 goto exit;
4910 }
4911 if (nargs < 4) {
4912 goto skip_optional;
4913 }
4914 if (PyFloat_Check(args[3])) {
4915 PyErr_SetString(PyExc_TypeError,
4916 "integer argument expected, got float" );
4917 goto exit;
4918 }
4919 flags = _PyLong_AsInt(args[3]);
4920 if (flags == -1 && PyErr_Occurred()) {
4921 goto exit;
4922 }
4923skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00004924 _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
4925 if ((_return_value == -1) && PyErr_Occurred()) {
4926 goto exit;
4927 }
4928 return_value = PyLong_FromSsize_t(_return_value);
4929
4930exit:
4931 return return_value;
4932}
4933
4934#endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
4935
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004936PyDoc_STRVAR(os_write__doc__,
4937"write($module, fd, data, /)\n"
4938"--\n"
4939"\n"
4940"Write a bytes object to a file descriptor.");
4941
4942#define OS_WRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004943 {"write", (PyCFunction)(void(*)(void))os_write, METH_FASTCALL, os_write__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004944
4945static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03004946os_write_impl(PyObject *module, int fd, Py_buffer *data);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004947
4948static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02004949os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004950{
4951 PyObject *return_value = NULL;
4952 int fd;
4953 Py_buffer data = {NULL, NULL};
4954 Py_ssize_t _return_value;
4955
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02004956 if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
4957 goto exit;
4958 }
4959 if (PyFloat_Check(args[0])) {
4960 PyErr_SetString(PyExc_TypeError,
4961 "integer argument expected, got float" );
4962 goto exit;
4963 }
4964 fd = _PyLong_AsInt(args[0]);
4965 if (fd == -1 && PyErr_Occurred()) {
4966 goto exit;
4967 }
4968 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
4969 goto exit;
4970 }
4971 if (!PyBuffer_IsContiguous(&data, 'C')) {
4972 _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]);
Victor Stinner259f0e42017-01-17 01:35:17 +01004973 goto exit;
4974 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004975 _return_value = os_write_impl(module, fd, &data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004976 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004977 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004978 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004979 return_value = PyLong_FromSsize_t(_return_value);
4980
4981exit:
4982 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004983 if (data.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004984 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03004985 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03004986
4987 return return_value;
4988}
4989
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004990#if defined(__APPLE__)
4991
4992PyDoc_STRVAR(os__fcopyfile__doc__,
4993"_fcopyfile($module, infd, outfd, flags, /)\n"
4994"--\n"
4995"\n"
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -07004996"Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02004997
4998#define OS__FCOPYFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02004999 {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02005000
5001static PyObject *
5002os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags);
5003
5004static PyObject *
5005os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5006{
5007 PyObject *return_value = NULL;
5008 int infd;
5009 int outfd;
5010 int flags;
5011
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005012 if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
5013 goto exit;
5014 }
5015 if (PyFloat_Check(args[0])) {
5016 PyErr_SetString(PyExc_TypeError,
5017 "integer argument expected, got float" );
5018 goto exit;
5019 }
5020 infd = _PyLong_AsInt(args[0]);
5021 if (infd == -1 && PyErr_Occurred()) {
5022 goto exit;
5023 }
5024 if (PyFloat_Check(args[1])) {
5025 PyErr_SetString(PyExc_TypeError,
5026 "integer argument expected, got float" );
5027 goto exit;
5028 }
5029 outfd = _PyLong_AsInt(args[1]);
5030 if (outfd == -1 && PyErr_Occurred()) {
5031 goto exit;
5032 }
5033 if (PyFloat_Check(args[2])) {
5034 PyErr_SetString(PyExc_TypeError,
5035 "integer argument expected, got float" );
5036 goto exit;
5037 }
5038 flags = _PyLong_AsInt(args[2]);
5039 if (flags == -1 && PyErr_Occurred()) {
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02005040 goto exit;
5041 }
5042 return_value = os__fcopyfile_impl(module, infd, outfd, flags);
5043
5044exit:
5045 return return_value;
5046}
5047
5048#endif /* defined(__APPLE__) */
5049
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005050PyDoc_STRVAR(os_fstat__doc__,
5051"fstat($module, /, fd)\n"
5052"--\n"
5053"\n"
5054"Perform a stat system call on the given file descriptor.\n"
5055"\n"
5056"Like stat(), but for an open file descriptor.\n"
5057"Equivalent to os.stat(fd).");
5058
5059#define OS_FSTAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005060 {"fstat", (PyCFunction)(void(*)(void))os_fstat, METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005061
5062static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005063os_fstat_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005064
5065static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005066os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005067{
5068 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005069 static const char * const _keywords[] = {"fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02005070 static _PyArg_Parser _parser = {NULL, _keywords, "fstat", 0};
5071 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005072 int fd;
5073
Serhiy Storchaka31913912019-03-14 10:32:22 +02005074 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
5075 if (!args) {
5076 goto exit;
5077 }
5078 if (PyFloat_Check(args[0])) {
5079 PyErr_SetString(PyExc_TypeError,
5080 "integer argument expected, got float" );
5081 goto exit;
5082 }
5083 fd = _PyLong_AsInt(args[0]);
5084 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005086 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005087 return_value = os_fstat_impl(module, fd);
5088
5089exit:
5090 return return_value;
5091}
5092
5093PyDoc_STRVAR(os_isatty__doc__,
5094"isatty($module, fd, /)\n"
5095"--\n"
5096"\n"
5097"Return True if the fd is connected to a terminal.\n"
5098"\n"
5099"Return True if the file descriptor is an open file descriptor\n"
5100"connected to the slave end of a terminal.");
5101
5102#define OS_ISATTY_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005103 {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005104
5105static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005106os_isatty_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005107
5108static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005109os_isatty(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005110{
5111 PyObject *return_value = NULL;
5112 int fd;
5113 int _return_value;
5114
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005115 if (PyFloat_Check(arg)) {
5116 PyErr_SetString(PyExc_TypeError,
5117 "integer argument expected, got float" );
5118 goto exit;
5119 }
5120 fd = _PyLong_AsInt(arg);
5121 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005122 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005123 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005124 _return_value = os_isatty_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005125 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005126 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005127 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005128 return_value = PyBool_FromLong((long)_return_value);
5129
5130exit:
5131 return return_value;
5132}
5133
5134#if defined(HAVE_PIPE)
5135
5136PyDoc_STRVAR(os_pipe__doc__,
5137"pipe($module, /)\n"
5138"--\n"
5139"\n"
5140"Create a pipe.\n"
5141"\n"
5142"Returns a tuple of two file descriptors:\n"
5143" (read_fd, write_fd)");
5144
5145#define OS_PIPE_METHODDEF \
5146 {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
5147
5148static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005149os_pipe_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005150
5151static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005152os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005153{
5154 return os_pipe_impl(module);
5155}
5156
5157#endif /* defined(HAVE_PIPE) */
5158
5159#if defined(HAVE_PIPE2)
5160
5161PyDoc_STRVAR(os_pipe2__doc__,
5162"pipe2($module, flags, /)\n"
5163"--\n"
5164"\n"
5165"Create a pipe with flags set atomically.\n"
5166"\n"
5167"Returns a tuple of two file descriptors:\n"
5168" (read_fd, write_fd)\n"
5169"\n"
5170"flags can be constructed by ORing together one or more of these values:\n"
5171"O_NONBLOCK, O_CLOEXEC.");
5172
5173#define OS_PIPE2_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005174 {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005175
5176static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005177os_pipe2_impl(PyObject *module, int flags);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005178
5179static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005180os_pipe2(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005181{
5182 PyObject *return_value = NULL;
5183 int flags;
5184
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005185 if (PyFloat_Check(arg)) {
5186 PyErr_SetString(PyExc_TypeError,
5187 "integer argument expected, got float" );
5188 goto exit;
5189 }
5190 flags = _PyLong_AsInt(arg);
5191 if (flags == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005192 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005193 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005194 return_value = os_pipe2_impl(module, flags);
5195
5196exit:
5197 return return_value;
5198}
5199
5200#endif /* defined(HAVE_PIPE2) */
5201
5202#if defined(HAVE_WRITEV)
5203
5204PyDoc_STRVAR(os_writev__doc__,
5205"writev($module, fd, buffers, /)\n"
5206"--\n"
5207"\n"
5208"Iterate over buffers, and write the contents of each to a file descriptor.\n"
5209"\n"
5210"Returns the total number of bytes written.\n"
5211"buffers must be a sequence of bytes-like objects.");
5212
5213#define OS_WRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005214 {"writev", (PyCFunction)(void(*)(void))os_writev, METH_FASTCALL, os_writev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005215
5216static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005217os_writev_impl(PyObject *module, int fd, PyObject *buffers);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005218
5219static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005220os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005221{
5222 PyObject *return_value = NULL;
5223 int fd;
5224 PyObject *buffers;
5225 Py_ssize_t _return_value;
5226
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005227 if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005228 goto exit;
5229 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005230 if (PyFloat_Check(args[0])) {
5231 PyErr_SetString(PyExc_TypeError,
5232 "integer argument expected, got float" );
5233 goto exit;
5234 }
5235 fd = _PyLong_AsInt(args[0]);
5236 if (fd == -1 && PyErr_Occurred()) {
5237 goto exit;
5238 }
5239 buffers = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005240 _return_value = os_writev_impl(module, fd, buffers);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005241 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005242 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005243 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005244 return_value = PyLong_FromSsize_t(_return_value);
5245
5246exit:
5247 return return_value;
5248}
5249
5250#endif /* defined(HAVE_WRITEV) */
5251
5252#if defined(HAVE_PWRITE)
5253
5254PyDoc_STRVAR(os_pwrite__doc__,
5255"pwrite($module, fd, buffer, offset, /)\n"
5256"--\n"
5257"\n"
5258"Write bytes to a file descriptor starting at a particular offset.\n"
5259"\n"
5260"Write buffer to fd, starting at offset bytes from the beginning of\n"
5261"the file. Returns the number of bytes writte. Does not change the\n"
5262"current file offset.");
5263
5264#define OS_PWRITE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005265 {"pwrite", (PyCFunction)(void(*)(void))os_pwrite, METH_FASTCALL, os_pwrite__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005266
5267static Py_ssize_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005268os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005269
5270static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005271os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005272{
5273 PyObject *return_value = NULL;
5274 int fd;
5275 Py_buffer buffer = {NULL, NULL};
5276 Py_off_t offset;
5277 Py_ssize_t _return_value;
5278
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005279 if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
5280 goto exit;
5281 }
5282 if (PyFloat_Check(args[0])) {
5283 PyErr_SetString(PyExc_TypeError,
5284 "integer argument expected, got float" );
5285 goto exit;
5286 }
5287 fd = _PyLong_AsInt(args[0]);
5288 if (fd == -1 && PyErr_Occurred()) {
5289 goto exit;
5290 }
5291 if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
5292 goto exit;
5293 }
5294 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
5295 _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]);
5296 goto exit;
5297 }
5298 if (!Py_off_t_converter(args[2], &offset)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005299 goto exit;
5300 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005301 _return_value = os_pwrite_impl(module, fd, &buffer, offset);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005302 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005303 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005304 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005305 return_value = PyLong_FromSsize_t(_return_value);
5306
5307exit:
5308 /* Cleanup for buffer */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005309 if (buffer.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005310 PyBuffer_Release(&buffer);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005311 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005312
5313 return return_value;
5314}
5315
5316#endif /* defined(HAVE_PWRITE) */
5317
Pablo Galindo4defba32018-01-27 16:16:37 +00005318#if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
5319
5320PyDoc_STRVAR(os_pwritev__doc__,
5321"pwritev($module, fd, buffers, offset, flags=0, /)\n"
5322"--\n"
5323"\n"
5324"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
5325"\n"
5326"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
5327"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
5328"buffer is written before proceeding to second, and so on. The operating system may\n"
5329"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
5330"This function writes the contents of each object to the file descriptor and returns\n"
5331"the total number of bytes written.\n"
5332"\n"
5333"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
5334"\n"
5335"- RWF_DSYNC\n"
5336"- RWF_SYNC\n"
5337"\n"
5338"Using non-zero flags requires Linux 4.7 or newer.");
5339
5340#define OS_PWRITEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005341 {"pwritev", (PyCFunction)(void(*)(void))os_pwritev, METH_FASTCALL, os_pwritev__doc__},
Pablo Galindo4defba32018-01-27 16:16:37 +00005342
5343static Py_ssize_t
5344os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
5345 int flags);
5346
5347static PyObject *
5348os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5349{
5350 PyObject *return_value = NULL;
5351 int fd;
5352 PyObject *buffers;
5353 Py_off_t offset;
5354 int flags = 0;
5355 Py_ssize_t _return_value;
5356
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005357 if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
Pablo Galindo4defba32018-01-27 16:16:37 +00005358 goto exit;
5359 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005360 if (PyFloat_Check(args[0])) {
5361 PyErr_SetString(PyExc_TypeError,
5362 "integer argument expected, got float" );
5363 goto exit;
5364 }
5365 fd = _PyLong_AsInt(args[0]);
5366 if (fd == -1 && PyErr_Occurred()) {
5367 goto exit;
5368 }
5369 buffers = args[1];
5370 if (!Py_off_t_converter(args[2], &offset)) {
5371 goto exit;
5372 }
5373 if (nargs < 4) {
5374 goto skip_optional;
5375 }
5376 if (PyFloat_Check(args[3])) {
5377 PyErr_SetString(PyExc_TypeError,
5378 "integer argument expected, got float" );
5379 goto exit;
5380 }
5381 flags = _PyLong_AsInt(args[3]);
5382 if (flags == -1 && PyErr_Occurred()) {
5383 goto exit;
5384 }
5385skip_optional:
Pablo Galindo4defba32018-01-27 16:16:37 +00005386 _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
5387 if ((_return_value == -1) && PyErr_Occurred()) {
5388 goto exit;
5389 }
5390 return_value = PyLong_FromSsize_t(_return_value);
5391
5392exit:
5393 return return_value;
5394}
5395
5396#endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
5397
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005398#if defined(HAVE_MKFIFO)
5399
5400PyDoc_STRVAR(os_mkfifo__doc__,
5401"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
5402"--\n"
5403"\n"
5404"Create a \"fifo\" (a POSIX named pipe).\n"
5405"\n"
5406"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
5407" and path should be relative; path will then be relative to that directory.\n"
5408"dir_fd may not be implemented on your platform.\n"
5409" If it is unavailable, using it will raise a NotImplementedError.");
5410
5411#define OS_MKFIFO_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005412 {"mkfifo", (PyCFunction)(void(*)(void))os_mkfifo, METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005413
5414static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005415os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005416
5417static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005418os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005419{
5420 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005421 static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02005422 static _PyArg_Parser _parser = {NULL, _keywords, "mkfifo", 0};
5423 PyObject *argsbuf[3];
5424 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005425 path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
5426 int mode = 438;
5427 int dir_fd = DEFAULT_DIR_FD;
5428
Serhiy Storchaka31913912019-03-14 10:32:22 +02005429 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
5430 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005431 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005432 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02005433 if (!path_converter(args[0], &path)) {
5434 goto exit;
5435 }
5436 if (!noptargs) {
5437 goto skip_optional_pos;
5438 }
5439 if (args[1]) {
5440 if (PyFloat_Check(args[1])) {
5441 PyErr_SetString(PyExc_TypeError,
5442 "integer argument expected, got float" );
5443 goto exit;
5444 }
5445 mode = _PyLong_AsInt(args[1]);
5446 if (mode == -1 && PyErr_Occurred()) {
5447 goto exit;
5448 }
5449 if (!--noptargs) {
5450 goto skip_optional_pos;
5451 }
5452 }
5453skip_optional_pos:
5454 if (!noptargs) {
5455 goto skip_optional_kwonly;
5456 }
5457 if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
5458 goto exit;
5459 }
5460skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005461 return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
5462
5463exit:
5464 /* Cleanup for path */
5465 path_cleanup(&path);
5466
5467 return return_value;
5468}
5469
5470#endif /* defined(HAVE_MKFIFO) */
5471
5472#if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
5473
5474PyDoc_STRVAR(os_mknod__doc__,
5475"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
5476"--\n"
5477"\n"
5478"Create a node in the file system.\n"
5479"\n"
5480"Create a node in the file system (file, device special file or named pipe)\n"
5481"at path. mode specifies both the permissions to use and the\n"
5482"type of node to be created, being combined (bitwise OR) with one of\n"
5483"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
5484"device defines the newly created device special file (probably using\n"
5485"os.makedev()). Otherwise device is ignored.\n"
5486"\n"
5487"If dir_fd is not None, it should be a file descriptor open to a directory,\n"
5488" and path should be relative; path will then be relative to that directory.\n"
5489"dir_fd may not be implemented on your platform.\n"
5490" If it is unavailable, using it will raise a NotImplementedError.");
5491
5492#define OS_MKNOD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005493 {"mknod", (PyCFunction)(void(*)(void))os_mknod, METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005494
5495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005496os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
Larry Hastings89964c42015-04-14 18:07:59 -04005497 int dir_fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005498
5499static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005500os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005501{
5502 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005503 static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02005504 static _PyArg_Parser _parser = {NULL, _keywords, "mknod", 0};
5505 PyObject *argsbuf[4];
5506 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005507 path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
5508 int mode = 384;
5509 dev_t device = 0;
5510 int dir_fd = DEFAULT_DIR_FD;
5511
Serhiy Storchaka31913912019-03-14 10:32:22 +02005512 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
5513 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005514 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005515 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02005516 if (!path_converter(args[0], &path)) {
5517 goto exit;
5518 }
5519 if (!noptargs) {
5520 goto skip_optional_pos;
5521 }
5522 if (args[1]) {
5523 if (PyFloat_Check(args[1])) {
5524 PyErr_SetString(PyExc_TypeError,
5525 "integer argument expected, got float" );
5526 goto exit;
5527 }
5528 mode = _PyLong_AsInt(args[1]);
5529 if (mode == -1 && PyErr_Occurred()) {
5530 goto exit;
5531 }
5532 if (!--noptargs) {
5533 goto skip_optional_pos;
5534 }
5535 }
5536 if (args[2]) {
5537 if (!_Py_Dev_Converter(args[2], &device)) {
5538 goto exit;
5539 }
5540 if (!--noptargs) {
5541 goto skip_optional_pos;
5542 }
5543 }
5544skip_optional_pos:
5545 if (!noptargs) {
5546 goto skip_optional_kwonly;
5547 }
5548 if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
5549 goto exit;
5550 }
5551skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005552 return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
5553
5554exit:
5555 /* Cleanup for path */
5556 path_cleanup(&path);
5557
5558 return return_value;
5559}
5560
5561#endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
5562
5563#if defined(HAVE_DEVICE_MACROS)
5564
5565PyDoc_STRVAR(os_major__doc__,
5566"major($module, device, /)\n"
5567"--\n"
5568"\n"
5569"Extracts a device major number from a raw device number.");
5570
5571#define OS_MAJOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005572 {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005573
5574static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005575os_major_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005576
5577static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005578os_major(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005579{
5580 PyObject *return_value = NULL;
5581 dev_t device;
5582 unsigned int _return_value;
5583
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005584 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005585 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005586 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005587 _return_value = os_major_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005588 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005589 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005590 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005591 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
5592
5593exit:
5594 return return_value;
5595}
5596
5597#endif /* defined(HAVE_DEVICE_MACROS) */
5598
5599#if defined(HAVE_DEVICE_MACROS)
5600
5601PyDoc_STRVAR(os_minor__doc__,
5602"minor($module, device, /)\n"
5603"--\n"
5604"\n"
5605"Extracts a device minor number from a raw device number.");
5606
5607#define OS_MINOR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03005608 {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005609
5610static unsigned int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005611os_minor_impl(PyObject *module, dev_t device);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005612
5613static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005614os_minor(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005615{
5616 PyObject *return_value = NULL;
5617 dev_t device;
5618 unsigned int _return_value;
5619
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02005620 if (!_Py_Dev_Converter(arg, &device)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005621 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005622 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005623 _return_value = os_minor_impl(module, device);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005624 if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005625 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005626 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005627 return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
5628
5629exit:
5630 return return_value;
5631}
5632
5633#endif /* defined(HAVE_DEVICE_MACROS) */
5634
5635#if defined(HAVE_DEVICE_MACROS)
5636
5637PyDoc_STRVAR(os_makedev__doc__,
5638"makedev($module, major, minor, /)\n"
5639"--\n"
5640"\n"
5641"Composes a raw device number from the major and minor device numbers.");
5642
5643#define OS_MAKEDEV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005644 {"makedev", (PyCFunction)(void(*)(void))os_makedev, METH_FASTCALL, os_makedev__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005645
5646static dev_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005647os_makedev_impl(PyObject *module, int major, int minor);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005648
5649static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005650os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005651{
5652 PyObject *return_value = NULL;
5653 int major;
5654 int minor;
5655 dev_t _return_value;
5656
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005657 if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
5658 goto exit;
5659 }
5660 if (PyFloat_Check(args[0])) {
5661 PyErr_SetString(PyExc_TypeError,
5662 "integer argument expected, got float" );
5663 goto exit;
5664 }
5665 major = _PyLong_AsInt(args[0]);
5666 if (major == -1 && PyErr_Occurred()) {
5667 goto exit;
5668 }
5669 if (PyFloat_Check(args[1])) {
5670 PyErr_SetString(PyExc_TypeError,
5671 "integer argument expected, got float" );
5672 goto exit;
5673 }
5674 minor = _PyLong_AsInt(args[1]);
5675 if (minor == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005676 goto exit;
5677 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005678 _return_value = os_makedev_impl(module, major, minor);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005679 if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005680 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005681 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005682 return_value = _PyLong_FromDev(_return_value);
5683
5684exit:
5685 return return_value;
5686}
5687
5688#endif /* defined(HAVE_DEVICE_MACROS) */
5689
Steve Dowerf7377032015-04-12 15:44:54 -04005690#if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005691
5692PyDoc_STRVAR(os_ftruncate__doc__,
5693"ftruncate($module, fd, length, /)\n"
5694"--\n"
5695"\n"
5696"Truncate a file, specified by file descriptor, to a specific length.");
5697
5698#define OS_FTRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005699 {"ftruncate", (PyCFunction)(void(*)(void))os_ftruncate, METH_FASTCALL, os_ftruncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005700
5701static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005702os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005703
5704static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005705os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005706{
5707 PyObject *return_value = NULL;
5708 int fd;
5709 Py_off_t length;
5710
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005711 if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
5712 goto exit;
5713 }
5714 if (PyFloat_Check(args[0])) {
5715 PyErr_SetString(PyExc_TypeError,
5716 "integer argument expected, got float" );
5717 goto exit;
5718 }
5719 fd = _PyLong_AsInt(args[0]);
5720 if (fd == -1 && PyErr_Occurred()) {
5721 goto exit;
5722 }
5723 if (!Py_off_t_converter(args[1], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005724 goto exit;
5725 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005726 return_value = os_ftruncate_impl(module, fd, length);
5727
5728exit:
5729 return return_value;
5730}
5731
Steve Dowerf7377032015-04-12 15:44:54 -04005732#endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005733
Steve Dowerf7377032015-04-12 15:44:54 -04005734#if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005735
5736PyDoc_STRVAR(os_truncate__doc__,
5737"truncate($module, /, path, length)\n"
5738"--\n"
5739"\n"
5740"Truncate a file, specified by path, to a specific length.\n"
5741"\n"
5742"On some platforms, path may also be specified as an open file descriptor.\n"
5743" If this functionality is unavailable, using it raises an exception.");
5744
5745#define OS_TRUNCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005746 {"truncate", (PyCFunction)(void(*)(void))os_truncate, METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005747
5748static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005749os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005750
5751static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005752os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005753{
5754 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03005755 static const char * const _keywords[] = {"path", "length", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02005756 static _PyArg_Parser _parser = {NULL, _keywords, "truncate", 0};
5757 PyObject *argsbuf[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005758 path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
5759 Py_off_t length;
5760
Serhiy Storchaka31913912019-03-14 10:32:22 +02005761 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
5762 if (!args) {
5763 goto exit;
5764 }
5765 if (!path_converter(args[0], &path)) {
5766 goto exit;
5767 }
5768 if (!Py_off_t_converter(args[1], &length)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005769 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03005770 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005771 return_value = os_truncate_impl(module, &path, length);
5772
5773exit:
5774 /* Cleanup for path */
5775 path_cleanup(&path);
5776
5777 return return_value;
5778}
5779
Steve Dowerf7377032015-04-12 15:44:54 -04005780#endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005781
5782#if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
5783
5784PyDoc_STRVAR(os_posix_fallocate__doc__,
5785"posix_fallocate($module, fd, offset, length, /)\n"
5786"--\n"
5787"\n"
5788"Ensure a file has allocated at least a particular number of bytes on disk.\n"
5789"\n"
5790"Ensure that the file specified by fd encompasses a range of bytes\n"
5791"starting at offset bytes from the beginning and continuing for length bytes.");
5792
5793#define OS_POSIX_FALLOCATE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005794 {"posix_fallocate", (PyCFunction)(void(*)(void))os_posix_fallocate, METH_FASTCALL, os_posix_fallocate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005795
5796static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005797os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04005798 Py_off_t length);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005799
5800static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005801os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005802{
5803 PyObject *return_value = NULL;
5804 int fd;
5805 Py_off_t offset;
5806 Py_off_t length;
5807
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005808 if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
5809 goto exit;
5810 }
5811 if (PyFloat_Check(args[0])) {
5812 PyErr_SetString(PyExc_TypeError,
5813 "integer argument expected, got float" );
5814 goto exit;
5815 }
5816 fd = _PyLong_AsInt(args[0]);
5817 if (fd == -1 && PyErr_Occurred()) {
5818 goto exit;
5819 }
5820 if (!Py_off_t_converter(args[1], &offset)) {
5821 goto exit;
5822 }
5823 if (!Py_off_t_converter(args[2], &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005824 goto exit;
5825 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005826 return_value = os_posix_fallocate_impl(module, fd, offset, length);
5827
5828exit:
5829 return return_value;
5830}
5831
5832#endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
5833
5834#if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
5835
5836PyDoc_STRVAR(os_posix_fadvise__doc__,
5837"posix_fadvise($module, fd, offset, length, advice, /)\n"
5838"--\n"
5839"\n"
5840"Announce an intention to access data in a specific pattern.\n"
5841"\n"
5842"Announce an intention to access data in a specific pattern, thus allowing\n"
5843"the kernel to make optimizations.\n"
5844"The advice applies to the region of the file specified by fd starting at\n"
5845"offset and continuing for length bytes.\n"
5846"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
5847"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
5848"POSIX_FADV_DONTNEED.");
5849
5850#define OS_POSIX_FADVISE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005851 {"posix_fadvise", (PyCFunction)(void(*)(void))os_posix_fadvise, METH_FASTCALL, os_posix_fadvise__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005852
5853static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005854os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
Larry Hastings89964c42015-04-14 18:07:59 -04005855 Py_off_t length, int advice);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005856
5857static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005858os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005859{
5860 PyObject *return_value = NULL;
5861 int fd;
5862 Py_off_t offset;
5863 Py_off_t length;
5864 int advice;
5865
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005866 if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
5867 goto exit;
5868 }
5869 if (PyFloat_Check(args[0])) {
5870 PyErr_SetString(PyExc_TypeError,
5871 "integer argument expected, got float" );
5872 goto exit;
5873 }
5874 fd = _PyLong_AsInt(args[0]);
5875 if (fd == -1 && PyErr_Occurred()) {
5876 goto exit;
5877 }
5878 if (!Py_off_t_converter(args[1], &offset)) {
5879 goto exit;
5880 }
5881 if (!Py_off_t_converter(args[2], &length)) {
5882 goto exit;
5883 }
5884 if (PyFloat_Check(args[3])) {
5885 PyErr_SetString(PyExc_TypeError,
5886 "integer argument expected, got float" );
5887 goto exit;
5888 }
5889 advice = _PyLong_AsInt(args[3]);
5890 if (advice == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005891 goto exit;
5892 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005893 return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
5894
5895exit:
5896 return return_value;
5897}
5898
5899#endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
5900
5901#if defined(HAVE_PUTENV) && defined(MS_WINDOWS)
5902
5903PyDoc_STRVAR(os_putenv__doc__,
5904"putenv($module, name, value, /)\n"
5905"--\n"
5906"\n"
5907"Change or add an environment variable.");
5908
5909#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005910 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005911
5912static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005913os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005914
5915static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005916os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005917{
5918 PyObject *return_value = NULL;
5919 PyObject *name;
5920 PyObject *value;
5921
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005922 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005923 goto exit;
5924 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005925 if (!PyUnicode_Check(args[0])) {
5926 _PyArg_BadArgument("putenv", 1, "str", args[0]);
5927 goto exit;
5928 }
5929 if (PyUnicode_READY(args[0]) == -1) {
5930 goto exit;
5931 }
5932 name = args[0];
5933 if (!PyUnicode_Check(args[1])) {
5934 _PyArg_BadArgument("putenv", 2, "str", args[1]);
5935 goto exit;
5936 }
5937 if (PyUnicode_READY(args[1]) == -1) {
5938 goto exit;
5939 }
5940 value = args[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005941 return_value = os_putenv_impl(module, name, value);
5942
5943exit:
5944 return return_value;
5945}
5946
5947#endif /* defined(HAVE_PUTENV) && defined(MS_WINDOWS) */
5948
5949#if defined(HAVE_PUTENV) && !defined(MS_WINDOWS)
5950
5951PyDoc_STRVAR(os_putenv__doc__,
5952"putenv($module, name, value, /)\n"
5953"--\n"
5954"\n"
5955"Change or add an environment variable.");
5956
5957#define OS_PUTENV_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02005958 {"putenv", (PyCFunction)(void(*)(void))os_putenv, METH_FASTCALL, os_putenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005959
5960static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03005961os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005962
5963static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02005964os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005965{
5966 PyObject *return_value = NULL;
5967 PyObject *name = NULL;
5968 PyObject *value = NULL;
5969
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02005970 if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
5971 goto exit;
5972 }
5973 if (!PyUnicode_FSConverter(args[0], &name)) {
5974 goto exit;
5975 }
5976 if (!PyUnicode_FSConverter(args[1], &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01005977 goto exit;
5978 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03005979 return_value = os_putenv_impl(module, name, value);
5980
5981exit:
5982 /* Cleanup for name */
5983 Py_XDECREF(name);
5984 /* Cleanup for value */
5985 Py_XDECREF(value);
5986
5987 return return_value;
5988}
5989
5990#endif /* defined(HAVE_PUTENV) && !defined(MS_WINDOWS) */
5991
5992#if defined(HAVE_UNSETENV)
5993
5994PyDoc_STRVAR(os_unsetenv__doc__,
5995"unsetenv($module, name, /)\n"
5996"--\n"
5997"\n"
5998"Delete an environment variable.");
5999
6000#define OS_UNSETENV_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006001 {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006002
6003static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006004os_unsetenv_impl(PyObject *module, PyObject *name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006005
6006static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006007os_unsetenv(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006008{
6009 PyObject *return_value = NULL;
6010 PyObject *name = NULL;
6011
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006012 if (!PyUnicode_FSConverter(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006013 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006014 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006015 return_value = os_unsetenv_impl(module, name);
6016
6017exit:
6018 /* Cleanup for name */
6019 Py_XDECREF(name);
6020
6021 return return_value;
6022}
6023
6024#endif /* defined(HAVE_UNSETENV) */
6025
6026PyDoc_STRVAR(os_strerror__doc__,
6027"strerror($module, code, /)\n"
6028"--\n"
6029"\n"
6030"Translate an error code to a message string.");
6031
6032#define OS_STRERROR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006033 {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006034
6035static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006036os_strerror_impl(PyObject *module, int code);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006037
6038static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006039os_strerror(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006040{
6041 PyObject *return_value = NULL;
6042 int code;
6043
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006044 if (PyFloat_Check(arg)) {
6045 PyErr_SetString(PyExc_TypeError,
6046 "integer argument expected, got float" );
6047 goto exit;
6048 }
6049 code = _PyLong_AsInt(arg);
6050 if (code == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006051 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006052 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006053 return_value = os_strerror_impl(module, code);
6054
6055exit:
6056 return return_value;
6057}
6058
6059#if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
6060
6061PyDoc_STRVAR(os_WCOREDUMP__doc__,
6062"WCOREDUMP($module, status, /)\n"
6063"--\n"
6064"\n"
6065"Return True if the process returning status was dumped to a core file.");
6066
6067#define OS_WCOREDUMP_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006068 {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006069
6070static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006071os_WCOREDUMP_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006072
6073static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006074os_WCOREDUMP(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006075{
6076 PyObject *return_value = NULL;
6077 int status;
6078 int _return_value;
6079
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006080 if (PyFloat_Check(arg)) {
6081 PyErr_SetString(PyExc_TypeError,
6082 "integer argument expected, got float" );
6083 goto exit;
6084 }
6085 status = _PyLong_AsInt(arg);
6086 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006087 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006088 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006089 _return_value = os_WCOREDUMP_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006090 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006091 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006092 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006093 return_value = PyBool_FromLong((long)_return_value);
6094
6095exit:
6096 return return_value;
6097}
6098
6099#endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
6100
6101#if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
6102
6103PyDoc_STRVAR(os_WIFCONTINUED__doc__,
6104"WIFCONTINUED($module, /, status)\n"
6105"--\n"
6106"\n"
6107"Return True if a particular process was continued from a job control stop.\n"
6108"\n"
6109"Return True if the process returning status was continued from a\n"
6110"job control stop.");
6111
6112#define OS_WIFCONTINUED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006113 {"WIFCONTINUED", (PyCFunction)(void(*)(void))os_WIFCONTINUED, METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006114
6115static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006116os_WIFCONTINUED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006117
6118static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006119os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006120{
6121 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006122 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006123 static _PyArg_Parser _parser = {NULL, _keywords, "WIFCONTINUED", 0};
6124 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006125 int status;
6126 int _return_value;
6127
Serhiy Storchaka31913912019-03-14 10:32:22 +02006128 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6129 if (!args) {
6130 goto exit;
6131 }
6132 if (PyFloat_Check(args[0])) {
6133 PyErr_SetString(PyExc_TypeError,
6134 "integer argument expected, got float" );
6135 goto exit;
6136 }
6137 status = _PyLong_AsInt(args[0]);
6138 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006139 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006140 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006141 _return_value = os_WIFCONTINUED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006142 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006143 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006144 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006145 return_value = PyBool_FromLong((long)_return_value);
6146
6147exit:
6148 return return_value;
6149}
6150
6151#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
6152
6153#if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
6154
6155PyDoc_STRVAR(os_WIFSTOPPED__doc__,
6156"WIFSTOPPED($module, /, status)\n"
6157"--\n"
6158"\n"
6159"Return True if the process returning status was stopped.");
6160
6161#define OS_WIFSTOPPED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006162 {"WIFSTOPPED", (PyCFunction)(void(*)(void))os_WIFSTOPPED, METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006163
6164static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006165os_WIFSTOPPED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006166
6167static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006168os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006169{
6170 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006171 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006172 static _PyArg_Parser _parser = {NULL, _keywords, "WIFSTOPPED", 0};
6173 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006174 int status;
6175 int _return_value;
6176
Serhiy Storchaka31913912019-03-14 10:32:22 +02006177 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6178 if (!args) {
6179 goto exit;
6180 }
6181 if (PyFloat_Check(args[0])) {
6182 PyErr_SetString(PyExc_TypeError,
6183 "integer argument expected, got float" );
6184 goto exit;
6185 }
6186 status = _PyLong_AsInt(args[0]);
6187 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006188 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006189 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006190 _return_value = os_WIFSTOPPED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006191 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006192 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006193 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006194 return_value = PyBool_FromLong((long)_return_value);
6195
6196exit:
6197 return return_value;
6198}
6199
6200#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
6201
6202#if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
6203
6204PyDoc_STRVAR(os_WIFSIGNALED__doc__,
6205"WIFSIGNALED($module, /, status)\n"
6206"--\n"
6207"\n"
6208"Return True if the process returning status was terminated by a signal.");
6209
6210#define OS_WIFSIGNALED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006211 {"WIFSIGNALED", (PyCFunction)(void(*)(void))os_WIFSIGNALED, METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006212
6213static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006214os_WIFSIGNALED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006215
6216static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006217os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006218{
6219 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006220 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006221 static _PyArg_Parser _parser = {NULL, _keywords, "WIFSIGNALED", 0};
6222 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006223 int status;
6224 int _return_value;
6225
Serhiy Storchaka31913912019-03-14 10:32:22 +02006226 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6227 if (!args) {
6228 goto exit;
6229 }
6230 if (PyFloat_Check(args[0])) {
6231 PyErr_SetString(PyExc_TypeError,
6232 "integer argument expected, got float" );
6233 goto exit;
6234 }
6235 status = _PyLong_AsInt(args[0]);
6236 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006237 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006238 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006239 _return_value = os_WIFSIGNALED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006240 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006241 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006242 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006243 return_value = PyBool_FromLong((long)_return_value);
6244
6245exit:
6246 return return_value;
6247}
6248
6249#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
6250
6251#if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
6252
6253PyDoc_STRVAR(os_WIFEXITED__doc__,
6254"WIFEXITED($module, /, status)\n"
6255"--\n"
6256"\n"
6257"Return True if the process returning status exited via the exit() system call.");
6258
6259#define OS_WIFEXITED_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006260 {"WIFEXITED", (PyCFunction)(void(*)(void))os_WIFEXITED, METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006261
6262static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006263os_WIFEXITED_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006264
6265static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006266os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006267{
6268 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006269 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006270 static _PyArg_Parser _parser = {NULL, _keywords, "WIFEXITED", 0};
6271 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006272 int status;
6273 int _return_value;
6274
Serhiy Storchaka31913912019-03-14 10:32:22 +02006275 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6276 if (!args) {
6277 goto exit;
6278 }
6279 if (PyFloat_Check(args[0])) {
6280 PyErr_SetString(PyExc_TypeError,
6281 "integer argument expected, got float" );
6282 goto exit;
6283 }
6284 status = _PyLong_AsInt(args[0]);
6285 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006286 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006287 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006288 _return_value = os_WIFEXITED_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006289 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006290 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006291 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006292 return_value = PyBool_FromLong((long)_return_value);
6293
6294exit:
6295 return return_value;
6296}
6297
6298#endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
6299
6300#if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
6301
6302PyDoc_STRVAR(os_WEXITSTATUS__doc__,
6303"WEXITSTATUS($module, /, status)\n"
6304"--\n"
6305"\n"
6306"Return the process return code from status.");
6307
6308#define OS_WEXITSTATUS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006309 {"WEXITSTATUS", (PyCFunction)(void(*)(void))os_WEXITSTATUS, METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006310
6311static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006312os_WEXITSTATUS_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006313
6314static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006315os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006316{
6317 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006318 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006319 static _PyArg_Parser _parser = {NULL, _keywords, "WEXITSTATUS", 0};
6320 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006321 int status;
6322 int _return_value;
6323
Serhiy Storchaka31913912019-03-14 10:32:22 +02006324 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6325 if (!args) {
6326 goto exit;
6327 }
6328 if (PyFloat_Check(args[0])) {
6329 PyErr_SetString(PyExc_TypeError,
6330 "integer argument expected, got float" );
6331 goto exit;
6332 }
6333 status = _PyLong_AsInt(args[0]);
6334 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006335 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006336 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006337 _return_value = os_WEXITSTATUS_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006338 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006339 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006340 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006341 return_value = PyLong_FromLong((long)_return_value);
6342
6343exit:
6344 return return_value;
6345}
6346
6347#endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
6348
6349#if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
6350
6351PyDoc_STRVAR(os_WTERMSIG__doc__,
6352"WTERMSIG($module, /, status)\n"
6353"--\n"
6354"\n"
6355"Return the signal that terminated the process that provided the status value.");
6356
6357#define OS_WTERMSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006358 {"WTERMSIG", (PyCFunction)(void(*)(void))os_WTERMSIG, METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006359
6360static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006361os_WTERMSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006362
6363static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006364os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006365{
6366 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006367 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006368 static _PyArg_Parser _parser = {NULL, _keywords, "WTERMSIG", 0};
6369 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006370 int status;
6371 int _return_value;
6372
Serhiy Storchaka31913912019-03-14 10:32:22 +02006373 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6374 if (!args) {
6375 goto exit;
6376 }
6377 if (PyFloat_Check(args[0])) {
6378 PyErr_SetString(PyExc_TypeError,
6379 "integer argument expected, got float" );
6380 goto exit;
6381 }
6382 status = _PyLong_AsInt(args[0]);
6383 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006385 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006386 _return_value = os_WTERMSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006387 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006388 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006389 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006390 return_value = PyLong_FromLong((long)_return_value);
6391
6392exit:
6393 return return_value;
6394}
6395
6396#endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
6397
6398#if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
6399
6400PyDoc_STRVAR(os_WSTOPSIG__doc__,
6401"WSTOPSIG($module, /, status)\n"
6402"--\n"
6403"\n"
6404"Return the signal that stopped the process that provided the status value.");
6405
6406#define OS_WSTOPSIG_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006407 {"WSTOPSIG", (PyCFunction)(void(*)(void))os_WSTOPSIG, METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006408
6409static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006410os_WSTOPSIG_impl(PyObject *module, int status);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006411
6412static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006413os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006414{
6415 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006416 static const char * const _keywords[] = {"status", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006417 static _PyArg_Parser _parser = {NULL, _keywords, "WSTOPSIG", 0};
6418 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006419 int status;
6420 int _return_value;
6421
Serhiy Storchaka31913912019-03-14 10:32:22 +02006422 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6423 if (!args) {
6424 goto exit;
6425 }
6426 if (PyFloat_Check(args[0])) {
6427 PyErr_SetString(PyExc_TypeError,
6428 "integer argument expected, got float" );
6429 goto exit;
6430 }
6431 status = _PyLong_AsInt(args[0]);
6432 if (status == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006435 _return_value = os_WSTOPSIG_impl(module, status);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006436 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006437 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006438 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006439 return_value = PyLong_FromLong((long)_return_value);
6440
6441exit:
6442 return return_value;
6443}
6444
6445#endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
6446
6447#if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
6448
6449PyDoc_STRVAR(os_fstatvfs__doc__,
6450"fstatvfs($module, fd, /)\n"
6451"--\n"
6452"\n"
6453"Perform an fstatvfs system call on the given fd.\n"
6454"\n"
6455"Equivalent to statvfs(fd).");
6456
6457#define OS_FSTATVFS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006458 {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006459
6460static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006461os_fstatvfs_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006462
6463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006464os_fstatvfs(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006465{
6466 PyObject *return_value = NULL;
6467 int fd;
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 Storchaka1009bf12015-04-03 23:53:51 +03006476 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006477 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006478 return_value = os_fstatvfs_impl(module, fd);
6479
6480exit:
6481 return return_value;
6482}
6483
6484#endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
6485
6486#if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
6487
6488PyDoc_STRVAR(os_statvfs__doc__,
6489"statvfs($module, /, path)\n"
6490"--\n"
6491"\n"
6492"Perform a statvfs system call on the given path.\n"
6493"\n"
6494"path may always be specified as a string.\n"
6495"On some platforms, path may also be specified as an open file descriptor.\n"
6496" If this functionality is unavailable, using it raises an exception.");
6497
6498#define OS_STATVFS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006499 {"statvfs", (PyCFunction)(void(*)(void))os_statvfs, METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006500
6501static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006502os_statvfs_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006503
6504static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006505os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006506{
6507 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006508 static const char * const _keywords[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006509 static _PyArg_Parser _parser = {NULL, _keywords, "statvfs", 0};
6510 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006511 path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
6512
Serhiy Storchaka31913912019-03-14 10:32:22 +02006513 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6514 if (!args) {
6515 goto exit;
6516 }
6517 if (!path_converter(args[0], &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006518 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006519 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006520 return_value = os_statvfs_impl(module, &path);
6521
6522exit:
6523 /* Cleanup for path */
6524 path_cleanup(&path);
6525
6526 return return_value;
6527}
6528
6529#endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
6530
6531#if defined(MS_WINDOWS)
6532
6533PyDoc_STRVAR(os__getdiskusage__doc__,
6534"_getdiskusage($module, /, path)\n"
6535"--\n"
6536"\n"
6537"Return disk usage statistics about the given path as a (total, free) tuple.");
6538
6539#define OS__GETDISKUSAGE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006540 {"_getdiskusage", (PyCFunction)(void(*)(void))os__getdiskusage, METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006541
6542static PyObject *
Steve Dower23ad6d02018-02-22 10:39:10 -08006543os__getdiskusage_impl(PyObject *module, path_t *path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006544
6545static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006546os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006547{
6548 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006549 static const char * const _keywords[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006550 static _PyArg_Parser _parser = {NULL, _keywords, "_getdiskusage", 0};
6551 PyObject *argsbuf[1];
Steve Dower23ad6d02018-02-22 10:39:10 -08006552 path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006553
Serhiy Storchaka31913912019-03-14 10:32:22 +02006554 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6555 if (!args) {
6556 goto exit;
6557 }
6558 if (!path_converter(args[0], &path)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006559 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006560 }
Steve Dower23ad6d02018-02-22 10:39:10 -08006561 return_value = os__getdiskusage_impl(module, &path);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006562
6563exit:
Steve Dower23ad6d02018-02-22 10:39:10 -08006564 /* Cleanup for path */
6565 path_cleanup(&path);
6566
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006567 return return_value;
6568}
6569
6570#endif /* defined(MS_WINDOWS) */
6571
6572#if defined(HAVE_FPATHCONF)
6573
6574PyDoc_STRVAR(os_fpathconf__doc__,
6575"fpathconf($module, fd, name, /)\n"
6576"--\n"
6577"\n"
6578"Return the configuration limit name for the file descriptor fd.\n"
6579"\n"
6580"If there is no limit, return -1.");
6581
6582#define OS_FPATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006583 {"fpathconf", (PyCFunction)(void(*)(void))os_fpathconf, METH_FASTCALL, os_fpathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006584
6585static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006586os_fpathconf_impl(PyObject *module, int fd, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006587
6588static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006589os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006590{
6591 PyObject *return_value = NULL;
6592 int fd;
6593 int name;
6594 long _return_value;
6595
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006596 if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
6597 goto exit;
6598 }
6599 if (PyFloat_Check(args[0])) {
6600 PyErr_SetString(PyExc_TypeError,
6601 "integer argument expected, got float" );
6602 goto exit;
6603 }
6604 fd = _PyLong_AsInt(args[0]);
6605 if (fd == -1 && PyErr_Occurred()) {
6606 goto exit;
6607 }
6608 if (!conv_path_confname(args[1], &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006609 goto exit;
6610 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006611 _return_value = os_fpathconf_impl(module, fd, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006612 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006613 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006614 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006615 return_value = PyLong_FromLong(_return_value);
6616
6617exit:
6618 return return_value;
6619}
6620
6621#endif /* defined(HAVE_FPATHCONF) */
6622
6623#if defined(HAVE_PATHCONF)
6624
6625PyDoc_STRVAR(os_pathconf__doc__,
6626"pathconf($module, /, path, name)\n"
6627"--\n"
6628"\n"
6629"Return the configuration limit name for the file or directory path.\n"
6630"\n"
6631"If there is no limit, return -1.\n"
6632"On some platforms, path may also be specified as an open file descriptor.\n"
6633" If this functionality is unavailable, using it raises an exception.");
6634
6635#define OS_PATHCONF_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006636 {"pathconf", (PyCFunction)(void(*)(void))os_pathconf, METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006637
6638static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006639os_pathconf_impl(PyObject *module, path_t *path, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006640
6641static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006642os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006643{
6644 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006645 static const char * const _keywords[] = {"path", "name", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006646 static _PyArg_Parser _parser = {NULL, _keywords, "pathconf", 0};
6647 PyObject *argsbuf[2];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006648 path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
6649 int name;
6650 long _return_value;
6651
Serhiy Storchaka31913912019-03-14 10:32:22 +02006652 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
6653 if (!args) {
6654 goto exit;
6655 }
6656 if (!path_converter(args[0], &path)) {
6657 goto exit;
6658 }
6659 if (!conv_path_confname(args[1], &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006660 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006661 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006662 _return_value = os_pathconf_impl(module, &path, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006663 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006664 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006665 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006666 return_value = PyLong_FromLong(_return_value);
6667
6668exit:
6669 /* Cleanup for path */
6670 path_cleanup(&path);
6671
6672 return return_value;
6673}
6674
6675#endif /* defined(HAVE_PATHCONF) */
6676
6677#if defined(HAVE_CONFSTR)
6678
6679PyDoc_STRVAR(os_confstr__doc__,
6680"confstr($module, name, /)\n"
6681"--\n"
6682"\n"
6683"Return a string-valued system configuration variable.");
6684
6685#define OS_CONFSTR_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006686 {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006687
6688static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006689os_confstr_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006690
6691static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006692os_confstr(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006693{
6694 PyObject *return_value = NULL;
6695 int name;
6696
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006697 if (!conv_confstr_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006698 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006699 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006700 return_value = os_confstr_impl(module, name);
6701
6702exit:
6703 return return_value;
6704}
6705
6706#endif /* defined(HAVE_CONFSTR) */
6707
6708#if defined(HAVE_SYSCONF)
6709
6710PyDoc_STRVAR(os_sysconf__doc__,
6711"sysconf($module, name, /)\n"
6712"--\n"
6713"\n"
6714"Return an integer-valued system configuration variable.");
6715
6716#define OS_SYSCONF_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03006717 {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006718
6719static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006720os_sysconf_impl(PyObject *module, int name);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006721
6722static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006723os_sysconf(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006724{
6725 PyObject *return_value = NULL;
6726 int name;
6727 long _return_value;
6728
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02006729 if (!conv_sysconf_confname(arg, &name)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006730 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006731 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006732 _return_value = os_sysconf_impl(module, name);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006733 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006734 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006735 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006736 return_value = PyLong_FromLong(_return_value);
6737
6738exit:
6739 return return_value;
6740}
6741
6742#endif /* defined(HAVE_SYSCONF) */
6743
6744PyDoc_STRVAR(os_abort__doc__,
6745"abort($module, /)\n"
6746"--\n"
6747"\n"
6748"Abort the interpreter immediately.\n"
6749"\n"
6750"This function \'dumps core\' or otherwise fails in the hardest way possible\n"
6751"on the hosting operating system. This function never returns.");
6752
6753#define OS_ABORT_METHODDEF \
6754 {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
6755
6756static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006757os_abort_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006758
6759static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006760os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006761{
6762 return os_abort_impl(module);
6763}
6764
Steve Dowercc16be82016-09-08 10:35:16 -07006765#if defined(MS_WINDOWS)
6766
6767PyDoc_STRVAR(os_startfile__doc__,
6768"startfile($module, /, filepath, operation=None)\n"
6769"--\n"
6770"\n"
6771"startfile(filepath [, operation])\n"
6772"\n"
6773"Start a file with its associated application.\n"
6774"\n"
6775"When \"operation\" is not specified or \"open\", this acts like\n"
6776"double-clicking the file in Explorer, or giving the file name as an\n"
6777"argument to the DOS \"start\" command: the file is opened with whatever\n"
6778"application (if any) its extension is associated.\n"
6779"When another \"operation\" is given, it specifies what should be done with\n"
6780"the file. A typical operation is \"print\".\n"
6781"\n"
6782"startfile returns as soon as the associated application is launched.\n"
6783"There is no option to wait for the application to close, and no way\n"
6784"to retrieve the application\'s exit status.\n"
6785"\n"
6786"The filepath is relative to the current directory. If you want to use\n"
6787"an absolute path, make sure the first character is not a slash (\"/\");\n"
6788"the underlying Win32 ShellExecute function doesn\'t work if it is.");
6789
6790#define OS_STARTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006791 {"startfile", (PyCFunction)(void(*)(void))os_startfile, METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
Steve Dowercc16be82016-09-08 10:35:16 -07006792
6793static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02006794os_startfile_impl(PyObject *module, path_t *filepath,
6795 const Py_UNICODE *operation);
Steve Dowercc16be82016-09-08 10:35:16 -07006796
6797static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006798os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Steve Dowercc16be82016-09-08 10:35:16 -07006799{
6800 PyObject *return_value = NULL;
Victor Stinner37e4ef72016-09-09 20:00:13 -07006801 static const char * const _keywords[] = {"filepath", "operation", NULL};
6802 static _PyArg_Parser _parser = {"O&|u:startfile", _keywords, 0};
Steve Dowercc16be82016-09-08 10:35:16 -07006803 path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02006804 const Py_UNICODE *operation = NULL;
Steve Dowercc16be82016-09-08 10:35:16 -07006805
Victor Stinner3e1fad62017-01-17 01:29:01 +01006806 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Steve Dowercc16be82016-09-08 10:35:16 -07006807 path_converter, &filepath, &operation)) {
6808 goto exit;
6809 }
6810 return_value = os_startfile_impl(module, &filepath, operation);
6811
6812exit:
6813 /* Cleanup for filepath */
6814 path_cleanup(&filepath);
6815
6816 return return_value;
6817}
6818
6819#endif /* defined(MS_WINDOWS) */
6820
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006821#if defined(HAVE_GETLOADAVG)
6822
6823PyDoc_STRVAR(os_getloadavg__doc__,
6824"getloadavg($module, /)\n"
6825"--\n"
6826"\n"
6827"Return average recent system load information.\n"
6828"\n"
6829"Return the number of processes in the system run queue averaged over\n"
6830"the last 1, 5, and 15 minutes as a tuple of three floats.\n"
6831"Raises OSError if the load average was unobtainable.");
6832
6833#define OS_GETLOADAVG_METHODDEF \
6834 {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
6835
6836static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006837os_getloadavg_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006838
6839static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006840os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006841{
6842 return os_getloadavg_impl(module);
6843}
6844
6845#endif /* defined(HAVE_GETLOADAVG) */
6846
6847PyDoc_STRVAR(os_device_encoding__doc__,
6848"device_encoding($module, /, fd)\n"
6849"--\n"
6850"\n"
6851"Return a string describing the encoding of a terminal\'s file descriptor.\n"
6852"\n"
6853"The file descriptor must be attached to a terminal.\n"
6854"If the device is not a terminal, return None.");
6855
6856#define OS_DEVICE_ENCODING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006857 {"device_encoding", (PyCFunction)(void(*)(void))os_device_encoding, METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006858
6859static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006860os_device_encoding_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006861
6862static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006863os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006864{
6865 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03006866 static const char * const _keywords[] = {"fd", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02006867 static _PyArg_Parser _parser = {NULL, _keywords, "device_encoding", 0};
6868 PyObject *argsbuf[1];
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006869 int fd;
6870
Serhiy Storchaka31913912019-03-14 10:32:22 +02006871 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
6872 if (!args) {
6873 goto exit;
6874 }
6875 if (PyFloat_Check(args[0])) {
6876 PyErr_SetString(PyExc_TypeError,
6877 "integer argument expected, got float" );
6878 goto exit;
6879 }
6880 fd = _PyLong_AsInt(args[0]);
6881 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006882 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03006883 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006884 return_value = os_device_encoding_impl(module, fd);
6885
6886exit:
6887 return return_value;
6888}
6889
6890#if defined(HAVE_SETRESUID)
6891
6892PyDoc_STRVAR(os_setresuid__doc__,
6893"setresuid($module, ruid, euid, suid, /)\n"
6894"--\n"
6895"\n"
6896"Set the current process\'s real, effective, and saved user ids.");
6897
6898#define OS_SETRESUID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006899 {"setresuid", (PyCFunction)(void(*)(void))os_setresuid, METH_FASTCALL, os_setresuid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006900
6901static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006902os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006903
6904static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006905os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006906{
6907 PyObject *return_value = NULL;
6908 uid_t ruid;
6909 uid_t euid;
6910 uid_t suid;
6911
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006912 if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
6913 goto exit;
6914 }
6915 if (!_Py_Uid_Converter(args[0], &ruid)) {
6916 goto exit;
6917 }
6918 if (!_Py_Uid_Converter(args[1], &euid)) {
6919 goto exit;
6920 }
6921 if (!_Py_Uid_Converter(args[2], &suid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006922 goto exit;
6923 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006924 return_value = os_setresuid_impl(module, ruid, euid, suid);
6925
6926exit:
6927 return return_value;
6928}
6929
6930#endif /* defined(HAVE_SETRESUID) */
6931
6932#if defined(HAVE_SETRESGID)
6933
6934PyDoc_STRVAR(os_setresgid__doc__,
6935"setresgid($module, rgid, egid, sgid, /)\n"
6936"--\n"
6937"\n"
6938"Set the current process\'s real, effective, and saved group ids.");
6939
6940#define OS_SETRESGID_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02006941 {"setresgid", (PyCFunction)(void(*)(void))os_setresgid, METH_FASTCALL, os_setresgid__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006942
6943static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006944os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006945
6946static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02006947os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006948{
6949 PyObject *return_value = NULL;
6950 gid_t rgid;
6951 gid_t egid;
6952 gid_t sgid;
6953
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02006954 if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
6955 goto exit;
6956 }
6957 if (!_Py_Gid_Converter(args[0], &rgid)) {
6958 goto exit;
6959 }
6960 if (!_Py_Gid_Converter(args[1], &egid)) {
6961 goto exit;
6962 }
6963 if (!_Py_Gid_Converter(args[2], &sgid)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01006964 goto exit;
6965 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006966 return_value = os_setresgid_impl(module, rgid, egid, sgid);
6967
6968exit:
6969 return return_value;
6970}
6971
6972#endif /* defined(HAVE_SETRESGID) */
6973
6974#if defined(HAVE_GETRESUID)
6975
6976PyDoc_STRVAR(os_getresuid__doc__,
6977"getresuid($module, /)\n"
6978"--\n"
6979"\n"
6980"Return a tuple of the current process\'s real, effective, and saved user ids.");
6981
6982#define OS_GETRESUID_METHODDEF \
6983 {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
6984
6985static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006986os_getresuid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006987
6988static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03006989os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03006990{
6991 return os_getresuid_impl(module);
6992}
6993
6994#endif /* defined(HAVE_GETRESUID) */
6995
6996#if defined(HAVE_GETRESGID)
6997
6998PyDoc_STRVAR(os_getresgid__doc__,
6999"getresgid($module, /)\n"
7000"--\n"
7001"\n"
7002"Return a tuple of the current process\'s real, effective, and saved group ids.");
7003
7004#define OS_GETRESGID_METHODDEF \
7005 {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
7006
7007static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007008os_getresgid_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007009
7010static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007011os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007012{
7013 return os_getresgid_impl(module);
7014}
7015
7016#endif /* defined(HAVE_GETRESGID) */
7017
7018#if defined(USE_XATTRS)
7019
7020PyDoc_STRVAR(os_getxattr__doc__,
7021"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
7022"--\n"
7023"\n"
7024"Return the value of extended attribute attribute on path.\n"
7025"\n"
BNMetricsb9427072018-11-02 15:20:19 +00007026"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007027"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7028" link, getxattr will examine the symbolic link itself instead of the file\n"
7029" the link points to.");
7030
7031#define OS_GETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007032 {"getxattr", (PyCFunction)(void(*)(void))os_getxattr, METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007033
7034static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007035os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04007036 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007037
7038static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007039os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007040{
7041 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03007042 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007043 static _PyArg_Parser _parser = {NULL, _keywords, "getxattr", 0};
7044 PyObject *argsbuf[3];
7045 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007046 path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
7047 path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
7048 int follow_symlinks = 1;
7049
Serhiy Storchaka31913912019-03-14 10:32:22 +02007050 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
7051 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007052 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007053 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007054 if (!path_converter(args[0], &path)) {
7055 goto exit;
7056 }
7057 if (!path_converter(args[1], &attribute)) {
7058 goto exit;
7059 }
7060 if (!noptargs) {
7061 goto skip_optional_kwonly;
7062 }
7063 follow_symlinks = PyObject_IsTrue(args[2]);
7064 if (follow_symlinks < 0) {
7065 goto exit;
7066 }
7067skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007068 return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
7069
7070exit:
7071 /* Cleanup for path */
7072 path_cleanup(&path);
7073 /* Cleanup for attribute */
7074 path_cleanup(&attribute);
7075
7076 return return_value;
7077}
7078
7079#endif /* defined(USE_XATTRS) */
7080
7081#if defined(USE_XATTRS)
7082
7083PyDoc_STRVAR(os_setxattr__doc__,
7084"setxattr($module, /, path, attribute, value, flags=0, *,\n"
7085" follow_symlinks=True)\n"
7086"--\n"
7087"\n"
7088"Set extended attribute attribute on path to value.\n"
7089"\n"
BNMetricsb9427072018-11-02 15:20:19 +00007090"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007091"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7092" link, setxattr will modify the symbolic link itself instead of the file\n"
7093" the link points to.");
7094
7095#define OS_SETXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007096 {"setxattr", (PyCFunction)(void(*)(void))os_setxattr, METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007097
7098static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007099os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04007100 Py_buffer *value, int flags, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007101
7102static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007103os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007104{
7105 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03007106 static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007107 static _PyArg_Parser _parser = {NULL, _keywords, "setxattr", 0};
7108 PyObject *argsbuf[5];
7109 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007110 path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
7111 path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
7112 Py_buffer value = {NULL, NULL};
7113 int flags = 0;
7114 int follow_symlinks = 1;
7115
Serhiy Storchaka31913912019-03-14 10:32:22 +02007116 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
7117 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007118 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007119 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007120 if (!path_converter(args[0], &path)) {
7121 goto exit;
7122 }
7123 if (!path_converter(args[1], &attribute)) {
7124 goto exit;
7125 }
7126 if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
7127 goto exit;
7128 }
7129 if (!PyBuffer_IsContiguous(&value, 'C')) {
7130 _PyArg_BadArgument("setxattr", 3, "contiguous buffer", args[2]);
7131 goto exit;
7132 }
7133 if (!noptargs) {
7134 goto skip_optional_pos;
7135 }
7136 if (args[3]) {
7137 if (PyFloat_Check(args[3])) {
7138 PyErr_SetString(PyExc_TypeError,
7139 "integer argument expected, got float" );
7140 goto exit;
7141 }
7142 flags = _PyLong_AsInt(args[3]);
7143 if (flags == -1 && PyErr_Occurred()) {
7144 goto exit;
7145 }
7146 if (!--noptargs) {
7147 goto skip_optional_pos;
7148 }
7149 }
7150skip_optional_pos:
7151 if (!noptargs) {
7152 goto skip_optional_kwonly;
7153 }
7154 follow_symlinks = PyObject_IsTrue(args[4]);
7155 if (follow_symlinks < 0) {
7156 goto exit;
7157 }
7158skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007159 return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
7160
7161exit:
7162 /* Cleanup for path */
7163 path_cleanup(&path);
7164 /* Cleanup for attribute */
7165 path_cleanup(&attribute);
7166 /* Cleanup for value */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007167 if (value.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007168 PyBuffer_Release(&value);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007169 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007170
7171 return return_value;
7172}
7173
7174#endif /* defined(USE_XATTRS) */
7175
7176#if defined(USE_XATTRS)
7177
7178PyDoc_STRVAR(os_removexattr__doc__,
7179"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
7180"--\n"
7181"\n"
7182"Remove extended attribute attribute on path.\n"
7183"\n"
BNMetricsb9427072018-11-02 15:20:19 +00007184"path may be either a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007185"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7186" link, removexattr will modify the symbolic link itself instead of the file\n"
7187" the link points to.");
7188
7189#define OS_REMOVEXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007190 {"removexattr", (PyCFunction)(void(*)(void))os_removexattr, METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007191
7192static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007193os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
Larry Hastings89964c42015-04-14 18:07:59 -04007194 int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007195
7196static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007197os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007198{
7199 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03007200 static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007201 static _PyArg_Parser _parser = {NULL, _keywords, "removexattr", 0};
7202 PyObject *argsbuf[3];
7203 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007204 path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
7205 path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
7206 int follow_symlinks = 1;
7207
Serhiy Storchaka31913912019-03-14 10:32:22 +02007208 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
7209 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007210 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007211 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007212 if (!path_converter(args[0], &path)) {
7213 goto exit;
7214 }
7215 if (!path_converter(args[1], &attribute)) {
7216 goto exit;
7217 }
7218 if (!noptargs) {
7219 goto skip_optional_kwonly;
7220 }
7221 follow_symlinks = PyObject_IsTrue(args[2]);
7222 if (follow_symlinks < 0) {
7223 goto exit;
7224 }
7225skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007226 return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
7227
7228exit:
7229 /* Cleanup for path */
7230 path_cleanup(&path);
7231 /* Cleanup for attribute */
7232 path_cleanup(&attribute);
7233
7234 return return_value;
7235}
7236
7237#endif /* defined(USE_XATTRS) */
7238
7239#if defined(USE_XATTRS)
7240
7241PyDoc_STRVAR(os_listxattr__doc__,
7242"listxattr($module, /, path=None, *, follow_symlinks=True)\n"
7243"--\n"
7244"\n"
7245"Return a list of extended attributes on path.\n"
7246"\n"
BNMetricsb9427072018-11-02 15:20:19 +00007247"path may be either None, a string, a path-like object, or an open file descriptor.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007248"if path is None, listxattr will examine the current directory.\n"
7249"If follow_symlinks is False, and the last element of the path is a symbolic\n"
7250" link, listxattr will examine the symbolic link itself instead of the file\n"
7251" the link points to.");
7252
7253#define OS_LISTXATTR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007254 {"listxattr", (PyCFunction)(void(*)(void))os_listxattr, METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007255
7256static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007257os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007258
7259static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007260os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007261{
7262 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03007263 static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007264 static _PyArg_Parser _parser = {NULL, _keywords, "listxattr", 0};
7265 PyObject *argsbuf[2];
7266 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007267 path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
7268 int follow_symlinks = 1;
7269
Serhiy Storchaka31913912019-03-14 10:32:22 +02007270 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
7271 if (!args) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007272 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007273 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007274 if (!noptargs) {
7275 goto skip_optional_pos;
7276 }
7277 if (args[0]) {
7278 if (!path_converter(args[0], &path)) {
7279 goto exit;
7280 }
7281 if (!--noptargs) {
7282 goto skip_optional_pos;
7283 }
7284 }
7285skip_optional_pos:
7286 if (!noptargs) {
7287 goto skip_optional_kwonly;
7288 }
7289 follow_symlinks = PyObject_IsTrue(args[1]);
7290 if (follow_symlinks < 0) {
7291 goto exit;
7292 }
7293skip_optional_kwonly:
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007294 return_value = os_listxattr_impl(module, &path, follow_symlinks);
7295
7296exit:
7297 /* Cleanup for path */
7298 path_cleanup(&path);
7299
7300 return return_value;
7301}
7302
7303#endif /* defined(USE_XATTRS) */
7304
7305PyDoc_STRVAR(os_urandom__doc__,
7306"urandom($module, size, /)\n"
7307"--\n"
7308"\n"
7309"Return a bytes object containing random bytes suitable for cryptographic use.");
7310
7311#define OS_URANDOM_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03007312 {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007313
7314static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007315os_urandom_impl(PyObject *module, Py_ssize_t size);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007316
7317static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007318os_urandom(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007319{
7320 PyObject *return_value = NULL;
7321 Py_ssize_t size;
7322
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02007323 if (PyFloat_Check(arg)) {
7324 PyErr_SetString(PyExc_TypeError,
7325 "integer argument expected, got float" );
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007326 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007327 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02007328 {
7329 Py_ssize_t ival = -1;
7330 PyObject *iobj = PyNumber_Index(arg);
7331 if (iobj != NULL) {
7332 ival = PyLong_AsSsize_t(iobj);
7333 Py_DECREF(iobj);
7334 }
7335 if (ival == -1 && PyErr_Occurred()) {
7336 goto exit;
7337 }
7338 size = ival;
7339 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007340 return_value = os_urandom_impl(module, size);
7341
7342exit:
7343 return return_value;
7344}
7345
7346PyDoc_STRVAR(os_cpu_count__doc__,
7347"cpu_count($module, /)\n"
7348"--\n"
7349"\n"
Charles-François Natali80d62e62015-08-13 20:37:08 +01007350"Return the number of CPUs in the system; return None if indeterminable.\n"
7351"\n"
7352"This number is not equivalent to the number of CPUs the current process can\n"
7353"use. The number of usable CPUs can be obtained with\n"
7354"``len(os.sched_getaffinity(0))``");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007355
7356#define OS_CPU_COUNT_METHODDEF \
7357 {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
7358
7359static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007360os_cpu_count_impl(PyObject *module);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007361
7362static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007363os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007364{
7365 return os_cpu_count_impl(module);
7366}
7367
7368PyDoc_STRVAR(os_get_inheritable__doc__,
7369"get_inheritable($module, fd, /)\n"
7370"--\n"
7371"\n"
7372"Get the close-on-exe flag of the specified file descriptor.");
7373
7374#define OS_GET_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03007375 {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007376
7377static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007378os_get_inheritable_impl(PyObject *module, int fd);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007379
7380static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007381os_get_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007382{
7383 PyObject *return_value = NULL;
7384 int fd;
7385 int _return_value;
7386
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02007387 if (PyFloat_Check(arg)) {
7388 PyErr_SetString(PyExc_TypeError,
7389 "integer argument expected, got float" );
7390 goto exit;
7391 }
7392 fd = _PyLong_AsInt(arg);
7393 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007394 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007395 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007396 _return_value = os_get_inheritable_impl(module, fd);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007397 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007398 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007400 return_value = PyBool_FromLong((long)_return_value);
7401
7402exit:
7403 return return_value;
7404}
7405
7406PyDoc_STRVAR(os_set_inheritable__doc__,
7407"set_inheritable($module, fd, inheritable, /)\n"
7408"--\n"
7409"\n"
7410"Set the inheritable flag of the specified file descriptor.");
7411
7412#define OS_SET_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007413 {"set_inheritable", (PyCFunction)(void(*)(void))os_set_inheritable, METH_FASTCALL, os_set_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007414
7415static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007416os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007417
7418static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007419os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007420{
7421 PyObject *return_value = NULL;
7422 int fd;
7423 int inheritable;
7424
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02007425 if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
7426 goto exit;
7427 }
7428 if (PyFloat_Check(args[0])) {
7429 PyErr_SetString(PyExc_TypeError,
7430 "integer argument expected, got float" );
7431 goto exit;
7432 }
7433 fd = _PyLong_AsInt(args[0]);
7434 if (fd == -1 && PyErr_Occurred()) {
7435 goto exit;
7436 }
7437 if (PyFloat_Check(args[1])) {
7438 PyErr_SetString(PyExc_TypeError,
7439 "integer argument expected, got float" );
7440 goto exit;
7441 }
7442 inheritable = _PyLong_AsInt(args[1]);
7443 if (inheritable == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +01007444 goto exit;
7445 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007446 return_value = os_set_inheritable_impl(module, fd, inheritable);
7447
7448exit:
7449 return return_value;
7450}
7451
7452#if defined(MS_WINDOWS)
7453
7454PyDoc_STRVAR(os_get_handle_inheritable__doc__,
7455"get_handle_inheritable($module, handle, /)\n"
7456"--\n"
7457"\n"
7458"Get the close-on-exe flag of the specified file descriptor.");
7459
7460#define OS_GET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +03007461 {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007462
7463static int
Victor Stinner581139c2016-09-06 15:54:20 -07007464os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007465
7466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03007467os_get_handle_inheritable(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007468{
7469 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07007470 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007471 int _return_value;
7472
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007473 if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007474 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007475 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007476 _return_value = os_get_handle_inheritable_impl(module, handle);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007477 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007478 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007479 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007480 return_value = PyBool_FromLong((long)_return_value);
7481
7482exit:
7483 return return_value;
7484}
7485
7486#endif /* defined(MS_WINDOWS) */
7487
7488#if defined(MS_WINDOWS)
7489
7490PyDoc_STRVAR(os_set_handle_inheritable__doc__,
7491"set_handle_inheritable($module, handle, inheritable, /)\n"
7492"--\n"
7493"\n"
7494"Set the inheritable flag of the specified handle.");
7495
7496#define OS_SET_HANDLE_INHERITABLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007497 {"set_handle_inheritable", (PyCFunction)(void(*)(void))os_set_handle_inheritable, METH_FASTCALL, os_set_handle_inheritable__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007498
7499static PyObject *
Victor Stinner581139c2016-09-06 15:54:20 -07007500os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
Larry Hastings89964c42015-04-14 18:07:59 -04007501 int inheritable);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007502
7503static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007504os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007505{
7506 PyObject *return_value = NULL;
Victor Stinner581139c2016-09-06 15:54:20 -07007507 intptr_t handle;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007508 int inheritable;
7509
Sylvain74453812017-06-10 06:51:48 +02007510 if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
7511 &handle, &inheritable)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01007512 goto exit;
7513 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03007514 return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
7515
7516exit:
7517 return return_value;
7518}
7519
7520#endif /* defined(MS_WINDOWS) */
7521
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007522#if !defined(MS_WINDOWS)
7523
7524PyDoc_STRVAR(os_get_blocking__doc__,
7525"get_blocking($module, fd, /)\n"
7526"--\n"
7527"\n"
7528"Get the blocking mode of the file descriptor.\n"
7529"\n"
7530"Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
7531
7532#define OS_GET_BLOCKING_METHODDEF \
7533 {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
7534
7535static int
7536os_get_blocking_impl(PyObject *module, int fd);
7537
7538static PyObject *
7539os_get_blocking(PyObject *module, PyObject *arg)
7540{
7541 PyObject *return_value = NULL;
7542 int fd;
7543 int _return_value;
7544
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02007545 if (PyFloat_Check(arg)) {
7546 PyErr_SetString(PyExc_TypeError,
7547 "integer argument expected, got float" );
7548 goto exit;
7549 }
7550 fd = _PyLong_AsInt(arg);
7551 if (fd == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007552 goto exit;
7553 }
7554 _return_value = os_get_blocking_impl(module, fd);
7555 if ((_return_value == -1) && PyErr_Occurred()) {
7556 goto exit;
7557 }
7558 return_value = PyBool_FromLong((long)_return_value);
7559
7560exit:
7561 return return_value;
7562}
7563
7564#endif /* !defined(MS_WINDOWS) */
7565
7566#if !defined(MS_WINDOWS)
7567
7568PyDoc_STRVAR(os_set_blocking__doc__,
7569"set_blocking($module, fd, blocking, /)\n"
7570"--\n"
7571"\n"
7572"Set the blocking mode of the specified file descriptor.\n"
7573"\n"
7574"Set the O_NONBLOCK flag if blocking is False,\n"
7575"clear the O_NONBLOCK flag otherwise.");
7576
7577#define OS_SET_BLOCKING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007578 {"set_blocking", (PyCFunction)(void(*)(void))os_set_blocking, METH_FASTCALL, os_set_blocking__doc__},
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007579
7580static PyObject *
7581os_set_blocking_impl(PyObject *module, int fd, int blocking);
7582
7583static PyObject *
7584os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7585{
7586 PyObject *return_value = NULL;
7587 int fd;
7588 int blocking;
7589
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02007590 if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
7591 goto exit;
7592 }
7593 if (PyFloat_Check(args[0])) {
7594 PyErr_SetString(PyExc_TypeError,
7595 "integer argument expected, got float" );
7596 goto exit;
7597 }
7598 fd = _PyLong_AsInt(args[0]);
7599 if (fd == -1 && PyErr_Occurred()) {
7600 goto exit;
7601 }
7602 if (PyFloat_Check(args[1])) {
7603 PyErr_SetString(PyExc_TypeError,
7604 "integer argument expected, got float" );
7605 goto exit;
7606 }
7607 blocking = _PyLong_AsInt(args[1]);
7608 if (blocking == -1 && PyErr_Occurred()) {
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03007609 goto exit;
7610 }
7611 return_value = os_set_blocking_impl(module, fd, blocking);
7612
7613exit:
7614 return return_value;
7615}
7616
7617#endif /* !defined(MS_WINDOWS) */
7618
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007619PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
7620"is_symlink($self, /)\n"
7621"--\n"
7622"\n"
7623"Return True if the entry is a symbolic link; cached per entry.");
7624
7625#define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
7626 {"is_symlink", (PyCFunction)os_DirEntry_is_symlink, METH_NOARGS, os_DirEntry_is_symlink__doc__},
7627
7628static int
7629os_DirEntry_is_symlink_impl(DirEntry *self);
7630
7631static PyObject *
7632os_DirEntry_is_symlink(DirEntry *self, PyObject *Py_UNUSED(ignored))
7633{
7634 PyObject *return_value = NULL;
7635 int _return_value;
7636
7637 _return_value = os_DirEntry_is_symlink_impl(self);
7638 if ((_return_value == -1) && PyErr_Occurred()) {
7639 goto exit;
7640 }
7641 return_value = PyBool_FromLong((long)_return_value);
7642
7643exit:
7644 return return_value;
7645}
7646
7647PyDoc_STRVAR(os_DirEntry_stat__doc__,
7648"stat($self, /, *, follow_symlinks=True)\n"
7649"--\n"
7650"\n"
7651"Return stat_result object for the entry; cached per entry.");
7652
7653#define OS_DIRENTRY_STAT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007654 {"stat", (PyCFunction)(void(*)(void))os_DirEntry_stat, METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007655
7656static PyObject *
7657os_DirEntry_stat_impl(DirEntry *self, int follow_symlinks);
7658
7659static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007660os_DirEntry_stat(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007661{
7662 PyObject *return_value = NULL;
7663 static const char * const _keywords[] = {"follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007664 static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0};
7665 PyObject *argsbuf[1];
7666 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007667 int follow_symlinks = 1;
7668
Serhiy Storchaka31913912019-03-14 10:32:22 +02007669 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
7670 if (!args) {
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007671 goto exit;
7672 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007673 if (!noptargs) {
7674 goto skip_optional_kwonly;
7675 }
7676 follow_symlinks = PyObject_IsTrue(args[0]);
7677 if (follow_symlinks < 0) {
7678 goto exit;
7679 }
7680skip_optional_kwonly:
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007681 return_value = os_DirEntry_stat_impl(self, follow_symlinks);
7682
7683exit:
7684 return return_value;
7685}
7686
7687PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
7688"is_dir($self, /, *, follow_symlinks=True)\n"
7689"--\n"
7690"\n"
7691"Return True if the entry is a directory; cached per entry.");
7692
7693#define OS_DIRENTRY_IS_DIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007694 {"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 +02007695
7696static int
7697os_DirEntry_is_dir_impl(DirEntry *self, int follow_symlinks);
7698
7699static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007700os_DirEntry_is_dir(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007701{
7702 PyObject *return_value = NULL;
7703 static const char * const _keywords[] = {"follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007704 static _PyArg_Parser _parser = {NULL, _keywords, "is_dir", 0};
7705 PyObject *argsbuf[1];
7706 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007707 int follow_symlinks = 1;
7708 int _return_value;
7709
Serhiy Storchaka31913912019-03-14 10:32:22 +02007710 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
7711 if (!args) {
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007712 goto exit;
7713 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007714 if (!noptargs) {
7715 goto skip_optional_kwonly;
7716 }
7717 follow_symlinks = PyObject_IsTrue(args[0]);
7718 if (follow_symlinks < 0) {
7719 goto exit;
7720 }
7721skip_optional_kwonly:
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007722 _return_value = os_DirEntry_is_dir_impl(self, follow_symlinks);
7723 if ((_return_value == -1) && PyErr_Occurred()) {
7724 goto exit;
7725 }
7726 return_value = PyBool_FromLong((long)_return_value);
7727
7728exit:
7729 return return_value;
7730}
7731
7732PyDoc_STRVAR(os_DirEntry_is_file__doc__,
7733"is_file($self, /, *, follow_symlinks=True)\n"
7734"--\n"
7735"\n"
7736"Return True if the entry is a file; cached per entry.");
7737
7738#define OS_DIRENTRY_IS_FILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007739 {"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 +02007740
7741static int
7742os_DirEntry_is_file_impl(DirEntry *self, int follow_symlinks);
7743
7744static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007745os_DirEntry_is_file(DirEntry *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007746{
7747 PyObject *return_value = NULL;
7748 static const char * const _keywords[] = {"follow_symlinks", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007749 static _PyArg_Parser _parser = {NULL, _keywords, "is_file", 0};
7750 PyObject *argsbuf[1];
7751 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007752 int follow_symlinks = 1;
7753 int _return_value;
7754
Serhiy Storchaka31913912019-03-14 10:32:22 +02007755 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
7756 if (!args) {
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007757 goto exit;
7758 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007759 if (!noptargs) {
7760 goto skip_optional_kwonly;
7761 }
7762 follow_symlinks = PyObject_IsTrue(args[0]);
7763 if (follow_symlinks < 0) {
7764 goto exit;
7765 }
7766skip_optional_kwonly:
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007767 _return_value = os_DirEntry_is_file_impl(self, follow_symlinks);
7768 if ((_return_value == -1) && PyErr_Occurred()) {
7769 goto exit;
7770 }
7771 return_value = PyBool_FromLong((long)_return_value);
7772
7773exit:
7774 return return_value;
7775}
7776
7777PyDoc_STRVAR(os_DirEntry_inode__doc__,
7778"inode($self, /)\n"
7779"--\n"
7780"\n"
7781"Return inode of the entry; cached per entry.");
7782
7783#define OS_DIRENTRY_INODE_METHODDEF \
7784 {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
7785
7786static PyObject *
7787os_DirEntry_inode_impl(DirEntry *self);
7788
7789static PyObject *
7790os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
7791{
7792 return os_DirEntry_inode_impl(self);
7793}
7794
7795PyDoc_STRVAR(os_DirEntry___fspath____doc__,
7796"__fspath__($self, /)\n"
7797"--\n"
7798"\n"
7799"Returns the path for the entry.");
7800
7801#define OS_DIRENTRY___FSPATH___METHODDEF \
7802 {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
7803
7804static PyObject *
7805os_DirEntry___fspath___impl(DirEntry *self);
7806
7807static PyObject *
7808os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
7809{
7810 return os_DirEntry___fspath___impl(self);
7811}
7812
7813PyDoc_STRVAR(os_scandir__doc__,
7814"scandir($module, /, path=None)\n"
7815"--\n"
7816"\n"
7817"Return an iterator of DirEntry objects for given path.\n"
7818"\n"
BNMetricsb9427072018-11-02 15:20:19 +00007819"path can be specified as either str, bytes, or a path-like object. If path\n"
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007820"is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
7821"all other circumstances they will be str.\n"
7822"\n"
7823"If path is None, uses the path=\'.\'.");
7824
7825#define OS_SCANDIR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007826 {"scandir", (PyCFunction)(void(*)(void))os_scandir, METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007827
7828static PyObject *
7829os_scandir_impl(PyObject *module, path_t *path);
7830
7831static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007832os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007833{
7834 PyObject *return_value = NULL;
7835 static const char * const _keywords[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007836 static _PyArg_Parser _parser = {NULL, _keywords, "scandir", 0};
7837 PyObject *argsbuf[1];
7838 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchakaea720fe2017-03-30 09:12:31 +03007839 path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007840
Serhiy Storchaka31913912019-03-14 10:32:22 +02007841 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
7842 if (!args) {
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007843 goto exit;
7844 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007845 if (!noptargs) {
7846 goto skip_optional_pos;
7847 }
7848 if (!path_converter(args[0], &path)) {
7849 goto exit;
7850 }
7851skip_optional_pos:
Serhiy Storchaka49d02d12016-11-06 13:45:33 +02007852 return_value = os_scandir_impl(module, &path);
7853
7854exit:
7855 /* Cleanup for path */
7856 path_cleanup(&path);
7857
7858 return return_value;
7859}
7860
Ethan Furman410ef8e2016-06-04 12:06:26 -07007861PyDoc_STRVAR(os_fspath__doc__,
7862"fspath($module, /, path)\n"
7863"--\n"
7864"\n"
7865"Return the file system path representation of the object.\n"
7866"\n"
Brett Cannonb4f43e92016-06-09 14:32:08 -07007867"If the object is str or bytes, then allow it to pass through as-is. If the\n"
7868"object defines __fspath__(), then return the result of that method. All other\n"
7869"types raise a TypeError.");
Ethan Furman410ef8e2016-06-04 12:06:26 -07007870
7871#define OS_FSPATH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007872 {"fspath", (PyCFunction)(void(*)(void))os_fspath, METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
Ethan Furman410ef8e2016-06-04 12:06:26 -07007873
7874static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +03007875os_fspath_impl(PyObject *module, PyObject *path);
Ethan Furman410ef8e2016-06-04 12:06:26 -07007876
7877static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007878os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Ethan Furman410ef8e2016-06-04 12:06:26 -07007879{
7880 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03007881 static const char * const _keywords[] = {"path", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007882 static _PyArg_Parser _parser = {NULL, _keywords, "fspath", 0};
7883 PyObject *argsbuf[1];
Ethan Furman410ef8e2016-06-04 12:06:26 -07007884 PyObject *path;
7885
Serhiy Storchaka31913912019-03-14 10:32:22 +02007886 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
7887 if (!args) {
Ethan Furman410ef8e2016-06-04 12:06:26 -07007888 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03007889 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007890 path = args[0];
Ethan Furman410ef8e2016-06-04 12:06:26 -07007891 return_value = os_fspath_impl(module, path);
7892
7893exit:
7894 return return_value;
7895}
7896
Victor Stinner9b1f4742016-09-06 16:18:52 -07007897#if defined(HAVE_GETRANDOM_SYSCALL)
7898
7899PyDoc_STRVAR(os_getrandom__doc__,
7900"getrandom($module, /, size, flags=0)\n"
7901"--\n"
7902"\n"
7903"Obtain a series of random bytes.");
7904
7905#define OS_GETRANDOM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02007906 {"getrandom", (PyCFunction)(void(*)(void))os_getrandom, METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
Victor Stinner9b1f4742016-09-06 16:18:52 -07007907
7908static PyObject *
7909os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
7910
7911static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02007912os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinner9b1f4742016-09-06 16:18:52 -07007913{
7914 PyObject *return_value = NULL;
7915 static const char * const _keywords[] = {"size", "flags", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02007916 static _PyArg_Parser _parser = {NULL, _keywords, "getrandom", 0};
7917 PyObject *argsbuf[2];
7918 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Victor Stinner9b1f4742016-09-06 16:18:52 -07007919 Py_ssize_t size;
7920 int flags = 0;
7921
Serhiy Storchaka31913912019-03-14 10:32:22 +02007922 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
7923 if (!args) {
Victor Stinner9b1f4742016-09-06 16:18:52 -07007924 goto exit;
7925 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02007926 if (PyFloat_Check(args[0])) {
7927 PyErr_SetString(PyExc_TypeError,
7928 "integer argument expected, got float" );
7929 goto exit;
7930 }
7931 {
7932 Py_ssize_t ival = -1;
7933 PyObject *iobj = PyNumber_Index(args[0]);
7934 if (iobj != NULL) {
7935 ival = PyLong_AsSsize_t(iobj);
7936 Py_DECREF(iobj);
7937 }
7938 if (ival == -1 && PyErr_Occurred()) {
7939 goto exit;
7940 }
7941 size = ival;
7942 }
7943 if (!noptargs) {
7944 goto skip_optional_pos;
7945 }
7946 if (PyFloat_Check(args[1])) {
7947 PyErr_SetString(PyExc_TypeError,
7948 "integer argument expected, got float" );
7949 goto exit;
7950 }
7951 flags = _PyLong_AsInt(args[1]);
7952 if (flags == -1 && PyErr_Occurred()) {
7953 goto exit;
7954 }
7955skip_optional_pos:
Victor Stinner9b1f4742016-09-06 16:18:52 -07007956 return_value = os_getrandom_impl(module, size, flags);
7957
7958exit:
7959 return return_value;
7960}
7961
7962#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
7963
Steve Dower2438cdf2019-03-29 16:37:16 -07007964#if defined(MS_WINDOWS)
7965
7966PyDoc_STRVAR(os__add_dll_directory__doc__,
7967"_add_dll_directory($module, /, path)\n"
7968"--\n"
7969"\n"
7970"Add a path to the DLL search path.\n"
7971"\n"
7972"This search path is used when resolving dependencies for imported\n"
7973"extension modules (the module itself is resolved through sys.path),\n"
7974"and also by ctypes.\n"
7975"\n"
7976"Returns an opaque value that may be passed to os.remove_dll_directory\n"
7977"to remove this directory from the search path.");
7978
7979#define OS__ADD_DLL_DIRECTORY_METHODDEF \
7980 {"_add_dll_directory", (PyCFunction)(void(*)(void))os__add_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
7981
7982static PyObject *
7983os__add_dll_directory_impl(PyObject *module, path_t *path);
7984
7985static PyObject *
7986os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7987{
7988 PyObject *return_value = NULL;
7989 static const char * const _keywords[] = {"path", NULL};
7990 static _PyArg_Parser _parser = {NULL, _keywords, "_add_dll_directory", 0};
7991 PyObject *argsbuf[1];
7992 path_t path = PATH_T_INITIALIZE("_add_dll_directory", "path", 0, 0);
7993
7994 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
7995 if (!args) {
7996 goto exit;
7997 }
7998 if (!path_converter(args[0], &path)) {
7999 goto exit;
8000 }
8001 return_value = os__add_dll_directory_impl(module, &path);
8002
8003exit:
8004 /* Cleanup for path */
8005 path_cleanup(&path);
8006
8007 return return_value;
8008}
8009
8010#endif /* defined(MS_WINDOWS) */
8011
8012#if defined(MS_WINDOWS)
8013
8014PyDoc_STRVAR(os__remove_dll_directory__doc__,
8015"_remove_dll_directory($module, /, cookie)\n"
8016"--\n"
8017"\n"
8018"Removes a path from the DLL search path.\n"
8019"\n"
8020"The parameter is an opaque value that was returned from\n"
8021"os.add_dll_directory. You can only remove directories that you added\n"
8022"yourself.");
8023
8024#define OS__REMOVE_DLL_DIRECTORY_METHODDEF \
8025 {"_remove_dll_directory", (PyCFunction)(void(*)(void))os__remove_dll_directory, METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
8026
8027static PyObject *
8028os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
8029
8030static PyObject *
8031os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8032{
8033 PyObject *return_value = NULL;
8034 static const char * const _keywords[] = {"cookie", NULL};
8035 static _PyArg_Parser _parser = {NULL, _keywords, "_remove_dll_directory", 0};
8036 PyObject *argsbuf[1];
8037 PyObject *cookie;
8038
8039 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
8040 if (!args) {
8041 goto exit;
8042 }
8043 cookie = args[0];
8044 return_value = os__remove_dll_directory_impl(module, cookie);
8045
8046exit:
8047 return return_value;
8048}
8049
8050#endif /* defined(MS_WINDOWS) */
8051
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008052#ifndef OS_TTYNAME_METHODDEF
8053 #define OS_TTYNAME_METHODDEF
8054#endif /* !defined(OS_TTYNAME_METHODDEF) */
8055
8056#ifndef OS_CTERMID_METHODDEF
8057 #define OS_CTERMID_METHODDEF
8058#endif /* !defined(OS_CTERMID_METHODDEF) */
8059
8060#ifndef OS_FCHDIR_METHODDEF
8061 #define OS_FCHDIR_METHODDEF
8062#endif /* !defined(OS_FCHDIR_METHODDEF) */
8063
8064#ifndef OS_FCHMOD_METHODDEF
8065 #define OS_FCHMOD_METHODDEF
8066#endif /* !defined(OS_FCHMOD_METHODDEF) */
8067
8068#ifndef OS_LCHMOD_METHODDEF
8069 #define OS_LCHMOD_METHODDEF
8070#endif /* !defined(OS_LCHMOD_METHODDEF) */
8071
8072#ifndef OS_CHFLAGS_METHODDEF
8073 #define OS_CHFLAGS_METHODDEF
8074#endif /* !defined(OS_CHFLAGS_METHODDEF) */
8075
8076#ifndef OS_LCHFLAGS_METHODDEF
8077 #define OS_LCHFLAGS_METHODDEF
8078#endif /* !defined(OS_LCHFLAGS_METHODDEF) */
8079
8080#ifndef OS_CHROOT_METHODDEF
8081 #define OS_CHROOT_METHODDEF
8082#endif /* !defined(OS_CHROOT_METHODDEF) */
8083
8084#ifndef OS_FSYNC_METHODDEF
8085 #define OS_FSYNC_METHODDEF
8086#endif /* !defined(OS_FSYNC_METHODDEF) */
8087
8088#ifndef OS_SYNC_METHODDEF
8089 #define OS_SYNC_METHODDEF
8090#endif /* !defined(OS_SYNC_METHODDEF) */
8091
8092#ifndef OS_FDATASYNC_METHODDEF
8093 #define OS_FDATASYNC_METHODDEF
8094#endif /* !defined(OS_FDATASYNC_METHODDEF) */
8095
8096#ifndef OS_CHOWN_METHODDEF
8097 #define OS_CHOWN_METHODDEF
8098#endif /* !defined(OS_CHOWN_METHODDEF) */
8099
8100#ifndef OS_FCHOWN_METHODDEF
8101 #define OS_FCHOWN_METHODDEF
8102#endif /* !defined(OS_FCHOWN_METHODDEF) */
8103
8104#ifndef OS_LCHOWN_METHODDEF
8105 #define OS_LCHOWN_METHODDEF
8106#endif /* !defined(OS_LCHOWN_METHODDEF) */
8107
8108#ifndef OS_LINK_METHODDEF
8109 #define OS_LINK_METHODDEF
8110#endif /* !defined(OS_LINK_METHODDEF) */
8111
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03008112#ifndef OS__GETFULLPATHNAME_METHODDEF
8113 #define OS__GETFULLPATHNAME_METHODDEF
8114#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
8115
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008116#ifndef OS__GETFINALPATHNAME_METHODDEF
8117 #define OS__GETFINALPATHNAME_METHODDEF
8118#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
8119
Serhiy Storchakaf0b50152015-05-13 00:52:39 +03008120#ifndef OS__ISDIR_METHODDEF
8121 #define OS__ISDIR_METHODDEF
8122#endif /* !defined(OS__ISDIR_METHODDEF) */
8123
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008124#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
8125 #define OS__GETVOLUMEPATHNAME_METHODDEF
8126#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
8127
8128#ifndef OS_NICE_METHODDEF
8129 #define OS_NICE_METHODDEF
8130#endif /* !defined(OS_NICE_METHODDEF) */
8131
8132#ifndef OS_GETPRIORITY_METHODDEF
8133 #define OS_GETPRIORITY_METHODDEF
8134#endif /* !defined(OS_GETPRIORITY_METHODDEF) */
8135
8136#ifndef OS_SETPRIORITY_METHODDEF
8137 #define OS_SETPRIORITY_METHODDEF
8138#endif /* !defined(OS_SETPRIORITY_METHODDEF) */
8139
8140#ifndef OS_SYSTEM_METHODDEF
8141 #define OS_SYSTEM_METHODDEF
8142#endif /* !defined(OS_SYSTEM_METHODDEF) */
8143
8144#ifndef OS_UNAME_METHODDEF
8145 #define OS_UNAME_METHODDEF
8146#endif /* !defined(OS_UNAME_METHODDEF) */
8147
8148#ifndef OS_EXECV_METHODDEF
8149 #define OS_EXECV_METHODDEF
8150#endif /* !defined(OS_EXECV_METHODDEF) */
8151
8152#ifndef OS_EXECVE_METHODDEF
8153 #define OS_EXECVE_METHODDEF
8154#endif /* !defined(OS_EXECVE_METHODDEF) */
8155
Pablo Galindo6c6ddf92018-01-29 01:56:10 +00008156#ifndef OS_POSIX_SPAWN_METHODDEF
8157 #define OS_POSIX_SPAWN_METHODDEF
8158#endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
8159
Joannah Nanjekye92b83222019-01-16 16:29:26 +03008160#ifndef OS_POSIX_SPAWNP_METHODDEF
8161 #define OS_POSIX_SPAWNP_METHODDEF
8162#endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
8163
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008164#ifndef OS_SPAWNV_METHODDEF
8165 #define OS_SPAWNV_METHODDEF
8166#endif /* !defined(OS_SPAWNV_METHODDEF) */
8167
8168#ifndef OS_SPAWNVE_METHODDEF
8169 #define OS_SPAWNVE_METHODDEF
8170#endif /* !defined(OS_SPAWNVE_METHODDEF) */
8171
Antoine Pitrou346cbd32017-05-27 17:50:54 +02008172#ifndef OS_REGISTER_AT_FORK_METHODDEF
8173 #define OS_REGISTER_AT_FORK_METHODDEF
8174#endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
8175
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008176#ifndef OS_FORK1_METHODDEF
8177 #define OS_FORK1_METHODDEF
8178#endif /* !defined(OS_FORK1_METHODDEF) */
8179
8180#ifndef OS_FORK_METHODDEF
8181 #define OS_FORK_METHODDEF
8182#endif /* !defined(OS_FORK_METHODDEF) */
8183
8184#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
8185 #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
8186#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
8187
8188#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
8189 #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
8190#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
8191
8192#ifndef OS_SCHED_GETSCHEDULER_METHODDEF
8193 #define OS_SCHED_GETSCHEDULER_METHODDEF
8194#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
8195
8196#ifndef OS_SCHED_SETSCHEDULER_METHODDEF
8197 #define OS_SCHED_SETSCHEDULER_METHODDEF
8198#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
8199
8200#ifndef OS_SCHED_GETPARAM_METHODDEF
8201 #define OS_SCHED_GETPARAM_METHODDEF
8202#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
8203
8204#ifndef OS_SCHED_SETPARAM_METHODDEF
8205 #define OS_SCHED_SETPARAM_METHODDEF
8206#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
8207
8208#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
8209 #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
8210#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
8211
8212#ifndef OS_SCHED_YIELD_METHODDEF
8213 #define OS_SCHED_YIELD_METHODDEF
8214#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
8215
8216#ifndef OS_SCHED_SETAFFINITY_METHODDEF
8217 #define OS_SCHED_SETAFFINITY_METHODDEF
8218#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
8219
8220#ifndef OS_SCHED_GETAFFINITY_METHODDEF
8221 #define OS_SCHED_GETAFFINITY_METHODDEF
8222#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
8223
8224#ifndef OS_OPENPTY_METHODDEF
8225 #define OS_OPENPTY_METHODDEF
8226#endif /* !defined(OS_OPENPTY_METHODDEF) */
8227
8228#ifndef OS_FORKPTY_METHODDEF
8229 #define OS_FORKPTY_METHODDEF
8230#endif /* !defined(OS_FORKPTY_METHODDEF) */
8231
8232#ifndef OS_GETEGID_METHODDEF
8233 #define OS_GETEGID_METHODDEF
8234#endif /* !defined(OS_GETEGID_METHODDEF) */
8235
8236#ifndef OS_GETEUID_METHODDEF
8237 #define OS_GETEUID_METHODDEF
8238#endif /* !defined(OS_GETEUID_METHODDEF) */
8239
8240#ifndef OS_GETGID_METHODDEF
8241 #define OS_GETGID_METHODDEF
8242#endif /* !defined(OS_GETGID_METHODDEF) */
8243
Berker Peksag39404992016-09-15 20:45:16 +03008244#ifndef OS_GETPID_METHODDEF
8245 #define OS_GETPID_METHODDEF
8246#endif /* !defined(OS_GETPID_METHODDEF) */
8247
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008248#ifndef OS_GETGROUPS_METHODDEF
8249 #define OS_GETGROUPS_METHODDEF
8250#endif /* !defined(OS_GETGROUPS_METHODDEF) */
8251
8252#ifndef OS_GETPGID_METHODDEF
8253 #define OS_GETPGID_METHODDEF
8254#endif /* !defined(OS_GETPGID_METHODDEF) */
8255
8256#ifndef OS_GETPGRP_METHODDEF
8257 #define OS_GETPGRP_METHODDEF
8258#endif /* !defined(OS_GETPGRP_METHODDEF) */
8259
8260#ifndef OS_SETPGRP_METHODDEF
8261 #define OS_SETPGRP_METHODDEF
8262#endif /* !defined(OS_SETPGRP_METHODDEF) */
8263
8264#ifndef OS_GETPPID_METHODDEF
8265 #define OS_GETPPID_METHODDEF
8266#endif /* !defined(OS_GETPPID_METHODDEF) */
8267
8268#ifndef OS_GETLOGIN_METHODDEF
8269 #define OS_GETLOGIN_METHODDEF
8270#endif /* !defined(OS_GETLOGIN_METHODDEF) */
8271
8272#ifndef OS_GETUID_METHODDEF
8273 #define OS_GETUID_METHODDEF
8274#endif /* !defined(OS_GETUID_METHODDEF) */
8275
8276#ifndef OS_KILL_METHODDEF
8277 #define OS_KILL_METHODDEF
8278#endif /* !defined(OS_KILL_METHODDEF) */
8279
8280#ifndef OS_KILLPG_METHODDEF
8281 #define OS_KILLPG_METHODDEF
8282#endif /* !defined(OS_KILLPG_METHODDEF) */
8283
8284#ifndef OS_PLOCK_METHODDEF
8285 #define OS_PLOCK_METHODDEF
8286#endif /* !defined(OS_PLOCK_METHODDEF) */
8287
8288#ifndef OS_SETUID_METHODDEF
8289 #define OS_SETUID_METHODDEF
8290#endif /* !defined(OS_SETUID_METHODDEF) */
8291
8292#ifndef OS_SETEUID_METHODDEF
8293 #define OS_SETEUID_METHODDEF
8294#endif /* !defined(OS_SETEUID_METHODDEF) */
8295
8296#ifndef OS_SETEGID_METHODDEF
8297 #define OS_SETEGID_METHODDEF
8298#endif /* !defined(OS_SETEGID_METHODDEF) */
8299
8300#ifndef OS_SETREUID_METHODDEF
8301 #define OS_SETREUID_METHODDEF
8302#endif /* !defined(OS_SETREUID_METHODDEF) */
8303
8304#ifndef OS_SETREGID_METHODDEF
8305 #define OS_SETREGID_METHODDEF
8306#endif /* !defined(OS_SETREGID_METHODDEF) */
8307
8308#ifndef OS_SETGID_METHODDEF
8309 #define OS_SETGID_METHODDEF
8310#endif /* !defined(OS_SETGID_METHODDEF) */
8311
8312#ifndef OS_SETGROUPS_METHODDEF
8313 #define OS_SETGROUPS_METHODDEF
8314#endif /* !defined(OS_SETGROUPS_METHODDEF) */
8315
8316#ifndef OS_WAIT3_METHODDEF
8317 #define OS_WAIT3_METHODDEF
8318#endif /* !defined(OS_WAIT3_METHODDEF) */
8319
8320#ifndef OS_WAIT4_METHODDEF
8321 #define OS_WAIT4_METHODDEF
8322#endif /* !defined(OS_WAIT4_METHODDEF) */
8323
8324#ifndef OS_WAITID_METHODDEF
8325 #define OS_WAITID_METHODDEF
8326#endif /* !defined(OS_WAITID_METHODDEF) */
8327
8328#ifndef OS_WAITPID_METHODDEF
8329 #define OS_WAITPID_METHODDEF
8330#endif /* !defined(OS_WAITPID_METHODDEF) */
8331
8332#ifndef OS_WAIT_METHODDEF
8333 #define OS_WAIT_METHODDEF
8334#endif /* !defined(OS_WAIT_METHODDEF) */
8335
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03008336#ifndef OS_READLINK_METHODDEF
8337 #define OS_READLINK_METHODDEF
8338#endif /* !defined(OS_READLINK_METHODDEF) */
8339
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008340#ifndef OS_SYMLINK_METHODDEF
8341 #define OS_SYMLINK_METHODDEF
8342#endif /* !defined(OS_SYMLINK_METHODDEF) */
8343
8344#ifndef OS_TIMES_METHODDEF
8345 #define OS_TIMES_METHODDEF
8346#endif /* !defined(OS_TIMES_METHODDEF) */
8347
8348#ifndef OS_GETSID_METHODDEF
8349 #define OS_GETSID_METHODDEF
8350#endif /* !defined(OS_GETSID_METHODDEF) */
8351
8352#ifndef OS_SETSID_METHODDEF
8353 #define OS_SETSID_METHODDEF
8354#endif /* !defined(OS_SETSID_METHODDEF) */
8355
8356#ifndef OS_SETPGID_METHODDEF
8357 #define OS_SETPGID_METHODDEF
8358#endif /* !defined(OS_SETPGID_METHODDEF) */
8359
8360#ifndef OS_TCGETPGRP_METHODDEF
8361 #define OS_TCGETPGRP_METHODDEF
8362#endif /* !defined(OS_TCGETPGRP_METHODDEF) */
8363
8364#ifndef OS_TCSETPGRP_METHODDEF
8365 #define OS_TCSETPGRP_METHODDEF
8366#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
8367
8368#ifndef OS_LOCKF_METHODDEF
8369 #define OS_LOCKF_METHODDEF
8370#endif /* !defined(OS_LOCKF_METHODDEF) */
8371
8372#ifndef OS_READV_METHODDEF
8373 #define OS_READV_METHODDEF
8374#endif /* !defined(OS_READV_METHODDEF) */
8375
8376#ifndef OS_PREAD_METHODDEF
8377 #define OS_PREAD_METHODDEF
8378#endif /* !defined(OS_PREAD_METHODDEF) */
8379
Pablo Galindo4defba32018-01-27 16:16:37 +00008380#ifndef OS_PREADV_METHODDEF
8381 #define OS_PREADV_METHODDEF
8382#endif /* !defined(OS_PREADV_METHODDEF) */
8383
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +02008384#ifndef OS__FCOPYFILE_METHODDEF
8385 #define OS__FCOPYFILE_METHODDEF
8386#endif /* !defined(OS__FCOPYFILE_METHODDEF) */
8387
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008388#ifndef OS_PIPE_METHODDEF
8389 #define OS_PIPE_METHODDEF
8390#endif /* !defined(OS_PIPE_METHODDEF) */
8391
8392#ifndef OS_PIPE2_METHODDEF
8393 #define OS_PIPE2_METHODDEF
8394#endif /* !defined(OS_PIPE2_METHODDEF) */
8395
8396#ifndef OS_WRITEV_METHODDEF
8397 #define OS_WRITEV_METHODDEF
8398#endif /* !defined(OS_WRITEV_METHODDEF) */
8399
8400#ifndef OS_PWRITE_METHODDEF
8401 #define OS_PWRITE_METHODDEF
8402#endif /* !defined(OS_PWRITE_METHODDEF) */
8403
Pablo Galindo4defba32018-01-27 16:16:37 +00008404#ifndef OS_PWRITEV_METHODDEF
8405 #define OS_PWRITEV_METHODDEF
8406#endif /* !defined(OS_PWRITEV_METHODDEF) */
8407
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008408#ifndef OS_MKFIFO_METHODDEF
8409 #define OS_MKFIFO_METHODDEF
8410#endif /* !defined(OS_MKFIFO_METHODDEF) */
8411
8412#ifndef OS_MKNOD_METHODDEF
8413 #define OS_MKNOD_METHODDEF
8414#endif /* !defined(OS_MKNOD_METHODDEF) */
8415
8416#ifndef OS_MAJOR_METHODDEF
8417 #define OS_MAJOR_METHODDEF
8418#endif /* !defined(OS_MAJOR_METHODDEF) */
8419
8420#ifndef OS_MINOR_METHODDEF
8421 #define OS_MINOR_METHODDEF
8422#endif /* !defined(OS_MINOR_METHODDEF) */
8423
8424#ifndef OS_MAKEDEV_METHODDEF
8425 #define OS_MAKEDEV_METHODDEF
8426#endif /* !defined(OS_MAKEDEV_METHODDEF) */
8427
8428#ifndef OS_FTRUNCATE_METHODDEF
8429 #define OS_FTRUNCATE_METHODDEF
8430#endif /* !defined(OS_FTRUNCATE_METHODDEF) */
8431
8432#ifndef OS_TRUNCATE_METHODDEF
8433 #define OS_TRUNCATE_METHODDEF
8434#endif /* !defined(OS_TRUNCATE_METHODDEF) */
8435
8436#ifndef OS_POSIX_FALLOCATE_METHODDEF
8437 #define OS_POSIX_FALLOCATE_METHODDEF
8438#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
8439
8440#ifndef OS_POSIX_FADVISE_METHODDEF
8441 #define OS_POSIX_FADVISE_METHODDEF
8442#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
8443
8444#ifndef OS_PUTENV_METHODDEF
8445 #define OS_PUTENV_METHODDEF
8446#endif /* !defined(OS_PUTENV_METHODDEF) */
8447
8448#ifndef OS_UNSETENV_METHODDEF
8449 #define OS_UNSETENV_METHODDEF
8450#endif /* !defined(OS_UNSETENV_METHODDEF) */
8451
8452#ifndef OS_WCOREDUMP_METHODDEF
8453 #define OS_WCOREDUMP_METHODDEF
8454#endif /* !defined(OS_WCOREDUMP_METHODDEF) */
8455
8456#ifndef OS_WIFCONTINUED_METHODDEF
8457 #define OS_WIFCONTINUED_METHODDEF
8458#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
8459
8460#ifndef OS_WIFSTOPPED_METHODDEF
8461 #define OS_WIFSTOPPED_METHODDEF
8462#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
8463
8464#ifndef OS_WIFSIGNALED_METHODDEF
8465 #define OS_WIFSIGNALED_METHODDEF
8466#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
8467
8468#ifndef OS_WIFEXITED_METHODDEF
8469 #define OS_WIFEXITED_METHODDEF
8470#endif /* !defined(OS_WIFEXITED_METHODDEF) */
8471
8472#ifndef OS_WEXITSTATUS_METHODDEF
8473 #define OS_WEXITSTATUS_METHODDEF
8474#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
8475
8476#ifndef OS_WTERMSIG_METHODDEF
8477 #define OS_WTERMSIG_METHODDEF
8478#endif /* !defined(OS_WTERMSIG_METHODDEF) */
8479
8480#ifndef OS_WSTOPSIG_METHODDEF
8481 #define OS_WSTOPSIG_METHODDEF
8482#endif /* !defined(OS_WSTOPSIG_METHODDEF) */
8483
8484#ifndef OS_FSTATVFS_METHODDEF
8485 #define OS_FSTATVFS_METHODDEF
8486#endif /* !defined(OS_FSTATVFS_METHODDEF) */
8487
8488#ifndef OS_STATVFS_METHODDEF
8489 #define OS_STATVFS_METHODDEF
8490#endif /* !defined(OS_STATVFS_METHODDEF) */
8491
8492#ifndef OS__GETDISKUSAGE_METHODDEF
8493 #define OS__GETDISKUSAGE_METHODDEF
8494#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
8495
8496#ifndef OS_FPATHCONF_METHODDEF
8497 #define OS_FPATHCONF_METHODDEF
8498#endif /* !defined(OS_FPATHCONF_METHODDEF) */
8499
8500#ifndef OS_PATHCONF_METHODDEF
8501 #define OS_PATHCONF_METHODDEF
8502#endif /* !defined(OS_PATHCONF_METHODDEF) */
8503
8504#ifndef OS_CONFSTR_METHODDEF
8505 #define OS_CONFSTR_METHODDEF
8506#endif /* !defined(OS_CONFSTR_METHODDEF) */
8507
8508#ifndef OS_SYSCONF_METHODDEF
8509 #define OS_SYSCONF_METHODDEF
8510#endif /* !defined(OS_SYSCONF_METHODDEF) */
8511
Steve Dowercc16be82016-09-08 10:35:16 -07008512#ifndef OS_STARTFILE_METHODDEF
8513 #define OS_STARTFILE_METHODDEF
8514#endif /* !defined(OS_STARTFILE_METHODDEF) */
8515
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03008516#ifndef OS_GETLOADAVG_METHODDEF
8517 #define OS_GETLOADAVG_METHODDEF
8518#endif /* !defined(OS_GETLOADAVG_METHODDEF) */
8519
8520#ifndef OS_SETRESUID_METHODDEF
8521 #define OS_SETRESUID_METHODDEF
8522#endif /* !defined(OS_SETRESUID_METHODDEF) */
8523
8524#ifndef OS_SETRESGID_METHODDEF
8525 #define OS_SETRESGID_METHODDEF
8526#endif /* !defined(OS_SETRESGID_METHODDEF) */
8527
8528#ifndef OS_GETRESUID_METHODDEF
8529 #define OS_GETRESUID_METHODDEF
8530#endif /* !defined(OS_GETRESUID_METHODDEF) */
8531
8532#ifndef OS_GETRESGID_METHODDEF
8533 #define OS_GETRESGID_METHODDEF
8534#endif /* !defined(OS_GETRESGID_METHODDEF) */
8535
8536#ifndef OS_GETXATTR_METHODDEF
8537 #define OS_GETXATTR_METHODDEF
8538#endif /* !defined(OS_GETXATTR_METHODDEF) */
8539
8540#ifndef OS_SETXATTR_METHODDEF
8541 #define OS_SETXATTR_METHODDEF
8542#endif /* !defined(OS_SETXATTR_METHODDEF) */
8543
8544#ifndef OS_REMOVEXATTR_METHODDEF
8545 #define OS_REMOVEXATTR_METHODDEF
8546#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
8547
8548#ifndef OS_LISTXATTR_METHODDEF
8549 #define OS_LISTXATTR_METHODDEF
8550#endif /* !defined(OS_LISTXATTR_METHODDEF) */
8551
8552#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
8553 #define OS_GET_HANDLE_INHERITABLE_METHODDEF
8554#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
8555
8556#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
8557 #define OS_SET_HANDLE_INHERITABLE_METHODDEF
8558#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
Victor Stinner9b1f4742016-09-06 16:18:52 -07008559
Serhiy Storchaka12a69db2018-09-17 15:38:27 +03008560#ifndef OS_GET_BLOCKING_METHODDEF
8561 #define OS_GET_BLOCKING_METHODDEF
8562#endif /* !defined(OS_GET_BLOCKING_METHODDEF) */
8563
8564#ifndef OS_SET_BLOCKING_METHODDEF
8565 #define OS_SET_BLOCKING_METHODDEF
8566#endif /* !defined(OS_SET_BLOCKING_METHODDEF) */
8567
Victor Stinner9b1f4742016-09-06 16:18:52 -07008568#ifndef OS_GETRANDOM_METHODDEF
8569 #define OS_GETRANDOM_METHODDEF
8570#endif /* !defined(OS_GETRANDOM_METHODDEF) */
Steve Dower2438cdf2019-03-29 16:37:16 -07008571
8572#ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
8573 #define OS__ADD_DLL_DIRECTORY_METHODDEF
8574#endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
8575
8576#ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
8577 #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
8578#endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
8579/*[clinic end generated code: output=ab36ec0376a422ae input=a9049054013a1b77]*/