Branch data Line data Source code
1 : : /*[clinic input]
2 : : preserve
3 : : [clinic start generated code]*/
4 : :
5 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 : : # include "pycore_gc.h" // PyGC_Head
7 : : # include "pycore_runtime.h" // _Py_ID()
8 : : #endif
9 : :
10 : :
11 : : PyDoc_STRVAR(os_stat__doc__,
12 : : "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
13 : : "--\n"
14 : : "\n"
15 : : "Perform a stat system call on the given path.\n"
16 : : "\n"
17 : : " path\n"
18 : : " Path to be examined; can be string, bytes, a path-like object or\n"
19 : : " open-file-descriptor int.\n"
20 : : " dir_fd\n"
21 : : " If not None, it should be a file descriptor open to a directory,\n"
22 : : " and path should be a relative string; path will then be relative to\n"
23 : : " that directory.\n"
24 : : " follow_symlinks\n"
25 : : " If False, and the last element of the path is a symbolic link,\n"
26 : : " stat will examine the symbolic link itself instead of the file\n"
27 : : " the link points to.\n"
28 : : "\n"
29 : : "dir_fd and follow_symlinks may not be implemented\n"
30 : : " on your platform. If they are unavailable, using them will raise a\n"
31 : : " NotImplementedError.\n"
32 : : "\n"
33 : : "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
34 : : " an open file descriptor.");
35 : :
36 : : #define OS_STAT_METHODDEF \
37 : : {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
38 : :
39 : : static PyObject *
40 : : os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
41 : :
42 : : static PyObject *
43 : 3121 : os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
44 : : {
45 : 3121 : PyObject *return_value = NULL;
46 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
47 : :
48 : : #define NUM_KEYWORDS 3
49 : : static struct {
50 : : PyGC_Head _this_is_not_used;
51 : : PyObject_VAR_HEAD
52 : : PyObject *ob_item[NUM_KEYWORDS];
53 : : } _kwtuple = {
54 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
55 : : .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
56 : : };
57 : : #undef NUM_KEYWORDS
58 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
59 : :
60 : : #else // !Py_BUILD_CORE
61 : : # define KWTUPLE NULL
62 : : #endif // !Py_BUILD_CORE
63 : :
64 : : static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
65 : : static _PyArg_Parser _parser = {
66 : : .keywords = _keywords,
67 : : .fname = "stat",
68 : : .kwtuple = KWTUPLE,
69 : : };
70 : : #undef KWTUPLE
71 : : PyObject *argsbuf[3];
72 [ - + ]: 3121 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
73 : 3121 : path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
74 : 3121 : int dir_fd = DEFAULT_DIR_FD;
75 : 3121 : int follow_symlinks = 1;
76 : :
77 [ + - + - : 3121 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
78 [ - + ]: 3121 : if (!args) {
79 : 0 : goto exit;
80 : : }
81 [ - + ]: 3121 : if (!path_converter(args[0], &path)) {
82 : 0 : goto exit;
83 : : }
84 [ + - ]: 3121 : if (!noptargs) {
85 : 3121 : goto skip_optional_kwonly;
86 : : }
87 [ # # ]: 0 : if (args[1]) {
88 [ # # ]: 0 : if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
89 : 0 : goto exit;
90 : : }
91 [ # # ]: 0 : if (!--noptargs) {
92 : 0 : goto skip_optional_kwonly;
93 : : }
94 : : }
95 : 0 : follow_symlinks = PyObject_IsTrue(args[2]);
96 [ # # ]: 0 : if (follow_symlinks < 0) {
97 : 0 : goto exit;
98 : : }
99 : 0 : skip_optional_kwonly:
100 : 3121 : return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
101 : :
102 : 3121 : exit:
103 : : /* Cleanup for path */
104 : 3121 : path_cleanup(&path);
105 : :
106 : 3121 : return return_value;
107 : : }
108 : :
109 : : PyDoc_STRVAR(os_lstat__doc__,
110 : : "lstat($module, /, path, *, dir_fd=None)\n"
111 : : "--\n"
112 : : "\n"
113 : : "Perform a stat system call on the given path, without following symbolic links.\n"
114 : : "\n"
115 : : "Like stat(), but do not follow symbolic links.\n"
116 : : "Equivalent to stat(path, follow_symlinks=False).");
117 : :
118 : : #define OS_LSTAT_METHODDEF \
119 : : {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
120 : :
121 : : static PyObject *
122 : : os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
123 : :
124 : : static PyObject *
125 : 83 : os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
126 : : {
127 : 83 : PyObject *return_value = NULL;
128 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
129 : :
130 : : #define NUM_KEYWORDS 2
131 : : static struct {
132 : : PyGC_Head _this_is_not_used;
133 : : PyObject_VAR_HEAD
134 : : PyObject *ob_item[NUM_KEYWORDS];
135 : : } _kwtuple = {
136 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
137 : : .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
138 : : };
139 : : #undef NUM_KEYWORDS
140 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
141 : :
142 : : #else // !Py_BUILD_CORE
143 : : # define KWTUPLE NULL
144 : : #endif // !Py_BUILD_CORE
145 : :
146 : : static const char * const _keywords[] = {"path", "dir_fd", NULL};
147 : : static _PyArg_Parser _parser = {
148 : : .keywords = _keywords,
149 : : .fname = "lstat",
150 : : .kwtuple = KWTUPLE,
151 : : };
152 : : #undef KWTUPLE
153 : : PyObject *argsbuf[2];
154 [ + + ]: 83 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
155 : 83 : path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
156 : 83 : int dir_fd = DEFAULT_DIR_FD;
157 : :
158 [ + + + - : 83 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
159 [ - + ]: 83 : if (!args) {
160 : 0 : goto exit;
161 : : }
162 [ - + ]: 83 : if (!path_converter(args[0], &path)) {
163 : 0 : goto exit;
164 : : }
165 [ + + ]: 83 : if (!noptargs) {
166 : 82 : goto skip_optional_kwonly;
167 : : }
168 [ - + ]: 1 : if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
169 : 0 : goto exit;
170 : : }
171 : 1 : skip_optional_kwonly:
172 : 83 : return_value = os_lstat_impl(module, &path, dir_fd);
173 : :
174 : 83 : exit:
175 : : /* Cleanup for path */
176 : 83 : path_cleanup(&path);
177 : :
178 : 83 : return return_value;
179 : : }
180 : :
181 : : PyDoc_STRVAR(os_access__doc__,
182 : : "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
183 : : " follow_symlinks=True)\n"
184 : : "--\n"
185 : : "\n"
186 : : "Use the real uid/gid to test for access to a path.\n"
187 : : "\n"
188 : : " path\n"
189 : : " Path to be tested; can be string, bytes, or a path-like object.\n"
190 : : " mode\n"
191 : : " Operating-system mode bitfield. Can be F_OK to test existence,\n"
192 : : " or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
193 : : " dir_fd\n"
194 : : " If not None, it should be a file descriptor open to a directory,\n"
195 : : " and path should be relative; path will then be relative to that\n"
196 : : " directory.\n"
197 : : " effective_ids\n"
198 : : " If True, access will use the effective uid/gid instead of\n"
199 : : " the real uid/gid.\n"
200 : : " follow_symlinks\n"
201 : : " If False, and the last element of the path is a symbolic link,\n"
202 : : " access will examine the symbolic link itself instead of the file\n"
203 : : " the link points to.\n"
204 : : "\n"
205 : : "dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
206 : : " on your platform. If they are unavailable, using them will raise a\n"
207 : : " NotImplementedError.\n"
208 : : "\n"
209 : : "Note that most operations will use the effective uid/gid, therefore this\n"
210 : : " routine can be used in a suid/sgid environment to test if the invoking user\n"
211 : : " has the specified access to the path.");
212 : :
213 : : #define OS_ACCESS_METHODDEF \
214 : : {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
215 : :
216 : : static int
217 : : os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
218 : : int effective_ids, int follow_symlinks);
219 : :
220 : : static PyObject *
221 : 0 : os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
222 : : {
223 : 0 : PyObject *return_value = NULL;
224 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
225 : :
226 : : #define NUM_KEYWORDS 5
227 : : static struct {
228 : : PyGC_Head _this_is_not_used;
229 : : PyObject_VAR_HEAD
230 : : PyObject *ob_item[NUM_KEYWORDS];
231 : : } _kwtuple = {
232 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
233 : : .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), },
234 : : };
235 : : #undef NUM_KEYWORDS
236 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
237 : :
238 : : #else // !Py_BUILD_CORE
239 : : # define KWTUPLE NULL
240 : : #endif // !Py_BUILD_CORE
241 : :
242 : : static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
243 : : static _PyArg_Parser _parser = {
244 : : .keywords = _keywords,
245 : : .fname = "access",
246 : : .kwtuple = KWTUPLE,
247 : : };
248 : : #undef KWTUPLE
249 : : PyObject *argsbuf[5];
250 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
251 : 0 : path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
252 : : int mode;
253 : 0 : int dir_fd = DEFAULT_DIR_FD;
254 : 0 : int effective_ids = 0;
255 : 0 : int follow_symlinks = 1;
256 : : int _return_value;
257 : :
258 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
259 [ # # ]: 0 : if (!args) {
260 : 0 : goto exit;
261 : : }
262 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
263 : 0 : goto exit;
264 : : }
265 : 0 : mode = _PyLong_AsInt(args[1]);
266 [ # # # # ]: 0 : if (mode == -1 && PyErr_Occurred()) {
267 : 0 : goto exit;
268 : : }
269 [ # # ]: 0 : if (!noptargs) {
270 : 0 : goto skip_optional_kwonly;
271 : : }
272 [ # # ]: 0 : if (args[2]) {
273 [ # # ]: 0 : if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
274 : 0 : goto exit;
275 : : }
276 [ # # ]: 0 : if (!--noptargs) {
277 : 0 : goto skip_optional_kwonly;
278 : : }
279 : : }
280 [ # # ]: 0 : if (args[3]) {
281 : 0 : effective_ids = PyObject_IsTrue(args[3]);
282 [ # # ]: 0 : if (effective_ids < 0) {
283 : 0 : goto exit;
284 : : }
285 [ # # ]: 0 : if (!--noptargs) {
286 : 0 : goto skip_optional_kwonly;
287 : : }
288 : : }
289 : 0 : follow_symlinks = PyObject_IsTrue(args[4]);
290 [ # # ]: 0 : if (follow_symlinks < 0) {
291 : 0 : goto exit;
292 : : }
293 : 0 : skip_optional_kwonly:
294 : 0 : _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
295 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
296 : 0 : goto exit;
297 : : }
298 : 0 : return_value = PyBool_FromLong((long)_return_value);
299 : :
300 : 0 : exit:
301 : : /* Cleanup for path */
302 : 0 : path_cleanup(&path);
303 : :
304 : 0 : return return_value;
305 : : }
306 : :
307 : : #if defined(HAVE_TTYNAME)
308 : :
309 : : PyDoc_STRVAR(os_ttyname__doc__,
310 : : "ttyname($module, fd, /)\n"
311 : : "--\n"
312 : : "\n"
313 : : "Return the name of the terminal device connected to \'fd\'.\n"
314 : : "\n"
315 : : " fd\n"
316 : : " Integer file descriptor handle.");
317 : :
318 : : #define OS_TTYNAME_METHODDEF \
319 : : {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
320 : :
321 : : static PyObject *
322 : : os_ttyname_impl(PyObject *module, int fd);
323 : :
324 : : static PyObject *
325 : 0 : os_ttyname(PyObject *module, PyObject *arg)
326 : : {
327 : 0 : PyObject *return_value = NULL;
328 : : int fd;
329 : :
330 : 0 : fd = _PyLong_AsInt(arg);
331 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
332 : 0 : goto exit;
333 : : }
334 : 0 : return_value = os_ttyname_impl(module, fd);
335 : :
336 : 0 : exit:
337 : 0 : return return_value;
338 : : }
339 : :
340 : : #endif /* defined(HAVE_TTYNAME) */
341 : :
342 : : #if defined(HAVE_CTERMID)
343 : :
344 : : PyDoc_STRVAR(os_ctermid__doc__,
345 : : "ctermid($module, /)\n"
346 : : "--\n"
347 : : "\n"
348 : : "Return the name of the controlling terminal for this process.");
349 : :
350 : : #define OS_CTERMID_METHODDEF \
351 : : {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
352 : :
353 : : static PyObject *
354 : : os_ctermid_impl(PyObject *module);
355 : :
356 : : static PyObject *
357 : 0 : os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
358 : : {
359 : 0 : return os_ctermid_impl(module);
360 : : }
361 : :
362 : : #endif /* defined(HAVE_CTERMID) */
363 : :
364 : : PyDoc_STRVAR(os_chdir__doc__,
365 : : "chdir($module, /, path)\n"
366 : : "--\n"
367 : : "\n"
368 : : "Change the current working directory to the specified path.\n"
369 : : "\n"
370 : : "path may always be specified as a string.\n"
371 : : "On some platforms, path may also be specified as an open file descriptor.\n"
372 : : " If this functionality is unavailable, using it raises an exception.");
373 : :
374 : : #define OS_CHDIR_METHODDEF \
375 : : {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
376 : :
377 : : static PyObject *
378 : : os_chdir_impl(PyObject *module, path_t *path);
379 : :
380 : : static PyObject *
381 : 2 : os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
382 : : {
383 : 2 : PyObject *return_value = NULL;
384 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
385 : :
386 : : #define NUM_KEYWORDS 1
387 : : static struct {
388 : : PyGC_Head _this_is_not_used;
389 : : PyObject_VAR_HEAD
390 : : PyObject *ob_item[NUM_KEYWORDS];
391 : : } _kwtuple = {
392 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
393 : : .ob_item = { &_Py_ID(path), },
394 : : };
395 : : #undef NUM_KEYWORDS
396 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
397 : :
398 : : #else // !Py_BUILD_CORE
399 : : # define KWTUPLE NULL
400 : : #endif // !Py_BUILD_CORE
401 : :
402 : : static const char * const _keywords[] = {"path", NULL};
403 : : static _PyArg_Parser _parser = {
404 : : .keywords = _keywords,
405 : : .fname = "chdir",
406 : : .kwtuple = KWTUPLE,
407 : : };
408 : : #undef KWTUPLE
409 : : PyObject *argsbuf[1];
410 : 2 : path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
411 : :
412 [ + - + - : 2 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
413 [ - + ]: 2 : if (!args) {
414 : 0 : goto exit;
415 : : }
416 [ - + ]: 2 : if (!path_converter(args[0], &path)) {
417 : 0 : goto exit;
418 : : }
419 : 2 : return_value = os_chdir_impl(module, &path);
420 : :
421 : 2 : exit:
422 : : /* Cleanup for path */
423 : 2 : path_cleanup(&path);
424 : :
425 : 2 : return return_value;
426 : : }
427 : :
428 : : #if defined(HAVE_FCHDIR)
429 : :
430 : : PyDoc_STRVAR(os_fchdir__doc__,
431 : : "fchdir($module, /, fd)\n"
432 : : "--\n"
433 : : "\n"
434 : : "Change to the directory of the given file descriptor.\n"
435 : : "\n"
436 : : "fd must be opened on a directory, not a file.\n"
437 : : "Equivalent to os.chdir(fd).");
438 : :
439 : : #define OS_FCHDIR_METHODDEF \
440 : : {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
441 : :
442 : : static PyObject *
443 : : os_fchdir_impl(PyObject *module, int fd);
444 : :
445 : : static PyObject *
446 : 0 : os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
447 : : {
448 : 0 : PyObject *return_value = NULL;
449 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
450 : :
451 : : #define NUM_KEYWORDS 1
452 : : static struct {
453 : : PyGC_Head _this_is_not_used;
454 : : PyObject_VAR_HEAD
455 : : PyObject *ob_item[NUM_KEYWORDS];
456 : : } _kwtuple = {
457 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
458 : : .ob_item = { &_Py_ID(fd), },
459 : : };
460 : : #undef NUM_KEYWORDS
461 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
462 : :
463 : : #else // !Py_BUILD_CORE
464 : : # define KWTUPLE NULL
465 : : #endif // !Py_BUILD_CORE
466 : :
467 : : static const char * const _keywords[] = {"fd", NULL};
468 : : static _PyArg_Parser _parser = {
469 : : .keywords = _keywords,
470 : : .fname = "fchdir",
471 : : .kwtuple = KWTUPLE,
472 : : };
473 : : #undef KWTUPLE
474 : : PyObject *argsbuf[1];
475 : : int fd;
476 : :
477 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
478 [ # # ]: 0 : if (!args) {
479 : 0 : goto exit;
480 : : }
481 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
482 : 0 : goto exit;
483 : : }
484 : 0 : return_value = os_fchdir_impl(module, fd);
485 : :
486 : 0 : exit:
487 : 0 : return return_value;
488 : : }
489 : :
490 : : #endif /* defined(HAVE_FCHDIR) */
491 : :
492 : : PyDoc_STRVAR(os_chmod__doc__,
493 : : "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
494 : : "--\n"
495 : : "\n"
496 : : "Change the access permissions of a file.\n"
497 : : "\n"
498 : : " path\n"
499 : : " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n"
500 : : " On some platforms, path may also be specified as an open file descriptor.\n"
501 : : " If this functionality is unavailable, using it raises an exception.\n"
502 : : " mode\n"
503 : : " Operating-system mode bitfield.\n"
504 : : " Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
505 : : " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
506 : : " Python.\n"
507 : : " dir_fd\n"
508 : : " If not None, it should be a file descriptor open to a directory,\n"
509 : : " and path should be relative; path will then be relative to that\n"
510 : : " directory.\n"
511 : : " follow_symlinks\n"
512 : : " If False, and the last element of the path is a symbolic link,\n"
513 : : " chmod will modify the symbolic link itself instead of the file\n"
514 : : " the link points to.\n"
515 : : "\n"
516 : : "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
517 : : " an open file descriptor.\n"
518 : : "dir_fd and follow_symlinks may not be implemented on your platform.\n"
519 : : " If they are unavailable, using them will raise a NotImplementedError.");
520 : :
521 : : #define OS_CHMOD_METHODDEF \
522 : : {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
523 : :
524 : : static PyObject *
525 : : os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
526 : : int follow_symlinks);
527 : :
528 : : static PyObject *
529 : 0 : os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
530 : : {
531 : 0 : PyObject *return_value = NULL;
532 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
533 : :
534 : : #define NUM_KEYWORDS 4
535 : : static struct {
536 : : PyGC_Head _this_is_not_used;
537 : : PyObject_VAR_HEAD
538 : : PyObject *ob_item[NUM_KEYWORDS];
539 : : } _kwtuple = {
540 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
541 : : .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
542 : : };
543 : : #undef NUM_KEYWORDS
544 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
545 : :
546 : : #else // !Py_BUILD_CORE
547 : : # define KWTUPLE NULL
548 : : #endif // !Py_BUILD_CORE
549 : :
550 : : static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
551 : : static _PyArg_Parser _parser = {
552 : : .keywords = _keywords,
553 : : .fname = "chmod",
554 : : .kwtuple = KWTUPLE,
555 : : };
556 : : #undef KWTUPLE
557 : : PyObject *argsbuf[4];
558 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
559 : 0 : path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
560 : : int mode;
561 : 0 : int dir_fd = DEFAULT_DIR_FD;
562 : 0 : int follow_symlinks = 1;
563 : :
564 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
565 [ # # ]: 0 : if (!args) {
566 : 0 : goto exit;
567 : : }
568 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
569 : 0 : goto exit;
570 : : }
571 : 0 : mode = _PyLong_AsInt(args[1]);
572 [ # # # # ]: 0 : if (mode == -1 && PyErr_Occurred()) {
573 : 0 : goto exit;
574 : : }
575 [ # # ]: 0 : if (!noptargs) {
576 : 0 : goto skip_optional_kwonly;
577 : : }
578 [ # # ]: 0 : if (args[2]) {
579 [ # # ]: 0 : if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
580 : 0 : goto exit;
581 : : }
582 [ # # ]: 0 : if (!--noptargs) {
583 : 0 : goto skip_optional_kwonly;
584 : : }
585 : : }
586 : 0 : follow_symlinks = PyObject_IsTrue(args[3]);
587 [ # # ]: 0 : if (follow_symlinks < 0) {
588 : 0 : goto exit;
589 : : }
590 : 0 : skip_optional_kwonly:
591 : 0 : return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
592 : :
593 : 0 : exit:
594 : : /* Cleanup for path */
595 : 0 : path_cleanup(&path);
596 : :
597 : 0 : return return_value;
598 : : }
599 : :
600 : : #if defined(HAVE_FCHMOD)
601 : :
602 : : PyDoc_STRVAR(os_fchmod__doc__,
603 : : "fchmod($module, /, fd, mode)\n"
604 : : "--\n"
605 : : "\n"
606 : : "Change the access permissions of the file given by file descriptor fd.\n"
607 : : "\n"
608 : : " fd\n"
609 : : " The file descriptor of the file to be modified.\n"
610 : : " mode\n"
611 : : " Operating-system mode bitfield.\n"
612 : : " Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
613 : : " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
614 : : " Python.\n"
615 : : "\n"
616 : : "Equivalent to os.chmod(fd, mode).");
617 : :
618 : : #define OS_FCHMOD_METHODDEF \
619 : : {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
620 : :
621 : : static PyObject *
622 : : os_fchmod_impl(PyObject *module, int fd, int mode);
623 : :
624 : : static PyObject *
625 : 0 : os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
626 : : {
627 : 0 : PyObject *return_value = NULL;
628 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
629 : :
630 : : #define NUM_KEYWORDS 2
631 : : static struct {
632 : : PyGC_Head _this_is_not_used;
633 : : PyObject_VAR_HEAD
634 : : PyObject *ob_item[NUM_KEYWORDS];
635 : : } _kwtuple = {
636 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
637 : : .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
638 : : };
639 : : #undef NUM_KEYWORDS
640 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
641 : :
642 : : #else // !Py_BUILD_CORE
643 : : # define KWTUPLE NULL
644 : : #endif // !Py_BUILD_CORE
645 : :
646 : : static const char * const _keywords[] = {"fd", "mode", NULL};
647 : : static _PyArg_Parser _parser = {
648 : : .keywords = _keywords,
649 : : .fname = "fchmod",
650 : : .kwtuple = KWTUPLE,
651 : : };
652 : : #undef KWTUPLE
653 : : PyObject *argsbuf[2];
654 : : int fd;
655 : : int mode;
656 : :
657 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
658 [ # # ]: 0 : if (!args) {
659 : 0 : goto exit;
660 : : }
661 : 0 : fd = _PyLong_AsInt(args[0]);
662 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
663 : 0 : goto exit;
664 : : }
665 : 0 : mode = _PyLong_AsInt(args[1]);
666 [ # # # # ]: 0 : if (mode == -1 && PyErr_Occurred()) {
667 : 0 : goto exit;
668 : : }
669 : 0 : return_value = os_fchmod_impl(module, fd, mode);
670 : :
671 : 0 : exit:
672 : 0 : return return_value;
673 : : }
674 : :
675 : : #endif /* defined(HAVE_FCHMOD) */
676 : :
677 : : #if defined(HAVE_LCHMOD)
678 : :
679 : : PyDoc_STRVAR(os_lchmod__doc__,
680 : : "lchmod($module, /, path, mode)\n"
681 : : "--\n"
682 : : "\n"
683 : : "Change the access permissions of a file, without following symbolic links.\n"
684 : : "\n"
685 : : "If path is a symlink, this affects the link itself rather than the target.\n"
686 : : "Equivalent to chmod(path, mode, follow_symlinks=False).\"");
687 : :
688 : : #define OS_LCHMOD_METHODDEF \
689 : : {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
690 : :
691 : : static PyObject *
692 : : os_lchmod_impl(PyObject *module, path_t *path, int mode);
693 : :
694 : : static PyObject *
695 : : os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
696 : : {
697 : : PyObject *return_value = NULL;
698 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
699 : :
700 : : #define NUM_KEYWORDS 2
701 : : static struct {
702 : : PyGC_Head _this_is_not_used;
703 : : PyObject_VAR_HEAD
704 : : PyObject *ob_item[NUM_KEYWORDS];
705 : : } _kwtuple = {
706 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
707 : : .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
708 : : };
709 : : #undef NUM_KEYWORDS
710 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
711 : :
712 : : #else // !Py_BUILD_CORE
713 : : # define KWTUPLE NULL
714 : : #endif // !Py_BUILD_CORE
715 : :
716 : : static const char * const _keywords[] = {"path", "mode", NULL};
717 : : static _PyArg_Parser _parser = {
718 : : .keywords = _keywords,
719 : : .fname = "lchmod",
720 : : .kwtuple = KWTUPLE,
721 : : };
722 : : #undef KWTUPLE
723 : : PyObject *argsbuf[2];
724 : : path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
725 : : int mode;
726 : :
727 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
728 : : if (!args) {
729 : : goto exit;
730 : : }
731 : : if (!path_converter(args[0], &path)) {
732 : : goto exit;
733 : : }
734 : : mode = _PyLong_AsInt(args[1]);
735 : : if (mode == -1 && PyErr_Occurred()) {
736 : : goto exit;
737 : : }
738 : : return_value = os_lchmod_impl(module, &path, mode);
739 : :
740 : : exit:
741 : : /* Cleanup for path */
742 : : path_cleanup(&path);
743 : :
744 : : return return_value;
745 : : }
746 : :
747 : : #endif /* defined(HAVE_LCHMOD) */
748 : :
749 : : #if defined(HAVE_CHFLAGS)
750 : :
751 : : PyDoc_STRVAR(os_chflags__doc__,
752 : : "chflags($module, /, path, flags, follow_symlinks=True)\n"
753 : : "--\n"
754 : : "\n"
755 : : "Set file flags.\n"
756 : : "\n"
757 : : "If follow_symlinks is False, and the last element of the path is a symbolic\n"
758 : : " link, chflags will change flags on the symbolic link itself instead of the\n"
759 : : " file the link points to.\n"
760 : : "follow_symlinks may not be implemented on your platform. If it is\n"
761 : : "unavailable, using it will raise a NotImplementedError.");
762 : :
763 : : #define OS_CHFLAGS_METHODDEF \
764 : : {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
765 : :
766 : : static PyObject *
767 : : os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
768 : : int follow_symlinks);
769 : :
770 : : static PyObject *
771 : : os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
772 : : {
773 : : PyObject *return_value = NULL;
774 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
775 : :
776 : : #define NUM_KEYWORDS 3
777 : : static struct {
778 : : PyGC_Head _this_is_not_used;
779 : : PyObject_VAR_HEAD
780 : : PyObject *ob_item[NUM_KEYWORDS];
781 : : } _kwtuple = {
782 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
783 : : .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
784 : : };
785 : : #undef NUM_KEYWORDS
786 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
787 : :
788 : : #else // !Py_BUILD_CORE
789 : : # define KWTUPLE NULL
790 : : #endif // !Py_BUILD_CORE
791 : :
792 : : static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
793 : : static _PyArg_Parser _parser = {
794 : : .keywords = _keywords,
795 : : .fname = "chflags",
796 : : .kwtuple = KWTUPLE,
797 : : };
798 : : #undef KWTUPLE
799 : : PyObject *argsbuf[3];
800 : : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
801 : : path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
802 : : unsigned long flags;
803 : : int follow_symlinks = 1;
804 : :
805 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
806 : : if (!args) {
807 : : goto exit;
808 : : }
809 : : if (!path_converter(args[0], &path)) {
810 : : goto exit;
811 : : }
812 : : if (!PyLong_Check(args[1])) {
813 : : _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
814 : : goto exit;
815 : : }
816 : : flags = PyLong_AsUnsignedLongMask(args[1]);
817 : : if (!noptargs) {
818 : : goto skip_optional_pos;
819 : : }
820 : : follow_symlinks = PyObject_IsTrue(args[2]);
821 : : if (follow_symlinks < 0) {
822 : : goto exit;
823 : : }
824 : : skip_optional_pos:
825 : : return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
826 : :
827 : : exit:
828 : : /* Cleanup for path */
829 : : path_cleanup(&path);
830 : :
831 : : return return_value;
832 : : }
833 : :
834 : : #endif /* defined(HAVE_CHFLAGS) */
835 : :
836 : : #if defined(HAVE_LCHFLAGS)
837 : :
838 : : PyDoc_STRVAR(os_lchflags__doc__,
839 : : "lchflags($module, /, path, flags)\n"
840 : : "--\n"
841 : : "\n"
842 : : "Set file flags.\n"
843 : : "\n"
844 : : "This function will not follow symbolic links.\n"
845 : : "Equivalent to chflags(path, flags, follow_symlinks=False).");
846 : :
847 : : #define OS_LCHFLAGS_METHODDEF \
848 : : {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
849 : :
850 : : static PyObject *
851 : : os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
852 : :
853 : : static PyObject *
854 : : os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
855 : : {
856 : : PyObject *return_value = NULL;
857 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
858 : :
859 : : #define NUM_KEYWORDS 2
860 : : static struct {
861 : : PyGC_Head _this_is_not_used;
862 : : PyObject_VAR_HEAD
863 : : PyObject *ob_item[NUM_KEYWORDS];
864 : : } _kwtuple = {
865 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
866 : : .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
867 : : };
868 : : #undef NUM_KEYWORDS
869 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
870 : :
871 : : #else // !Py_BUILD_CORE
872 : : # define KWTUPLE NULL
873 : : #endif // !Py_BUILD_CORE
874 : :
875 : : static const char * const _keywords[] = {"path", "flags", NULL};
876 : : static _PyArg_Parser _parser = {
877 : : .keywords = _keywords,
878 : : .fname = "lchflags",
879 : : .kwtuple = KWTUPLE,
880 : : };
881 : : #undef KWTUPLE
882 : : PyObject *argsbuf[2];
883 : : path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
884 : : unsigned long flags;
885 : :
886 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
887 : : if (!args) {
888 : : goto exit;
889 : : }
890 : : if (!path_converter(args[0], &path)) {
891 : : goto exit;
892 : : }
893 : : if (!PyLong_Check(args[1])) {
894 : : _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
895 : : goto exit;
896 : : }
897 : : flags = PyLong_AsUnsignedLongMask(args[1]);
898 : : return_value = os_lchflags_impl(module, &path, flags);
899 : :
900 : : exit:
901 : : /* Cleanup for path */
902 : : path_cleanup(&path);
903 : :
904 : : return return_value;
905 : : }
906 : :
907 : : #endif /* defined(HAVE_LCHFLAGS) */
908 : :
909 : : #if defined(HAVE_CHROOT)
910 : :
911 : : PyDoc_STRVAR(os_chroot__doc__,
912 : : "chroot($module, /, path)\n"
913 : : "--\n"
914 : : "\n"
915 : : "Change root directory to path.");
916 : :
917 : : #define OS_CHROOT_METHODDEF \
918 : : {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
919 : :
920 : : static PyObject *
921 : : os_chroot_impl(PyObject *module, path_t *path);
922 : :
923 : : static PyObject *
924 : 0 : os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
925 : : {
926 : 0 : PyObject *return_value = NULL;
927 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
928 : :
929 : : #define NUM_KEYWORDS 1
930 : : static struct {
931 : : PyGC_Head _this_is_not_used;
932 : : PyObject_VAR_HEAD
933 : : PyObject *ob_item[NUM_KEYWORDS];
934 : : } _kwtuple = {
935 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
936 : : .ob_item = { &_Py_ID(path), },
937 : : };
938 : : #undef NUM_KEYWORDS
939 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
940 : :
941 : : #else // !Py_BUILD_CORE
942 : : # define KWTUPLE NULL
943 : : #endif // !Py_BUILD_CORE
944 : :
945 : : static const char * const _keywords[] = {"path", NULL};
946 : : static _PyArg_Parser _parser = {
947 : : .keywords = _keywords,
948 : : .fname = "chroot",
949 : : .kwtuple = KWTUPLE,
950 : : };
951 : : #undef KWTUPLE
952 : : PyObject *argsbuf[1];
953 : 0 : path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
954 : :
955 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
956 [ # # ]: 0 : if (!args) {
957 : 0 : goto exit;
958 : : }
959 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
960 : 0 : goto exit;
961 : : }
962 : 0 : return_value = os_chroot_impl(module, &path);
963 : :
964 : 0 : exit:
965 : : /* Cleanup for path */
966 : 0 : path_cleanup(&path);
967 : :
968 : 0 : return return_value;
969 : : }
970 : :
971 : : #endif /* defined(HAVE_CHROOT) */
972 : :
973 : : #if defined(HAVE_FSYNC)
974 : :
975 : : PyDoc_STRVAR(os_fsync__doc__,
976 : : "fsync($module, /, fd)\n"
977 : : "--\n"
978 : : "\n"
979 : : "Force write of fd to disk.");
980 : :
981 : : #define OS_FSYNC_METHODDEF \
982 : : {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
983 : :
984 : : static PyObject *
985 : : os_fsync_impl(PyObject *module, int fd);
986 : :
987 : : static PyObject *
988 : 0 : os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
989 : : {
990 : 0 : PyObject *return_value = NULL;
991 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
992 : :
993 : : #define NUM_KEYWORDS 1
994 : : static struct {
995 : : PyGC_Head _this_is_not_used;
996 : : PyObject_VAR_HEAD
997 : : PyObject *ob_item[NUM_KEYWORDS];
998 : : } _kwtuple = {
999 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1000 : : .ob_item = { &_Py_ID(fd), },
1001 : : };
1002 : : #undef NUM_KEYWORDS
1003 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1004 : :
1005 : : #else // !Py_BUILD_CORE
1006 : : # define KWTUPLE NULL
1007 : : #endif // !Py_BUILD_CORE
1008 : :
1009 : : static const char * const _keywords[] = {"fd", NULL};
1010 : : static _PyArg_Parser _parser = {
1011 : : .keywords = _keywords,
1012 : : .fname = "fsync",
1013 : : .kwtuple = KWTUPLE,
1014 : : };
1015 : : #undef KWTUPLE
1016 : : PyObject *argsbuf[1];
1017 : : int fd;
1018 : :
1019 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
1020 [ # # ]: 0 : if (!args) {
1021 : 0 : goto exit;
1022 : : }
1023 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
1024 : 0 : goto exit;
1025 : : }
1026 : 0 : return_value = os_fsync_impl(module, fd);
1027 : :
1028 : 0 : exit:
1029 : 0 : return return_value;
1030 : : }
1031 : :
1032 : : #endif /* defined(HAVE_FSYNC) */
1033 : :
1034 : : #if defined(HAVE_SYNC)
1035 : :
1036 : : PyDoc_STRVAR(os_sync__doc__,
1037 : : "sync($module, /)\n"
1038 : : "--\n"
1039 : : "\n"
1040 : : "Force write of everything to disk.");
1041 : :
1042 : : #define OS_SYNC_METHODDEF \
1043 : : {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
1044 : :
1045 : : static PyObject *
1046 : : os_sync_impl(PyObject *module);
1047 : :
1048 : : static PyObject *
1049 : 0 : os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
1050 : : {
1051 : 0 : return os_sync_impl(module);
1052 : : }
1053 : :
1054 : : #endif /* defined(HAVE_SYNC) */
1055 : :
1056 : : #if defined(HAVE_FDATASYNC)
1057 : :
1058 : : PyDoc_STRVAR(os_fdatasync__doc__,
1059 : : "fdatasync($module, /, fd)\n"
1060 : : "--\n"
1061 : : "\n"
1062 : : "Force write of fd to disk without forcing update of metadata.");
1063 : :
1064 : : #define OS_FDATASYNC_METHODDEF \
1065 : : {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
1066 : :
1067 : : static PyObject *
1068 : : os_fdatasync_impl(PyObject *module, int fd);
1069 : :
1070 : : static PyObject *
1071 : 0 : os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1072 : : {
1073 : 0 : PyObject *return_value = NULL;
1074 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1075 : :
1076 : : #define NUM_KEYWORDS 1
1077 : : static struct {
1078 : : PyGC_Head _this_is_not_used;
1079 : : PyObject_VAR_HEAD
1080 : : PyObject *ob_item[NUM_KEYWORDS];
1081 : : } _kwtuple = {
1082 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1083 : : .ob_item = { &_Py_ID(fd), },
1084 : : };
1085 : : #undef NUM_KEYWORDS
1086 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1087 : :
1088 : : #else // !Py_BUILD_CORE
1089 : : # define KWTUPLE NULL
1090 : : #endif // !Py_BUILD_CORE
1091 : :
1092 : : static const char * const _keywords[] = {"fd", NULL};
1093 : : static _PyArg_Parser _parser = {
1094 : : .keywords = _keywords,
1095 : : .fname = "fdatasync",
1096 : : .kwtuple = KWTUPLE,
1097 : : };
1098 : : #undef KWTUPLE
1099 : : PyObject *argsbuf[1];
1100 : : int fd;
1101 : :
1102 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
1103 [ # # ]: 0 : if (!args) {
1104 : 0 : goto exit;
1105 : : }
1106 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
1107 : 0 : goto exit;
1108 : : }
1109 : 0 : return_value = os_fdatasync_impl(module, fd);
1110 : :
1111 : 0 : exit:
1112 : 0 : return return_value;
1113 : : }
1114 : :
1115 : : #endif /* defined(HAVE_FDATASYNC) */
1116 : :
1117 : : #if defined(HAVE_CHOWN)
1118 : :
1119 : : PyDoc_STRVAR(os_chown__doc__,
1120 : : "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
1121 : : "--\n"
1122 : : "\n"
1123 : : "Change the owner and group id of path to the numeric uid and gid.\\\n"
1124 : : "\n"
1125 : : " path\n"
1126 : : " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
1127 : : " dir_fd\n"
1128 : : " If not None, it should be a file descriptor open to a directory,\n"
1129 : : " and path should be relative; path will then be relative to that\n"
1130 : : " directory.\n"
1131 : : " follow_symlinks\n"
1132 : : " If False, and the last element of the path is a symbolic link,\n"
1133 : : " stat will examine the symbolic link itself instead of the file\n"
1134 : : " the link points to.\n"
1135 : : "\n"
1136 : : "path may always be specified as a string.\n"
1137 : : "On some platforms, path may also be specified as an open file descriptor.\n"
1138 : : " If this functionality is unavailable, using it raises an exception.\n"
1139 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
1140 : : " and path should be relative; path will then be relative to that directory.\n"
1141 : : "If follow_symlinks is False, and the last element of the path is a symbolic\n"
1142 : : " link, chown will modify the symbolic link itself instead of the file the\n"
1143 : : " link points to.\n"
1144 : : "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
1145 : : " an open file descriptor.\n"
1146 : : "dir_fd and follow_symlinks may not be implemented on your platform.\n"
1147 : : " If they are unavailable, using them will raise a NotImplementedError.");
1148 : :
1149 : : #define OS_CHOWN_METHODDEF \
1150 : : {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
1151 : :
1152 : : static PyObject *
1153 : : os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
1154 : : int dir_fd, int follow_symlinks);
1155 : :
1156 : : static PyObject *
1157 : 0 : os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1158 : : {
1159 : 0 : PyObject *return_value = NULL;
1160 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1161 : :
1162 : : #define NUM_KEYWORDS 5
1163 : : static struct {
1164 : : PyGC_Head _this_is_not_used;
1165 : : PyObject_VAR_HEAD
1166 : : PyObject *ob_item[NUM_KEYWORDS];
1167 : : } _kwtuple = {
1168 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1169 : : .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
1170 : : };
1171 : : #undef NUM_KEYWORDS
1172 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1173 : :
1174 : : #else // !Py_BUILD_CORE
1175 : : # define KWTUPLE NULL
1176 : : #endif // !Py_BUILD_CORE
1177 : :
1178 : : static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
1179 : : static _PyArg_Parser _parser = {
1180 : : .keywords = _keywords,
1181 : : .fname = "chown",
1182 : : .kwtuple = KWTUPLE,
1183 : : };
1184 : : #undef KWTUPLE
1185 : : PyObject *argsbuf[5];
1186 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
1187 : 0 : path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
1188 : : uid_t uid;
1189 : : gid_t gid;
1190 : 0 : int dir_fd = DEFAULT_DIR_FD;
1191 : 0 : int follow_symlinks = 1;
1192 : :
1193 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
1194 [ # # ]: 0 : if (!args) {
1195 : 0 : goto exit;
1196 : : }
1197 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
1198 : 0 : goto exit;
1199 : : }
1200 [ # # ]: 0 : if (!_Py_Uid_Converter(args[1], &uid)) {
1201 : 0 : goto exit;
1202 : : }
1203 [ # # ]: 0 : if (!_Py_Gid_Converter(args[2], &gid)) {
1204 : 0 : goto exit;
1205 : : }
1206 [ # # ]: 0 : if (!noptargs) {
1207 : 0 : goto skip_optional_kwonly;
1208 : : }
1209 [ # # ]: 0 : if (args[3]) {
1210 [ # # ]: 0 : if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
1211 : 0 : goto exit;
1212 : : }
1213 [ # # ]: 0 : if (!--noptargs) {
1214 : 0 : goto skip_optional_kwonly;
1215 : : }
1216 : : }
1217 : 0 : follow_symlinks = PyObject_IsTrue(args[4]);
1218 [ # # ]: 0 : if (follow_symlinks < 0) {
1219 : 0 : goto exit;
1220 : : }
1221 : 0 : skip_optional_kwonly:
1222 : 0 : return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
1223 : :
1224 : 0 : exit:
1225 : : /* Cleanup for path */
1226 : 0 : path_cleanup(&path);
1227 : :
1228 : 0 : return return_value;
1229 : : }
1230 : :
1231 : : #endif /* defined(HAVE_CHOWN) */
1232 : :
1233 : : #if defined(HAVE_FCHOWN)
1234 : :
1235 : : PyDoc_STRVAR(os_fchown__doc__,
1236 : : "fchown($module, /, fd, uid, gid)\n"
1237 : : "--\n"
1238 : : "\n"
1239 : : "Change the owner and group id of the file specified by file descriptor.\n"
1240 : : "\n"
1241 : : "Equivalent to os.chown(fd, uid, gid).");
1242 : :
1243 : : #define OS_FCHOWN_METHODDEF \
1244 : : {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
1245 : :
1246 : : static PyObject *
1247 : : os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
1248 : :
1249 : : static PyObject *
1250 : 0 : os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1251 : : {
1252 : 0 : PyObject *return_value = NULL;
1253 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1254 : :
1255 : : #define NUM_KEYWORDS 3
1256 : : static struct {
1257 : : PyGC_Head _this_is_not_used;
1258 : : PyObject_VAR_HEAD
1259 : : PyObject *ob_item[NUM_KEYWORDS];
1260 : : } _kwtuple = {
1261 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1262 : : .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
1263 : : };
1264 : : #undef NUM_KEYWORDS
1265 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1266 : :
1267 : : #else // !Py_BUILD_CORE
1268 : : # define KWTUPLE NULL
1269 : : #endif // !Py_BUILD_CORE
1270 : :
1271 : : static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
1272 : : static _PyArg_Parser _parser = {
1273 : : .keywords = _keywords,
1274 : : .fname = "fchown",
1275 : : .kwtuple = KWTUPLE,
1276 : : };
1277 : : #undef KWTUPLE
1278 : : PyObject *argsbuf[3];
1279 : : int fd;
1280 : : uid_t uid;
1281 : : gid_t gid;
1282 : :
1283 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
1284 [ # # ]: 0 : if (!args) {
1285 : 0 : goto exit;
1286 : : }
1287 : 0 : fd = _PyLong_AsInt(args[0]);
1288 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
1289 : 0 : goto exit;
1290 : : }
1291 [ # # ]: 0 : if (!_Py_Uid_Converter(args[1], &uid)) {
1292 : 0 : goto exit;
1293 : : }
1294 [ # # ]: 0 : if (!_Py_Gid_Converter(args[2], &gid)) {
1295 : 0 : goto exit;
1296 : : }
1297 : 0 : return_value = os_fchown_impl(module, fd, uid, gid);
1298 : :
1299 : 0 : exit:
1300 : 0 : return return_value;
1301 : : }
1302 : :
1303 : : #endif /* defined(HAVE_FCHOWN) */
1304 : :
1305 : : #if defined(HAVE_LCHOWN)
1306 : :
1307 : : PyDoc_STRVAR(os_lchown__doc__,
1308 : : "lchown($module, /, path, uid, gid)\n"
1309 : : "--\n"
1310 : : "\n"
1311 : : "Change the owner and group id of path to the numeric uid and gid.\n"
1312 : : "\n"
1313 : : "This function will not follow symbolic links.\n"
1314 : : "Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
1315 : :
1316 : : #define OS_LCHOWN_METHODDEF \
1317 : : {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
1318 : :
1319 : : static PyObject *
1320 : : os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
1321 : :
1322 : : static PyObject *
1323 : 0 : os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1324 : : {
1325 : 0 : PyObject *return_value = NULL;
1326 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1327 : :
1328 : : #define NUM_KEYWORDS 3
1329 : : static struct {
1330 : : PyGC_Head _this_is_not_used;
1331 : : PyObject_VAR_HEAD
1332 : : PyObject *ob_item[NUM_KEYWORDS];
1333 : : } _kwtuple = {
1334 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1335 : : .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
1336 : : };
1337 : : #undef NUM_KEYWORDS
1338 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1339 : :
1340 : : #else // !Py_BUILD_CORE
1341 : : # define KWTUPLE NULL
1342 : : #endif // !Py_BUILD_CORE
1343 : :
1344 : : static const char * const _keywords[] = {"path", "uid", "gid", NULL};
1345 : : static _PyArg_Parser _parser = {
1346 : : .keywords = _keywords,
1347 : : .fname = "lchown",
1348 : : .kwtuple = KWTUPLE,
1349 : : };
1350 : : #undef KWTUPLE
1351 : : PyObject *argsbuf[3];
1352 : 0 : path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
1353 : : uid_t uid;
1354 : : gid_t gid;
1355 : :
1356 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
1357 [ # # ]: 0 : if (!args) {
1358 : 0 : goto exit;
1359 : : }
1360 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
1361 : 0 : goto exit;
1362 : : }
1363 [ # # ]: 0 : if (!_Py_Uid_Converter(args[1], &uid)) {
1364 : 0 : goto exit;
1365 : : }
1366 [ # # ]: 0 : if (!_Py_Gid_Converter(args[2], &gid)) {
1367 : 0 : goto exit;
1368 : : }
1369 : 0 : return_value = os_lchown_impl(module, &path, uid, gid);
1370 : :
1371 : 0 : exit:
1372 : : /* Cleanup for path */
1373 : 0 : path_cleanup(&path);
1374 : :
1375 : 0 : return return_value;
1376 : : }
1377 : :
1378 : : #endif /* defined(HAVE_LCHOWN) */
1379 : :
1380 : : PyDoc_STRVAR(os_getcwd__doc__,
1381 : : "getcwd($module, /)\n"
1382 : : "--\n"
1383 : : "\n"
1384 : : "Return a unicode string representing the current working directory.");
1385 : :
1386 : : #define OS_GETCWD_METHODDEF \
1387 : : {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
1388 : :
1389 : : static PyObject *
1390 : : os_getcwd_impl(PyObject *module);
1391 : :
1392 : : static PyObject *
1393 : 96 : os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
1394 : : {
1395 : 96 : return os_getcwd_impl(module);
1396 : : }
1397 : :
1398 : : PyDoc_STRVAR(os_getcwdb__doc__,
1399 : : "getcwdb($module, /)\n"
1400 : : "--\n"
1401 : : "\n"
1402 : : "Return a bytes string representing the current working directory.");
1403 : :
1404 : : #define OS_GETCWDB_METHODDEF \
1405 : : {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
1406 : :
1407 : : static PyObject *
1408 : : os_getcwdb_impl(PyObject *module);
1409 : :
1410 : : static PyObject *
1411 : 0 : os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
1412 : : {
1413 : 0 : return os_getcwdb_impl(module);
1414 : : }
1415 : :
1416 : : #if defined(HAVE_LINK)
1417 : :
1418 : : PyDoc_STRVAR(os_link__doc__,
1419 : : "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
1420 : : " follow_symlinks=True)\n"
1421 : : "--\n"
1422 : : "\n"
1423 : : "Create a hard link to a file.\n"
1424 : : "\n"
1425 : : "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
1426 : : " descriptor open to a directory, and the respective path string (src or dst)\n"
1427 : : " should be relative; the path will then be relative to that directory.\n"
1428 : : "If follow_symlinks is False, and the last element of src is a symbolic\n"
1429 : : " link, link will create a link to the symbolic link itself instead of the\n"
1430 : : " file the link points to.\n"
1431 : : "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
1432 : : " platform. If they are unavailable, using them will raise a\n"
1433 : : " NotImplementedError.");
1434 : :
1435 : : #define OS_LINK_METHODDEF \
1436 : : {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
1437 : :
1438 : : static PyObject *
1439 : : os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
1440 : : int dst_dir_fd, int follow_symlinks);
1441 : :
1442 : : static PyObject *
1443 : 0 : os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1444 : : {
1445 : 0 : PyObject *return_value = NULL;
1446 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1447 : :
1448 : : #define NUM_KEYWORDS 5
1449 : : static struct {
1450 : : PyGC_Head _this_is_not_used;
1451 : : PyObject_VAR_HEAD
1452 : : PyObject *ob_item[NUM_KEYWORDS];
1453 : : } _kwtuple = {
1454 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1455 : : .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
1456 : : };
1457 : : #undef NUM_KEYWORDS
1458 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1459 : :
1460 : : #else // !Py_BUILD_CORE
1461 : : # define KWTUPLE NULL
1462 : : #endif // !Py_BUILD_CORE
1463 : :
1464 : : static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
1465 : : static _PyArg_Parser _parser = {
1466 : : .keywords = _keywords,
1467 : : .fname = "link",
1468 : : .kwtuple = KWTUPLE,
1469 : : };
1470 : : #undef KWTUPLE
1471 : : PyObject *argsbuf[5];
1472 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
1473 : 0 : path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
1474 : 0 : path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
1475 : 0 : int src_dir_fd = DEFAULT_DIR_FD;
1476 : 0 : int dst_dir_fd = DEFAULT_DIR_FD;
1477 : 0 : int follow_symlinks = 1;
1478 : :
1479 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
1480 [ # # ]: 0 : if (!args) {
1481 : 0 : goto exit;
1482 : : }
1483 [ # # ]: 0 : if (!path_converter(args[0], &src)) {
1484 : 0 : goto exit;
1485 : : }
1486 [ # # ]: 0 : if (!path_converter(args[1], &dst)) {
1487 : 0 : goto exit;
1488 : : }
1489 [ # # ]: 0 : if (!noptargs) {
1490 : 0 : goto skip_optional_kwonly;
1491 : : }
1492 [ # # ]: 0 : if (args[2]) {
1493 [ # # ]: 0 : if (!dir_fd_converter(args[2], &src_dir_fd)) {
1494 : 0 : goto exit;
1495 : : }
1496 [ # # ]: 0 : if (!--noptargs) {
1497 : 0 : goto skip_optional_kwonly;
1498 : : }
1499 : : }
1500 [ # # ]: 0 : if (args[3]) {
1501 [ # # ]: 0 : if (!dir_fd_converter(args[3], &dst_dir_fd)) {
1502 : 0 : goto exit;
1503 : : }
1504 [ # # ]: 0 : if (!--noptargs) {
1505 : 0 : goto skip_optional_kwonly;
1506 : : }
1507 : : }
1508 : 0 : follow_symlinks = PyObject_IsTrue(args[4]);
1509 [ # # ]: 0 : if (follow_symlinks < 0) {
1510 : 0 : goto exit;
1511 : : }
1512 : 0 : skip_optional_kwonly:
1513 : 0 : return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
1514 : :
1515 : 0 : exit:
1516 : : /* Cleanup for src */
1517 : 0 : path_cleanup(&src);
1518 : : /* Cleanup for dst */
1519 : 0 : path_cleanup(&dst);
1520 : :
1521 : 0 : return return_value;
1522 : : }
1523 : :
1524 : : #endif /* defined(HAVE_LINK) */
1525 : :
1526 : : PyDoc_STRVAR(os_listdir__doc__,
1527 : : "listdir($module, /, path=None)\n"
1528 : : "--\n"
1529 : : "\n"
1530 : : "Return a list containing the names of the files in the directory.\n"
1531 : : "\n"
1532 : : "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n"
1533 : : " the filenames returned will also be bytes; in all other circumstances\n"
1534 : : " the filenames returned will be str.\n"
1535 : : "If path is None, uses the path=\'.\'.\n"
1536 : : "On some platforms, path may also be specified as an open file descriptor;\\\n"
1537 : : " the file descriptor must refer to a directory.\n"
1538 : : " If this functionality is unavailable, using it raises NotImplementedError.\n"
1539 : : "\n"
1540 : : "The list is in arbitrary order. It does not include the special\n"
1541 : : "entries \'.\' and \'..\' even if they are present in the directory.");
1542 : :
1543 : : #define OS_LISTDIR_METHODDEF \
1544 : : {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
1545 : :
1546 : : static PyObject *
1547 : : os_listdir_impl(PyObject *module, path_t *path);
1548 : :
1549 : : static PyObject *
1550 : 89 : os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1551 : : {
1552 : 89 : PyObject *return_value = NULL;
1553 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1554 : :
1555 : : #define NUM_KEYWORDS 1
1556 : : static struct {
1557 : : PyGC_Head _this_is_not_used;
1558 : : PyObject_VAR_HEAD
1559 : : PyObject *ob_item[NUM_KEYWORDS];
1560 : : } _kwtuple = {
1561 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1562 : : .ob_item = { &_Py_ID(path), },
1563 : : };
1564 : : #undef NUM_KEYWORDS
1565 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1566 : :
1567 : : #else // !Py_BUILD_CORE
1568 : : # define KWTUPLE NULL
1569 : : #endif // !Py_BUILD_CORE
1570 : :
1571 : : static const char * const _keywords[] = {"path", NULL};
1572 : : static _PyArg_Parser _parser = {
1573 : : .keywords = _keywords,
1574 : : .fname = "listdir",
1575 : : .kwtuple = KWTUPLE,
1576 : : };
1577 : : #undef KWTUPLE
1578 : : PyObject *argsbuf[1];
1579 [ - + ]: 89 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1580 : 89 : path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
1581 : :
1582 [ + - + - : 89 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
+ - - + ]
1583 [ - + ]: 89 : if (!args) {
1584 : 0 : goto exit;
1585 : : }
1586 [ + + ]: 89 : if (!noptargs) {
1587 : 4 : goto skip_optional_pos;
1588 : : }
1589 [ - + ]: 85 : if (!path_converter(args[0], &path)) {
1590 : 0 : goto exit;
1591 : : }
1592 : 85 : skip_optional_pos:
1593 : 89 : return_value = os_listdir_impl(module, &path);
1594 : :
1595 : 89 : exit:
1596 : : /* Cleanup for path */
1597 : 89 : path_cleanup(&path);
1598 : :
1599 : 89 : return return_value;
1600 : : }
1601 : :
1602 : : #if defined(MS_WINDOWS)
1603 : :
1604 : : PyDoc_STRVAR(os_listdrives__doc__,
1605 : : "listdrives($module, /)\n"
1606 : : "--\n"
1607 : : "\n"
1608 : : "Return a list containing the names of drives in the system.\n"
1609 : : "\n"
1610 : : "A drive name typically looks like \'C:\\\\\'.");
1611 : :
1612 : : #define OS_LISTDRIVES_METHODDEF \
1613 : : {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
1614 : :
1615 : : static PyObject *
1616 : : os_listdrives_impl(PyObject *module);
1617 : :
1618 : : static PyObject *
1619 : : os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
1620 : : {
1621 : : return os_listdrives_impl(module);
1622 : : }
1623 : :
1624 : : #endif /* defined(MS_WINDOWS) */
1625 : :
1626 : : #if defined(MS_WINDOWS)
1627 : :
1628 : : PyDoc_STRVAR(os_listvolumes__doc__,
1629 : : "listvolumes($module, /)\n"
1630 : : "--\n"
1631 : : "\n"
1632 : : "Return a list containing the volumes in the system.\n"
1633 : : "\n"
1634 : : "Volumes are typically represented as a GUID path.");
1635 : :
1636 : : #define OS_LISTVOLUMES_METHODDEF \
1637 : : {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
1638 : :
1639 : : static PyObject *
1640 : : os_listvolumes_impl(PyObject *module);
1641 : :
1642 : : static PyObject *
1643 : : os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
1644 : : {
1645 : : return os_listvolumes_impl(module);
1646 : : }
1647 : :
1648 : : #endif /* defined(MS_WINDOWS) */
1649 : :
1650 : : #if defined(MS_WINDOWS)
1651 : :
1652 : : PyDoc_STRVAR(os_listmounts__doc__,
1653 : : "listmounts($module, /, volume)\n"
1654 : : "--\n"
1655 : : "\n"
1656 : : "Return a list containing mount points for a particular volume.\n"
1657 : : "\n"
1658 : : "\'volume\' should be a GUID path as returned from os.listvolumes.");
1659 : :
1660 : : #define OS_LISTMOUNTS_METHODDEF \
1661 : : {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
1662 : :
1663 : : static PyObject *
1664 : : os_listmounts_impl(PyObject *module, path_t *volume);
1665 : :
1666 : : static PyObject *
1667 : : os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1668 : : {
1669 : : PyObject *return_value = NULL;
1670 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1671 : :
1672 : : #define NUM_KEYWORDS 1
1673 : : static struct {
1674 : : PyGC_Head _this_is_not_used;
1675 : : PyObject_VAR_HEAD
1676 : : PyObject *ob_item[NUM_KEYWORDS];
1677 : : } _kwtuple = {
1678 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1679 : : .ob_item = { &_Py_ID(volume), },
1680 : : };
1681 : : #undef NUM_KEYWORDS
1682 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1683 : :
1684 : : #else // !Py_BUILD_CORE
1685 : : # define KWTUPLE NULL
1686 : : #endif // !Py_BUILD_CORE
1687 : :
1688 : : static const char * const _keywords[] = {"volume", NULL};
1689 : : static _PyArg_Parser _parser = {
1690 : : .keywords = _keywords,
1691 : : .fname = "listmounts",
1692 : : .kwtuple = KWTUPLE,
1693 : : };
1694 : : #undef KWTUPLE
1695 : : PyObject *argsbuf[1];
1696 : : path_t volume = PATH_T_INITIALIZE("listmounts", "volume", 0, 0);
1697 : :
1698 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1699 : : if (!args) {
1700 : : goto exit;
1701 : : }
1702 : : if (!path_converter(args[0], &volume)) {
1703 : : goto exit;
1704 : : }
1705 : : return_value = os_listmounts_impl(module, &volume);
1706 : :
1707 : : exit:
1708 : : /* Cleanup for volume */
1709 : : path_cleanup(&volume);
1710 : :
1711 : : return return_value;
1712 : : }
1713 : :
1714 : : #endif /* defined(MS_WINDOWS) */
1715 : :
1716 : : #if defined(MS_WINDOWS)
1717 : :
1718 : : PyDoc_STRVAR(os__getfullpathname__doc__,
1719 : : "_getfullpathname($module, path, /)\n"
1720 : : "--\n"
1721 : : "\n");
1722 : :
1723 : : #define OS__GETFULLPATHNAME_METHODDEF \
1724 : : {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
1725 : :
1726 : : static PyObject *
1727 : : os__getfullpathname_impl(PyObject *module, path_t *path);
1728 : :
1729 : : static PyObject *
1730 : : os__getfullpathname(PyObject *module, PyObject *arg)
1731 : : {
1732 : : PyObject *return_value = NULL;
1733 : : path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
1734 : :
1735 : : if (!path_converter(arg, &path)) {
1736 : : goto exit;
1737 : : }
1738 : : return_value = os__getfullpathname_impl(module, &path);
1739 : :
1740 : : exit:
1741 : : /* Cleanup for path */
1742 : : path_cleanup(&path);
1743 : :
1744 : : return return_value;
1745 : : }
1746 : :
1747 : : #endif /* defined(MS_WINDOWS) */
1748 : :
1749 : : #if defined(MS_WINDOWS)
1750 : :
1751 : : PyDoc_STRVAR(os__getfinalpathname__doc__,
1752 : : "_getfinalpathname($module, path, /)\n"
1753 : : "--\n"
1754 : : "\n"
1755 : : "A helper function for samepath on windows.");
1756 : :
1757 : : #define OS__GETFINALPATHNAME_METHODDEF \
1758 : : {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
1759 : :
1760 : : static PyObject *
1761 : : os__getfinalpathname_impl(PyObject *module, path_t *path);
1762 : :
1763 : : static PyObject *
1764 : : os__getfinalpathname(PyObject *module, PyObject *arg)
1765 : : {
1766 : : PyObject *return_value = NULL;
1767 : : path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
1768 : :
1769 : : if (!path_converter(arg, &path)) {
1770 : : goto exit;
1771 : : }
1772 : : return_value = os__getfinalpathname_impl(module, &path);
1773 : :
1774 : : exit:
1775 : : /* Cleanup for path */
1776 : : path_cleanup(&path);
1777 : :
1778 : : return return_value;
1779 : : }
1780 : :
1781 : : #endif /* defined(MS_WINDOWS) */
1782 : :
1783 : : #if defined(MS_WINDOWS)
1784 : :
1785 : : PyDoc_STRVAR(os__getvolumepathname__doc__,
1786 : : "_getvolumepathname($module, /, path)\n"
1787 : : "--\n"
1788 : : "\n"
1789 : : "A helper function for ismount on Win32.");
1790 : :
1791 : : #define OS__GETVOLUMEPATHNAME_METHODDEF \
1792 : : {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
1793 : :
1794 : : static PyObject *
1795 : : os__getvolumepathname_impl(PyObject *module, path_t *path);
1796 : :
1797 : : static PyObject *
1798 : : os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1799 : : {
1800 : : PyObject *return_value = NULL;
1801 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1802 : :
1803 : : #define NUM_KEYWORDS 1
1804 : : static struct {
1805 : : PyGC_Head _this_is_not_used;
1806 : : PyObject_VAR_HEAD
1807 : : PyObject *ob_item[NUM_KEYWORDS];
1808 : : } _kwtuple = {
1809 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1810 : : .ob_item = { &_Py_ID(path), },
1811 : : };
1812 : : #undef NUM_KEYWORDS
1813 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1814 : :
1815 : : #else // !Py_BUILD_CORE
1816 : : # define KWTUPLE NULL
1817 : : #endif // !Py_BUILD_CORE
1818 : :
1819 : : static const char * const _keywords[] = {"path", NULL};
1820 : : static _PyArg_Parser _parser = {
1821 : : .keywords = _keywords,
1822 : : .fname = "_getvolumepathname",
1823 : : .kwtuple = KWTUPLE,
1824 : : };
1825 : : #undef KWTUPLE
1826 : : PyObject *argsbuf[1];
1827 : : path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
1828 : :
1829 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1830 : : if (!args) {
1831 : : goto exit;
1832 : : }
1833 : : if (!path_converter(args[0], &path)) {
1834 : : goto exit;
1835 : : }
1836 : : return_value = os__getvolumepathname_impl(module, &path);
1837 : :
1838 : : exit:
1839 : : /* Cleanup for path */
1840 : : path_cleanup(&path);
1841 : :
1842 : : return return_value;
1843 : : }
1844 : :
1845 : : #endif /* defined(MS_WINDOWS) */
1846 : :
1847 : : #if defined(MS_WINDOWS)
1848 : :
1849 : : PyDoc_STRVAR(os__path_splitroot__doc__,
1850 : : "_path_splitroot($module, /, path)\n"
1851 : : "--\n"
1852 : : "\n"
1853 : : "Removes everything after the root on Win32.");
1854 : :
1855 : : #define OS__PATH_SPLITROOT_METHODDEF \
1856 : : {"_path_splitroot", _PyCFunction_CAST(os__path_splitroot), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot__doc__},
1857 : :
1858 : : static PyObject *
1859 : : os__path_splitroot_impl(PyObject *module, path_t *path);
1860 : :
1861 : : static PyObject *
1862 : : os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1863 : : {
1864 : : PyObject *return_value = NULL;
1865 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1866 : :
1867 : : #define NUM_KEYWORDS 1
1868 : : static struct {
1869 : : PyGC_Head _this_is_not_used;
1870 : : PyObject_VAR_HEAD
1871 : : PyObject *ob_item[NUM_KEYWORDS];
1872 : : } _kwtuple = {
1873 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1874 : : .ob_item = { &_Py_ID(path), },
1875 : : };
1876 : : #undef NUM_KEYWORDS
1877 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1878 : :
1879 : : #else // !Py_BUILD_CORE
1880 : : # define KWTUPLE NULL
1881 : : #endif // !Py_BUILD_CORE
1882 : :
1883 : : static const char * const _keywords[] = {"path", NULL};
1884 : : static _PyArg_Parser _parser = {
1885 : : .keywords = _keywords,
1886 : : .fname = "_path_splitroot",
1887 : : .kwtuple = KWTUPLE,
1888 : : };
1889 : : #undef KWTUPLE
1890 : : PyObject *argsbuf[1];
1891 : : path_t path = PATH_T_INITIALIZE("_path_splitroot", "path", 0, 0);
1892 : :
1893 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1894 : : if (!args) {
1895 : : goto exit;
1896 : : }
1897 : : if (!path_converter(args[0], &path)) {
1898 : : goto exit;
1899 : : }
1900 : : return_value = os__path_splitroot_impl(module, &path);
1901 : :
1902 : : exit:
1903 : : /* Cleanup for path */
1904 : : path_cleanup(&path);
1905 : :
1906 : : return return_value;
1907 : : }
1908 : :
1909 : : #endif /* defined(MS_WINDOWS) */
1910 : :
1911 : : #if defined(MS_WINDOWS)
1912 : :
1913 : : PyDoc_STRVAR(os__path_isdir__doc__,
1914 : : "_path_isdir($module, /, path)\n"
1915 : : "--\n"
1916 : : "\n"
1917 : : "Return true if the pathname refers to an existing directory.");
1918 : :
1919 : : #define OS__PATH_ISDIR_METHODDEF \
1920 : : {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__},
1921 : :
1922 : : static PyObject *
1923 : : os__path_isdir_impl(PyObject *module, PyObject *path);
1924 : :
1925 : : static PyObject *
1926 : : os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1927 : : {
1928 : : PyObject *return_value = NULL;
1929 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1930 : :
1931 : : #define NUM_KEYWORDS 1
1932 : : static struct {
1933 : : PyGC_Head _this_is_not_used;
1934 : : PyObject_VAR_HEAD
1935 : : PyObject *ob_item[NUM_KEYWORDS];
1936 : : } _kwtuple = {
1937 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1938 : : .ob_item = { &_Py_ID(path), },
1939 : : };
1940 : : #undef NUM_KEYWORDS
1941 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1942 : :
1943 : : #else // !Py_BUILD_CORE
1944 : : # define KWTUPLE NULL
1945 : : #endif // !Py_BUILD_CORE
1946 : :
1947 : : static const char * const _keywords[] = {"path", NULL};
1948 : : static _PyArg_Parser _parser = {
1949 : : .keywords = _keywords,
1950 : : .fname = "_path_isdir",
1951 : : .kwtuple = KWTUPLE,
1952 : : };
1953 : : #undef KWTUPLE
1954 : : PyObject *argsbuf[1];
1955 : : PyObject *path;
1956 : :
1957 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1958 : : if (!args) {
1959 : : goto exit;
1960 : : }
1961 : : path = args[0];
1962 : : return_value = os__path_isdir_impl(module, path);
1963 : :
1964 : : exit:
1965 : : return return_value;
1966 : : }
1967 : :
1968 : : #endif /* defined(MS_WINDOWS) */
1969 : :
1970 : : #if defined(MS_WINDOWS)
1971 : :
1972 : : PyDoc_STRVAR(os__path_isfile__doc__,
1973 : : "_path_isfile($module, /, path)\n"
1974 : : "--\n"
1975 : : "\n"
1976 : : "Test whether a path is a regular file");
1977 : :
1978 : : #define OS__PATH_ISFILE_METHODDEF \
1979 : : {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
1980 : :
1981 : : static PyObject *
1982 : : os__path_isfile_impl(PyObject *module, PyObject *path);
1983 : :
1984 : : static PyObject *
1985 : : os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1986 : : {
1987 : : PyObject *return_value = NULL;
1988 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1989 : :
1990 : : #define NUM_KEYWORDS 1
1991 : : static struct {
1992 : : PyGC_Head _this_is_not_used;
1993 : : PyObject_VAR_HEAD
1994 : : PyObject *ob_item[NUM_KEYWORDS];
1995 : : } _kwtuple = {
1996 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1997 : : .ob_item = { &_Py_ID(path), },
1998 : : };
1999 : : #undef NUM_KEYWORDS
2000 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2001 : :
2002 : : #else // !Py_BUILD_CORE
2003 : : # define KWTUPLE NULL
2004 : : #endif // !Py_BUILD_CORE
2005 : :
2006 : : static const char * const _keywords[] = {"path", NULL};
2007 : : static _PyArg_Parser _parser = {
2008 : : .keywords = _keywords,
2009 : : .fname = "_path_isfile",
2010 : : .kwtuple = KWTUPLE,
2011 : : };
2012 : : #undef KWTUPLE
2013 : : PyObject *argsbuf[1];
2014 : : PyObject *path;
2015 : :
2016 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2017 : : if (!args) {
2018 : : goto exit;
2019 : : }
2020 : : path = args[0];
2021 : : return_value = os__path_isfile_impl(module, path);
2022 : :
2023 : : exit:
2024 : : return return_value;
2025 : : }
2026 : :
2027 : : #endif /* defined(MS_WINDOWS) */
2028 : :
2029 : : #if defined(MS_WINDOWS)
2030 : :
2031 : : PyDoc_STRVAR(os__path_exists__doc__,
2032 : : "_path_exists($module, /, path)\n"
2033 : : "--\n"
2034 : : "\n"
2035 : : "Test whether a path exists. Returns False for broken symbolic links");
2036 : :
2037 : : #define OS__PATH_EXISTS_METHODDEF \
2038 : : {"_path_exists", _PyCFunction_CAST(os__path_exists), METH_FASTCALL|METH_KEYWORDS, os__path_exists__doc__},
2039 : :
2040 : : static PyObject *
2041 : : os__path_exists_impl(PyObject *module, PyObject *path);
2042 : :
2043 : : static PyObject *
2044 : : os__path_exists(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2045 : : {
2046 : : PyObject *return_value = NULL;
2047 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2048 : :
2049 : : #define NUM_KEYWORDS 1
2050 : : static struct {
2051 : : PyGC_Head _this_is_not_used;
2052 : : PyObject_VAR_HEAD
2053 : : PyObject *ob_item[NUM_KEYWORDS];
2054 : : } _kwtuple = {
2055 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2056 : : .ob_item = { &_Py_ID(path), },
2057 : : };
2058 : : #undef NUM_KEYWORDS
2059 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2060 : :
2061 : : #else // !Py_BUILD_CORE
2062 : : # define KWTUPLE NULL
2063 : : #endif // !Py_BUILD_CORE
2064 : :
2065 : : static const char * const _keywords[] = {"path", NULL};
2066 : : static _PyArg_Parser _parser = {
2067 : : .keywords = _keywords,
2068 : : .fname = "_path_exists",
2069 : : .kwtuple = KWTUPLE,
2070 : : };
2071 : : #undef KWTUPLE
2072 : : PyObject *argsbuf[1];
2073 : : PyObject *path;
2074 : :
2075 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2076 : : if (!args) {
2077 : : goto exit;
2078 : : }
2079 : : path = args[0];
2080 : : return_value = os__path_exists_impl(module, path);
2081 : :
2082 : : exit:
2083 : : return return_value;
2084 : : }
2085 : :
2086 : : #endif /* defined(MS_WINDOWS) */
2087 : :
2088 : : #if defined(MS_WINDOWS)
2089 : :
2090 : : PyDoc_STRVAR(os__path_islink__doc__,
2091 : : "_path_islink($module, /, path)\n"
2092 : : "--\n"
2093 : : "\n"
2094 : : "Test whether a path is a symbolic link");
2095 : :
2096 : : #define OS__PATH_ISLINK_METHODDEF \
2097 : : {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
2098 : :
2099 : : static PyObject *
2100 : : os__path_islink_impl(PyObject *module, PyObject *path);
2101 : :
2102 : : static PyObject *
2103 : : os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2104 : : {
2105 : : PyObject *return_value = NULL;
2106 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2107 : :
2108 : : #define NUM_KEYWORDS 1
2109 : : static struct {
2110 : : PyGC_Head _this_is_not_used;
2111 : : PyObject_VAR_HEAD
2112 : : PyObject *ob_item[NUM_KEYWORDS];
2113 : : } _kwtuple = {
2114 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2115 : : .ob_item = { &_Py_ID(path), },
2116 : : };
2117 : : #undef NUM_KEYWORDS
2118 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2119 : :
2120 : : #else // !Py_BUILD_CORE
2121 : : # define KWTUPLE NULL
2122 : : #endif // !Py_BUILD_CORE
2123 : :
2124 : : static const char * const _keywords[] = {"path", NULL};
2125 : : static _PyArg_Parser _parser = {
2126 : : .keywords = _keywords,
2127 : : .fname = "_path_islink",
2128 : : .kwtuple = KWTUPLE,
2129 : : };
2130 : : #undef KWTUPLE
2131 : : PyObject *argsbuf[1];
2132 : : PyObject *path;
2133 : :
2134 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2135 : : if (!args) {
2136 : : goto exit;
2137 : : }
2138 : : path = args[0];
2139 : : return_value = os__path_islink_impl(module, path);
2140 : :
2141 : : exit:
2142 : : return return_value;
2143 : : }
2144 : :
2145 : : #endif /* defined(MS_WINDOWS) */
2146 : :
2147 : : PyDoc_STRVAR(os__path_normpath__doc__,
2148 : : "_path_normpath($module, /, path)\n"
2149 : : "--\n"
2150 : : "\n"
2151 : : "Basic path normalization.");
2152 : :
2153 : : #define OS__PATH_NORMPATH_METHODDEF \
2154 : : {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
2155 : :
2156 : : static PyObject *
2157 : : os__path_normpath_impl(PyObject *module, PyObject *path);
2158 : :
2159 : : static PyObject *
2160 : 249 : os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2161 : : {
2162 : 249 : PyObject *return_value = NULL;
2163 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2164 : :
2165 : : #define NUM_KEYWORDS 1
2166 : : static struct {
2167 : : PyGC_Head _this_is_not_used;
2168 : : PyObject_VAR_HEAD
2169 : : PyObject *ob_item[NUM_KEYWORDS];
2170 : : } _kwtuple = {
2171 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2172 : : .ob_item = { &_Py_ID(path), },
2173 : : };
2174 : : #undef NUM_KEYWORDS
2175 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2176 : :
2177 : : #else // !Py_BUILD_CORE
2178 : : # define KWTUPLE NULL
2179 : : #endif // !Py_BUILD_CORE
2180 : :
2181 : : static const char * const _keywords[] = {"path", NULL};
2182 : : static _PyArg_Parser _parser = {
2183 : : .keywords = _keywords,
2184 : : .fname = "_path_normpath",
2185 : : .kwtuple = KWTUPLE,
2186 : : };
2187 : : #undef KWTUPLE
2188 : : PyObject *argsbuf[1];
2189 : : PyObject *path;
2190 : :
2191 [ + - + - : 249 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
2192 [ - + ]: 249 : if (!args) {
2193 : 0 : goto exit;
2194 : : }
2195 : 249 : path = args[0];
2196 : 249 : return_value = os__path_normpath_impl(module, path);
2197 : :
2198 : 249 : exit:
2199 : 249 : return return_value;
2200 : : }
2201 : :
2202 : : PyDoc_STRVAR(os_mkdir__doc__,
2203 : : "mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
2204 : : "--\n"
2205 : : "\n"
2206 : : "Create a directory.\n"
2207 : : "\n"
2208 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2209 : : " and path should be relative; path will then be relative to that directory.\n"
2210 : : "dir_fd may not be implemented on your platform.\n"
2211 : : " If it is unavailable, using it will raise a NotImplementedError.\n"
2212 : : "\n"
2213 : : "The mode argument is ignored on Windows. Where it is used, the current umask\n"
2214 : : "value is first masked out.");
2215 : :
2216 : : #define OS_MKDIR_METHODDEF \
2217 : : {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
2218 : :
2219 : : static PyObject *
2220 : : os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
2221 : :
2222 : : static PyObject *
2223 : 23 : os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2224 : : {
2225 : 23 : PyObject *return_value = NULL;
2226 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2227 : :
2228 : : #define NUM_KEYWORDS 3
2229 : : static struct {
2230 : : PyGC_Head _this_is_not_used;
2231 : : PyObject_VAR_HEAD
2232 : : PyObject *ob_item[NUM_KEYWORDS];
2233 : : } _kwtuple = {
2234 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2235 : : .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
2236 : : };
2237 : : #undef NUM_KEYWORDS
2238 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2239 : :
2240 : : #else // !Py_BUILD_CORE
2241 : : # define KWTUPLE NULL
2242 : : #endif // !Py_BUILD_CORE
2243 : :
2244 : : static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
2245 : : static _PyArg_Parser _parser = {
2246 : : .keywords = _keywords,
2247 : : .fname = "mkdir",
2248 : : .kwtuple = KWTUPLE,
2249 : : };
2250 : : #undef KWTUPLE
2251 : : PyObject *argsbuf[3];
2252 [ - + ]: 23 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2253 : 23 : path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
2254 : 23 : int mode = 511;
2255 : 23 : int dir_fd = DEFAULT_DIR_FD;
2256 : :
2257 [ + - + - : 23 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ - - + ]
2258 [ - + ]: 23 : if (!args) {
2259 : 0 : goto exit;
2260 : : }
2261 [ - + ]: 23 : if (!path_converter(args[0], &path)) {
2262 : 0 : goto exit;
2263 : : }
2264 [ + + ]: 23 : if (!noptargs) {
2265 : 21 : goto skip_optional_pos;
2266 : : }
2267 [ - + ]: 2 : if (args[1]) {
2268 : 2 : mode = _PyLong_AsInt(args[1]);
2269 [ - + - - ]: 2 : if (mode == -1 && PyErr_Occurred()) {
2270 : 0 : goto exit;
2271 : : }
2272 [ - + ]: 2 : if (!--noptargs) {
2273 : 2 : goto skip_optional_pos;
2274 : : }
2275 : : }
2276 : 0 : skip_optional_pos:
2277 [ + - ]: 23 : if (!noptargs) {
2278 : 23 : goto skip_optional_kwonly;
2279 : : }
2280 [ # # ]: 0 : if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
2281 : 0 : goto exit;
2282 : : }
2283 : 0 : skip_optional_kwonly:
2284 : 23 : return_value = os_mkdir_impl(module, &path, mode, dir_fd);
2285 : :
2286 : 23 : exit:
2287 : : /* Cleanup for path */
2288 : 23 : path_cleanup(&path);
2289 : :
2290 : 23 : return return_value;
2291 : : }
2292 : :
2293 : : #if defined(HAVE_NICE)
2294 : :
2295 : : PyDoc_STRVAR(os_nice__doc__,
2296 : : "nice($module, increment, /)\n"
2297 : : "--\n"
2298 : : "\n"
2299 : : "Add increment to the priority of process and return the new priority.");
2300 : :
2301 : : #define OS_NICE_METHODDEF \
2302 : : {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
2303 : :
2304 : : static PyObject *
2305 : : os_nice_impl(PyObject *module, int increment);
2306 : :
2307 : : static PyObject *
2308 : 0 : os_nice(PyObject *module, PyObject *arg)
2309 : : {
2310 : 0 : PyObject *return_value = NULL;
2311 : : int increment;
2312 : :
2313 : 0 : increment = _PyLong_AsInt(arg);
2314 [ # # # # ]: 0 : if (increment == -1 && PyErr_Occurred()) {
2315 : 0 : goto exit;
2316 : : }
2317 : 0 : return_value = os_nice_impl(module, increment);
2318 : :
2319 : 0 : exit:
2320 : 0 : return return_value;
2321 : : }
2322 : :
2323 : : #endif /* defined(HAVE_NICE) */
2324 : :
2325 : : #if defined(HAVE_GETPRIORITY)
2326 : :
2327 : : PyDoc_STRVAR(os_getpriority__doc__,
2328 : : "getpriority($module, /, which, who)\n"
2329 : : "--\n"
2330 : : "\n"
2331 : : "Return program scheduling priority.");
2332 : :
2333 : : #define OS_GETPRIORITY_METHODDEF \
2334 : : {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
2335 : :
2336 : : static PyObject *
2337 : : os_getpriority_impl(PyObject *module, int which, int who);
2338 : :
2339 : : static PyObject *
2340 : 0 : os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2341 : : {
2342 : 0 : PyObject *return_value = NULL;
2343 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2344 : :
2345 : : #define NUM_KEYWORDS 2
2346 : : static struct {
2347 : : PyGC_Head _this_is_not_used;
2348 : : PyObject_VAR_HEAD
2349 : : PyObject *ob_item[NUM_KEYWORDS];
2350 : : } _kwtuple = {
2351 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2352 : : .ob_item = { &_Py_ID(which), &_Py_ID(who), },
2353 : : };
2354 : : #undef NUM_KEYWORDS
2355 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2356 : :
2357 : : #else // !Py_BUILD_CORE
2358 : : # define KWTUPLE NULL
2359 : : #endif // !Py_BUILD_CORE
2360 : :
2361 : : static const char * const _keywords[] = {"which", "who", NULL};
2362 : : static _PyArg_Parser _parser = {
2363 : : .keywords = _keywords,
2364 : : .fname = "getpriority",
2365 : : .kwtuple = KWTUPLE,
2366 : : };
2367 : : #undef KWTUPLE
2368 : : PyObject *argsbuf[2];
2369 : : int which;
2370 : : int who;
2371 : :
2372 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
2373 [ # # ]: 0 : if (!args) {
2374 : 0 : goto exit;
2375 : : }
2376 : 0 : which = _PyLong_AsInt(args[0]);
2377 [ # # # # ]: 0 : if (which == -1 && PyErr_Occurred()) {
2378 : 0 : goto exit;
2379 : : }
2380 : 0 : who = _PyLong_AsInt(args[1]);
2381 [ # # # # ]: 0 : if (who == -1 && PyErr_Occurred()) {
2382 : 0 : goto exit;
2383 : : }
2384 : 0 : return_value = os_getpriority_impl(module, which, who);
2385 : :
2386 : 0 : exit:
2387 : 0 : return return_value;
2388 : : }
2389 : :
2390 : : #endif /* defined(HAVE_GETPRIORITY) */
2391 : :
2392 : : #if defined(HAVE_SETPRIORITY)
2393 : :
2394 : : PyDoc_STRVAR(os_setpriority__doc__,
2395 : : "setpriority($module, /, which, who, priority)\n"
2396 : : "--\n"
2397 : : "\n"
2398 : : "Set program scheduling priority.");
2399 : :
2400 : : #define OS_SETPRIORITY_METHODDEF \
2401 : : {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
2402 : :
2403 : : static PyObject *
2404 : : os_setpriority_impl(PyObject *module, int which, int who, int priority);
2405 : :
2406 : : static PyObject *
2407 : 0 : os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2408 : : {
2409 : 0 : PyObject *return_value = NULL;
2410 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2411 : :
2412 : : #define NUM_KEYWORDS 3
2413 : : static struct {
2414 : : PyGC_Head _this_is_not_used;
2415 : : PyObject_VAR_HEAD
2416 : : PyObject *ob_item[NUM_KEYWORDS];
2417 : : } _kwtuple = {
2418 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2419 : : .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
2420 : : };
2421 : : #undef NUM_KEYWORDS
2422 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2423 : :
2424 : : #else // !Py_BUILD_CORE
2425 : : # define KWTUPLE NULL
2426 : : #endif // !Py_BUILD_CORE
2427 : :
2428 : : static const char * const _keywords[] = {"which", "who", "priority", NULL};
2429 : : static _PyArg_Parser _parser = {
2430 : : .keywords = _keywords,
2431 : : .fname = "setpriority",
2432 : : .kwtuple = KWTUPLE,
2433 : : };
2434 : : #undef KWTUPLE
2435 : : PyObject *argsbuf[3];
2436 : : int which;
2437 : : int who;
2438 : : int priority;
2439 : :
2440 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
2441 [ # # ]: 0 : if (!args) {
2442 : 0 : goto exit;
2443 : : }
2444 : 0 : which = _PyLong_AsInt(args[0]);
2445 [ # # # # ]: 0 : if (which == -1 && PyErr_Occurred()) {
2446 : 0 : goto exit;
2447 : : }
2448 : 0 : who = _PyLong_AsInt(args[1]);
2449 [ # # # # ]: 0 : if (who == -1 && PyErr_Occurred()) {
2450 : 0 : goto exit;
2451 : : }
2452 : 0 : priority = _PyLong_AsInt(args[2]);
2453 [ # # # # ]: 0 : if (priority == -1 && PyErr_Occurred()) {
2454 : 0 : goto exit;
2455 : : }
2456 : 0 : return_value = os_setpriority_impl(module, which, who, priority);
2457 : :
2458 : 0 : exit:
2459 : 0 : return return_value;
2460 : : }
2461 : :
2462 : : #endif /* defined(HAVE_SETPRIORITY) */
2463 : :
2464 : : PyDoc_STRVAR(os_rename__doc__,
2465 : : "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2466 : : "--\n"
2467 : : "\n"
2468 : : "Rename a file or directory.\n"
2469 : : "\n"
2470 : : "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2471 : : " descriptor open to a directory, and the respective path string (src or dst)\n"
2472 : : " should be relative; the path will then be relative to that directory.\n"
2473 : : "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2474 : : " If they are unavailable, using them will raise a NotImplementedError.");
2475 : :
2476 : : #define OS_RENAME_METHODDEF \
2477 : : {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
2478 : :
2479 : : static PyObject *
2480 : : os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2481 : : int dst_dir_fd);
2482 : :
2483 : : static PyObject *
2484 : 0 : os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2485 : : {
2486 : 0 : PyObject *return_value = NULL;
2487 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2488 : :
2489 : : #define NUM_KEYWORDS 4
2490 : : static struct {
2491 : : PyGC_Head _this_is_not_used;
2492 : : PyObject_VAR_HEAD
2493 : : PyObject *ob_item[NUM_KEYWORDS];
2494 : : } _kwtuple = {
2495 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2496 : : .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
2497 : : };
2498 : : #undef NUM_KEYWORDS
2499 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2500 : :
2501 : : #else // !Py_BUILD_CORE
2502 : : # define KWTUPLE NULL
2503 : : #endif // !Py_BUILD_CORE
2504 : :
2505 : : static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
2506 : : static _PyArg_Parser _parser = {
2507 : : .keywords = _keywords,
2508 : : .fname = "rename",
2509 : : .kwtuple = KWTUPLE,
2510 : : };
2511 : : #undef KWTUPLE
2512 : : PyObject *argsbuf[4];
2513 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
2514 : 0 : path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
2515 : 0 : path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
2516 : 0 : int src_dir_fd = DEFAULT_DIR_FD;
2517 : 0 : int dst_dir_fd = DEFAULT_DIR_FD;
2518 : :
2519 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
2520 [ # # ]: 0 : if (!args) {
2521 : 0 : goto exit;
2522 : : }
2523 [ # # ]: 0 : if (!path_converter(args[0], &src)) {
2524 : 0 : goto exit;
2525 : : }
2526 [ # # ]: 0 : if (!path_converter(args[1], &dst)) {
2527 : 0 : goto exit;
2528 : : }
2529 [ # # ]: 0 : if (!noptargs) {
2530 : 0 : goto skip_optional_kwonly;
2531 : : }
2532 [ # # ]: 0 : if (args[2]) {
2533 [ # # ]: 0 : if (!dir_fd_converter(args[2], &src_dir_fd)) {
2534 : 0 : goto exit;
2535 : : }
2536 [ # # ]: 0 : if (!--noptargs) {
2537 : 0 : goto skip_optional_kwonly;
2538 : : }
2539 : : }
2540 [ # # ]: 0 : if (!dir_fd_converter(args[3], &dst_dir_fd)) {
2541 : 0 : goto exit;
2542 : : }
2543 : 0 : skip_optional_kwonly:
2544 : 0 : return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
2545 : :
2546 : 0 : exit:
2547 : : /* Cleanup for src */
2548 : 0 : path_cleanup(&src);
2549 : : /* Cleanup for dst */
2550 : 0 : path_cleanup(&dst);
2551 : :
2552 : 0 : return return_value;
2553 : : }
2554 : :
2555 : : PyDoc_STRVAR(os_replace__doc__,
2556 : : "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
2557 : : "--\n"
2558 : : "\n"
2559 : : "Rename a file or directory, overwriting the destination.\n"
2560 : : "\n"
2561 : : "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
2562 : : " descriptor open to a directory, and the respective path string (src or dst)\n"
2563 : : " should be relative; the path will then be relative to that directory.\n"
2564 : : "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
2565 : : " If they are unavailable, using them will raise a NotImplementedError.");
2566 : :
2567 : : #define OS_REPLACE_METHODDEF \
2568 : : {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
2569 : :
2570 : : static PyObject *
2571 : : os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
2572 : : int dst_dir_fd);
2573 : :
2574 : : static PyObject *
2575 : 159 : os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2576 : : {
2577 : 159 : PyObject *return_value = NULL;
2578 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2579 : :
2580 : : #define NUM_KEYWORDS 4
2581 : : static struct {
2582 : : PyGC_Head _this_is_not_used;
2583 : : PyObject_VAR_HEAD
2584 : : PyObject *ob_item[NUM_KEYWORDS];
2585 : : } _kwtuple = {
2586 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2587 : : .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
2588 : : };
2589 : : #undef NUM_KEYWORDS
2590 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2591 : :
2592 : : #else // !Py_BUILD_CORE
2593 : : # define KWTUPLE NULL
2594 : : #endif // !Py_BUILD_CORE
2595 : :
2596 : : static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
2597 : : static _PyArg_Parser _parser = {
2598 : : .keywords = _keywords,
2599 : : .fname = "replace",
2600 : : .kwtuple = KWTUPLE,
2601 : : };
2602 : : #undef KWTUPLE
2603 : : PyObject *argsbuf[4];
2604 [ - + ]: 159 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
2605 : 159 : path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
2606 : 159 : path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
2607 : 159 : int src_dir_fd = DEFAULT_DIR_FD;
2608 : 159 : int dst_dir_fd = DEFAULT_DIR_FD;
2609 : :
2610 [ + - + - : 159 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
+ - - + ]
2611 [ - + ]: 159 : if (!args) {
2612 : 0 : goto exit;
2613 : : }
2614 [ - + ]: 159 : if (!path_converter(args[0], &src)) {
2615 : 0 : goto exit;
2616 : : }
2617 [ - + ]: 159 : if (!path_converter(args[1], &dst)) {
2618 : 0 : goto exit;
2619 : : }
2620 [ + - ]: 159 : if (!noptargs) {
2621 : 159 : goto skip_optional_kwonly;
2622 : : }
2623 [ # # ]: 0 : if (args[2]) {
2624 [ # # ]: 0 : if (!dir_fd_converter(args[2], &src_dir_fd)) {
2625 : 0 : goto exit;
2626 : : }
2627 [ # # ]: 0 : if (!--noptargs) {
2628 : 0 : goto skip_optional_kwonly;
2629 : : }
2630 : : }
2631 [ # # ]: 0 : if (!dir_fd_converter(args[3], &dst_dir_fd)) {
2632 : 0 : goto exit;
2633 : : }
2634 : 0 : skip_optional_kwonly:
2635 : 159 : return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
2636 : :
2637 : 159 : exit:
2638 : : /* Cleanup for src */
2639 : 159 : path_cleanup(&src);
2640 : : /* Cleanup for dst */
2641 : 159 : path_cleanup(&dst);
2642 : :
2643 : 159 : return return_value;
2644 : : }
2645 : :
2646 : : PyDoc_STRVAR(os_rmdir__doc__,
2647 : : "rmdir($module, /, path, *, dir_fd=None)\n"
2648 : : "--\n"
2649 : : "\n"
2650 : : "Remove a directory.\n"
2651 : : "\n"
2652 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2653 : : " and path should be relative; path will then be relative to that directory.\n"
2654 : : "dir_fd may not be implemented on your platform.\n"
2655 : : " If it is unavailable, using it will raise a NotImplementedError.");
2656 : :
2657 : : #define OS_RMDIR_METHODDEF \
2658 : : {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
2659 : :
2660 : : static PyObject *
2661 : : os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
2662 : :
2663 : : static PyObject *
2664 : 1 : os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2665 : : {
2666 : 1 : PyObject *return_value = NULL;
2667 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2668 : :
2669 : : #define NUM_KEYWORDS 2
2670 : : static struct {
2671 : : PyGC_Head _this_is_not_used;
2672 : : PyObject_VAR_HEAD
2673 : : PyObject *ob_item[NUM_KEYWORDS];
2674 : : } _kwtuple = {
2675 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2676 : : .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
2677 : : };
2678 : : #undef NUM_KEYWORDS
2679 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2680 : :
2681 : : #else // !Py_BUILD_CORE
2682 : : # define KWTUPLE NULL
2683 : : #endif // !Py_BUILD_CORE
2684 : :
2685 : : static const char * const _keywords[] = {"path", "dir_fd", NULL};
2686 : : static _PyArg_Parser _parser = {
2687 : : .keywords = _keywords,
2688 : : .fname = "rmdir",
2689 : : .kwtuple = KWTUPLE,
2690 : : };
2691 : : #undef KWTUPLE
2692 : : PyObject *argsbuf[2];
2693 [ + - ]: 1 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2694 : 1 : path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
2695 : 1 : int dir_fd = DEFAULT_DIR_FD;
2696 : :
2697 [ - + - - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- - - - ]
2698 [ - + ]: 1 : if (!args) {
2699 : 0 : goto exit;
2700 : : }
2701 [ - + ]: 1 : if (!path_converter(args[0], &path)) {
2702 : 0 : goto exit;
2703 : : }
2704 [ - + ]: 1 : if (!noptargs) {
2705 : 0 : goto skip_optional_kwonly;
2706 : : }
2707 [ - + ]: 1 : if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
2708 : 0 : goto exit;
2709 : : }
2710 : 1 : skip_optional_kwonly:
2711 : 1 : return_value = os_rmdir_impl(module, &path, dir_fd);
2712 : :
2713 : 1 : exit:
2714 : : /* Cleanup for path */
2715 : 1 : path_cleanup(&path);
2716 : :
2717 : 1 : return return_value;
2718 : : }
2719 : :
2720 : : #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
2721 : :
2722 : : PyDoc_STRVAR(os_system__doc__,
2723 : : "system($module, /, command)\n"
2724 : : "--\n"
2725 : : "\n"
2726 : : "Execute the command in a subshell.");
2727 : :
2728 : : #define OS_SYSTEM_METHODDEF \
2729 : : {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
2730 : :
2731 : : static long
2732 : : os_system_impl(PyObject *module, const Py_UNICODE *command);
2733 : :
2734 : : static PyObject *
2735 : : os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2736 : : {
2737 : : PyObject *return_value = NULL;
2738 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2739 : :
2740 : : #define NUM_KEYWORDS 1
2741 : : static struct {
2742 : : PyGC_Head _this_is_not_used;
2743 : : PyObject_VAR_HEAD
2744 : : PyObject *ob_item[NUM_KEYWORDS];
2745 : : } _kwtuple = {
2746 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2747 : : .ob_item = { &_Py_ID(command), },
2748 : : };
2749 : : #undef NUM_KEYWORDS
2750 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2751 : :
2752 : : #else // !Py_BUILD_CORE
2753 : : # define KWTUPLE NULL
2754 : : #endif // !Py_BUILD_CORE
2755 : :
2756 : : static const char * const _keywords[] = {"command", NULL};
2757 : : static _PyArg_Parser _parser = {
2758 : : .keywords = _keywords,
2759 : : .fname = "system",
2760 : : .kwtuple = KWTUPLE,
2761 : : };
2762 : : #undef KWTUPLE
2763 : : PyObject *argsbuf[1];
2764 : : const Py_UNICODE *command = NULL;
2765 : : long _return_value;
2766 : :
2767 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
2768 : : if (!args) {
2769 : : goto exit;
2770 : : }
2771 : : if (!PyUnicode_Check(args[0])) {
2772 : : _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
2773 : : goto exit;
2774 : : }
2775 : : command = PyUnicode_AsWideCharString(args[0], NULL);
2776 : : if (command == NULL) {
2777 : : goto exit;
2778 : : }
2779 : : _return_value = os_system_impl(module, command);
2780 : : if ((_return_value == -1) && PyErr_Occurred()) {
2781 : : goto exit;
2782 : : }
2783 : : return_value = PyLong_FromLong(_return_value);
2784 : :
2785 : : exit:
2786 : : /* Cleanup for command */
2787 : : PyMem_Free((void *)command);
2788 : :
2789 : : return return_value;
2790 : : }
2791 : :
2792 : : #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
2793 : :
2794 : : #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
2795 : :
2796 : : PyDoc_STRVAR(os_system__doc__,
2797 : : "system($module, /, command)\n"
2798 : : "--\n"
2799 : : "\n"
2800 : : "Execute the command in a subshell.");
2801 : :
2802 : : #define OS_SYSTEM_METHODDEF \
2803 : : {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
2804 : :
2805 : : static long
2806 : : os_system_impl(PyObject *module, PyObject *command);
2807 : :
2808 : : static PyObject *
2809 : 0 : os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2810 : : {
2811 : 0 : PyObject *return_value = NULL;
2812 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2813 : :
2814 : : #define NUM_KEYWORDS 1
2815 : : static struct {
2816 : : PyGC_Head _this_is_not_used;
2817 : : PyObject_VAR_HEAD
2818 : : PyObject *ob_item[NUM_KEYWORDS];
2819 : : } _kwtuple = {
2820 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2821 : : .ob_item = { &_Py_ID(command), },
2822 : : };
2823 : : #undef NUM_KEYWORDS
2824 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2825 : :
2826 : : #else // !Py_BUILD_CORE
2827 : : # define KWTUPLE NULL
2828 : : #endif // !Py_BUILD_CORE
2829 : :
2830 : : static const char * const _keywords[] = {"command", NULL};
2831 : : static _PyArg_Parser _parser = {
2832 : : .keywords = _keywords,
2833 : : .fname = "system",
2834 : : .kwtuple = KWTUPLE,
2835 : : };
2836 : : #undef KWTUPLE
2837 : : PyObject *argsbuf[1];
2838 : 0 : PyObject *command = NULL;
2839 : : long _return_value;
2840 : :
2841 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
2842 [ # # ]: 0 : if (!args) {
2843 : 0 : goto exit;
2844 : : }
2845 [ # # ]: 0 : if (!PyUnicode_FSConverter(args[0], &command)) {
2846 : 0 : goto exit;
2847 : : }
2848 : 0 : _return_value = os_system_impl(module, command);
2849 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
2850 : 0 : goto exit;
2851 : : }
2852 : 0 : return_value = PyLong_FromLong(_return_value);
2853 : :
2854 : 0 : exit:
2855 : : /* Cleanup for command */
2856 : 0 : Py_XDECREF(command);
2857 : :
2858 : 0 : return return_value;
2859 : : }
2860 : :
2861 : : #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
2862 : :
2863 : : #if defined(HAVE_UMASK)
2864 : :
2865 : : PyDoc_STRVAR(os_umask__doc__,
2866 : : "umask($module, mask, /)\n"
2867 : : "--\n"
2868 : : "\n"
2869 : : "Set the current numeric umask and return the previous umask.");
2870 : :
2871 : : #define OS_UMASK_METHODDEF \
2872 : : {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
2873 : :
2874 : : static PyObject *
2875 : : os_umask_impl(PyObject *module, int mask);
2876 : :
2877 : : static PyObject *
2878 : 0 : os_umask(PyObject *module, PyObject *arg)
2879 : : {
2880 : 0 : PyObject *return_value = NULL;
2881 : : int mask;
2882 : :
2883 : 0 : mask = _PyLong_AsInt(arg);
2884 [ # # # # ]: 0 : if (mask == -1 && PyErr_Occurred()) {
2885 : 0 : goto exit;
2886 : : }
2887 : 0 : return_value = os_umask_impl(module, mask);
2888 : :
2889 : 0 : exit:
2890 : 0 : return return_value;
2891 : : }
2892 : :
2893 : : #endif /* defined(HAVE_UMASK) */
2894 : :
2895 : : PyDoc_STRVAR(os_unlink__doc__,
2896 : : "unlink($module, /, path, *, dir_fd=None)\n"
2897 : : "--\n"
2898 : : "\n"
2899 : : "Remove a file (same as remove()).\n"
2900 : : "\n"
2901 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2902 : : " and path should be relative; path will then be relative to that directory.\n"
2903 : : "dir_fd may not be implemented on your platform.\n"
2904 : : " If it is unavailable, using it will raise a NotImplementedError.");
2905 : :
2906 : : #define OS_UNLINK_METHODDEF \
2907 : : {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
2908 : :
2909 : : static PyObject *
2910 : : os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
2911 : :
2912 : : static PyObject *
2913 : 0 : os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2914 : : {
2915 : 0 : PyObject *return_value = NULL;
2916 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2917 : :
2918 : : #define NUM_KEYWORDS 2
2919 : : static struct {
2920 : : PyGC_Head _this_is_not_used;
2921 : : PyObject_VAR_HEAD
2922 : : PyObject *ob_item[NUM_KEYWORDS];
2923 : : } _kwtuple = {
2924 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2925 : : .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
2926 : : };
2927 : : #undef NUM_KEYWORDS
2928 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
2929 : :
2930 : : #else // !Py_BUILD_CORE
2931 : : # define KWTUPLE NULL
2932 : : #endif // !Py_BUILD_CORE
2933 : :
2934 : : static const char * const _keywords[] = {"path", "dir_fd", NULL};
2935 : : static _PyArg_Parser _parser = {
2936 : : .keywords = _keywords,
2937 : : .fname = "unlink",
2938 : : .kwtuple = KWTUPLE,
2939 : : };
2940 : : #undef KWTUPLE
2941 : : PyObject *argsbuf[2];
2942 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
2943 : 0 : path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
2944 : 0 : int dir_fd = DEFAULT_DIR_FD;
2945 : :
2946 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
2947 [ # # ]: 0 : if (!args) {
2948 : 0 : goto exit;
2949 : : }
2950 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
2951 : 0 : goto exit;
2952 : : }
2953 [ # # ]: 0 : if (!noptargs) {
2954 : 0 : goto skip_optional_kwonly;
2955 : : }
2956 [ # # ]: 0 : if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
2957 : 0 : goto exit;
2958 : : }
2959 : 0 : skip_optional_kwonly:
2960 : 0 : return_value = os_unlink_impl(module, &path, dir_fd);
2961 : :
2962 : 0 : exit:
2963 : : /* Cleanup for path */
2964 : 0 : path_cleanup(&path);
2965 : :
2966 : 0 : return return_value;
2967 : : }
2968 : :
2969 : : PyDoc_STRVAR(os_remove__doc__,
2970 : : "remove($module, /, path, *, dir_fd=None)\n"
2971 : : "--\n"
2972 : : "\n"
2973 : : "Remove a file (same as unlink()).\n"
2974 : : "\n"
2975 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
2976 : : " and path should be relative; path will then be relative to that directory.\n"
2977 : : "dir_fd may not be implemented on your platform.\n"
2978 : : " If it is unavailable, using it will raise a NotImplementedError.");
2979 : :
2980 : : #define OS_REMOVE_METHODDEF \
2981 : : {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
2982 : :
2983 : : static PyObject *
2984 : : os_remove_impl(PyObject *module, path_t *path, int dir_fd);
2985 : :
2986 : : static PyObject *
2987 : 0 : os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
2988 : : {
2989 : 0 : PyObject *return_value = NULL;
2990 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2991 : :
2992 : : #define NUM_KEYWORDS 2
2993 : : static struct {
2994 : : PyGC_Head _this_is_not_used;
2995 : : PyObject_VAR_HEAD
2996 : : PyObject *ob_item[NUM_KEYWORDS];
2997 : : } _kwtuple = {
2998 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
2999 : : .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
3000 : : };
3001 : : #undef NUM_KEYWORDS
3002 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3003 : :
3004 : : #else // !Py_BUILD_CORE
3005 : : # define KWTUPLE NULL
3006 : : #endif // !Py_BUILD_CORE
3007 : :
3008 : : static const char * const _keywords[] = {"path", "dir_fd", NULL};
3009 : : static _PyArg_Parser _parser = {
3010 : : .keywords = _keywords,
3011 : : .fname = "remove",
3012 : : .kwtuple = KWTUPLE,
3013 : : };
3014 : : #undef KWTUPLE
3015 : : PyObject *argsbuf[2];
3016 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3017 : 0 : path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
3018 : 0 : int dir_fd = DEFAULT_DIR_FD;
3019 : :
3020 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
3021 [ # # ]: 0 : if (!args) {
3022 : 0 : goto exit;
3023 : : }
3024 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
3025 : 0 : goto exit;
3026 : : }
3027 [ # # ]: 0 : if (!noptargs) {
3028 : 0 : goto skip_optional_kwonly;
3029 : : }
3030 [ # # ]: 0 : if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
3031 : 0 : goto exit;
3032 : : }
3033 : 0 : skip_optional_kwonly:
3034 : 0 : return_value = os_remove_impl(module, &path, dir_fd);
3035 : :
3036 : 0 : exit:
3037 : : /* Cleanup for path */
3038 : 0 : path_cleanup(&path);
3039 : :
3040 : 0 : return return_value;
3041 : : }
3042 : :
3043 : : #if defined(HAVE_UNAME)
3044 : :
3045 : : PyDoc_STRVAR(os_uname__doc__,
3046 : : "uname($module, /)\n"
3047 : : "--\n"
3048 : : "\n"
3049 : : "Return an object identifying the current operating system.\n"
3050 : : "\n"
3051 : : "The object behaves like a named tuple with the following fields:\n"
3052 : : " (sysname, nodename, release, version, machine)");
3053 : :
3054 : : #define OS_UNAME_METHODDEF \
3055 : : {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
3056 : :
3057 : : static PyObject *
3058 : : os_uname_impl(PyObject *module);
3059 : :
3060 : : static PyObject *
3061 : 3 : os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
3062 : : {
3063 : 3 : return os_uname_impl(module);
3064 : : }
3065 : :
3066 : : #endif /* defined(HAVE_UNAME) */
3067 : :
3068 : : PyDoc_STRVAR(os_utime__doc__,
3069 : : "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
3070 : : " dir_fd=None, follow_symlinks=True)\n"
3071 : : "--\n"
3072 : : "\n"
3073 : : "Set the access and modified time of path.\n"
3074 : : "\n"
3075 : : "path may always be specified as a string.\n"
3076 : : "On some platforms, path may also be specified as an open file descriptor.\n"
3077 : : " If this functionality is unavailable, using it raises an exception.\n"
3078 : : "\n"
3079 : : "If times is not None, it must be a tuple (atime, mtime);\n"
3080 : : " atime and mtime should be expressed as float seconds since the epoch.\n"
3081 : : "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
3082 : : " atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
3083 : : " since the epoch.\n"
3084 : : "If times is None and ns is unspecified, utime uses the current time.\n"
3085 : : "Specifying tuples for both times and ns is an error.\n"
3086 : : "\n"
3087 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
3088 : : " and path should be relative; path will then be relative to that directory.\n"
3089 : : "If follow_symlinks is False, and the last element of the path is a symbolic\n"
3090 : : " link, utime will modify the symbolic link itself instead of the file the\n"
3091 : : " link points to.\n"
3092 : : "It is an error to use dir_fd or follow_symlinks when specifying path\n"
3093 : : " as an open file descriptor.\n"
3094 : : "dir_fd and follow_symlinks may not be available on your platform.\n"
3095 : : " If they are unavailable, using them will raise a NotImplementedError.");
3096 : :
3097 : : #define OS_UTIME_METHODDEF \
3098 : : {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
3099 : :
3100 : : static PyObject *
3101 : : os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
3102 : : int dir_fd, int follow_symlinks);
3103 : :
3104 : : static PyObject *
3105 : 0 : os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3106 : : {
3107 : 0 : PyObject *return_value = NULL;
3108 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3109 : :
3110 : : #define NUM_KEYWORDS 5
3111 : : static struct {
3112 : : PyGC_Head _this_is_not_used;
3113 : : PyObject_VAR_HEAD
3114 : : PyObject *ob_item[NUM_KEYWORDS];
3115 : : } _kwtuple = {
3116 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3117 : : .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
3118 : : };
3119 : : #undef NUM_KEYWORDS
3120 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3121 : :
3122 : : #else // !Py_BUILD_CORE
3123 : : # define KWTUPLE NULL
3124 : : #endif // !Py_BUILD_CORE
3125 : :
3126 : : static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
3127 : : static _PyArg_Parser _parser = {
3128 : : .keywords = _keywords,
3129 : : .fname = "utime",
3130 : : .kwtuple = KWTUPLE,
3131 : : };
3132 : : #undef KWTUPLE
3133 : : PyObject *argsbuf[5];
3134 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
3135 : 0 : path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
3136 : 0 : PyObject *times = Py_None;
3137 : 0 : PyObject *ns = NULL;
3138 : 0 : int dir_fd = DEFAULT_DIR_FD;
3139 : 0 : int follow_symlinks = 1;
3140 : :
3141 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
3142 [ # # ]: 0 : if (!args) {
3143 : 0 : goto exit;
3144 : : }
3145 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
3146 : 0 : goto exit;
3147 : : }
3148 [ # # ]: 0 : if (!noptargs) {
3149 : 0 : goto skip_optional_pos;
3150 : : }
3151 [ # # ]: 0 : if (args[1]) {
3152 : 0 : times = args[1];
3153 [ # # ]: 0 : if (!--noptargs) {
3154 : 0 : goto skip_optional_pos;
3155 : : }
3156 : : }
3157 : 0 : skip_optional_pos:
3158 [ # # ]: 0 : if (!noptargs) {
3159 : 0 : goto skip_optional_kwonly;
3160 : : }
3161 [ # # ]: 0 : if (args[2]) {
3162 : 0 : ns = args[2];
3163 [ # # ]: 0 : if (!--noptargs) {
3164 : 0 : goto skip_optional_kwonly;
3165 : : }
3166 : : }
3167 [ # # ]: 0 : if (args[3]) {
3168 [ # # ]: 0 : if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
3169 : 0 : goto exit;
3170 : : }
3171 [ # # ]: 0 : if (!--noptargs) {
3172 : 0 : goto skip_optional_kwonly;
3173 : : }
3174 : : }
3175 : 0 : follow_symlinks = PyObject_IsTrue(args[4]);
3176 [ # # ]: 0 : if (follow_symlinks < 0) {
3177 : 0 : goto exit;
3178 : : }
3179 : 0 : skip_optional_kwonly:
3180 : 0 : return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
3181 : :
3182 : 0 : exit:
3183 : : /* Cleanup for path */
3184 : 0 : path_cleanup(&path);
3185 : :
3186 : 0 : return return_value;
3187 : : }
3188 : :
3189 : : PyDoc_STRVAR(os__exit__doc__,
3190 : : "_exit($module, /, status)\n"
3191 : : "--\n"
3192 : : "\n"
3193 : : "Exit to the system with specified status, without normal exit processing.");
3194 : :
3195 : : #define OS__EXIT_METHODDEF \
3196 : : {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
3197 : :
3198 : : static PyObject *
3199 : : os__exit_impl(PyObject *module, int status);
3200 : :
3201 : : static PyObject *
3202 : 0 : os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3203 : : {
3204 : 0 : PyObject *return_value = NULL;
3205 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3206 : :
3207 : : #define NUM_KEYWORDS 1
3208 : : static struct {
3209 : : PyGC_Head _this_is_not_used;
3210 : : PyObject_VAR_HEAD
3211 : : PyObject *ob_item[NUM_KEYWORDS];
3212 : : } _kwtuple = {
3213 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3214 : : .ob_item = { &_Py_ID(status), },
3215 : : };
3216 : : #undef NUM_KEYWORDS
3217 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3218 : :
3219 : : #else // !Py_BUILD_CORE
3220 : : # define KWTUPLE NULL
3221 : : #endif // !Py_BUILD_CORE
3222 : :
3223 : : static const char * const _keywords[] = {"status", NULL};
3224 : : static _PyArg_Parser _parser = {
3225 : : .keywords = _keywords,
3226 : : .fname = "_exit",
3227 : : .kwtuple = KWTUPLE,
3228 : : };
3229 : : #undef KWTUPLE
3230 : : PyObject *argsbuf[1];
3231 : : int status;
3232 : :
3233 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
3234 [ # # ]: 0 : if (!args) {
3235 : 0 : goto exit;
3236 : : }
3237 : 0 : status = _PyLong_AsInt(args[0]);
3238 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
3239 : 0 : goto exit;
3240 : : }
3241 : 0 : return_value = os__exit_impl(module, status);
3242 : :
3243 : 0 : exit:
3244 : 0 : return return_value;
3245 : : }
3246 : :
3247 : : #if defined(HAVE_EXECV)
3248 : :
3249 : : PyDoc_STRVAR(os_execv__doc__,
3250 : : "execv($module, path, argv, /)\n"
3251 : : "--\n"
3252 : : "\n"
3253 : : "Execute an executable path with arguments, replacing current process.\n"
3254 : : "\n"
3255 : : " path\n"
3256 : : " Path of executable file.\n"
3257 : : " argv\n"
3258 : : " Tuple or list of strings.");
3259 : :
3260 : : #define OS_EXECV_METHODDEF \
3261 : : {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
3262 : :
3263 : : static PyObject *
3264 : : os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
3265 : :
3266 : : static PyObject *
3267 : 0 : os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3268 : : {
3269 : 0 : PyObject *return_value = NULL;
3270 : 0 : path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
3271 : : PyObject *argv;
3272 : :
3273 [ # # # # : 0 : if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
# # ]
3274 : 0 : goto exit;
3275 : : }
3276 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
3277 : 0 : goto exit;
3278 : : }
3279 : 0 : argv = args[1];
3280 : 0 : return_value = os_execv_impl(module, &path, argv);
3281 : :
3282 : 0 : exit:
3283 : : /* Cleanup for path */
3284 : 0 : path_cleanup(&path);
3285 : :
3286 : 0 : return return_value;
3287 : : }
3288 : :
3289 : : #endif /* defined(HAVE_EXECV) */
3290 : :
3291 : : #if defined(HAVE_EXECV)
3292 : :
3293 : : PyDoc_STRVAR(os_execve__doc__,
3294 : : "execve($module, /, path, argv, env)\n"
3295 : : "--\n"
3296 : : "\n"
3297 : : "Execute an executable path with arguments, replacing current process.\n"
3298 : : "\n"
3299 : : " path\n"
3300 : : " Path of executable file.\n"
3301 : : " argv\n"
3302 : : " Tuple or list of strings.\n"
3303 : : " env\n"
3304 : : " Dictionary of strings mapping to strings.");
3305 : :
3306 : : #define OS_EXECVE_METHODDEF \
3307 : : {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
3308 : :
3309 : : static PyObject *
3310 : : os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
3311 : :
3312 : : static PyObject *
3313 : 0 : os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3314 : : {
3315 : 0 : PyObject *return_value = NULL;
3316 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3317 : :
3318 : : #define NUM_KEYWORDS 3
3319 : : static struct {
3320 : : PyGC_Head _this_is_not_used;
3321 : : PyObject_VAR_HEAD
3322 : : PyObject *ob_item[NUM_KEYWORDS];
3323 : : } _kwtuple = {
3324 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3325 : : .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
3326 : : };
3327 : : #undef NUM_KEYWORDS
3328 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3329 : :
3330 : : #else // !Py_BUILD_CORE
3331 : : # define KWTUPLE NULL
3332 : : #endif // !Py_BUILD_CORE
3333 : :
3334 : : static const char * const _keywords[] = {"path", "argv", "env", NULL};
3335 : : static _PyArg_Parser _parser = {
3336 : : .keywords = _keywords,
3337 : : .fname = "execve",
3338 : : .kwtuple = KWTUPLE,
3339 : : };
3340 : : #undef KWTUPLE
3341 : : PyObject *argsbuf[3];
3342 : 0 : path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
3343 : : PyObject *argv;
3344 : : PyObject *env;
3345 : :
3346 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
3347 [ # # ]: 0 : if (!args) {
3348 : 0 : goto exit;
3349 : : }
3350 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
3351 : 0 : goto exit;
3352 : : }
3353 : 0 : argv = args[1];
3354 : 0 : env = args[2];
3355 : 0 : return_value = os_execve_impl(module, &path, argv, env);
3356 : :
3357 : 0 : exit:
3358 : : /* Cleanup for path */
3359 : 0 : path_cleanup(&path);
3360 : :
3361 : 0 : return return_value;
3362 : : }
3363 : :
3364 : : #endif /* defined(HAVE_EXECV) */
3365 : :
3366 : : #if defined(HAVE_POSIX_SPAWN)
3367 : :
3368 : : PyDoc_STRVAR(os_posix_spawn__doc__,
3369 : : "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
3370 : : " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
3371 : : " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
3372 : : "--\n"
3373 : : "\n"
3374 : : "Execute the program specified by path in a new process.\n"
3375 : : "\n"
3376 : : " path\n"
3377 : : " Path of executable file.\n"
3378 : : " argv\n"
3379 : : " Tuple or list of strings.\n"
3380 : : " env\n"
3381 : : " Dictionary of strings mapping to strings.\n"
3382 : : " file_actions\n"
3383 : : " A sequence of file action tuples.\n"
3384 : : " setpgroup\n"
3385 : : " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3386 : : " resetids\n"
3387 : : " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
3388 : : " setsid\n"
3389 : : " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
3390 : : " setsigmask\n"
3391 : : " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3392 : : " setsigdef\n"
3393 : : " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3394 : : " scheduler\n"
3395 : : " A tuple with the scheduler policy (optional) and parameters.");
3396 : :
3397 : : #define OS_POSIX_SPAWN_METHODDEF \
3398 : : {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
3399 : :
3400 : : static PyObject *
3401 : : os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
3402 : : PyObject *env, PyObject *file_actions,
3403 : : PyObject *setpgroup, int resetids, int setsid,
3404 : : PyObject *setsigmask, PyObject *setsigdef,
3405 : : PyObject *scheduler);
3406 : :
3407 : : static PyObject *
3408 : 0 : os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3409 : : {
3410 : 0 : PyObject *return_value = NULL;
3411 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3412 : :
3413 : : #define NUM_KEYWORDS 7
3414 : : static struct {
3415 : : PyGC_Head _this_is_not_used;
3416 : : PyObject_VAR_HEAD
3417 : : PyObject *ob_item[NUM_KEYWORDS];
3418 : : } _kwtuple = {
3419 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3420 : : .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
3421 : : };
3422 : : #undef NUM_KEYWORDS
3423 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3424 : :
3425 : : #else // !Py_BUILD_CORE
3426 : : # define KWTUPLE NULL
3427 : : #endif // !Py_BUILD_CORE
3428 : :
3429 : : static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3430 : : static _PyArg_Parser _parser = {
3431 : : .keywords = _keywords,
3432 : : .fname = "posix_spawn",
3433 : : .kwtuple = KWTUPLE,
3434 : : };
3435 : : #undef KWTUPLE
3436 : : PyObject *argsbuf[10];
3437 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
3438 : 0 : path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
3439 : : PyObject *argv;
3440 : : PyObject *env;
3441 : 0 : PyObject *file_actions = NULL;
3442 : 0 : PyObject *setpgroup = NULL;
3443 : 0 : int resetids = 0;
3444 : 0 : int setsid = 0;
3445 : 0 : PyObject *setsigmask = NULL;
3446 : 0 : PyObject *setsigdef = NULL;
3447 : 0 : PyObject *scheduler = NULL;
3448 : :
3449 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
3450 [ # # ]: 0 : if (!args) {
3451 : 0 : goto exit;
3452 : : }
3453 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
3454 : 0 : goto exit;
3455 : : }
3456 : 0 : argv = args[1];
3457 : 0 : env = args[2];
3458 [ # # ]: 0 : if (!noptargs) {
3459 : 0 : goto skip_optional_kwonly;
3460 : : }
3461 [ # # ]: 0 : if (args[3]) {
3462 : 0 : file_actions = args[3];
3463 [ # # ]: 0 : if (!--noptargs) {
3464 : 0 : goto skip_optional_kwonly;
3465 : : }
3466 : : }
3467 [ # # ]: 0 : if (args[4]) {
3468 : 0 : setpgroup = args[4];
3469 [ # # ]: 0 : if (!--noptargs) {
3470 : 0 : goto skip_optional_kwonly;
3471 : : }
3472 : : }
3473 [ # # ]: 0 : if (args[5]) {
3474 : 0 : resetids = PyObject_IsTrue(args[5]);
3475 [ # # ]: 0 : if (resetids < 0) {
3476 : 0 : goto exit;
3477 : : }
3478 [ # # ]: 0 : if (!--noptargs) {
3479 : 0 : goto skip_optional_kwonly;
3480 : : }
3481 : : }
3482 [ # # ]: 0 : if (args[6]) {
3483 : 0 : setsid = PyObject_IsTrue(args[6]);
3484 [ # # ]: 0 : if (setsid < 0) {
3485 : 0 : goto exit;
3486 : : }
3487 [ # # ]: 0 : if (!--noptargs) {
3488 : 0 : goto skip_optional_kwonly;
3489 : : }
3490 : : }
3491 [ # # ]: 0 : if (args[7]) {
3492 : 0 : setsigmask = args[7];
3493 [ # # ]: 0 : if (!--noptargs) {
3494 : 0 : goto skip_optional_kwonly;
3495 : : }
3496 : : }
3497 [ # # ]: 0 : if (args[8]) {
3498 : 0 : setsigdef = args[8];
3499 [ # # ]: 0 : if (!--noptargs) {
3500 : 0 : goto skip_optional_kwonly;
3501 : : }
3502 : : }
3503 : 0 : scheduler = args[9];
3504 : 0 : skip_optional_kwonly:
3505 : 0 : return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
3506 : :
3507 : 0 : exit:
3508 : : /* Cleanup for path */
3509 : 0 : path_cleanup(&path);
3510 : :
3511 : 0 : return return_value;
3512 : : }
3513 : :
3514 : : #endif /* defined(HAVE_POSIX_SPAWN) */
3515 : :
3516 : : #if defined(HAVE_POSIX_SPAWNP)
3517 : :
3518 : : PyDoc_STRVAR(os_posix_spawnp__doc__,
3519 : : "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
3520 : : " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
3521 : : " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
3522 : : "--\n"
3523 : : "\n"
3524 : : "Execute the program specified by path in a new process.\n"
3525 : : "\n"
3526 : : " path\n"
3527 : : " Path of executable file.\n"
3528 : : " argv\n"
3529 : : " Tuple or list of strings.\n"
3530 : : " env\n"
3531 : : " Dictionary of strings mapping to strings.\n"
3532 : : " file_actions\n"
3533 : : " A sequence of file action tuples.\n"
3534 : : " setpgroup\n"
3535 : : " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
3536 : : " resetids\n"
3537 : : " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
3538 : : " setsid\n"
3539 : : " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
3540 : : " setsigmask\n"
3541 : : " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
3542 : : " setsigdef\n"
3543 : : " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
3544 : : " scheduler\n"
3545 : : " A tuple with the scheduler policy (optional) and parameters.");
3546 : :
3547 : : #define OS_POSIX_SPAWNP_METHODDEF \
3548 : : {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
3549 : :
3550 : : static PyObject *
3551 : : os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
3552 : : PyObject *env, PyObject *file_actions,
3553 : : PyObject *setpgroup, int resetids, int setsid,
3554 : : PyObject *setsigmask, PyObject *setsigdef,
3555 : : PyObject *scheduler);
3556 : :
3557 : : static PyObject *
3558 : 0 : os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3559 : : {
3560 : 0 : PyObject *return_value = NULL;
3561 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3562 : :
3563 : : #define NUM_KEYWORDS 7
3564 : : static struct {
3565 : : PyGC_Head _this_is_not_used;
3566 : : PyObject_VAR_HEAD
3567 : : PyObject *ob_item[NUM_KEYWORDS];
3568 : : } _kwtuple = {
3569 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3570 : : .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
3571 : : };
3572 : : #undef NUM_KEYWORDS
3573 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3574 : :
3575 : : #else // !Py_BUILD_CORE
3576 : : # define KWTUPLE NULL
3577 : : #endif // !Py_BUILD_CORE
3578 : :
3579 : : static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
3580 : : static _PyArg_Parser _parser = {
3581 : : .keywords = _keywords,
3582 : : .fname = "posix_spawnp",
3583 : : .kwtuple = KWTUPLE,
3584 : : };
3585 : : #undef KWTUPLE
3586 : : PyObject *argsbuf[10];
3587 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
3588 : 0 : path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0);
3589 : : PyObject *argv;
3590 : : PyObject *env;
3591 : 0 : PyObject *file_actions = NULL;
3592 : 0 : PyObject *setpgroup = NULL;
3593 : 0 : int resetids = 0;
3594 : 0 : int setsid = 0;
3595 : 0 : PyObject *setsigmask = NULL;
3596 : 0 : PyObject *setsigdef = NULL;
3597 : 0 : PyObject *scheduler = NULL;
3598 : :
3599 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
# # # # ]
3600 [ # # ]: 0 : if (!args) {
3601 : 0 : goto exit;
3602 : : }
3603 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
3604 : 0 : goto exit;
3605 : : }
3606 : 0 : argv = args[1];
3607 : 0 : env = args[2];
3608 [ # # ]: 0 : if (!noptargs) {
3609 : 0 : goto skip_optional_kwonly;
3610 : : }
3611 [ # # ]: 0 : if (args[3]) {
3612 : 0 : file_actions = args[3];
3613 [ # # ]: 0 : if (!--noptargs) {
3614 : 0 : goto skip_optional_kwonly;
3615 : : }
3616 : : }
3617 [ # # ]: 0 : if (args[4]) {
3618 : 0 : setpgroup = args[4];
3619 [ # # ]: 0 : if (!--noptargs) {
3620 : 0 : goto skip_optional_kwonly;
3621 : : }
3622 : : }
3623 [ # # ]: 0 : if (args[5]) {
3624 : 0 : resetids = PyObject_IsTrue(args[5]);
3625 [ # # ]: 0 : if (resetids < 0) {
3626 : 0 : goto exit;
3627 : : }
3628 [ # # ]: 0 : if (!--noptargs) {
3629 : 0 : goto skip_optional_kwonly;
3630 : : }
3631 : : }
3632 [ # # ]: 0 : if (args[6]) {
3633 : 0 : setsid = PyObject_IsTrue(args[6]);
3634 [ # # ]: 0 : if (setsid < 0) {
3635 : 0 : goto exit;
3636 : : }
3637 [ # # ]: 0 : if (!--noptargs) {
3638 : 0 : goto skip_optional_kwonly;
3639 : : }
3640 : : }
3641 [ # # ]: 0 : if (args[7]) {
3642 : 0 : setsigmask = args[7];
3643 [ # # ]: 0 : if (!--noptargs) {
3644 : 0 : goto skip_optional_kwonly;
3645 : : }
3646 : : }
3647 [ # # ]: 0 : if (args[8]) {
3648 : 0 : setsigdef = args[8];
3649 [ # # ]: 0 : if (!--noptargs) {
3650 : 0 : goto skip_optional_kwonly;
3651 : : }
3652 : : }
3653 : 0 : scheduler = args[9];
3654 : 0 : skip_optional_kwonly:
3655 : 0 : return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
3656 : :
3657 : 0 : exit:
3658 : : /* Cleanup for path */
3659 : 0 : path_cleanup(&path);
3660 : :
3661 : 0 : return return_value;
3662 : : }
3663 : :
3664 : : #endif /* defined(HAVE_POSIX_SPAWNP) */
3665 : :
3666 : : #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
3667 : :
3668 : : PyDoc_STRVAR(os_spawnv__doc__,
3669 : : "spawnv($module, mode, path, argv, /)\n"
3670 : : "--\n"
3671 : : "\n"
3672 : : "Execute the program specified by path in a new process.\n"
3673 : : "\n"
3674 : : " mode\n"
3675 : : " Mode of process creation.\n"
3676 : : " path\n"
3677 : : " Path of executable file.\n"
3678 : : " argv\n"
3679 : : " Tuple or list of strings.");
3680 : :
3681 : : #define OS_SPAWNV_METHODDEF \
3682 : : {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
3683 : :
3684 : : static PyObject *
3685 : : os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
3686 : :
3687 : : static PyObject *
3688 : : os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3689 : : {
3690 : : PyObject *return_value = NULL;
3691 : : int mode;
3692 : : path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
3693 : : PyObject *argv;
3694 : :
3695 : : if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
3696 : : goto exit;
3697 : : }
3698 : : mode = _PyLong_AsInt(args[0]);
3699 : : if (mode == -1 && PyErr_Occurred()) {
3700 : : goto exit;
3701 : : }
3702 : : if (!path_converter(args[1], &path)) {
3703 : : goto exit;
3704 : : }
3705 : : argv = args[2];
3706 : : return_value = os_spawnv_impl(module, mode, &path, argv);
3707 : :
3708 : : exit:
3709 : : /* Cleanup for path */
3710 : : path_cleanup(&path);
3711 : :
3712 : : return return_value;
3713 : : }
3714 : :
3715 : : #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
3716 : :
3717 : : #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
3718 : :
3719 : : PyDoc_STRVAR(os_spawnve__doc__,
3720 : : "spawnve($module, mode, path, argv, env, /)\n"
3721 : : "--\n"
3722 : : "\n"
3723 : : "Execute the program specified by path in a new process.\n"
3724 : : "\n"
3725 : : " mode\n"
3726 : : " Mode of process creation.\n"
3727 : : " path\n"
3728 : : " Path of executable file.\n"
3729 : : " argv\n"
3730 : : " Tuple or list of strings.\n"
3731 : : " env\n"
3732 : : " Dictionary of strings mapping to strings.");
3733 : :
3734 : : #define OS_SPAWNVE_METHODDEF \
3735 : : {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
3736 : :
3737 : : static PyObject *
3738 : : os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
3739 : : PyObject *env);
3740 : :
3741 : : static PyObject *
3742 : : os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
3743 : : {
3744 : : PyObject *return_value = NULL;
3745 : : int mode;
3746 : : path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
3747 : : PyObject *argv;
3748 : : PyObject *env;
3749 : :
3750 : : if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
3751 : : goto exit;
3752 : : }
3753 : : mode = _PyLong_AsInt(args[0]);
3754 : : if (mode == -1 && PyErr_Occurred()) {
3755 : : goto exit;
3756 : : }
3757 : : if (!path_converter(args[1], &path)) {
3758 : : goto exit;
3759 : : }
3760 : : argv = args[2];
3761 : : env = args[3];
3762 : : return_value = os_spawnve_impl(module, mode, &path, argv, env);
3763 : :
3764 : : exit:
3765 : : /* Cleanup for path */
3766 : : path_cleanup(&path);
3767 : :
3768 : : return return_value;
3769 : : }
3770 : :
3771 : : #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
3772 : :
3773 : : #if defined(HAVE_FORK)
3774 : :
3775 : : PyDoc_STRVAR(os_register_at_fork__doc__,
3776 : : "register_at_fork($module, /, *, before=<unrepresentable>,\n"
3777 : : " after_in_child=<unrepresentable>,\n"
3778 : : " after_in_parent=<unrepresentable>)\n"
3779 : : "--\n"
3780 : : "\n"
3781 : : "Register callables to be called when forking a new process.\n"
3782 : : "\n"
3783 : : " before\n"
3784 : : " A callable to be called in the parent before the fork() syscall.\n"
3785 : : " after_in_child\n"
3786 : : " A callable to be called in the child after fork().\n"
3787 : : " after_in_parent\n"
3788 : : " A callable to be called in the parent after fork().\n"
3789 : : "\n"
3790 : : "\'before\' callbacks are called in reverse order.\n"
3791 : : "\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
3792 : :
3793 : : #define OS_REGISTER_AT_FORK_METHODDEF \
3794 : : {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
3795 : :
3796 : : static PyObject *
3797 : : os_register_at_fork_impl(PyObject *module, PyObject *before,
3798 : : PyObject *after_in_child, PyObject *after_in_parent);
3799 : :
3800 : : static PyObject *
3801 : 7 : os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3802 : : {
3803 : 7 : PyObject *return_value = NULL;
3804 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3805 : :
3806 : : #define NUM_KEYWORDS 3
3807 : : static struct {
3808 : : PyGC_Head _this_is_not_used;
3809 : : PyObject_VAR_HEAD
3810 : : PyObject *ob_item[NUM_KEYWORDS];
3811 : : } _kwtuple = {
3812 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3813 : : .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
3814 : : };
3815 : : #undef NUM_KEYWORDS
3816 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3817 : :
3818 : : #else // !Py_BUILD_CORE
3819 : : # define KWTUPLE NULL
3820 : : #endif // !Py_BUILD_CORE
3821 : :
3822 : : static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
3823 : : static _PyArg_Parser _parser = {
3824 : : .keywords = _keywords,
3825 : : .fname = "register_at_fork",
3826 : : .kwtuple = KWTUPLE,
3827 : : };
3828 : : #undef KWTUPLE
3829 : : PyObject *argsbuf[3];
3830 [ + - ]: 7 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
3831 : 7 : PyObject *before = NULL;
3832 : 7 : PyObject *after_in_child = NULL;
3833 : 7 : PyObject *after_in_parent = NULL;
3834 : :
3835 [ - + - - : 7 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
- - - - ]
3836 [ - + ]: 7 : if (!args) {
3837 : 0 : goto exit;
3838 : : }
3839 [ - + ]: 7 : if (!noptargs) {
3840 : 0 : goto skip_optional_kwonly;
3841 : : }
3842 [ + + ]: 7 : if (args[0]) {
3843 : 1 : before = args[0];
3844 [ - + ]: 1 : if (!--noptargs) {
3845 : 0 : goto skip_optional_kwonly;
3846 : : }
3847 : : }
3848 [ + - ]: 7 : if (args[1]) {
3849 : 7 : after_in_child = args[1];
3850 [ + + ]: 7 : if (!--noptargs) {
3851 : 6 : goto skip_optional_kwonly;
3852 : : }
3853 : : }
3854 : 1 : after_in_parent = args[2];
3855 : 7 : skip_optional_kwonly:
3856 : 7 : return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
3857 : :
3858 : 7 : exit:
3859 : 7 : return return_value;
3860 : : }
3861 : :
3862 : : #endif /* defined(HAVE_FORK) */
3863 : :
3864 : : #if defined(HAVE_FORK1)
3865 : :
3866 : : PyDoc_STRVAR(os_fork1__doc__,
3867 : : "fork1($module, /)\n"
3868 : : "--\n"
3869 : : "\n"
3870 : : "Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
3871 : : "\n"
3872 : : "Return 0 to child process and PID of child to parent process.");
3873 : :
3874 : : #define OS_FORK1_METHODDEF \
3875 : : {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
3876 : :
3877 : : static PyObject *
3878 : : os_fork1_impl(PyObject *module);
3879 : :
3880 : : static PyObject *
3881 : : os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
3882 : : {
3883 : : return os_fork1_impl(module);
3884 : : }
3885 : :
3886 : : #endif /* defined(HAVE_FORK1) */
3887 : :
3888 : : #if defined(HAVE_FORK)
3889 : :
3890 : : PyDoc_STRVAR(os_fork__doc__,
3891 : : "fork($module, /)\n"
3892 : : "--\n"
3893 : : "\n"
3894 : : "Fork a child process.\n"
3895 : : "\n"
3896 : : "Return 0 to child process and PID of child to parent process.");
3897 : :
3898 : : #define OS_FORK_METHODDEF \
3899 : : {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
3900 : :
3901 : : static PyObject *
3902 : : os_fork_impl(PyObject *module);
3903 : :
3904 : : static PyObject *
3905 : 0 : os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
3906 : : {
3907 : 0 : return os_fork_impl(module);
3908 : : }
3909 : :
3910 : : #endif /* defined(HAVE_FORK) */
3911 : :
3912 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
3913 : :
3914 : : PyDoc_STRVAR(os_sched_get_priority_max__doc__,
3915 : : "sched_get_priority_max($module, /, policy)\n"
3916 : : "--\n"
3917 : : "\n"
3918 : : "Get the maximum scheduling priority for policy.");
3919 : :
3920 : : #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
3921 : : {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
3922 : :
3923 : : static PyObject *
3924 : : os_sched_get_priority_max_impl(PyObject *module, int policy);
3925 : :
3926 : : static PyObject *
3927 : 0 : os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3928 : : {
3929 : 0 : PyObject *return_value = NULL;
3930 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3931 : :
3932 : : #define NUM_KEYWORDS 1
3933 : : static struct {
3934 : : PyGC_Head _this_is_not_used;
3935 : : PyObject_VAR_HEAD
3936 : : PyObject *ob_item[NUM_KEYWORDS];
3937 : : } _kwtuple = {
3938 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
3939 : : .ob_item = { &_Py_ID(policy), },
3940 : : };
3941 : : #undef NUM_KEYWORDS
3942 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
3943 : :
3944 : : #else // !Py_BUILD_CORE
3945 : : # define KWTUPLE NULL
3946 : : #endif // !Py_BUILD_CORE
3947 : :
3948 : : static const char * const _keywords[] = {"policy", NULL};
3949 : : static _PyArg_Parser _parser = {
3950 : : .keywords = _keywords,
3951 : : .fname = "sched_get_priority_max",
3952 : : .kwtuple = KWTUPLE,
3953 : : };
3954 : : #undef KWTUPLE
3955 : : PyObject *argsbuf[1];
3956 : : int policy;
3957 : :
3958 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
3959 [ # # ]: 0 : if (!args) {
3960 : 0 : goto exit;
3961 : : }
3962 : 0 : policy = _PyLong_AsInt(args[0]);
3963 [ # # # # ]: 0 : if (policy == -1 && PyErr_Occurred()) {
3964 : 0 : goto exit;
3965 : : }
3966 : 0 : return_value = os_sched_get_priority_max_impl(module, policy);
3967 : :
3968 : 0 : exit:
3969 : 0 : return return_value;
3970 : : }
3971 : :
3972 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
3973 : :
3974 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
3975 : :
3976 : : PyDoc_STRVAR(os_sched_get_priority_min__doc__,
3977 : : "sched_get_priority_min($module, /, policy)\n"
3978 : : "--\n"
3979 : : "\n"
3980 : : "Get the minimum scheduling priority for policy.");
3981 : :
3982 : : #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
3983 : : {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
3984 : :
3985 : : static PyObject *
3986 : : os_sched_get_priority_min_impl(PyObject *module, int policy);
3987 : :
3988 : : static PyObject *
3989 : 0 : os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
3990 : : {
3991 : 0 : PyObject *return_value = NULL;
3992 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
3993 : :
3994 : : #define NUM_KEYWORDS 1
3995 : : static struct {
3996 : : PyGC_Head _this_is_not_used;
3997 : : PyObject_VAR_HEAD
3998 : : PyObject *ob_item[NUM_KEYWORDS];
3999 : : } _kwtuple = {
4000 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4001 : : .ob_item = { &_Py_ID(policy), },
4002 : : };
4003 : : #undef NUM_KEYWORDS
4004 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4005 : :
4006 : : #else // !Py_BUILD_CORE
4007 : : # define KWTUPLE NULL
4008 : : #endif // !Py_BUILD_CORE
4009 : :
4010 : : static const char * const _keywords[] = {"policy", NULL};
4011 : : static _PyArg_Parser _parser = {
4012 : : .keywords = _keywords,
4013 : : .fname = "sched_get_priority_min",
4014 : : .kwtuple = KWTUPLE,
4015 : : };
4016 : : #undef KWTUPLE
4017 : : PyObject *argsbuf[1];
4018 : : int policy;
4019 : :
4020 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
4021 [ # # ]: 0 : if (!args) {
4022 : 0 : goto exit;
4023 : : }
4024 : 0 : policy = _PyLong_AsInt(args[0]);
4025 [ # # # # ]: 0 : if (policy == -1 && PyErr_Occurred()) {
4026 : 0 : goto exit;
4027 : : }
4028 : 0 : return_value = os_sched_get_priority_min_impl(module, policy);
4029 : :
4030 : 0 : exit:
4031 : 0 : return return_value;
4032 : : }
4033 : :
4034 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
4035 : :
4036 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4037 : :
4038 : : PyDoc_STRVAR(os_sched_getscheduler__doc__,
4039 : : "sched_getscheduler($module, pid, /)\n"
4040 : : "--\n"
4041 : : "\n"
4042 : : "Get the scheduling policy for the process identified by pid.\n"
4043 : : "\n"
4044 : : "Passing 0 for pid returns the scheduling policy for the calling process.");
4045 : :
4046 : : #define OS_SCHED_GETSCHEDULER_METHODDEF \
4047 : : {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
4048 : :
4049 : : static PyObject *
4050 : : os_sched_getscheduler_impl(PyObject *module, pid_t pid);
4051 : :
4052 : : static PyObject *
4053 : 0 : os_sched_getscheduler(PyObject *module, PyObject *arg)
4054 : : {
4055 : 0 : PyObject *return_value = NULL;
4056 : : pid_t pid;
4057 : :
4058 [ # # ]: 0 : if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
4059 : 0 : goto exit;
4060 : : }
4061 : 0 : return_value = os_sched_getscheduler_impl(module, pid);
4062 : :
4063 : 0 : exit:
4064 : 0 : return return_value;
4065 : : }
4066 : :
4067 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4068 : :
4069 : : #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
4070 : :
4071 : : PyDoc_STRVAR(os_sched_param__doc__,
4072 : : "sched_param(sched_priority)\n"
4073 : : "--\n"
4074 : : "\n"
4075 : : "Currently has only one field: sched_priority\n"
4076 : : "\n"
4077 : : " sched_priority\n"
4078 : : " A scheduling parameter.");
4079 : :
4080 : : static PyObject *
4081 : : os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
4082 : :
4083 : : static PyObject *
4084 : 0 : os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
4085 : : {
4086 : 0 : PyObject *return_value = NULL;
4087 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4088 : :
4089 : : #define NUM_KEYWORDS 1
4090 : : static struct {
4091 : : PyGC_Head _this_is_not_used;
4092 : : PyObject_VAR_HEAD
4093 : : PyObject *ob_item[NUM_KEYWORDS];
4094 : : } _kwtuple = {
4095 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4096 : : .ob_item = { &_Py_ID(sched_priority), },
4097 : : };
4098 : : #undef NUM_KEYWORDS
4099 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4100 : :
4101 : : #else // !Py_BUILD_CORE
4102 : : # define KWTUPLE NULL
4103 : : #endif // !Py_BUILD_CORE
4104 : :
4105 : : static const char * const _keywords[] = {"sched_priority", NULL};
4106 : : static _PyArg_Parser _parser = {
4107 : : .keywords = _keywords,
4108 : : .fname = "sched_param",
4109 : : .kwtuple = KWTUPLE,
4110 : : };
4111 : : #undef KWTUPLE
4112 : : PyObject *argsbuf[1];
4113 : : PyObject * const *fastargs;
4114 : 0 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
4115 : : PyObject *sched_priority;
4116 : :
4117 [ # # # # : 0 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
# # # # ]
4118 [ # # ]: 0 : if (!fastargs) {
4119 : 0 : goto exit;
4120 : : }
4121 : 0 : sched_priority = fastargs[0];
4122 : 0 : return_value = os_sched_param_impl(type, sched_priority);
4123 : :
4124 : 0 : exit:
4125 : 0 : return return_value;
4126 : : }
4127 : :
4128 : : #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
4129 : :
4130 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
4131 : :
4132 : : PyDoc_STRVAR(os_sched_setscheduler__doc__,
4133 : : "sched_setscheduler($module, pid, policy, param, /)\n"
4134 : : "--\n"
4135 : : "\n"
4136 : : "Set the scheduling policy for the process identified by pid.\n"
4137 : : "\n"
4138 : : "If pid is 0, the calling process is changed.\n"
4139 : : "param is an instance of sched_param.");
4140 : :
4141 : : #define OS_SCHED_SETSCHEDULER_METHODDEF \
4142 : : {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
4143 : :
4144 : : static PyObject *
4145 : : os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
4146 : : PyObject *param_obj);
4147 : :
4148 : : static PyObject *
4149 : 0 : os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4150 : : {
4151 : 0 : PyObject *return_value = NULL;
4152 : : pid_t pid;
4153 : : int policy;
4154 : : PyObject *param_obj;
4155 : :
4156 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO:sched_setscheduler",
4157 : : &pid, &policy, ¶m_obj)) {
4158 : 0 : goto exit;
4159 : : }
4160 : 0 : return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
4161 : :
4162 : 0 : exit:
4163 : 0 : return return_value;
4164 : : }
4165 : :
4166 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
4167 : :
4168 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4169 : :
4170 : : PyDoc_STRVAR(os_sched_getparam__doc__,
4171 : : "sched_getparam($module, pid, /)\n"
4172 : : "--\n"
4173 : : "\n"
4174 : : "Returns scheduling parameters for the process identified by pid.\n"
4175 : : "\n"
4176 : : "If pid is 0, returns parameters for the calling process.\n"
4177 : : "Return value is an instance of sched_param.");
4178 : :
4179 : : #define OS_SCHED_GETPARAM_METHODDEF \
4180 : : {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
4181 : :
4182 : : static PyObject *
4183 : : os_sched_getparam_impl(PyObject *module, pid_t pid);
4184 : :
4185 : : static PyObject *
4186 : 0 : os_sched_getparam(PyObject *module, PyObject *arg)
4187 : : {
4188 : 0 : PyObject *return_value = NULL;
4189 : : pid_t pid;
4190 : :
4191 [ # # ]: 0 : if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
4192 : 0 : goto exit;
4193 : : }
4194 : 0 : return_value = os_sched_getparam_impl(module, pid);
4195 : :
4196 : 0 : exit:
4197 : 0 : return return_value;
4198 : : }
4199 : :
4200 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4201 : :
4202 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
4203 : :
4204 : : PyDoc_STRVAR(os_sched_setparam__doc__,
4205 : : "sched_setparam($module, pid, param, /)\n"
4206 : : "--\n"
4207 : : "\n"
4208 : : "Set scheduling parameters for the process identified by pid.\n"
4209 : : "\n"
4210 : : "If pid is 0, sets parameters for the calling process.\n"
4211 : : "param should be an instance of sched_param.");
4212 : :
4213 : : #define OS_SCHED_SETPARAM_METHODDEF \
4214 : : {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
4215 : :
4216 : : static PyObject *
4217 : : os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
4218 : :
4219 : : static PyObject *
4220 : 0 : os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4221 : : {
4222 : 0 : PyObject *return_value = NULL;
4223 : : pid_t pid;
4224 : : PyObject *param_obj;
4225 : :
4226 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setparam",
4227 : : &pid, ¶m_obj)) {
4228 : 0 : goto exit;
4229 : : }
4230 : 0 : return_value = os_sched_setparam_impl(module, pid, param_obj);
4231 : :
4232 : 0 : exit:
4233 : 0 : return return_value;
4234 : : }
4235 : :
4236 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
4237 : :
4238 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
4239 : :
4240 : : PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
4241 : : "sched_rr_get_interval($module, pid, /)\n"
4242 : : "--\n"
4243 : : "\n"
4244 : : "Return the round-robin quantum for the process identified by pid, in seconds.\n"
4245 : : "\n"
4246 : : "Value returned is a float.");
4247 : :
4248 : : #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
4249 : : {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
4250 : :
4251 : : static double
4252 : : os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
4253 : :
4254 : : static PyObject *
4255 : 0 : os_sched_rr_get_interval(PyObject *module, PyObject *arg)
4256 : : {
4257 : 0 : PyObject *return_value = NULL;
4258 : : pid_t pid;
4259 : : double _return_value;
4260 : :
4261 [ # # ]: 0 : if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
4262 : 0 : goto exit;
4263 : : }
4264 : 0 : _return_value = os_sched_rr_get_interval_impl(module, pid);
4265 [ # # # # ]: 0 : if ((_return_value == -1.0) && PyErr_Occurred()) {
4266 : 0 : goto exit;
4267 : : }
4268 : 0 : return_value = PyFloat_FromDouble(_return_value);
4269 : :
4270 : 0 : exit:
4271 : 0 : return return_value;
4272 : : }
4273 : :
4274 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
4275 : :
4276 : : #if defined(HAVE_SCHED_H)
4277 : :
4278 : : PyDoc_STRVAR(os_sched_yield__doc__,
4279 : : "sched_yield($module, /)\n"
4280 : : "--\n"
4281 : : "\n"
4282 : : "Voluntarily relinquish the CPU.");
4283 : :
4284 : : #define OS_SCHED_YIELD_METHODDEF \
4285 : : {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
4286 : :
4287 : : static PyObject *
4288 : : os_sched_yield_impl(PyObject *module);
4289 : :
4290 : : static PyObject *
4291 : 0 : os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
4292 : : {
4293 : 0 : return os_sched_yield_impl(module);
4294 : : }
4295 : :
4296 : : #endif /* defined(HAVE_SCHED_H) */
4297 : :
4298 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4299 : :
4300 : : PyDoc_STRVAR(os_sched_setaffinity__doc__,
4301 : : "sched_setaffinity($module, pid, mask, /)\n"
4302 : : "--\n"
4303 : : "\n"
4304 : : "Set the CPU affinity of the process identified by pid to mask.\n"
4305 : : "\n"
4306 : : "mask should be an iterable of integers identifying CPUs.");
4307 : :
4308 : : #define OS_SCHED_SETAFFINITY_METHODDEF \
4309 : : {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
4310 : :
4311 : : static PyObject *
4312 : : os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
4313 : :
4314 : : static PyObject *
4315 : 0 : os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4316 : : {
4317 : 0 : PyObject *return_value = NULL;
4318 : : pid_t pid;
4319 : : PyObject *mask;
4320 : :
4321 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
4322 : : &pid, &mask)) {
4323 : 0 : goto exit;
4324 : : }
4325 : 0 : return_value = os_sched_setaffinity_impl(module, pid, mask);
4326 : :
4327 : 0 : exit:
4328 : 0 : return return_value;
4329 : : }
4330 : :
4331 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4332 : :
4333 : : #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
4334 : :
4335 : : PyDoc_STRVAR(os_sched_getaffinity__doc__,
4336 : : "sched_getaffinity($module, pid, /)\n"
4337 : : "--\n"
4338 : : "\n"
4339 : : "Return the affinity of the process identified by pid (or the current process if zero).\n"
4340 : : "\n"
4341 : : "The affinity is returned as a set of CPU identifiers.");
4342 : :
4343 : : #define OS_SCHED_GETAFFINITY_METHODDEF \
4344 : : {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
4345 : :
4346 : : static PyObject *
4347 : : os_sched_getaffinity_impl(PyObject *module, pid_t pid);
4348 : :
4349 : : static PyObject *
4350 : 0 : os_sched_getaffinity(PyObject *module, PyObject *arg)
4351 : : {
4352 : 0 : PyObject *return_value = NULL;
4353 : : pid_t pid;
4354 : :
4355 [ # # ]: 0 : if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
4356 : 0 : goto exit;
4357 : : }
4358 : 0 : return_value = os_sched_getaffinity_impl(module, pid);
4359 : :
4360 : 0 : exit:
4361 : 0 : return return_value;
4362 : : }
4363 : :
4364 : : #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
4365 : :
4366 : : #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
4367 : :
4368 : : PyDoc_STRVAR(os_openpty__doc__,
4369 : : "openpty($module, /)\n"
4370 : : "--\n"
4371 : : "\n"
4372 : : "Open a pseudo-terminal.\n"
4373 : : "\n"
4374 : : "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
4375 : : "for both the master and slave ends.");
4376 : :
4377 : : #define OS_OPENPTY_METHODDEF \
4378 : : {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
4379 : :
4380 : : static PyObject *
4381 : : os_openpty_impl(PyObject *module);
4382 : :
4383 : : static PyObject *
4384 : 0 : os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
4385 : : {
4386 : 0 : return os_openpty_impl(module);
4387 : : }
4388 : :
4389 : : #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
4390 : :
4391 : : #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
4392 : :
4393 : : PyDoc_STRVAR(os_login_tty__doc__,
4394 : : "login_tty($module, fd, /)\n"
4395 : : "--\n"
4396 : : "\n"
4397 : : "Prepare the tty of which fd is a file descriptor for a new login session.\n"
4398 : : "\n"
4399 : : "Make the calling process a session leader; make the tty the\n"
4400 : : "controlling tty, the stdin, the stdout, and the stderr of the\n"
4401 : : "calling process; close fd.");
4402 : :
4403 : : #define OS_LOGIN_TTY_METHODDEF \
4404 : : {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
4405 : :
4406 : : static PyObject *
4407 : : os_login_tty_impl(PyObject *module, int fd);
4408 : :
4409 : : static PyObject *
4410 : 0 : os_login_tty(PyObject *module, PyObject *arg)
4411 : : {
4412 : 0 : PyObject *return_value = NULL;
4413 : : int fd;
4414 : :
4415 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(arg, &fd)) {
4416 : 0 : goto exit;
4417 : : }
4418 : 0 : return_value = os_login_tty_impl(module, fd);
4419 : :
4420 : 0 : exit:
4421 : 0 : return return_value;
4422 : : }
4423 : :
4424 : : #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
4425 : :
4426 : : #if defined(HAVE_FORKPTY)
4427 : :
4428 : : PyDoc_STRVAR(os_forkpty__doc__,
4429 : : "forkpty($module, /)\n"
4430 : : "--\n"
4431 : : "\n"
4432 : : "Fork a new process with a new pseudo-terminal as controlling tty.\n"
4433 : : "\n"
4434 : : "Returns a tuple of (pid, master_fd).\n"
4435 : : "Like fork(), return pid of 0 to the child process,\n"
4436 : : "and pid of child to the parent process.\n"
4437 : : "To both, return fd of newly opened pseudo-terminal.");
4438 : :
4439 : : #define OS_FORKPTY_METHODDEF \
4440 : : {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
4441 : :
4442 : : static PyObject *
4443 : : os_forkpty_impl(PyObject *module);
4444 : :
4445 : : static PyObject *
4446 : 0 : os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
4447 : : {
4448 : 0 : return os_forkpty_impl(module);
4449 : : }
4450 : :
4451 : : #endif /* defined(HAVE_FORKPTY) */
4452 : :
4453 : : #if defined(HAVE_GETEGID)
4454 : :
4455 : : PyDoc_STRVAR(os_getegid__doc__,
4456 : : "getegid($module, /)\n"
4457 : : "--\n"
4458 : : "\n"
4459 : : "Return the current process\'s effective group id.");
4460 : :
4461 : : #define OS_GETEGID_METHODDEF \
4462 : : {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
4463 : :
4464 : : static PyObject *
4465 : : os_getegid_impl(PyObject *module);
4466 : :
4467 : : static PyObject *
4468 : 3 : os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
4469 : : {
4470 : 3 : return os_getegid_impl(module);
4471 : : }
4472 : :
4473 : : #endif /* defined(HAVE_GETEGID) */
4474 : :
4475 : : #if defined(HAVE_GETEUID)
4476 : :
4477 : : PyDoc_STRVAR(os_geteuid__doc__,
4478 : : "geteuid($module, /)\n"
4479 : : "--\n"
4480 : : "\n"
4481 : : "Return the current process\'s effective user id.");
4482 : :
4483 : : #define OS_GETEUID_METHODDEF \
4484 : : {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
4485 : :
4486 : : static PyObject *
4487 : : os_geteuid_impl(PyObject *module);
4488 : :
4489 : : static PyObject *
4490 : 3 : os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
4491 : : {
4492 : 3 : return os_geteuid_impl(module);
4493 : : }
4494 : :
4495 : : #endif /* defined(HAVE_GETEUID) */
4496 : :
4497 : : #if defined(HAVE_GETGID)
4498 : :
4499 : : PyDoc_STRVAR(os_getgid__doc__,
4500 : : "getgid($module, /)\n"
4501 : : "--\n"
4502 : : "\n"
4503 : : "Return the current process\'s group id.");
4504 : :
4505 : : #define OS_GETGID_METHODDEF \
4506 : : {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
4507 : :
4508 : : static PyObject *
4509 : : os_getgid_impl(PyObject *module);
4510 : :
4511 : : static PyObject *
4512 : 3 : os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
4513 : : {
4514 : 3 : return os_getgid_impl(module);
4515 : : }
4516 : :
4517 : : #endif /* defined(HAVE_GETGID) */
4518 : :
4519 : : #if defined(HAVE_GETPID)
4520 : :
4521 : : PyDoc_STRVAR(os_getpid__doc__,
4522 : : "getpid($module, /)\n"
4523 : : "--\n"
4524 : : "\n"
4525 : : "Return the current process id.");
4526 : :
4527 : : #define OS_GETPID_METHODDEF \
4528 : : {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
4529 : :
4530 : : static PyObject *
4531 : : os_getpid_impl(PyObject *module);
4532 : :
4533 : : static PyObject *
4534 : 4 : os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
4535 : : {
4536 : 4 : return os_getpid_impl(module);
4537 : : }
4538 : :
4539 : : #endif /* defined(HAVE_GETPID) */
4540 : :
4541 : : #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
4542 : :
4543 : : PyDoc_STRVAR(os_getgrouplist__doc__,
4544 : : "getgrouplist($module, user, group, /)\n"
4545 : : "--\n"
4546 : : "\n"
4547 : : "Returns a list of groups to which a user belongs.\n"
4548 : : "\n"
4549 : : " user\n"
4550 : : " username to lookup\n"
4551 : : " group\n"
4552 : : " base group id of the user");
4553 : :
4554 : : #define OS_GETGROUPLIST_METHODDEF \
4555 : : {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
4556 : :
4557 : : static PyObject *
4558 : : os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
4559 : :
4560 : : static PyObject *
4561 : : os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4562 : : {
4563 : : PyObject *return_value = NULL;
4564 : : const char *user;
4565 : : int basegid;
4566 : :
4567 : : if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
4568 : : goto exit;
4569 : : }
4570 : : if (!PyUnicode_Check(args[0])) {
4571 : : _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
4572 : : goto exit;
4573 : : }
4574 : : Py_ssize_t user_length;
4575 : : user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
4576 : : if (user == NULL) {
4577 : : goto exit;
4578 : : }
4579 : : if (strlen(user) != (size_t)user_length) {
4580 : : PyErr_SetString(PyExc_ValueError, "embedded null character");
4581 : : goto exit;
4582 : : }
4583 : : basegid = _PyLong_AsInt(args[1]);
4584 : : if (basegid == -1 && PyErr_Occurred()) {
4585 : : goto exit;
4586 : : }
4587 : : return_value = os_getgrouplist_impl(module, user, basegid);
4588 : :
4589 : : exit:
4590 : : return return_value;
4591 : : }
4592 : :
4593 : : #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
4594 : :
4595 : : #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
4596 : :
4597 : : PyDoc_STRVAR(os_getgrouplist__doc__,
4598 : : "getgrouplist($module, user, group, /)\n"
4599 : : "--\n"
4600 : : "\n"
4601 : : "Returns a list of groups to which a user belongs.\n"
4602 : : "\n"
4603 : : " user\n"
4604 : : " username to lookup\n"
4605 : : " group\n"
4606 : : " base group id of the user");
4607 : :
4608 : : #define OS_GETGROUPLIST_METHODDEF \
4609 : : {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
4610 : :
4611 : : static PyObject *
4612 : : os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
4613 : :
4614 : : static PyObject *
4615 : 0 : os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4616 : : {
4617 : 0 : PyObject *return_value = NULL;
4618 : : const char *user;
4619 : : gid_t basegid;
4620 : :
4621 [ # # # # : 0 : if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
# # ]
4622 : 0 : goto exit;
4623 : : }
4624 [ # # ]: 0 : if (!PyUnicode_Check(args[0])) {
4625 : 0 : _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
4626 : 0 : goto exit;
4627 : : }
4628 : : Py_ssize_t user_length;
4629 : 0 : user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
4630 [ # # ]: 0 : if (user == NULL) {
4631 : 0 : goto exit;
4632 : : }
4633 [ # # ]: 0 : if (strlen(user) != (size_t)user_length) {
4634 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
4635 : 0 : goto exit;
4636 : : }
4637 [ # # ]: 0 : if (!_Py_Gid_Converter(args[1], &basegid)) {
4638 : 0 : goto exit;
4639 : : }
4640 : 0 : return_value = os_getgrouplist_impl(module, user, basegid);
4641 : :
4642 : 0 : exit:
4643 : 0 : return return_value;
4644 : : }
4645 : :
4646 : : #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
4647 : :
4648 : : #if defined(HAVE_GETGROUPS)
4649 : :
4650 : : PyDoc_STRVAR(os_getgroups__doc__,
4651 : : "getgroups($module, /)\n"
4652 : : "--\n"
4653 : : "\n"
4654 : : "Return list of supplemental group IDs for the process.");
4655 : :
4656 : : #define OS_GETGROUPS_METHODDEF \
4657 : : {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
4658 : :
4659 : : static PyObject *
4660 : : os_getgroups_impl(PyObject *module);
4661 : :
4662 : : static PyObject *
4663 : 0 : os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
4664 : : {
4665 : 0 : return os_getgroups_impl(module);
4666 : : }
4667 : :
4668 : : #endif /* defined(HAVE_GETGROUPS) */
4669 : :
4670 : : #if defined(HAVE_INITGROUPS) && defined(__APPLE__)
4671 : :
4672 : : PyDoc_STRVAR(os_initgroups__doc__,
4673 : : "initgroups($module, username, gid, /)\n"
4674 : : "--\n"
4675 : : "\n"
4676 : : "Initialize the group access list.\n"
4677 : : "\n"
4678 : : "Call the system initgroups() to initialize the group access list with all of\n"
4679 : : "the groups of which the specified username is a member, plus the specified\n"
4680 : : "group id.");
4681 : :
4682 : : #define OS_INITGROUPS_METHODDEF \
4683 : : {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
4684 : :
4685 : : static PyObject *
4686 : : os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
4687 : :
4688 : : static PyObject *
4689 : : os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4690 : : {
4691 : : PyObject *return_value = NULL;
4692 : : PyObject *oname = NULL;
4693 : : int gid;
4694 : :
4695 : : if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
4696 : : goto exit;
4697 : : }
4698 : : if (!PyUnicode_FSConverter(args[0], &oname)) {
4699 : : goto exit;
4700 : : }
4701 : : gid = _PyLong_AsInt(args[1]);
4702 : : if (gid == -1 && PyErr_Occurred()) {
4703 : : goto exit;
4704 : : }
4705 : : return_value = os_initgroups_impl(module, oname, gid);
4706 : :
4707 : : exit:
4708 : : /* Cleanup for oname */
4709 : : Py_XDECREF(oname);
4710 : :
4711 : : return return_value;
4712 : : }
4713 : :
4714 : : #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
4715 : :
4716 : : #if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
4717 : :
4718 : : PyDoc_STRVAR(os_initgroups__doc__,
4719 : : "initgroups($module, username, gid, /)\n"
4720 : : "--\n"
4721 : : "\n"
4722 : : "Initialize the group access list.\n"
4723 : : "\n"
4724 : : "Call the system initgroups() to initialize the group access list with all of\n"
4725 : : "the groups of which the specified username is a member, plus the specified\n"
4726 : : "group id.");
4727 : :
4728 : : #define OS_INITGROUPS_METHODDEF \
4729 : : {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
4730 : :
4731 : : static PyObject *
4732 : : os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
4733 : :
4734 : : static PyObject *
4735 : 0 : os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4736 : : {
4737 : 0 : PyObject *return_value = NULL;
4738 : 0 : PyObject *oname = NULL;
4739 : : gid_t gid;
4740 : :
4741 [ # # # # : 0 : if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
# # ]
4742 : 0 : goto exit;
4743 : : }
4744 [ # # ]: 0 : if (!PyUnicode_FSConverter(args[0], &oname)) {
4745 : 0 : goto exit;
4746 : : }
4747 [ # # ]: 0 : if (!_Py_Gid_Converter(args[1], &gid)) {
4748 : 0 : goto exit;
4749 : : }
4750 : 0 : return_value = os_initgroups_impl(module, oname, gid);
4751 : :
4752 : 0 : exit:
4753 : : /* Cleanup for oname */
4754 : 0 : Py_XDECREF(oname);
4755 : :
4756 : 0 : return return_value;
4757 : : }
4758 : :
4759 : : #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
4760 : :
4761 : : #if defined(HAVE_GETPGID)
4762 : :
4763 : : PyDoc_STRVAR(os_getpgid__doc__,
4764 : : "getpgid($module, /, pid)\n"
4765 : : "--\n"
4766 : : "\n"
4767 : : "Call the system call getpgid(), and return the result.");
4768 : :
4769 : : #define OS_GETPGID_METHODDEF \
4770 : : {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
4771 : :
4772 : : static PyObject *
4773 : : os_getpgid_impl(PyObject *module, pid_t pid);
4774 : :
4775 : : static PyObject *
4776 : 0 : os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
4777 : : {
4778 : 0 : PyObject *return_value = NULL;
4779 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
4780 : :
4781 : : #define NUM_KEYWORDS 1
4782 : : static struct {
4783 : : PyGC_Head _this_is_not_used;
4784 : : PyObject_VAR_HEAD
4785 : : PyObject *ob_item[NUM_KEYWORDS];
4786 : : } _kwtuple = {
4787 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
4788 : : .ob_item = { &_Py_ID(pid), },
4789 : : };
4790 : : #undef NUM_KEYWORDS
4791 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
4792 : :
4793 : : #else // !Py_BUILD_CORE
4794 : : # define KWTUPLE NULL
4795 : : #endif // !Py_BUILD_CORE
4796 : :
4797 : : static const char * const _keywords[] = {"pid", NULL};
4798 : : static _PyArg_Parser _parser = {
4799 : : .keywords = _keywords,
4800 : : .format = "" _Py_PARSE_PID ":getpgid",
4801 : : .kwtuple = KWTUPLE,
4802 : : };
4803 : : #undef KWTUPLE
4804 : : pid_t pid;
4805 : :
4806 [ # # ]: 0 : if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
4807 : : &pid)) {
4808 : 0 : goto exit;
4809 : : }
4810 : 0 : return_value = os_getpgid_impl(module, pid);
4811 : :
4812 : 0 : exit:
4813 : 0 : return return_value;
4814 : : }
4815 : :
4816 : : #endif /* defined(HAVE_GETPGID) */
4817 : :
4818 : : #if defined(HAVE_GETPGRP)
4819 : :
4820 : : PyDoc_STRVAR(os_getpgrp__doc__,
4821 : : "getpgrp($module, /)\n"
4822 : : "--\n"
4823 : : "\n"
4824 : : "Return the current process group id.");
4825 : :
4826 : : #define OS_GETPGRP_METHODDEF \
4827 : : {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
4828 : :
4829 : : static PyObject *
4830 : : os_getpgrp_impl(PyObject *module);
4831 : :
4832 : : static PyObject *
4833 : 0 : os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
4834 : : {
4835 : 0 : return os_getpgrp_impl(module);
4836 : : }
4837 : :
4838 : : #endif /* defined(HAVE_GETPGRP) */
4839 : :
4840 : : #if defined(HAVE_SETPGRP)
4841 : :
4842 : : PyDoc_STRVAR(os_setpgrp__doc__,
4843 : : "setpgrp($module, /)\n"
4844 : : "--\n"
4845 : : "\n"
4846 : : "Make the current process the leader of its process group.");
4847 : :
4848 : : #define OS_SETPGRP_METHODDEF \
4849 : : {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
4850 : :
4851 : : static PyObject *
4852 : : os_setpgrp_impl(PyObject *module);
4853 : :
4854 : : static PyObject *
4855 : 0 : os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
4856 : : {
4857 : 0 : return os_setpgrp_impl(module);
4858 : : }
4859 : :
4860 : : #endif /* defined(HAVE_SETPGRP) */
4861 : :
4862 : : #if defined(HAVE_GETPPID)
4863 : :
4864 : : PyDoc_STRVAR(os_getppid__doc__,
4865 : : "getppid($module, /)\n"
4866 : : "--\n"
4867 : : "\n"
4868 : : "Return the parent\'s process id.\n"
4869 : : "\n"
4870 : : "If the parent process has already exited, Windows machines will still\n"
4871 : : "return its id; others systems will return the id of the \'init\' process (1).");
4872 : :
4873 : : #define OS_GETPPID_METHODDEF \
4874 : : {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
4875 : :
4876 : : static PyObject *
4877 : : os_getppid_impl(PyObject *module);
4878 : :
4879 : : static PyObject *
4880 : 0 : os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
4881 : : {
4882 : 0 : return os_getppid_impl(module);
4883 : : }
4884 : :
4885 : : #endif /* defined(HAVE_GETPPID) */
4886 : :
4887 : : #if defined(HAVE_GETLOGIN)
4888 : :
4889 : : PyDoc_STRVAR(os_getlogin__doc__,
4890 : : "getlogin($module, /)\n"
4891 : : "--\n"
4892 : : "\n"
4893 : : "Return the actual login name.");
4894 : :
4895 : : #define OS_GETLOGIN_METHODDEF \
4896 : : {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
4897 : :
4898 : : static PyObject *
4899 : : os_getlogin_impl(PyObject *module);
4900 : :
4901 : : static PyObject *
4902 : 0 : os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
4903 : : {
4904 : 0 : return os_getlogin_impl(module);
4905 : : }
4906 : :
4907 : : #endif /* defined(HAVE_GETLOGIN) */
4908 : :
4909 : : #if defined(HAVE_GETUID)
4910 : :
4911 : : PyDoc_STRVAR(os_getuid__doc__,
4912 : : "getuid($module, /)\n"
4913 : : "--\n"
4914 : : "\n"
4915 : : "Return the current process\'s user id.");
4916 : :
4917 : : #define OS_GETUID_METHODDEF \
4918 : : {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
4919 : :
4920 : : static PyObject *
4921 : : os_getuid_impl(PyObject *module);
4922 : :
4923 : : static PyObject *
4924 : 3 : os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
4925 : : {
4926 : 3 : return os_getuid_impl(module);
4927 : : }
4928 : :
4929 : : #endif /* defined(HAVE_GETUID) */
4930 : :
4931 : : #if defined(HAVE_KILL)
4932 : :
4933 : : PyDoc_STRVAR(os_kill__doc__,
4934 : : "kill($module, pid, signal, /)\n"
4935 : : "--\n"
4936 : : "\n"
4937 : : "Kill a process with a signal.");
4938 : :
4939 : : #define OS_KILL_METHODDEF \
4940 : : {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
4941 : :
4942 : : static PyObject *
4943 : : os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
4944 : :
4945 : : static PyObject *
4946 : 0 : os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4947 : : {
4948 : 0 : PyObject *return_value = NULL;
4949 : : pid_t pid;
4950 : : Py_ssize_t signal;
4951 : :
4952 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
4953 : : &pid, &signal)) {
4954 : 0 : goto exit;
4955 : : }
4956 : 0 : return_value = os_kill_impl(module, pid, signal);
4957 : :
4958 : 0 : exit:
4959 : 0 : return return_value;
4960 : : }
4961 : :
4962 : : #endif /* defined(HAVE_KILL) */
4963 : :
4964 : : #if defined(HAVE_KILLPG)
4965 : :
4966 : : PyDoc_STRVAR(os_killpg__doc__,
4967 : : "killpg($module, pgid, signal, /)\n"
4968 : : "--\n"
4969 : : "\n"
4970 : : "Kill a process group with a signal.");
4971 : :
4972 : : #define OS_KILLPG_METHODDEF \
4973 : : {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
4974 : :
4975 : : static PyObject *
4976 : : os_killpg_impl(PyObject *module, pid_t pgid, int signal);
4977 : :
4978 : : static PyObject *
4979 : 0 : os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
4980 : : {
4981 : 0 : PyObject *return_value = NULL;
4982 : : pid_t pgid;
4983 : : int signal;
4984 : :
4985 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
4986 : : &pgid, &signal)) {
4987 : 0 : goto exit;
4988 : : }
4989 : 0 : return_value = os_killpg_impl(module, pgid, signal);
4990 : :
4991 : 0 : exit:
4992 : 0 : return return_value;
4993 : : }
4994 : :
4995 : : #endif /* defined(HAVE_KILLPG) */
4996 : :
4997 : : #if defined(HAVE_PLOCK)
4998 : :
4999 : : PyDoc_STRVAR(os_plock__doc__,
5000 : : "plock($module, op, /)\n"
5001 : : "--\n"
5002 : : "\n"
5003 : : "Lock program segments into memory.\");");
5004 : :
5005 : : #define OS_PLOCK_METHODDEF \
5006 : : {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
5007 : :
5008 : : static PyObject *
5009 : : os_plock_impl(PyObject *module, int op);
5010 : :
5011 : : static PyObject *
5012 : : os_plock(PyObject *module, PyObject *arg)
5013 : : {
5014 : : PyObject *return_value = NULL;
5015 : : int op;
5016 : :
5017 : : op = _PyLong_AsInt(arg);
5018 : : if (op == -1 && PyErr_Occurred()) {
5019 : : goto exit;
5020 : : }
5021 : : return_value = os_plock_impl(module, op);
5022 : :
5023 : : exit:
5024 : : return return_value;
5025 : : }
5026 : :
5027 : : #endif /* defined(HAVE_PLOCK) */
5028 : :
5029 : : #if defined(HAVE_SETUID)
5030 : :
5031 : : PyDoc_STRVAR(os_setuid__doc__,
5032 : : "setuid($module, uid, /)\n"
5033 : : "--\n"
5034 : : "\n"
5035 : : "Set the current process\'s user id.");
5036 : :
5037 : : #define OS_SETUID_METHODDEF \
5038 : : {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
5039 : :
5040 : : static PyObject *
5041 : : os_setuid_impl(PyObject *module, uid_t uid);
5042 : :
5043 : : static PyObject *
5044 : 0 : os_setuid(PyObject *module, PyObject *arg)
5045 : : {
5046 : 0 : PyObject *return_value = NULL;
5047 : : uid_t uid;
5048 : :
5049 [ # # ]: 0 : if (!_Py_Uid_Converter(arg, &uid)) {
5050 : 0 : goto exit;
5051 : : }
5052 : 0 : return_value = os_setuid_impl(module, uid);
5053 : :
5054 : 0 : exit:
5055 : 0 : return return_value;
5056 : : }
5057 : :
5058 : : #endif /* defined(HAVE_SETUID) */
5059 : :
5060 : : #if defined(HAVE_SETEUID)
5061 : :
5062 : : PyDoc_STRVAR(os_seteuid__doc__,
5063 : : "seteuid($module, euid, /)\n"
5064 : : "--\n"
5065 : : "\n"
5066 : : "Set the current process\'s effective user id.");
5067 : :
5068 : : #define OS_SETEUID_METHODDEF \
5069 : : {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
5070 : :
5071 : : static PyObject *
5072 : : os_seteuid_impl(PyObject *module, uid_t euid);
5073 : :
5074 : : static PyObject *
5075 : 0 : os_seteuid(PyObject *module, PyObject *arg)
5076 : : {
5077 : 0 : PyObject *return_value = NULL;
5078 : : uid_t euid;
5079 : :
5080 [ # # ]: 0 : if (!_Py_Uid_Converter(arg, &euid)) {
5081 : 0 : goto exit;
5082 : : }
5083 : 0 : return_value = os_seteuid_impl(module, euid);
5084 : :
5085 : 0 : exit:
5086 : 0 : return return_value;
5087 : : }
5088 : :
5089 : : #endif /* defined(HAVE_SETEUID) */
5090 : :
5091 : : #if defined(HAVE_SETEGID)
5092 : :
5093 : : PyDoc_STRVAR(os_setegid__doc__,
5094 : : "setegid($module, egid, /)\n"
5095 : : "--\n"
5096 : : "\n"
5097 : : "Set the current process\'s effective group id.");
5098 : :
5099 : : #define OS_SETEGID_METHODDEF \
5100 : : {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
5101 : :
5102 : : static PyObject *
5103 : : os_setegid_impl(PyObject *module, gid_t egid);
5104 : :
5105 : : static PyObject *
5106 : 0 : os_setegid(PyObject *module, PyObject *arg)
5107 : : {
5108 : 0 : PyObject *return_value = NULL;
5109 : : gid_t egid;
5110 : :
5111 [ # # ]: 0 : if (!_Py_Gid_Converter(arg, &egid)) {
5112 : 0 : goto exit;
5113 : : }
5114 : 0 : return_value = os_setegid_impl(module, egid);
5115 : :
5116 : 0 : exit:
5117 : 0 : return return_value;
5118 : : }
5119 : :
5120 : : #endif /* defined(HAVE_SETEGID) */
5121 : :
5122 : : #if defined(HAVE_SETREUID)
5123 : :
5124 : : PyDoc_STRVAR(os_setreuid__doc__,
5125 : : "setreuid($module, ruid, euid, /)\n"
5126 : : "--\n"
5127 : : "\n"
5128 : : "Set the current process\'s real and effective user ids.");
5129 : :
5130 : : #define OS_SETREUID_METHODDEF \
5131 : : {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
5132 : :
5133 : : static PyObject *
5134 : : os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
5135 : :
5136 : : static PyObject *
5137 : 0 : os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5138 : : {
5139 : 0 : PyObject *return_value = NULL;
5140 : : uid_t ruid;
5141 : : uid_t euid;
5142 : :
5143 [ # # # # : 0 : if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
# # ]
5144 : 0 : goto exit;
5145 : : }
5146 [ # # ]: 0 : if (!_Py_Uid_Converter(args[0], &ruid)) {
5147 : 0 : goto exit;
5148 : : }
5149 [ # # ]: 0 : if (!_Py_Uid_Converter(args[1], &euid)) {
5150 : 0 : goto exit;
5151 : : }
5152 : 0 : return_value = os_setreuid_impl(module, ruid, euid);
5153 : :
5154 : 0 : exit:
5155 : 0 : return return_value;
5156 : : }
5157 : :
5158 : : #endif /* defined(HAVE_SETREUID) */
5159 : :
5160 : : #if defined(HAVE_SETREGID)
5161 : :
5162 : : PyDoc_STRVAR(os_setregid__doc__,
5163 : : "setregid($module, rgid, egid, /)\n"
5164 : : "--\n"
5165 : : "\n"
5166 : : "Set the current process\'s real and effective group ids.");
5167 : :
5168 : : #define OS_SETREGID_METHODDEF \
5169 : : {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
5170 : :
5171 : : static PyObject *
5172 : : os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
5173 : :
5174 : : static PyObject *
5175 : 0 : os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5176 : : {
5177 : 0 : PyObject *return_value = NULL;
5178 : : gid_t rgid;
5179 : : gid_t egid;
5180 : :
5181 [ # # # # : 0 : if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
# # ]
5182 : 0 : goto exit;
5183 : : }
5184 [ # # ]: 0 : if (!_Py_Gid_Converter(args[0], &rgid)) {
5185 : 0 : goto exit;
5186 : : }
5187 [ # # ]: 0 : if (!_Py_Gid_Converter(args[1], &egid)) {
5188 : 0 : goto exit;
5189 : : }
5190 : 0 : return_value = os_setregid_impl(module, rgid, egid);
5191 : :
5192 : 0 : exit:
5193 : 0 : return return_value;
5194 : : }
5195 : :
5196 : : #endif /* defined(HAVE_SETREGID) */
5197 : :
5198 : : #if defined(HAVE_SETGID)
5199 : :
5200 : : PyDoc_STRVAR(os_setgid__doc__,
5201 : : "setgid($module, gid, /)\n"
5202 : : "--\n"
5203 : : "\n"
5204 : : "Set the current process\'s group id.");
5205 : :
5206 : : #define OS_SETGID_METHODDEF \
5207 : : {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
5208 : :
5209 : : static PyObject *
5210 : : os_setgid_impl(PyObject *module, gid_t gid);
5211 : :
5212 : : static PyObject *
5213 : 0 : os_setgid(PyObject *module, PyObject *arg)
5214 : : {
5215 : 0 : PyObject *return_value = NULL;
5216 : : gid_t gid;
5217 : :
5218 [ # # ]: 0 : if (!_Py_Gid_Converter(arg, &gid)) {
5219 : 0 : goto exit;
5220 : : }
5221 : 0 : return_value = os_setgid_impl(module, gid);
5222 : :
5223 : 0 : exit:
5224 : 0 : return return_value;
5225 : : }
5226 : :
5227 : : #endif /* defined(HAVE_SETGID) */
5228 : :
5229 : : #if defined(HAVE_SETGROUPS)
5230 : :
5231 : : PyDoc_STRVAR(os_setgroups__doc__,
5232 : : "setgroups($module, groups, /)\n"
5233 : : "--\n"
5234 : : "\n"
5235 : : "Set the groups of the current process to list.");
5236 : :
5237 : : #define OS_SETGROUPS_METHODDEF \
5238 : : {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
5239 : :
5240 : : #endif /* defined(HAVE_SETGROUPS) */
5241 : :
5242 : : #if defined(HAVE_WAIT3)
5243 : :
5244 : : PyDoc_STRVAR(os_wait3__doc__,
5245 : : "wait3($module, /, options)\n"
5246 : : "--\n"
5247 : : "\n"
5248 : : "Wait for completion of a child process.\n"
5249 : : "\n"
5250 : : "Returns a tuple of information about the child process:\n"
5251 : : " (pid, status, rusage)");
5252 : :
5253 : : #define OS_WAIT3_METHODDEF \
5254 : : {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
5255 : :
5256 : : static PyObject *
5257 : : os_wait3_impl(PyObject *module, int options);
5258 : :
5259 : : static PyObject *
5260 : 0 : os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5261 : : {
5262 : 0 : PyObject *return_value = NULL;
5263 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5264 : :
5265 : : #define NUM_KEYWORDS 1
5266 : : static struct {
5267 : : PyGC_Head _this_is_not_used;
5268 : : PyObject_VAR_HEAD
5269 : : PyObject *ob_item[NUM_KEYWORDS];
5270 : : } _kwtuple = {
5271 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5272 : : .ob_item = { &_Py_ID(options), },
5273 : : };
5274 : : #undef NUM_KEYWORDS
5275 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5276 : :
5277 : : #else // !Py_BUILD_CORE
5278 : : # define KWTUPLE NULL
5279 : : #endif // !Py_BUILD_CORE
5280 : :
5281 : : static const char * const _keywords[] = {"options", NULL};
5282 : : static _PyArg_Parser _parser = {
5283 : : .keywords = _keywords,
5284 : : .fname = "wait3",
5285 : : .kwtuple = KWTUPLE,
5286 : : };
5287 : : #undef KWTUPLE
5288 : : PyObject *argsbuf[1];
5289 : : int options;
5290 : :
5291 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
5292 [ # # ]: 0 : if (!args) {
5293 : 0 : goto exit;
5294 : : }
5295 : 0 : options = _PyLong_AsInt(args[0]);
5296 [ # # # # ]: 0 : if (options == -1 && PyErr_Occurred()) {
5297 : 0 : goto exit;
5298 : : }
5299 : 0 : return_value = os_wait3_impl(module, options);
5300 : :
5301 : 0 : exit:
5302 : 0 : return return_value;
5303 : : }
5304 : :
5305 : : #endif /* defined(HAVE_WAIT3) */
5306 : :
5307 : : #if defined(HAVE_WAIT4)
5308 : :
5309 : : PyDoc_STRVAR(os_wait4__doc__,
5310 : : "wait4($module, /, pid, options)\n"
5311 : : "--\n"
5312 : : "\n"
5313 : : "Wait for completion of a specific child process.\n"
5314 : : "\n"
5315 : : "Returns a tuple of information about the child process:\n"
5316 : : " (pid, status, rusage)");
5317 : :
5318 : : #define OS_WAIT4_METHODDEF \
5319 : : {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
5320 : :
5321 : : static PyObject *
5322 : : os_wait4_impl(PyObject *module, pid_t pid, int options);
5323 : :
5324 : : static PyObject *
5325 : 0 : os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5326 : : {
5327 : 0 : PyObject *return_value = NULL;
5328 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5329 : :
5330 : : #define NUM_KEYWORDS 2
5331 : : static struct {
5332 : : PyGC_Head _this_is_not_used;
5333 : : PyObject_VAR_HEAD
5334 : : PyObject *ob_item[NUM_KEYWORDS];
5335 : : } _kwtuple = {
5336 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5337 : : .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
5338 : : };
5339 : : #undef NUM_KEYWORDS
5340 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5341 : :
5342 : : #else // !Py_BUILD_CORE
5343 : : # define KWTUPLE NULL
5344 : : #endif // !Py_BUILD_CORE
5345 : :
5346 : : static const char * const _keywords[] = {"pid", "options", NULL};
5347 : : static _PyArg_Parser _parser = {
5348 : : .keywords = _keywords,
5349 : : .format = "" _Py_PARSE_PID "i:wait4",
5350 : : .kwtuple = KWTUPLE,
5351 : : };
5352 : : #undef KWTUPLE
5353 : : pid_t pid;
5354 : : int options;
5355 : :
5356 [ # # ]: 0 : if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5357 : : &pid, &options)) {
5358 : 0 : goto exit;
5359 : : }
5360 : 0 : return_value = os_wait4_impl(module, pid, options);
5361 : :
5362 : 0 : exit:
5363 : 0 : return return_value;
5364 : : }
5365 : :
5366 : : #endif /* defined(HAVE_WAIT4) */
5367 : :
5368 : : #if (defined(HAVE_WAITID) && !defined(__APPLE__))
5369 : :
5370 : : PyDoc_STRVAR(os_waitid__doc__,
5371 : : "waitid($module, idtype, id, options, /)\n"
5372 : : "--\n"
5373 : : "\n"
5374 : : "Returns the result of waiting for a process or processes.\n"
5375 : : "\n"
5376 : : " idtype\n"
5377 : : " Must be one of be P_PID, P_PGID or P_ALL.\n"
5378 : : " id\n"
5379 : : " The id to wait on.\n"
5380 : : " options\n"
5381 : : " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
5382 : : " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
5383 : : "\n"
5384 : : "Returns either waitid_result or None if WNOHANG is specified and there are\n"
5385 : : "no children in a waitable state.");
5386 : :
5387 : : #define OS_WAITID_METHODDEF \
5388 : : {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
5389 : :
5390 : : static PyObject *
5391 : : os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
5392 : :
5393 : : static PyObject *
5394 : 0 : os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5395 : : {
5396 : 0 : PyObject *return_value = NULL;
5397 : : idtype_t idtype;
5398 : : id_t id;
5399 : : int options;
5400 : :
5401 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
5402 : : &idtype, &id, &options)) {
5403 : 0 : goto exit;
5404 : : }
5405 : 0 : return_value = os_waitid_impl(module, idtype, id, options);
5406 : :
5407 : 0 : exit:
5408 : 0 : return return_value;
5409 : : }
5410 : :
5411 : : #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
5412 : :
5413 : : #if defined(HAVE_WAITPID)
5414 : :
5415 : : PyDoc_STRVAR(os_waitpid__doc__,
5416 : : "waitpid($module, pid, options, /)\n"
5417 : : "--\n"
5418 : : "\n"
5419 : : "Wait for completion of a given child process.\n"
5420 : : "\n"
5421 : : "Returns a tuple of information regarding the child process:\n"
5422 : : " (pid, status)\n"
5423 : : "\n"
5424 : : "The options argument is ignored on Windows.");
5425 : :
5426 : : #define OS_WAITPID_METHODDEF \
5427 : : {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
5428 : :
5429 : : static PyObject *
5430 : : os_waitpid_impl(PyObject *module, pid_t pid, int options);
5431 : :
5432 : : static PyObject *
5433 : 1 : os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5434 : : {
5435 : 1 : PyObject *return_value = NULL;
5436 : : pid_t pid;
5437 : : int options;
5438 : :
5439 [ - + ]: 1 : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
5440 : : &pid, &options)) {
5441 : 0 : goto exit;
5442 : : }
5443 : 1 : return_value = os_waitpid_impl(module, pid, options);
5444 : :
5445 : 1 : exit:
5446 : 1 : return return_value;
5447 : : }
5448 : :
5449 : : #endif /* defined(HAVE_WAITPID) */
5450 : :
5451 : : #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
5452 : :
5453 : : PyDoc_STRVAR(os_waitpid__doc__,
5454 : : "waitpid($module, pid, options, /)\n"
5455 : : "--\n"
5456 : : "\n"
5457 : : "Wait for completion of a given process.\n"
5458 : : "\n"
5459 : : "Returns a tuple of information regarding the process:\n"
5460 : : " (pid, status << 8)\n"
5461 : : "\n"
5462 : : "The options argument is ignored on Windows.");
5463 : :
5464 : : #define OS_WAITPID_METHODDEF \
5465 : : {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
5466 : :
5467 : : static PyObject *
5468 : : os_waitpid_impl(PyObject *module, intptr_t pid, int options);
5469 : :
5470 : : static PyObject *
5471 : : os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5472 : : {
5473 : : PyObject *return_value = NULL;
5474 : : intptr_t pid;
5475 : : int options;
5476 : :
5477 : : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
5478 : : &pid, &options)) {
5479 : : goto exit;
5480 : : }
5481 : : return_value = os_waitpid_impl(module, pid, options);
5482 : :
5483 : : exit:
5484 : : return return_value;
5485 : : }
5486 : :
5487 : : #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
5488 : :
5489 : : #if defined(HAVE_WAIT)
5490 : :
5491 : : PyDoc_STRVAR(os_wait__doc__,
5492 : : "wait($module, /)\n"
5493 : : "--\n"
5494 : : "\n"
5495 : : "Wait for completion of a child process.\n"
5496 : : "\n"
5497 : : "Returns a tuple of information about the child process:\n"
5498 : : " (pid, status)");
5499 : :
5500 : : #define OS_WAIT_METHODDEF \
5501 : : {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
5502 : :
5503 : : static PyObject *
5504 : : os_wait_impl(PyObject *module);
5505 : :
5506 : : static PyObject *
5507 : 0 : os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
5508 : : {
5509 : 0 : return os_wait_impl(module);
5510 : : }
5511 : :
5512 : : #endif /* defined(HAVE_WAIT) */
5513 : :
5514 : : #if (defined(__linux__) && defined(__NR_pidfd_open))
5515 : :
5516 : : PyDoc_STRVAR(os_pidfd_open__doc__,
5517 : : "pidfd_open($module, /, pid, flags=0)\n"
5518 : : "--\n"
5519 : : "\n"
5520 : : "Return a file descriptor referring to the process *pid*.\n"
5521 : : "\n"
5522 : : "The descriptor can be used to perform process management without races and\n"
5523 : : "signals.");
5524 : :
5525 : : #define OS_PIDFD_OPEN_METHODDEF \
5526 : : {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
5527 : :
5528 : : static PyObject *
5529 : : os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
5530 : :
5531 : : static PyObject *
5532 : 0 : os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5533 : : {
5534 : 0 : PyObject *return_value = NULL;
5535 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5536 : :
5537 : : #define NUM_KEYWORDS 2
5538 : : static struct {
5539 : : PyGC_Head _this_is_not_used;
5540 : : PyObject_VAR_HEAD
5541 : : PyObject *ob_item[NUM_KEYWORDS];
5542 : : } _kwtuple = {
5543 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5544 : : .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
5545 : : };
5546 : : #undef NUM_KEYWORDS
5547 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5548 : :
5549 : : #else // !Py_BUILD_CORE
5550 : : # define KWTUPLE NULL
5551 : : #endif // !Py_BUILD_CORE
5552 : :
5553 : : static const char * const _keywords[] = {"pid", "flags", NULL};
5554 : : static _PyArg_Parser _parser = {
5555 : : .keywords = _keywords,
5556 : : .format = "" _Py_PARSE_PID "|O&:pidfd_open",
5557 : : .kwtuple = KWTUPLE,
5558 : : };
5559 : : #undef KWTUPLE
5560 : : pid_t pid;
5561 : 0 : unsigned int flags = 0;
5562 : :
5563 [ # # ]: 0 : if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
5564 : : &pid, _PyLong_UnsignedInt_Converter, &flags)) {
5565 : 0 : goto exit;
5566 : : }
5567 : 0 : return_value = os_pidfd_open_impl(module, pid, flags);
5568 : :
5569 : 0 : exit:
5570 : 0 : return return_value;
5571 : : }
5572 : :
5573 : : #endif /* (defined(__linux__) && defined(__NR_pidfd_open)) */
5574 : :
5575 : : #if defined(HAVE_SETNS)
5576 : :
5577 : : PyDoc_STRVAR(os_setns__doc__,
5578 : : "setns($module, /, fd, nstype=0)\n"
5579 : : "--\n"
5580 : : "\n"
5581 : : "Move the calling thread into different namespaces.\n"
5582 : : "\n"
5583 : : " fd\n"
5584 : : " A file descriptor to a namespace.\n"
5585 : : " nstype\n"
5586 : : " Type of namespace.");
5587 : :
5588 : : #define OS_SETNS_METHODDEF \
5589 : : {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
5590 : :
5591 : : static PyObject *
5592 : : os_setns_impl(PyObject *module, int fd, int nstype);
5593 : :
5594 : : static PyObject *
5595 : 0 : os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5596 : : {
5597 : 0 : PyObject *return_value = NULL;
5598 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5599 : :
5600 : : #define NUM_KEYWORDS 2
5601 : : static struct {
5602 : : PyGC_Head _this_is_not_used;
5603 : : PyObject_VAR_HEAD
5604 : : PyObject *ob_item[NUM_KEYWORDS];
5605 : : } _kwtuple = {
5606 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5607 : : .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
5608 : : };
5609 : : #undef NUM_KEYWORDS
5610 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5611 : :
5612 : : #else // !Py_BUILD_CORE
5613 : : # define KWTUPLE NULL
5614 : : #endif // !Py_BUILD_CORE
5615 : :
5616 : : static const char * const _keywords[] = {"fd", "nstype", NULL};
5617 : : static _PyArg_Parser _parser = {
5618 : : .keywords = _keywords,
5619 : : .fname = "setns",
5620 : : .kwtuple = KWTUPLE,
5621 : : };
5622 : : #undef KWTUPLE
5623 : : PyObject *argsbuf[2];
5624 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
5625 : : int fd;
5626 : 0 : int nstype = 0;
5627 : :
5628 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
5629 [ # # ]: 0 : if (!args) {
5630 : 0 : goto exit;
5631 : : }
5632 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
5633 : 0 : goto exit;
5634 : : }
5635 [ # # ]: 0 : if (!noptargs) {
5636 : 0 : goto skip_optional_pos;
5637 : : }
5638 : 0 : nstype = _PyLong_AsInt(args[1]);
5639 [ # # # # ]: 0 : if (nstype == -1 && PyErr_Occurred()) {
5640 : 0 : goto exit;
5641 : : }
5642 : 0 : skip_optional_pos:
5643 : 0 : return_value = os_setns_impl(module, fd, nstype);
5644 : :
5645 : 0 : exit:
5646 : 0 : return return_value;
5647 : : }
5648 : :
5649 : : #endif /* defined(HAVE_SETNS) */
5650 : :
5651 : : #if defined(HAVE_UNSHARE)
5652 : :
5653 : : PyDoc_STRVAR(os_unshare__doc__,
5654 : : "unshare($module, /, flags)\n"
5655 : : "--\n"
5656 : : "\n"
5657 : : "Disassociate parts of a process (or thread) execution context.\n"
5658 : : "\n"
5659 : : " flags\n"
5660 : : " Namespaces to be unshared.");
5661 : :
5662 : : #define OS_UNSHARE_METHODDEF \
5663 : : {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
5664 : :
5665 : : static PyObject *
5666 : : os_unshare_impl(PyObject *module, int flags);
5667 : :
5668 : : static PyObject *
5669 : 0 : os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5670 : : {
5671 : 0 : PyObject *return_value = NULL;
5672 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5673 : :
5674 : : #define NUM_KEYWORDS 1
5675 : : static struct {
5676 : : PyGC_Head _this_is_not_used;
5677 : : PyObject_VAR_HEAD
5678 : : PyObject *ob_item[NUM_KEYWORDS];
5679 : : } _kwtuple = {
5680 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5681 : : .ob_item = { &_Py_ID(flags), },
5682 : : };
5683 : : #undef NUM_KEYWORDS
5684 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5685 : :
5686 : : #else // !Py_BUILD_CORE
5687 : : # define KWTUPLE NULL
5688 : : #endif // !Py_BUILD_CORE
5689 : :
5690 : : static const char * const _keywords[] = {"flags", NULL};
5691 : : static _PyArg_Parser _parser = {
5692 : : .keywords = _keywords,
5693 : : .fname = "unshare",
5694 : : .kwtuple = KWTUPLE,
5695 : : };
5696 : : #undef KWTUPLE
5697 : : PyObject *argsbuf[1];
5698 : : int flags;
5699 : :
5700 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
5701 [ # # ]: 0 : if (!args) {
5702 : 0 : goto exit;
5703 : : }
5704 : 0 : flags = _PyLong_AsInt(args[0]);
5705 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
5706 : 0 : goto exit;
5707 : : }
5708 : 0 : return_value = os_unshare_impl(module, flags);
5709 : :
5710 : 0 : exit:
5711 : 0 : return return_value;
5712 : : }
5713 : :
5714 : : #endif /* defined(HAVE_UNSHARE) */
5715 : :
5716 : : #if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
5717 : :
5718 : : PyDoc_STRVAR(os_readlink__doc__,
5719 : : "readlink($module, /, path, *, dir_fd=None)\n"
5720 : : "--\n"
5721 : : "\n"
5722 : : "Return a string representing the path to which the symbolic link points.\n"
5723 : : "\n"
5724 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
5725 : : "and path should be relative; path will then be relative to that directory.\n"
5726 : : "\n"
5727 : : "dir_fd may not be implemented on your platform. If it is unavailable,\n"
5728 : : "using it will raise a NotImplementedError.");
5729 : :
5730 : : #define OS_READLINK_METHODDEF \
5731 : : {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
5732 : :
5733 : : static PyObject *
5734 : : os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
5735 : :
5736 : : static PyObject *
5737 : 0 : os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5738 : : {
5739 : 0 : PyObject *return_value = NULL;
5740 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5741 : :
5742 : : #define NUM_KEYWORDS 2
5743 : : static struct {
5744 : : PyGC_Head _this_is_not_used;
5745 : : PyObject_VAR_HEAD
5746 : : PyObject *ob_item[NUM_KEYWORDS];
5747 : : } _kwtuple = {
5748 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5749 : : .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
5750 : : };
5751 : : #undef NUM_KEYWORDS
5752 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5753 : :
5754 : : #else // !Py_BUILD_CORE
5755 : : # define KWTUPLE NULL
5756 : : #endif // !Py_BUILD_CORE
5757 : :
5758 : : static const char * const _keywords[] = {"path", "dir_fd", NULL};
5759 : : static _PyArg_Parser _parser = {
5760 : : .keywords = _keywords,
5761 : : .fname = "readlink",
5762 : : .kwtuple = KWTUPLE,
5763 : : };
5764 : : #undef KWTUPLE
5765 : : PyObject *argsbuf[2];
5766 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
5767 : 0 : path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
5768 : 0 : int dir_fd = DEFAULT_DIR_FD;
5769 : :
5770 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
5771 [ # # ]: 0 : if (!args) {
5772 : 0 : goto exit;
5773 : : }
5774 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
5775 : 0 : goto exit;
5776 : : }
5777 [ # # ]: 0 : if (!noptargs) {
5778 : 0 : goto skip_optional_kwonly;
5779 : : }
5780 [ # # ]: 0 : if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
5781 : 0 : goto exit;
5782 : : }
5783 : 0 : skip_optional_kwonly:
5784 : 0 : return_value = os_readlink_impl(module, &path, dir_fd);
5785 : :
5786 : 0 : exit:
5787 : : /* Cleanup for path */
5788 : 0 : path_cleanup(&path);
5789 : :
5790 : 0 : return return_value;
5791 : : }
5792 : :
5793 : : #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
5794 : :
5795 : : #if defined(HAVE_SYMLINK)
5796 : :
5797 : : PyDoc_STRVAR(os_symlink__doc__,
5798 : : "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
5799 : : "--\n"
5800 : : "\n"
5801 : : "Create a symbolic link pointing to src named dst.\n"
5802 : : "\n"
5803 : : "target_is_directory is required on Windows if the target is to be\n"
5804 : : " interpreted as a directory. (On Windows, symlink requires\n"
5805 : : " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
5806 : : " target_is_directory is ignored on non-Windows platforms.\n"
5807 : : "\n"
5808 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
5809 : : " and path should be relative; path will then be relative to that directory.\n"
5810 : : "dir_fd may not be implemented on your platform.\n"
5811 : : " If it is unavailable, using it will raise a NotImplementedError.");
5812 : :
5813 : : #define OS_SYMLINK_METHODDEF \
5814 : : {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
5815 : :
5816 : : static PyObject *
5817 : : os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
5818 : : int target_is_directory, int dir_fd);
5819 : :
5820 : : static PyObject *
5821 : 0 : os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
5822 : : {
5823 : 0 : PyObject *return_value = NULL;
5824 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
5825 : :
5826 : : #define NUM_KEYWORDS 4
5827 : : static struct {
5828 : : PyGC_Head _this_is_not_used;
5829 : : PyObject_VAR_HEAD
5830 : : PyObject *ob_item[NUM_KEYWORDS];
5831 : : } _kwtuple = {
5832 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
5833 : : .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
5834 : : };
5835 : : #undef NUM_KEYWORDS
5836 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
5837 : :
5838 : : #else // !Py_BUILD_CORE
5839 : : # define KWTUPLE NULL
5840 : : #endif // !Py_BUILD_CORE
5841 : :
5842 : : static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
5843 : : static _PyArg_Parser _parser = {
5844 : : .keywords = _keywords,
5845 : : .fname = "symlink",
5846 : : .kwtuple = KWTUPLE,
5847 : : };
5848 : : #undef KWTUPLE
5849 : : PyObject *argsbuf[4];
5850 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
5851 : 0 : path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
5852 : 0 : path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
5853 : 0 : int target_is_directory = 0;
5854 : 0 : int dir_fd = DEFAULT_DIR_FD;
5855 : :
5856 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
# # # # ]
5857 [ # # ]: 0 : if (!args) {
5858 : 0 : goto exit;
5859 : : }
5860 [ # # ]: 0 : if (!path_converter(args[0], &src)) {
5861 : 0 : goto exit;
5862 : : }
5863 [ # # ]: 0 : if (!path_converter(args[1], &dst)) {
5864 : 0 : goto exit;
5865 : : }
5866 [ # # ]: 0 : if (!noptargs) {
5867 : 0 : goto skip_optional_pos;
5868 : : }
5869 [ # # ]: 0 : if (args[2]) {
5870 : 0 : target_is_directory = PyObject_IsTrue(args[2]);
5871 [ # # ]: 0 : if (target_is_directory < 0) {
5872 : 0 : goto exit;
5873 : : }
5874 [ # # ]: 0 : if (!--noptargs) {
5875 : 0 : goto skip_optional_pos;
5876 : : }
5877 : : }
5878 : 0 : skip_optional_pos:
5879 [ # # ]: 0 : if (!noptargs) {
5880 : 0 : goto skip_optional_kwonly;
5881 : : }
5882 [ # # ]: 0 : if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
5883 : 0 : goto exit;
5884 : : }
5885 : 0 : skip_optional_kwonly:
5886 : 0 : return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
5887 : :
5888 : 0 : exit:
5889 : : /* Cleanup for src */
5890 : 0 : path_cleanup(&src);
5891 : : /* Cleanup for dst */
5892 : 0 : path_cleanup(&dst);
5893 : :
5894 : 0 : return return_value;
5895 : : }
5896 : :
5897 : : #endif /* defined(HAVE_SYMLINK) */
5898 : :
5899 : : #if defined(HAVE_TIMES)
5900 : :
5901 : : PyDoc_STRVAR(os_times__doc__,
5902 : : "times($module, /)\n"
5903 : : "--\n"
5904 : : "\n"
5905 : : "Return a collection containing process timing information.\n"
5906 : : "\n"
5907 : : "The object returned behaves like a named tuple with these fields:\n"
5908 : : " (utime, stime, cutime, cstime, elapsed_time)\n"
5909 : : "All fields are floating point numbers.");
5910 : :
5911 : : #define OS_TIMES_METHODDEF \
5912 : : {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
5913 : :
5914 : : static PyObject *
5915 : : os_times_impl(PyObject *module);
5916 : :
5917 : : static PyObject *
5918 : 0 : os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
5919 : : {
5920 : 0 : return os_times_impl(module);
5921 : : }
5922 : :
5923 : : #endif /* defined(HAVE_TIMES) */
5924 : :
5925 : : #if defined(HAVE_GETSID)
5926 : :
5927 : : PyDoc_STRVAR(os_getsid__doc__,
5928 : : "getsid($module, pid, /)\n"
5929 : : "--\n"
5930 : : "\n"
5931 : : "Call the system call getsid(pid) and return the result.");
5932 : :
5933 : : #define OS_GETSID_METHODDEF \
5934 : : {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
5935 : :
5936 : : static PyObject *
5937 : : os_getsid_impl(PyObject *module, pid_t pid);
5938 : :
5939 : : static PyObject *
5940 : 0 : os_getsid(PyObject *module, PyObject *arg)
5941 : : {
5942 : 0 : PyObject *return_value = NULL;
5943 : : pid_t pid;
5944 : :
5945 [ # # ]: 0 : if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
5946 : 0 : goto exit;
5947 : : }
5948 : 0 : return_value = os_getsid_impl(module, pid);
5949 : :
5950 : 0 : exit:
5951 : 0 : return return_value;
5952 : : }
5953 : :
5954 : : #endif /* defined(HAVE_GETSID) */
5955 : :
5956 : : #if defined(HAVE_SETSID)
5957 : :
5958 : : PyDoc_STRVAR(os_setsid__doc__,
5959 : : "setsid($module, /)\n"
5960 : : "--\n"
5961 : : "\n"
5962 : : "Call the system call setsid().");
5963 : :
5964 : : #define OS_SETSID_METHODDEF \
5965 : : {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
5966 : :
5967 : : static PyObject *
5968 : : os_setsid_impl(PyObject *module);
5969 : :
5970 : : static PyObject *
5971 : 0 : os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
5972 : : {
5973 : 0 : return os_setsid_impl(module);
5974 : : }
5975 : :
5976 : : #endif /* defined(HAVE_SETSID) */
5977 : :
5978 : : #if defined(HAVE_SETPGID)
5979 : :
5980 : : PyDoc_STRVAR(os_setpgid__doc__,
5981 : : "setpgid($module, pid, pgrp, /)\n"
5982 : : "--\n"
5983 : : "\n"
5984 : : "Call the system call setpgid(pid, pgrp).");
5985 : :
5986 : : #define OS_SETPGID_METHODDEF \
5987 : : {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
5988 : :
5989 : : static PyObject *
5990 : : os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
5991 : :
5992 : : static PyObject *
5993 : 0 : os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
5994 : : {
5995 : 0 : PyObject *return_value = NULL;
5996 : : pid_t pid;
5997 : : pid_t pgrp;
5998 : :
5999 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
6000 : : &pid, &pgrp)) {
6001 : 0 : goto exit;
6002 : : }
6003 : 0 : return_value = os_setpgid_impl(module, pid, pgrp);
6004 : :
6005 : 0 : exit:
6006 : 0 : return return_value;
6007 : : }
6008 : :
6009 : : #endif /* defined(HAVE_SETPGID) */
6010 : :
6011 : : #if defined(HAVE_TCGETPGRP)
6012 : :
6013 : : PyDoc_STRVAR(os_tcgetpgrp__doc__,
6014 : : "tcgetpgrp($module, fd, /)\n"
6015 : : "--\n"
6016 : : "\n"
6017 : : "Return the process group associated with the terminal specified by fd.");
6018 : :
6019 : : #define OS_TCGETPGRP_METHODDEF \
6020 : : {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
6021 : :
6022 : : static PyObject *
6023 : : os_tcgetpgrp_impl(PyObject *module, int fd);
6024 : :
6025 : : static PyObject *
6026 : 0 : os_tcgetpgrp(PyObject *module, PyObject *arg)
6027 : : {
6028 : 0 : PyObject *return_value = NULL;
6029 : : int fd;
6030 : :
6031 : 0 : fd = _PyLong_AsInt(arg);
6032 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6033 : 0 : goto exit;
6034 : : }
6035 : 0 : return_value = os_tcgetpgrp_impl(module, fd);
6036 : :
6037 : 0 : exit:
6038 : 0 : return return_value;
6039 : : }
6040 : :
6041 : : #endif /* defined(HAVE_TCGETPGRP) */
6042 : :
6043 : : #if defined(HAVE_TCSETPGRP)
6044 : :
6045 : : PyDoc_STRVAR(os_tcsetpgrp__doc__,
6046 : : "tcsetpgrp($module, fd, pgid, /)\n"
6047 : : "--\n"
6048 : : "\n"
6049 : : "Set the process group associated with the terminal specified by fd.");
6050 : :
6051 : : #define OS_TCSETPGRP_METHODDEF \
6052 : : {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
6053 : :
6054 : : static PyObject *
6055 : : os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
6056 : :
6057 : : static PyObject *
6058 : 0 : os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6059 : : {
6060 : 0 : PyObject *return_value = NULL;
6061 : : int fd;
6062 : : pid_t pgid;
6063 : :
6064 [ # # ]: 0 : if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
6065 : : &fd, &pgid)) {
6066 : 0 : goto exit;
6067 : : }
6068 : 0 : return_value = os_tcsetpgrp_impl(module, fd, pgid);
6069 : :
6070 : 0 : exit:
6071 : 0 : return return_value;
6072 : : }
6073 : :
6074 : : #endif /* defined(HAVE_TCSETPGRP) */
6075 : :
6076 : : PyDoc_STRVAR(os_open__doc__,
6077 : : "open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
6078 : : "--\n"
6079 : : "\n"
6080 : : "Open a file for low level IO. Returns a file descriptor (integer).\n"
6081 : : "\n"
6082 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
6083 : : " and path should be relative; path will then be relative to that directory.\n"
6084 : : "dir_fd may not be implemented on your platform.\n"
6085 : : " If it is unavailable, using it will raise a NotImplementedError.");
6086 : :
6087 : : #define OS_OPEN_METHODDEF \
6088 : : {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
6089 : :
6090 : : static int
6091 : : os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
6092 : :
6093 : : static PyObject *
6094 : 160 : os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6095 : : {
6096 : 160 : PyObject *return_value = NULL;
6097 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6098 : :
6099 : : #define NUM_KEYWORDS 4
6100 : : static struct {
6101 : : PyGC_Head _this_is_not_used;
6102 : : PyObject_VAR_HEAD
6103 : : PyObject *ob_item[NUM_KEYWORDS];
6104 : : } _kwtuple = {
6105 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6106 : : .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
6107 : : };
6108 : : #undef NUM_KEYWORDS
6109 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6110 : :
6111 : : #else // !Py_BUILD_CORE
6112 : : # define KWTUPLE NULL
6113 : : #endif // !Py_BUILD_CORE
6114 : :
6115 : : static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
6116 : : static _PyArg_Parser _parser = {
6117 : : .keywords = _keywords,
6118 : : .fname = "open",
6119 : : .kwtuple = KWTUPLE,
6120 : : };
6121 : : #undef KWTUPLE
6122 : : PyObject *argsbuf[4];
6123 [ + + ]: 160 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6124 : 160 : path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
6125 : : int flags;
6126 : 160 : int mode = 511;
6127 : 160 : int dir_fd = DEFAULT_DIR_FD;
6128 : : int _return_value;
6129 : :
6130 [ + + + - : 160 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
+ - - + ]
6131 [ - + ]: 160 : if (!args) {
6132 : 0 : goto exit;
6133 : : }
6134 [ - + ]: 160 : if (!path_converter(args[0], &path)) {
6135 : 0 : goto exit;
6136 : : }
6137 : 160 : flags = _PyLong_AsInt(args[1]);
6138 [ - + - - ]: 160 : if (flags == -1 && PyErr_Occurred()) {
6139 : 0 : goto exit;
6140 : : }
6141 [ - + ]: 160 : if (!noptargs) {
6142 : 0 : goto skip_optional_pos;
6143 : : }
6144 [ + + ]: 160 : if (args[2]) {
6145 : 159 : mode = _PyLong_AsInt(args[2]);
6146 [ - + - - ]: 159 : if (mode == -1 && PyErr_Occurred()) {
6147 : 0 : goto exit;
6148 : : }
6149 [ - + ]: 159 : if (!--noptargs) {
6150 : 159 : goto skip_optional_pos;
6151 : : }
6152 : : }
6153 : 1 : skip_optional_pos:
6154 [ + + ]: 160 : if (!noptargs) {
6155 : 159 : goto skip_optional_kwonly;
6156 : : }
6157 [ - + ]: 1 : if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
6158 : 0 : goto exit;
6159 : : }
6160 : 1 : skip_optional_kwonly:
6161 : 160 : _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
6162 [ - + - - ]: 160 : if ((_return_value == -1) && PyErr_Occurred()) {
6163 : 0 : goto exit;
6164 : : }
6165 : 160 : return_value = PyLong_FromLong((long)_return_value);
6166 : :
6167 : 160 : exit:
6168 : : /* Cleanup for path */
6169 : 160 : path_cleanup(&path);
6170 : :
6171 : 160 : return return_value;
6172 : : }
6173 : :
6174 : : PyDoc_STRVAR(os_close__doc__,
6175 : : "close($module, /, fd)\n"
6176 : : "--\n"
6177 : : "\n"
6178 : : "Close a file descriptor.");
6179 : :
6180 : : #define OS_CLOSE_METHODDEF \
6181 : : {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
6182 : :
6183 : : static PyObject *
6184 : : os_close_impl(PyObject *module, int fd);
6185 : :
6186 : : static PyObject *
6187 : 1 : os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6188 : : {
6189 : 1 : PyObject *return_value = NULL;
6190 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6191 : :
6192 : : #define NUM_KEYWORDS 1
6193 : : static struct {
6194 : : PyGC_Head _this_is_not_used;
6195 : : PyObject_VAR_HEAD
6196 : : PyObject *ob_item[NUM_KEYWORDS];
6197 : : } _kwtuple = {
6198 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6199 : : .ob_item = { &_Py_ID(fd), },
6200 : : };
6201 : : #undef NUM_KEYWORDS
6202 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6203 : :
6204 : : #else // !Py_BUILD_CORE
6205 : : # define KWTUPLE NULL
6206 : : #endif // !Py_BUILD_CORE
6207 : :
6208 : : static const char * const _keywords[] = {"fd", NULL};
6209 : : static _PyArg_Parser _parser = {
6210 : : .keywords = _keywords,
6211 : : .fname = "close",
6212 : : .kwtuple = KWTUPLE,
6213 : : };
6214 : : #undef KWTUPLE
6215 : : PyObject *argsbuf[1];
6216 : : int fd;
6217 : :
6218 [ + - + - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
6219 [ - + ]: 1 : if (!args) {
6220 : 0 : goto exit;
6221 : : }
6222 : 1 : fd = _PyLong_AsInt(args[0]);
6223 [ - + - - ]: 1 : if (fd == -1 && PyErr_Occurred()) {
6224 : 0 : goto exit;
6225 : : }
6226 : 1 : return_value = os_close_impl(module, fd);
6227 : :
6228 : 1 : exit:
6229 : 1 : return return_value;
6230 : : }
6231 : :
6232 : : PyDoc_STRVAR(os_closerange__doc__,
6233 : : "closerange($module, fd_low, fd_high, /)\n"
6234 : : "--\n"
6235 : : "\n"
6236 : : "Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
6237 : :
6238 : : #define OS_CLOSERANGE_METHODDEF \
6239 : : {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
6240 : :
6241 : : static PyObject *
6242 : : os_closerange_impl(PyObject *module, int fd_low, int fd_high);
6243 : :
6244 : : static PyObject *
6245 : 0 : os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6246 : : {
6247 : 0 : PyObject *return_value = NULL;
6248 : : int fd_low;
6249 : : int fd_high;
6250 : :
6251 [ # # # # : 0 : if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
# # ]
6252 : 0 : goto exit;
6253 : : }
6254 : 0 : fd_low = _PyLong_AsInt(args[0]);
6255 [ # # # # ]: 0 : if (fd_low == -1 && PyErr_Occurred()) {
6256 : 0 : goto exit;
6257 : : }
6258 : 0 : fd_high = _PyLong_AsInt(args[1]);
6259 [ # # # # ]: 0 : if (fd_high == -1 && PyErr_Occurred()) {
6260 : 0 : goto exit;
6261 : : }
6262 : 0 : return_value = os_closerange_impl(module, fd_low, fd_high);
6263 : :
6264 : 0 : exit:
6265 : 0 : return return_value;
6266 : : }
6267 : :
6268 : : PyDoc_STRVAR(os_dup__doc__,
6269 : : "dup($module, fd, /)\n"
6270 : : "--\n"
6271 : : "\n"
6272 : : "Return a duplicate of a file descriptor.");
6273 : :
6274 : : #define OS_DUP_METHODDEF \
6275 : : {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
6276 : :
6277 : : static int
6278 : : os_dup_impl(PyObject *module, int fd);
6279 : :
6280 : : static PyObject *
6281 : 0 : os_dup(PyObject *module, PyObject *arg)
6282 : : {
6283 : 0 : PyObject *return_value = NULL;
6284 : : int fd;
6285 : : int _return_value;
6286 : :
6287 : 0 : fd = _PyLong_AsInt(arg);
6288 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6289 : 0 : goto exit;
6290 : : }
6291 : 0 : _return_value = os_dup_impl(module, fd);
6292 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
6293 : 0 : goto exit;
6294 : : }
6295 : 0 : return_value = PyLong_FromLong((long)_return_value);
6296 : :
6297 : 0 : exit:
6298 : 0 : return return_value;
6299 : : }
6300 : :
6301 : : #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
6302 : :
6303 : : PyDoc_STRVAR(os_dup2__doc__,
6304 : : "dup2($module, /, fd, fd2, inheritable=True)\n"
6305 : : "--\n"
6306 : : "\n"
6307 : : "Duplicate file descriptor.");
6308 : :
6309 : : #define OS_DUP2_METHODDEF \
6310 : : {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
6311 : :
6312 : : static int
6313 : : os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
6314 : :
6315 : : static PyObject *
6316 : 0 : os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6317 : : {
6318 : 0 : PyObject *return_value = NULL;
6319 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6320 : :
6321 : : #define NUM_KEYWORDS 3
6322 : : static struct {
6323 : : PyGC_Head _this_is_not_used;
6324 : : PyObject_VAR_HEAD
6325 : : PyObject *ob_item[NUM_KEYWORDS];
6326 : : } _kwtuple = {
6327 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6328 : : .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
6329 : : };
6330 : : #undef NUM_KEYWORDS
6331 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6332 : :
6333 : : #else // !Py_BUILD_CORE
6334 : : # define KWTUPLE NULL
6335 : : #endif // !Py_BUILD_CORE
6336 : :
6337 : : static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
6338 : : static _PyArg_Parser _parser = {
6339 : : .keywords = _keywords,
6340 : : .fname = "dup2",
6341 : : .kwtuple = KWTUPLE,
6342 : : };
6343 : : #undef KWTUPLE
6344 : : PyObject *argsbuf[3];
6345 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
6346 : : int fd;
6347 : : int fd2;
6348 : 0 : int inheritable = 1;
6349 : : int _return_value;
6350 : :
6351 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
# # # # ]
6352 [ # # ]: 0 : if (!args) {
6353 : 0 : goto exit;
6354 : : }
6355 : 0 : fd = _PyLong_AsInt(args[0]);
6356 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6357 : 0 : goto exit;
6358 : : }
6359 : 0 : fd2 = _PyLong_AsInt(args[1]);
6360 [ # # # # ]: 0 : if (fd2 == -1 && PyErr_Occurred()) {
6361 : 0 : goto exit;
6362 : : }
6363 [ # # ]: 0 : if (!noptargs) {
6364 : 0 : goto skip_optional_pos;
6365 : : }
6366 : 0 : inheritable = PyObject_IsTrue(args[2]);
6367 [ # # ]: 0 : if (inheritable < 0) {
6368 : 0 : goto exit;
6369 : : }
6370 : 0 : skip_optional_pos:
6371 : 0 : _return_value = os_dup2_impl(module, fd, fd2, inheritable);
6372 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
6373 : 0 : goto exit;
6374 : : }
6375 : 0 : return_value = PyLong_FromLong((long)_return_value);
6376 : :
6377 : 0 : exit:
6378 : 0 : return return_value;
6379 : : }
6380 : :
6381 : : #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
6382 : :
6383 : : #if defined(HAVE_LOCKF)
6384 : :
6385 : : PyDoc_STRVAR(os_lockf__doc__,
6386 : : "lockf($module, fd, command, length, /)\n"
6387 : : "--\n"
6388 : : "\n"
6389 : : "Apply, test or remove a POSIX lock on an open file descriptor.\n"
6390 : : "\n"
6391 : : " fd\n"
6392 : : " An open file descriptor.\n"
6393 : : " command\n"
6394 : : " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
6395 : : " length\n"
6396 : : " The number of bytes to lock, starting at the current position.");
6397 : :
6398 : : #define OS_LOCKF_METHODDEF \
6399 : : {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
6400 : :
6401 : : static PyObject *
6402 : : os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
6403 : :
6404 : : static PyObject *
6405 : 0 : os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6406 : : {
6407 : 0 : PyObject *return_value = NULL;
6408 : : int fd;
6409 : : int command;
6410 : : Py_off_t length;
6411 : :
6412 [ # # # # : 0 : if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
# # ]
6413 : 0 : goto exit;
6414 : : }
6415 : 0 : fd = _PyLong_AsInt(args[0]);
6416 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6417 : 0 : goto exit;
6418 : : }
6419 : 0 : command = _PyLong_AsInt(args[1]);
6420 [ # # # # ]: 0 : if (command == -1 && PyErr_Occurred()) {
6421 : 0 : goto exit;
6422 : : }
6423 [ # # ]: 0 : if (!Py_off_t_converter(args[2], &length)) {
6424 : 0 : goto exit;
6425 : : }
6426 : 0 : return_value = os_lockf_impl(module, fd, command, length);
6427 : :
6428 : 0 : exit:
6429 : 0 : return return_value;
6430 : : }
6431 : :
6432 : : #endif /* defined(HAVE_LOCKF) */
6433 : :
6434 : : PyDoc_STRVAR(os_lseek__doc__,
6435 : : "lseek($module, fd, position, how, /)\n"
6436 : : "--\n"
6437 : : "\n"
6438 : : "Set the position of a file descriptor. Return the new position.\n"
6439 : : "\n"
6440 : : "Return the new cursor position in number of bytes\n"
6441 : : "relative to the beginning of the file.");
6442 : :
6443 : : #define OS_LSEEK_METHODDEF \
6444 : : {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
6445 : :
6446 : : static Py_off_t
6447 : : os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
6448 : :
6449 : : static PyObject *
6450 : 0 : os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6451 : : {
6452 : 0 : PyObject *return_value = NULL;
6453 : : int fd;
6454 : : Py_off_t position;
6455 : : int how;
6456 : : Py_off_t _return_value;
6457 : :
6458 [ # # # # : 0 : if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
# # ]
6459 : 0 : goto exit;
6460 : : }
6461 : 0 : fd = _PyLong_AsInt(args[0]);
6462 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6463 : 0 : goto exit;
6464 : : }
6465 [ # # ]: 0 : if (!Py_off_t_converter(args[1], &position)) {
6466 : 0 : goto exit;
6467 : : }
6468 : 0 : how = _PyLong_AsInt(args[2]);
6469 [ # # # # ]: 0 : if (how == -1 && PyErr_Occurred()) {
6470 : 0 : goto exit;
6471 : : }
6472 : 0 : _return_value = os_lseek_impl(module, fd, position, how);
6473 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
6474 : 0 : goto exit;
6475 : : }
6476 : 0 : return_value = PyLong_FromPy_off_t(_return_value);
6477 : :
6478 : 0 : exit:
6479 : 0 : return return_value;
6480 : : }
6481 : :
6482 : : PyDoc_STRVAR(os_read__doc__,
6483 : : "read($module, fd, length, /)\n"
6484 : : "--\n"
6485 : : "\n"
6486 : : "Read from a file descriptor. Returns a bytes object.");
6487 : :
6488 : : #define OS_READ_METHODDEF \
6489 : : {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
6490 : :
6491 : : static PyObject *
6492 : : os_read_impl(PyObject *module, int fd, Py_ssize_t length);
6493 : :
6494 : : static PyObject *
6495 : 0 : os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6496 : : {
6497 : 0 : PyObject *return_value = NULL;
6498 : : int fd;
6499 : : Py_ssize_t length;
6500 : :
6501 [ # # # # : 0 : if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
# # ]
6502 : 0 : goto exit;
6503 : : }
6504 : 0 : fd = _PyLong_AsInt(args[0]);
6505 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6506 : 0 : goto exit;
6507 : : }
6508 : : {
6509 : 0 : Py_ssize_t ival = -1;
6510 : 0 : PyObject *iobj = _PyNumber_Index(args[1]);
6511 [ # # ]: 0 : if (iobj != NULL) {
6512 : 0 : ival = PyLong_AsSsize_t(iobj);
6513 : 0 : Py_DECREF(iobj);
6514 : : }
6515 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
6516 : 0 : goto exit;
6517 : : }
6518 : 0 : length = ival;
6519 : : }
6520 : 0 : return_value = os_read_impl(module, fd, length);
6521 : :
6522 : 0 : exit:
6523 : 0 : return return_value;
6524 : : }
6525 : :
6526 : : #if defined(HAVE_READV)
6527 : :
6528 : : PyDoc_STRVAR(os_readv__doc__,
6529 : : "readv($module, fd, buffers, /)\n"
6530 : : "--\n"
6531 : : "\n"
6532 : : "Read from a file descriptor fd into an iterable of buffers.\n"
6533 : : "\n"
6534 : : "The buffers should be mutable buffers accepting bytes.\n"
6535 : : "readv will transfer data into each buffer until it is full\n"
6536 : : "and then move on to the next buffer in the sequence to hold\n"
6537 : : "the rest of the data.\n"
6538 : : "\n"
6539 : : "readv returns the total number of bytes read,\n"
6540 : : "which may be less than the total capacity of all the buffers.");
6541 : :
6542 : : #define OS_READV_METHODDEF \
6543 : : {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
6544 : :
6545 : : static Py_ssize_t
6546 : : os_readv_impl(PyObject *module, int fd, PyObject *buffers);
6547 : :
6548 : : static PyObject *
6549 : 0 : os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6550 : : {
6551 : 0 : PyObject *return_value = NULL;
6552 : : int fd;
6553 : : PyObject *buffers;
6554 : : Py_ssize_t _return_value;
6555 : :
6556 [ # # # # : 0 : if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
# # ]
6557 : 0 : goto exit;
6558 : : }
6559 : 0 : fd = _PyLong_AsInt(args[0]);
6560 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6561 : 0 : goto exit;
6562 : : }
6563 : 0 : buffers = args[1];
6564 : 0 : _return_value = os_readv_impl(module, fd, buffers);
6565 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
6566 : 0 : goto exit;
6567 : : }
6568 : 0 : return_value = PyLong_FromSsize_t(_return_value);
6569 : :
6570 : 0 : exit:
6571 : 0 : return return_value;
6572 : : }
6573 : :
6574 : : #endif /* defined(HAVE_READV) */
6575 : :
6576 : : #if defined(HAVE_PREAD)
6577 : :
6578 : : PyDoc_STRVAR(os_pread__doc__,
6579 : : "pread($module, fd, length, offset, /)\n"
6580 : : "--\n"
6581 : : "\n"
6582 : : "Read a number of bytes from a file descriptor starting at a particular offset.\n"
6583 : : "\n"
6584 : : "Read length bytes from file descriptor fd, starting at offset bytes from\n"
6585 : : "the beginning of the file. The file offset remains unchanged.");
6586 : :
6587 : : #define OS_PREAD_METHODDEF \
6588 : : {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
6589 : :
6590 : : static PyObject *
6591 : : os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
6592 : :
6593 : : static PyObject *
6594 : 0 : os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6595 : : {
6596 : 0 : PyObject *return_value = NULL;
6597 : : int fd;
6598 : : Py_ssize_t length;
6599 : : Py_off_t offset;
6600 : :
6601 [ # # # # : 0 : if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
# # ]
6602 : 0 : goto exit;
6603 : : }
6604 : 0 : fd = _PyLong_AsInt(args[0]);
6605 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6606 : 0 : goto exit;
6607 : : }
6608 : : {
6609 : 0 : Py_ssize_t ival = -1;
6610 : 0 : PyObject *iobj = _PyNumber_Index(args[1]);
6611 [ # # ]: 0 : if (iobj != NULL) {
6612 : 0 : ival = PyLong_AsSsize_t(iobj);
6613 : 0 : Py_DECREF(iobj);
6614 : : }
6615 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
6616 : 0 : goto exit;
6617 : : }
6618 : 0 : length = ival;
6619 : : }
6620 [ # # ]: 0 : if (!Py_off_t_converter(args[2], &offset)) {
6621 : 0 : goto exit;
6622 : : }
6623 : 0 : return_value = os_pread_impl(module, fd, length, offset);
6624 : :
6625 : 0 : exit:
6626 : 0 : return return_value;
6627 : : }
6628 : :
6629 : : #endif /* defined(HAVE_PREAD) */
6630 : :
6631 : : #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
6632 : :
6633 : : PyDoc_STRVAR(os_preadv__doc__,
6634 : : "preadv($module, fd, buffers, offset, flags=0, /)\n"
6635 : : "--\n"
6636 : : "\n"
6637 : : "Reads from a file descriptor into a number of mutable bytes-like objects.\n"
6638 : : "\n"
6639 : : "Combines the functionality of readv() and pread(). As readv(), it will\n"
6640 : : "transfer data into each buffer until it is full and then move on to the next\n"
6641 : : "buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
6642 : : "specifies the file offset at which the input operation is to be performed. It\n"
6643 : : "will return the total number of bytes read (which can be less than the total\n"
6644 : : "capacity of all the objects).\n"
6645 : : "\n"
6646 : : "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
6647 : : "\n"
6648 : : "- RWF_HIPRI\n"
6649 : : "- RWF_NOWAIT\n"
6650 : : "\n"
6651 : : "Using non-zero flags requires Linux 4.6 or newer.");
6652 : :
6653 : : #define OS_PREADV_METHODDEF \
6654 : : {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
6655 : :
6656 : : static Py_ssize_t
6657 : : os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
6658 : : int flags);
6659 : :
6660 : : static PyObject *
6661 : 0 : os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6662 : : {
6663 : 0 : PyObject *return_value = NULL;
6664 : : int fd;
6665 : : PyObject *buffers;
6666 : : Py_off_t offset;
6667 : 0 : int flags = 0;
6668 : : Py_ssize_t _return_value;
6669 : :
6670 [ # # # # : 0 : if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
# # ]
6671 : 0 : goto exit;
6672 : : }
6673 : 0 : fd = _PyLong_AsInt(args[0]);
6674 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6675 : 0 : goto exit;
6676 : : }
6677 : 0 : buffers = args[1];
6678 [ # # ]: 0 : if (!Py_off_t_converter(args[2], &offset)) {
6679 : 0 : goto exit;
6680 : : }
6681 [ # # ]: 0 : if (nargs < 4) {
6682 : 0 : goto skip_optional;
6683 : : }
6684 : 0 : flags = _PyLong_AsInt(args[3]);
6685 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
6686 : 0 : goto exit;
6687 : : }
6688 : 0 : skip_optional:
6689 : 0 : _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
6690 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
6691 : 0 : goto exit;
6692 : : }
6693 : 0 : return_value = PyLong_FromSsize_t(_return_value);
6694 : :
6695 : 0 : exit:
6696 : 0 : return return_value;
6697 : : }
6698 : :
6699 : : #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
6700 : :
6701 : : PyDoc_STRVAR(os_write__doc__,
6702 : : "write($module, fd, data, /)\n"
6703 : : "--\n"
6704 : : "\n"
6705 : : "Write a bytes object to a file descriptor.");
6706 : :
6707 : : #define OS_WRITE_METHODDEF \
6708 : : {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
6709 : :
6710 : : static Py_ssize_t
6711 : : os_write_impl(PyObject *module, int fd, Py_buffer *data);
6712 : :
6713 : : static PyObject *
6714 : 0 : os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
6715 : : {
6716 : 0 : PyObject *return_value = NULL;
6717 : : int fd;
6718 : 0 : Py_buffer data = {NULL, NULL};
6719 : : Py_ssize_t _return_value;
6720 : :
6721 [ # # # # : 0 : if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
# # ]
6722 : 0 : goto exit;
6723 : : }
6724 : 0 : fd = _PyLong_AsInt(args[0]);
6725 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
6726 : 0 : goto exit;
6727 : : }
6728 [ # # ]: 0 : if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
6729 : 0 : goto exit;
6730 : : }
6731 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&data, 'C')) {
6732 : 0 : _PyArg_BadArgument("write", "argument 2", "contiguous buffer", args[1]);
6733 : 0 : goto exit;
6734 : : }
6735 : 0 : _return_value = os_write_impl(module, fd, &data);
6736 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
6737 : 0 : goto exit;
6738 : : }
6739 : 0 : return_value = PyLong_FromSsize_t(_return_value);
6740 : :
6741 : 0 : exit:
6742 : : /* Cleanup for data */
6743 [ # # ]: 0 : if (data.obj) {
6744 : 0 : PyBuffer_Release(&data);
6745 : : }
6746 : :
6747 : 0 : return return_value;
6748 : : }
6749 : :
6750 : : #if defined(HAVE_SENDFILE) && defined(__APPLE__)
6751 : :
6752 : : PyDoc_STRVAR(os_sendfile__doc__,
6753 : : "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
6754 : : " trailers=(), flags=0)\n"
6755 : : "--\n"
6756 : : "\n"
6757 : : "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
6758 : :
6759 : : #define OS_SENDFILE_METHODDEF \
6760 : : {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
6761 : :
6762 : : static PyObject *
6763 : : os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
6764 : : Py_off_t sbytes, PyObject *headers, PyObject *trailers,
6765 : : int flags);
6766 : :
6767 : : static PyObject *
6768 : : os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6769 : : {
6770 : : PyObject *return_value = NULL;
6771 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6772 : :
6773 : : #define NUM_KEYWORDS 7
6774 : : static struct {
6775 : : PyGC_Head _this_is_not_used;
6776 : : PyObject_VAR_HEAD
6777 : : PyObject *ob_item[NUM_KEYWORDS];
6778 : : } _kwtuple = {
6779 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6780 : : .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), },
6781 : : };
6782 : : #undef NUM_KEYWORDS
6783 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6784 : :
6785 : : #else // !Py_BUILD_CORE
6786 : : # define KWTUPLE NULL
6787 : : #endif // !Py_BUILD_CORE
6788 : :
6789 : : static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
6790 : : static _PyArg_Parser _parser = {
6791 : : .keywords = _keywords,
6792 : : .fname = "sendfile",
6793 : : .kwtuple = KWTUPLE,
6794 : : };
6795 : : #undef KWTUPLE
6796 : : PyObject *argsbuf[7];
6797 : : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
6798 : : int out_fd;
6799 : : int in_fd;
6800 : : Py_off_t offset;
6801 : : Py_off_t sbytes;
6802 : : PyObject *headers = NULL;
6803 : : PyObject *trailers = NULL;
6804 : : int flags = 0;
6805 : :
6806 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf);
6807 : : if (!args) {
6808 : : goto exit;
6809 : : }
6810 : : out_fd = _PyLong_AsInt(args[0]);
6811 : : if (out_fd == -1 && PyErr_Occurred()) {
6812 : : goto exit;
6813 : : }
6814 : : in_fd = _PyLong_AsInt(args[1]);
6815 : : if (in_fd == -1 && PyErr_Occurred()) {
6816 : : goto exit;
6817 : : }
6818 : : if (!Py_off_t_converter(args[2], &offset)) {
6819 : : goto exit;
6820 : : }
6821 : : if (!Py_off_t_converter(args[3], &sbytes)) {
6822 : : goto exit;
6823 : : }
6824 : : if (!noptargs) {
6825 : : goto skip_optional_pos;
6826 : : }
6827 : : if (args[4]) {
6828 : : headers = args[4];
6829 : : if (!--noptargs) {
6830 : : goto skip_optional_pos;
6831 : : }
6832 : : }
6833 : : if (args[5]) {
6834 : : trailers = args[5];
6835 : : if (!--noptargs) {
6836 : : goto skip_optional_pos;
6837 : : }
6838 : : }
6839 : : flags = _PyLong_AsInt(args[6]);
6840 : : if (flags == -1 && PyErr_Occurred()) {
6841 : : goto exit;
6842 : : }
6843 : : skip_optional_pos:
6844 : : return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
6845 : :
6846 : : exit:
6847 : : return return_value;
6848 : : }
6849 : :
6850 : : #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
6851 : :
6852 : : #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
6853 : :
6854 : : PyDoc_STRVAR(os_sendfile__doc__,
6855 : : "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
6856 : : " trailers=(), flags=0)\n"
6857 : : "--\n"
6858 : : "\n"
6859 : : "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
6860 : :
6861 : : #define OS_SENDFILE_METHODDEF \
6862 : : {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
6863 : :
6864 : : static PyObject *
6865 : : os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
6866 : : Py_ssize_t count, PyObject *headers, PyObject *trailers,
6867 : : int flags);
6868 : :
6869 : : static PyObject *
6870 : : os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6871 : : {
6872 : : PyObject *return_value = NULL;
6873 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6874 : :
6875 : : #define NUM_KEYWORDS 7
6876 : : static struct {
6877 : : PyGC_Head _this_is_not_used;
6878 : : PyObject_VAR_HEAD
6879 : : PyObject *ob_item[NUM_KEYWORDS];
6880 : : } _kwtuple = {
6881 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6882 : : .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), },
6883 : : };
6884 : : #undef NUM_KEYWORDS
6885 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6886 : :
6887 : : #else // !Py_BUILD_CORE
6888 : : # define KWTUPLE NULL
6889 : : #endif // !Py_BUILD_CORE
6890 : :
6891 : : static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
6892 : : static _PyArg_Parser _parser = {
6893 : : .keywords = _keywords,
6894 : : .fname = "sendfile",
6895 : : .kwtuple = KWTUPLE,
6896 : : };
6897 : : #undef KWTUPLE
6898 : : PyObject *argsbuf[7];
6899 : : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
6900 : : int out_fd;
6901 : : int in_fd;
6902 : : Py_off_t offset;
6903 : : Py_ssize_t count;
6904 : : PyObject *headers = NULL;
6905 : : PyObject *trailers = NULL;
6906 : : int flags = 0;
6907 : :
6908 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf);
6909 : : if (!args) {
6910 : : goto exit;
6911 : : }
6912 : : out_fd = _PyLong_AsInt(args[0]);
6913 : : if (out_fd == -1 && PyErr_Occurred()) {
6914 : : goto exit;
6915 : : }
6916 : : in_fd = _PyLong_AsInt(args[1]);
6917 : : if (in_fd == -1 && PyErr_Occurred()) {
6918 : : goto exit;
6919 : : }
6920 : : if (!Py_off_t_converter(args[2], &offset)) {
6921 : : goto exit;
6922 : : }
6923 : : {
6924 : : Py_ssize_t ival = -1;
6925 : : PyObject *iobj = _PyNumber_Index(args[3]);
6926 : : if (iobj != NULL) {
6927 : : ival = PyLong_AsSsize_t(iobj);
6928 : : Py_DECREF(iobj);
6929 : : }
6930 : : if (ival == -1 && PyErr_Occurred()) {
6931 : : goto exit;
6932 : : }
6933 : : count = ival;
6934 : : }
6935 : : if (!noptargs) {
6936 : : goto skip_optional_pos;
6937 : : }
6938 : : if (args[4]) {
6939 : : headers = args[4];
6940 : : if (!--noptargs) {
6941 : : goto skip_optional_pos;
6942 : : }
6943 : : }
6944 : : if (args[5]) {
6945 : : trailers = args[5];
6946 : : if (!--noptargs) {
6947 : : goto skip_optional_pos;
6948 : : }
6949 : : }
6950 : : flags = _PyLong_AsInt(args[6]);
6951 : : if (flags == -1 && PyErr_Occurred()) {
6952 : : goto exit;
6953 : : }
6954 : : skip_optional_pos:
6955 : : return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
6956 : :
6957 : : exit:
6958 : : return return_value;
6959 : : }
6960 : :
6961 : : #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
6962 : :
6963 : : #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
6964 : :
6965 : : PyDoc_STRVAR(os_sendfile__doc__,
6966 : : "sendfile($module, /, out_fd, in_fd, offset, count)\n"
6967 : : "--\n"
6968 : : "\n"
6969 : : "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
6970 : :
6971 : : #define OS_SENDFILE_METHODDEF \
6972 : : {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
6973 : :
6974 : : static PyObject *
6975 : : os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
6976 : : Py_ssize_t count);
6977 : :
6978 : : static PyObject *
6979 : 0 : os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
6980 : : {
6981 : 0 : PyObject *return_value = NULL;
6982 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6983 : :
6984 : : #define NUM_KEYWORDS 4
6985 : : static struct {
6986 : : PyGC_Head _this_is_not_used;
6987 : : PyObject_VAR_HEAD
6988 : : PyObject *ob_item[NUM_KEYWORDS];
6989 : : } _kwtuple = {
6990 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
6991 : : .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
6992 : : };
6993 : : #undef NUM_KEYWORDS
6994 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
6995 : :
6996 : : #else // !Py_BUILD_CORE
6997 : : # define KWTUPLE NULL
6998 : : #endif // !Py_BUILD_CORE
6999 : :
7000 : : static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
7001 : : static _PyArg_Parser _parser = {
7002 : : .keywords = _keywords,
7003 : : .fname = "sendfile",
7004 : : .kwtuple = KWTUPLE,
7005 : : };
7006 : : #undef KWTUPLE
7007 : : PyObject *argsbuf[4];
7008 : : int out_fd;
7009 : : int in_fd;
7010 : : PyObject *offobj;
7011 : : Py_ssize_t count;
7012 : :
7013 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf);
# # # # ]
7014 [ # # ]: 0 : if (!args) {
7015 : 0 : goto exit;
7016 : : }
7017 : 0 : out_fd = _PyLong_AsInt(args[0]);
7018 [ # # # # ]: 0 : if (out_fd == -1 && PyErr_Occurred()) {
7019 : 0 : goto exit;
7020 : : }
7021 : 0 : in_fd = _PyLong_AsInt(args[1]);
7022 [ # # # # ]: 0 : if (in_fd == -1 && PyErr_Occurred()) {
7023 : 0 : goto exit;
7024 : : }
7025 : 0 : offobj = args[2];
7026 : : {
7027 : 0 : Py_ssize_t ival = -1;
7028 : 0 : PyObject *iobj = _PyNumber_Index(args[3]);
7029 [ # # ]: 0 : if (iobj != NULL) {
7030 : 0 : ival = PyLong_AsSsize_t(iobj);
7031 : 0 : Py_DECREF(iobj);
7032 : : }
7033 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
7034 : 0 : goto exit;
7035 : : }
7036 : 0 : count = ival;
7037 : : }
7038 : 0 : return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
7039 : :
7040 : 0 : exit:
7041 : 0 : return return_value;
7042 : : }
7043 : :
7044 : : #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
7045 : :
7046 : : #if defined(__APPLE__)
7047 : :
7048 : : PyDoc_STRVAR(os__fcopyfile__doc__,
7049 : : "_fcopyfile($module, in_fd, out_fd, flags, /)\n"
7050 : : "--\n"
7051 : : "\n"
7052 : : "Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
7053 : :
7054 : : #define OS__FCOPYFILE_METHODDEF \
7055 : : {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
7056 : :
7057 : : static PyObject *
7058 : : os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
7059 : :
7060 : : static PyObject *
7061 : : os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7062 : : {
7063 : : PyObject *return_value = NULL;
7064 : : int in_fd;
7065 : : int out_fd;
7066 : : int flags;
7067 : :
7068 : : if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
7069 : : goto exit;
7070 : : }
7071 : : in_fd = _PyLong_AsInt(args[0]);
7072 : : if (in_fd == -1 && PyErr_Occurred()) {
7073 : : goto exit;
7074 : : }
7075 : : out_fd = _PyLong_AsInt(args[1]);
7076 : : if (out_fd == -1 && PyErr_Occurred()) {
7077 : : goto exit;
7078 : : }
7079 : : flags = _PyLong_AsInt(args[2]);
7080 : : if (flags == -1 && PyErr_Occurred()) {
7081 : : goto exit;
7082 : : }
7083 : : return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
7084 : :
7085 : : exit:
7086 : : return return_value;
7087 : : }
7088 : :
7089 : : #endif /* defined(__APPLE__) */
7090 : :
7091 : : PyDoc_STRVAR(os_fstat__doc__,
7092 : : "fstat($module, /, fd)\n"
7093 : : "--\n"
7094 : : "\n"
7095 : : "Perform a stat system call on the given file descriptor.\n"
7096 : : "\n"
7097 : : "Like stat(), but for an open file descriptor.\n"
7098 : : "Equivalent to os.stat(fd).");
7099 : :
7100 : : #define OS_FSTAT_METHODDEF \
7101 : : {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
7102 : :
7103 : : static PyObject *
7104 : : os_fstat_impl(PyObject *module, int fd);
7105 : :
7106 : : static PyObject *
7107 : 1 : os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7108 : : {
7109 : 1 : PyObject *return_value = NULL;
7110 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7111 : :
7112 : : #define NUM_KEYWORDS 1
7113 : : static struct {
7114 : : PyGC_Head _this_is_not_used;
7115 : : PyObject_VAR_HEAD
7116 : : PyObject *ob_item[NUM_KEYWORDS];
7117 : : } _kwtuple = {
7118 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7119 : : .ob_item = { &_Py_ID(fd), },
7120 : : };
7121 : : #undef NUM_KEYWORDS
7122 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7123 : :
7124 : : #else // !Py_BUILD_CORE
7125 : : # define KWTUPLE NULL
7126 : : #endif // !Py_BUILD_CORE
7127 : :
7128 : : static const char * const _keywords[] = {"fd", NULL};
7129 : : static _PyArg_Parser _parser = {
7130 : : .keywords = _keywords,
7131 : : .fname = "fstat",
7132 : : .kwtuple = KWTUPLE,
7133 : : };
7134 : : #undef KWTUPLE
7135 : : PyObject *argsbuf[1];
7136 : : int fd;
7137 : :
7138 [ + - + - : 1 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
7139 [ - + ]: 1 : if (!args) {
7140 : 0 : goto exit;
7141 : : }
7142 : 1 : fd = _PyLong_AsInt(args[0]);
7143 [ - + - - ]: 1 : if (fd == -1 && PyErr_Occurred()) {
7144 : 0 : goto exit;
7145 : : }
7146 : 1 : return_value = os_fstat_impl(module, fd);
7147 : :
7148 : 1 : exit:
7149 : 1 : return return_value;
7150 : : }
7151 : :
7152 : : PyDoc_STRVAR(os_isatty__doc__,
7153 : : "isatty($module, fd, /)\n"
7154 : : "--\n"
7155 : : "\n"
7156 : : "Return True if the fd is connected to a terminal.\n"
7157 : : "\n"
7158 : : "Return True if the file descriptor is an open file descriptor\n"
7159 : : "connected to the slave end of a terminal.");
7160 : :
7161 : : #define OS_ISATTY_METHODDEF \
7162 : : {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
7163 : :
7164 : : static int
7165 : : os_isatty_impl(PyObject *module, int fd);
7166 : :
7167 : : static PyObject *
7168 : 0 : os_isatty(PyObject *module, PyObject *arg)
7169 : : {
7170 : 0 : PyObject *return_value = NULL;
7171 : : int fd;
7172 : : int _return_value;
7173 : :
7174 : 0 : fd = _PyLong_AsInt(arg);
7175 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
7176 : 0 : goto exit;
7177 : : }
7178 : 0 : _return_value = os_isatty_impl(module, fd);
7179 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
7180 : 0 : goto exit;
7181 : : }
7182 : 0 : return_value = PyBool_FromLong((long)_return_value);
7183 : :
7184 : 0 : exit:
7185 : 0 : return return_value;
7186 : : }
7187 : :
7188 : : #if defined(HAVE_PIPE)
7189 : :
7190 : : PyDoc_STRVAR(os_pipe__doc__,
7191 : : "pipe($module, /)\n"
7192 : : "--\n"
7193 : : "\n"
7194 : : "Create a pipe.\n"
7195 : : "\n"
7196 : : "Returns a tuple of two file descriptors:\n"
7197 : : " (read_fd, write_fd)");
7198 : :
7199 : : #define OS_PIPE_METHODDEF \
7200 : : {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
7201 : :
7202 : : static PyObject *
7203 : : os_pipe_impl(PyObject *module);
7204 : :
7205 : : static PyObject *
7206 : 0 : os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
7207 : : {
7208 : 0 : return os_pipe_impl(module);
7209 : : }
7210 : :
7211 : : #endif /* defined(HAVE_PIPE) */
7212 : :
7213 : : #if defined(HAVE_PIPE2)
7214 : :
7215 : : PyDoc_STRVAR(os_pipe2__doc__,
7216 : : "pipe2($module, flags, /)\n"
7217 : : "--\n"
7218 : : "\n"
7219 : : "Create a pipe with flags set atomically.\n"
7220 : : "\n"
7221 : : "Returns a tuple of two file descriptors:\n"
7222 : : " (read_fd, write_fd)\n"
7223 : : "\n"
7224 : : "flags can be constructed by ORing together one or more of these values:\n"
7225 : : "O_NONBLOCK, O_CLOEXEC.");
7226 : :
7227 : : #define OS_PIPE2_METHODDEF \
7228 : : {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
7229 : :
7230 : : static PyObject *
7231 : : os_pipe2_impl(PyObject *module, int flags);
7232 : :
7233 : : static PyObject *
7234 : 0 : os_pipe2(PyObject *module, PyObject *arg)
7235 : : {
7236 : 0 : PyObject *return_value = NULL;
7237 : : int flags;
7238 : :
7239 : 0 : flags = _PyLong_AsInt(arg);
7240 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
7241 : 0 : goto exit;
7242 : : }
7243 : 0 : return_value = os_pipe2_impl(module, flags);
7244 : :
7245 : 0 : exit:
7246 : 0 : return return_value;
7247 : : }
7248 : :
7249 : : #endif /* defined(HAVE_PIPE2) */
7250 : :
7251 : : #if defined(HAVE_WRITEV)
7252 : :
7253 : : PyDoc_STRVAR(os_writev__doc__,
7254 : : "writev($module, fd, buffers, /)\n"
7255 : : "--\n"
7256 : : "\n"
7257 : : "Iterate over buffers, and write the contents of each to a file descriptor.\n"
7258 : : "\n"
7259 : : "Returns the total number of bytes written.\n"
7260 : : "buffers must be a sequence of bytes-like objects.");
7261 : :
7262 : : #define OS_WRITEV_METHODDEF \
7263 : : {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
7264 : :
7265 : : static Py_ssize_t
7266 : : os_writev_impl(PyObject *module, int fd, PyObject *buffers);
7267 : :
7268 : : static PyObject *
7269 : 0 : os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7270 : : {
7271 : 0 : PyObject *return_value = NULL;
7272 : : int fd;
7273 : : PyObject *buffers;
7274 : : Py_ssize_t _return_value;
7275 : :
7276 [ # # # # : 0 : if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
# # ]
7277 : 0 : goto exit;
7278 : : }
7279 : 0 : fd = _PyLong_AsInt(args[0]);
7280 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
7281 : 0 : goto exit;
7282 : : }
7283 : 0 : buffers = args[1];
7284 : 0 : _return_value = os_writev_impl(module, fd, buffers);
7285 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
7286 : 0 : goto exit;
7287 : : }
7288 : 0 : return_value = PyLong_FromSsize_t(_return_value);
7289 : :
7290 : 0 : exit:
7291 : 0 : return return_value;
7292 : : }
7293 : :
7294 : : #endif /* defined(HAVE_WRITEV) */
7295 : :
7296 : : #if defined(HAVE_PWRITE)
7297 : :
7298 : : PyDoc_STRVAR(os_pwrite__doc__,
7299 : : "pwrite($module, fd, buffer, offset, /)\n"
7300 : : "--\n"
7301 : : "\n"
7302 : : "Write bytes to a file descriptor starting at a particular offset.\n"
7303 : : "\n"
7304 : : "Write buffer to fd, starting at offset bytes from the beginning of\n"
7305 : : "the file. Returns the number of bytes writte. Does not change the\n"
7306 : : "current file offset.");
7307 : :
7308 : : #define OS_PWRITE_METHODDEF \
7309 : : {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
7310 : :
7311 : : static Py_ssize_t
7312 : : os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
7313 : :
7314 : : static PyObject *
7315 : 0 : os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7316 : : {
7317 : 0 : PyObject *return_value = NULL;
7318 : : int fd;
7319 : 0 : Py_buffer buffer = {NULL, NULL};
7320 : : Py_off_t offset;
7321 : : Py_ssize_t _return_value;
7322 : :
7323 [ # # # # : 0 : if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
# # ]
7324 : 0 : goto exit;
7325 : : }
7326 : 0 : fd = _PyLong_AsInt(args[0]);
7327 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
7328 : 0 : goto exit;
7329 : : }
7330 [ # # ]: 0 : if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
7331 : 0 : goto exit;
7332 : : }
7333 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&buffer, 'C')) {
7334 : 0 : _PyArg_BadArgument("pwrite", "argument 2", "contiguous buffer", args[1]);
7335 : 0 : goto exit;
7336 : : }
7337 [ # # ]: 0 : if (!Py_off_t_converter(args[2], &offset)) {
7338 : 0 : goto exit;
7339 : : }
7340 : 0 : _return_value = os_pwrite_impl(module, fd, &buffer, offset);
7341 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
7342 : 0 : goto exit;
7343 : : }
7344 : 0 : return_value = PyLong_FromSsize_t(_return_value);
7345 : :
7346 : 0 : exit:
7347 : : /* Cleanup for buffer */
7348 [ # # ]: 0 : if (buffer.obj) {
7349 : 0 : PyBuffer_Release(&buffer);
7350 : : }
7351 : :
7352 : 0 : return return_value;
7353 : : }
7354 : :
7355 : : #endif /* defined(HAVE_PWRITE) */
7356 : :
7357 : : #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
7358 : :
7359 : : PyDoc_STRVAR(os_pwritev__doc__,
7360 : : "pwritev($module, fd, buffers, offset, flags=0, /)\n"
7361 : : "--\n"
7362 : : "\n"
7363 : : "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
7364 : : "\n"
7365 : : "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
7366 : : "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
7367 : : "buffer is written before proceeding to second, and so on. The operating system may\n"
7368 : : "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
7369 : : "This function writes the contents of each object to the file descriptor and returns\n"
7370 : : "the total number of bytes written.\n"
7371 : : "\n"
7372 : : "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
7373 : : "\n"
7374 : : "- RWF_DSYNC\n"
7375 : : "- RWF_SYNC\n"
7376 : : "- RWF_APPEND\n"
7377 : : "\n"
7378 : : "Using non-zero flags requires Linux 4.7 or newer.");
7379 : :
7380 : : #define OS_PWRITEV_METHODDEF \
7381 : : {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
7382 : :
7383 : : static Py_ssize_t
7384 : : os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
7385 : : int flags);
7386 : :
7387 : : static PyObject *
7388 : 0 : os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7389 : : {
7390 : 0 : PyObject *return_value = NULL;
7391 : : int fd;
7392 : : PyObject *buffers;
7393 : : Py_off_t offset;
7394 : 0 : int flags = 0;
7395 : : Py_ssize_t _return_value;
7396 : :
7397 [ # # # # : 0 : if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
# # ]
7398 : 0 : goto exit;
7399 : : }
7400 : 0 : fd = _PyLong_AsInt(args[0]);
7401 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
7402 : 0 : goto exit;
7403 : : }
7404 : 0 : buffers = args[1];
7405 [ # # ]: 0 : if (!Py_off_t_converter(args[2], &offset)) {
7406 : 0 : goto exit;
7407 : : }
7408 [ # # ]: 0 : if (nargs < 4) {
7409 : 0 : goto skip_optional;
7410 : : }
7411 : 0 : flags = _PyLong_AsInt(args[3]);
7412 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
7413 : 0 : goto exit;
7414 : : }
7415 : 0 : skip_optional:
7416 : 0 : _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
7417 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
7418 : 0 : goto exit;
7419 : : }
7420 : 0 : return_value = PyLong_FromSsize_t(_return_value);
7421 : :
7422 : 0 : exit:
7423 : 0 : return return_value;
7424 : : }
7425 : :
7426 : : #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
7427 : :
7428 : : #if defined(HAVE_COPY_FILE_RANGE)
7429 : :
7430 : : PyDoc_STRVAR(os_copy_file_range__doc__,
7431 : : "copy_file_range($module, /, src, dst, count, offset_src=None,\n"
7432 : : " offset_dst=None)\n"
7433 : : "--\n"
7434 : : "\n"
7435 : : "Copy count bytes from one file descriptor to another.\n"
7436 : : "\n"
7437 : : " src\n"
7438 : : " Source file descriptor.\n"
7439 : : " dst\n"
7440 : : " Destination file descriptor.\n"
7441 : : " count\n"
7442 : : " Number of bytes to copy.\n"
7443 : : " offset_src\n"
7444 : : " Starting offset in src.\n"
7445 : : " offset_dst\n"
7446 : : " Starting offset in dst.\n"
7447 : : "\n"
7448 : : "If offset_src is None, then src is read from the current position;\n"
7449 : : "respectively for offset_dst.");
7450 : :
7451 : : #define OS_COPY_FILE_RANGE_METHODDEF \
7452 : : {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
7453 : :
7454 : : static PyObject *
7455 : : os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
7456 : : PyObject *offset_src, PyObject *offset_dst);
7457 : :
7458 : : static PyObject *
7459 : 0 : os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7460 : : {
7461 : 0 : PyObject *return_value = NULL;
7462 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7463 : :
7464 : : #define NUM_KEYWORDS 5
7465 : : static struct {
7466 : : PyGC_Head _this_is_not_used;
7467 : : PyObject_VAR_HEAD
7468 : : PyObject *ob_item[NUM_KEYWORDS];
7469 : : } _kwtuple = {
7470 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7471 : : .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
7472 : : };
7473 : : #undef NUM_KEYWORDS
7474 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7475 : :
7476 : : #else // !Py_BUILD_CORE
7477 : : # define KWTUPLE NULL
7478 : : #endif // !Py_BUILD_CORE
7479 : :
7480 : : static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
7481 : : static _PyArg_Parser _parser = {
7482 : : .keywords = _keywords,
7483 : : .fname = "copy_file_range",
7484 : : .kwtuple = KWTUPLE,
7485 : : };
7486 : : #undef KWTUPLE
7487 : : PyObject *argsbuf[5];
7488 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
7489 : : int src;
7490 : : int dst;
7491 : : Py_ssize_t count;
7492 : 0 : PyObject *offset_src = Py_None;
7493 : 0 : PyObject *offset_dst = Py_None;
7494 : :
7495 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 5, 0, argsbuf);
# # # # ]
7496 [ # # ]: 0 : if (!args) {
7497 : 0 : goto exit;
7498 : : }
7499 : 0 : src = _PyLong_AsInt(args[0]);
7500 [ # # # # ]: 0 : if (src == -1 && PyErr_Occurred()) {
7501 : 0 : goto exit;
7502 : : }
7503 : 0 : dst = _PyLong_AsInt(args[1]);
7504 [ # # # # ]: 0 : if (dst == -1 && PyErr_Occurred()) {
7505 : 0 : goto exit;
7506 : : }
7507 : : {
7508 : 0 : Py_ssize_t ival = -1;
7509 : 0 : PyObject *iobj = _PyNumber_Index(args[2]);
7510 [ # # ]: 0 : if (iobj != NULL) {
7511 : 0 : ival = PyLong_AsSsize_t(iobj);
7512 : 0 : Py_DECREF(iobj);
7513 : : }
7514 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
7515 : 0 : goto exit;
7516 : : }
7517 : 0 : count = ival;
7518 : : }
7519 [ # # ]: 0 : if (!noptargs) {
7520 : 0 : goto skip_optional_pos;
7521 : : }
7522 [ # # ]: 0 : if (args[3]) {
7523 : 0 : offset_src = args[3];
7524 [ # # ]: 0 : if (!--noptargs) {
7525 : 0 : goto skip_optional_pos;
7526 : : }
7527 : : }
7528 : 0 : offset_dst = args[4];
7529 : 0 : skip_optional_pos:
7530 : 0 : return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
7531 : :
7532 : 0 : exit:
7533 : 0 : return return_value;
7534 : : }
7535 : :
7536 : : #endif /* defined(HAVE_COPY_FILE_RANGE) */
7537 : :
7538 : : #if ((defined(HAVE_SPLICE) && !defined(_AIX)))
7539 : :
7540 : : PyDoc_STRVAR(os_splice__doc__,
7541 : : "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
7542 : : " flags=0)\n"
7543 : : "--\n"
7544 : : "\n"
7545 : : "Transfer count bytes from one pipe to a descriptor or vice versa.\n"
7546 : : "\n"
7547 : : " src\n"
7548 : : " Source file descriptor.\n"
7549 : : " dst\n"
7550 : : " Destination file descriptor.\n"
7551 : : " count\n"
7552 : : " Number of bytes to copy.\n"
7553 : : " offset_src\n"
7554 : : " Starting offset in src.\n"
7555 : : " offset_dst\n"
7556 : : " Starting offset in dst.\n"
7557 : : " flags\n"
7558 : : " Flags to modify the semantics of the call.\n"
7559 : : "\n"
7560 : : "If offset_src is None, then src is read from the current position;\n"
7561 : : "respectively for offset_dst. The offset associated to the file\n"
7562 : : "descriptor that refers to a pipe must be None.");
7563 : :
7564 : : #define OS_SPLICE_METHODDEF \
7565 : : {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
7566 : :
7567 : : static PyObject *
7568 : : os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
7569 : : PyObject *offset_src, PyObject *offset_dst,
7570 : : unsigned int flags);
7571 : :
7572 : : static PyObject *
7573 : 0 : os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7574 : : {
7575 : 0 : PyObject *return_value = NULL;
7576 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7577 : :
7578 : : #define NUM_KEYWORDS 6
7579 : : static struct {
7580 : : PyGC_Head _this_is_not_used;
7581 : : PyObject_VAR_HEAD
7582 : : PyObject *ob_item[NUM_KEYWORDS];
7583 : : } _kwtuple = {
7584 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7585 : : .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
7586 : : };
7587 : : #undef NUM_KEYWORDS
7588 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7589 : :
7590 : : #else // !Py_BUILD_CORE
7591 : : # define KWTUPLE NULL
7592 : : #endif // !Py_BUILD_CORE
7593 : :
7594 : : static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
7595 : : static _PyArg_Parser _parser = {
7596 : : .keywords = _keywords,
7597 : : .fname = "splice",
7598 : : .kwtuple = KWTUPLE,
7599 : : };
7600 : : #undef KWTUPLE
7601 : : PyObject *argsbuf[6];
7602 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
7603 : : int src;
7604 : : int dst;
7605 : : Py_ssize_t count;
7606 : 0 : PyObject *offset_src = Py_None;
7607 : 0 : PyObject *offset_dst = Py_None;
7608 : 0 : unsigned int flags = 0;
7609 : :
7610 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf);
# # # # ]
7611 [ # # ]: 0 : if (!args) {
7612 : 0 : goto exit;
7613 : : }
7614 : 0 : src = _PyLong_AsInt(args[0]);
7615 [ # # # # ]: 0 : if (src == -1 && PyErr_Occurred()) {
7616 : 0 : goto exit;
7617 : : }
7618 : 0 : dst = _PyLong_AsInt(args[1]);
7619 [ # # # # ]: 0 : if (dst == -1 && PyErr_Occurred()) {
7620 : 0 : goto exit;
7621 : : }
7622 : : {
7623 : 0 : Py_ssize_t ival = -1;
7624 : 0 : PyObject *iobj = _PyNumber_Index(args[2]);
7625 [ # # ]: 0 : if (iobj != NULL) {
7626 : 0 : ival = PyLong_AsSsize_t(iobj);
7627 : 0 : Py_DECREF(iobj);
7628 : : }
7629 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
7630 : 0 : goto exit;
7631 : : }
7632 : 0 : count = ival;
7633 : : }
7634 [ # # ]: 0 : if (!noptargs) {
7635 : 0 : goto skip_optional_pos;
7636 : : }
7637 [ # # ]: 0 : if (args[3]) {
7638 : 0 : offset_src = args[3];
7639 [ # # ]: 0 : if (!--noptargs) {
7640 : 0 : goto skip_optional_pos;
7641 : : }
7642 : : }
7643 [ # # ]: 0 : if (args[4]) {
7644 : 0 : offset_dst = args[4];
7645 [ # # ]: 0 : if (!--noptargs) {
7646 : 0 : goto skip_optional_pos;
7647 : : }
7648 : : }
7649 [ # # ]: 0 : if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
7650 : 0 : goto exit;
7651 : : }
7652 : 0 : skip_optional_pos:
7653 : 0 : return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
7654 : :
7655 : 0 : exit:
7656 : 0 : return return_value;
7657 : : }
7658 : :
7659 : : #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
7660 : :
7661 : : #if defined(HAVE_MKFIFO)
7662 : :
7663 : : PyDoc_STRVAR(os_mkfifo__doc__,
7664 : : "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
7665 : : "--\n"
7666 : : "\n"
7667 : : "Create a \"fifo\" (a POSIX named pipe).\n"
7668 : : "\n"
7669 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
7670 : : " and path should be relative; path will then be relative to that directory.\n"
7671 : : "dir_fd may not be implemented on your platform.\n"
7672 : : " If it is unavailable, using it will raise a NotImplementedError.");
7673 : :
7674 : : #define OS_MKFIFO_METHODDEF \
7675 : : {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
7676 : :
7677 : : static PyObject *
7678 : : os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
7679 : :
7680 : : static PyObject *
7681 : 0 : os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7682 : : {
7683 : 0 : PyObject *return_value = NULL;
7684 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7685 : :
7686 : : #define NUM_KEYWORDS 3
7687 : : static struct {
7688 : : PyGC_Head _this_is_not_used;
7689 : : PyObject_VAR_HEAD
7690 : : PyObject *ob_item[NUM_KEYWORDS];
7691 : : } _kwtuple = {
7692 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7693 : : .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
7694 : : };
7695 : : #undef NUM_KEYWORDS
7696 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7697 : :
7698 : : #else // !Py_BUILD_CORE
7699 : : # define KWTUPLE NULL
7700 : : #endif // !Py_BUILD_CORE
7701 : :
7702 : : static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
7703 : : static _PyArg_Parser _parser = {
7704 : : .keywords = _keywords,
7705 : : .fname = "mkfifo",
7706 : : .kwtuple = KWTUPLE,
7707 : : };
7708 : : #undef KWTUPLE
7709 : : PyObject *argsbuf[3];
7710 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
7711 : 0 : path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
7712 : 0 : int mode = 438;
7713 : 0 : int dir_fd = DEFAULT_DIR_FD;
7714 : :
7715 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
7716 [ # # ]: 0 : if (!args) {
7717 : 0 : goto exit;
7718 : : }
7719 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
7720 : 0 : goto exit;
7721 : : }
7722 [ # # ]: 0 : if (!noptargs) {
7723 : 0 : goto skip_optional_pos;
7724 : : }
7725 [ # # ]: 0 : if (args[1]) {
7726 : 0 : mode = _PyLong_AsInt(args[1]);
7727 [ # # # # ]: 0 : if (mode == -1 && PyErr_Occurred()) {
7728 : 0 : goto exit;
7729 : : }
7730 [ # # ]: 0 : if (!--noptargs) {
7731 : 0 : goto skip_optional_pos;
7732 : : }
7733 : : }
7734 : 0 : skip_optional_pos:
7735 [ # # ]: 0 : if (!noptargs) {
7736 : 0 : goto skip_optional_kwonly;
7737 : : }
7738 [ # # ]: 0 : if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
7739 : 0 : goto exit;
7740 : : }
7741 : 0 : skip_optional_kwonly:
7742 : 0 : return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
7743 : :
7744 : 0 : exit:
7745 : : /* Cleanup for path */
7746 : 0 : path_cleanup(&path);
7747 : :
7748 : 0 : return return_value;
7749 : : }
7750 : :
7751 : : #endif /* defined(HAVE_MKFIFO) */
7752 : :
7753 : : #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
7754 : :
7755 : : PyDoc_STRVAR(os_mknod__doc__,
7756 : : "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
7757 : : "--\n"
7758 : : "\n"
7759 : : "Create a node in the file system.\n"
7760 : : "\n"
7761 : : "Create a node in the file system (file, device special file or named pipe)\n"
7762 : : "at path. mode specifies both the permissions to use and the\n"
7763 : : "type of node to be created, being combined (bitwise OR) with one of\n"
7764 : : "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
7765 : : "device defines the newly created device special file (probably using\n"
7766 : : "os.makedev()). Otherwise device is ignored.\n"
7767 : : "\n"
7768 : : "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
7769 : : " and path should be relative; path will then be relative to that directory.\n"
7770 : : "dir_fd may not be implemented on your platform.\n"
7771 : : " If it is unavailable, using it will raise a NotImplementedError.");
7772 : :
7773 : : #define OS_MKNOD_METHODDEF \
7774 : : {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
7775 : :
7776 : : static PyObject *
7777 : : os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
7778 : : int dir_fd);
7779 : :
7780 : : static PyObject *
7781 : 0 : os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
7782 : : {
7783 : 0 : PyObject *return_value = NULL;
7784 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
7785 : :
7786 : : #define NUM_KEYWORDS 4
7787 : : static struct {
7788 : : PyGC_Head _this_is_not_used;
7789 : : PyObject_VAR_HEAD
7790 : : PyObject *ob_item[NUM_KEYWORDS];
7791 : : } _kwtuple = {
7792 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
7793 : : .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
7794 : : };
7795 : : #undef NUM_KEYWORDS
7796 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
7797 : :
7798 : : #else // !Py_BUILD_CORE
7799 : : # define KWTUPLE NULL
7800 : : #endif // !Py_BUILD_CORE
7801 : :
7802 : : static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
7803 : : static _PyArg_Parser _parser = {
7804 : : .keywords = _keywords,
7805 : : .fname = "mknod",
7806 : : .kwtuple = KWTUPLE,
7807 : : };
7808 : : #undef KWTUPLE
7809 : : PyObject *argsbuf[4];
7810 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
7811 : 0 : path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
7812 : 0 : int mode = 384;
7813 : 0 : dev_t device = 0;
7814 : 0 : int dir_fd = DEFAULT_DIR_FD;
7815 : :
7816 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
# # # # ]
7817 [ # # ]: 0 : if (!args) {
7818 : 0 : goto exit;
7819 : : }
7820 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
7821 : 0 : goto exit;
7822 : : }
7823 [ # # ]: 0 : if (!noptargs) {
7824 : 0 : goto skip_optional_pos;
7825 : : }
7826 [ # # ]: 0 : if (args[1]) {
7827 : 0 : mode = _PyLong_AsInt(args[1]);
7828 [ # # # # ]: 0 : if (mode == -1 && PyErr_Occurred()) {
7829 : 0 : goto exit;
7830 : : }
7831 [ # # ]: 0 : if (!--noptargs) {
7832 : 0 : goto skip_optional_pos;
7833 : : }
7834 : : }
7835 [ # # ]: 0 : if (args[2]) {
7836 [ # # ]: 0 : if (!_Py_Dev_Converter(args[2], &device)) {
7837 : 0 : goto exit;
7838 : : }
7839 [ # # ]: 0 : if (!--noptargs) {
7840 : 0 : goto skip_optional_pos;
7841 : : }
7842 : : }
7843 : 0 : skip_optional_pos:
7844 [ # # ]: 0 : if (!noptargs) {
7845 : 0 : goto skip_optional_kwonly;
7846 : : }
7847 [ # # ]: 0 : if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
7848 : 0 : goto exit;
7849 : : }
7850 : 0 : skip_optional_kwonly:
7851 : 0 : return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
7852 : :
7853 : 0 : exit:
7854 : : /* Cleanup for path */
7855 : 0 : path_cleanup(&path);
7856 : :
7857 : 0 : return return_value;
7858 : : }
7859 : :
7860 : : #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
7861 : :
7862 : : #if defined(HAVE_DEVICE_MACROS)
7863 : :
7864 : : PyDoc_STRVAR(os_major__doc__,
7865 : : "major($module, device, /)\n"
7866 : : "--\n"
7867 : : "\n"
7868 : : "Extracts a device major number from a raw device number.");
7869 : :
7870 : : #define OS_MAJOR_METHODDEF \
7871 : : {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
7872 : :
7873 : : static unsigned int
7874 : : os_major_impl(PyObject *module, dev_t device);
7875 : :
7876 : : static PyObject *
7877 : 0 : os_major(PyObject *module, PyObject *arg)
7878 : : {
7879 : 0 : PyObject *return_value = NULL;
7880 : : dev_t device;
7881 : : unsigned int _return_value;
7882 : :
7883 [ # # ]: 0 : if (!_Py_Dev_Converter(arg, &device)) {
7884 : 0 : goto exit;
7885 : : }
7886 : 0 : _return_value = os_major_impl(module, device);
7887 [ # # # # ]: 0 : if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
7888 : 0 : goto exit;
7889 : : }
7890 : 0 : return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
7891 : :
7892 : 0 : exit:
7893 : 0 : return return_value;
7894 : : }
7895 : :
7896 : : #endif /* defined(HAVE_DEVICE_MACROS) */
7897 : :
7898 : : #if defined(HAVE_DEVICE_MACROS)
7899 : :
7900 : : PyDoc_STRVAR(os_minor__doc__,
7901 : : "minor($module, device, /)\n"
7902 : : "--\n"
7903 : : "\n"
7904 : : "Extracts a device minor number from a raw device number.");
7905 : :
7906 : : #define OS_MINOR_METHODDEF \
7907 : : {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
7908 : :
7909 : : static unsigned int
7910 : : os_minor_impl(PyObject *module, dev_t device);
7911 : :
7912 : : static PyObject *
7913 : 0 : os_minor(PyObject *module, PyObject *arg)
7914 : : {
7915 : 0 : PyObject *return_value = NULL;
7916 : : dev_t device;
7917 : : unsigned int _return_value;
7918 : :
7919 [ # # ]: 0 : if (!_Py_Dev_Converter(arg, &device)) {
7920 : 0 : goto exit;
7921 : : }
7922 : 0 : _return_value = os_minor_impl(module, device);
7923 [ # # # # ]: 0 : if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) {
7924 : 0 : goto exit;
7925 : : }
7926 : 0 : return_value = PyLong_FromUnsignedLong((unsigned long)_return_value);
7927 : :
7928 : 0 : exit:
7929 : 0 : return return_value;
7930 : : }
7931 : :
7932 : : #endif /* defined(HAVE_DEVICE_MACROS) */
7933 : :
7934 : : #if defined(HAVE_DEVICE_MACROS)
7935 : :
7936 : : PyDoc_STRVAR(os_makedev__doc__,
7937 : : "makedev($module, major, minor, /)\n"
7938 : : "--\n"
7939 : : "\n"
7940 : : "Composes a raw device number from the major and minor device numbers.");
7941 : :
7942 : : #define OS_MAKEDEV_METHODDEF \
7943 : : {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
7944 : :
7945 : : static dev_t
7946 : : os_makedev_impl(PyObject *module, int major, int minor);
7947 : :
7948 : : static PyObject *
7949 : 0 : os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7950 : : {
7951 : 0 : PyObject *return_value = NULL;
7952 : : int major;
7953 : : int minor;
7954 : : dev_t _return_value;
7955 : :
7956 [ # # # # : 0 : if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
# # ]
7957 : 0 : goto exit;
7958 : : }
7959 : 0 : major = _PyLong_AsInt(args[0]);
7960 [ # # # # ]: 0 : if (major == -1 && PyErr_Occurred()) {
7961 : 0 : goto exit;
7962 : : }
7963 : 0 : minor = _PyLong_AsInt(args[1]);
7964 [ # # # # ]: 0 : if (minor == -1 && PyErr_Occurred()) {
7965 : 0 : goto exit;
7966 : : }
7967 : 0 : _return_value = os_makedev_impl(module, major, minor);
7968 [ # # # # ]: 0 : if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
7969 : 0 : goto exit;
7970 : : }
7971 : 0 : return_value = _PyLong_FromDev(_return_value);
7972 : :
7973 : 0 : exit:
7974 : 0 : return return_value;
7975 : : }
7976 : :
7977 : : #endif /* defined(HAVE_DEVICE_MACROS) */
7978 : :
7979 : : #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
7980 : :
7981 : : PyDoc_STRVAR(os_ftruncate__doc__,
7982 : : "ftruncate($module, fd, length, /)\n"
7983 : : "--\n"
7984 : : "\n"
7985 : : "Truncate a file, specified by file descriptor, to a specific length.");
7986 : :
7987 : : #define OS_FTRUNCATE_METHODDEF \
7988 : : {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
7989 : :
7990 : : static PyObject *
7991 : : os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
7992 : :
7993 : : static PyObject *
7994 : 0 : os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
7995 : : {
7996 : 0 : PyObject *return_value = NULL;
7997 : : int fd;
7998 : : Py_off_t length;
7999 : :
8000 [ # # # # : 0 : if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
# # ]
8001 : 0 : goto exit;
8002 : : }
8003 : 0 : fd = _PyLong_AsInt(args[0]);
8004 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
8005 : 0 : goto exit;
8006 : : }
8007 [ # # ]: 0 : if (!Py_off_t_converter(args[1], &length)) {
8008 : 0 : goto exit;
8009 : : }
8010 : 0 : return_value = os_ftruncate_impl(module, fd, length);
8011 : :
8012 : 0 : exit:
8013 : 0 : return return_value;
8014 : : }
8015 : :
8016 : : #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
8017 : :
8018 : : #if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
8019 : :
8020 : : PyDoc_STRVAR(os_truncate__doc__,
8021 : : "truncate($module, /, path, length)\n"
8022 : : "--\n"
8023 : : "\n"
8024 : : "Truncate a file, specified by path, to a specific length.\n"
8025 : : "\n"
8026 : : "On some platforms, path may also be specified as an open file descriptor.\n"
8027 : : " If this functionality is unavailable, using it raises an exception.");
8028 : :
8029 : : #define OS_TRUNCATE_METHODDEF \
8030 : : {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
8031 : :
8032 : : static PyObject *
8033 : : os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
8034 : :
8035 : : static PyObject *
8036 : 0 : os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8037 : : {
8038 : 0 : PyObject *return_value = NULL;
8039 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8040 : :
8041 : : #define NUM_KEYWORDS 2
8042 : : static struct {
8043 : : PyGC_Head _this_is_not_used;
8044 : : PyObject_VAR_HEAD
8045 : : PyObject *ob_item[NUM_KEYWORDS];
8046 : : } _kwtuple = {
8047 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8048 : : .ob_item = { &_Py_ID(path), &_Py_ID(length), },
8049 : : };
8050 : : #undef NUM_KEYWORDS
8051 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8052 : :
8053 : : #else // !Py_BUILD_CORE
8054 : : # define KWTUPLE NULL
8055 : : #endif // !Py_BUILD_CORE
8056 : :
8057 : : static const char * const _keywords[] = {"path", "length", NULL};
8058 : : static _PyArg_Parser _parser = {
8059 : : .keywords = _keywords,
8060 : : .fname = "truncate",
8061 : : .kwtuple = KWTUPLE,
8062 : : };
8063 : : #undef KWTUPLE
8064 : : PyObject *argsbuf[2];
8065 : 0 : path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
8066 : : Py_off_t length;
8067 : :
8068 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
8069 [ # # ]: 0 : if (!args) {
8070 : 0 : goto exit;
8071 : : }
8072 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
8073 : 0 : goto exit;
8074 : : }
8075 [ # # ]: 0 : if (!Py_off_t_converter(args[1], &length)) {
8076 : 0 : goto exit;
8077 : : }
8078 : 0 : return_value = os_truncate_impl(module, &path, length);
8079 : :
8080 : 0 : exit:
8081 : : /* Cleanup for path */
8082 : 0 : path_cleanup(&path);
8083 : :
8084 : 0 : return return_value;
8085 : : }
8086 : :
8087 : : #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
8088 : :
8089 : : #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG))
8090 : :
8091 : : PyDoc_STRVAR(os_posix_fallocate__doc__,
8092 : : "posix_fallocate($module, fd, offset, length, /)\n"
8093 : : "--\n"
8094 : : "\n"
8095 : : "Ensure a file has allocated at least a particular number of bytes on disk.\n"
8096 : : "\n"
8097 : : "Ensure that the file specified by fd encompasses a range of bytes\n"
8098 : : "starting at offset bytes from the beginning and continuing for length bytes.");
8099 : :
8100 : : #define OS_POSIX_FALLOCATE_METHODDEF \
8101 : : {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
8102 : :
8103 : : static PyObject *
8104 : : os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
8105 : : Py_off_t length);
8106 : :
8107 : : static PyObject *
8108 : 0 : os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8109 : : {
8110 : 0 : PyObject *return_value = NULL;
8111 : : int fd;
8112 : : Py_off_t offset;
8113 : : Py_off_t length;
8114 : :
8115 [ # # # # : 0 : if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
# # ]
8116 : 0 : goto exit;
8117 : : }
8118 : 0 : fd = _PyLong_AsInt(args[0]);
8119 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
8120 : 0 : goto exit;
8121 : : }
8122 [ # # ]: 0 : if (!Py_off_t_converter(args[1], &offset)) {
8123 : 0 : goto exit;
8124 : : }
8125 [ # # ]: 0 : if (!Py_off_t_converter(args[2], &length)) {
8126 : 0 : goto exit;
8127 : : }
8128 : 0 : return_value = os_posix_fallocate_impl(module, fd, offset, length);
8129 : :
8130 : 0 : exit:
8131 : 0 : return return_value;
8132 : : }
8133 : :
8134 : : #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)) */
8135 : :
8136 : : #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
8137 : :
8138 : : PyDoc_STRVAR(os_posix_fadvise__doc__,
8139 : : "posix_fadvise($module, fd, offset, length, advice, /)\n"
8140 : : "--\n"
8141 : : "\n"
8142 : : "Announce an intention to access data in a specific pattern.\n"
8143 : : "\n"
8144 : : "Announce an intention to access data in a specific pattern, thus allowing\n"
8145 : : "the kernel to make optimizations.\n"
8146 : : "The advice applies to the region of the file specified by fd starting at\n"
8147 : : "offset and continuing for length bytes.\n"
8148 : : "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
8149 : : "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
8150 : : "POSIX_FADV_DONTNEED.");
8151 : :
8152 : : #define OS_POSIX_FADVISE_METHODDEF \
8153 : : {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
8154 : :
8155 : : static PyObject *
8156 : : os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
8157 : : Py_off_t length, int advice);
8158 : :
8159 : : static PyObject *
8160 : 0 : os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8161 : : {
8162 : 0 : PyObject *return_value = NULL;
8163 : : int fd;
8164 : : Py_off_t offset;
8165 : : Py_off_t length;
8166 : : int advice;
8167 : :
8168 [ # # # # : 0 : if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
# # ]
8169 : 0 : goto exit;
8170 : : }
8171 : 0 : fd = _PyLong_AsInt(args[0]);
8172 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
8173 : 0 : goto exit;
8174 : : }
8175 [ # # ]: 0 : if (!Py_off_t_converter(args[1], &offset)) {
8176 : 0 : goto exit;
8177 : : }
8178 [ # # ]: 0 : if (!Py_off_t_converter(args[2], &length)) {
8179 : 0 : goto exit;
8180 : : }
8181 : 0 : advice = _PyLong_AsInt(args[3]);
8182 [ # # # # ]: 0 : if (advice == -1 && PyErr_Occurred()) {
8183 : 0 : goto exit;
8184 : : }
8185 : 0 : return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
8186 : :
8187 : 0 : exit:
8188 : 0 : return return_value;
8189 : : }
8190 : :
8191 : : #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
8192 : :
8193 : : #if defined(MS_WINDOWS)
8194 : :
8195 : : PyDoc_STRVAR(os_putenv__doc__,
8196 : : "putenv($module, name, value, /)\n"
8197 : : "--\n"
8198 : : "\n"
8199 : : "Change or add an environment variable.");
8200 : :
8201 : : #define OS_PUTENV_METHODDEF \
8202 : : {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
8203 : :
8204 : : static PyObject *
8205 : : os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
8206 : :
8207 : : static PyObject *
8208 : : os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8209 : : {
8210 : : PyObject *return_value = NULL;
8211 : : PyObject *name;
8212 : : PyObject *value;
8213 : :
8214 : : if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
8215 : : goto exit;
8216 : : }
8217 : : if (!PyUnicode_Check(args[0])) {
8218 : : _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
8219 : : goto exit;
8220 : : }
8221 : : if (PyUnicode_READY(args[0]) == -1) {
8222 : : goto exit;
8223 : : }
8224 : : name = args[0];
8225 : : if (!PyUnicode_Check(args[1])) {
8226 : : _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
8227 : : goto exit;
8228 : : }
8229 : : if (PyUnicode_READY(args[1]) == -1) {
8230 : : goto exit;
8231 : : }
8232 : : value = args[1];
8233 : : return_value = os_putenv_impl(module, name, value);
8234 : :
8235 : : exit:
8236 : : return return_value;
8237 : : }
8238 : :
8239 : : #endif /* defined(MS_WINDOWS) */
8240 : :
8241 : : #if !defined(MS_WINDOWS)
8242 : :
8243 : : PyDoc_STRVAR(os_putenv__doc__,
8244 : : "putenv($module, name, value, /)\n"
8245 : : "--\n"
8246 : : "\n"
8247 : : "Change or add an environment variable.");
8248 : :
8249 : : #define OS_PUTENV_METHODDEF \
8250 : : {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
8251 : :
8252 : : static PyObject *
8253 : : os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
8254 : :
8255 : : static PyObject *
8256 : 1 : os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
8257 : : {
8258 : 1 : PyObject *return_value = NULL;
8259 : 1 : PyObject *name = NULL;
8260 : 1 : PyObject *value = NULL;
8261 : :
8262 [ + - - + : 1 : if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
- - ]
8263 : 0 : goto exit;
8264 : : }
8265 [ - + ]: 1 : if (!PyUnicode_FSConverter(args[0], &name)) {
8266 : 0 : goto exit;
8267 : : }
8268 [ - + ]: 1 : if (!PyUnicode_FSConverter(args[1], &value)) {
8269 : 0 : goto exit;
8270 : : }
8271 : 1 : return_value = os_putenv_impl(module, name, value);
8272 : :
8273 : 1 : exit:
8274 : : /* Cleanup for name */
8275 : 1 : Py_XDECREF(name);
8276 : : /* Cleanup for value */
8277 : 1 : Py_XDECREF(value);
8278 : :
8279 : 1 : return return_value;
8280 : : }
8281 : :
8282 : : #endif /* !defined(MS_WINDOWS) */
8283 : :
8284 : : #if defined(MS_WINDOWS)
8285 : :
8286 : : PyDoc_STRVAR(os_unsetenv__doc__,
8287 : : "unsetenv($module, name, /)\n"
8288 : : "--\n"
8289 : : "\n"
8290 : : "Delete an environment variable.");
8291 : :
8292 : : #define OS_UNSETENV_METHODDEF \
8293 : : {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
8294 : :
8295 : : static PyObject *
8296 : : os_unsetenv_impl(PyObject *module, PyObject *name);
8297 : :
8298 : : static PyObject *
8299 : : os_unsetenv(PyObject *module, PyObject *arg)
8300 : : {
8301 : : PyObject *return_value = NULL;
8302 : : PyObject *name;
8303 : :
8304 : : if (!PyUnicode_Check(arg)) {
8305 : : _PyArg_BadArgument("unsetenv", "argument", "str", arg);
8306 : : goto exit;
8307 : : }
8308 : : if (PyUnicode_READY(arg) == -1) {
8309 : : goto exit;
8310 : : }
8311 : : name = arg;
8312 : : return_value = os_unsetenv_impl(module, name);
8313 : :
8314 : : exit:
8315 : : return return_value;
8316 : : }
8317 : :
8318 : : #endif /* defined(MS_WINDOWS) */
8319 : :
8320 : : #if !defined(MS_WINDOWS)
8321 : :
8322 : : PyDoc_STRVAR(os_unsetenv__doc__,
8323 : : "unsetenv($module, name, /)\n"
8324 : : "--\n"
8325 : : "\n"
8326 : : "Delete an environment variable.");
8327 : :
8328 : : #define OS_UNSETENV_METHODDEF \
8329 : : {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
8330 : :
8331 : : static PyObject *
8332 : : os_unsetenv_impl(PyObject *module, PyObject *name);
8333 : :
8334 : : static PyObject *
8335 : 0 : os_unsetenv(PyObject *module, PyObject *arg)
8336 : : {
8337 : 0 : PyObject *return_value = NULL;
8338 : 0 : PyObject *name = NULL;
8339 : :
8340 [ # # ]: 0 : if (!PyUnicode_FSConverter(arg, &name)) {
8341 : 0 : goto exit;
8342 : : }
8343 : 0 : return_value = os_unsetenv_impl(module, name);
8344 : :
8345 : 0 : exit:
8346 : : /* Cleanup for name */
8347 : 0 : Py_XDECREF(name);
8348 : :
8349 : 0 : return return_value;
8350 : : }
8351 : :
8352 : : #endif /* !defined(MS_WINDOWS) */
8353 : :
8354 : : PyDoc_STRVAR(os_strerror__doc__,
8355 : : "strerror($module, code, /)\n"
8356 : : "--\n"
8357 : : "\n"
8358 : : "Translate an error code to a message string.");
8359 : :
8360 : : #define OS_STRERROR_METHODDEF \
8361 : : {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
8362 : :
8363 : : static PyObject *
8364 : : os_strerror_impl(PyObject *module, int code);
8365 : :
8366 : : static PyObject *
8367 : 0 : os_strerror(PyObject *module, PyObject *arg)
8368 : : {
8369 : 0 : PyObject *return_value = NULL;
8370 : : int code;
8371 : :
8372 : 0 : code = _PyLong_AsInt(arg);
8373 [ # # # # ]: 0 : if (code == -1 && PyErr_Occurred()) {
8374 : 0 : goto exit;
8375 : : }
8376 : 0 : return_value = os_strerror_impl(module, code);
8377 : :
8378 : 0 : exit:
8379 : 0 : return return_value;
8380 : : }
8381 : :
8382 : : #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
8383 : :
8384 : : PyDoc_STRVAR(os_WCOREDUMP__doc__,
8385 : : "WCOREDUMP($module, status, /)\n"
8386 : : "--\n"
8387 : : "\n"
8388 : : "Return True if the process returning status was dumped to a core file.");
8389 : :
8390 : : #define OS_WCOREDUMP_METHODDEF \
8391 : : {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
8392 : :
8393 : : static int
8394 : : os_WCOREDUMP_impl(PyObject *module, int status);
8395 : :
8396 : : static PyObject *
8397 : 0 : os_WCOREDUMP(PyObject *module, PyObject *arg)
8398 : : {
8399 : 0 : PyObject *return_value = NULL;
8400 : : int status;
8401 : : int _return_value;
8402 : :
8403 : 0 : status = _PyLong_AsInt(arg);
8404 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8405 : 0 : goto exit;
8406 : : }
8407 : 0 : _return_value = os_WCOREDUMP_impl(module, status);
8408 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8409 : 0 : goto exit;
8410 : : }
8411 : 0 : return_value = PyBool_FromLong((long)_return_value);
8412 : :
8413 : 0 : exit:
8414 : 0 : return return_value;
8415 : : }
8416 : :
8417 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
8418 : :
8419 : : #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
8420 : :
8421 : : PyDoc_STRVAR(os_WIFCONTINUED__doc__,
8422 : : "WIFCONTINUED($module, /, status)\n"
8423 : : "--\n"
8424 : : "\n"
8425 : : "Return True if a particular process was continued from a job control stop.\n"
8426 : : "\n"
8427 : : "Return True if the process returning status was continued from a\n"
8428 : : "job control stop.");
8429 : :
8430 : : #define OS_WIFCONTINUED_METHODDEF \
8431 : : {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
8432 : :
8433 : : static int
8434 : : os_WIFCONTINUED_impl(PyObject *module, int status);
8435 : :
8436 : : static PyObject *
8437 : 0 : os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8438 : : {
8439 : 0 : PyObject *return_value = NULL;
8440 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8441 : :
8442 : : #define NUM_KEYWORDS 1
8443 : : static struct {
8444 : : PyGC_Head _this_is_not_used;
8445 : : PyObject_VAR_HEAD
8446 : : PyObject *ob_item[NUM_KEYWORDS];
8447 : : } _kwtuple = {
8448 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8449 : : .ob_item = { &_Py_ID(status), },
8450 : : };
8451 : : #undef NUM_KEYWORDS
8452 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8453 : :
8454 : : #else // !Py_BUILD_CORE
8455 : : # define KWTUPLE NULL
8456 : : #endif // !Py_BUILD_CORE
8457 : :
8458 : : static const char * const _keywords[] = {"status", NULL};
8459 : : static _PyArg_Parser _parser = {
8460 : : .keywords = _keywords,
8461 : : .fname = "WIFCONTINUED",
8462 : : .kwtuple = KWTUPLE,
8463 : : };
8464 : : #undef KWTUPLE
8465 : : PyObject *argsbuf[1];
8466 : : int status;
8467 : : int _return_value;
8468 : :
8469 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8470 [ # # ]: 0 : if (!args) {
8471 : 0 : goto exit;
8472 : : }
8473 : 0 : status = _PyLong_AsInt(args[0]);
8474 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8475 : 0 : goto exit;
8476 : : }
8477 : 0 : _return_value = os_WIFCONTINUED_impl(module, status);
8478 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8479 : 0 : goto exit;
8480 : : }
8481 : 0 : return_value = PyBool_FromLong((long)_return_value);
8482 : :
8483 : 0 : exit:
8484 : 0 : return return_value;
8485 : : }
8486 : :
8487 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
8488 : :
8489 : : #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
8490 : :
8491 : : PyDoc_STRVAR(os_WIFSTOPPED__doc__,
8492 : : "WIFSTOPPED($module, /, status)\n"
8493 : : "--\n"
8494 : : "\n"
8495 : : "Return True if the process returning status was stopped.");
8496 : :
8497 : : #define OS_WIFSTOPPED_METHODDEF \
8498 : : {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
8499 : :
8500 : : static int
8501 : : os_WIFSTOPPED_impl(PyObject *module, int status);
8502 : :
8503 : : static PyObject *
8504 : 0 : os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8505 : : {
8506 : 0 : PyObject *return_value = NULL;
8507 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8508 : :
8509 : : #define NUM_KEYWORDS 1
8510 : : static struct {
8511 : : PyGC_Head _this_is_not_used;
8512 : : PyObject_VAR_HEAD
8513 : : PyObject *ob_item[NUM_KEYWORDS];
8514 : : } _kwtuple = {
8515 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8516 : : .ob_item = { &_Py_ID(status), },
8517 : : };
8518 : : #undef NUM_KEYWORDS
8519 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8520 : :
8521 : : #else // !Py_BUILD_CORE
8522 : : # define KWTUPLE NULL
8523 : : #endif // !Py_BUILD_CORE
8524 : :
8525 : : static const char * const _keywords[] = {"status", NULL};
8526 : : static _PyArg_Parser _parser = {
8527 : : .keywords = _keywords,
8528 : : .fname = "WIFSTOPPED",
8529 : : .kwtuple = KWTUPLE,
8530 : : };
8531 : : #undef KWTUPLE
8532 : : PyObject *argsbuf[1];
8533 : : int status;
8534 : : int _return_value;
8535 : :
8536 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8537 [ # # ]: 0 : if (!args) {
8538 : 0 : goto exit;
8539 : : }
8540 : 0 : status = _PyLong_AsInt(args[0]);
8541 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8542 : 0 : goto exit;
8543 : : }
8544 : 0 : _return_value = os_WIFSTOPPED_impl(module, status);
8545 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8546 : 0 : goto exit;
8547 : : }
8548 : 0 : return_value = PyBool_FromLong((long)_return_value);
8549 : :
8550 : 0 : exit:
8551 : 0 : return return_value;
8552 : : }
8553 : :
8554 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
8555 : :
8556 : : #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
8557 : :
8558 : : PyDoc_STRVAR(os_WIFSIGNALED__doc__,
8559 : : "WIFSIGNALED($module, /, status)\n"
8560 : : "--\n"
8561 : : "\n"
8562 : : "Return True if the process returning status was terminated by a signal.");
8563 : :
8564 : : #define OS_WIFSIGNALED_METHODDEF \
8565 : : {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
8566 : :
8567 : : static int
8568 : : os_WIFSIGNALED_impl(PyObject *module, int status);
8569 : :
8570 : : static PyObject *
8571 : 0 : os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8572 : : {
8573 : 0 : PyObject *return_value = NULL;
8574 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8575 : :
8576 : : #define NUM_KEYWORDS 1
8577 : : static struct {
8578 : : PyGC_Head _this_is_not_used;
8579 : : PyObject_VAR_HEAD
8580 : : PyObject *ob_item[NUM_KEYWORDS];
8581 : : } _kwtuple = {
8582 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8583 : : .ob_item = { &_Py_ID(status), },
8584 : : };
8585 : : #undef NUM_KEYWORDS
8586 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8587 : :
8588 : : #else // !Py_BUILD_CORE
8589 : : # define KWTUPLE NULL
8590 : : #endif // !Py_BUILD_CORE
8591 : :
8592 : : static const char * const _keywords[] = {"status", NULL};
8593 : : static _PyArg_Parser _parser = {
8594 : : .keywords = _keywords,
8595 : : .fname = "WIFSIGNALED",
8596 : : .kwtuple = KWTUPLE,
8597 : : };
8598 : : #undef KWTUPLE
8599 : : PyObject *argsbuf[1];
8600 : : int status;
8601 : : int _return_value;
8602 : :
8603 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8604 [ # # ]: 0 : if (!args) {
8605 : 0 : goto exit;
8606 : : }
8607 : 0 : status = _PyLong_AsInt(args[0]);
8608 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8609 : 0 : goto exit;
8610 : : }
8611 : 0 : _return_value = os_WIFSIGNALED_impl(module, status);
8612 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8613 : 0 : goto exit;
8614 : : }
8615 : 0 : return_value = PyBool_FromLong((long)_return_value);
8616 : :
8617 : 0 : exit:
8618 : 0 : return return_value;
8619 : : }
8620 : :
8621 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
8622 : :
8623 : : #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
8624 : :
8625 : : PyDoc_STRVAR(os_WIFEXITED__doc__,
8626 : : "WIFEXITED($module, /, status)\n"
8627 : : "--\n"
8628 : : "\n"
8629 : : "Return True if the process returning status exited via the exit() system call.");
8630 : :
8631 : : #define OS_WIFEXITED_METHODDEF \
8632 : : {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
8633 : :
8634 : : static int
8635 : : os_WIFEXITED_impl(PyObject *module, int status);
8636 : :
8637 : : static PyObject *
8638 : 0 : os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8639 : : {
8640 : 0 : PyObject *return_value = NULL;
8641 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8642 : :
8643 : : #define NUM_KEYWORDS 1
8644 : : static struct {
8645 : : PyGC_Head _this_is_not_used;
8646 : : PyObject_VAR_HEAD
8647 : : PyObject *ob_item[NUM_KEYWORDS];
8648 : : } _kwtuple = {
8649 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8650 : : .ob_item = { &_Py_ID(status), },
8651 : : };
8652 : : #undef NUM_KEYWORDS
8653 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8654 : :
8655 : : #else // !Py_BUILD_CORE
8656 : : # define KWTUPLE NULL
8657 : : #endif // !Py_BUILD_CORE
8658 : :
8659 : : static const char * const _keywords[] = {"status", NULL};
8660 : : static _PyArg_Parser _parser = {
8661 : : .keywords = _keywords,
8662 : : .fname = "WIFEXITED",
8663 : : .kwtuple = KWTUPLE,
8664 : : };
8665 : : #undef KWTUPLE
8666 : : PyObject *argsbuf[1];
8667 : : int status;
8668 : : int _return_value;
8669 : :
8670 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8671 [ # # ]: 0 : if (!args) {
8672 : 0 : goto exit;
8673 : : }
8674 : 0 : status = _PyLong_AsInt(args[0]);
8675 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8676 : 0 : goto exit;
8677 : : }
8678 : 0 : _return_value = os_WIFEXITED_impl(module, status);
8679 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8680 : 0 : goto exit;
8681 : : }
8682 : 0 : return_value = PyBool_FromLong((long)_return_value);
8683 : :
8684 : 0 : exit:
8685 : 0 : return return_value;
8686 : : }
8687 : :
8688 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
8689 : :
8690 : : #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
8691 : :
8692 : : PyDoc_STRVAR(os_WEXITSTATUS__doc__,
8693 : : "WEXITSTATUS($module, /, status)\n"
8694 : : "--\n"
8695 : : "\n"
8696 : : "Return the process return code from status.");
8697 : :
8698 : : #define OS_WEXITSTATUS_METHODDEF \
8699 : : {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
8700 : :
8701 : : static int
8702 : : os_WEXITSTATUS_impl(PyObject *module, int status);
8703 : :
8704 : : static PyObject *
8705 : 0 : os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8706 : : {
8707 : 0 : PyObject *return_value = NULL;
8708 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8709 : :
8710 : : #define NUM_KEYWORDS 1
8711 : : static struct {
8712 : : PyGC_Head _this_is_not_used;
8713 : : PyObject_VAR_HEAD
8714 : : PyObject *ob_item[NUM_KEYWORDS];
8715 : : } _kwtuple = {
8716 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8717 : : .ob_item = { &_Py_ID(status), },
8718 : : };
8719 : : #undef NUM_KEYWORDS
8720 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8721 : :
8722 : : #else // !Py_BUILD_CORE
8723 : : # define KWTUPLE NULL
8724 : : #endif // !Py_BUILD_CORE
8725 : :
8726 : : static const char * const _keywords[] = {"status", NULL};
8727 : : static _PyArg_Parser _parser = {
8728 : : .keywords = _keywords,
8729 : : .fname = "WEXITSTATUS",
8730 : : .kwtuple = KWTUPLE,
8731 : : };
8732 : : #undef KWTUPLE
8733 : : PyObject *argsbuf[1];
8734 : : int status;
8735 : : int _return_value;
8736 : :
8737 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8738 [ # # ]: 0 : if (!args) {
8739 : 0 : goto exit;
8740 : : }
8741 : 0 : status = _PyLong_AsInt(args[0]);
8742 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8743 : 0 : goto exit;
8744 : : }
8745 : 0 : _return_value = os_WEXITSTATUS_impl(module, status);
8746 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8747 : 0 : goto exit;
8748 : : }
8749 : 0 : return_value = PyLong_FromLong((long)_return_value);
8750 : :
8751 : 0 : exit:
8752 : 0 : return return_value;
8753 : : }
8754 : :
8755 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
8756 : :
8757 : : #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
8758 : :
8759 : : PyDoc_STRVAR(os_WTERMSIG__doc__,
8760 : : "WTERMSIG($module, /, status)\n"
8761 : : "--\n"
8762 : : "\n"
8763 : : "Return the signal that terminated the process that provided the status value.");
8764 : :
8765 : : #define OS_WTERMSIG_METHODDEF \
8766 : : {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
8767 : :
8768 : : static int
8769 : : os_WTERMSIG_impl(PyObject *module, int status);
8770 : :
8771 : : static PyObject *
8772 : 0 : os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8773 : : {
8774 : 0 : PyObject *return_value = NULL;
8775 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8776 : :
8777 : : #define NUM_KEYWORDS 1
8778 : : static struct {
8779 : : PyGC_Head _this_is_not_used;
8780 : : PyObject_VAR_HEAD
8781 : : PyObject *ob_item[NUM_KEYWORDS];
8782 : : } _kwtuple = {
8783 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8784 : : .ob_item = { &_Py_ID(status), },
8785 : : };
8786 : : #undef NUM_KEYWORDS
8787 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8788 : :
8789 : : #else // !Py_BUILD_CORE
8790 : : # define KWTUPLE NULL
8791 : : #endif // !Py_BUILD_CORE
8792 : :
8793 : : static const char * const _keywords[] = {"status", NULL};
8794 : : static _PyArg_Parser _parser = {
8795 : : .keywords = _keywords,
8796 : : .fname = "WTERMSIG",
8797 : : .kwtuple = KWTUPLE,
8798 : : };
8799 : : #undef KWTUPLE
8800 : : PyObject *argsbuf[1];
8801 : : int status;
8802 : : int _return_value;
8803 : :
8804 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8805 [ # # ]: 0 : if (!args) {
8806 : 0 : goto exit;
8807 : : }
8808 : 0 : status = _PyLong_AsInt(args[0]);
8809 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8810 : 0 : goto exit;
8811 : : }
8812 : 0 : _return_value = os_WTERMSIG_impl(module, status);
8813 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8814 : 0 : goto exit;
8815 : : }
8816 : 0 : return_value = PyLong_FromLong((long)_return_value);
8817 : :
8818 : 0 : exit:
8819 : 0 : return return_value;
8820 : : }
8821 : :
8822 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
8823 : :
8824 : : #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
8825 : :
8826 : : PyDoc_STRVAR(os_WSTOPSIG__doc__,
8827 : : "WSTOPSIG($module, /, status)\n"
8828 : : "--\n"
8829 : : "\n"
8830 : : "Return the signal that stopped the process that provided the status value.");
8831 : :
8832 : : #define OS_WSTOPSIG_METHODDEF \
8833 : : {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
8834 : :
8835 : : static int
8836 : : os_WSTOPSIG_impl(PyObject *module, int status);
8837 : :
8838 : : static PyObject *
8839 : 0 : os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8840 : : {
8841 : 0 : PyObject *return_value = NULL;
8842 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8843 : :
8844 : : #define NUM_KEYWORDS 1
8845 : : static struct {
8846 : : PyGC_Head _this_is_not_used;
8847 : : PyObject_VAR_HEAD
8848 : : PyObject *ob_item[NUM_KEYWORDS];
8849 : : } _kwtuple = {
8850 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8851 : : .ob_item = { &_Py_ID(status), },
8852 : : };
8853 : : #undef NUM_KEYWORDS
8854 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8855 : :
8856 : : #else // !Py_BUILD_CORE
8857 : : # define KWTUPLE NULL
8858 : : #endif // !Py_BUILD_CORE
8859 : :
8860 : : static const char * const _keywords[] = {"status", NULL};
8861 : : static _PyArg_Parser _parser = {
8862 : : .keywords = _keywords,
8863 : : .fname = "WSTOPSIG",
8864 : : .kwtuple = KWTUPLE,
8865 : : };
8866 : : #undef KWTUPLE
8867 : : PyObject *argsbuf[1];
8868 : : int status;
8869 : : int _return_value;
8870 : :
8871 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8872 [ # # ]: 0 : if (!args) {
8873 : 0 : goto exit;
8874 : : }
8875 : 0 : status = _PyLong_AsInt(args[0]);
8876 [ # # # # ]: 0 : if (status == -1 && PyErr_Occurred()) {
8877 : 0 : goto exit;
8878 : : }
8879 : 0 : _return_value = os_WSTOPSIG_impl(module, status);
8880 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
8881 : 0 : goto exit;
8882 : : }
8883 : 0 : return_value = PyLong_FromLong((long)_return_value);
8884 : :
8885 : 0 : exit:
8886 : 0 : return return_value;
8887 : : }
8888 : :
8889 : : #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
8890 : :
8891 : : #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
8892 : :
8893 : : PyDoc_STRVAR(os_fstatvfs__doc__,
8894 : : "fstatvfs($module, fd, /)\n"
8895 : : "--\n"
8896 : : "\n"
8897 : : "Perform an fstatvfs system call on the given fd.\n"
8898 : : "\n"
8899 : : "Equivalent to statvfs(fd).");
8900 : :
8901 : : #define OS_FSTATVFS_METHODDEF \
8902 : : {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
8903 : :
8904 : : static PyObject *
8905 : : os_fstatvfs_impl(PyObject *module, int fd);
8906 : :
8907 : : static PyObject *
8908 : 0 : os_fstatvfs(PyObject *module, PyObject *arg)
8909 : : {
8910 : 0 : PyObject *return_value = NULL;
8911 : : int fd;
8912 : :
8913 : 0 : fd = _PyLong_AsInt(arg);
8914 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
8915 : 0 : goto exit;
8916 : : }
8917 : 0 : return_value = os_fstatvfs_impl(module, fd);
8918 : :
8919 : 0 : exit:
8920 : 0 : return return_value;
8921 : : }
8922 : :
8923 : : #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
8924 : :
8925 : : #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
8926 : :
8927 : : PyDoc_STRVAR(os_statvfs__doc__,
8928 : : "statvfs($module, /, path)\n"
8929 : : "--\n"
8930 : : "\n"
8931 : : "Perform a statvfs system call on the given path.\n"
8932 : : "\n"
8933 : : "path may always be specified as a string.\n"
8934 : : "On some platforms, path may also be specified as an open file descriptor.\n"
8935 : : " If this functionality is unavailable, using it raises an exception.");
8936 : :
8937 : : #define OS_STATVFS_METHODDEF \
8938 : : {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
8939 : :
8940 : : static PyObject *
8941 : : os_statvfs_impl(PyObject *module, path_t *path);
8942 : :
8943 : : static PyObject *
8944 : 0 : os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
8945 : : {
8946 : 0 : PyObject *return_value = NULL;
8947 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
8948 : :
8949 : : #define NUM_KEYWORDS 1
8950 : : static struct {
8951 : : PyGC_Head _this_is_not_used;
8952 : : PyObject_VAR_HEAD
8953 : : PyObject *ob_item[NUM_KEYWORDS];
8954 : : } _kwtuple = {
8955 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
8956 : : .ob_item = { &_Py_ID(path), },
8957 : : };
8958 : : #undef NUM_KEYWORDS
8959 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
8960 : :
8961 : : #else // !Py_BUILD_CORE
8962 : : # define KWTUPLE NULL
8963 : : #endif // !Py_BUILD_CORE
8964 : :
8965 : : static const char * const _keywords[] = {"path", NULL};
8966 : : static _PyArg_Parser _parser = {
8967 : : .keywords = _keywords,
8968 : : .fname = "statvfs",
8969 : : .kwtuple = KWTUPLE,
8970 : : };
8971 : : #undef KWTUPLE
8972 : : PyObject *argsbuf[1];
8973 : 0 : path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
8974 : :
8975 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
8976 [ # # ]: 0 : if (!args) {
8977 : 0 : goto exit;
8978 : : }
8979 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
8980 : 0 : goto exit;
8981 : : }
8982 : 0 : return_value = os_statvfs_impl(module, &path);
8983 : :
8984 : 0 : exit:
8985 : : /* Cleanup for path */
8986 : 0 : path_cleanup(&path);
8987 : :
8988 : 0 : return return_value;
8989 : : }
8990 : :
8991 : : #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
8992 : :
8993 : : #if defined(MS_WINDOWS)
8994 : :
8995 : : PyDoc_STRVAR(os__getdiskusage__doc__,
8996 : : "_getdiskusage($module, /, path)\n"
8997 : : "--\n"
8998 : : "\n"
8999 : : "Return disk usage statistics about the given path as a (total, free) tuple.");
9000 : :
9001 : : #define OS__GETDISKUSAGE_METHODDEF \
9002 : : {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
9003 : :
9004 : : static PyObject *
9005 : : os__getdiskusage_impl(PyObject *module, path_t *path);
9006 : :
9007 : : static PyObject *
9008 : : os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9009 : : {
9010 : : PyObject *return_value = NULL;
9011 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9012 : :
9013 : : #define NUM_KEYWORDS 1
9014 : : static struct {
9015 : : PyGC_Head _this_is_not_used;
9016 : : PyObject_VAR_HEAD
9017 : : PyObject *ob_item[NUM_KEYWORDS];
9018 : : } _kwtuple = {
9019 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9020 : : .ob_item = { &_Py_ID(path), },
9021 : : };
9022 : : #undef NUM_KEYWORDS
9023 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9024 : :
9025 : : #else // !Py_BUILD_CORE
9026 : : # define KWTUPLE NULL
9027 : : #endif // !Py_BUILD_CORE
9028 : :
9029 : : static const char * const _keywords[] = {"path", NULL};
9030 : : static _PyArg_Parser _parser = {
9031 : : .keywords = _keywords,
9032 : : .fname = "_getdiskusage",
9033 : : .kwtuple = KWTUPLE,
9034 : : };
9035 : : #undef KWTUPLE
9036 : : PyObject *argsbuf[1];
9037 : : path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
9038 : :
9039 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
9040 : : if (!args) {
9041 : : goto exit;
9042 : : }
9043 : : if (!path_converter(args[0], &path)) {
9044 : : goto exit;
9045 : : }
9046 : : return_value = os__getdiskusage_impl(module, &path);
9047 : :
9048 : : exit:
9049 : : /* Cleanup for path */
9050 : : path_cleanup(&path);
9051 : :
9052 : : return return_value;
9053 : : }
9054 : :
9055 : : #endif /* defined(MS_WINDOWS) */
9056 : :
9057 : : #if defined(HAVE_FPATHCONF)
9058 : :
9059 : : PyDoc_STRVAR(os_fpathconf__doc__,
9060 : : "fpathconf($module, fd, name, /)\n"
9061 : : "--\n"
9062 : : "\n"
9063 : : "Return the configuration limit name for the file descriptor fd.\n"
9064 : : "\n"
9065 : : "If there is no limit, return -1.");
9066 : :
9067 : : #define OS_FPATHCONF_METHODDEF \
9068 : : {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
9069 : :
9070 : : static long
9071 : : os_fpathconf_impl(PyObject *module, int fd, int name);
9072 : :
9073 : : static PyObject *
9074 : 0 : os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9075 : : {
9076 : 0 : PyObject *return_value = NULL;
9077 : : int fd;
9078 : : int name;
9079 : : long _return_value;
9080 : :
9081 [ # # # # : 0 : if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
# # ]
9082 : 0 : goto exit;
9083 : : }
9084 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
9085 : 0 : goto exit;
9086 : : }
9087 [ # # ]: 0 : if (!conv_path_confname(args[1], &name)) {
9088 : 0 : goto exit;
9089 : : }
9090 : 0 : _return_value = os_fpathconf_impl(module, fd, name);
9091 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
9092 : 0 : goto exit;
9093 : : }
9094 : 0 : return_value = PyLong_FromLong(_return_value);
9095 : :
9096 : 0 : exit:
9097 : 0 : return return_value;
9098 : : }
9099 : :
9100 : : #endif /* defined(HAVE_FPATHCONF) */
9101 : :
9102 : : #if defined(HAVE_PATHCONF)
9103 : :
9104 : : PyDoc_STRVAR(os_pathconf__doc__,
9105 : : "pathconf($module, /, path, name)\n"
9106 : : "--\n"
9107 : : "\n"
9108 : : "Return the configuration limit name for the file or directory path.\n"
9109 : : "\n"
9110 : : "If there is no limit, return -1.\n"
9111 : : "On some platforms, path may also be specified as an open file descriptor.\n"
9112 : : " If this functionality is unavailable, using it raises an exception.");
9113 : :
9114 : : #define OS_PATHCONF_METHODDEF \
9115 : : {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
9116 : :
9117 : : static long
9118 : : os_pathconf_impl(PyObject *module, path_t *path, int name);
9119 : :
9120 : : static PyObject *
9121 : 0 : os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9122 : : {
9123 : 0 : PyObject *return_value = NULL;
9124 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9125 : :
9126 : : #define NUM_KEYWORDS 2
9127 : : static struct {
9128 : : PyGC_Head _this_is_not_used;
9129 : : PyObject_VAR_HEAD
9130 : : PyObject *ob_item[NUM_KEYWORDS];
9131 : : } _kwtuple = {
9132 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9133 : : .ob_item = { &_Py_ID(path), &_Py_ID(name), },
9134 : : };
9135 : : #undef NUM_KEYWORDS
9136 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9137 : :
9138 : : #else // !Py_BUILD_CORE
9139 : : # define KWTUPLE NULL
9140 : : #endif // !Py_BUILD_CORE
9141 : :
9142 : : static const char * const _keywords[] = {"path", "name", NULL};
9143 : : static _PyArg_Parser _parser = {
9144 : : .keywords = _keywords,
9145 : : .fname = "pathconf",
9146 : : .kwtuple = KWTUPLE,
9147 : : };
9148 : : #undef KWTUPLE
9149 : : PyObject *argsbuf[2];
9150 : 0 : path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
9151 : : int name;
9152 : : long _return_value;
9153 : :
9154 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
9155 [ # # ]: 0 : if (!args) {
9156 : 0 : goto exit;
9157 : : }
9158 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
9159 : 0 : goto exit;
9160 : : }
9161 [ # # ]: 0 : if (!conv_path_confname(args[1], &name)) {
9162 : 0 : goto exit;
9163 : : }
9164 : 0 : _return_value = os_pathconf_impl(module, &path, name);
9165 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
9166 : 0 : goto exit;
9167 : : }
9168 : 0 : return_value = PyLong_FromLong(_return_value);
9169 : :
9170 : 0 : exit:
9171 : : /* Cleanup for path */
9172 : 0 : path_cleanup(&path);
9173 : :
9174 : 0 : return return_value;
9175 : : }
9176 : :
9177 : : #endif /* defined(HAVE_PATHCONF) */
9178 : :
9179 : : #if defined(HAVE_CONFSTR)
9180 : :
9181 : : PyDoc_STRVAR(os_confstr__doc__,
9182 : : "confstr($module, name, /)\n"
9183 : : "--\n"
9184 : : "\n"
9185 : : "Return a string-valued system configuration variable.");
9186 : :
9187 : : #define OS_CONFSTR_METHODDEF \
9188 : : {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
9189 : :
9190 : : static PyObject *
9191 : : os_confstr_impl(PyObject *module, int name);
9192 : :
9193 : : static PyObject *
9194 : 1 : os_confstr(PyObject *module, PyObject *arg)
9195 : : {
9196 : 1 : PyObject *return_value = NULL;
9197 : : int name;
9198 : :
9199 [ - + ]: 1 : if (!conv_confstr_confname(arg, &name)) {
9200 : 0 : goto exit;
9201 : : }
9202 : 1 : return_value = os_confstr_impl(module, name);
9203 : :
9204 : 1 : exit:
9205 : 1 : return return_value;
9206 : : }
9207 : :
9208 : : #endif /* defined(HAVE_CONFSTR) */
9209 : :
9210 : : #if defined(HAVE_SYSCONF)
9211 : :
9212 : : PyDoc_STRVAR(os_sysconf__doc__,
9213 : : "sysconf($module, name, /)\n"
9214 : : "--\n"
9215 : : "\n"
9216 : : "Return an integer-valued system configuration variable.");
9217 : :
9218 : : #define OS_SYSCONF_METHODDEF \
9219 : : {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
9220 : :
9221 : : static long
9222 : : os_sysconf_impl(PyObject *module, int name);
9223 : :
9224 : : static PyObject *
9225 : 1 : os_sysconf(PyObject *module, PyObject *arg)
9226 : : {
9227 : 1 : PyObject *return_value = NULL;
9228 : : int name;
9229 : : long _return_value;
9230 : :
9231 [ - + ]: 1 : if (!conv_sysconf_confname(arg, &name)) {
9232 : 0 : goto exit;
9233 : : }
9234 : 1 : _return_value = os_sysconf_impl(module, name);
9235 [ - + - - ]: 1 : if ((_return_value == -1) && PyErr_Occurred()) {
9236 : 0 : goto exit;
9237 : : }
9238 : 1 : return_value = PyLong_FromLong(_return_value);
9239 : :
9240 : 1 : exit:
9241 : 1 : return return_value;
9242 : : }
9243 : :
9244 : : #endif /* defined(HAVE_SYSCONF) */
9245 : :
9246 : : PyDoc_STRVAR(os_abort__doc__,
9247 : : "abort($module, /)\n"
9248 : : "--\n"
9249 : : "\n"
9250 : : "Abort the interpreter immediately.\n"
9251 : : "\n"
9252 : : "This function \'dumps core\' or otherwise fails in the hardest way possible\n"
9253 : : "on the hosting operating system. This function never returns.");
9254 : :
9255 : : #define OS_ABORT_METHODDEF \
9256 : : {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
9257 : :
9258 : : static PyObject *
9259 : : os_abort_impl(PyObject *module);
9260 : :
9261 : : static PyObject *
9262 : 0 : os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
9263 : : {
9264 : 0 : return os_abort_impl(module);
9265 : : }
9266 : :
9267 : : #if defined(MS_WINDOWS)
9268 : :
9269 : : PyDoc_STRVAR(os_startfile__doc__,
9270 : : "startfile($module, /, filepath, operation=<unrepresentable>,\n"
9271 : : " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
9272 : : "--\n"
9273 : : "\n"
9274 : : "Start a file with its associated application.\n"
9275 : : "\n"
9276 : : "When \"operation\" is not specified or \"open\", this acts like\n"
9277 : : "double-clicking the file in Explorer, or giving the file name as an\n"
9278 : : "argument to the DOS \"start\" command: the file is opened with whatever\n"
9279 : : "application (if any) its extension is associated.\n"
9280 : : "When another \"operation\" is given, it specifies what should be done with\n"
9281 : : "the file. A typical operation is \"print\".\n"
9282 : : "\n"
9283 : : "\"arguments\" is passed to the application, but should be omitted if the\n"
9284 : : "file is a document.\n"
9285 : : "\n"
9286 : : "\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
9287 : : "relative, it will be resolved against this directory. This argument\n"
9288 : : "should usually be an absolute path.\n"
9289 : : "\n"
9290 : : "\"show_cmd\" can be used to override the recommended visibility option.\n"
9291 : : "See the Windows ShellExecute documentation for values.\n"
9292 : : "\n"
9293 : : "startfile returns as soon as the associated application is launched.\n"
9294 : : "There is no option to wait for the application to close, and no way\n"
9295 : : "to retrieve the application\'s exit status.\n"
9296 : : "\n"
9297 : : "The filepath is relative to the current directory. If you want to use\n"
9298 : : "an absolute path, make sure the first character is not a slash (\"/\");\n"
9299 : : "the underlying Win32 ShellExecute function doesn\'t work if it is.");
9300 : :
9301 : : #define OS_STARTFILE_METHODDEF \
9302 : : {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
9303 : :
9304 : : static PyObject *
9305 : : os_startfile_impl(PyObject *module, path_t *filepath,
9306 : : const Py_UNICODE *operation, const Py_UNICODE *arguments,
9307 : : path_t *cwd, int show_cmd);
9308 : :
9309 : : static PyObject *
9310 : : os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9311 : : {
9312 : : PyObject *return_value = NULL;
9313 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9314 : :
9315 : : #define NUM_KEYWORDS 5
9316 : : static struct {
9317 : : PyGC_Head _this_is_not_used;
9318 : : PyObject_VAR_HEAD
9319 : : PyObject *ob_item[NUM_KEYWORDS];
9320 : : } _kwtuple = {
9321 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9322 : : .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
9323 : : };
9324 : : #undef NUM_KEYWORDS
9325 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9326 : :
9327 : : #else // !Py_BUILD_CORE
9328 : : # define KWTUPLE NULL
9329 : : #endif // !Py_BUILD_CORE
9330 : :
9331 : : static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
9332 : : static _PyArg_Parser _parser = {
9333 : : .keywords = _keywords,
9334 : : .fname = "startfile",
9335 : : .kwtuple = KWTUPLE,
9336 : : };
9337 : : #undef KWTUPLE
9338 : : PyObject *argsbuf[5];
9339 : : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
9340 : : path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
9341 : : const Py_UNICODE *operation = NULL;
9342 : : const Py_UNICODE *arguments = NULL;
9343 : : path_t cwd = PATH_T_INITIALIZE("startfile", "cwd", 1, 0);
9344 : : int show_cmd = 1;
9345 : :
9346 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
9347 : : if (!args) {
9348 : : goto exit;
9349 : : }
9350 : : if (!path_converter(args[0], &filepath)) {
9351 : : goto exit;
9352 : : }
9353 : : if (!noptargs) {
9354 : : goto skip_optional_pos;
9355 : : }
9356 : : if (args[1]) {
9357 : : if (!PyUnicode_Check(args[1])) {
9358 : : _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
9359 : : goto exit;
9360 : : }
9361 : : operation = PyUnicode_AsWideCharString(args[1], NULL);
9362 : : if (operation == NULL) {
9363 : : goto exit;
9364 : : }
9365 : : if (!--noptargs) {
9366 : : goto skip_optional_pos;
9367 : : }
9368 : : }
9369 : : if (args[2]) {
9370 : : if (!PyUnicode_Check(args[2])) {
9371 : : _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
9372 : : goto exit;
9373 : : }
9374 : : arguments = PyUnicode_AsWideCharString(args[2], NULL);
9375 : : if (arguments == NULL) {
9376 : : goto exit;
9377 : : }
9378 : : if (!--noptargs) {
9379 : : goto skip_optional_pos;
9380 : : }
9381 : : }
9382 : : if (args[3]) {
9383 : : if (!path_converter(args[3], &cwd)) {
9384 : : goto exit;
9385 : : }
9386 : : if (!--noptargs) {
9387 : : goto skip_optional_pos;
9388 : : }
9389 : : }
9390 : : show_cmd = _PyLong_AsInt(args[4]);
9391 : : if (show_cmd == -1 && PyErr_Occurred()) {
9392 : : goto exit;
9393 : : }
9394 : : skip_optional_pos:
9395 : : return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
9396 : :
9397 : : exit:
9398 : : /* Cleanup for filepath */
9399 : : path_cleanup(&filepath);
9400 : : /* Cleanup for operation */
9401 : : PyMem_Free((void *)operation);
9402 : : /* Cleanup for arguments */
9403 : : PyMem_Free((void *)arguments);
9404 : : /* Cleanup for cwd */
9405 : : path_cleanup(&cwd);
9406 : :
9407 : : return return_value;
9408 : : }
9409 : :
9410 : : #endif /* defined(MS_WINDOWS) */
9411 : :
9412 : : #if defined(HAVE_GETLOADAVG)
9413 : :
9414 : : PyDoc_STRVAR(os_getloadavg__doc__,
9415 : : "getloadavg($module, /)\n"
9416 : : "--\n"
9417 : : "\n"
9418 : : "Return average recent system load information.\n"
9419 : : "\n"
9420 : : "Return the number of processes in the system run queue averaged over\n"
9421 : : "the last 1, 5, and 15 minutes as a tuple of three floats.\n"
9422 : : "Raises OSError if the load average was unobtainable.");
9423 : :
9424 : : #define OS_GETLOADAVG_METHODDEF \
9425 : : {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
9426 : :
9427 : : static PyObject *
9428 : : os_getloadavg_impl(PyObject *module);
9429 : :
9430 : : static PyObject *
9431 : 2 : os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
9432 : : {
9433 : 2 : return os_getloadavg_impl(module);
9434 : : }
9435 : :
9436 : : #endif /* defined(HAVE_GETLOADAVG) */
9437 : :
9438 : : PyDoc_STRVAR(os_device_encoding__doc__,
9439 : : "device_encoding($module, /, fd)\n"
9440 : : "--\n"
9441 : : "\n"
9442 : : "Return a string describing the encoding of a terminal\'s file descriptor.\n"
9443 : : "\n"
9444 : : "The file descriptor must be attached to a terminal.\n"
9445 : : "If the device is not a terminal, return None.");
9446 : :
9447 : : #define OS_DEVICE_ENCODING_METHODDEF \
9448 : : {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
9449 : :
9450 : : static PyObject *
9451 : : os_device_encoding_impl(PyObject *module, int fd);
9452 : :
9453 : : static PyObject *
9454 : 0 : os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9455 : : {
9456 : 0 : PyObject *return_value = NULL;
9457 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9458 : :
9459 : : #define NUM_KEYWORDS 1
9460 : : static struct {
9461 : : PyGC_Head _this_is_not_used;
9462 : : PyObject_VAR_HEAD
9463 : : PyObject *ob_item[NUM_KEYWORDS];
9464 : : } _kwtuple = {
9465 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9466 : : .ob_item = { &_Py_ID(fd), },
9467 : : };
9468 : : #undef NUM_KEYWORDS
9469 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9470 : :
9471 : : #else // !Py_BUILD_CORE
9472 : : # define KWTUPLE NULL
9473 : : #endif // !Py_BUILD_CORE
9474 : :
9475 : : static const char * const _keywords[] = {"fd", NULL};
9476 : : static _PyArg_Parser _parser = {
9477 : : .keywords = _keywords,
9478 : : .fname = "device_encoding",
9479 : : .kwtuple = KWTUPLE,
9480 : : };
9481 : : #undef KWTUPLE
9482 : : PyObject *argsbuf[1];
9483 : : int fd;
9484 : :
9485 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
9486 [ # # ]: 0 : if (!args) {
9487 : 0 : goto exit;
9488 : : }
9489 : 0 : fd = _PyLong_AsInt(args[0]);
9490 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
9491 : 0 : goto exit;
9492 : : }
9493 : 0 : return_value = os_device_encoding_impl(module, fd);
9494 : :
9495 : 0 : exit:
9496 : 0 : return return_value;
9497 : : }
9498 : :
9499 : : #if defined(HAVE_SETRESUID)
9500 : :
9501 : : PyDoc_STRVAR(os_setresuid__doc__,
9502 : : "setresuid($module, ruid, euid, suid, /)\n"
9503 : : "--\n"
9504 : : "\n"
9505 : : "Set the current process\'s real, effective, and saved user ids.");
9506 : :
9507 : : #define OS_SETRESUID_METHODDEF \
9508 : : {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
9509 : :
9510 : : static PyObject *
9511 : : os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
9512 : :
9513 : : static PyObject *
9514 : 0 : os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9515 : : {
9516 : 0 : PyObject *return_value = NULL;
9517 : : uid_t ruid;
9518 : : uid_t euid;
9519 : : uid_t suid;
9520 : :
9521 [ # # # # : 0 : if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
# # ]
9522 : 0 : goto exit;
9523 : : }
9524 [ # # ]: 0 : if (!_Py_Uid_Converter(args[0], &ruid)) {
9525 : 0 : goto exit;
9526 : : }
9527 [ # # ]: 0 : if (!_Py_Uid_Converter(args[1], &euid)) {
9528 : 0 : goto exit;
9529 : : }
9530 [ # # ]: 0 : if (!_Py_Uid_Converter(args[2], &suid)) {
9531 : 0 : goto exit;
9532 : : }
9533 : 0 : return_value = os_setresuid_impl(module, ruid, euid, suid);
9534 : :
9535 : 0 : exit:
9536 : 0 : return return_value;
9537 : : }
9538 : :
9539 : : #endif /* defined(HAVE_SETRESUID) */
9540 : :
9541 : : #if defined(HAVE_SETRESGID)
9542 : :
9543 : : PyDoc_STRVAR(os_setresgid__doc__,
9544 : : "setresgid($module, rgid, egid, sgid, /)\n"
9545 : : "--\n"
9546 : : "\n"
9547 : : "Set the current process\'s real, effective, and saved group ids.");
9548 : :
9549 : : #define OS_SETRESGID_METHODDEF \
9550 : : {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
9551 : :
9552 : : static PyObject *
9553 : : os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
9554 : :
9555 : : static PyObject *
9556 : 0 : os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
9557 : : {
9558 : 0 : PyObject *return_value = NULL;
9559 : : gid_t rgid;
9560 : : gid_t egid;
9561 : : gid_t sgid;
9562 : :
9563 [ # # # # : 0 : if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
# # ]
9564 : 0 : goto exit;
9565 : : }
9566 [ # # ]: 0 : if (!_Py_Gid_Converter(args[0], &rgid)) {
9567 : 0 : goto exit;
9568 : : }
9569 [ # # ]: 0 : if (!_Py_Gid_Converter(args[1], &egid)) {
9570 : 0 : goto exit;
9571 : : }
9572 [ # # ]: 0 : if (!_Py_Gid_Converter(args[2], &sgid)) {
9573 : 0 : goto exit;
9574 : : }
9575 : 0 : return_value = os_setresgid_impl(module, rgid, egid, sgid);
9576 : :
9577 : 0 : exit:
9578 : 0 : return return_value;
9579 : : }
9580 : :
9581 : : #endif /* defined(HAVE_SETRESGID) */
9582 : :
9583 : : #if defined(HAVE_GETRESUID)
9584 : :
9585 : : PyDoc_STRVAR(os_getresuid__doc__,
9586 : : "getresuid($module, /)\n"
9587 : : "--\n"
9588 : : "\n"
9589 : : "Return a tuple of the current process\'s real, effective, and saved user ids.");
9590 : :
9591 : : #define OS_GETRESUID_METHODDEF \
9592 : : {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
9593 : :
9594 : : static PyObject *
9595 : : os_getresuid_impl(PyObject *module);
9596 : :
9597 : : static PyObject *
9598 : 0 : os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
9599 : : {
9600 : 0 : return os_getresuid_impl(module);
9601 : : }
9602 : :
9603 : : #endif /* defined(HAVE_GETRESUID) */
9604 : :
9605 : : #if defined(HAVE_GETRESGID)
9606 : :
9607 : : PyDoc_STRVAR(os_getresgid__doc__,
9608 : : "getresgid($module, /)\n"
9609 : : "--\n"
9610 : : "\n"
9611 : : "Return a tuple of the current process\'s real, effective, and saved group ids.");
9612 : :
9613 : : #define OS_GETRESGID_METHODDEF \
9614 : : {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
9615 : :
9616 : : static PyObject *
9617 : : os_getresgid_impl(PyObject *module);
9618 : :
9619 : : static PyObject *
9620 : 0 : os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
9621 : : {
9622 : 0 : return os_getresgid_impl(module);
9623 : : }
9624 : :
9625 : : #endif /* defined(HAVE_GETRESGID) */
9626 : :
9627 : : #if defined(USE_XATTRS)
9628 : :
9629 : : PyDoc_STRVAR(os_getxattr__doc__,
9630 : : "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
9631 : : "--\n"
9632 : : "\n"
9633 : : "Return the value of extended attribute attribute on path.\n"
9634 : : "\n"
9635 : : "path may be either a string, a path-like object, or an open file descriptor.\n"
9636 : : "If follow_symlinks is False, and the last element of the path is a symbolic\n"
9637 : : " link, getxattr will examine the symbolic link itself instead of the file\n"
9638 : : " the link points to.");
9639 : :
9640 : : #define OS_GETXATTR_METHODDEF \
9641 : : {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
9642 : :
9643 : : static PyObject *
9644 : : os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
9645 : : int follow_symlinks);
9646 : :
9647 : : static PyObject *
9648 : 0 : os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9649 : : {
9650 : 0 : PyObject *return_value = NULL;
9651 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9652 : :
9653 : : #define NUM_KEYWORDS 3
9654 : : static struct {
9655 : : PyGC_Head _this_is_not_used;
9656 : : PyObject_VAR_HEAD
9657 : : PyObject *ob_item[NUM_KEYWORDS];
9658 : : } _kwtuple = {
9659 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9660 : : .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
9661 : : };
9662 : : #undef NUM_KEYWORDS
9663 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9664 : :
9665 : : #else // !Py_BUILD_CORE
9666 : : # define KWTUPLE NULL
9667 : : #endif // !Py_BUILD_CORE
9668 : :
9669 : : static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
9670 : : static _PyArg_Parser _parser = {
9671 : : .keywords = _keywords,
9672 : : .fname = "getxattr",
9673 : : .kwtuple = KWTUPLE,
9674 : : };
9675 : : #undef KWTUPLE
9676 : : PyObject *argsbuf[3];
9677 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
9678 : 0 : path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
9679 : 0 : path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
9680 : 0 : int follow_symlinks = 1;
9681 : :
9682 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
9683 [ # # ]: 0 : if (!args) {
9684 : 0 : goto exit;
9685 : : }
9686 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
9687 : 0 : goto exit;
9688 : : }
9689 [ # # ]: 0 : if (!path_converter(args[1], &attribute)) {
9690 : 0 : goto exit;
9691 : : }
9692 [ # # ]: 0 : if (!noptargs) {
9693 : 0 : goto skip_optional_kwonly;
9694 : : }
9695 : 0 : follow_symlinks = PyObject_IsTrue(args[2]);
9696 [ # # ]: 0 : if (follow_symlinks < 0) {
9697 : 0 : goto exit;
9698 : : }
9699 : 0 : skip_optional_kwonly:
9700 : 0 : return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
9701 : :
9702 : 0 : exit:
9703 : : /* Cleanup for path */
9704 : 0 : path_cleanup(&path);
9705 : : /* Cleanup for attribute */
9706 : 0 : path_cleanup(&attribute);
9707 : :
9708 : 0 : return return_value;
9709 : : }
9710 : :
9711 : : #endif /* defined(USE_XATTRS) */
9712 : :
9713 : : #if defined(USE_XATTRS)
9714 : :
9715 : : PyDoc_STRVAR(os_setxattr__doc__,
9716 : : "setxattr($module, /, path, attribute, value, flags=0, *,\n"
9717 : : " follow_symlinks=True)\n"
9718 : : "--\n"
9719 : : "\n"
9720 : : "Set extended attribute attribute on path to value.\n"
9721 : : "\n"
9722 : : "path may be either a string, a path-like object, or an open file descriptor.\n"
9723 : : "If follow_symlinks is False, and the last element of the path is a symbolic\n"
9724 : : " link, setxattr will modify the symbolic link itself instead of the file\n"
9725 : : " the link points to.");
9726 : :
9727 : : #define OS_SETXATTR_METHODDEF \
9728 : : {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
9729 : :
9730 : : static PyObject *
9731 : : os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
9732 : : Py_buffer *value, int flags, int follow_symlinks);
9733 : :
9734 : : static PyObject *
9735 : 0 : os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9736 : : {
9737 : 0 : PyObject *return_value = NULL;
9738 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9739 : :
9740 : : #define NUM_KEYWORDS 5
9741 : : static struct {
9742 : : PyGC_Head _this_is_not_used;
9743 : : PyObject_VAR_HEAD
9744 : : PyObject *ob_item[NUM_KEYWORDS];
9745 : : } _kwtuple = {
9746 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9747 : : .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
9748 : : };
9749 : : #undef NUM_KEYWORDS
9750 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9751 : :
9752 : : #else // !Py_BUILD_CORE
9753 : : # define KWTUPLE NULL
9754 : : #endif // !Py_BUILD_CORE
9755 : :
9756 : : static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
9757 : : static _PyArg_Parser _parser = {
9758 : : .keywords = _keywords,
9759 : : .fname = "setxattr",
9760 : : .kwtuple = KWTUPLE,
9761 : : };
9762 : : #undef KWTUPLE
9763 : : PyObject *argsbuf[5];
9764 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
9765 : 0 : path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
9766 : 0 : path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
9767 : 0 : Py_buffer value = {NULL, NULL};
9768 : 0 : int flags = 0;
9769 : 0 : int follow_symlinks = 1;
9770 : :
9771 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
# # # # ]
9772 [ # # ]: 0 : if (!args) {
9773 : 0 : goto exit;
9774 : : }
9775 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
9776 : 0 : goto exit;
9777 : : }
9778 [ # # ]: 0 : if (!path_converter(args[1], &attribute)) {
9779 : 0 : goto exit;
9780 : : }
9781 [ # # ]: 0 : if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
9782 : 0 : goto exit;
9783 : : }
9784 [ # # ]: 0 : if (!PyBuffer_IsContiguous(&value, 'C')) {
9785 : 0 : _PyArg_BadArgument("setxattr", "argument 'value'", "contiguous buffer", args[2]);
9786 : 0 : goto exit;
9787 : : }
9788 [ # # ]: 0 : if (!noptargs) {
9789 : 0 : goto skip_optional_pos;
9790 : : }
9791 [ # # ]: 0 : if (args[3]) {
9792 : 0 : flags = _PyLong_AsInt(args[3]);
9793 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
9794 : 0 : goto exit;
9795 : : }
9796 [ # # ]: 0 : if (!--noptargs) {
9797 : 0 : goto skip_optional_pos;
9798 : : }
9799 : : }
9800 : 0 : skip_optional_pos:
9801 [ # # ]: 0 : if (!noptargs) {
9802 : 0 : goto skip_optional_kwonly;
9803 : : }
9804 : 0 : follow_symlinks = PyObject_IsTrue(args[4]);
9805 [ # # ]: 0 : if (follow_symlinks < 0) {
9806 : 0 : goto exit;
9807 : : }
9808 : 0 : skip_optional_kwonly:
9809 : 0 : return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
9810 : :
9811 : 0 : exit:
9812 : : /* Cleanup for path */
9813 : 0 : path_cleanup(&path);
9814 : : /* Cleanup for attribute */
9815 : 0 : path_cleanup(&attribute);
9816 : : /* Cleanup for value */
9817 [ # # ]: 0 : if (value.obj) {
9818 : 0 : PyBuffer_Release(&value);
9819 : : }
9820 : :
9821 : 0 : return return_value;
9822 : : }
9823 : :
9824 : : #endif /* defined(USE_XATTRS) */
9825 : :
9826 : : #if defined(USE_XATTRS)
9827 : :
9828 : : PyDoc_STRVAR(os_removexattr__doc__,
9829 : : "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
9830 : : "--\n"
9831 : : "\n"
9832 : : "Remove extended attribute attribute on path.\n"
9833 : : "\n"
9834 : : "path may be either a string, a path-like object, or an open file descriptor.\n"
9835 : : "If follow_symlinks is False, and the last element of the path is a symbolic\n"
9836 : : " link, removexattr will modify the symbolic link itself instead of the file\n"
9837 : : " the link points to.");
9838 : :
9839 : : #define OS_REMOVEXATTR_METHODDEF \
9840 : : {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
9841 : :
9842 : : static PyObject *
9843 : : os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
9844 : : int follow_symlinks);
9845 : :
9846 : : static PyObject *
9847 : 0 : os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9848 : : {
9849 : 0 : PyObject *return_value = NULL;
9850 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9851 : :
9852 : : #define NUM_KEYWORDS 3
9853 : : static struct {
9854 : : PyGC_Head _this_is_not_used;
9855 : : PyObject_VAR_HEAD
9856 : : PyObject *ob_item[NUM_KEYWORDS];
9857 : : } _kwtuple = {
9858 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9859 : : .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
9860 : : };
9861 : : #undef NUM_KEYWORDS
9862 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9863 : :
9864 : : #else // !Py_BUILD_CORE
9865 : : # define KWTUPLE NULL
9866 : : #endif // !Py_BUILD_CORE
9867 : :
9868 : : static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
9869 : : static _PyArg_Parser _parser = {
9870 : : .keywords = _keywords,
9871 : : .fname = "removexattr",
9872 : : .kwtuple = KWTUPLE,
9873 : : };
9874 : : #undef KWTUPLE
9875 : : PyObject *argsbuf[3];
9876 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
9877 : 0 : path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
9878 : 0 : path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
9879 : 0 : int follow_symlinks = 1;
9880 : :
9881 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
9882 [ # # ]: 0 : if (!args) {
9883 : 0 : goto exit;
9884 : : }
9885 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
9886 : 0 : goto exit;
9887 : : }
9888 [ # # ]: 0 : if (!path_converter(args[1], &attribute)) {
9889 : 0 : goto exit;
9890 : : }
9891 [ # # ]: 0 : if (!noptargs) {
9892 : 0 : goto skip_optional_kwonly;
9893 : : }
9894 : 0 : follow_symlinks = PyObject_IsTrue(args[2]);
9895 [ # # ]: 0 : if (follow_symlinks < 0) {
9896 : 0 : goto exit;
9897 : : }
9898 : 0 : skip_optional_kwonly:
9899 : 0 : return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
9900 : :
9901 : 0 : exit:
9902 : : /* Cleanup for path */
9903 : 0 : path_cleanup(&path);
9904 : : /* Cleanup for attribute */
9905 : 0 : path_cleanup(&attribute);
9906 : :
9907 : 0 : return return_value;
9908 : : }
9909 : :
9910 : : #endif /* defined(USE_XATTRS) */
9911 : :
9912 : : #if defined(USE_XATTRS)
9913 : :
9914 : : PyDoc_STRVAR(os_listxattr__doc__,
9915 : : "listxattr($module, /, path=None, *, follow_symlinks=True)\n"
9916 : : "--\n"
9917 : : "\n"
9918 : : "Return a list of extended attributes on path.\n"
9919 : : "\n"
9920 : : "path may be either None, a string, a path-like object, or an open file descriptor.\n"
9921 : : "if path is None, listxattr will examine the current directory.\n"
9922 : : "If follow_symlinks is False, and the last element of the path is a symbolic\n"
9923 : : " link, listxattr will examine the symbolic link itself instead of the file\n"
9924 : : " the link points to.");
9925 : :
9926 : : #define OS_LISTXATTR_METHODDEF \
9927 : : {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
9928 : :
9929 : : static PyObject *
9930 : : os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
9931 : :
9932 : : static PyObject *
9933 : 0 : os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
9934 : : {
9935 : 0 : PyObject *return_value = NULL;
9936 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
9937 : :
9938 : : #define NUM_KEYWORDS 2
9939 : : static struct {
9940 : : PyGC_Head _this_is_not_used;
9941 : : PyObject_VAR_HEAD
9942 : : PyObject *ob_item[NUM_KEYWORDS];
9943 : : } _kwtuple = {
9944 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
9945 : : .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
9946 : : };
9947 : : #undef NUM_KEYWORDS
9948 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
9949 : :
9950 : : #else // !Py_BUILD_CORE
9951 : : # define KWTUPLE NULL
9952 : : #endif // !Py_BUILD_CORE
9953 : :
9954 : : static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
9955 : : static _PyArg_Parser _parser = {
9956 : : .keywords = _keywords,
9957 : : .fname = "listxattr",
9958 : : .kwtuple = KWTUPLE,
9959 : : };
9960 : : #undef KWTUPLE
9961 : : PyObject *argsbuf[2];
9962 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
9963 : 0 : path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
9964 : 0 : int follow_symlinks = 1;
9965 : :
9966 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
9967 [ # # ]: 0 : if (!args) {
9968 : 0 : goto exit;
9969 : : }
9970 [ # # ]: 0 : if (!noptargs) {
9971 : 0 : goto skip_optional_pos;
9972 : : }
9973 [ # # ]: 0 : if (args[0]) {
9974 [ # # ]: 0 : if (!path_converter(args[0], &path)) {
9975 : 0 : goto exit;
9976 : : }
9977 [ # # ]: 0 : if (!--noptargs) {
9978 : 0 : goto skip_optional_pos;
9979 : : }
9980 : : }
9981 : 0 : skip_optional_pos:
9982 [ # # ]: 0 : if (!noptargs) {
9983 : 0 : goto skip_optional_kwonly;
9984 : : }
9985 : 0 : follow_symlinks = PyObject_IsTrue(args[1]);
9986 [ # # ]: 0 : if (follow_symlinks < 0) {
9987 : 0 : goto exit;
9988 : : }
9989 : 0 : skip_optional_kwonly:
9990 : 0 : return_value = os_listxattr_impl(module, &path, follow_symlinks);
9991 : :
9992 : 0 : exit:
9993 : : /* Cleanup for path */
9994 : 0 : path_cleanup(&path);
9995 : :
9996 : 0 : return return_value;
9997 : : }
9998 : :
9999 : : #endif /* defined(USE_XATTRS) */
10000 : :
10001 : : PyDoc_STRVAR(os_urandom__doc__,
10002 : : "urandom($module, size, /)\n"
10003 : : "--\n"
10004 : : "\n"
10005 : : "Return a bytes object containing random bytes suitable for cryptographic use.");
10006 : :
10007 : : #define OS_URANDOM_METHODDEF \
10008 : : {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
10009 : :
10010 : : static PyObject *
10011 : : os_urandom_impl(PyObject *module, Py_ssize_t size);
10012 : :
10013 : : static PyObject *
10014 : 0 : os_urandom(PyObject *module, PyObject *arg)
10015 : : {
10016 : 0 : PyObject *return_value = NULL;
10017 : : Py_ssize_t size;
10018 : :
10019 : : {
10020 : 0 : Py_ssize_t ival = -1;
10021 : 0 : PyObject *iobj = _PyNumber_Index(arg);
10022 [ # # ]: 0 : if (iobj != NULL) {
10023 : 0 : ival = PyLong_AsSsize_t(iobj);
10024 : 0 : Py_DECREF(iobj);
10025 : : }
10026 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
10027 : 0 : goto exit;
10028 : : }
10029 : 0 : size = ival;
10030 : : }
10031 : 0 : return_value = os_urandom_impl(module, size);
10032 : :
10033 : 0 : exit:
10034 : 0 : return return_value;
10035 : : }
10036 : :
10037 : : #if defined(HAVE_MEMFD_CREATE)
10038 : :
10039 : : PyDoc_STRVAR(os_memfd_create__doc__,
10040 : : "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
10041 : : "--\n"
10042 : : "\n");
10043 : :
10044 : : #define OS_MEMFD_CREATE_METHODDEF \
10045 : : {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
10046 : :
10047 : : static PyObject *
10048 : : os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
10049 : :
10050 : : static PyObject *
10051 : 0 : os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10052 : : {
10053 : 0 : PyObject *return_value = NULL;
10054 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10055 : :
10056 : : #define NUM_KEYWORDS 2
10057 : : static struct {
10058 : : PyGC_Head _this_is_not_used;
10059 : : PyObject_VAR_HEAD
10060 : : PyObject *ob_item[NUM_KEYWORDS];
10061 : : } _kwtuple = {
10062 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10063 : : .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
10064 : : };
10065 : : #undef NUM_KEYWORDS
10066 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10067 : :
10068 : : #else // !Py_BUILD_CORE
10069 : : # define KWTUPLE NULL
10070 : : #endif // !Py_BUILD_CORE
10071 : :
10072 : : static const char * const _keywords[] = {"name", "flags", NULL};
10073 : : static _PyArg_Parser _parser = {
10074 : : .keywords = _keywords,
10075 : : .fname = "memfd_create",
10076 : : .kwtuple = KWTUPLE,
10077 : : };
10078 : : #undef KWTUPLE
10079 : : PyObject *argsbuf[2];
10080 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
10081 : 0 : PyObject *name = NULL;
10082 : 0 : unsigned int flags = MFD_CLOEXEC;
10083 : :
10084 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
10085 [ # # ]: 0 : if (!args) {
10086 : 0 : goto exit;
10087 : : }
10088 [ # # ]: 0 : if (!PyUnicode_FSConverter(args[0], &name)) {
10089 : 0 : goto exit;
10090 : : }
10091 [ # # ]: 0 : if (!noptargs) {
10092 : 0 : goto skip_optional_pos;
10093 : : }
10094 : 0 : flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
10095 [ # # # # ]: 0 : if (flags == (unsigned int)-1 && PyErr_Occurred()) {
10096 : 0 : goto exit;
10097 : : }
10098 : 0 : skip_optional_pos:
10099 : 0 : return_value = os_memfd_create_impl(module, name, flags);
10100 : :
10101 : 0 : exit:
10102 : : /* Cleanup for name */
10103 : 0 : Py_XDECREF(name);
10104 : :
10105 : 0 : return return_value;
10106 : : }
10107 : :
10108 : : #endif /* defined(HAVE_MEMFD_CREATE) */
10109 : :
10110 : : #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
10111 : :
10112 : : PyDoc_STRVAR(os_eventfd__doc__,
10113 : : "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
10114 : : "--\n"
10115 : : "\n"
10116 : : "Creates and returns an event notification file descriptor.");
10117 : :
10118 : : #define OS_EVENTFD_METHODDEF \
10119 : : {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
10120 : :
10121 : : static PyObject *
10122 : : os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
10123 : :
10124 : : static PyObject *
10125 : 0 : os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10126 : : {
10127 : 0 : PyObject *return_value = NULL;
10128 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10129 : :
10130 : : #define NUM_KEYWORDS 2
10131 : : static struct {
10132 : : PyGC_Head _this_is_not_used;
10133 : : PyObject_VAR_HEAD
10134 : : PyObject *ob_item[NUM_KEYWORDS];
10135 : : } _kwtuple = {
10136 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10137 : : .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
10138 : : };
10139 : : #undef NUM_KEYWORDS
10140 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10141 : :
10142 : : #else // !Py_BUILD_CORE
10143 : : # define KWTUPLE NULL
10144 : : #endif // !Py_BUILD_CORE
10145 : :
10146 : : static const char * const _keywords[] = {"initval", "flags", NULL};
10147 : : static _PyArg_Parser _parser = {
10148 : : .keywords = _keywords,
10149 : : .fname = "eventfd",
10150 : : .kwtuple = KWTUPLE,
10151 : : };
10152 : : #undef KWTUPLE
10153 : : PyObject *argsbuf[2];
10154 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
10155 : : unsigned int initval;
10156 : 0 : int flags = EFD_CLOEXEC;
10157 : :
10158 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
10159 [ # # ]: 0 : if (!args) {
10160 : 0 : goto exit;
10161 : : }
10162 [ # # ]: 0 : if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
10163 : 0 : goto exit;
10164 : : }
10165 [ # # ]: 0 : if (!noptargs) {
10166 : 0 : goto skip_optional_pos;
10167 : : }
10168 : 0 : flags = _PyLong_AsInt(args[1]);
10169 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
10170 : 0 : goto exit;
10171 : : }
10172 : 0 : skip_optional_pos:
10173 : 0 : return_value = os_eventfd_impl(module, initval, flags);
10174 : :
10175 : 0 : exit:
10176 : 0 : return return_value;
10177 : : }
10178 : :
10179 : : #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
10180 : :
10181 : : #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
10182 : :
10183 : : PyDoc_STRVAR(os_eventfd_read__doc__,
10184 : : "eventfd_read($module, /, fd)\n"
10185 : : "--\n"
10186 : : "\n"
10187 : : "Read eventfd value");
10188 : :
10189 : : #define OS_EVENTFD_READ_METHODDEF \
10190 : : {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
10191 : :
10192 : : static PyObject *
10193 : : os_eventfd_read_impl(PyObject *module, int fd);
10194 : :
10195 : : static PyObject *
10196 : 0 : os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10197 : : {
10198 : 0 : PyObject *return_value = NULL;
10199 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10200 : :
10201 : : #define NUM_KEYWORDS 1
10202 : : static struct {
10203 : : PyGC_Head _this_is_not_used;
10204 : : PyObject_VAR_HEAD
10205 : : PyObject *ob_item[NUM_KEYWORDS];
10206 : : } _kwtuple = {
10207 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10208 : : .ob_item = { &_Py_ID(fd), },
10209 : : };
10210 : : #undef NUM_KEYWORDS
10211 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10212 : :
10213 : : #else // !Py_BUILD_CORE
10214 : : # define KWTUPLE NULL
10215 : : #endif // !Py_BUILD_CORE
10216 : :
10217 : : static const char * const _keywords[] = {"fd", NULL};
10218 : : static _PyArg_Parser _parser = {
10219 : : .keywords = _keywords,
10220 : : .fname = "eventfd_read",
10221 : : .kwtuple = KWTUPLE,
10222 : : };
10223 : : #undef KWTUPLE
10224 : : PyObject *argsbuf[1];
10225 : : int fd;
10226 : :
10227 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
10228 [ # # ]: 0 : if (!args) {
10229 : 0 : goto exit;
10230 : : }
10231 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
10232 : 0 : goto exit;
10233 : : }
10234 : 0 : return_value = os_eventfd_read_impl(module, fd);
10235 : :
10236 : 0 : exit:
10237 : 0 : return return_value;
10238 : : }
10239 : :
10240 : : #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
10241 : :
10242 : : #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
10243 : :
10244 : : PyDoc_STRVAR(os_eventfd_write__doc__,
10245 : : "eventfd_write($module, /, fd, value)\n"
10246 : : "--\n"
10247 : : "\n"
10248 : : "Write eventfd value.");
10249 : :
10250 : : #define OS_EVENTFD_WRITE_METHODDEF \
10251 : : {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
10252 : :
10253 : : static PyObject *
10254 : : os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
10255 : :
10256 : : static PyObject *
10257 : 0 : os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10258 : : {
10259 : 0 : PyObject *return_value = NULL;
10260 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10261 : :
10262 : : #define NUM_KEYWORDS 2
10263 : : static struct {
10264 : : PyGC_Head _this_is_not_used;
10265 : : PyObject_VAR_HEAD
10266 : : PyObject *ob_item[NUM_KEYWORDS];
10267 : : } _kwtuple = {
10268 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10269 : : .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
10270 : : };
10271 : : #undef NUM_KEYWORDS
10272 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10273 : :
10274 : : #else // !Py_BUILD_CORE
10275 : : # define KWTUPLE NULL
10276 : : #endif // !Py_BUILD_CORE
10277 : :
10278 : : static const char * const _keywords[] = {"fd", "value", NULL};
10279 : : static _PyArg_Parser _parser = {
10280 : : .keywords = _keywords,
10281 : : .fname = "eventfd_write",
10282 : : .kwtuple = KWTUPLE,
10283 : : };
10284 : : #undef KWTUPLE
10285 : : PyObject *argsbuf[2];
10286 : : int fd;
10287 : : unsigned long long value;
10288 : :
10289 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
10290 [ # # ]: 0 : if (!args) {
10291 : 0 : goto exit;
10292 : : }
10293 [ # # ]: 0 : if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
10294 : 0 : goto exit;
10295 : : }
10296 [ # # ]: 0 : if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
10297 : 0 : goto exit;
10298 : : }
10299 : 0 : return_value = os_eventfd_write_impl(module, fd, value);
10300 : :
10301 : 0 : exit:
10302 : 0 : return return_value;
10303 : : }
10304 : :
10305 : : #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
10306 : :
10307 : : #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
10308 : :
10309 : : PyDoc_STRVAR(os_get_terminal_size__doc__,
10310 : : "get_terminal_size($module, fd=<unrepresentable>, /)\n"
10311 : : "--\n"
10312 : : "\n"
10313 : : "Return the size of the terminal window as (columns, lines).\n"
10314 : : "\n"
10315 : : "The optional argument fd (default standard output) specifies\n"
10316 : : "which file descriptor should be queried.\n"
10317 : : "\n"
10318 : : "If the file descriptor is not connected to a terminal, an OSError\n"
10319 : : "is thrown.\n"
10320 : : "\n"
10321 : : "This function will only be defined if an implementation is\n"
10322 : : "available for this system.\n"
10323 : : "\n"
10324 : : "shutil.get_terminal_size is the high-level function which should\n"
10325 : : "normally be used, os.get_terminal_size is the low-level implementation.");
10326 : :
10327 : : #define OS_GET_TERMINAL_SIZE_METHODDEF \
10328 : : {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
10329 : :
10330 : : static PyObject *
10331 : : os_get_terminal_size_impl(PyObject *module, int fd);
10332 : :
10333 : : static PyObject *
10334 : 10 : os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10335 : : {
10336 : 10 : PyObject *return_value = NULL;
10337 : 10 : int fd = fileno(stdout);
10338 : :
10339 [ + - - + : 10 : if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
- - ]
10340 : 0 : goto exit;
10341 : : }
10342 [ - + ]: 10 : if (nargs < 1) {
10343 : 0 : goto skip_optional;
10344 : : }
10345 : 10 : fd = _PyLong_AsInt(args[0]);
10346 [ - + - - ]: 10 : if (fd == -1 && PyErr_Occurred()) {
10347 : 0 : goto exit;
10348 : : }
10349 : 10 : skip_optional:
10350 : 10 : return_value = os_get_terminal_size_impl(module, fd);
10351 : :
10352 : 10 : exit:
10353 : 10 : return return_value;
10354 : : }
10355 : :
10356 : : #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
10357 : :
10358 : : PyDoc_STRVAR(os_cpu_count__doc__,
10359 : : "cpu_count($module, /)\n"
10360 : : "--\n"
10361 : : "\n"
10362 : : "Return the number of CPUs in the system; return None if indeterminable.\n"
10363 : : "\n"
10364 : : "This number is not equivalent to the number of CPUs the current process can\n"
10365 : : "use. The number of usable CPUs can be obtained with\n"
10366 : : "``len(os.sched_getaffinity(0))``");
10367 : :
10368 : : #define OS_CPU_COUNT_METHODDEF \
10369 : : {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
10370 : :
10371 : : static PyObject *
10372 : : os_cpu_count_impl(PyObject *module);
10373 : :
10374 : : static PyObject *
10375 : 0 : os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
10376 : : {
10377 : 0 : return os_cpu_count_impl(module);
10378 : : }
10379 : :
10380 : : PyDoc_STRVAR(os_get_inheritable__doc__,
10381 : : "get_inheritable($module, fd, /)\n"
10382 : : "--\n"
10383 : : "\n"
10384 : : "Get the close-on-exe flag of the specified file descriptor.");
10385 : :
10386 : : #define OS_GET_INHERITABLE_METHODDEF \
10387 : : {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
10388 : :
10389 : : static int
10390 : : os_get_inheritable_impl(PyObject *module, int fd);
10391 : :
10392 : : static PyObject *
10393 : 0 : os_get_inheritable(PyObject *module, PyObject *arg)
10394 : : {
10395 : 0 : PyObject *return_value = NULL;
10396 : : int fd;
10397 : : int _return_value;
10398 : :
10399 : 0 : fd = _PyLong_AsInt(arg);
10400 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
10401 : 0 : goto exit;
10402 : : }
10403 : 0 : _return_value = os_get_inheritable_impl(module, fd);
10404 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
10405 : 0 : goto exit;
10406 : : }
10407 : 0 : return_value = PyBool_FromLong((long)_return_value);
10408 : :
10409 : 0 : exit:
10410 : 0 : return return_value;
10411 : : }
10412 : :
10413 : : PyDoc_STRVAR(os_set_inheritable__doc__,
10414 : : "set_inheritable($module, fd, inheritable, /)\n"
10415 : : "--\n"
10416 : : "\n"
10417 : : "Set the inheritable flag of the specified file descriptor.");
10418 : :
10419 : : #define OS_SET_INHERITABLE_METHODDEF \
10420 : : {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
10421 : :
10422 : : static PyObject *
10423 : : os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
10424 : :
10425 : : static PyObject *
10426 : 0 : os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10427 : : {
10428 : 0 : PyObject *return_value = NULL;
10429 : : int fd;
10430 : : int inheritable;
10431 : :
10432 [ # # # # : 0 : if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
# # ]
10433 : 0 : goto exit;
10434 : : }
10435 : 0 : fd = _PyLong_AsInt(args[0]);
10436 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
10437 : 0 : goto exit;
10438 : : }
10439 : 0 : inheritable = _PyLong_AsInt(args[1]);
10440 [ # # # # ]: 0 : if (inheritable == -1 && PyErr_Occurred()) {
10441 : 0 : goto exit;
10442 : : }
10443 : 0 : return_value = os_set_inheritable_impl(module, fd, inheritable);
10444 : :
10445 : 0 : exit:
10446 : 0 : return return_value;
10447 : : }
10448 : :
10449 : : #if defined(MS_WINDOWS)
10450 : :
10451 : : PyDoc_STRVAR(os_get_handle_inheritable__doc__,
10452 : : "get_handle_inheritable($module, handle, /)\n"
10453 : : "--\n"
10454 : : "\n"
10455 : : "Get the close-on-exe flag of the specified file descriptor.");
10456 : :
10457 : : #define OS_GET_HANDLE_INHERITABLE_METHODDEF \
10458 : : {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
10459 : :
10460 : : static int
10461 : : os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
10462 : :
10463 : : static PyObject *
10464 : : os_get_handle_inheritable(PyObject *module, PyObject *arg)
10465 : : {
10466 : : PyObject *return_value = NULL;
10467 : : intptr_t handle;
10468 : : int _return_value;
10469 : :
10470 : : if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
10471 : : goto exit;
10472 : : }
10473 : : _return_value = os_get_handle_inheritable_impl(module, handle);
10474 : : if ((_return_value == -1) && PyErr_Occurred()) {
10475 : : goto exit;
10476 : : }
10477 : : return_value = PyBool_FromLong((long)_return_value);
10478 : :
10479 : : exit:
10480 : : return return_value;
10481 : : }
10482 : :
10483 : : #endif /* defined(MS_WINDOWS) */
10484 : :
10485 : : #if defined(MS_WINDOWS)
10486 : :
10487 : : PyDoc_STRVAR(os_set_handle_inheritable__doc__,
10488 : : "set_handle_inheritable($module, handle, inheritable, /)\n"
10489 : : "--\n"
10490 : : "\n"
10491 : : "Set the inheritable flag of the specified handle.");
10492 : :
10493 : : #define OS_SET_HANDLE_INHERITABLE_METHODDEF \
10494 : : {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
10495 : :
10496 : : static PyObject *
10497 : : os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
10498 : : int inheritable);
10499 : :
10500 : : static PyObject *
10501 : : os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10502 : : {
10503 : : PyObject *return_value = NULL;
10504 : : intptr_t handle;
10505 : : int inheritable;
10506 : :
10507 : : if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
10508 : : &handle, &inheritable)) {
10509 : : goto exit;
10510 : : }
10511 : : return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
10512 : :
10513 : : exit:
10514 : : return return_value;
10515 : : }
10516 : :
10517 : : #endif /* defined(MS_WINDOWS) */
10518 : :
10519 : : PyDoc_STRVAR(os_get_blocking__doc__,
10520 : : "get_blocking($module, fd, /)\n"
10521 : : "--\n"
10522 : : "\n"
10523 : : "Get the blocking mode of the file descriptor.\n"
10524 : : "\n"
10525 : : "Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
10526 : :
10527 : : #define OS_GET_BLOCKING_METHODDEF \
10528 : : {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
10529 : :
10530 : : static int
10531 : : os_get_blocking_impl(PyObject *module, int fd);
10532 : :
10533 : : static PyObject *
10534 : 0 : os_get_blocking(PyObject *module, PyObject *arg)
10535 : : {
10536 : 0 : PyObject *return_value = NULL;
10537 : : int fd;
10538 : : int _return_value;
10539 : :
10540 : 0 : fd = _PyLong_AsInt(arg);
10541 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
10542 : 0 : goto exit;
10543 : : }
10544 : 0 : _return_value = os_get_blocking_impl(module, fd);
10545 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
10546 : 0 : goto exit;
10547 : : }
10548 : 0 : return_value = PyBool_FromLong((long)_return_value);
10549 : :
10550 : 0 : exit:
10551 : 0 : return return_value;
10552 : : }
10553 : :
10554 : : PyDoc_STRVAR(os_set_blocking__doc__,
10555 : : "set_blocking($module, fd, blocking, /)\n"
10556 : : "--\n"
10557 : : "\n"
10558 : : "Set the blocking mode of the specified file descriptor.\n"
10559 : : "\n"
10560 : : "Set the O_NONBLOCK flag if blocking is False,\n"
10561 : : "clear the O_NONBLOCK flag otherwise.");
10562 : :
10563 : : #define OS_SET_BLOCKING_METHODDEF \
10564 : : {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
10565 : :
10566 : : static PyObject *
10567 : : os_set_blocking_impl(PyObject *module, int fd, int blocking);
10568 : :
10569 : : static PyObject *
10570 : 0 : os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
10571 : : {
10572 : 0 : PyObject *return_value = NULL;
10573 : : int fd;
10574 : : int blocking;
10575 : :
10576 [ # # # # : 0 : if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
# # ]
10577 : 0 : goto exit;
10578 : : }
10579 : 0 : fd = _PyLong_AsInt(args[0]);
10580 [ # # # # ]: 0 : if (fd == -1 && PyErr_Occurred()) {
10581 : 0 : goto exit;
10582 : : }
10583 : 0 : blocking = PyObject_IsTrue(args[1]);
10584 [ # # ]: 0 : if (blocking < 0) {
10585 : 0 : goto exit;
10586 : : }
10587 : 0 : return_value = os_set_blocking_impl(module, fd, blocking);
10588 : :
10589 : 0 : exit:
10590 : 0 : return return_value;
10591 : : }
10592 : :
10593 : : PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
10594 : : "is_symlink($self, /)\n"
10595 : : "--\n"
10596 : : "\n"
10597 : : "Return True if the entry is a symbolic link; cached per entry.");
10598 : :
10599 : : #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
10600 : : {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
10601 : :
10602 : : static int
10603 : : os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
10604 : :
10605 : : static PyObject *
10606 : 0 : os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10607 : : {
10608 : 0 : PyObject *return_value = NULL;
10609 : : int _return_value;
10610 : :
10611 [ # # ]: 0 : if (nargs) {
10612 : 0 : PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
10613 : 0 : goto exit;
10614 : : }
10615 : 0 : _return_value = os_DirEntry_is_symlink_impl(self, defining_class);
10616 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
10617 : 0 : goto exit;
10618 : : }
10619 : 0 : return_value = PyBool_FromLong((long)_return_value);
10620 : :
10621 : 0 : exit:
10622 : 0 : return return_value;
10623 : : }
10624 : :
10625 : : PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
10626 : : "is_junction($self, /)\n"
10627 : : "--\n"
10628 : : "\n"
10629 : : "Return True if the entry is a junction; cached per entry.");
10630 : :
10631 : : #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \
10632 : : {"is_junction", _PyCFunction_CAST(os_DirEntry_is_junction), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_junction__doc__},
10633 : :
10634 : : static int
10635 : : os_DirEntry_is_junction_impl(DirEntry *self, PyTypeObject *defining_class);
10636 : :
10637 : : static PyObject *
10638 : 0 : os_DirEntry_is_junction(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10639 : : {
10640 : 0 : PyObject *return_value = NULL;
10641 : : int _return_value;
10642 : :
10643 [ # # ]: 0 : if (nargs) {
10644 : 0 : PyErr_SetString(PyExc_TypeError, "is_junction() takes no arguments");
10645 : 0 : goto exit;
10646 : : }
10647 : 0 : _return_value = os_DirEntry_is_junction_impl(self, defining_class);
10648 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
10649 : 0 : goto exit;
10650 : : }
10651 : 0 : return_value = PyBool_FromLong((long)_return_value);
10652 : :
10653 : 0 : exit:
10654 : 0 : return return_value;
10655 : : }
10656 : :
10657 : : PyDoc_STRVAR(os_DirEntry_stat__doc__,
10658 : : "stat($self, /, *, follow_symlinks=True)\n"
10659 : : "--\n"
10660 : : "\n"
10661 : : "Return stat_result object for the entry; cached per entry.");
10662 : :
10663 : : #define OS_DIRENTRY_STAT_METHODDEF \
10664 : : {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
10665 : :
10666 : : static PyObject *
10667 : : os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
10668 : : int follow_symlinks);
10669 : :
10670 : : static PyObject *
10671 : 0 : os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10672 : : {
10673 : 0 : PyObject *return_value = NULL;
10674 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10675 : :
10676 : : #define NUM_KEYWORDS 1
10677 : : static struct {
10678 : : PyGC_Head _this_is_not_used;
10679 : : PyObject_VAR_HEAD
10680 : : PyObject *ob_item[NUM_KEYWORDS];
10681 : : } _kwtuple = {
10682 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10683 : : .ob_item = { &_Py_ID(follow_symlinks), },
10684 : : };
10685 : : #undef NUM_KEYWORDS
10686 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10687 : :
10688 : : #else // !Py_BUILD_CORE
10689 : : # define KWTUPLE NULL
10690 : : #endif // !Py_BUILD_CORE
10691 : :
10692 : : static const char * const _keywords[] = {"follow_symlinks", NULL};
10693 : : static _PyArg_Parser _parser = {
10694 : : .keywords = _keywords,
10695 : : .fname = "stat",
10696 : : .kwtuple = KWTUPLE,
10697 : : };
10698 : : #undef KWTUPLE
10699 : : PyObject *argsbuf[1];
10700 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
10701 : 0 : int follow_symlinks = 1;
10702 : :
10703 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
# # # # ]
10704 [ # # ]: 0 : if (!args) {
10705 : 0 : goto exit;
10706 : : }
10707 [ # # ]: 0 : if (!noptargs) {
10708 : 0 : goto skip_optional_kwonly;
10709 : : }
10710 : 0 : follow_symlinks = PyObject_IsTrue(args[0]);
10711 [ # # ]: 0 : if (follow_symlinks < 0) {
10712 : 0 : goto exit;
10713 : : }
10714 : 0 : skip_optional_kwonly:
10715 : 0 : return_value = os_DirEntry_stat_impl(self, defining_class, follow_symlinks);
10716 : :
10717 : 0 : exit:
10718 : 0 : return return_value;
10719 : : }
10720 : :
10721 : : PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
10722 : : "is_dir($self, /, *, follow_symlinks=True)\n"
10723 : : "--\n"
10724 : : "\n"
10725 : : "Return True if the entry is a directory; cached per entry.");
10726 : :
10727 : : #define OS_DIRENTRY_IS_DIR_METHODDEF \
10728 : : {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
10729 : :
10730 : : static int
10731 : : os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
10732 : : int follow_symlinks);
10733 : :
10734 : : static PyObject *
10735 : 1540 : os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10736 : : {
10737 : 1540 : PyObject *return_value = NULL;
10738 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10739 : :
10740 : : #define NUM_KEYWORDS 1
10741 : : static struct {
10742 : : PyGC_Head _this_is_not_used;
10743 : : PyObject_VAR_HEAD
10744 : : PyObject *ob_item[NUM_KEYWORDS];
10745 : : } _kwtuple = {
10746 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10747 : : .ob_item = { &_Py_ID(follow_symlinks), },
10748 : : };
10749 : : #undef NUM_KEYWORDS
10750 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10751 : :
10752 : : #else // !Py_BUILD_CORE
10753 : : # define KWTUPLE NULL
10754 : : #endif // !Py_BUILD_CORE
10755 : :
10756 : : static const char * const _keywords[] = {"follow_symlinks", NULL};
10757 : : static _PyArg_Parser _parser = {
10758 : : .keywords = _keywords,
10759 : : .fname = "is_dir",
10760 : : .kwtuple = KWTUPLE,
10761 : : };
10762 : : #undef KWTUPLE
10763 : : PyObject *argsbuf[1];
10764 [ - + ]: 1540 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
10765 : 1540 : int follow_symlinks = 1;
10766 : : int _return_value;
10767 : :
10768 [ + - + - : 1540 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
+ - - + ]
10769 [ - + ]: 1540 : if (!args) {
10770 : 0 : goto exit;
10771 : : }
10772 [ + - ]: 1540 : if (!noptargs) {
10773 : 1540 : goto skip_optional_kwonly;
10774 : : }
10775 : 0 : follow_symlinks = PyObject_IsTrue(args[0]);
10776 [ # # ]: 0 : if (follow_symlinks < 0) {
10777 : 0 : goto exit;
10778 : : }
10779 : 0 : skip_optional_kwonly:
10780 : 1540 : _return_value = os_DirEntry_is_dir_impl(self, defining_class, follow_symlinks);
10781 [ - + - - ]: 1540 : if ((_return_value == -1) && PyErr_Occurred()) {
10782 : 0 : goto exit;
10783 : : }
10784 : 1540 : return_value = PyBool_FromLong((long)_return_value);
10785 : :
10786 : 1540 : exit:
10787 : 1540 : return return_value;
10788 : : }
10789 : :
10790 : : PyDoc_STRVAR(os_DirEntry_is_file__doc__,
10791 : : "is_file($self, /, *, follow_symlinks=True)\n"
10792 : : "--\n"
10793 : : "\n"
10794 : : "Return True if the entry is a file; cached per entry.");
10795 : :
10796 : : #define OS_DIRENTRY_IS_FILE_METHODDEF \
10797 : : {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
10798 : :
10799 : : static int
10800 : : os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
10801 : : int follow_symlinks);
10802 : :
10803 : : static PyObject *
10804 : 0 : os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10805 : : {
10806 : 0 : PyObject *return_value = NULL;
10807 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10808 : :
10809 : : #define NUM_KEYWORDS 1
10810 : : static struct {
10811 : : PyGC_Head _this_is_not_used;
10812 : : PyObject_VAR_HEAD
10813 : : PyObject *ob_item[NUM_KEYWORDS];
10814 : : } _kwtuple = {
10815 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10816 : : .ob_item = { &_Py_ID(follow_symlinks), },
10817 : : };
10818 : : #undef NUM_KEYWORDS
10819 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10820 : :
10821 : : #else // !Py_BUILD_CORE
10822 : : # define KWTUPLE NULL
10823 : : #endif // !Py_BUILD_CORE
10824 : :
10825 : : static const char * const _keywords[] = {"follow_symlinks", NULL};
10826 : : static _PyArg_Parser _parser = {
10827 : : .keywords = _keywords,
10828 : : .fname = "is_file",
10829 : : .kwtuple = KWTUPLE,
10830 : : };
10831 : : #undef KWTUPLE
10832 : : PyObject *argsbuf[1];
10833 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
10834 : 0 : int follow_symlinks = 1;
10835 : : int _return_value;
10836 : :
10837 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
# # # # ]
10838 [ # # ]: 0 : if (!args) {
10839 : 0 : goto exit;
10840 : : }
10841 [ # # ]: 0 : if (!noptargs) {
10842 : 0 : goto skip_optional_kwonly;
10843 : : }
10844 : 0 : follow_symlinks = PyObject_IsTrue(args[0]);
10845 [ # # ]: 0 : if (follow_symlinks < 0) {
10846 : 0 : goto exit;
10847 : : }
10848 : 0 : skip_optional_kwonly:
10849 : 0 : _return_value = os_DirEntry_is_file_impl(self, defining_class, follow_symlinks);
10850 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
10851 : 0 : goto exit;
10852 : : }
10853 : 0 : return_value = PyBool_FromLong((long)_return_value);
10854 : :
10855 : 0 : exit:
10856 : 0 : return return_value;
10857 : : }
10858 : :
10859 : : PyDoc_STRVAR(os_DirEntry_inode__doc__,
10860 : : "inode($self, /)\n"
10861 : : "--\n"
10862 : : "\n"
10863 : : "Return inode of the entry; cached per entry.");
10864 : :
10865 : : #define OS_DIRENTRY_INODE_METHODDEF \
10866 : : {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
10867 : :
10868 : : static PyObject *
10869 : : os_DirEntry_inode_impl(DirEntry *self);
10870 : :
10871 : : static PyObject *
10872 : 0 : os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
10873 : : {
10874 : 0 : return os_DirEntry_inode_impl(self);
10875 : : }
10876 : :
10877 : : PyDoc_STRVAR(os_DirEntry___fspath____doc__,
10878 : : "__fspath__($self, /)\n"
10879 : : "--\n"
10880 : : "\n"
10881 : : "Returns the path for the entry.");
10882 : :
10883 : : #define OS_DIRENTRY___FSPATH___METHODDEF \
10884 : : {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
10885 : :
10886 : : static PyObject *
10887 : : os_DirEntry___fspath___impl(DirEntry *self);
10888 : :
10889 : : static PyObject *
10890 : 0 : os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
10891 : : {
10892 : 0 : return os_DirEntry___fspath___impl(self);
10893 : : }
10894 : :
10895 : : PyDoc_STRVAR(os_scandir__doc__,
10896 : : "scandir($module, /, path=None)\n"
10897 : : "--\n"
10898 : : "\n"
10899 : : "Return an iterator of DirEntry objects for given path.\n"
10900 : : "\n"
10901 : : "path can be specified as either str, bytes, or a path-like object. If path\n"
10902 : : "is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
10903 : : "all other circumstances they will be str.\n"
10904 : : "\n"
10905 : : "If path is None, uses the path=\'.\'.");
10906 : :
10907 : : #define OS_SCANDIR_METHODDEF \
10908 : : {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
10909 : :
10910 : : static PyObject *
10911 : : os_scandir_impl(PyObject *module, path_t *path);
10912 : :
10913 : : static PyObject *
10914 : 55 : os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10915 : : {
10916 : 55 : PyObject *return_value = NULL;
10917 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10918 : :
10919 : : #define NUM_KEYWORDS 1
10920 : : static struct {
10921 : : PyGC_Head _this_is_not_used;
10922 : : PyObject_VAR_HEAD
10923 : : PyObject *ob_item[NUM_KEYWORDS];
10924 : : } _kwtuple = {
10925 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10926 : : .ob_item = { &_Py_ID(path), },
10927 : : };
10928 : : #undef NUM_KEYWORDS
10929 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10930 : :
10931 : : #else // !Py_BUILD_CORE
10932 : : # define KWTUPLE NULL
10933 : : #endif // !Py_BUILD_CORE
10934 : :
10935 : : static const char * const _keywords[] = {"path", NULL};
10936 : : static _PyArg_Parser _parser = {
10937 : : .keywords = _keywords,
10938 : : .fname = "scandir",
10939 : : .kwtuple = KWTUPLE,
10940 : : };
10941 : : #undef KWTUPLE
10942 : : PyObject *argsbuf[1];
10943 [ - + ]: 55 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
10944 : 55 : path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
10945 : :
10946 [ + - + - : 55 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
+ - - + ]
10947 [ - + ]: 55 : if (!args) {
10948 : 0 : goto exit;
10949 : : }
10950 [ - + ]: 55 : if (!noptargs) {
10951 : 0 : goto skip_optional_pos;
10952 : : }
10953 [ - + ]: 55 : if (!path_converter(args[0], &path)) {
10954 : 0 : goto exit;
10955 : : }
10956 : 55 : skip_optional_pos:
10957 : 55 : return_value = os_scandir_impl(module, &path);
10958 : :
10959 : 55 : exit:
10960 : : /* Cleanup for path */
10961 : 55 : path_cleanup(&path);
10962 : :
10963 : 55 : return return_value;
10964 : : }
10965 : :
10966 : : PyDoc_STRVAR(os_fspath__doc__,
10967 : : "fspath($module, /, path)\n"
10968 : : "--\n"
10969 : : "\n"
10970 : : "Return the file system path representation of the object.\n"
10971 : : "\n"
10972 : : "If the object is str or bytes, then allow it to pass through as-is. If the\n"
10973 : : "object defines __fspath__(), then return the result of that method. All other\n"
10974 : : "types raise a TypeError.");
10975 : :
10976 : : #define OS_FSPATH_METHODDEF \
10977 : : {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
10978 : :
10979 : : static PyObject *
10980 : : os_fspath_impl(PyObject *module, PyObject *path);
10981 : :
10982 : : static PyObject *
10983 : 6021 : os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
10984 : : {
10985 : 6021 : PyObject *return_value = NULL;
10986 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
10987 : :
10988 : : #define NUM_KEYWORDS 1
10989 : : static struct {
10990 : : PyGC_Head _this_is_not_used;
10991 : : PyObject_VAR_HEAD
10992 : : PyObject *ob_item[NUM_KEYWORDS];
10993 : : } _kwtuple = {
10994 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
10995 : : .ob_item = { &_Py_ID(path), },
10996 : : };
10997 : : #undef NUM_KEYWORDS
10998 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
10999 : :
11000 : : #else // !Py_BUILD_CORE
11001 : : # define KWTUPLE NULL
11002 : : #endif // !Py_BUILD_CORE
11003 : :
11004 : : static const char * const _keywords[] = {"path", NULL};
11005 : : static _PyArg_Parser _parser = {
11006 : : .keywords = _keywords,
11007 : : .fname = "fspath",
11008 : : .kwtuple = KWTUPLE,
11009 : : };
11010 : : #undef KWTUPLE
11011 : : PyObject *argsbuf[1];
11012 : : PyObject *path;
11013 : :
11014 [ + - + - : 6021 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
11015 [ - + ]: 6021 : if (!args) {
11016 : 0 : goto exit;
11017 : : }
11018 : 6021 : path = args[0];
11019 : 6021 : return_value = os_fspath_impl(module, path);
11020 : :
11021 : 6021 : exit:
11022 : 6021 : return return_value;
11023 : : }
11024 : :
11025 : : #if defined(HAVE_GETRANDOM_SYSCALL)
11026 : :
11027 : : PyDoc_STRVAR(os_getrandom__doc__,
11028 : : "getrandom($module, /, size, flags=0)\n"
11029 : : "--\n"
11030 : : "\n"
11031 : : "Obtain a series of random bytes.");
11032 : :
11033 : : #define OS_GETRANDOM_METHODDEF \
11034 : : {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
11035 : :
11036 : : static PyObject *
11037 : : os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
11038 : :
11039 : : static PyObject *
11040 : 0 : os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11041 : : {
11042 : 0 : PyObject *return_value = NULL;
11043 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11044 : :
11045 : : #define NUM_KEYWORDS 2
11046 : : static struct {
11047 : : PyGC_Head _this_is_not_used;
11048 : : PyObject_VAR_HEAD
11049 : : PyObject *ob_item[NUM_KEYWORDS];
11050 : : } _kwtuple = {
11051 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11052 : : .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
11053 : : };
11054 : : #undef NUM_KEYWORDS
11055 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11056 : :
11057 : : #else // !Py_BUILD_CORE
11058 : : # define KWTUPLE NULL
11059 : : #endif // !Py_BUILD_CORE
11060 : :
11061 : : static const char * const _keywords[] = {"size", "flags", NULL};
11062 : : static _PyArg_Parser _parser = {
11063 : : .keywords = _keywords,
11064 : : .fname = "getrandom",
11065 : : .kwtuple = KWTUPLE,
11066 : : };
11067 : : #undef KWTUPLE
11068 : : PyObject *argsbuf[2];
11069 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
11070 : : Py_ssize_t size;
11071 : 0 : int flags = 0;
11072 : :
11073 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
# # # # ]
11074 [ # # ]: 0 : if (!args) {
11075 : 0 : goto exit;
11076 : : }
11077 : : {
11078 : 0 : Py_ssize_t ival = -1;
11079 : 0 : PyObject *iobj = _PyNumber_Index(args[0]);
11080 [ # # ]: 0 : if (iobj != NULL) {
11081 : 0 : ival = PyLong_AsSsize_t(iobj);
11082 : 0 : Py_DECREF(iobj);
11083 : : }
11084 [ # # # # ]: 0 : if (ival == -1 && PyErr_Occurred()) {
11085 : 0 : goto exit;
11086 : : }
11087 : 0 : size = ival;
11088 : : }
11089 [ # # ]: 0 : if (!noptargs) {
11090 : 0 : goto skip_optional_pos;
11091 : : }
11092 : 0 : flags = _PyLong_AsInt(args[1]);
11093 [ # # # # ]: 0 : if (flags == -1 && PyErr_Occurred()) {
11094 : 0 : goto exit;
11095 : : }
11096 : 0 : skip_optional_pos:
11097 : 0 : return_value = os_getrandom_impl(module, size, flags);
11098 : :
11099 : 0 : exit:
11100 : 0 : return return_value;
11101 : : }
11102 : :
11103 : : #endif /* defined(HAVE_GETRANDOM_SYSCALL) */
11104 : :
11105 : : #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
11106 : :
11107 : : PyDoc_STRVAR(os__add_dll_directory__doc__,
11108 : : "_add_dll_directory($module, /, path)\n"
11109 : : "--\n"
11110 : : "\n"
11111 : : "Add a path to the DLL search path.\n"
11112 : : "\n"
11113 : : "This search path is used when resolving dependencies for imported\n"
11114 : : "extension modules (the module itself is resolved through sys.path),\n"
11115 : : "and also by ctypes.\n"
11116 : : "\n"
11117 : : "Returns an opaque value that may be passed to os.remove_dll_directory\n"
11118 : : "to remove this directory from the search path.");
11119 : :
11120 : : #define OS__ADD_DLL_DIRECTORY_METHODDEF \
11121 : : {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
11122 : :
11123 : : static PyObject *
11124 : : os__add_dll_directory_impl(PyObject *module, path_t *path);
11125 : :
11126 : : static PyObject *
11127 : : os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11128 : : {
11129 : : PyObject *return_value = NULL;
11130 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11131 : :
11132 : : #define NUM_KEYWORDS 1
11133 : : static struct {
11134 : : PyGC_Head _this_is_not_used;
11135 : : PyObject_VAR_HEAD
11136 : : PyObject *ob_item[NUM_KEYWORDS];
11137 : : } _kwtuple = {
11138 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11139 : : .ob_item = { &_Py_ID(path), },
11140 : : };
11141 : : #undef NUM_KEYWORDS
11142 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11143 : :
11144 : : #else // !Py_BUILD_CORE
11145 : : # define KWTUPLE NULL
11146 : : #endif // !Py_BUILD_CORE
11147 : :
11148 : : static const char * const _keywords[] = {"path", NULL};
11149 : : static _PyArg_Parser _parser = {
11150 : : .keywords = _keywords,
11151 : : .fname = "_add_dll_directory",
11152 : : .kwtuple = KWTUPLE,
11153 : : };
11154 : : #undef KWTUPLE
11155 : : PyObject *argsbuf[1];
11156 : : path_t path = PATH_T_INITIALIZE("_add_dll_directory", "path", 0, 0);
11157 : :
11158 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
11159 : : if (!args) {
11160 : : goto exit;
11161 : : }
11162 : : if (!path_converter(args[0], &path)) {
11163 : : goto exit;
11164 : : }
11165 : : return_value = os__add_dll_directory_impl(module, &path);
11166 : :
11167 : : exit:
11168 : : /* Cleanup for path */
11169 : : path_cleanup(&path);
11170 : :
11171 : : return return_value;
11172 : : }
11173 : :
11174 : : #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
11175 : :
11176 : : #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
11177 : :
11178 : : PyDoc_STRVAR(os__remove_dll_directory__doc__,
11179 : : "_remove_dll_directory($module, /, cookie)\n"
11180 : : "--\n"
11181 : : "\n"
11182 : : "Removes a path from the DLL search path.\n"
11183 : : "\n"
11184 : : "The parameter is an opaque value that was returned from\n"
11185 : : "os.add_dll_directory. You can only remove directories that you added\n"
11186 : : "yourself.");
11187 : :
11188 : : #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \
11189 : : {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
11190 : :
11191 : : static PyObject *
11192 : : os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
11193 : :
11194 : : static PyObject *
11195 : : os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11196 : : {
11197 : : PyObject *return_value = NULL;
11198 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11199 : :
11200 : : #define NUM_KEYWORDS 1
11201 : : static struct {
11202 : : PyGC_Head _this_is_not_used;
11203 : : PyObject_VAR_HEAD
11204 : : PyObject *ob_item[NUM_KEYWORDS];
11205 : : } _kwtuple = {
11206 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11207 : : .ob_item = { &_Py_ID(cookie), },
11208 : : };
11209 : : #undef NUM_KEYWORDS
11210 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11211 : :
11212 : : #else // !Py_BUILD_CORE
11213 : : # define KWTUPLE NULL
11214 : : #endif // !Py_BUILD_CORE
11215 : :
11216 : : static const char * const _keywords[] = {"cookie", NULL};
11217 : : static _PyArg_Parser _parser = {
11218 : : .keywords = _keywords,
11219 : : .fname = "_remove_dll_directory",
11220 : : .kwtuple = KWTUPLE,
11221 : : };
11222 : : #undef KWTUPLE
11223 : : PyObject *argsbuf[1];
11224 : : PyObject *cookie;
11225 : :
11226 : : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
11227 : : if (!args) {
11228 : : goto exit;
11229 : : }
11230 : : cookie = args[0];
11231 : : return_value = os__remove_dll_directory_impl(module, cookie);
11232 : :
11233 : : exit:
11234 : : return return_value;
11235 : : }
11236 : :
11237 : : #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
11238 : :
11239 : : #if (defined(WIFEXITED) || defined(MS_WINDOWS))
11240 : :
11241 : : PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
11242 : : "waitstatus_to_exitcode($module, /, status)\n"
11243 : : "--\n"
11244 : : "\n"
11245 : : "Convert a wait status to an exit code.\n"
11246 : : "\n"
11247 : : "On Unix:\n"
11248 : : "\n"
11249 : : "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
11250 : : "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
11251 : : "* Otherwise, raise a ValueError.\n"
11252 : : "\n"
11253 : : "On Windows, return status shifted right by 8 bits.\n"
11254 : : "\n"
11255 : : "On Unix, if the process is being traced or if waitpid() was called with\n"
11256 : : "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n"
11257 : : "This function must not be called if WIFSTOPPED(status) is true.");
11258 : :
11259 : : #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \
11260 : : {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
11261 : :
11262 : : static PyObject *
11263 : : os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
11264 : :
11265 : : static PyObject *
11266 : 0 : os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
11267 : : {
11268 : 0 : PyObject *return_value = NULL;
11269 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
11270 : :
11271 : : #define NUM_KEYWORDS 1
11272 : : static struct {
11273 : : PyGC_Head _this_is_not_used;
11274 : : PyObject_VAR_HEAD
11275 : : PyObject *ob_item[NUM_KEYWORDS];
11276 : : } _kwtuple = {
11277 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
11278 : : .ob_item = { &_Py_ID(status), },
11279 : : };
11280 : : #undef NUM_KEYWORDS
11281 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
11282 : :
11283 : : #else // !Py_BUILD_CORE
11284 : : # define KWTUPLE NULL
11285 : : #endif // !Py_BUILD_CORE
11286 : :
11287 : : static const char * const _keywords[] = {"status", NULL};
11288 : : static _PyArg_Parser _parser = {
11289 : : .keywords = _keywords,
11290 : : .fname = "waitstatus_to_exitcode",
11291 : : .kwtuple = KWTUPLE,
11292 : : };
11293 : : #undef KWTUPLE
11294 : : PyObject *argsbuf[1];
11295 : : PyObject *status_obj;
11296 : :
11297 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
11298 [ # # ]: 0 : if (!args) {
11299 : 0 : goto exit;
11300 : : }
11301 : 0 : status_obj = args[0];
11302 : 0 : return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
11303 : :
11304 : 0 : exit:
11305 : 0 : return return_value;
11306 : : }
11307 : :
11308 : : #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
11309 : :
11310 : : #ifndef OS_TTYNAME_METHODDEF
11311 : : #define OS_TTYNAME_METHODDEF
11312 : : #endif /* !defined(OS_TTYNAME_METHODDEF) */
11313 : :
11314 : : #ifndef OS_CTERMID_METHODDEF
11315 : : #define OS_CTERMID_METHODDEF
11316 : : #endif /* !defined(OS_CTERMID_METHODDEF) */
11317 : :
11318 : : #ifndef OS_FCHDIR_METHODDEF
11319 : : #define OS_FCHDIR_METHODDEF
11320 : : #endif /* !defined(OS_FCHDIR_METHODDEF) */
11321 : :
11322 : : #ifndef OS_FCHMOD_METHODDEF
11323 : : #define OS_FCHMOD_METHODDEF
11324 : : #endif /* !defined(OS_FCHMOD_METHODDEF) */
11325 : :
11326 : : #ifndef OS_LCHMOD_METHODDEF
11327 : : #define OS_LCHMOD_METHODDEF
11328 : : #endif /* !defined(OS_LCHMOD_METHODDEF) */
11329 : :
11330 : : #ifndef OS_CHFLAGS_METHODDEF
11331 : : #define OS_CHFLAGS_METHODDEF
11332 : : #endif /* !defined(OS_CHFLAGS_METHODDEF) */
11333 : :
11334 : : #ifndef OS_LCHFLAGS_METHODDEF
11335 : : #define OS_LCHFLAGS_METHODDEF
11336 : : #endif /* !defined(OS_LCHFLAGS_METHODDEF) */
11337 : :
11338 : : #ifndef OS_CHROOT_METHODDEF
11339 : : #define OS_CHROOT_METHODDEF
11340 : : #endif /* !defined(OS_CHROOT_METHODDEF) */
11341 : :
11342 : : #ifndef OS_FSYNC_METHODDEF
11343 : : #define OS_FSYNC_METHODDEF
11344 : : #endif /* !defined(OS_FSYNC_METHODDEF) */
11345 : :
11346 : : #ifndef OS_SYNC_METHODDEF
11347 : : #define OS_SYNC_METHODDEF
11348 : : #endif /* !defined(OS_SYNC_METHODDEF) */
11349 : :
11350 : : #ifndef OS_FDATASYNC_METHODDEF
11351 : : #define OS_FDATASYNC_METHODDEF
11352 : : #endif /* !defined(OS_FDATASYNC_METHODDEF) */
11353 : :
11354 : : #ifndef OS_CHOWN_METHODDEF
11355 : : #define OS_CHOWN_METHODDEF
11356 : : #endif /* !defined(OS_CHOWN_METHODDEF) */
11357 : :
11358 : : #ifndef OS_FCHOWN_METHODDEF
11359 : : #define OS_FCHOWN_METHODDEF
11360 : : #endif /* !defined(OS_FCHOWN_METHODDEF) */
11361 : :
11362 : : #ifndef OS_LCHOWN_METHODDEF
11363 : : #define OS_LCHOWN_METHODDEF
11364 : : #endif /* !defined(OS_LCHOWN_METHODDEF) */
11365 : :
11366 : : #ifndef OS_LINK_METHODDEF
11367 : : #define OS_LINK_METHODDEF
11368 : : #endif /* !defined(OS_LINK_METHODDEF) */
11369 : :
11370 : : #ifndef OS_LISTDRIVES_METHODDEF
11371 : : #define OS_LISTDRIVES_METHODDEF
11372 : : #endif /* !defined(OS_LISTDRIVES_METHODDEF) */
11373 : :
11374 : : #ifndef OS_LISTVOLUMES_METHODDEF
11375 : : #define OS_LISTVOLUMES_METHODDEF
11376 : : #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
11377 : :
11378 : : #ifndef OS_LISTMOUNTS_METHODDEF
11379 : : #define OS_LISTMOUNTS_METHODDEF
11380 : : #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
11381 : :
11382 : : #ifndef OS__GETFULLPATHNAME_METHODDEF
11383 : : #define OS__GETFULLPATHNAME_METHODDEF
11384 : : #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
11385 : :
11386 : : #ifndef OS__GETFINALPATHNAME_METHODDEF
11387 : : #define OS__GETFINALPATHNAME_METHODDEF
11388 : : #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
11389 : :
11390 : : #ifndef OS__GETVOLUMEPATHNAME_METHODDEF
11391 : : #define OS__GETVOLUMEPATHNAME_METHODDEF
11392 : : #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
11393 : :
11394 : : #ifndef OS__PATH_SPLITROOT_METHODDEF
11395 : : #define OS__PATH_SPLITROOT_METHODDEF
11396 : : #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
11397 : :
11398 : : #ifndef OS__PATH_ISDIR_METHODDEF
11399 : : #define OS__PATH_ISDIR_METHODDEF
11400 : : #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
11401 : :
11402 : : #ifndef OS__PATH_ISFILE_METHODDEF
11403 : : #define OS__PATH_ISFILE_METHODDEF
11404 : : #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
11405 : :
11406 : : #ifndef OS__PATH_EXISTS_METHODDEF
11407 : : #define OS__PATH_EXISTS_METHODDEF
11408 : : #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
11409 : :
11410 : : #ifndef OS__PATH_ISLINK_METHODDEF
11411 : : #define OS__PATH_ISLINK_METHODDEF
11412 : : #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
11413 : :
11414 : : #ifndef OS_NICE_METHODDEF
11415 : : #define OS_NICE_METHODDEF
11416 : : #endif /* !defined(OS_NICE_METHODDEF) */
11417 : :
11418 : : #ifndef OS_GETPRIORITY_METHODDEF
11419 : : #define OS_GETPRIORITY_METHODDEF
11420 : : #endif /* !defined(OS_GETPRIORITY_METHODDEF) */
11421 : :
11422 : : #ifndef OS_SETPRIORITY_METHODDEF
11423 : : #define OS_SETPRIORITY_METHODDEF
11424 : : #endif /* !defined(OS_SETPRIORITY_METHODDEF) */
11425 : :
11426 : : #ifndef OS_SYSTEM_METHODDEF
11427 : : #define OS_SYSTEM_METHODDEF
11428 : : #endif /* !defined(OS_SYSTEM_METHODDEF) */
11429 : :
11430 : : #ifndef OS_UMASK_METHODDEF
11431 : : #define OS_UMASK_METHODDEF
11432 : : #endif /* !defined(OS_UMASK_METHODDEF) */
11433 : :
11434 : : #ifndef OS_UNAME_METHODDEF
11435 : : #define OS_UNAME_METHODDEF
11436 : : #endif /* !defined(OS_UNAME_METHODDEF) */
11437 : :
11438 : : #ifndef OS_EXECV_METHODDEF
11439 : : #define OS_EXECV_METHODDEF
11440 : : #endif /* !defined(OS_EXECV_METHODDEF) */
11441 : :
11442 : : #ifndef OS_EXECVE_METHODDEF
11443 : : #define OS_EXECVE_METHODDEF
11444 : : #endif /* !defined(OS_EXECVE_METHODDEF) */
11445 : :
11446 : : #ifndef OS_POSIX_SPAWN_METHODDEF
11447 : : #define OS_POSIX_SPAWN_METHODDEF
11448 : : #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
11449 : :
11450 : : #ifndef OS_POSIX_SPAWNP_METHODDEF
11451 : : #define OS_POSIX_SPAWNP_METHODDEF
11452 : : #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
11453 : :
11454 : : #ifndef OS_SPAWNV_METHODDEF
11455 : : #define OS_SPAWNV_METHODDEF
11456 : : #endif /* !defined(OS_SPAWNV_METHODDEF) */
11457 : :
11458 : : #ifndef OS_SPAWNVE_METHODDEF
11459 : : #define OS_SPAWNVE_METHODDEF
11460 : : #endif /* !defined(OS_SPAWNVE_METHODDEF) */
11461 : :
11462 : : #ifndef OS_REGISTER_AT_FORK_METHODDEF
11463 : : #define OS_REGISTER_AT_FORK_METHODDEF
11464 : : #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
11465 : :
11466 : : #ifndef OS_FORK1_METHODDEF
11467 : : #define OS_FORK1_METHODDEF
11468 : : #endif /* !defined(OS_FORK1_METHODDEF) */
11469 : :
11470 : : #ifndef OS_FORK_METHODDEF
11471 : : #define OS_FORK_METHODDEF
11472 : : #endif /* !defined(OS_FORK_METHODDEF) */
11473 : :
11474 : : #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
11475 : : #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
11476 : : #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
11477 : :
11478 : : #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
11479 : : #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
11480 : : #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
11481 : :
11482 : : #ifndef OS_SCHED_GETSCHEDULER_METHODDEF
11483 : : #define OS_SCHED_GETSCHEDULER_METHODDEF
11484 : : #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
11485 : :
11486 : : #ifndef OS_SCHED_SETSCHEDULER_METHODDEF
11487 : : #define OS_SCHED_SETSCHEDULER_METHODDEF
11488 : : #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
11489 : :
11490 : : #ifndef OS_SCHED_GETPARAM_METHODDEF
11491 : : #define OS_SCHED_GETPARAM_METHODDEF
11492 : : #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
11493 : :
11494 : : #ifndef OS_SCHED_SETPARAM_METHODDEF
11495 : : #define OS_SCHED_SETPARAM_METHODDEF
11496 : : #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
11497 : :
11498 : : #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
11499 : : #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
11500 : : #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
11501 : :
11502 : : #ifndef OS_SCHED_YIELD_METHODDEF
11503 : : #define OS_SCHED_YIELD_METHODDEF
11504 : : #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
11505 : :
11506 : : #ifndef OS_SCHED_SETAFFINITY_METHODDEF
11507 : : #define OS_SCHED_SETAFFINITY_METHODDEF
11508 : : #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
11509 : :
11510 : : #ifndef OS_SCHED_GETAFFINITY_METHODDEF
11511 : : #define OS_SCHED_GETAFFINITY_METHODDEF
11512 : : #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
11513 : :
11514 : : #ifndef OS_OPENPTY_METHODDEF
11515 : : #define OS_OPENPTY_METHODDEF
11516 : : #endif /* !defined(OS_OPENPTY_METHODDEF) */
11517 : :
11518 : : #ifndef OS_LOGIN_TTY_METHODDEF
11519 : : #define OS_LOGIN_TTY_METHODDEF
11520 : : #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
11521 : :
11522 : : #ifndef OS_FORKPTY_METHODDEF
11523 : : #define OS_FORKPTY_METHODDEF
11524 : : #endif /* !defined(OS_FORKPTY_METHODDEF) */
11525 : :
11526 : : #ifndef OS_GETEGID_METHODDEF
11527 : : #define OS_GETEGID_METHODDEF
11528 : : #endif /* !defined(OS_GETEGID_METHODDEF) */
11529 : :
11530 : : #ifndef OS_GETEUID_METHODDEF
11531 : : #define OS_GETEUID_METHODDEF
11532 : : #endif /* !defined(OS_GETEUID_METHODDEF) */
11533 : :
11534 : : #ifndef OS_GETGID_METHODDEF
11535 : : #define OS_GETGID_METHODDEF
11536 : : #endif /* !defined(OS_GETGID_METHODDEF) */
11537 : :
11538 : : #ifndef OS_GETPID_METHODDEF
11539 : : #define OS_GETPID_METHODDEF
11540 : : #endif /* !defined(OS_GETPID_METHODDEF) */
11541 : :
11542 : : #ifndef OS_GETGROUPLIST_METHODDEF
11543 : : #define OS_GETGROUPLIST_METHODDEF
11544 : : #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
11545 : :
11546 : : #ifndef OS_GETGROUPS_METHODDEF
11547 : : #define OS_GETGROUPS_METHODDEF
11548 : : #endif /* !defined(OS_GETGROUPS_METHODDEF) */
11549 : :
11550 : : #ifndef OS_INITGROUPS_METHODDEF
11551 : : #define OS_INITGROUPS_METHODDEF
11552 : : #endif /* !defined(OS_INITGROUPS_METHODDEF) */
11553 : :
11554 : : #ifndef OS_GETPGID_METHODDEF
11555 : : #define OS_GETPGID_METHODDEF
11556 : : #endif /* !defined(OS_GETPGID_METHODDEF) */
11557 : :
11558 : : #ifndef OS_GETPGRP_METHODDEF
11559 : : #define OS_GETPGRP_METHODDEF
11560 : : #endif /* !defined(OS_GETPGRP_METHODDEF) */
11561 : :
11562 : : #ifndef OS_SETPGRP_METHODDEF
11563 : : #define OS_SETPGRP_METHODDEF
11564 : : #endif /* !defined(OS_SETPGRP_METHODDEF) */
11565 : :
11566 : : #ifndef OS_GETPPID_METHODDEF
11567 : : #define OS_GETPPID_METHODDEF
11568 : : #endif /* !defined(OS_GETPPID_METHODDEF) */
11569 : :
11570 : : #ifndef OS_GETLOGIN_METHODDEF
11571 : : #define OS_GETLOGIN_METHODDEF
11572 : : #endif /* !defined(OS_GETLOGIN_METHODDEF) */
11573 : :
11574 : : #ifndef OS_GETUID_METHODDEF
11575 : : #define OS_GETUID_METHODDEF
11576 : : #endif /* !defined(OS_GETUID_METHODDEF) */
11577 : :
11578 : : #ifndef OS_KILL_METHODDEF
11579 : : #define OS_KILL_METHODDEF
11580 : : #endif /* !defined(OS_KILL_METHODDEF) */
11581 : :
11582 : : #ifndef OS_KILLPG_METHODDEF
11583 : : #define OS_KILLPG_METHODDEF
11584 : : #endif /* !defined(OS_KILLPG_METHODDEF) */
11585 : :
11586 : : #ifndef OS_PLOCK_METHODDEF
11587 : : #define OS_PLOCK_METHODDEF
11588 : : #endif /* !defined(OS_PLOCK_METHODDEF) */
11589 : :
11590 : : #ifndef OS_SETUID_METHODDEF
11591 : : #define OS_SETUID_METHODDEF
11592 : : #endif /* !defined(OS_SETUID_METHODDEF) */
11593 : :
11594 : : #ifndef OS_SETEUID_METHODDEF
11595 : : #define OS_SETEUID_METHODDEF
11596 : : #endif /* !defined(OS_SETEUID_METHODDEF) */
11597 : :
11598 : : #ifndef OS_SETEGID_METHODDEF
11599 : : #define OS_SETEGID_METHODDEF
11600 : : #endif /* !defined(OS_SETEGID_METHODDEF) */
11601 : :
11602 : : #ifndef OS_SETREUID_METHODDEF
11603 : : #define OS_SETREUID_METHODDEF
11604 : : #endif /* !defined(OS_SETREUID_METHODDEF) */
11605 : :
11606 : : #ifndef OS_SETREGID_METHODDEF
11607 : : #define OS_SETREGID_METHODDEF
11608 : : #endif /* !defined(OS_SETREGID_METHODDEF) */
11609 : :
11610 : : #ifndef OS_SETGID_METHODDEF
11611 : : #define OS_SETGID_METHODDEF
11612 : : #endif /* !defined(OS_SETGID_METHODDEF) */
11613 : :
11614 : : #ifndef OS_SETGROUPS_METHODDEF
11615 : : #define OS_SETGROUPS_METHODDEF
11616 : : #endif /* !defined(OS_SETGROUPS_METHODDEF) */
11617 : :
11618 : : #ifndef OS_WAIT3_METHODDEF
11619 : : #define OS_WAIT3_METHODDEF
11620 : : #endif /* !defined(OS_WAIT3_METHODDEF) */
11621 : :
11622 : : #ifndef OS_WAIT4_METHODDEF
11623 : : #define OS_WAIT4_METHODDEF
11624 : : #endif /* !defined(OS_WAIT4_METHODDEF) */
11625 : :
11626 : : #ifndef OS_WAITID_METHODDEF
11627 : : #define OS_WAITID_METHODDEF
11628 : : #endif /* !defined(OS_WAITID_METHODDEF) */
11629 : :
11630 : : #ifndef OS_WAITPID_METHODDEF
11631 : : #define OS_WAITPID_METHODDEF
11632 : : #endif /* !defined(OS_WAITPID_METHODDEF) */
11633 : :
11634 : : #ifndef OS_WAIT_METHODDEF
11635 : : #define OS_WAIT_METHODDEF
11636 : : #endif /* !defined(OS_WAIT_METHODDEF) */
11637 : :
11638 : : #ifndef OS_PIDFD_OPEN_METHODDEF
11639 : : #define OS_PIDFD_OPEN_METHODDEF
11640 : : #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
11641 : :
11642 : : #ifndef OS_SETNS_METHODDEF
11643 : : #define OS_SETNS_METHODDEF
11644 : : #endif /* !defined(OS_SETNS_METHODDEF) */
11645 : :
11646 : : #ifndef OS_UNSHARE_METHODDEF
11647 : : #define OS_UNSHARE_METHODDEF
11648 : : #endif /* !defined(OS_UNSHARE_METHODDEF) */
11649 : :
11650 : : #ifndef OS_READLINK_METHODDEF
11651 : : #define OS_READLINK_METHODDEF
11652 : : #endif /* !defined(OS_READLINK_METHODDEF) */
11653 : :
11654 : : #ifndef OS_SYMLINK_METHODDEF
11655 : : #define OS_SYMLINK_METHODDEF
11656 : : #endif /* !defined(OS_SYMLINK_METHODDEF) */
11657 : :
11658 : : #ifndef OS_TIMES_METHODDEF
11659 : : #define OS_TIMES_METHODDEF
11660 : : #endif /* !defined(OS_TIMES_METHODDEF) */
11661 : :
11662 : : #ifndef OS_GETSID_METHODDEF
11663 : : #define OS_GETSID_METHODDEF
11664 : : #endif /* !defined(OS_GETSID_METHODDEF) */
11665 : :
11666 : : #ifndef OS_SETSID_METHODDEF
11667 : : #define OS_SETSID_METHODDEF
11668 : : #endif /* !defined(OS_SETSID_METHODDEF) */
11669 : :
11670 : : #ifndef OS_SETPGID_METHODDEF
11671 : : #define OS_SETPGID_METHODDEF
11672 : : #endif /* !defined(OS_SETPGID_METHODDEF) */
11673 : :
11674 : : #ifndef OS_TCGETPGRP_METHODDEF
11675 : : #define OS_TCGETPGRP_METHODDEF
11676 : : #endif /* !defined(OS_TCGETPGRP_METHODDEF) */
11677 : :
11678 : : #ifndef OS_TCSETPGRP_METHODDEF
11679 : : #define OS_TCSETPGRP_METHODDEF
11680 : : #endif /* !defined(OS_TCSETPGRP_METHODDEF) */
11681 : :
11682 : : #ifndef OS_DUP2_METHODDEF
11683 : : #define OS_DUP2_METHODDEF
11684 : : #endif /* !defined(OS_DUP2_METHODDEF) */
11685 : :
11686 : : #ifndef OS_LOCKF_METHODDEF
11687 : : #define OS_LOCKF_METHODDEF
11688 : : #endif /* !defined(OS_LOCKF_METHODDEF) */
11689 : :
11690 : : #ifndef OS_READV_METHODDEF
11691 : : #define OS_READV_METHODDEF
11692 : : #endif /* !defined(OS_READV_METHODDEF) */
11693 : :
11694 : : #ifndef OS_PREAD_METHODDEF
11695 : : #define OS_PREAD_METHODDEF
11696 : : #endif /* !defined(OS_PREAD_METHODDEF) */
11697 : :
11698 : : #ifndef OS_PREADV_METHODDEF
11699 : : #define OS_PREADV_METHODDEF
11700 : : #endif /* !defined(OS_PREADV_METHODDEF) */
11701 : :
11702 : : #ifndef OS_SENDFILE_METHODDEF
11703 : : #define OS_SENDFILE_METHODDEF
11704 : : #endif /* !defined(OS_SENDFILE_METHODDEF) */
11705 : :
11706 : : #ifndef OS__FCOPYFILE_METHODDEF
11707 : : #define OS__FCOPYFILE_METHODDEF
11708 : : #endif /* !defined(OS__FCOPYFILE_METHODDEF) */
11709 : :
11710 : : #ifndef OS_PIPE_METHODDEF
11711 : : #define OS_PIPE_METHODDEF
11712 : : #endif /* !defined(OS_PIPE_METHODDEF) */
11713 : :
11714 : : #ifndef OS_PIPE2_METHODDEF
11715 : : #define OS_PIPE2_METHODDEF
11716 : : #endif /* !defined(OS_PIPE2_METHODDEF) */
11717 : :
11718 : : #ifndef OS_WRITEV_METHODDEF
11719 : : #define OS_WRITEV_METHODDEF
11720 : : #endif /* !defined(OS_WRITEV_METHODDEF) */
11721 : :
11722 : : #ifndef OS_PWRITE_METHODDEF
11723 : : #define OS_PWRITE_METHODDEF
11724 : : #endif /* !defined(OS_PWRITE_METHODDEF) */
11725 : :
11726 : : #ifndef OS_PWRITEV_METHODDEF
11727 : : #define OS_PWRITEV_METHODDEF
11728 : : #endif /* !defined(OS_PWRITEV_METHODDEF) */
11729 : :
11730 : : #ifndef OS_COPY_FILE_RANGE_METHODDEF
11731 : : #define OS_COPY_FILE_RANGE_METHODDEF
11732 : : #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
11733 : :
11734 : : #ifndef OS_SPLICE_METHODDEF
11735 : : #define OS_SPLICE_METHODDEF
11736 : : #endif /* !defined(OS_SPLICE_METHODDEF) */
11737 : :
11738 : : #ifndef OS_MKFIFO_METHODDEF
11739 : : #define OS_MKFIFO_METHODDEF
11740 : : #endif /* !defined(OS_MKFIFO_METHODDEF) */
11741 : :
11742 : : #ifndef OS_MKNOD_METHODDEF
11743 : : #define OS_MKNOD_METHODDEF
11744 : : #endif /* !defined(OS_MKNOD_METHODDEF) */
11745 : :
11746 : : #ifndef OS_MAJOR_METHODDEF
11747 : : #define OS_MAJOR_METHODDEF
11748 : : #endif /* !defined(OS_MAJOR_METHODDEF) */
11749 : :
11750 : : #ifndef OS_MINOR_METHODDEF
11751 : : #define OS_MINOR_METHODDEF
11752 : : #endif /* !defined(OS_MINOR_METHODDEF) */
11753 : :
11754 : : #ifndef OS_MAKEDEV_METHODDEF
11755 : : #define OS_MAKEDEV_METHODDEF
11756 : : #endif /* !defined(OS_MAKEDEV_METHODDEF) */
11757 : :
11758 : : #ifndef OS_FTRUNCATE_METHODDEF
11759 : : #define OS_FTRUNCATE_METHODDEF
11760 : : #endif /* !defined(OS_FTRUNCATE_METHODDEF) */
11761 : :
11762 : : #ifndef OS_TRUNCATE_METHODDEF
11763 : : #define OS_TRUNCATE_METHODDEF
11764 : : #endif /* !defined(OS_TRUNCATE_METHODDEF) */
11765 : :
11766 : : #ifndef OS_POSIX_FALLOCATE_METHODDEF
11767 : : #define OS_POSIX_FALLOCATE_METHODDEF
11768 : : #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
11769 : :
11770 : : #ifndef OS_POSIX_FADVISE_METHODDEF
11771 : : #define OS_POSIX_FADVISE_METHODDEF
11772 : : #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
11773 : :
11774 : : #ifndef OS_PUTENV_METHODDEF
11775 : : #define OS_PUTENV_METHODDEF
11776 : : #endif /* !defined(OS_PUTENV_METHODDEF) */
11777 : :
11778 : : #ifndef OS_UNSETENV_METHODDEF
11779 : : #define OS_UNSETENV_METHODDEF
11780 : : #endif /* !defined(OS_UNSETENV_METHODDEF) */
11781 : :
11782 : : #ifndef OS_WCOREDUMP_METHODDEF
11783 : : #define OS_WCOREDUMP_METHODDEF
11784 : : #endif /* !defined(OS_WCOREDUMP_METHODDEF) */
11785 : :
11786 : : #ifndef OS_WIFCONTINUED_METHODDEF
11787 : : #define OS_WIFCONTINUED_METHODDEF
11788 : : #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
11789 : :
11790 : : #ifndef OS_WIFSTOPPED_METHODDEF
11791 : : #define OS_WIFSTOPPED_METHODDEF
11792 : : #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
11793 : :
11794 : : #ifndef OS_WIFSIGNALED_METHODDEF
11795 : : #define OS_WIFSIGNALED_METHODDEF
11796 : : #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
11797 : :
11798 : : #ifndef OS_WIFEXITED_METHODDEF
11799 : : #define OS_WIFEXITED_METHODDEF
11800 : : #endif /* !defined(OS_WIFEXITED_METHODDEF) */
11801 : :
11802 : : #ifndef OS_WEXITSTATUS_METHODDEF
11803 : : #define OS_WEXITSTATUS_METHODDEF
11804 : : #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
11805 : :
11806 : : #ifndef OS_WTERMSIG_METHODDEF
11807 : : #define OS_WTERMSIG_METHODDEF
11808 : : #endif /* !defined(OS_WTERMSIG_METHODDEF) */
11809 : :
11810 : : #ifndef OS_WSTOPSIG_METHODDEF
11811 : : #define OS_WSTOPSIG_METHODDEF
11812 : : #endif /* !defined(OS_WSTOPSIG_METHODDEF) */
11813 : :
11814 : : #ifndef OS_FSTATVFS_METHODDEF
11815 : : #define OS_FSTATVFS_METHODDEF
11816 : : #endif /* !defined(OS_FSTATVFS_METHODDEF) */
11817 : :
11818 : : #ifndef OS_STATVFS_METHODDEF
11819 : : #define OS_STATVFS_METHODDEF
11820 : : #endif /* !defined(OS_STATVFS_METHODDEF) */
11821 : :
11822 : : #ifndef OS__GETDISKUSAGE_METHODDEF
11823 : : #define OS__GETDISKUSAGE_METHODDEF
11824 : : #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
11825 : :
11826 : : #ifndef OS_FPATHCONF_METHODDEF
11827 : : #define OS_FPATHCONF_METHODDEF
11828 : : #endif /* !defined(OS_FPATHCONF_METHODDEF) */
11829 : :
11830 : : #ifndef OS_PATHCONF_METHODDEF
11831 : : #define OS_PATHCONF_METHODDEF
11832 : : #endif /* !defined(OS_PATHCONF_METHODDEF) */
11833 : :
11834 : : #ifndef OS_CONFSTR_METHODDEF
11835 : : #define OS_CONFSTR_METHODDEF
11836 : : #endif /* !defined(OS_CONFSTR_METHODDEF) */
11837 : :
11838 : : #ifndef OS_SYSCONF_METHODDEF
11839 : : #define OS_SYSCONF_METHODDEF
11840 : : #endif /* !defined(OS_SYSCONF_METHODDEF) */
11841 : :
11842 : : #ifndef OS_STARTFILE_METHODDEF
11843 : : #define OS_STARTFILE_METHODDEF
11844 : : #endif /* !defined(OS_STARTFILE_METHODDEF) */
11845 : :
11846 : : #ifndef OS_GETLOADAVG_METHODDEF
11847 : : #define OS_GETLOADAVG_METHODDEF
11848 : : #endif /* !defined(OS_GETLOADAVG_METHODDEF) */
11849 : :
11850 : : #ifndef OS_SETRESUID_METHODDEF
11851 : : #define OS_SETRESUID_METHODDEF
11852 : : #endif /* !defined(OS_SETRESUID_METHODDEF) */
11853 : :
11854 : : #ifndef OS_SETRESGID_METHODDEF
11855 : : #define OS_SETRESGID_METHODDEF
11856 : : #endif /* !defined(OS_SETRESGID_METHODDEF) */
11857 : :
11858 : : #ifndef OS_GETRESUID_METHODDEF
11859 : : #define OS_GETRESUID_METHODDEF
11860 : : #endif /* !defined(OS_GETRESUID_METHODDEF) */
11861 : :
11862 : : #ifndef OS_GETRESGID_METHODDEF
11863 : : #define OS_GETRESGID_METHODDEF
11864 : : #endif /* !defined(OS_GETRESGID_METHODDEF) */
11865 : :
11866 : : #ifndef OS_GETXATTR_METHODDEF
11867 : : #define OS_GETXATTR_METHODDEF
11868 : : #endif /* !defined(OS_GETXATTR_METHODDEF) */
11869 : :
11870 : : #ifndef OS_SETXATTR_METHODDEF
11871 : : #define OS_SETXATTR_METHODDEF
11872 : : #endif /* !defined(OS_SETXATTR_METHODDEF) */
11873 : :
11874 : : #ifndef OS_REMOVEXATTR_METHODDEF
11875 : : #define OS_REMOVEXATTR_METHODDEF
11876 : : #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
11877 : :
11878 : : #ifndef OS_LISTXATTR_METHODDEF
11879 : : #define OS_LISTXATTR_METHODDEF
11880 : : #endif /* !defined(OS_LISTXATTR_METHODDEF) */
11881 : :
11882 : : #ifndef OS_MEMFD_CREATE_METHODDEF
11883 : : #define OS_MEMFD_CREATE_METHODDEF
11884 : : #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
11885 : :
11886 : : #ifndef OS_EVENTFD_METHODDEF
11887 : : #define OS_EVENTFD_METHODDEF
11888 : : #endif /* !defined(OS_EVENTFD_METHODDEF) */
11889 : :
11890 : : #ifndef OS_EVENTFD_READ_METHODDEF
11891 : : #define OS_EVENTFD_READ_METHODDEF
11892 : : #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
11893 : :
11894 : : #ifndef OS_EVENTFD_WRITE_METHODDEF
11895 : : #define OS_EVENTFD_WRITE_METHODDEF
11896 : : #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
11897 : :
11898 : : #ifndef OS_GET_TERMINAL_SIZE_METHODDEF
11899 : : #define OS_GET_TERMINAL_SIZE_METHODDEF
11900 : : #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
11901 : :
11902 : : #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
11903 : : #define OS_GET_HANDLE_INHERITABLE_METHODDEF
11904 : : #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
11905 : :
11906 : : #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
11907 : : #define OS_SET_HANDLE_INHERITABLE_METHODDEF
11908 : : #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
11909 : :
11910 : : #ifndef OS_GETRANDOM_METHODDEF
11911 : : #define OS_GETRANDOM_METHODDEF
11912 : : #endif /* !defined(OS_GETRANDOM_METHODDEF) */
11913 : :
11914 : : #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
11915 : : #define OS__ADD_DLL_DIRECTORY_METHODDEF
11916 : : #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
11917 : :
11918 : : #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
11919 : : #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
11920 : : #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
11921 : :
11922 : : #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
11923 : : #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
11924 : : #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
11925 : : /*[clinic end generated code: output=47750e0e29c8d707 input=a9049054013a1b77]*/
|